@pnpm/installing.linking.real-hoist 1100.0.9 → 1100.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.
package/lib/index.d.ts CHANGED
@@ -1,7 +1,27 @@
1
1
  import { type LockfileObject } from '@pnpm/lockfile.utils';
2
2
  import { type HoisterResult } from '@yarnpkg/nm/hoist';
3
- export type HoistingLimits = Map<string, Set<string>>;
3
+ /**
4
+ * Controls how far dependencies are hoisted, mirroring yarn's
5
+ * `nmHoistingLimits`. Given workspace package `A` → `B` → `C`:
6
+ *
7
+ * - `'none'` (default): hoist as far as possible.
8
+ * - `/packages/A`, `/node_modules/B`, `/node_modules/C`
9
+ * - `'workspaces'`: hoist only as far as each workspace package.
10
+ * - `/packages/A`, `/packages/A/node_modules/B`, `/packages/A/node_modules/C`
11
+ * - `'dependencies'`: hoist only up to each workspace package's direct
12
+ * dependencies.
13
+ * - `/packages/A`, `/packages/A/node_modules/B`, `/packages/A/node_modules/B/node_modules/C`
14
+ */
15
+ export type HoistingLimits = 'none' | 'workspaces' | 'dependencies';
4
16
  export type { HoisterResult };
17
+ /**
18
+ * Translate the user-facing {@link HoistingLimits} mode into the
19
+ * `@yarnpkg/nm` hoister's per-locator border map. A name in a
20
+ * locator's set is a hoisting border: that node's dependencies are
21
+ * not hoisted above it. Returns `undefined` for `'none'` (and when
22
+ * unset) so the hoister hoists as far as possible.
23
+ */
24
+ export declare function getHoistingLimits(lockfile: Pick<LockfileObject, 'importers'>, mode: HoistingLimits | undefined): Map<string, Set<string>> | undefined;
5
25
  export declare function hoist(lockfile: LockfileObject, opts?: {
6
26
  hoistingLimits?: HoistingLimits;
7
27
  externalDependencies?: Set<string>;
package/lib/index.js CHANGED
@@ -2,6 +2,43 @@ import * as dp from '@pnpm/deps.path';
2
2
  import { LockfileMissingDependencyError } from '@pnpm/error';
3
3
  import { nameVerFromPkgSnapshot, } from '@pnpm/lockfile.utils';
4
4
  import { hoist as _hoist, HoisterDependencyKind } from '@yarnpkg/nm/hoist';
5
+ /**
6
+ * Translate the user-facing {@link HoistingLimits} mode into the
7
+ * `@yarnpkg/nm` hoister's per-locator border map. A name in a
8
+ * locator's set is a hoisting border: that node's dependencies are
9
+ * not hoisted above it. Returns `undefined` for `'none'` (and when
10
+ * unset) so the hoister hoists as far as possible.
11
+ */
12
+ export function getHoistingLimits(lockfile, mode) {
13
+ if (!mode || mode === 'none')
14
+ return undefined;
15
+ const hoistingLimits = new Map();
16
+ const rootHoistingLimit = new Set();
17
+ for (const [importerId, importer] of Object.entries(lockfile.importers)) {
18
+ const isWorkspaceRoot = importerId === '.';
19
+ const encodedId = encodeURIComponent(importerId);
20
+ if (!isWorkspaceRoot) {
21
+ rootHoistingLimit.add(encodedId);
22
+ if (mode !== 'dependencies') {
23
+ // In `'workspaces'` mode it's enough to border each workspace
24
+ // package at the root; their own direct deps don't need a
25
+ // per-importer border.
26
+ continue;
27
+ }
28
+ }
29
+ const reference = isWorkspaceRoot ? '' : `workspace:${importerId}`;
30
+ const hoistingLimit = isWorkspaceRoot ? rootHoistingLimit : new Set();
31
+ hoistingLimits.set(`${encodedId}@${reference}`, hoistingLimit);
32
+ for (const deps of [importer.dependencies, importer.devDependencies, importer.optionalDependencies]) {
33
+ if (!deps)
34
+ continue;
35
+ for (const dep of Object.keys(deps)) {
36
+ hoistingLimit.add(dep);
37
+ }
38
+ }
39
+ }
40
+ return hoistingLimits;
41
+ }
5
42
  export function hoist(lockfile, opts) {
6
43
  const nodes = new Map();
7
44
  const ctx = {
@@ -47,7 +84,8 @@ export function hoist(lockfile, opts) {
47
84
  };
48
85
  node.dependencies.add(importerNode);
49
86
  }
50
- const hoisterResult = _hoist(node, opts);
87
+ const hoistingLimits = getHoistingLimits(lockfile, opts?.hoistingLimits);
88
+ const hoisterResult = _hoist(node, { ...opts, hoistingLimits });
51
89
  if (opts?.externalDependencies) {
52
90
  for (const hoistedDep of hoisterResult.dependencies.values()) {
53
91
  if (opts.externalDependencies.has(hoistedDep.name)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/installing.linking.real-hoist",
3
- "version": "1100.0.9",
3
+ "version": "1100.1.0",
4
4
  "description": "Hoists dependencies in a node_modules created by pnpm",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -25,16 +25,16 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@yarnpkg/nm": "4.0.7",
28
- "@pnpm/deps.path": "1100.0.4",
29
- "@pnpm/error": "1100.0.0",
30
- "@pnpm/lockfile.utils": "1100.0.9"
28
+ "@pnpm/deps.path": "1100.0.5",
29
+ "@pnpm/lockfile.utils": "1100.0.10",
30
+ "@pnpm/error": "1100.0.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@jest/globals": "30.3.0",
34
- "@pnpm/installing.linking.real-hoist": "1100.0.9",
35
- "@pnpm/lockfile.fs": "1100.1.1",
34
+ "@pnpm/lockfile.fs": "1100.1.2",
35
+ "@pnpm/installing.linking.real-hoist": "1100.1.0",
36
36
  "@pnpm/test-fixtures": "1100.0.0",
37
- "@pnpm/types": "1101.1.1"
37
+ "@pnpm/types": "1101.2.0"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=22.13"