@yarnpkg/nm 3.0.0 → 3.0.1-rc.12

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.
@@ -73,7 +73,15 @@ const buildLocatorMap = (nodeModulesTree) => {
73
73
  val.locations = val.locations.sort((loc1, loc2) => {
74
74
  const len1 = loc1.split(fslib_1.ppath.delimiter).length;
75
75
  const len2 = loc2.split(fslib_1.ppath.delimiter).length;
76
- return len1 !== len2 ? len2 - len1 : loc2.localeCompare(loc1);
76
+ if (loc2 === loc1) {
77
+ return 0;
78
+ }
79
+ else if (len1 !== len2) {
80
+ return len2 - len1;
81
+ }
82
+ else {
83
+ return loc2 > loc1 ? 1 : -1;
84
+ }
77
85
  });
78
86
  }
79
87
  return map;
@@ -194,7 +202,7 @@ const buildPackageTree = (pnp, options) => {
194
202
  reference: topLocator.reference,
195
203
  peerNames: topPkg.packagePeers,
196
204
  dependencies: new Set(),
197
- isWorkspace: true,
205
+ dependencyKind: hoist_1.HoisterDependencyKind.WORKSPACE,
198
206
  };
199
207
  const nodes = new Map();
200
208
  const getNodeKey = (name, locator) => `${stringifyLocator(locator)}:${name}`;
@@ -209,7 +217,11 @@ const buildPackageTree = (pnp, options) => {
209
217
  }
210
218
  const isExternalSoftLinkPackage = isExternalSoftLink(pkg, locator, pnp, topPkgPortableLocation);
211
219
  if (!node) {
212
- const isWorkspace = pkg.linkType === LinkType.SOFT && locator.name.endsWith(WORKSPACE_NAME_SUFFIX);
220
+ let dependencyKind = hoist_1.HoisterDependencyKind.REGULAR;
221
+ if (isExternalSoftLinkPackage)
222
+ dependencyKind = hoist_1.HoisterDependencyKind.EXTERNAL_SOFT_LINK;
223
+ else if (pkg.linkType === LinkType.SOFT && locator.name.endsWith(WORKSPACE_NAME_SUFFIX))
224
+ dependencyKind = hoist_1.HoisterDependencyKind.WORKSPACE;
213
225
  node = {
214
226
  name,
215
227
  identName: locator.name,
@@ -217,8 +229,8 @@ const buildPackageTree = (pnp, options) => {
217
229
  dependencies: new Set(),
218
230
  // View peer dependencies as regular dependencies for workspaces
219
231
  // (meeting workspace peer dependency constraints is sometimes hard, sometimes impossible for the nm linker)
220
- peerNames: isWorkspace ? new Set() : pkg.packagePeers,
221
- isWorkspace,
232
+ peerNames: dependencyKind === hoist_1.HoisterDependencyKind.WORKSPACE ? new Set() : pkg.packagePeers,
233
+ dependencyKind,
222
234
  };
223
235
  nodes.set(nodeKey, node);
224
236
  }
@@ -325,7 +337,7 @@ const buildPackageTree = (pnp, options) => {
325
337
  const isHoistBorder = parentHoistingLimits === NodeModulesHoistingLimits.DEPENDENCIES
326
338
  || depHoistingLimits === NodeModulesHoistingLimits.DEPENDENCIES
327
339
  || depHoistingLimits === NodeModulesHoistingLimits.WORKSPACES;
328
- addPackageToTree(stringifyLocator(depLocator) === stringifyLocator(locator) ? name : depName, depPkg, depLocator, node, pkg, allDependencies, relativeDepCwd, isHoistBorder);
340
+ addPackageToTree(depName, depPkg, depLocator, node, pkg, allDependencies, relativeDepCwd, isHoistBorder);
329
341
  }
330
342
  }
331
343
  }
package/lib/hoist.d.ts CHANGED
@@ -46,6 +46,11 @@
46
46
  * until you run out of candidates for current tree root.
47
47
  */
48
48
  declare type PackageName = string;
