@pnpm/deps.graph-hasher 1100.0.0 → 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,5 +1,5 @@
1
1
  import type { LockfileObject, LockfileResolution, PackageSnapshot } from '@pnpm/lockfile.types';
2
- import type { AllowBuild, DepPath, PkgIdWithPatchHash } from '@pnpm/types';
2
+ import type { AllowBuild, DepPath, PkgIdWithPatchHash, SupportedArchitectures } from '@pnpm/types';
3
3
  export type DepsGraph<T extends string> = Record<T, DepsGraphNode<T>>;
4
4
  export interface DepsGraphNode<T extends string> {
5
5
  children: {
@@ -15,6 +15,7 @@ export interface DepsStateCache {
15
15
  export declare function calcDepState<T extends string>(depsGraph: DepsGraph<T>, cache: DepsStateCache, depPath: string, opts: {
16
16
  patchFileHash?: string;
17
17
  includeDepGraphHash: boolean;
18
+ supportedArchitectures?: SupportedArchitectures;
18
19
  }): string;
19
20
  export interface PkgMeta {
20
21
  depPath: DepPath;
@@ -26,12 +27,13 @@ export interface HashedDepPath<T extends PkgMeta> {
26
27
  pkgMeta: T;
27
28
  hash: string;
28
29
  }
29
- export declare function iterateHashedGraphNodes<T extends PkgMeta>(graph: DepsGraph<DepPath>, pkgMetaIterator: PkgMetaIterator<T>, allowBuild?: AllowBuild): IterableIterator<HashedDepPath<T>>;
30
- export declare function calcGraphNodeHash<T extends PkgMeta>({ graph, cache, builtDepPaths, buildRequiredCache }: {
30
+ export declare function iterateHashedGraphNodes<T extends PkgMeta>(graph: DepsGraph<DepPath>, pkgMetaIterator: PkgMetaIterator<T>, allowBuild?: AllowBuild, supportedArchitectures?: SupportedArchitectures): IterableIterator<HashedDepPath<T>>;
31
+ export declare function calcGraphNodeHash<T extends PkgMeta>({ graph, cache, builtDepPaths, buildRequiredCache, supportedArchitectures }: {
31
32
  graph: DepsGraph<DepPath>;
32
33
  cache: DepsStateCache;
33
34
  builtDepPaths?: Set<DepPath>;
34
35
  buildRequiredCache?: Record<string, boolean>;
36
+ supportedArchitectures?: SupportedArchitectures;
35
37
  }, pkgMeta: T): string;
36
38
  export declare function calcLeafGlobalVirtualStorePath(fullPkgId: string, name: string, version: string): string;
37
39
  export interface PkgMetaAndSnapshot extends PkgMeta {
@@ -39,4 +41,4 @@ export interface PkgMetaAndSnapshot extends PkgMeta {
39
41
  pkgIdWithPatchHash: PkgIdWithPatchHash;
40
42
  }
41
43
  export declare function iteratePkgMeta(lockfile: LockfileObject, graph: DepsGraph<DepPath>): PkgMetaIterator<PkgMetaAndSnapshot>;
42
- export declare function lockfileToDepGraph(lockfile: LockfileObject): DepsGraph<DepPath>;
44
+ export declare function lockfileToDepGraph(lockfile: LockfileObject, supportedArchitectures?: SupportedArchitectures): DepsGraph<DepPath>;
package/lib/index.js CHANGED
@@ -2,10 +2,12 @@ import { ENGINE_NAME } from '@pnpm/constants';
2
2
  import { hashObject, hashObjectWithoutSorting } from '@pnpm/crypto.object-hasher';
3
3
  import { getPkgIdWithPatchHash, refToRelative } from '@pnpm/deps.path';
4
4
  import { nameVerFromPkgSnapshot } from '@pnpm/lockfile.utils';
5
+ import { resolvePlatformSelector, selectPlatformVariant } from '@pnpm/resolving.resolver-base';
6
+ import { familySync } from 'detect-libc';
5
7
  export function calcDepState(depsGraph, cache, depPath, opts) {
6
8
  let result = ENGINE_NAME;
7
9
  if (opts.includeDepGraphHash) {
8
- const depGraphHash = calcDepGraphHash(depsGraph, cache, new Set(), depPath);
10
+ const depGraphHash = calcDepGraphHash(depsGraph, cache, new Set(), depPath, opts.supportedArchitectures);
9
11
  result += `;deps=${depGraphHash}`;
10
12
  }
11
13
  if (opts.patchFileHash) {
@@ -13,7 +15,7 @@ export function calcDepState(depsGraph, cache, depPath, opts) {
13
15
  }
14
16
  return result;
15
17
  }
16
- function calcDepGraphHash(depsGraph, cache, parents, depPath) {
18
+ function calcDepGraphHash(depsGraph, cache, parents, depPath, supportedArchitectures) {
17
19
  if (cache[depPath])
18
20
  return cache[depPath];
19
21
  const node = depsGraph[depPath];
@@ -26,16 +28,15 @@ function calcDepGraphHash(depsGraph, cache, parents, depPath) {
26
28
  if (!node.resolution) {
27
29
  throw new Error(`resolution is not defined for ${depPath} in depsGraph`);
28
30
  }
29
- node.fullPkgId = createFullPkgId(node.pkgIdWithPatchHash, node.resolution);
31
+ node.fullPkgId = createFullPkgId(node.pkgIdWithPatchHash, node.resolution, supportedArchitectures);
30
32
  }
31
33
  const deps = {};
32
34
  if (Object.keys(node.children).length && !parents.has(node.fullPkgId)) {
33
35
  const nextParents = new Set([...Array.from(parents), node.fullPkgId]);
34
- const _calcDepGraphHash = calcDepGraphHash.bind(null, depsGraph, cache, nextParents);
35
36
  for (const alias in node.children) {
36
37
  if (Object.hasOwn(node.children, alias)) {
37
38
  const childId = node.children[alias];
38
- deps[alias] = _calcDepGraphHash(childId);
39
+ deps[alias] = calcDepGraphHash(depsGraph, cache, nextParents, childId, supportedArchitectures);
39
40
  }
40
41
  }
41
42
  }
@@ -45,7 +46,7 @@ function calcDepGraphHash(depsGraph, cache, parents, depPath) {
45
46
  });
46
47
  return cache[depPath];
47
48
  }
48
- export function* iterateHashedGraphNodes(graph, pkgMetaIterator, allowBuild) {
49
+ export function* iterateHashedGraphNodes(graph, pkgMetaIterator, allowBuild, supportedArchitectures) {
49
50
  let builtDepPaths;
50
51
  let entries;
51
52
  if (allowBuild != null) {
@@ -56,20 +57,21 @@ export function* iterateHashedGraphNodes(graph, pkgMetaIterator, allowBuild) {
56
57
  else {
57
58
  entries = pkgMetaIterator;
58
59
  }
59
- const _calcGraphNodeHash = calcGraphNodeHash.bind(null, {
60
+ const ctx = {
60
61
  graph,
61
62
  cache: {},
62
63
  builtDepPaths,
63
64
  buildRequiredCache: builtDepPaths !== undefined ? {} : undefined,
64
- });
65
+ supportedArchitectures,
66
+ };
65
67
  for (const pkgMeta of entries) {
66
68
  yield {
67
- hash: _calcGraphNodeHash(pkgMeta),
69
+ hash: calcGraphNodeHash(ctx, pkgMeta),
68
70
  pkgMeta,
69
71
  };
70
72
  }
71
73
  }
72
- export function calcGraphNodeHash({ graph, cache, builtDepPaths, buildRequiredCache }, pkgMeta) {
74
+ export function calcGraphNodeHash({ graph, cache, builtDepPaths, buildRequiredCache, supportedArchitectures }, pkgMeta) {
73
75
  const { name, version, depPath } = pkgMeta;
74
76
  // When builtDepPaths is provided (derived from the allowBuilds config),
75
77
  // we only include the engine name for packages that are allowed to build
@@ -79,7 +81,7 @@ export function calcGraphNodeHash({ graph, cache, builtDepPaths, buildRequiredCa
79
81
  const includeEngine = builtDepPaths === undefined ||
80
82
  transitivelyRequiresBuild(graph, builtDepPaths, buildRequiredCache ??= {}, depPath, new Set());
81
83
  const engine = includeEngine ? ENGINE_NAME : null;
82
- const deps = calcDepGraphHash(graph, cache, new Set(), depPath);
84
+ const deps = calcDepGraphHash(graph, cache, new Set(), depPath, supportedArchitectures);
83
85
  const hexDigest = hashObjectWithoutSorting({ engine, deps }, { encoding: 'hex' });
84
86
  return formatGlobalVirtualStorePath(name, version, hexDigest);
85
87
  }
@@ -114,7 +116,7 @@ export function* iteratePkgMeta(lockfile, graph) {
114
116
  };
115
117
  }
116
118
  }
117
- export function lockfileToDepGraph(lockfile) {
119
+ export function lockfileToDepGraph(lockfile, supportedArchitectures) {
118
120
  const graph = {};
119
121
  if (lockfile.packages != null) {
120
122
  for (const [depPath, pkgSnapshot] of Object.entries(lockfile.packages)) {
@@ -124,7 +126,7 @@ export function lockfileToDepGraph(lockfile) {
124
126
  });
125
127
  graph[depPath] = {
126
128
  children,
127
- fullPkgId: createFullPkgId(getPkgIdWithPatchHash(depPath), pkgSnapshot.resolution),
129
+ fullPkgId: createFullPkgId(getPkgIdWithPatchHash(depPath), pkgSnapshot.resolution, supportedArchitectures),
128
130
  };
129
131
  }
130
132
  }
@@ -174,8 +176,30 @@ function lockfileDepsToGraphChildren(deps) {
174
176
  }
175
177
  return children;
176
178
  }
177
- function createFullPkgId(pkgIdWithPatchHash, resolution) {
178
- const res = 'integrity' in resolution ? String(resolution.integrity) : hashObject(resolution);
179
- return `${pkgIdWithPatchHash}:${res}`;
179
+ function createFullPkgId(pkgIdWithPatchHash, resolution, supportedArchitectures) {
180
+ if ('integrity' in resolution && resolution.integrity != null) {
181
+ return `${pkgIdWithPatchHash}:${resolution.integrity}`;
182
+ }
183
+ if ('type' in resolution && resolution.type === 'variations') {
184
+ // Variations resolutions list every platform variant for a runtime (e.g. all
185
+ // OS/arch combinations for a Node.js version). Hashing the whole object
186
+ // would be identical across hosts, so two projects that install different
187
+ // variants of the same runtime would collide on the same virtual store
188
+ // directory — the first install would "win" and subsequent installs with
189
+ // different --os/--cpu/--libc would silently reuse the cached variant.
190
+ // Incorporate the chosen variant's integrity instead so each variant gets
191
+ // its own entry in the global virtual store.
192
+ const selector = resolvePlatformSelector(supportedArchitectures, {
193
+ platform: process.platform,
194
+ arch: process.arch,
195
+ libc: familySync(),
196
+ });
197
+ const variant = selectPlatformVariant(resolution.variants, selector);
198
+ const chosenResolution = variant?.resolution;
199
+ if (chosenResolution && 'integrity' in chosenResolution && chosenResolution.integrity != null) {
200
+ return `${pkgIdWithPatchHash}:${chosenResolution.integrity}`;
201
+ }
202
+ }
203
+ return `${pkgIdWithPatchHash}:${hashObject(resolution)}`;
180
204
  }
181
205
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/deps.graph-hasher",
3
- "version": "1100.0.0",
3
+ "version": "1100.1.0",
4
4
  "description": "Calculates the state of a dependency",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -24,15 +24,17 @@
24
24
  "!*.map"
25
25
  ],
26
26
  "dependencies": {
27
+ "detect-libc": "^2.0.3",
27
28
  "@pnpm/constants": "1100.0.0",
28
- "@pnpm/deps.path": "1100.0.0",
29
29
  "@pnpm/crypto.object-hasher": "1100.0.0",
30
- "@pnpm/lockfile.types": "1100.0.0",
31
- "@pnpm/lockfile.utils": "1100.0.0",
32
- "@pnpm/types": "1100.0.0"
30
+ "@pnpm/deps.path": "1100.0.1",
31
+ "@pnpm/lockfile.utils": "1100.0.2",
32
+ "@pnpm/lockfile.types": "1100.0.2",
33
+ "@pnpm/types": "1101.0.0",
34
+ "@pnpm/resolving.resolver-base": "1100.1.0"
33
35
  },
34
36
  "devDependencies": {
35
- "@pnpm/deps.graph-hasher": "1100.0.0"
37
+ "@pnpm/deps.graph-hasher": "1100.1.0"
36
38
  },
37
39
  "engines": {
38
40
  "node": ">=22.13"