Please sign in to comment.
Don't use a relative path to resolve Default404 template (#1250)
* Don't use a relative path to resolve Default404 template The current approach assumes that the current directory when running `react-static` is the root path, which might not be the case if you customize the root. This came up as I'm developing a CLI module that embeds `react-static`, takes some command line arguments, spawns `react-static` using files inside the CLI module, and stores the results in the user's destination directory. When the tool (and therefore `react-static`) are installed globally, my `ROOT` is: ``` /Users/jviotti/.nvm/versions/node/v9.11.2/lib/node_modules/<my-cli> ``` And `__dirname` from `src/static/getRoutes.js` becomes: ``` /Users/jviotti/.nvm/versions/node/v9.11.2/lib/node_modules/<my-cli>/node_modules/react-static/lib/static ``` Given those two variables, the code in `getRoutes.js` will evaluate the `Default404` template path to: ``` node_modules/react-static/lib/browser/components/Default404 ``` Which is a relative path, therefore `react-static` will try to find `Default404` in a local installation of `react-static` in the place the user ran the CLI, which is not expected. Making the path absolute ensures that `react-static` always defaults the 404 template to the one it itself ships, instead of accidentally cross referencing another version of itself.
- Loading branch information...
Showing with 12 additions and 17 deletions.
- +1 −1 packages/react-static/src/static/components/BodyWithMeta.js
- +3 −3 packages/react-static/src/static/components/__tests__/__snapshots__/BodyWithMeta.test.js.snap
- +1 −3 packages/react-static/src/static/extractTemplates.js
- +4 −4 packages/react-static/src/static/getConfig.js
- +3 −6 packages/react-static/src/static/getRoutes.js