@npmcli/arborist 5.0.6 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -124,6 +124,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
124
124
  globalStyle = false,
125
125
  idealTree = null,
126
126
  includeWorkspaceRoot = false,
127
+ installLinks = false,
127
128
  legacyPeerDeps = false,
128
129
  packageLock = true,
129
130
  strictPeerDeps = false,
@@ -135,6 +136,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
135
136
  this[_strictPeerDeps] = !!strictPeerDeps
136
137
 
137
138
  this.idealTree = idealTree
139
+ this.installLinks = installLinks
138
140
  this.legacyPeerDeps = legacyPeerDeps
139
141
 
140
142
  this[_usePackageLock] = packageLock
@@ -410,6 +412,7 @@ Try using the package name instead, e.g:
410
412
  peer: false,
411
413
  optional: false,
412
414
  global: this[_global],
415
+ installLinks: this.installLinks,
413
416
  legacyPeerDeps: this.legacyPeerDeps,
414
417
  loadOverrides: true,
415
418
  })
@@ -424,6 +427,7 @@ Try using the package name instead, e.g:
424
427
  peer: false,
425
428
  optional: false,
426
429
  global: this[_global],
430
+ installLinks: this.installLinks,
427
431
  legacyPeerDeps: this.legacyPeerDeps,
428
432
  root,
429
433
  })
@@ -992,6 +996,7 @@ This is a one-time fix-up, please be patient...
992
996
  preferDedupe: this[_preferDedupe],
993
997
  legacyBundling: this[_legacyBundling],
994
998
  strictPeerDeps: this[_strictPeerDeps],
999
+ installLinks: this.installLinks,
995
1000
  legacyPeerDeps: this.legacyPeerDeps,
996
1001
  globalStyle: this[_globalStyle],
997
1002
  }))
@@ -1151,6 +1156,7 @@ This is a one-time fix-up, please be patient...
1151
1156
  const vr = new Node({
1152
1157
  path: node.realpath,
1153
1158
  sourceReference: node,
1159
+ installLinks: this.installLinks,
1154
1160
  legacyPeerDeps: this.legacyPeerDeps,
1155
1161
  overrides: node.overrides,
1156
1162
  })
@@ -1268,17 +1274,18 @@ This is a one-time fix-up, please be patient...
1268
1274
  // the object so it doesn't get mutated.
1269
1275
  // Don't bother to load the manifest for link deps, because the target
1270
1276
  // might be within another package that doesn't exist yet.
1271
- const { legacyPeerDeps } = this
1277
+ const { installLinks, legacyPeerDeps } = this
1278
+ const isWorkspace = this.idealTree.workspaces && this.idealTree.workspaces.has(spec.name)
1272
1279
 
