Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relativize file links when inflating shrinkwrap #758

Closed
wants to merge 9 commits into from
18 changes: 17 additions & 1 deletion lib/install/inflate-shrinkwrap.js
Expand Up @@ -89,6 +89,14 @@ function tarballToVersion (name, tb) {
return match[2] || match[1]
}

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

function inflatableChild (onDiskChild, name, topPath, tree, sw, requested, opts) {
validate('OSSOOOO|ZSSOOOO', arguments)
const usesIntegrity = (
Expand All @@ -101,7 +109,15 @@ function inflatableChild (onDiskChild, name, topPath, tree, sw, requested, opts)
sw.resolved = sw.version
sw.version = regTarball
}
if (sw.requires) Object.keys(sw.requires).map(_ => { sw.requires[_] = tarballToVersion(_, sw.requires[_]) || sw.requires[_] })
if (sw.requires) {
Object.keys(sw.requires).forEach(_ => {
ruyadorno marked this conversation as resolved.
Show resolved Hide resolved
sw.requires[_] = (
tarballToVersion(_, sw.requires[_]) ||
relativizeLink(_, sw.requires[_], topPath, requested) ||
sw.requires[_]
)
})
}
const modernLink = requested.type === 'directory' && !sw.from
if (hasModernMeta(onDiskChild) && childIsEquivalent(sw, requested, onDiskChild)) {
// The version on disk matches the shrinkwrap entry.
Expand Down