Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/test/test-version-utils/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ lib/test
# Default .npmignore rules only include the root node_modules.
# Adding an explicit rule here ensures we don't publish the compat_workspace's node_modules.
**/node_modules
# Preserve the .npmrc file in compat-workspaces/full so that its settings apply to the postinstall script in test-version-utils
!compat-workspaces/full/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node-linker=isolated
frozen-lockfile=true
engine-strict=true
strict-peer-dependencies=true
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"license": "MIT",
"author": "Microsoft and contributors",
"scripts": {
"preinstall": "node ../scripts/only-pnpm.cjs"
"preinstall": "node scripts/only-pnpm.cjs"
}
}
2 changes: 1 addition & 1 deletion packages/test/test-version-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"eslint:fix": "eslint --quiet --format stylish src --fix --fix-type problem,suggestion,layout",
"format": "npm run format:biome",
"format:biome": "biome check . --write",
"postinstall": "pnpm --dir compat-workspaces/full install --frozen-lockfile",
"postinstall": "pnpm --dir compat-workspaces/full install",
Comment thread
Abe27342 marked this conversation as resolved.
"lint": "fluid-build . --task lint",
"lint:fix": "fluid-build . --task eslint:fix --task format",
"test": "npm run test:mocha",
Expand Down
28 changes: 22 additions & 6 deletions packages/test/test-version-utils/scripts/updateCompatVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
* 3. Writes `compat-workspaces/generated-versions.cjs` with the resolved exact versions.
* 4. Creates or updates per-version `package.json` files in `compat-workspaces/full/`.
* 5. Removes version directories that are no longer needed.
* 6. Runs `pnpm install --no-frozen-lockfile` in the workspace to regenerate the lockfile.
* 6. Runs `pnpm install --no-frozen-lockfile [extra args]` in the workspace to regenerate the lockfile.
*
* Commit all files produced by this script, including the updated `pnpm-lock.yaml`.
*
* Any extra arguments passed to this script are forwarded verbatim to `pnpm install`. For example:
*
* pnpm run update-compat-versions -- --lockfile-only
* pnpm run update-compat-versions -- --store-dir /custom/store
*
* MACHINE-MAINTAINED (do not edit by hand — regenerated by this script):
* compat-workspaces/generated-versions.cjs
* compat-workspaces/full/<version>/package.json (one per version)
* compat-workspaces/full/pnpm-lock.yaml
*/

import { execSync } from "node:child_process";
import { execFileSync, execSync } from "node:child_process";
import {
existsSync,
mkdirSync,
Expand Down Expand Up @@ -204,12 +209,20 @@ function removeStaleVersionDirs(workspaceDir: string, keepVersions: Set<string>)
return removed;
}

function pnpmInstallWorkspace(workspaceDir: string): void {
console.log(`\nRunning pnpm install in ${path.relative(pkgRoot, workspaceDir)} ...`);
execSync(`pnpm install --no-frozen-lockfile`, {
function pnpmInstallWorkspace(workspaceDir: string, extraPnpmArgs: string[] = []): void {
const args = ["install", "--no-frozen-lockfile", ...extraPnpmArgs];
console.log(
`\nRunning pnpm ${args.join(" ")} in ${path.relative(pkgRoot, workspaceDir)} ...`,
);
// On Windows, pnpm is a .cmd shim, which Node refuses to spawn without shell: true
// (CVE-2024-27980). With shell: true on Windows, Node escapes array args for cmd.exe,
// so this still passes arguments verbatim — no shell parsing of caller-provided values.
const isWindows = process.platform === "win32";
execFileSync(isWindows ? "pnpm.cmd" : "pnpm", args, {
cwd: workspaceDir,
Comment thread
Abe27342 marked this conversation as resolved.
env: { ...process.env, NODE_OPTIONS: "" },
stdio: "inherit",
shell: isWindows,
});
}

Expand All @@ -218,6 +231,9 @@ function pnpmInstallWorkspace(workspaceDir: string): void {
// ---------------------------------------------------------------------------

async function main(): Promise<void> {
// Any arguments after the script name are forwarded to pnpm install.
const extraPnpmArgs = process.argv.slice(2);

// Read current package version
const pkgJsonPath = path.join(pkgRoot, "package.json");
const { version: pkgVer } = JSON.parse(readFileSync(pkgJsonPath, "utf8")) as {
Expand Down Expand Up @@ -331,7 +347,7 @@ async function main(): Promise<void> {

if (anyChanged) {
// Regenerate lockfile
pnpmInstallWorkspace(fullDir);
pnpmInstallWorkspace(fullDir, extraPnpmArgs);

console.log("\nDone. Commit all changes in compat-workspaces/ to the repository.");
} else {
Expand Down
Loading