@pnpm/building.after-install 1101.0.19 → 1101.0.21

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.
Files changed (2) hide show
  1. package/lib/index.js +49 -6
  2. package/package.json +22 -22
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import assert from 'node:assert';
2
+ import fs from 'node:fs';
2
3
  import path from 'node:path';
3
4
  import util from 'node:util';
4
5
  import { linkBins } from '@pnpm/bins.linker';
@@ -42,15 +43,18 @@ function findPackages(packages, searched, opts) {
42
43
  });
43
44
  return false;
44
45
  }
45
- return matches(searched, pkgInfo);
46
+ return matches(searched, pkgInfo, dp.getPkgIdWithPatchHash(relativeDepPath));
46
47
  });
47
48
  }
48
49
  // TODO: move this logic to separate package as this is also used in tree-builder
49
- function matches(searched, manifest) {
50
+ function matches(searched, manifest, pkgIdWithPatchHash) {
50
51
  return searched.some((searchedPkg) => {
51
52
  if (typeof searchedPkg === 'string') {
52
53
  return manifest.name === searchedPkg;
53
54
  }
55
+ if ('pkgIdWithPatchHash' in searchedPkg) {
56
+ return searchedPkg.pkgIdWithPatchHash === pkgIdWithPatchHash;
57
+ }
54
58
  return searchedPkg.name === manifest.name && !!manifest.version &&
55
59
  semver.satisfies(manifest.version, searchedPkg.range);
56
60
  });
@@ -66,6 +70,9 @@ export async function buildSelectedPkgs(projects, pkgSpecs, maybeOpts) {
66
70
  return {};
67
71
  const packages = ctx.currentLockfile.packages;
68
72
  const searched = pkgSpecs.map((arg) => {
73
+ if (matchesDepPath(packages, arg)) {
74
+ return { pkgIdWithPatchHash: dp.removePeersSuffix(arg) };
75
+ }
69
76
  const { fetchSpec, name, raw, type } = npa(arg);
70
77
  if (raw === name) {
71
78
  return name;
@@ -111,6 +118,10 @@ export async function buildSelectedPkgs(projects, pkgSpecs, maybeOpts) {
111
118
  ignoredBuilds: ignoredPkgs,
112
119
  };
113
120
  }
121
+ function matchesDepPath(packages, pkgSpec) {
122
+ const normalizedPkgSpec = dp.removePeersSuffix(pkgSpec);
123
+ return Object.keys(packages).some((depPath) => dp.removePeersSuffix(depPath) === normalizedPkgSpec);
124
+ }
114
125
  export async function buildProjects(projects, maybeOpts) {
115
126
  const reporter = maybeOpts?.reporter;
116
127
  if ((reporter != null) && typeof reporter === 'function') {
@@ -221,8 +232,8 @@ async function _rebuild(ctx, opts) {
221
232
  };
222
233
  const ignoredPkgs = new Set();
223
234
  const _allowBuild = createAllowBuildFunction(opts) ?? (() => undefined);
224
- const allowBuild = (pkgName, version, depPath) => {
225
- switch (_allowBuild(pkgName, version)) {
235
+ const allowBuild = (depPath) => {
236
+ switch (_allowBuild(depPath)) {
226
237
  case true: return true;
227
238
  case undefined: {
228
239
  ignoredPkgs.add(depPath);
@@ -240,7 +251,10 @@ async function _rebuild(ctx, opts) {
240
251
  if (opts.enableGlobalVirtualStore) {
241
252
  const globalVirtualStoreDir = opts.globalVirtualStoreDir ?? path.join(opts.storeDir, 'links');
242
253
  for (const { hash, pkgMeta } of iterateHashedGraphNodes(depGraph, iteratePkgMeta(ctx.currentLockfile, depGraph), _allowBuild, opts.supportedArchitectures, nodeVersion)) {
243
- gvsDirByDepPath.set(pkgMeta.depPath, path.join(globalVirtualStoreDir, hash));
254
+ const preferredGvsDir = path.join(globalVirtualStoreDir, hash);
255
+ gvsDirByDepPath.set(pkgMeta.depPath, fs.existsSync(preferredGvsDir)
256
+ ? preferredGvsDir
257
+ : findLinkedGvsDir(pkgMeta.name, Object.values(ctx.projects), globalVirtualStoreDir) ?? preferredGvsDir);
244
258
  }
245
259
  }
246
260
  const pkgModulesDir = (depPath) => gvsDirByDepPath.has(depPath)
@@ -320,7 +334,7 @@ async function _rebuild(ctx, opts) {
320
334
  // However, currently rebuild doesn't work for such packages at all, which should be fixed.
321
335
  requiresBuild = pkgRequiresBuild(pgkManifest, new Map());
322
336
  }
323
- const hasSideEffects = requiresBuild && allowBuild(pkgInfo.name, pkgInfo.version, depPath) && await runPostinstallHooks({
337
+ const hasSideEffects = requiresBuild && allowBuild(depPath) && await runPostinstallHooks({
324
338
  depPath,
325
339
  extraBinPaths,
326
340
  extraEnv: opts.extraEnv,
@@ -408,6 +422,35 @@ async function _rebuild(ctx, opts) {
408
422
  }
409
423
  return { pkgsThatWereRebuilt, ignoredPkgs };
410
424
  }
425
+ // TODO: delete once rebuild relocates GVS projections to the newly computed
426
+ // hash instead of building in place (https://github.com/pnpm/pnpm/issues/12302).
427
+ function findLinkedGvsDir(pkgName, projects, globalVirtualStoreDir) {
428
+ const normalizedGvsRoot = `${path.resolve(globalVirtualStoreDir)}${path.sep}`;
429
+ for (const { rootDir } of projects) {
430
+ const pkgLink = path.join(rootDir, 'node_modules', pkgName);
431
+ try {
432
+ const target = fs.readlinkSync(pkgLink);
433
+ const pkgRoot = path.resolve(path.dirname(pkgLink), target);
434
+ if (!pkgRoot.startsWith(normalizedGvsRoot))
435
+ continue;
436
+ return nthAncestorDir(pkgRoot, pkgName.split('/').length + 1);
437
+ }
438
+ catch (err) {
439
+ // EINVAL: pkgLink exists but is not a symlink.
440
+ if (util.types.isNativeError(err) && 'code' in err && (err.code === 'EINVAL' || err.code === 'ENOENT'))
441
+ continue;
442
+ throw err;
443
+ }
444
+ }
445
+ return undefined;
446
+ }
447
+ function nthAncestorDir(dir, levels) {
448
+ let result = dir;
449
+ for (let i = 0; i < levels; i++) {
450
+ result = path.dirname(result);
451
+ }
452
+ return result;
453
+ }
411
454
  function binDirsInAllParentDirs(pkgRoot, lockfileDir) {
412
455
  const binDirs = [];
413
456
  let dir = pkgRoot;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/building.after-install",
3
- "version": "1101.0.19",
3
+ "version": "1101.0.21",
4
4
  "description": "Rebuild packages that are already installed by running their lifecycle scripts",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -33,37 +33,37 @@
33
33
  "p-limit": "^7.3.0",
34
34
  "run-groups": "^5.0.0",
35
35
  "semver": "^7.8.1",
36
- "@pnpm/building.pkg-requires-build": "1100.0.6",
37
- "@pnpm/config.normalize-registries": "1100.0.6",
38
- "@pnpm/config.reader": "1101.6.0",
36
+ "@pnpm/bins.linker": "1100.0.13",
37
+ "@pnpm/building.pkg-requires-build": "1100.0.7",
38
+ "@pnpm/building.policy": "1100.0.9",
39
+ "@pnpm/config.normalize-registries": "1100.0.7",
40
+ "@pnpm/config.reader": "1101.8.0",
41
+ "@pnpm/core-loggers": "1100.2.0",
39
42
  "@pnpm/constants": "1100.0.0",
40
- "@pnpm/building.policy": "1100.0.8",
41
- "@pnpm/core-loggers": "1100.1.3",
43
+ "@pnpm/deps.graph-hasher": "1100.2.4",
42
44
  "@pnpm/deps.graph-sequencer": "1100.0.0",
43
- "@pnpm/deps.path": "1100.0.6",
44
- "@pnpm/deps.graph-hasher": "1100.2.3",
45
+ "@pnpm/deps.path": "1100.0.7",
46
+ "@pnpm/exec.lifecycle": "1100.0.17",
45
47
  "@pnpm/error": "1100.0.0",
46
- "@pnpm/installing.context": "1100.0.15",
47
- "@pnpm/exec.lifecycle": "1100.0.15",
48
- "@pnpm/installing.modules-yaml": "1100.0.7",
49
- "@pnpm/lockfile.utils": "1100.0.11",
50
- "@pnpm/lockfile.walker": "1100.0.9",
51
- "@pnpm/pkg-manifest.reader": "1100.0.6",
52
- "@pnpm/store.cafs": "1100.1.8",
53
- "@pnpm/store.connection-manager": "1100.2.6",
54
- "@pnpm/store.controller-types": "1100.1.3",
48
+ "@pnpm/installing.context": "1100.0.17",
49
+ "@pnpm/installing.modules-yaml": "1100.0.8",
50
+ "@pnpm/lockfile.types": "1100.0.10",
51
+ "@pnpm/lockfile.walker": "1100.0.10",
52
+ "@pnpm/lockfile.utils": "1100.0.12",
53
+ "@pnpm/pkg-manifest.reader": "1100.0.7",
54
+ "@pnpm/store.cafs": "1100.1.9",
55
+ "@pnpm/store.connection-manager": "1100.2.8",
56
+ "@pnpm/store.controller-types": "1100.1.4",
55
57
  "@pnpm/store.index": "1100.1.0",
56
- "@pnpm/lockfile.types": "1100.0.9",
57
- "@pnpm/types": "1101.3.0",
58
- "@pnpm/bins.linker": "1100.0.11"
58
+ "@pnpm/types": "1101.3.1"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@pnpm/logger": "^1001.0.1",
62
- "@pnpm/worker": "^1100.1.9"
62
+ "@pnpm/worker": "^1100.1.11"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/semver": "7.7.1",
66
- "@pnpm/building.after-install": "1101.0.19"
66
+ "@pnpm/building.after-install": "1101.0.21"
67
67
  },
68
68
  "engines": {
69
69
  "node": ">=22.13"