@yarnpkg/nm 3.0.1 → 4.0.0-rc.3
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.
- package/lib/buildNodeModulesTree.js +5 -15
- package/lib/hoist.js +28 -11
- package/package.json +7 -6
|
@@ -273,7 +273,7 @@ const buildPackageTree = (pnp, options) => {
|
|
|
273
273
|
allDependencies.set(`${workspaceLocator.name}${WORKSPACE_NAME_SUFFIX}`, workspaceLocator.reference);
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
|
-
if (pkg !== parentPkg || pkg.linkType !== LinkType.SOFT || !options.selfReferencesByCwd || options.selfReferencesByCwd.get(parentRelativeCwd))
|
|
276
|
+
if (pkg !== parentPkg || pkg.linkType !== LinkType.SOFT || (!isExternalSoftLinkPackage && (!options.selfReferencesByCwd || options.selfReferencesByCwd.get(parentRelativeCwd))))
|
|
277
277
|
parent.dependencies.add(node);
|
|
278
278
|
const isWorkspaceDependency = locator !== topLocator && pkg.linkType === LinkType.SOFT && !locator.name.endsWith(WORKSPACE_NAME_SUFFIX) && !isExternalSoftLinkPackage;
|
|
279
279
|
if (!isSeen && !isWorkspaceDependency) {
|
|
@@ -356,22 +356,14 @@ function getTargetLocatorPath(locator, pnp, options) {
|
|
|
356
356
|
const info = pnp.getPackageInformation(pkgLocator);
|
|
357
357
|
if (info === null)
|
|
358
358
|
throw new Error(`Assertion failed: Expected the package to be registered`);
|
|
359
|
-
|
|
360
|
-
let target;
|
|
361
|
-
if (options.pnpifyFs) {
|
|
359
|
+
return options.pnpifyFs
|
|
362
360
|
// In case of pnpifyFs we represent modules as symlinks to archives in NodeModulesFS
|
|
363
361
|
// `/home/user/project/foo` is a symlink to `/home/user/project/.yarn/.cache/foo.zip/node_modules/foo`
|
|
364
362
|
// To make this fs layout work with legacy tools we make
|
|
365
363
|
// `/home/user/project/.yarn/.cache/foo.zip/node_modules/foo/node_modules` (which normally does not exist inside archive) a symlink to:
|
|
366
364
|
// `/home/user/project/node_modules/foo/node_modules`, so that the tools were able to access it
|
|
367
|
-
target
|
|
368
|
-
linkType
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
target = getRealPackageLocation(info, locator, pnp);
|
|
372
|
-
linkType = info.linkType;
|
|
373
|
-
}
|
|
374
|
-
return { linkType, target };
|
|
365
|
+
? { linkType: LinkType.SOFT, target: fslib_1.npath.toPortablePath(info.packageLocation) }
|
|
366
|
+
: { linkType: info.linkType, target: getRealPackageLocation(info, locator, pnp) };
|
|
375
367
|
}
|
|
376
368
|
/**
|
|
377
369
|
* Converts hoisted tree to node modules map
|
|
@@ -449,8 +441,7 @@ const populateNodeModulesTree = (pnp, hoistedTree, options) => {
|
|
|
449
441
|
tree.set(nodeModulesLocation, leafNode);
|
|
450
442
|
const segments = nodeModulesLocation.split(`/`);
|
|
451
443
|
const nodeModulesIdx = segments.indexOf(NODE_MODULES);
|
|
452
|
-
let segCount = segments.length - 1;
|
|
453
|
-
while (nodeModulesIdx >= 0 && segCount > nodeModulesIdx) {
|
|
444
|
+
for (let segCount = segments.length - 1; nodeModulesIdx >= 0 && segCount > nodeModulesIdx; segCount--) {
|
|
454
445
|
const dirPath = fslib_1.npath.toPortablePath(segments.slice(0, segCount).join(fslib_1.ppath.sep));
|
|
455
446
|
const targetDir = (0, fslib_1.toFilename)(segments[segCount]);
|
|
456
447
|
const subdirs = tree.get(dirPath);
|
|
@@ -465,7 +456,6 @@ const populateNodeModulesTree = (pnp, hoistedTree, options) => {
|
|
|
465
456
|
subdirs.dirList.add(targetDir);
|
|
466
457
|
}
|
|
467
458
|
}
|
|
468
|
-
segCount--;
|
|
469
459
|
}
|
|
470
460
|
}
|
|
471
461
|
buildTree(dep, leafNode.linkType === LinkType.SOFT ? leafNode.target : nodeModulesLocation, nodePath);
|
package/lib/hoist.js
CHANGED
|
@@ -281,7 +281,10 @@ const hoistTo = (tree, rootNodePath, rootNodePathLocators, parentShadowedNodes,
|
|
|
281
281
|
seenNodes.add(rootNode);
|
|
282
282
|
const preferenceMap = buildPreferenceMap(rootNode);
|
|
283
283
|
const hoistIdentMap = getHoistIdentMap(rootNode, preferenceMap);
|
|
284
|
-
const usedDependencies = tree == rootNode ? new Map() :
|
|
284
|
+
const usedDependencies = tree == rootNode ? new Map() :
|
|
285
|
+
(options.fastLookupPossible
|
|
286
|
+
? getZeroRoundUsedDependencies(rootNodePath)
|
|
287
|
+
: getUsedDependencies(rootNodePath));
|
|
285
288
|
let wasStateChanged;
|
|
286
289
|
let anotherRoundNeeded = false;
|
|
287
290
|
let isGraphChanged = false;
|
|
@@ -316,6 +319,14 @@ const hoistTo = (tree, rootNodePath, rootNodePathLocators, parentShadowedNodes,
|
|
|
316
319
|
}
|
|
317
320
|
return { anotherRoundNeeded, isGraphChanged };
|
|
318
321
|
};
|
|
322
|
+
const hasUnhoistedDependencies = (node) => {
|
|
323
|
+
for (const [subName, subDependency] of node.dependencies) {
|
|
324
|
+
if (!node.peerNames.has(subName) && subDependency.ident !== node.ident) {
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return false;
|
|
329
|
+
};
|
|
319
330
|
const getNodeHoistInfo = (rootNode, rootNodePathLocators, nodePath, node, usedDependencies, hoistIdents, hoistIdentMap, shadowedNodes, { outputReason, fastLookupPossible }) => {
|
|
320
331
|
let reasonRoot;
|
|
321
332
|
let reason = null;
|
|
@@ -334,8 +345,8 @@ const getNodeHoistInfo = (rootNode, rootNodePathLocators, nodePath, node, usedDe
|
|
|
334
345
|
reason = `- workspace`;
|
|
335
346
|
}
|
|
336
347
|
}
|
|
337
|
-
if (isHoistable) {
|
|
338
|
-
isHoistable = node
|
|
348
|
+
if (isHoistable && node.dependencyKind === HoisterDependencyKind.EXTERNAL_SOFT_LINK) {
|
|
349
|
+
isHoistable = !hasUnhoistedDependencies(node);
|
|
339
350
|
if (outputReason && !isHoistable) {
|
|
340
351
|
reason = `- external soft link with unhoisted dependencies`;
|
|
341
352
|
}
|
|
@@ -427,7 +438,7 @@ const getNodeHoistInfo = (rootNode, rootNodePathLocators, nodePath, node, usedDe
|
|
|
427
438
|
}
|
|
428
439
|
if (isHoistable && !fastLookupPossible) {
|
|
429
440
|
for (const origDep of node.hoistedDependencies.values()) {
|
|
430
|
-
const usedDep = usedDependencies.get(origDep.name);
|
|
441
|
+
const usedDep = usedDependencies.get(origDep.name) || rootNode.dependencies.get(origDep.name);
|
|
431
442
|
if (!usedDep || origDep.ident !== usedDep.ident) {
|
|
432
443
|
isHoistable = false;
|
|
433
444
|
if (outputReason)
|
|
@@ -443,6 +454,7 @@ const getNodeHoistInfo = (rootNode, rootNodePathLocators, nodePath, node, usedDe
|
|
|
443
454
|
return { isHoistable: isHoistable ? Hoistable.YES : Hoistable.NO, reason };
|
|
444
455
|
}
|
|
445
456
|
};
|
|
457
|
+
const getAliasedLocator = (node) => `${node.name}@${node.locator}`;
|
|
446
458
|
/**
|
|
447
459
|
* Performs actual graph transformation, by hoisting packages to the root node.
|
|
448
460
|
*
|
|
@@ -457,10 +469,11 @@ const hoistGraph = (tree, rootNodePath, rootNodePathLocators, usedDependencies,
|
|
|
457
469
|
const seenNodes = new Set();
|
|
458
470
|
let anotherRoundNeeded = false;
|
|
459
471
|
let isGraphChanged = false;
|
|
460
|
-
const hoistNodeDependencies = (nodePath, locatorPath, parentNode, newNodes) => {
|
|
472
|
+
const hoistNodeDependencies = (nodePath, locatorPath, aliasedLocatorPath, parentNode, newNodes) => {
|
|
461
473
|
if (seenNodes.has(parentNode))
|
|
462
474
|
return;
|
|
463
|
-
const nextLocatorPath = [...locatorPath, parentNode
|
|
475
|
+
const nextLocatorPath = [...locatorPath, getAliasedLocator(parentNode)];
|
|
476
|
+
const nextAliasedLocatorPath = [...aliasedLocatorPath, getAliasedLocator(parentNode)];
|
|
464
477
|
const dependantTree = new Map();
|
|
465
478
|
const hoistInfos = new Map();
|
|
466
479
|
for (const subDependency of getSortedRegularDependencies(parentNode)) {
|
|
@@ -487,12 +500,14 @@ const hoistGraph = (tree, rootNodePath, rootNodePathLocators, usedDependencies,
|
|
|
487
500
|
for (const [node, hoistInfo] of hoistInfos)
|
|
488
501
|
if (hoistInfo.isHoistable === Hoistable.NO)
|
|
489
502
|
addUnhoistableNode(node, hoistInfo, hoistInfo.reason);
|
|
503
|
+
let wereNodesHoisted = false;
|
|
490
504
|
for (const node of hoistInfos.keys()) {
|
|
491
505
|
if (!unhoistableNodes.has(node)) {
|
|
492
506
|
isGraphChanged = true;
|
|
493
507
|
const shadowedNames = parentShadowedNodes.get(parentNode);
|
|
494
508
|
if (shadowedNames && shadowedNames.has(node.name))
|
|
495
509
|
anotherRoundNeeded = true;
|
|
510
|
+
wereNodesHoisted = true;
|
|
496
511
|
parentNode.dependencies.delete(node.name);
|
|
497
512
|
parentNode.hoistedDependencies.set(node.name, node);
|
|
498
513
|
parentNode.reasons.delete(node.name);
|
|
@@ -522,6 +537,8 @@ const hoistGraph = (tree, rootNodePath, rootNodePathLocators, usedDependencies,
|
|
|
522
537
|
}
|
|
523
538
|
}
|
|
524
539
|
}
|
|
540
|
+
if (parentNode.dependencyKind === HoisterDependencyKind.EXTERNAL_SOFT_LINK && wereNodesHoisted)
|
|
541
|
+
anotherRoundNeeded = true;
|
|
525
542
|
if (options.check) {
|
|
526
543
|
const checkLog = selfCheck(tree);
|
|
527
544
|
if (checkLog) {
|
|
@@ -535,10 +552,10 @@ const hoistGraph = (tree, rootNodePath, rootNodePathLocators, usedDependencies,
|
|
|
535
552
|
const hoistableIdent = hoistIdents.get(node.name);
|
|
536
553
|
if ((hoistableIdent === node.ident || !parentNode.reasons.has(node.name)) && hoistInfo.isHoistable !== Hoistable.YES)
|
|
537
554
|
parentNode.reasons.set(node.name, hoistInfo.reason);
|
|
538
|
-
if (!node.isHoistBorder &&
|
|
555
|
+
if (!node.isHoistBorder && nextAliasedLocatorPath.indexOf(getAliasedLocator(node)) < 0) {
|
|
539
556
|
seenNodes.add(parentNode);
|
|
540
557
|
const decoupledNode = decoupleGraphNode(parentNode, node);
|
|
541
|
-
hoistNodeDependencies([...nodePath, parentNode],
|
|
558
|
+
hoistNodeDependencies([...nodePath, parentNode], nextLocatorPath, nextAliasedLocatorPath, decoupledNode, nextNewNodes);
|
|
542
559
|
seenNodes.delete(parentNode);
|
|
543
560
|
}
|
|
544
561
|
}
|
|
@@ -546,6 +563,7 @@ const hoistGraph = (tree, rootNodePath, rootNodePathLocators, usedDependencies,
|
|
|
546
563
|
};
|
|
547
564
|
let newNodes;
|
|
548
565
|
let nextNewNodes = new Set(getSortedRegularDependencies(rootNode));
|
|
566
|
+
const aliasedRootNodePathLocators = Array.from(rootNodePath).map(x => getAliasedLocator(x));
|
|
549
567
|
do {
|
|
550
568
|
newNodes = nextNewNodes;
|
|
551
569
|
nextNewNodes = new Set();
|
|
@@ -553,7 +571,7 @@ const hoistGraph = (tree, rootNodePath, rootNodePathLocators, usedDependencies,
|
|
|
553
571
|
if (dep.locator === rootNode.locator || dep.isHoistBorder)
|
|
554
572
|
continue;
|
|
555
573
|
const decoupledDependency = decoupleGraphNode(rootNode, dep);
|
|
556
|
-
hoistNodeDependencies([], Array.from(rootNodePathLocators), decoupledDependency, nextNewNodes);
|
|
574
|
+
hoistNodeDependencies([], Array.from(rootNodePathLocators), aliasedRootNodePathLocators, decoupledDependency, nextNewNodes);
|
|
557
575
|
}
|
|
558
576
|
} while (nextNewNodes.size > 0);
|
|
559
577
|
return { anotherRoundNeeded, isGraphChanged };
|
|
@@ -828,8 +846,7 @@ const dumpDepTree = (tree) => {
|
|
|
828
846
|
if (!pkg.peerNames.has(dep.name) && dep !== pkg) {
|
|
829
847
|
const reason = pkg.reasons.get(dep.name);
|
|
830
848
|
const identName = getIdentName(dep.locator);
|
|
831
|
-
|
|
832
|
-
str += `${prefix}${idx < dependencies.length - 1 ? `├─` : `└─`}${(parents.has(dep) ? `>` : ``) + (identName !== dep.name ? `a:${dep.name}:` : ``) + prettyPrintLocator(dep.locator) + (reason ? ` ${reason}` : ``) + (dep !== pkg && hoistedFrom.length > 0 ? `, hoisted from: ${hoistedFrom.join(`, `)}` : ``)}\n`;
|
|
849
|
+
str += `${prefix}${idx < dependencies.length - 1 ? `├─` : `└─`}${(parents.has(dep) ? `>` : ``) + (identName !== dep.name ? `a:${dep.name}:` : ``) + prettyPrintLocator(dep.locator) + (reason ? ` ${reason}` : ``)}\n`;
|
|
833
850
|
str += dumpPackage(dep, parents, `${prefix}${idx < dependencies.length - 1 ? `│ ` : ` `}`);
|
|
834
851
|
}
|
|
835
852
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarnpkg/nm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.3",
|
|
4
4
|
"license": "BSD-2-Clause",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@yarnpkg/core": "^
|
|
10
|
-
"@yarnpkg/fslib": "^
|
|
9
|
+
"@yarnpkg/core": "^4.0.0-rc.3",
|
|
10
|
+
"@yarnpkg/fslib": "^3.0.0-rc.3"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@yarnpkg/pnp": "^
|
|
13
|
+
"@yarnpkg/pnp": "^4.0.0-rc.3"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"postpack": "rm -rf lib",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"directory": "packages/yarnpkg-nm"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
35
|
-
}
|
|
34
|
+
"node": ">=14.15.0"
|
|
35
|
+
},
|
|
36
|
+
"stableVersion": "3.0.1"
|
|
36
37
|
}
|