Skip to content
Prev Previous commit
Next Next commit
Simplify relativizeLink now it doesn't need to look at sw.resolved
  • Loading branch information
jsnajdr committed Feb 14, 2020
commit ce2936f810fa6f8940229e1775551d338cac1017
14 changes: 5 additions & 9 deletions lib/install/inflate-shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,14 @@ function tarballToVersion (name, tb) {
return match[2] || match[1]
}

function relativizeLink (name, spec, topPath, sw, requested) {
function relativizeLink (name, spec, topPath, requested) {
if (!spec.startsWith('file:')) {
return
}

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

const relativized = path.relative(requestedPath, path.resolve(topPath, spec.slice(5)))
Expand All @@ -123,7 +119,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, sw, requested) ||
relativizeLink(name, spec, topPath, requested) ||
spec
})
}
Expand Down