Skip to content

Commit ffe354f

Browse files
committed
fix(add): Always use POSIX paths when computing relative file: specifiers
1 parent 16d93b6 commit ffe354f

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎commands/add/index.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ class AddCommand extends Command {
147147
if (this.selfSatisfied) {
148148
const node = this.packageGraph.get(name);
149149

150-
return Promise.resolve(this.spec.saveRelativeFileSpec ? node.location : node.version);
150+
// ALWAYS use POSIX path for relative file: specifiers
151+
return Promise.resolve(
152+
this.spec.saveRelativeFileSpec ? path.posix.normalize(node.location) : node.version
153+
);
151154
}
152155

153156
return packageJson(name, { version: fetchSpec }).then(pkg => pkg.version);

‎commands/add/lib/get-range-to-reference.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ function getRangeToReference(spec, deps, loc, prefix) {
1111
const resolved = spec.type === "tag" ? `${prefix}${spec.version}` : spec.fetchSpec;
1212

1313
if (spec.saveRelativeFileSpec) {
14-
// "version" has been resolved to pkg.location in getPackageVersion()
15-
return npa.resolve(spec.name, path.relative(loc, spec.version), loc).saveSpec;
14+
// ALWAYS render a POSIX file: spec, Windows can deal with it
15+
const where = path.posix.normalize(loc);
16+
17+
// "spec.version" has been resolved to pkg.location in getPackageVersion()
18+
const relativeFileSpec = `file:${path.posix.relative(where, spec.version)}`;
19+
20+
return npa.resolve(spec.name, relativeFileSpec, where).saveSpec;
1621
}
1722

1823
if (prefix && current && semver.intersects(current, resolved)) {

0 commit comments

Comments
 (0)