Skip to content

Commit

Permalink
always use linux path separators in require path
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Jun 16, 2020
1 parent ed6bd63 commit 39713e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions packages/kbn-optimizer/src/worker/entry_point_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
* under the License.
*/

module.exports = function ({ entries }: { entries: Array<{ importId: string; relPath: string }> }) {
const lines = entries.map(({ importId, relPath }) => [
`__kbnBundles__.define('${importId}', __webpack_require__, require.resolve('./${relPath}'))`,
module.exports = function ({
entries,
}: {
entries: Array<{ importId: string; requirePath: string }>;
}) {
const lines = entries.map(({ importId, requirePath }) => [
`__kbnBundles__.define('${importId}', __webpack_require__, require.resolve('${requirePath}'))`,
]);

return {
Expand Down
14 changes: 10 additions & 4 deletions packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
entries: bundle.publicDirNames.map((name) => {
const absolute = Path.resolve(bundle.contextDir, name);
const newContext = Path.dirname(ENTRY_CREATOR);
return {
importId: `${bundle.type}/${bundle.id}/${name}`,
relPath: Path.relative(newContext, absolute),
};
const importId = `${bundle.type}/${bundle.id}/${name}`;

// relative path from context of the ENTRY_CREATOR, with linux path separators
let requirePath = Path.relative(newContext, absolute).split('\\').join('/');
if (!requirePath.startsWith('.')) {
// ensure requirePath is identified by node as relative
requirePath = `./${requirePath}`;
}

return { importId, requirePath };
}),
},
},
Expand Down

0 comments on commit 39713e4

Please sign in to comment.