Skip to content

Commit 35b2b64

Browse files
committed
Fix node_modules paths on Windows
This change moves 'prefix' test to happen after the absolute path is resolved. Without it, the prefix tests never actually fire when starting with a relative path, and the resulting dirs all end up looking like [ '/C:..', '/C:...' ] instead of [ 'C:...', 'C:...' ]
1 parent 9f2431b commit 35b2b64

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/node-modules-paths.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ module.exports = function (start, opts) {
55
? [].concat(opts.moduleDirectory)
66
: ['node_modules']
77
;
8+
9+
// ensure that `start` is an absolute path at this point,
10+
// resolving against the process' current working directory
11+
start = path.resolve(start);
12+
813
var prefix = '/';
914
if (/^([A-Za-z]:)/.test(start)) {
1015
prefix = '';
1116
} else if (/^\\\\/.test(start)) {
1217
prefix = '\\\\';
1318
}
14-
var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/;
1519

16-
// ensure that `start` is an absolute path at this point,
17-
// resolving against the process' current working directory
18-
start = path.resolve(start);
20+
var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/;
1921

2022
var parts = start.split(splitRe);
2123

0 commit comments

Comments
 (0)