From 4f8d9030aebe9aecb05334fdfe49cc57ff4f3361 Mon Sep 17 00:00:00 2001 From: Liang Date: Sat, 28 Nov 2026 14:00:56 +0800 Subject: [PATCH 1/2] fix(migrate): replace bundled packages only when they are devDependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current `vp migrate` removes Oxlint, Oxfmt, tsdown, `@vitest/browser`, and `@vitest/browser-preview` from every dependency field. A tsdown plugin that lists `tsdown` in both `devDependencies` and `peerDependencies` loses both declarations, so the published package drops its `tsdown` peer and its own tests no longer run against a real tsdown. This PR replaces these packages only when they are devDependencies. A package that also lists one in `dependencies`, `optionalDependencies`, or `peerDependencies` keeps every declaration of it, including the development copy. Such a package publishes or runs the tool, and its consumers may not use Vite+. A kept `catalog:` reference becomes the range it pointed at, because migration still removes the catalog entry. This PR includes a shared `declaresRuntimeDependency` check in `migrator/shared.ts`. It replaces the Oxlint-only exception in both the fresh and existing Vite+ paths, and the tsx, oxnode, and ts-node runner check, which already followed this rule. Optional `oxlint` now counts as a runtime declaration too. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- docs/guide/migrate-rules.md | 4 +- .../src/migration/__tests__/migrator.spec.ts | 30 ++++++++-- .../oxlint-plugin-dependency.spec.ts | 6 +- .../src/migration/migrator/package-json.ts | 49 +++++----------- .../src/migration/migrator/script-runner.ts | 13 +---- packages/cli/src/migration/migrator/shared.ts | 58 ++++++++++++++++--- .../migration/migrator/vite-plus-bootstrap.ts | 36 ++---------- 7 files changed, 103 insertions(+), 93 deletions(-) diff --git a/docs/guide/migrate-rules.md b/docs/guide/migrate-rules.md index 94a87b558c..927c252076 100644 --- a/docs/guide/migrate-rules.md +++ b/docs/guide/migrate-rules.md @@ -135,6 +135,8 @@ What happens to each toolchain dependency, at a glance: | `@vitest/*` | Directly installed lockstep packages aligned to the bundled Vitest version (see [Vitest Ecosystem Packages](#vitest-ecosystem-packages)). | | `@voidzero-dev/vite-plus-test` | Removed everywhere: dependencies, overrides, resolutions, and catalog aliases. Imports are rewritten to the current `vite-plus/test*` surface. | +Vite+ bundles Oxlint, Oxfmt, tsdown, `@vitest/browser`, and `@vitest/browser-preview`, so migration removes their `devDependencies` entries. A package that also lists one of them in `dependencies`, `optionalDependencies`, or `peerDependencies` keeps every declaration of it, including the development copy. Such a package publishes or runs the tool, and its consumers may not use Vite+. A tsdown plugin, for example, keeps `tsdown` as a peer and as the devDependency it tests against. A kept `catalog:` reference becomes the range its catalog entry pointed at, because migration still removes that entry. + ### Version Selection - `vite-plus` is pinned to the concrete version of the CLI running the migration, never the `latest` dist-tag. @@ -239,7 +241,7 @@ The migration leaves three forms alone: - Default and namespace `oxlint` imports. They name no binding, so the migration cannot tell the two surfaces apart. - Bare side-effect `oxlint` imports, for the same reason. -The migration also skips a package that declares `oxlint` or `@oxlint/plugins` in `dependencies` or `peerDependencies`, or `@oxlint/plugins` in `optionalDependencies`. These dependencies can supply a published Oxlint plugin. Its consumers may not run Vite+. +The migration also skips a package that declares `oxlint` or `@oxlint/plugins` in `dependencies`, `optionalDependencies`, or `peerDependencies`. These dependencies can supply a published Oxlint plugin. Its consumers may not run Vite+. The cleanup retains a development dependency on `@oxlint/plugins` when source, package import aliases, or built plugins still reference it. This includes ignored output in directories such as `dist`, `build`, and `out`. diff --git a/packages/cli/src/migration/__tests__/migrator.spec.ts b/packages/cli/src/migration/__tests__/migrator.spec.ts index b306677972..1d1cfd42e1 100644 --- a/packages/cli/src/migration/__tests__/migrator.spec.ts +++ b/packages/cli/src/migration/__tests__/migrator.spec.ts @@ -272,7 +272,7 @@ describe('rewritePackageJson', () => { }; rewritePackageJson(pkg, packageManager, isMonorepo); expect(pkg).toEqual({ - dependencies: { foo: '1.0.0' }, + dependencies: { foo: '1.0.0', tsdown: '1.0.0' }, devDependencies: { 'vite-plus': vitePlusSpec }, }); }, @@ -529,9 +529,9 @@ describe('rewritePackageJson', () => { rewritePackageJson(pkg, PackageManager.pnpm, true); expect(pkg.peerDependencies.vite).toBe('*'); - expect(pkg.peerDependencies).not.toHaveProperty('tsdown'); + expect(pkg.peerDependencies).toHaveProperty('tsdown'); expect(pkg.optionalDependencies.vitest).toBe('catalog:test'); - expect(pkg.optionalDependencies).not.toHaveProperty('oxlint'); + expect(pkg.optionalDependencies).toHaveProperty('oxlint'); expect(pkg).toHaveProperty(['devDependencies', 'vite-plus'], 'catalog:'); }); @@ -5645,7 +5645,29 @@ describe('rewriteStandaloneProject pnpm workspace yaml', () => { // catalog entry to its public range before pruning it so the peer cannot // dangle after migration. expect(pkg).toHaveProperty(['peerDependencies', 'vitest'], '^4.0.0'); - expect(pkg.peerDependencies).not.toHaveProperty('tsdown'); + expect(pkg).toHaveProperty(['peerDependencies', 'tsdown'], '^0.1.0'); + }); + + // A tsdown plugin builds and tests against the tsdown its consumers provide. + it('keeps a bundled package that the project also declares as a peer', () => { + const packageJsonPath = path.join(tmpDir, 'package.json'); + fs.writeFileSync( + packageJsonPath, + JSON.stringify({ + name: 'tsdown-plugin-example', + peerDependencies: { tsdown: '^0.23.0' }, + devDependencies: { tsdown: '^0.23.0' }, + }), + ); + const workspace = makeWorkspaceInfo(tmpDir, PackageManager.pnpm); + + rewriteStandaloneProject(tmpDir, workspace, true, true); + + const pkg = readJson(packageJsonPath); + expect(pkg.peerDependencies).toEqual({ tsdown: '^0.23.0' }); + expect(pkg.devDependencies).toEqual({ tsdown: '^0.23.0', 'vite-plus': 'catalog:' }); + checkBootstrapPass(workspace, false); + expect(readJson(packageJsonPath)).toEqual(pkg); }); it('reuses catalogs.default without creating a duplicate top-level catalog', () => { diff --git a/packages/cli/src/migration/__tests__/oxlint-plugin-dependency.spec.ts b/packages/cli/src/migration/__tests__/oxlint-plugin-dependency.spec.ts index a25a90d576..7deac8001b 100644 --- a/packages/cli/src/migration/__tests__/oxlint-plugin-dependency.spec.ts +++ b/packages/cli/src/migration/__tests__/oxlint-plugin-dependency.spec.ts @@ -607,11 +607,11 @@ describe('Oxlint plugin dependency cleanup', () => { expect(pending()).toBe(false); }); - it('keeps optional oxlint on the existing tool-migration path', () => { + it('keeps optional oxlint as a runtime dependency', () => { const pkg = { optionalDependencies: { oxlint: '^1.79.0' } }; - expect(packageOwnsOxlintApi(pkg)).toBe(false); + expect(packageOwnsOxlintApi(pkg)).toBe(true); rewritePackageJson(pkg, PackageManager.pnpm); - expect(pkg.optionalDependencies).toEqual({}); + expect(pkg.optionalDependencies).toEqual({ oxlint: '^1.79.0' }); }); }); diff --git a/packages/cli/src/migration/migrator/package-json.ts b/packages/cli/src/migration/migrator/package-json.ts index 8842463c28..05a98f38a9 100644 --- a/packages/cli/src/migration/migrator/package-json.ts +++ b/packages/cli/src/migration/migrator/package-json.ts @@ -30,9 +30,9 @@ import { resolveProviderPeerSpec, OPT_IN_BROWSER_PROVIDERS, OXLINT_PLUGINS_PACKAGE, - OXLINT_PLUGIN_API_PACKAGES, packageOwnsOxlintApi, bundledPackagesToRemove, + removeBundledDevDependencies, VITEST_BROWSER_DEP_NAMES, VITEST_IS_MANAGED_OVERRIDE, } from './shared.ts'; @@ -186,43 +186,20 @@ export function rewritePackageJson( const hasBrowserDepSignal = VITEST_BROWSER_DEP_NAMES.some((name) => dependencyGroups.some(({ dependencies }) => dependencies?.[name] !== undefined), ); - // Published plugins keep their upstream imports and the dependencies that - // supply them, including optional @oxlint/plugins integrations. - const ownsOxlintApi = packageOwnsOxlintApi(pkg); - // Rewritten imports need a direct vite-plus dependency. Defer removal of - // @oxlint/plugins until dropDeadOxlintPluginsDependency checks the final source. - if (pkg.devDependencies?.[OXLINT_PLUGINS_PACKAGE] !== undefined && !ownsOxlintApi) { + // Rewritten imports need a direct vite-plus dependency, but published plugins + // keep their upstream imports. Defer removal of @oxlint/plugins until + // dropDeadOxlintPluginsDependency checks the final source. + if (pkg.devDependencies?.[OXLINT_PLUGINS_PACKAGE] !== undefined && !packageOwnsOxlintApi(pkg)) { needVitePlus = true; } - // remove packages that are replaced with vite-plus - for (const name of bundledPackagesToRemove(retainedBrowserPackages)) { - let wasRemoved = false; - for (const { dependencyField, dependencies } of dependencyGroups) { - if ( - ownsOxlintApi && - (dependencyField === 'peerDependencies' || dependencyField === 'dependencies') && - (OXLINT_PLUGIN_API_PACKAGES as ReadonlyArray).includes(name) - ) { - // A `catalog:` reference would dangle once the catalog entry for a - // REMOVE_PACKAGES name is dropped, and the next install fails. Resolve - // it to the concrete range the catalog currently points at. - const current = dependencies?.[name]; - if (current?.startsWith('catalog:') && dependencies) { - const resolved = catalogDependencyResolver?.(current, name); - if (resolved) { - dependencies[name] = resolved; - } - } - continue; - } - if (dependencies?.[name]) { - delete dependencies[name]; - wasRemoved = true; - } - } - if (wasRemoved) { - needVitePlus = true; - } + if ( + removeBundledDevDependencies( + pkg, + bundledPackagesToRemove(retainedBrowserPackages), + catalogDependencyResolver, + ) + ) { + needVitePlus = true; } // Official opt-in providers remain project dependencies. Align their versions // with bundled Vitest and ensure the framework peer required by each shim. diff --git a/packages/cli/src/migration/migrator/script-runner.ts b/packages/cli/src/migration/migrator/script-runner.ts index 69f465ee9b..3939a4e43c 100644 --- a/packages/cli/src/migration/migrator/script-runner.ts +++ b/packages/cli/src/migration/migrator/script-runner.ts @@ -15,6 +15,7 @@ import { sourceTreeMatches } from '../migrator.ts'; import type { MigrationReport } from '../report.ts'; import type { DependencyBag } from './shared.ts'; import { + declaresRuntimeDependency, getCommandStartIndex, isPlainRecord, LINT_STAGED_JSON_CONFIG_FILES, @@ -944,17 +945,9 @@ function lintStagedJsonFiles(dir: string): Array { ); } -/** - * A package that lists a runner outside devDependencies keeps it: published code or - * production scripts can need it, and `vpx` comes from the vite-plus devDependency. - */ +// `vpx` comes from the vite-plus devDependency, so it cannot replace a runner the package needs at runtime. function ownsRunnerAtRuntime(runner: ScriptRunnerMigration, pkg: DependencyBag): boolean { - return runner.dependencies.some( - (dependency) => - pkg.dependencies?.[dependency] !== undefined || - pkg.optionalDependencies?.[dependency] !== undefined || - pkg.peerDependencies?.[dependency] !== undefined, - ); + return runner.dependencies.some((dependency) => declaresRuntimeDependency(pkg, dependency)); } function packageDirs(rootDir: string, packages?: ReadonlyArray): Array { diff --git a/packages/cli/src/migration/migrator/shared.ts b/packages/cli/src/migration/migrator/shared.ts index f136365131..c861db0455 100644 --- a/packages/cli/src/migration/migrator/shared.ts +++ b/packages/cli/src/migration/migrator/shared.ts @@ -469,23 +469,63 @@ export function pnpmMajor(version: string | undefined): number | undefined { return version ? coerce(version)?.major : undefined; } -// Packages that own the Oxlint JS-plugin authoring API as a published contract. -// Optional `@oxlint/plugins` is also a runtime contract for consumers of a -// published integration. Optional `oxlint` keeps the existing tool policy. export const OXLINT_PLUGINS_PACKAGE = '@oxlint/plugins'; -export const OXLINT_PLUGIN_API_PACKAGES = ['oxlint', OXLINT_PLUGINS_PACKAGE] as const; +const OXLINT_PLUGIN_API_PACKAGES = ['oxlint', OXLINT_PLUGINS_PACKAGE] as const; +// A package that declares either at runtime owns the Oxlint JS-plugin authoring API as a published contract. export function packageOwnsOxlintApi(pkg: DependencyBag): boolean { + return OXLINT_PLUGIN_API_PACKAGES.some((name) => declaresRuntimeDependency(pkg, name)); +} + +/** + * Vite+ replaces only a devDependency. A package that also lists it in + * `dependencies`, `optionalDependencies`, or `peerDependencies` publishes or + * runs it, and its consumers may not use Vite+. + */ +export function declaresRuntimeDependency(pkg: DependencyBag, name: string): boolean { return ( - pkg.optionalDependencies?.[OXLINT_PLUGINS_PACKAGE] !== undefined || - OXLINT_PLUGIN_API_PACKAGES.some( - (name) => - pkg.dependencies?.[name] !== undefined || pkg.peerDependencies?.[name] !== undefined, - ) + pkg.dependencies?.[name] !== undefined || + pkg.optionalDependencies?.[name] !== undefined || + pkg.peerDependencies?.[name] !== undefined ); } +/** + * Remove the bundled packages that Vite+ replaces. Returns whether the package + * lists any of them as a devDependency, kept or not. + */ +export function removeBundledDevDependencies( + pkg: DependencyBag, + names: ReadonlyArray, + catalogDependencyResolver?: CatalogDependencyResolver, +): boolean { + let declared = false; + for (const name of names) { + declared ||= pkg.devDependencies?.[name] !== undefined; + if (!declaresRuntimeDependency(pkg, name)) { + delete pkg.devDependencies?.[name]; + continue; + } + // Catalog cleanup deletes the bundled entry, so a kept reference takes the range it pointed at. + for (const dependencies of [ + pkg.devDependencies, + pkg.dependencies, + pkg.optionalDependencies, + pkg.peerDependencies, + ]) { + const current = dependencies?.[name]; + const resolved = current?.startsWith('catalog:') + ? catalogDependencyResolver?.(current, name) + : undefined; + if (dependencies && resolved) { + dependencies[name] = resolved; + } + } + } + return declared; +} + /** * Capture plugin owners before manifest edits, so the import rewriter can * preserve their upstream API imports after those edits. diff --git a/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts b/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts index bcb0737a07..2eef23d7d2 100644 --- a/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts +++ b/packages/cli/src/migration/migrator/vite-plus-bootstrap.ts @@ -75,9 +75,8 @@ import { hasProviderPeerDependency, resolveProviderPeerSpec, OPT_IN_BROWSER_PROVIDERS, - OXLINT_PLUGIN_API_PACKAGES, - packageOwnsOxlintApi, bundledPackagesToRemove, + removeBundledDevDependencies, VITEST_IS_MANAGED_OVERRIDE, managedOverrideKey, pinnedPackageManagerVersion, @@ -394,34 +393,11 @@ function reconcileVitePlusBootstrapPackage( // Match the fresh migration and catalog cleanup. A preserved browser import // still needs its declared browser dependency in this package. - const ownsOxlintApi = packageOwnsOxlintApi(pkg); - for (const bundledPackage of bundledPackagesToRemove( - retainedImportDependencies?.browser.get(projectPath), - )) { - for (const dependencies of installGroups) { - if ( - ownsOxlintApi && - dependencies !== undefined && - dependencies === pkg.dependencies && - (OXLINT_PLUGIN_API_PACKAGES as ReadonlyArray).includes(bundledPackage) - ) { - // A published plugin keeps the runtime dependency that supplies its - // upstream imports, as the fresh path does. Its `catalog:` reference - // becomes the concrete range because the catalog entry is deleted. - const current = dependencies[bundledPackage]; - if (current?.startsWith('catalog:')) { - const resolved = catalogDependencyResolver?.(current, bundledPackage); - if (resolved) { - dependencies[bundledPackage] = resolved; - } - } - continue; - } - if (dependencies?.[bundledPackage] !== undefined) { - delete dependencies[bundledPackage]; - } - } - } + removeBundledDevDependencies( + pkg, + bundledPackagesToRemove(retainedImportDependencies?.browser.get(projectPath)), + catalogDependencyResolver, + ); if (usesAnyOptInProvider && packageManager === PackageManager.npm) { const viteAlreadyDirect = installGroups.some( From 7d75a566691df3f805ab6698d12900a06b997730 Mon Sep 17 00:00:00 2001 From: Liang Date: Sat, 28 Nov 2026 17:43:13 +0800 Subject: [PATCH 2/2] ci: retry macOS launcher snapshot