Skip to content

Commit

Permalink
fix(nextjs): Escape Windows paths when writing wrapper templates (#6101)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Nov 2, 2022
1 parent aad2f85 commit 621e0b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/loaders/prefixLoader.ts
Expand Up @@ -20,7 +20,7 @@ export default function prefixLoader(this: LoaderThis<LoaderOptions>, userCode:

// Fill in the placeholder
let templateCode = fs.readFileSync(templatePath).toString();
templateCode = templateCode.replace('__DIST_DIR__', distDir);
templateCode = templateCode.replace('__DIST_DIR__', distDir.replace(/\\/g, '\\\\'));

return `${templateCode}\n${userCode}`;
}
6 changes: 3 additions & 3 deletions packages/nextjs/src/config/loaders/proxyLoader.ts
Expand Up @@ -47,12 +47,12 @@ export default async function proxyLoader(this: LoaderThis<LoaderOptions>, userC
: 'pageProxyLoaderTemplate.js';
const templatePath = path.resolve(__dirname, `../templates/${templateFile}`);
let templateCode = fs.readFileSync(templatePath).toString();
// Make sure the template is included when runing `webpack watch`
// Make sure the template is included when running `webpack watch`
this.addDependency(templatePath);

// Inject the route and the path to the file we're wrapping into the template
templateCode = templateCode.replace(/__ROUTE__/g, parameterizedRoute);
templateCode = templateCode.replace(/__RESOURCE_PATH__/g, this.resourcePath);
templateCode = templateCode.replace(/__ROUTE__/g, parameterizedRoute.replace(/\\/g, '\\\\'));
templateCode = templateCode.replace(/__RESOURCE_PATH__/g, this.resourcePath.replace(/\\/g, '\\\\'));

// Run the proxy module code through Rollup, in order to split the `export * from '<wrapped file>'` out into
// individual exports (which nextjs seems to require).
Expand Down

0 comments on commit 621e0b3

Please sign in to comment.