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
12 changes: 6 additions & 6 deletions packages/cli/src/create/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 17 additions & 17 deletions packages/cli/src/utils/__tests__/prompts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down Expand Up @@ -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);
});
});
24 changes: 22 additions & 2 deletions packages/cli/src/utils/__tests__/run-vite-install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'],
}),
);
});
});
35 changes: 23 additions & 12 deletions packages/cli/src/utils/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`.
Expand All @@ -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);
Expand Down
Loading