49
+ export declare enum HoisterDependencyKind {
50
+ REGULAR = 0,
51
+ WORKSPACE = 1,
52
+ EXTERNAL_SOFT_LINK = 2
53
+ }
49
54
  export declare type HoisterTree = {
50
55
  name: PackageName;
51
56
  identName: PackageName;
@@ -53,7 +58,7 @@ export declare type HoisterTree = {
53
58
  dependencies: Set<HoisterTree>;
54
59
  peerNames: Set<PackageName>;
55
60
  hoistPriority?: number;
56
- isWorkspace?: boolean;
61
+ dependencyKind?: HoisterDependencyKind;
57
62
  };
58
63
  export declare type HoisterResult = {
59
64
  name: PackageName;
package/lib/hoist.js CHANGED
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hoist = void 0;
3
+ exports.hoist = exports.HoisterDependencyKind = void 0;
4
+ var HoisterDependencyKind;
5
+ (function (HoisterDependencyKind) {
6
+ HoisterDependencyKind[HoisterDependencyKind["REGULAR"] = 0] = "REGULAR";
7
+ HoisterDependencyKind[HoisterDependencyKind["WORKSPACE"] = 1] = "WORKSPACE";
8
+ HoisterDependencyKind[HoisterDependencyKind["EXTERNAL_SOFT_LINK"] = 2] = "EXTERNAL_SOFT_LINK";
9
+ })(HoisterDependencyKind = exports.HoisterDependencyKind || (exports.HoisterDependencyKind = {}));
4
10
  var Hoistable;
5
11
  (function (Hoistable) {
6
12
  Hoistable[Hoistable["YES"] = 0] = "YES";
@@ -134,7 +140,7 @@ const getUsedDependencies = (rootNodePath) => {
134
140
  const decoupleGraphNode = (parent, node) => {
135
141
  if (node.decoupled)
136
142
  return node;
137
- const { name, references, ident, locator, dependencies, originalDependencies, hoistedDependencies, peerNames, reasons, isHoistBorder, hoistPriority, isWorkspace, hoistedFrom, hoistedTo } = node;
143
+ const { name, references, ident, locator, dependencies, originalDependencies, hoistedDependencies, peerNames, reasons, isHoistBorder, hoistPriority, dependencyKind, hoistedFrom, hoistedTo } = node;
138
144
  // To perform node hoisting from parent node we must clone parent nodes up to the root node,
139
145
  // because some other package in the tree might depend on the parent package where hoisting
140
146
  // cannot be performed
@@ -151,7 +157,7 @@ const decoupleGraphNode = (parent, node) => {
151
157
  decoupled: true,
152
158
  isHoistBorder,
153
159
  hoistPriority,
154
- isWorkspace,
160
+ dependencyKind,
155
161
  hoistedFrom: new Map(hoistedFrom),
156
162
  hoistedTo: new Map(hoistedTo),
157
163
  };
@@ -323,11 +329,17 @@ const getNodeHoistInfo = (rootNode, rootNodePathLocators, nodePath, node, usedDe
323
329
  if (outputReason && !isHoistable)
324
330
  reason = `- self-reference`;
325
331
  if (isHoistable) {
326
- isHoistable = !node.isWorkspace;
332
+ isHoistable = node.dependencyKind !== HoisterDependencyKind.WORKSPACE;
327
333
  if (outputReason && !isHoistable) {
328
334
  reason = `- workspace`;
329
335
  }
330
336
  }
337
+ if (isHoistable) {
338
+ isHoistable = node.dependencyKind !== HoisterDependencyKind.EXTERNAL_SOFT_LINK || node.dependencies.size === 0;
339
+ if (outputReason && !isHoistable) {
340
+ reason = `- external soft link with unhoisted dependencies`;
341
+ }
342
+ }
331
343
  if (isHoistable) {
332
344
  // Direct workspace dependencies must be hoisted to any common ancestor workspace of all the
333
345
  // graph paths that include the dependency, because otherwise running app with
@@ -340,7 +352,7 @@ const getNodeHoistInfo = (rootNode, rootNodePathLocators, nodePath, node, usedDe
340
352
  // It is difficult to find all common ancestors, but there is one easy to find common ancestor -
341
353
  // the root workspace, so, for now, we either hoist direct dependencies into the root workspace, or we keep them
342
354
  // unhoisted, thus we are safe from various pathological cases with `--preserve-symlinks`
343
- isHoistable = !parentNode.isWorkspace || parentNode.hoistedFrom.has(node.name) || rootNodePathLocators.size === 1;
355
+ isHoistable = parentNode.dependencyKind !== HoisterDependencyKind.WORKSPACE || parentNode.hoistedFrom.has(node.name) || rootNodePathLocators.size === 1;
344
356
  if (outputReason && !isHoistable) {
345
357
  reason = parentNode.reasons.get(node.name);
346
358
  }
@@ -614,7 +626,7 @@ const cloneTree = (tree, options) => {
614
626
  decoupled: true,
615
627
  isHoistBorder: true,
616
628
  hoistPriority: 0,
617
- isWorkspace: true,
629
+ dependencyKind: HoisterDependencyKind.WORKSPACE,
618
630
  hoistedFrom: new Map(),
619
631
  hoistedTo: new Map(),
620
632
  };
@@ -623,7 +635,7 @@ const cloneTree = (tree, options) => {
623
635
  let workNode = seenNodes.get(node);
624
636
  const isSeen = !!workNode;
625
637
  if (!workNode) {
626
- const { name, identName, reference, peerNames, hoistPriority, isWorkspace } = node;
638
+ const { name, identName, reference, peerNames, hoistPriority, dependencyKind } = node;
627
639
  const dependenciesNmHoistingLimits = options.hoistingLimits.get(parentNode.locator);
628
640
  workNode = {
629
641
  name,
@@ -638,7 +650,7 @@ const cloneTree = (tree, options) => {
638
650
  decoupled: true,
639
651
  isHoistBorder: dependenciesNmHoistingLimits ? dependenciesNmHoistingLimits.has(name) : false,
640
652
  hoistPriority: hoistPriority || 0,
641
- isWorkspace: isWorkspace || false,
653
+ dependencyKind: dependencyKind || HoisterDependencyKind.REGULAR,
642
654
  hoistedFrom: new Map(),
643
655
  hoistedTo: new Map(),
644
656
  };
@@ -801,7 +813,14 @@ const dumpDepTree = (tree) => {
801
813
  if (nodeCount > MAX_NODES_TO_DUMP || parents.has(pkg))
802
814
  return ``;
803
815
  nodeCount++;
804
- const dependencies = Array.from(pkg.dependencies.values()).sort((n1, n2) => n1.name.localeCompare(n2.name));
816
+ const dependencies = Array.from(pkg.dependencies.values()).sort((n1, n2) => {
817
+ if (n1.name === n2.name) {
818
+ return 0;
819
+ }
820
+ else {
821
+ return n1.name > n2.name ? 1 : -1;
822
+ }
823
+ });
805
824
  let str = ``;
806
825
  parents.add(pkg);
807
826
  for (let idx = 0; idx < dependencies.length; idx++) {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@yarnpkg/nm",
3
- "version": "3.0.0",
3
+ "version": "3.0.1-rc.12",
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.1.0",
10
- "@yarnpkg/fslib": "^2.6.0"
9
+ "@yarnpkg/core": "^3.2.0-rc.12",
10
+ "@yarnpkg/fslib": "^2.6.1-rc.7"
11
11
  },
12
12
  "devDependencies": {
13
- "@yarnpkg/pnp": "^3.1.0"
13
+ "@yarnpkg/pnp": "^3.1.1-rc.12"
14
14
  },
15
15
  "scripts": {
16
16
  "postpack": "rm -rf lib",
@@ -32,5 +32,6 @@
32
32
  },
33
33
  "engines": {
34
34
  "node": ">=12 <14 || 14.2 - 14.9 || >14.10.0"
35
- }
35
+ },
36
+ "stableVersion": "3.0.0"
36
37
  }