From 421ceac0b3eabcdeacab89327cfef38ca6987f95 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 22 Mar 2026 10:56:36 +0100 Subject: [PATCH] chore: compile pnpm CLI bundle before tests that use it (#11059) Packages whose tests spawn the local pnpm CLI (pnpm/bin/pnpm.mjs) need the bundle (pnpm/dist/pnpm.mjs) to exist. Add `pnpm --filter pnpm run compile` to their test scripts so the bundle is built before tests run. --- .meta-updater/src/index.ts | 16 ++++++++++++++++ __utils__/test-ipc-server/package.json | 2 +- building/commands/package.json | 2 +- cache/commands/package.json | 2 +- deps/inspection/commands/package.json | 2 +- exec/commands/package.json | 2 +- lockfile/make-dedicated-lockfile/package.json | 2 +- releasing/commands/package.json | 2 +- releasing/exportable-manifest/package.json | 2 +- store/commands/package.json | 2 +- 10 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.meta-updater/src/index.ts b/.meta-updater/src/index.ts index ac5b264a53..821500a71d 100644 --- a/.meta-updater/src/index.ts +++ b/.meta-updater/src/index.ts @@ -15,6 +15,19 @@ import { writeJsonFile } from 'write-json-file' const CLI_PKG_NAME = 'pnpm' +// Packages whose tests spawn the local pnpm CLI binary (pnpm/bin/pnpm.mjs) +// and therefore need the CLI bundle (pnpm/dist/pnpm.mjs) to be built first. +const PKGS_NEEDING_CLI_COMPILE = new Set([ + '@pnpm/building.commands', + '@pnpm/cache.commands', + '@pnpm/deps.inspection.commands', + '@pnpm/exec.commands', + '@pnpm/lockfile.make-dedicated-lockfile', + '@pnpm/releasing.commands', + '@pnpm/releasing.exportable-manifest', + '@pnpm/store.commands', +]) + export default async (workspaceDir: string) => { // eslint-disable-line const workspaceManifest = await readWorkspaceManifest(workspaceDir)! const pnpmManifest = loadJsonFileSync(path.join(workspaceDir, 'pnpm/package.json')) @@ -299,6 +312,9 @@ async function updateManifest (workspaceDir: string, manifest: ProjectManifest, } break } + if (manifest.name && PKGS_NEEDING_CLI_COMPILE.has(manifest.name)) { + scripts.test = 'pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test' + } // Clean up old underscore-prefixed script names delete scripts._test delete scripts._compile diff --git a/__utils__/test-ipc-server/package.json b/__utils__/test-ipc-server/package.json index 268b7913b6..2779691974 100644 --- a/__utils__/test-ipc-server/package.json +++ b/__utils__/test-ipc-server/package.json @@ -17,7 +17,7 @@ "scripts": { "lint": "eslint src/**/*.ts test/**/*.ts", "compile": "rimraf tsconfig.tsbuildinfo lib && tsc --build", - "test": "pnpm run compile && cross-env NODE_OPTIONS=--experimental-vm-modules jest" + "test": "pnpm run compile && pnpm --filter pnpm run compile && cross-env NODE_OPTIONS=--experimental-vm-modules jest" }, "keywords": [ "pnpm", diff --git a/building/commands/package.json b/building/commands/package.json index f034726491..4b7f3e35b1 100644 --- a/building/commands/package.json +++ b/building/commands/package.json @@ -26,7 +26,7 @@ ], "scripts": { "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", - "test": "pnpm run compile && pnpm run .test", + "test": "pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test", "prepublishOnly": "pnpm run compile", "compile": "tsgo --build && pnpm run lint --fix", ".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest" diff --git a/cache/commands/package.json b/cache/commands/package.json index 94f7e2cf13..3146abad89 100644 --- a/cache/commands/package.json +++ b/cache/commands/package.json @@ -26,7 +26,7 @@ ], "scripts": { "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", - "test": "pnpm run compile && pnpm run .test", + "test": "pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test", "prepublishOnly": "pnpm run compile", "compile": "tsgo --build && pnpm run lint --fix", ".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest" diff --git a/deps/inspection/commands/package.json b/deps/inspection/commands/package.json index 4814ded596..d6649600f7 100644 --- a/deps/inspection/commands/package.json +++ b/deps/inspection/commands/package.json @@ -25,7 +25,7 @@ ], "scripts": { "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", - "test": "pnpm run compile && pnpm run .test", + "test": "pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test", "prepublishOnly": "pnpm run compile", "compile": "tsgo --build && pnpm run lint --fix", ".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest" diff --git a/exec/commands/package.json b/exec/commands/package.json index cdf9361b48..7b3ee7b069 100644 --- a/exec/commands/package.json +++ b/exec/commands/package.json @@ -26,7 +26,7 @@ ], "scripts": { "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", - "test": "pnpm run compile && pnpm run .test", + "test": "pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test", "prepublishOnly": "pnpm run compile", "start": "tsgo --watch", "compile": "tsgo --build && pnpm run lint --fix", diff --git a/lockfile/make-dedicated-lockfile/package.json b/lockfile/make-dedicated-lockfile/package.json index 038ad899f3..463705592f 100644 --- a/lockfile/make-dedicated-lockfile/package.json +++ b/lockfile/make-dedicated-lockfile/package.json @@ -28,7 +28,7 @@ "bin": "./bin/make-dedicated-lockfile.js", "scripts": { "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", - "test": "pnpm run compile && pnpm run .test", + "test": "pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test", "prepublishOnly": "pnpm run compile", "compile": "tsgo --build && pnpm run lint --fix", ".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest" diff --git a/releasing/commands/package.json b/releasing/commands/package.json index 1477fe1242..b29257aed4 100644 --- a/releasing/commands/package.json +++ b/releasing/commands/package.json @@ -26,7 +26,7 @@ "scripts": { "start": "tsgo --watch", "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", - "test": "pnpm run compile && pnpm run .test", + "test": "pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test", "prepublishOnly": "pnpm run compile", "compile": "tsgo --build && pnpm run lint --fix", ".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest" diff --git a/releasing/exportable-manifest/package.json b/releasing/exportable-manifest/package.json index 0df0b12c30..119547d566 100644 --- a/releasing/exportable-manifest/package.json +++ b/releasing/exportable-manifest/package.json @@ -25,7 +25,7 @@ ], "scripts": { "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", - "test": "pnpm run compile && pnpm run .test", + "test": "pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test", "prepublishOnly": "pnpm run compile", "compile": "tsgo --build && pnpm run lint --fix", ".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest" diff --git a/store/commands/package.json b/store/commands/package.json index cb041e4db4..44e48db1a7 100644 --- a/store/commands/package.json +++ b/store/commands/package.json @@ -26,7 +26,7 @@ ], "scripts": { "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", - "test": "pnpm run compile && pnpm run .test", + "test": "pnpm run compile && pnpm --filter pnpm run compile && pnpm run .test", "prepublishOnly": "pnpm run compile", "compile": "tsgo --build && pnpm run lint --fix", ".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest"