Skip to content

Commit 9e2fd2c

Browse files
authored
[Fix] node-modules-paths: correctly resolve paths that are on Windows networked drives
Merge pull request #156 from GeekMode/networked_drive_fix
2 parents 1354943 + 6a0acc8 commit 9e2fd2c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/node-modules-paths.js

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
1818

1919
return paths.reduce(function (dirs, aPath) {
2020
return dirs.concat(modules.map(function (moduleDir) {
21-
return path.join(prefix, aPath, moduleDir);
21+
return path.resolve(prefix, aPath, moduleDir);
2222
}));
2323
}, []);
2424
};

test/node-modules-paths.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,26 @@ test('node-modules-paths', function (t) {
118118

119119
t.end();
120120
});
121+
122+
t.test('combine paths correctly on Windows', function (t) {
123+
var start = 'C:\\Users\\username\\myProject\\src';
124+
var paths = [];
125+
var moduleDirectories = ['node_modules', start];
126+
var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });
127+
128+
t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir');
129+
130+
t.end();
131+
});
132+
133+
t.test('combine paths correctly on non-Windows', { skip: process.platform === 'win32' }, function (t) {
134+
var start = '/Users/username/git/myProject/src';
135+
var paths = [];
136+
var moduleDirectories = ['node_modules', '/Users/username/git/myProject/src'];
137+
var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });
138+
139+
t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir');
140+
141+
t.end();
142+
});
121143
});

0 commit comments

Comments
 (0)