From d3c96b8f55237b714ac0eed03d94d0d1b6cff565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Roma=C5=84czyk?= Date: Wed, 28 Aug 2024 14:00:42 +0200 Subject: [PATCH] fix: finding path to `webpack.config.mjs` on Windows (#723) * fix: check filename and not raw candidate * refactor: use pathToFileURL, remove redundant absolute path check * chore: add changeset --- .changeset/friendly-melons-argue.md | 5 +++++ .../src/commands/utils/getWebpackConfigPath.ts | 16 +++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 .changeset/friendly-melons-argue.md diff --git a/.changeset/friendly-melons-argue.md b/.changeset/friendly-melons-argue.md new file mode 100644 index 000000000..c352a9f3f --- /dev/null +++ b/.changeset/friendly-melons-argue.md @@ -0,0 +1,5 @@ +--- +'@callstack/repack': patch +--- + +Fix reading `webpack.config.mjs` on Windows diff --git a/packages/repack/src/commands/utils/getWebpackConfigPath.ts b/packages/repack/src/commands/utils/getWebpackConfigPath.ts index ea285f87c..eeaa3fa8d 100644 --- a/packages/repack/src/commands/utils/getWebpackConfigPath.ts +++ b/packages/repack/src/commands/utils/getWebpackConfigPath.ts @@ -1,6 +1,7 @@ -import path from 'path'; -import fs from 'fs'; -import Os from 'os'; +import path from 'node:path'; +import fs from 'node:fs'; +import os from 'node:os'; +import url from 'node:url'; // Supports the same files as Webpack CLI. const DEFAULT_WEBPACK_CONFIG_LOCATIONS = [ @@ -22,13 +23,10 @@ export function getWebpackConfigPath(root: string, customPath?: string) { const filename = path.isAbsolute(candidate) ? candidate : path.join(root, candidate); + if (fs.existsSync(filename)) { - if ( - path.isAbsolute(candidate) && - candidate.endsWith('.mjs') && - Os.platform() === 'win32' - ) { - return `file:\\${filename}`; + if (path.extname(filename) === '.mjs' && os.platform() === 'win32') { + return url.pathToFileURL(filename).href; } else { return filename; }