Skip to content

Commit

Permalink
fix: finding path to webpack.config.mjs on Windows (#723)
Browse files Browse the repository at this point in the history
* fix: check filename and not raw candidate

* refactor: use pathToFileURL, remove redundant absolute path check

* chore: add changeset
  • Loading branch information
jbroma authored Aug 28, 2024
1 parent 912942d commit d3c96b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-melons-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@callstack/repack': patch
---

Fix reading `webpack.config.mjs` on Windows
16 changes: 7 additions & 9 deletions packages/repack/src/commands/utils/getWebpackConfigPath.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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;
}
Expand Down

0 comments on commit d3c96b8

Please sign in to comment.