Skip to content

Commit

Permalink
0.19.11
Browse files Browse the repository at this point in the history
- Fixed bug that caused isoRequire to only work with absolute paths.
- Various dependencies updated.
  • Loading branch information
kethinov authored Nov 28, 2021
1 parent 91425f4 commit ce5a994
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 98 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

- Put your changes here...

## 0.19.11

- Fixed bug that caused isoRequire to only work with absolute paths.
- Various dependencies updated.

## 0.19.10

- Added `roosevelt-router` feature to improve support for writing isomorphic code for SPAs.
Expand Down
28 changes: 25 additions & 3 deletions lib/mapRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,33 @@ module.exports = app => {
// optional require designed to fail silently allowing || chaining
router.isoRequire = (module) => {
try {
return require(module)
// the paths added by appModulePath in sourceParams aren't automatically available here because of https://github.com/patrick-steele-idem/app-module-path-node/issues/17
// thus we have to examine each path manually so the shorthands still work in isoRequire the same as they would in require
let mod
mod = path.join(params.appDir, module)
if (fsr.fileExists(mod) || fsr.fileExists(mod + '.js')) {
return require(path.join(params.appDir, module))
}
mod = path.join(path.join(params.appDir, params.modelsPath, '../'), module)
if (fsr.fileExists(mod) || fsr.fileExists(mod + '.js')) {
return require(path.join(path.join(params.appDir, params.modelsPath, '../'), module))
}
mod = path.join(path.join(params.appDir, params.controllersPath, '../'), module)
if (fsr.fileExists(mod) || fsr.fileExists(mod + '.js')) {
return require(path.join(path.join(params.appDir, params.controllersPath, '../'), module))
}
if (fsr.fileExists(module)) {
return require(module)
}
return () => {
logger.error(`isoRequire was unable to load module: ${module}`)
return {}
}
} catch (e) {
// fail silently by returning a function that does nothing but return false
console.error(e)
return () => {
return false
logger.error(`isoRequire was unable to load module: ${module}`)
return {}
}
}
}
Expand Down
Loading

0 comments on commit ce5a994

Please sign in to comment.