@yarnpkg/nm 3.0.3 → 3.1.1
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.d.ts +6 -6
- package/lib/buildNodeModulesTree.js +11 -18
- package/lib/hoist.d.ts +5 -5
- package/lib/hoist.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -1
- package/package.json +4 -6
|
@@ -10,10 +10,10 @@ export declare enum NodeModulesHoistingLimits {
|
|
|
10
10
|
DEPENDENCIES = "dependencies",
|
|
11
11
|
NONE = "none"
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type NodeModulesBaseNode = {
|
|
14
14
|
dirList: Set<Filename>;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type NodeModulesPackageNode = {
|
|
17
17
|
locator: LocatorKey;
|
|
18
18
|
target: PortablePath;
|
|
19
19
|
linkType: LinkType;
|
|
@@ -30,8 +30,8 @@ export declare type NodeModulesPackageNode = {
|
|
|
30
30
|
* /home/user/project/node_modules/foo -> {target: '/home/user/project/.yarn/.cache/foo.zip/node_modules/foo', linkType: 'HARD'}
|
|
31
31
|
* /home/user/project/node_modules/bar -> {target: '/home/user/project/packages/bar', linkType: 'SOFT'}
|
|
32
32
|
*/
|
|
33
|
-
export
|
|
34
|
-
export
|
|
33
|
+
export type NodeModulesTree = Map<PortablePath, NodeModulesBaseNode | NodeModulesPackageNode>;
|
|
34
|
+
export type NodeModulesTreeErrors = Array<{
|
|
35
35
|
messageName: MessageName;
|
|
36
36
|
text: string;
|
|
37
37
|
}>;
|
|
@@ -43,7 +43,7 @@ export interface NodeModulesTreeOptions {
|
|
|
43
43
|
project?: Project;
|
|
44
44
|
}
|
|
45
45
|
/** Package locator key for usage inside maps */
|
|
46
|
-
|
|
46
|
+
type LocatorKey = string;
|
|
47
47
|
/**
|
|
48
48
|
* Returns path to archive, if package location is inside the archive.
|
|
49
49
|
*
|
|
@@ -65,7 +65,7 @@ export declare const buildNodeModulesTree: (pnp: PnpApi, options: NodeModulesTre
|
|
|
65
65
|
errors: NodeModulesTreeErrors;
|
|
66
66
|
preserveSymlinksRequired: boolean;
|
|
67
67
|
};
|
|
68
|
-
export
|
|
68
|
+
export type NodeModulesLocatorMap = Map<LocatorKey, {
|
|
69
69
|
target: PortablePath;
|
|
70
70
|
linkType: LinkType;
|
|
71
71
|
locations: Array<PortablePath>;
|
|
@@ -12,13 +12,13 @@ var LinkType;
|
|
|
12
12
|
(function (LinkType) {
|
|
13
13
|
LinkType["HARD"] = "HARD";
|
|
14
14
|
LinkType["SOFT"] = "SOFT";
|
|
15
|
-
})(LinkType
|
|
15
|
+
})(LinkType || (exports.LinkType = LinkType = {}));
|
|
16
16
|
var NodeModulesHoistingLimits;
|
|
17
17
|
(function (NodeModulesHoistingLimits) {
|
|
18
18
|
NodeModulesHoistingLimits["WORKSPACES"] = "workspaces";
|
|
19
19
|
NodeModulesHoistingLimits["DEPENDENCIES"] = "dependencies";
|
|
20
20
|
NodeModulesHoistingLimits["NONE"] = "none";
|
|
21
|
-
})(NodeModulesHoistingLimits
|
|
21
|
+
})(NodeModulesHoistingLimits || (exports.NodeModulesHoistingLimits = NodeModulesHoistingLimits = {}));
|
|
22
22
|
/** node_modules path segment */
|
|
23
23
|
const NODE_MODULES = `node_modules`;
|
|
24
24
|
/**
|
|
@@ -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
|
|
@@ -410,9 +402,11 @@ const populateNodeModulesTree = (pnp, hoistedTree, options) => {
|
|
|
410
402
|
if (seenNodes.has(pkg))
|
|
411
403
|
return;
|
|
412
404
|
seenNodes.add(pkg);
|
|
405
|
+
const pkgReferences = Array.from(pkg.references).sort().join(`#`);
|
|
413
406
|
for (const dep of pkg.dependencies) {
|
|
407
|
+
const depReferences = Array.from(dep.references).sort().join(`#`);
|
|
414
408
|
// We do not want self-references in node_modules, since they confuse existing tools
|
|
415
|
-
if (dep === pkg)
|
|
409
|
+
if (dep.identName === pkg.identName && depReferences === pkgReferences)
|
|
416
410
|
continue;
|
|
417
411
|
const references = Array.from(dep.references).sort();
|
|
418
412
|
const locator = { name: dep.identName, reference: references[0] };
|
|
@@ -430,7 +424,8 @@ const populateNodeModulesTree = (pnp, hoistedTree, options) => {
|
|
|
430
424
|
const workspace = options.project.workspacesByCwd.get(leafNode.target.slice(0, -1));
|
|
431
425
|
isAnonymousWorkspace = !!(workspace && !workspace.manifest.name);
|
|
432
426
|
}
|
|
433
|
-
|
|
427
|
+
const isCircularSymlink = leafNode.linkType === LinkType.SOFT && nodeModulesLocation.startsWith(leafNode.target);
|
|
428
|
+
if (!dep.name.endsWith(WORKSPACE_NAME_SUFFIX) && !isAnonymousWorkspace && !isCircularSymlink) {
|
|
434
429
|
const prevNode = tree.get(nodeModulesLocation);
|
|
435
430
|
if (prevNode) {
|
|
436
431
|
if (prevNode.dirList) {
|
|
@@ -449,8 +444,7 @@ const populateNodeModulesTree = (pnp, hoistedTree, options) => {
|
|
|
449
444
|
tree.set(nodeModulesLocation, leafNode);
|
|
450
445
|
const segments = nodeModulesLocation.split(`/`);
|
|
451
446
|
const nodeModulesIdx = segments.indexOf(NODE_MODULES);
|
|
452
|
-
let segCount = segments.length - 1;
|
|
453
|
-
while (nodeModulesIdx >= 0 && segCount > nodeModulesIdx) {
|
|
447
|
+
for (let segCount = segments.length - 1; nodeModulesIdx >= 0 && segCount > nodeModulesIdx; segCount--) {
|
|
454
448
|
const dirPath = fslib_1.npath.toPortablePath(segments.slice(0, segCount).join(fslib_1.ppath.sep));
|
|
455
449
|
const targetDir = (0, fslib_1.toFilename)(segments[segCount]);
|
|
456
450
|
const subdirs = tree.get(dirPath);
|
|
@@ -465,7 +459,6 @@ const populateNodeModulesTree = (pnp, hoistedTree, options) => {
|
|
|
465
459
|
subdirs.dirList.add(targetDir);
|
|
466
460
|
}
|
|
467
461
|
}
|
|
468
|
-
segCount--;
|
|
469
462
|
}
|
|
470
463
|
}
|
|
471
464
|
buildTree(dep, leafNode.linkType === LinkType.SOFT ? leafNode.target : nodeModulesLocation, nodePath);
|
package/lib/hoist.d.ts
CHANGED
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
* the next node as current tree root and run the algorithm again
|
|
46
46
|
* until you run out of candidates for current tree root.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
type PackageName = string;
|
|
49
49
|
export declare enum HoisterDependencyKind {
|
|
50
50
|
REGULAR = 0,
|
|
51
51
|
WORKSPACE = 1,
|
|
52
52
|
EXTERNAL_SOFT_LINK = 2
|
|
53
53
|
}
|
|
54
|
-
export
|
|
54
|
+
export type HoisterTree = {
|
|
55
55
|
name: PackageName;
|
|
56
56
|
identName: PackageName;
|
|
57
57
|
reference: string;
|
|
@@ -60,13 +60,13 @@ export declare type HoisterTree = {
|
|
|
60
60
|
hoistPriority?: number;
|
|
61
61
|
dependencyKind?: HoisterDependencyKind;
|
|
62
62
|
};
|
|
63
|
-
export
|
|
63
|
+
export type HoisterResult = {
|
|
64
64
|
name: PackageName;
|
|
65
65
|
identName: PackageName;
|
|
66
66
|
references: Set<string>;
|
|
67
67
|
dependencies: Set<HoisterResult>;
|
|
68
68
|
};
|
|
69
|
-
|
|
69
|
+
type Locator = string;
|
|
70
70
|
declare enum DebugLevel {
|
|
71
71
|
NONE = -1,
|
|
72
72
|
PERF = 0,
|
|
@@ -74,7 +74,7 @@ declare enum DebugLevel {
|
|
|
74
74
|
REASONS = 2,
|
|
75
75
|
INTENSIVE_CHECK = 9
|
|
76
76
|
}
|
|
77
|
-
export
|
|
77
|
+
export type HoistOptions = {
|
|
78
78
|
/** Runs self-checks after hoisting is finished */
|
|
79
79
|
check?: boolean;
|
|
80
80
|
/** Debug level */
|
package/lib/hoist.js
CHANGED
|
@@ -6,7 +6,7 @@ var HoisterDependencyKind;
|
|
|
6
6
|
HoisterDependencyKind[HoisterDependencyKind["REGULAR"] = 0] = "REGULAR";
|
|
7
7
|
HoisterDependencyKind[HoisterDependencyKind["WORKSPACE"] = 1] = "WORKSPACE";
|
|
8
8
|
HoisterDependencyKind[HoisterDependencyKind["EXTERNAL_SOFT_LINK"] = 2] = "EXTERNAL_SOFT_LINK";
|
|
9
|
-
})(HoisterDependencyKind
|
|
9
|
+
})(HoisterDependencyKind || (exports.HoisterDependencyKind = HoisterDependencyKind = {}));
|
|
10
10
|
var Hoistable;
|
|
11
11
|
(function (Hoistable) {
|
|
12
12
|
Hoistable[Hoistable["YES"] = 0] = "YES";
|
package/lib/index.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export type { NodeModulesBaseNode, NodeModulesPackageNode, NodeModulesTreeOption
|
|
|
4
4
|
export { NodeModulesHoistingLimits, } from './buildNodeModulesTree';
|
|
5
5
|
export { buildNodeModulesTree, buildLocatorMap, getArchivePath, };
|
|
6
6
|
export type { NodeModulesLocatorMap };
|
|
7
|
+
export type { HoisterTree, HoisterResult } from './hoist';
|
|
8
|
+
export { hoist, HoisterDependencyKind } from './hoist';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getArchivePath = exports.buildLocatorMap = exports.buildNodeModulesTree = exports.NodeModulesHoistingLimits = void 0;
|
|
3
|
+
exports.HoisterDependencyKind = exports.hoist = exports.getArchivePath = exports.buildLocatorMap = exports.buildNodeModulesTree = exports.NodeModulesHoistingLimits = void 0;
|
|
4
4
|
const buildNodeModulesTree_1 = require("./buildNodeModulesTree");
|
|
5
5
|
Object.defineProperty(exports, "getArchivePath", { enumerable: true, get: function () { return buildNodeModulesTree_1.getArchivePath; } });
|
|
6
6
|
const buildNodeModulesTree_2 = require("./buildNodeModulesTree");
|
|
@@ -8,3 +8,6 @@ Object.defineProperty(exports, "buildNodeModulesTree", { enumerable: true, get:
|
|
|
8
8
|
Object.defineProperty(exports, "buildLocatorMap", { enumerable: true, get: function () { return buildNodeModulesTree_2.buildLocatorMap; } });
|
|
9
9
|
var buildNodeModulesTree_3 = require("./buildNodeModulesTree");
|
|
10
10
|
Object.defineProperty(exports, "NodeModulesHoistingLimits", { enumerable: true, get: function () { return buildNodeModulesTree_3.NodeModulesHoistingLimits; } });
|
|
11
|
+
var hoist_1 = require("./hoist");
|
|
12
|
+
Object.defineProperty(exports, "hoist", { enumerable: true, get: function () { return hoist_1.hoist; } });
|
|
13
|
+
Object.defineProperty(exports, "HoisterDependencyKind", { enumerable: true, get: function () { return hoist_1.HoisterDependencyKind; } });
|
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarnpkg/nm",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
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": "^3.
|
|
10
|
-
"@yarnpkg/fslib": "^2.
|
|
11
|
-
|
|
12
|
-
"devDependencies": {
|
|
13
|
-
"@yarnpkg/pnp": "^3.2.1"
|
|
9
|
+
"@yarnpkg/core": "^3.6.0",
|
|
10
|
+
"@yarnpkg/fslib": "^2.10.3",
|
|
11
|
+
"@yarnpkg/pnp": "^3.3.6"
|
|
14
12
|
},
|
|
15
13
|
"scripts": {
|
|
16
14
|
"postpack": "rm -rf lib",
|