Skip to content

Commit

Permalink
fix(add): Always use POSIX paths when computing relative file: specif…
Browse files Browse the repository at this point in the history
…iers
  • Loading branch information
evocateur committed Jul 31, 2018
1 parent 16d93b6 commit ffe354f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion commands/add/index.js
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions commands/add/lib/get-range-to-reference.js
Expand Up @@ -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)) {
Expand Down

0 comments on commit ffe354f

Please sign in to comment.