1273
- // spec is a directory, link it
1274
- if (spec.type === 'directory') {
1280
+ // spec is a directory, link it unless installLinks is set or it's a workspace
1281
+ if (spec.type === 'directory' && (isWorkspace || !installLinks)) {
1275
1282
  return this[_linkFromSpec](name, spec, parent, edge)
1276
1283
  }
1277
1284
 
1278
1285
  // if the spec matches a workspace name, then see if the workspace node will
1279
1286
  // satisfy the edge. if it does, we return the workspace node to make sure it
1280
1287
  // takes priority.
1281
- if (this.idealTree.workspaces && this.idealTree.workspaces.has(spec.name)) {
1288
+ if (isWorkspace) {
1282
1289
  const existingNode = this.idealTree.edgesOut.get(spec.name).to
1283
1290
  if (existingNode && existingNode.isWorkspace && existingNode.satisfies(edge)) {
1284
1291
  return edge.to
@@ -1288,7 +1295,7 @@ This is a one-time fix-up, please be patient...
1288
1295
  // spec isn't a directory, and either isn't a workspace or the workspace we have
1289
1296
  // doesn't satisfy the edge. try to fetch a manifest and build a node from that.
1290
1297
  return this[_fetchManifest](spec)
1291
- .then(pkg => new Node({ name, pkg, parent, legacyPeerDeps }), error => {
1298
+ .then(pkg => new Node({ name, pkg, parent, installLinks, legacyPeerDeps }), error => {
1292
1299
  error.requiredBy = edge.from.location || '.'
1293
1300
 
1294
1301
  // failed to load the spec, either because of enotarget or
@@ -1298,6 +1305,7 @@ This is a one-time fix-up, please be patient...
1298
1305
  name,
1299
1306
  parent,
1300
1307
  error,
1308
+ installLinks,
1301
1309
  legacyPeerDeps,
1302
1310
  })
1303
1311
  this[_loadFailures].add(n)
@@ -1307,9 +1315,9 @@ This is a one-time fix-up, please be patient...
1307
1315
 
1308
1316
  [_linkFromSpec] (name, spec, parent, edge) {
1309
1317
  const realpath = spec.fetchSpec
1310
- const { legacyPeerDeps } = this
1318
+ const { installLinks, legacyPeerDeps } = this
1311
1319
  return rpj(realpath + '/package.json').catch(() => ({})).then(pkg => {
1312
- const link = new Link({ name, parent, realpath, pkg, legacyPeerDeps })
1320
+ const link = new Link({ name, parent, realpath, pkg, installLinks, legacyPeerDeps })
1313
1321
  this[_linkNodes].add(link)
1314
1322
  return link
1315
1323
  })
@@ -283,6 +283,7 @@ module.exports = cls => class ActualLoader extends cls {
283
283
  .then(pkg => [pkg, null], error => [null, error])
284
284
  .then(([pkg, error]) => {
285
285
  return this[normalize(path) === real ? _newNode : _newLink]({
286
+ installLinks: this.installLinks,
286
287
  legacyPeerDeps: this.legacyPeerDeps,
287
288
  path,
288
289
  realpath: real,
@@ -278,6 +278,7 @@ module.exports = cls => class VirtualLoader extends cls {
278
278
  const peer = sw.peer
279
279
 
280
280
  const node = new Node({
281
+ installLinks: this.installLinks,
281
282
  legacyPeerDeps: this.legacyPeerDeps,
282
283
  root: this.virtualTree,
283
284
  path,
@@ -304,6 +305,7 @@ module.exports = cls => class VirtualLoader extends cls {
304
305
  [loadLink] (location, targetLoc, target, meta) {
305
306
  const path = resolve(this.path, location)
306
307
  const link = new Link({
308
+ installLinks: this.installLinks,
307
309
  legacyPeerDeps: this.legacyPeerDeps,
308
310
  path,
309
311
  realpath: resolve(this.path, targetLoc),
package/lib/dep-valid.js CHANGED
@@ -53,9 +53,7 @@ const depValid = (child, requested, requestor) => {
53
53
  return semver.satisfies(child.version, requested.fetchSpec, true)
54
54
 
55
55
  case 'directory':
56
- // directory must be a link to the specified folder
57
- return !!child.isLink &&
58
- relative(child.realpath, requested.fetchSpec) === ''
56
+ return linkValid(child, requested, requestor)
59
57
 
60
58
  case 'file':
61
59
  return tarballValid(child, requested, requestor)
@@ -108,6 +106,18 @@ const depValid = (child, requested, requestor) => {
108
106
  return false
109
107
  }
110
108
 
109
+ const linkValid = (child, requested, requestor) => {
110
+ const isLink = !!child.isLink
111
+ // if we're installing links and the node is a link, then it's invalid because we want
112
+ // a real node to be there
113
+ if (requestor.installLinks) {
114
+ return !isLink
115
+ }
116
+
117
+ // directory must be a link to the specified folder
118
+ return isLink && relative(child.realpath, requested.fetchSpec) === ''
119
+ }
120
+
111
121
  const tarballValid = (child, requested, requestor) => {
112
122
  if (child.isLink) {
113
123
  return false
package/lib/node.js CHANGED
@@ -86,6 +86,7 @@ class Node {
86
86
  name,
87
87
  children,
88
88
  fsChildren,
89
+ installLinks = false,
89
90
  legacyPeerDeps = false,
90
91
  linksIn,
91
92
  hasShrinkwrap,
@@ -152,6 +153,7 @@ class Node {
152
153
  }
153
154
  this.integrity = integrity || pkg._integrity || null
154
155
  this.hasShrinkwrap = hasShrinkwrap || pkg._hasShrinkwrap || false
156
+ this.installLinks = installLinks
155
157
  this.legacyPeerDeps = legacyPeerDeps
156
158
 
157
159
  this.children = new CaseInsensitiveMap()
@@ -1149,6 +1151,9 @@ class Node {
1149
1151
  for (const kid of node.children.values()) {
1150
1152
  kid.parent = this
1151
1153
  }
1154
+ if (node.isLink && node.target) {
1155
+ node.target.root = null
1156
+ }
1152
1157
  }
1153
1158
 
1154
1159
  if (!node.isRoot) {
package/lib/place-dep.js CHANGED
@@ -45,6 +45,7 @@ class PlaceDep {
45
45
  auditReport,
46
46
  legacyBundling,
47
47
  strictPeerDeps,
48
+ installLinks,
48
49
  legacyPeerDeps,
49
50
  globalStyle,
50
51
  } = parent || options
@@ -56,6 +57,7 @@ class PlaceDep {
56
57
  auditReport,
57
58
  legacyBundling,
58
59
  strictPeerDeps,
60
+ installLinks,
59
61
  legacyPeerDeps,
60
62
  globalStyle,
61
63
  })
@@ -293,6 +295,7 @@ class PlaceDep {
293
295
  pkg: dep.package,
294
296
  resolved: dep.resolved,
295
297
  integrity: dep.integrity,
298
+ installLinks: this.installLinks,
296
299
  legacyPeerDeps: this.legacyPeerDeps,
297
300
  error: dep.errors[0],
298
301
  ...(dep.overrides ? { overrides: dep.overrides } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/arborist",
3
- "version": "5.0.6",
3
+ "version": "5.1.0",
4
4
  "description": "Manage node_modules trees",
5
5
  "dependencies": {
6
6
  "@isaacs/string-locale-compare": "^1.1.0",