From b2e136339689a176eb3e5d7f32aed90a6dc45fbf Mon Sep 17 00:00:00 2001 From: "voidzero-bot[bot]" <348775505+voidzero-bot[bot]@users.noreply.github.com> Date: Sun, 29 Nov 2026 04:56:27 +0000 Subject: [PATCH] fix(cli): keep approved builds running during pnpm >= 11 auto-installs --- packages/cli/src/create/bin.ts | 12 +++---- .../cli/src/utils/__tests__/prompts.spec.ts | 34 +++++++++--------- .../utils/__tests__/run-vite-install.spec.ts | 24 +++++++++++-- packages/cli/src/utils/prompts.ts | 35 ++++++++++++------- 4 files changed, 68 insertions(+), 37 deletions(-) diff --git a/packages/cli/src/create/bin.ts b/packages/cli/src/create/bin.ts index 2cba743a71..cbb623c605 100644 --- a/packages/cli/src/create/bin.ts +++ b/packages/cli/src/create/bin.ts @@ -1240,12 +1240,12 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h } } updateCreateProgress('Installing dependencies'); - // Detect gated builds here too: without this, pnpm>=11 adds `--ignore-scripts`, - // which pins the ignore-scripts state so the later main install reports - // "already up to date" and never surfaces the gated build. The main install - // re-detects and approves, so we only need this pre-install to skip - // `--ignore-scripts` (detectIgnoredBuilds treats the gated-build error as - // installed, so migration still proceeds). + // Detect gated builds here too: without this, pnpm>=11 relaxes + // strict-dep-builds, which pins the skipped-build state so the later main + // install reports "already up to date" and never surfaces the gated build. + // The main install re-detects and approves, so we only need this + // pre-install to keep the relaxation off (detectIgnoredBuilds treats the + // gated-build error as installed, so migration still proceeds). installSummary = await runViteInstall( installCwd, options.interactive, diff --git a/packages/cli/src/utils/__tests__/prompts.spec.ts b/packages/cli/src/utils/__tests__/prompts.spec.ts index 9d4ab9622f..fb14582c63 100644 --- a/packages/cli/src/utils/__tests__/prompts.spec.ts +++ b/packages/cli/src/utils/__tests__/prompts.spec.ts @@ -5,7 +5,7 @@ import { PackageManager } from '../../types/index.ts'; import { downloadPackageManager, resolveGitInit, - shouldIgnoreScriptsForAutoInstall, + shouldRelaxStrictDepBuildsForAutoInstall, } from '../prompts.ts'; vi.mock(import('../../../binding/index.js'), async (importOriginal) => ({ @@ -78,37 +78,37 @@ describe('resolveGitInit', () => { }); }); -describe('shouldIgnoreScriptsForAutoInstall', () => { +describe('shouldRelaxStrictDepBuildsForAutoInstall', () => { it('returns true for pnpm >= 11.0.0', () => { - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, '11.0.0')).toBe(true); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, '11.0.8')).toBe(true); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, '12.0.0')).toBe(true); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, '11.0.0')).toBe(true); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, '11.0.8')).toBe(true); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, '12.0.0')).toBe(true); }); it('returns false for pnpm < 11.0.0', () => { - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, '10.33.2')).toBe(false); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, '9.5.0')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, '10.33.2')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, '9.5.0')).toBe(false); }); it('returns false for non-pnpm package managers', () => { - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.npm, '11.0.0')).toBe(false); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.yarn, '11.0.0')).toBe(false); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.bun, '11.0.0')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.npm, '11.0.0')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.yarn, '11.0.0')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.bun, '11.0.0')).toBe(false); }); it('returns false when version is unknown or unparsable', () => { - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, undefined)).toBe(false); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, 'latest')).toBe(false); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, '')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, undefined)).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, 'latest')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, '')).toBe(false); }); it('returns false when packageManager is undefined', () => { - expect(shouldIgnoreScriptsForAutoInstall(undefined, '11.0.0')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(undefined, '11.0.0')).toBe(false); }); it('coerces non-strict semver pnpm versions', () => { - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, 'v11.0.0')).toBe(true); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, '11')).toBe(true); - expect(shouldIgnoreScriptsForAutoInstall(PackageManager.pnpm, '10')).toBe(false); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, 'v11.0.0')).toBe(true); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, '11')).toBe(true); + expect(shouldRelaxStrictDepBuildsForAutoInstall(PackageManager.pnpm, '10')).toBe(false); }); }); diff --git a/packages/cli/src/utils/__tests__/run-vite-install.spec.ts b/packages/cli/src/utils/__tests__/run-vite-install.spec.ts index ffdbd52dba..f7975350a3 100644 --- a/packages/cli/src/utils/__tests__/run-vite-install.spec.ts +++ b/packages/cli/src/utils/__tests__/run-vite-install.spec.ts @@ -79,7 +79,7 @@ describe('runViteInstall with detectIgnoredBuilds', () => { expect(summary.pendingBuilds).toEqual(['esbuild']); }); - it('keeps the --ignore-scripts workaround (and no pendingBuilds) when detection is off', async () => { + it('relaxes strict-dep-builds (and reports no pendingBuilds) when detection is off', async () => { mockRun.mockResolvedValue(installResult(0, '')); const summary = await runViteInstall('/project', false, undefined, { silent: true, @@ -88,8 +88,28 @@ describe('runViteInstall with detectIgnoredBuilds', () => { }); expect(summary.status).toBe('installed'); expect(summary.pendingBuilds).toBeUndefined(); + // The relaxation must reach pnpm via `vp install`'s pass-through slot: + // `--ignore-scripts` would skip approved builds too (e.g. a git + // dependency's `prepare`), leaving them unbuilt with no way to recover. expect(mockRun).toHaveBeenCalledWith( - expect.objectContaining({ args: [expect.any(String), 'install', '--ignore-scripts'] }), + expect.objectContaining({ + args: [expect.any(String), 'install', '--', '--config.strict-dep-builds=false'], + }), + ); + }); + + it('keeps an explicit --ignore-scripts from the caller', async () => { + mockRun.mockResolvedValue(installResult(0, '')); + const summary = await runViteInstall('/project', false, ['--ignore-scripts'], { + silent: true, + packageManager: PackageManager.pnpm, + packageManagerVersion: '11.6.0', + }); + expect(summary.status).toBe('installed'); + expect(mockRun).toHaveBeenCalledWith( + expect.objectContaining({ + args: [expect.any(String), 'install', '--ignore-scripts'], + }), ); }); }); diff --git a/packages/cli/src/utils/prompts.ts b/packages/cli/src/utils/prompts.ts index 31ac8deb14..9eb708cc2d 100644 --- a/packages/cli/src/utils/prompts.ts +++ b/packages/cli/src/utils/prompts.ts @@ -30,10 +30,16 @@ export interface CommandRunSummary { * exit-1. Auto-installs run by `vp migrate` / `vp create` happen before the * user has a chance to approve build scripts via `pnpm.onlyBuiltDependencies`, * so transitive deps like `esbuild` would fail the install. Pass - * `--ignore-scripts` in that window so the orchestration succeeds; the user's - * own subsequent `vp install` keeps default pnpm behavior. + * `--config.strict-dep-builds=false` in that window so the orchestration + * succeeds: approved builds (for example a git dependency's `prepare`) still + * run, only unapproved ones are skipped, and the user's own subsequent + * `vp install` keeps default pnpm behavior. (`--ignore-scripts` would also + * stop the install from failing, but it skips approved builds too, and a + * skipped `prepare` is never re-run — a git dependency re-fetched after the + * migration's `vite@*` override stays without its `dist/` until + * `pnpm install --force`.) */ -export function shouldIgnoreScriptsForAutoInstall( +export function shouldRelaxStrictDepBuildsForAutoInstall( packageManager: PackageManager | undefined, packageManagerVersion: string | undefined, ): boolean { @@ -141,8 +147,8 @@ export async function runViteInstall( packageManagerOverride?: string; /** * Surface the package manager's gated build scripts instead of suppressing - * them. When set, the auto `--ignore-scripts` workaround is skipped (so - * pnpm records which packages need approval), a pnpm >= 11 + * them. When set, the auto `--config.strict-dep-builds=false` workaround is + * skipped (so pnpm records which packages need approval), a pnpm >= 11 * `ERR_PNPM_IGNORED_BUILDS` exit is treated as a successful install (deps * are on disk), and the gated package names (pnpm, yarn, npm >= 12) are * returned in `pendingBuilds`. @@ -166,17 +172,22 @@ export async function runViteInstall( const detectIgnoredBuilds = options?.detectIgnoredBuilds === true; const installArgs = [...(extraArgs ?? [])]; - // `--ignore-scripts` keeps auto-installs from hard-failing on pnpm >= 11, but - // it also makes the gated builds unrecoverable (`approve-builds` then reports - // nothing pending). When the caller wants to act on those builds, leave the - // flag off and instead tolerate the resulting `ERR_PNPM_IGNORED_BUILDS` exit - // below. + // `--config.strict-dep-builds=false` keeps auto-installs from hard-failing on + // pnpm >= 11 while still running approved builds (unlike `--ignore-scripts`, + // which also skips them unrecoverably). It must go through `vp install`'s + // pass-through slot — `vp install` has no first-class `--config` flag. + // Detection callers instead want pnpm to record the gated builds, so they + // leave the relaxation off and tolerate the resulting + // `ERR_PNPM_IGNORED_BUILDS` exit below. if ( !detectIgnoredBuilds && - shouldIgnoreScriptsForAutoInstall(options?.packageManager, options?.packageManagerVersion) && + shouldRelaxStrictDepBuildsForAutoInstall( + options?.packageManager, + options?.packageManagerVersion, + ) && !installArgs.includes('--ignore-scripts') ) { - installArgs.push('--ignore-scripts'); + installArgs.push('--', '--config.strict-dep-builds=false'); } const spinner = options?.silent ? getSilentSpinner() : getSpinner(interactive);