Skip to content

Commit

Permalink
Fix relativizeLink for requests from tarballs
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Feb 5, 2020
1 parent 1a893fc commit 1b597b1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/install/inflate-shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,21 @@ function tarballToVersion (name, tb) {
return match[2] || match[1]
}

function relativizeLink (name, spec, topPath, requested) {
function relativizeLink (name, spec, topPath, sw, requested) {
if (!spec.startsWith('file:')) {
return
}
const relativized = path.relative(requested.fetchSpec, path.resolve(topPath, spec.slice(5)))

let requestedPath
if (requested.type === 'directory') {
requestedPath = requested.fetchSpec
} else if (requested.type === 'file') {
requestedPath = path.dirname(requested.fetchSpec)
} else {
requestedPath = sw.resolved
}

const relativized = path.relative(requestedPath, path.resolve(topPath, spec.slice(5)))
return 'file:' + relativized
}

Expand All @@ -113,7 +123,7 @@ function inflatableChild (onDiskChild, name, topPath, tree, sw, requested, opts)
Object.keys(sw.requires).forEach(name => {
const spec = sw.requires[name]
sw.requires[name] = tarballToVersion(name, spec) ||
relativizeLink(name, spec, topPath, requested) ||
relativizeLink(name, spec, topPath, sw, requested) ||
spec
})
}
Expand Down

0 comments on commit 1b597b1

Please sign in to comment.