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
80 changes: 80 additions & 0 deletions packages/cli/src/migration/__tests__/migrator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4647,6 +4647,41 @@ describe('ensureVitePlusBootstrap', () => {
expect(workspace.minimumReleaseAgeExclude).toBeUndefined();
});

it.each([0, '0', -60])(
'does not add minimumReleaseAgeExclude when the pnpm age gate is disabled by minimumReleaseAge: %s',
(disabledGate) => {
fs.writeFileSync(
path.join(tmpDir, 'package.json'),
JSON.stringify({
name: 'test',
devDependencies: { 'vite-plus': 'catalog:' },
devEngines: {
packageManager: { name: 'pnpm', version: '10.33.0', onFail: 'download' },
},
}),
);
fs.writeFileSync(
path.join(tmpDir, 'pnpm-workspace.yaml'),
[
'catalog:',
' vite: npm:@voidzero-dev/vite-plus-core@latest',
' vitest: npm:@voidzero-dev/vite-plus-test@latest',
`minimumReleaseAge: ${disabledGate}`,
'',
].join('\n'),
);

ensureVitePlusBootstrap(makeWorkspaceInfo(tmpDir, PackageManager.pnpm));

const workspace = readYamlObject(path.join(tmpDir, 'pnpm-workspace.yaml')) as {
minimumReleaseAgeExclude?: Array<string>;
};
// A `minimumReleaseAge` of 0 (or less) disables the gate → nothing is
// held back, so there is nothing to exempt and no list is introduced.
expect(workspace.minimumReleaseAgeExclude).toBeUndefined();
},
);

it.each(['example@1.0.0', 'tsrs@0.25.0-ts7.1.0-beta'])(
'reconciles the bundled tsrs exception while preserving %s and pnpm trust checks',
(existingException) => {
Expand Down Expand Up @@ -4898,6 +4933,51 @@ describe('ensureVitePlusBootstrap', () => {
expect(detectVitePlusBootstrapPending(tmpDir, PackageManager.pnpm)).toBe(false);
});

// Issue #3601: `minimumReleaseAge: 0` disables pnpm's age gate, so there is
// nothing to exempt. Both the writer and this pending check used to look at
// key presence only, so a disabled gate kept getting (and re-adding) the
// exclusion list and the workspace never converged to "already using Vite+".
it('does not treat a workspace whose age gate is disabled by minimumReleaseAge: 0 as pending', () => {
fs.writeFileSync(
path.join(tmpDir, 'package.json'),
JSON.stringify({
name: 'test',
devDependencies: { vite: 'catalog:', 'vite-plus': 'catalog:' },
devEngines: {
packageManager: { name: 'pnpm', version: '10.33.0', onFail: 'download' },
},
}),
);
fs.writeFileSync(
path.join(tmpDir, 'pnpm-workspace.yaml'),
[
'catalog:',
' vite: npm:@voidzero-dev/vite-plus-core@latest',
' vite-plus: latest',
'overrides:',
" 'vite@*': 'catalog:'",
'peerDependencyRules:',
' allowAny: [vite]',
' allowedVersions:',
" vite: '*'",
// The age gate is disabled: nothing is held back, so no exemptions
// are expected even though the key is present.
'minimumReleaseAge: 0',
'',
].join('\n'),
);

expect(detectVitePlusBootstrapPending(tmpDir, PackageManager.pnpm)).toBe(false);

ensureVitePlusBootstrap(makeWorkspaceInfo(tmpDir, PackageManager.pnpm));

const workspace = readYamlObject(path.join(tmpDir, 'pnpm-workspace.yaml')) as {
minimumReleaseAgeExclude?: Array<string>;
};
expect(workspace.minimumReleaseAgeExclude).toBeUndefined();
expect(detectVitePlusBootstrapPending(tmpDir, PackageManager.pnpm)).toBe(false);
});

// Finding 4: the bun reconcile injected a direct `vite` devDependency into EVERY
// workspace package lacking one (for oven-sh/bun#8406), dirtying unrelated
// workspaces that do not depend on vite-plus/vitest/a browser provider. The
Expand Down
26 changes: 22 additions & 4 deletions packages/cli/src/migration/migrator/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ const PNPM_MINIMUM_RELEASE_AGE_EXCLUDES = [
...VITEST_AGE_GATE_EXEMPT_PACKAGES,
] as const;

// True when pnpm's `minimumReleaseAge` gate actually holds anything back. The
// gate is off for an absent/null value (pnpm < 11) and for `0` or any negative
// value, which pnpm (and Vite+'s own installer override, see
// crates/vp_setup/src/install.rs) treats as a disabled gate — nothing is
// quarantined, so there is nothing to exempt. Shared between the writer
// (`rewritePnpmWorkspaceYaml`) and the pending check
// (`pnpmWorkspaceMinimumReleaseAgeExemptionsPending`) so they cannot drift.
function pnpmAgeGateEnabled(value: unknown): boolean {
if (value === undefined || value === null) {
return false;
}
const age = typeof value === 'number' ? value : Number(value);
return Number.isFinite(age) && age > 0;
}

// The bootstrap placeholder used staged publishing; the real release uses
// GitHub trusted publishing with provenance. pnpm ranks the former higher.
// Use the same dependency metadata as vp toolchain. Exempt only the bundled
Expand Down Expand Up @@ -495,7 +510,9 @@ export function rewritePnpmWorkspaceYaml(

// minimumReleaseAgeExclude: exempt the Vite+-managed packages (vite-plus,
// @voidzero-dev/*, the ox* family, and the vitest family) from the age gate.
if (doc.has('minimumReleaseAge')) {
// Only an enabled gate quarantines anything; `minimumReleaseAge: 0` disables
// it, so a disabled gate gets no exemptions.
if (pnpmAgeGateEnabled(doc.get('minimumReleaseAge'))) {
const existingExclude = doc.getIn(['minimumReleaseAgeExclude']);
if (existingExclude && !isSeq(existingExclude)) {
throw new Error('pnpm-workspace.yaml: minimumReleaseAgeExclude must be a sequence');
Expand Down Expand Up @@ -1399,8 +1416,9 @@ export function readPnpmWorkspaceOverrides(
// `rewritePnpmWorkspaceYaml` would add. Used by the bootstrap pending check so an
// otherwise-current workspace is not reported "already using Vite+" while the
// freshly pinned versions would still be quarantined by the age gate. Gated on
// `minimumReleaseAge` being present, mirroring the writer (no gate -> nothing to
// exempt).
// the release-age gate being enabled, mirroring the writer: pnpm treats
// `minimumReleaseAge: 0` (or a negative value) as a disabled gate, and an
// absent value is no gate on pnpm < 11 (no gate -> nothing to exempt).
export function pnpmWorkspaceMinimumReleaseAgeExemptionsPending(projectPath: string): boolean {
const pnpmWorkspaceYamlPath = path.join(projectPath, 'pnpm-workspace.yaml');
if (!fs.existsSync(pnpmWorkspaceYamlPath)) {
Expand All @@ -1410,7 +1428,7 @@ export function pnpmWorkspaceMinimumReleaseAgeExemptionsPending(projectPath: str
minimumReleaseAge?: unknown;
minimumReleaseAgeExclude?: Array<string>;
} | null;
if (!doc || doc.minimumReleaseAge === undefined) {
if (!doc || !pnpmAgeGateEnabled(doc.minimumReleaseAge)) {
return false;
}
const existing = new Set(
Expand Down
Loading