diff --git a/commands/add/index.js b/commands/add/index.js index 20c883e35f..e681724e37 100644 --- a/commands/add/index.js +++ b/commands/add/index.js @@ -147,7 +147,10 @@ class AddCommand extends Command { if (this.selfSatisfied) { const node = this.packageGraph.get(name); - return Promise.resolve(this.spec.saveRelativeFileSpec ? node.location : node.version); + // ALWAYS use POSIX path for relative file: specifiers + return Promise.resolve( + this.spec.saveRelativeFileSpec ? path.posix.normalize(node.location) : node.version + ); } return packageJson(name, { version: fetchSpec }).then(pkg => pkg.version); diff --git a/commands/add/lib/get-range-to-reference.js b/commands/add/lib/get-range-to-reference.js index cf1398dbaf..9a65fe4474 100644 --- a/commands/add/lib/get-range-to-reference.js +++ b/commands/add/lib/get-range-to-reference.js @@ -11,8 +11,13 @@ function getRangeToReference(spec, deps, loc, prefix) { const resolved = spec.type === "tag" ? `${prefix}${spec.version}` : spec.fetchSpec; if (spec.saveRelativeFileSpec) { - // "version" has been resolved to pkg.location in getPackageVersion() - return npa.resolve(spec.name, path.relative(loc, spec.version), loc).saveSpec; + // ALWAYS render a POSIX file: spec, Windows can deal with it + const where = path.posix.normalize(loc); + + // "spec.version" has been resolved to pkg.location in getPackageVersion() + const relativeFileSpec = `file:${path.posix.relative(where, spec.version)}`; + + return npa.resolve(spec.name, relativeFileSpec, where).saveSpec; } if (prefix && current && semver.intersects(current, resolved)) {