From 14d08bee162e85a28cf82e4ea447b49c900aebc9 Mon Sep 17 00:00:00 2001 From: Niroshan Sugirtharatnam Date: Mon, 9 Apr 2018 03:48:38 -0400 Subject: [PATCH 1/2] [Fix] `node-modules-paths`: correctly resolve paths that are on Windows networked drives Fixes #155. --- lib/node-modules-paths.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 lib/node-modules-paths.js diff --git a/lib/node-modules-paths.js b/lib/node-modules-paths.js old mode 100644 new mode 100755 index df50f48b..2b43813a --- a/lib/node-modules-paths.js +++ b/lib/node-modules-paths.js @@ -18,7 +18,7 @@ var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) { return paths.reduce(function (dirs, aPath) { return dirs.concat(modules.map(function (moduleDir) { - return path.join(prefix, aPath, moduleDir); + return path.resolve(prefix, aPath, moduleDir); })); }, []); }; From 6a0acc88cc8dbf74448e9dd6a5d4a30dde93c814 Mon Sep 17 00:00:00 2001 From: Tim van den Eijnden Date: Wed, 29 May 2019 11:21:22 +0200 Subject: [PATCH 2/2] [Tests] add test cases for resolving path on Windows networked drives --- test/node-modules-paths.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/node-modules-paths.js b/test/node-modules-paths.js index 1500fb19..675441db 100644 --- a/test/node-modules-paths.js +++ b/test/node-modules-paths.js @@ -118,4 +118,26 @@ test('node-modules-paths', function (t) { t.end(); }); + + t.test('combine paths correctly on Windows', function (t) { + var start = 'C:\\Users\\username\\myProject\\src'; + var paths = []; + var moduleDirectories = ['node_modules', start]; + var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories }); + + t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir'); + + t.end(); + }); + + t.test('combine paths correctly on non-Windows', { skip: process.platform === 'win32' }, function (t) { + var start = '/Users/username/git/myProject/src'; + var paths = []; + var moduleDirectories = ['node_modules', '/Users/username/git/myProject/src']; + var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories }); + + t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir'); + + t.end(); + }); });