Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornlf <quitlahok@gmail.com>2022-04-14 01:07:01 +0300
committerLuke Karrys <luke@lukekarrys.com>2022-04-20 02:22:20 +0300
commit0ebadf5b603368557e9e837a46ea5c59c2677a81 (patch)
tree41266961691be10397e1dd388fdd2f1476573cc4 /workspaces/arborist/lib
parent3d964940f410052918e37a9b05818fe9dc4cd86a (diff)
feat(arborist): add support for installLinks
when set, installLinks instructs arborist to pack and extract a file: dependency rather than creating a symlink to it. this has the effect of also installing the dependencies for the linked dependency, though if local changes are made it also requires the user to reinstall the package
Diffstat (limited to 'workspaces/arborist/lib')
-rw-r--r--workspaces/arborist/lib/arborist/build-ideal-tree.js22
-rw-r--r--workspaces/arborist/lib/arborist/load-actual.js1
-rw-r--r--workspaces/arborist/lib/arborist/load-virtual.js2
-rw-r--r--workspaces/arborist/lib/dep-valid.js16
-rw-r--r--workspaces/arborist/lib/node.js2
-rw-r--r--workspaces/arborist/lib/place-dep.js3
6 files changed, 36 insertions, 10 deletions
diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js
index f3166c37e..55eb82923 100644
--- a/workspaces/arborist/lib/arborist/build-ideal-tree.js
+++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js
@@ -124,6 +124,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
globalStyle = false,
idealTree = null,
includeWorkspaceRoot = false,
+ installLinks = false,
legacyPeerDeps = false,
packageLock = true,
strictPeerDeps = false,
@@ -135,6 +136,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
this[_strictPeerDeps] = !!strictPeerDeps
this.idealTree = idealTree
+ this.installLinks = installLinks
this.legacyPeerDeps = legacyPeerDeps
this[_usePackageLock] = packageLock
@@ -410,6 +412,7 @@ Try using the package name instead, e.g:
peer: false,
optional: false,
global: this[_global],
+ installLinks: this.installLinks,
legacyPeerDeps: this.legacyPeerDeps,
loadOverrides: true,
})
@@ -424,6 +427,7 @@ Try using the package name instead, e.g:
peer: false,
optional: false,
global: this[_global],
+ installLinks: this.installLinks,
legacyPeerDeps: this.legacyPeerDeps,
root,
})
@@ -992,6 +996,7 @@ This is a one-time fix-up, please be patient...
preferDedupe: this[_preferDedupe],
legacyBundling: this[_legacyBundling],
strictPeerDeps: this[_strictPeerDeps],
+ installLinks: this.installLinks,
legacyPeerDeps: this.legacyPeerDeps,
globalStyle: this[_globalStyle],
}))
@@ -1151,6 +1156,7 @@ This is a one-time fix-up, please be patient...
const vr = new Node({
path: node.realpath,
sourceReference: node,
+ installLinks: this.installLinks,
legacyPeerDeps: this.legacyPeerDeps,
overrides: node.overrides,
})
@@ -1268,17 +1274,18 @@ This is a one-time fix-up, please be patient...
// the object so it doesn't get mutated.
// Don't bother to load the manifest for link deps, because the target
// might be within another package that doesn't exist yet.
- const { legacyPeerDeps } = this
+ const { installLinks, legacyPeerDeps } = this
+ const isWorkspace = this.idealTree.workspaces && this.idealTree.workspaces.has(spec.name)
- // spec is a directory, link it
- if (spec.type === 'directory') {
+ // spec is a directory, link it unless installLinks is set or it's a workspace
+ if (spec.type === 'directory' && (isWorkspace || !installLinks)) {
return this[_linkFromSpec](name, spec, parent, edge)
}
// if the spec matches a workspace name, then see if the workspace node will
// satisfy the edge. if it does, we return the workspace node to make sure it
// takes priority.
- if (this.idealTree.workspaces && this.idealTree.workspaces.has(spec.name)) {
+ if (isWorkspace) {
const existingNode = this.idealTree.edgesOut.get(spec.name).to
if (existingNode && existingNode.isWorkspace && existingNode.satisfies(edge)) {
return edge.to
@@ -1288,7 +1295,7 @@ This is a one-time fix-up, please be patient...
// spec isn't a directory, and either isn't a workspace or the workspace we have
// doesn't satisfy the edge. try to fetch a manifest and build a node from that.
return this[_fetchManifest](spec)
- .then(pkg => new Node({ name, pkg, parent, legacyPeerDeps }), error => {
+ .then(pkg => new Node({ name, pkg, parent, installLinks, legacyPeerDeps }), error => {
error.requiredBy = edge.from.location || '.'
// failed to load the spec, either because of enotarget or
@@ -1298,6 +1305,7 @@ This is a one-time fix-up, please be patient...
name,
parent,
error,
+ installLinks,
legacyPeerDeps,
})
this[_loadFailures].add(n)
@@ -1307,9 +1315,9 @@ This is a one-time fix-up, please be patient...
[_linkFromSpec] (name, spec, parent, edge) {
const realpath = spec.fetchSpec
- const { legacyPeerDeps } = this
+ const { installLinks, legacyPeerDeps } = this
return rpj(realpath + '/package.json').catch(() => ({})).then(pkg => {
- const link = new Link({ name, parent, realpath, pkg, legacyPeerDeps })
+ const link = new Link({ name, parent, realpath, pkg, installLinks, legacyPeerDeps })
this[_linkNodes].add(link)
return link
})
diff --git a/workspaces/arborist/lib/arborist/load-actual.js b/workspaces/arborist/lib/arborist/load-actual.js
index b04fc88f6..70b898141 100644
--- a/workspaces/arborist/lib/arborist/load-actual.js
+++ b/workspaces/arborist/lib/arborist/load-actual.js
@@ -283,6 +283,7 @@ module.exports = cls => class ActualLoader extends cls {
.then(pkg => [pkg, null], error => [null, error])
.then(([pkg, error]) => {
return this[normalize(path) === real ? _newNode : _newLink]({
+ installLinks: this.installLinks,
legacyPeerDeps: this.legacyPeerDeps,
path,
realpath: real,
diff --git a/workspaces/arborist/lib/arborist/load-virtual.js b/workspaces/arborist/lib/arborist/load-virtual.js
index 8a41e7686..097e5fb84 100644
--- a/workspaces/arborist/lib/arborist/load-virtual.js
+++ b/workspaces/arborist/lib/arborist/load-virtual.js
@@ -278,6 +278,7 @@ module.exports = cls => class VirtualLoader extends cls {
const peer = sw.peer
const node = new Node({
+ installLinks: this.installLinks,
legacyPeerDeps: this.legacyPeerDeps,
root: this.virtualTree,
path,
@@ -304,6 +305,7 @@ module.exports = cls => class VirtualLoader extends cls {
[loadLink] (location, targetLoc, target, meta) {
const path = resolve(this.path, location)
const link = new Link({
+ installLinks: this.installLinks,
legacyPeerDeps: this.legacyPeerDeps,
path,
realpath: resolve(this.path, targetLoc),
diff --git a/workspaces/arborist/lib/dep-valid.js b/workspaces/arborist/lib/dep-valid.js
index 2c837ae88..c69ab557a 100644
--- a/workspaces/arborist/lib/dep-valid.js
+++ b/workspaces/arborist/lib/dep-valid.js
@@ -53,9 +53,7 @@ const depValid = (child, requested, requestor) => {
return semver.satisfies(child.version, requested.fetchSpec, true)
case 'directory':
- // directory must be a link to the specified folder
- return !!child.isLink &&
- relative(child.realpath, requested.fetchSpec) === ''
+ return linkValid(child, requested, requestor)
case 'file':
return tarballValid(child, requested, requestor)
@@ -108,6 +106,18 @@ const depValid = (child, requested, requestor) => {
return false
}
+const linkValid = (child, requested, requestor) => {
+ const isLink = !!child.isLink
+ // if we're installing links and the node is a link, then it's invalid because we want
+ // a real node to be there
+ if (requestor.installLinks) {
+ return !isLink
+ }
+
+ // directory must be a link to the specified folder
+ return isLink && relative(child.realpath, requested.fetchSpec) === ''
+}
+
const tarballValid = (child, requested, requestor) => {
if (child.isLink) {
return false
diff --git a/workspaces/arborist/lib/node.js b/workspaces/arborist/lib/node.js
index abd54ffe9..60301798b 100644
--- a/workspaces/arborist/lib/node.js
+++ b/workspaces/arborist/lib/node.js
@@ -86,6 +86,7 @@ class Node {
name,
children,
fsChildren,
+ installLinks = false,
legacyPeerDeps = false,
linksIn,
hasShrinkwrap,
@@ -152,6 +153,7 @@ class Node {
}
this.integrity = integrity || pkg._integrity || null
this.hasShrinkwrap = hasShrinkwrap || pkg._hasShrinkwrap || false
+ this.installLinks = installLinks
this.legacyPeerDeps = legacyPeerDeps
this.children = new CaseInsensitiveMap()
diff --git a/workspaces/arborist/lib/place-dep.js b/workspaces/arborist/lib/place-dep.js
index c0cbe91fe..9d84d3f1b 100644
--- a/workspaces/arborist/lib/place-dep.js
+++ b/workspaces/arborist/lib/place-dep.js
@@ -45,6 +45,7 @@ class PlaceDep {
auditReport,
legacyBundling,
strictPeerDeps,
+ installLinks,
legacyPeerDeps,
globalStyle,
} = parent || options
@@ -56,6 +57,7 @@ class PlaceDep {
auditReport,
legacyBundling,
strictPeerDeps,
+ installLinks,
legacyPeerDeps,
globalStyle,
})
@@ -293,6 +295,7 @@ class PlaceDep {
pkg: dep.package,
resolved: dep.resolved,
integrity: dep.integrity,
+ installLinks: this.installLinks,
legacyPeerDeps: this.legacyPeerDeps,
error: dep.errors[0],
...(dep.overrides ? { overrides: dep.overrides } : {}),