Skip to content

Commit 2585eb6

Browse files
committed
Fix getModule so it correctly handles Windows paths
1 parent 1d5ac33 commit 2585eb6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/node/src/module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ export function getModule(filename: string | undefined): string | undefined {
66
return;
77
}
88

9+
const normalizedFilename = filename
10+
.replace(/^[A-Z]:/, '') // remove Windows-style prefix
11+
.replace(/\\/g, '/'); // replace all `\` instances with `/`;
12+
913
// We could use optional chaining here but webpack does like that mixed with require
1014
const base = `${
1115
(require && require.main && require.main.filename && dirname(require.main.filename)) || global.process.cwd()
1216
}/`;
1317

1418
// It's specifically a module
15-
const file = basename(filename, '.js');
19+
const file = basename(normalizedFilename, '.js');
1620

17-
const path = dirname(filename);
21+
const path = dirname(normalizedFilename);
1822
let n = path.lastIndexOf('/node_modules/');
1923
if (n > -1) {
2024
// /node_modules/ is 14 chars

0 commit comments

Comments
 (0)