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.
This commit is contained in:
Zoltan Kochan
2026-03-22 10:56:36 +01:00
committed by GitHub
parent 6557dc09f9
commit 421ceac0b3
10 changed files with 25 additions and 9 deletions

View File

@@ -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<ProjectManifest>(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

View File

@@ -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",

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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",

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"