Skip to content

Commit

Permalink
Don't use path.relative() in react-static/src/static (#1254)
Browse files Browse the repository at this point in the history
I've been lately hitting various issues due to the way react-static
defaults to relative paths, which tend to break as soon as you tweak
react-static directories (artifacts, dist, root, etc) to locations that
are not the ones react-static recommend.

Most of these issues are automatically resolved by switching to
`path.resolve()`, which always results in absolute paths, and avoids
large `../../` chains if the second argument is absolute.
  • Loading branch information
jviotti authored and SleeplessByte committed Jul 19, 2019
1 parent 4e7891a commit 02fd470
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react-static/src/static/generateBrowserPlugins.js
Expand Up @@ -24,7 +24,7 @@ export default async state => {
: -1
if (pluginIndex === -1 && browserLocation) {
pluginImports.push(
slash(path.relative(config.paths.ARTIFACTS, browserLocation))
slash(path.resolve(config.paths.ARTIFACTS, browserLocation))
)
pluginIndex = pluginImports.length - 1
}
Expand All @@ -33,7 +33,7 @@ export default async state => {
// IIF to return the final plugin
return `{
location: "${slash(path.relative(config.paths.ARTIFACTS, location))}",
location: "${slash(path.resolve(config.paths.ARTIFACTS, location))}",
plugins: ${recurse(plugins || [])},
hooks: ${
browserLocation
Expand Down
Expand Up @@ -46,7 +46,7 @@ export default function({ config }) {
NODE_MODULES,
SRC,
DIST,
...[NODE_MODULES, SRC, DIST].map(d => path.relative(__dirname, d)),
...[NODE_MODULES, SRC, DIST].map(d => path.resolve(__dirname, d)),
'node_modules',
],
extensions: ['.wasm', '.mjs', '.js', '.json', '.jsx'],
Expand Down
Expand Up @@ -119,7 +119,7 @@ function common(state) {
SRC,
DIST,
...[NODE_MODULES, SRC, DIST].map(d =>
DIST.startsWith(ROOT) ? path.relative(__dirname, d) : path.resolve(d)
DIST.startsWith(ROOT) ? path.resolve(__dirname, d) : path.resolve(d)
),
'node_modules',
],
Expand Down

0 comments on commit 02fd470

Please sign in to comment.