diff options
author | Matt Colyer <matt@colyer.name> | 2013-11-15 05:09:12 +0400 |
---|---|---|
committer | Robert Kowalski <rok@kowalski.gd> | 2013-11-24 16:24:49 +0400 |
commit | 7677de4583100bc39407093ecc6bc13715bf8161 (patch) | |
tree | 444718f076190f361bed3c6cc6e1b1210589ca46 /lib/dedupe.js | |
parent | ff74687472b20c35a310b4bf965fb65fe32acd17 (diff) |
Use platform independent path separators in dedup
`npm dedupe` fails silently on windows due to incorrect
path splitting and joining without these changes.
Diffstat (limited to 'lib/dedupe.js')
-rw-r--r-- | lib/dedupe.js | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/dedupe.js b/lib/dedupe.js index 3d49cbf6f..ce161a46c 100644 --- a/lib/dedupe.js +++ b/lib/dedupe.js @@ -130,15 +130,16 @@ function dedupe_ (dir, filter, unavoidable, dryrun, silent, cb) { // a=/path/to/node_modules/foo/node_modules/bar // b=/path/to/node_modules/elk/node_modules/bar // ==/path/to/node_modules/bar - a = a.split(/\/node_modules\//) - b = b.split(/\/node_modules\//) + var nmReg = new RegExp("\\" + path.sep + "node_modules\\" + path.sep) + a = a.split(nmReg) + b = b.split(nmReg) var name = a.pop() b.pop() // find the longest chain that both A and B share. // then push the name back on it, and join by /node_modules/ var res = [] for (var i = 0, al = a.length, bl = b.length; i < al && i < bl && a[i] === b[i]; i++); - return a.slice(0, i).concat(name).join("/node_modules/") + return a.slice(0, i).concat(name).join(path.sep + "node_modules" + path.sep) }) : undefined return [item[0], { item: item @@ -192,9 +193,10 @@ function installAndRetest (set, filter, dir, unavoidable, silent, cb) { // where is /path/to/node_modules/foo/node_modules/bar // for package "bar", but we need it to be just // /path/to/node_modules/foo - where = where.split(/\/node_modules\//) + var nmReg = new RegExp("\\" + path.sep + "node_modules\\" + path.sep) + where = where.split(nmReg) where.pop() - where = where.join("/node_modules/") + where = where.join(path.sep + "node_modules" + path.sep) remove.push.apply(remove, others) return npm.commands.install(where, what, cb) |