Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
name = "migration_eslint_monorepo_plugins_in_packages"
vp = "global"
steps = [
{ argv = ["vp", "migrate", "--no-interactive"], comment = "workspace packages get the SAME aggressive cleanup as the root (deps, configs, lint-staged)", continue-on-failure = true },
{ argv = ["vp", "migrate", "--no-interactive"], comment = "migrate ESLint across the workspace", continue-on-failure = true },
{ argv = ["vpt", "print-file", "package.json"], comment = "root: eslint + eslint-config-airbnb removed", continue-on-failure = true },
{ argv = ["vpt", "print-file", "packages/app/package.json"], comment = "workspace: eslint, eslint-plugin-vue, @typescript-eslint/parser removed; @typescript-eslint/utils preserved (reusable AST lib)", continue-on-failure = true },
{ argv = ["vpt", "print-file", "packages/lint-config/package.json"], comment = "workspace: all eslint-plugin-* removed; peerDeps.eslint scrubbed (field deleted when empty)", continue-on-failure = true },
{ argv = ["vpt", "print-file", "packages/lint-config/package.json"], comment = "the shared lint config keeps its plugin dependencies and ESLint peer", continue-on-failure = true },
{ argv = ["vpt", "stat-file", "packages/app/eslint.config.mjs", "--assert-not", "file"], comment = "workspace eslint config is deleted", continue-on-failure = true },
{ argv = ["vpt", "print-file", "packages/app/.lintstagedrc.json"], comment = "workspace lint-staged rewritten (eslint --fix → vp lint --fix)", continue-on-failure = true },
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## `vp migrate --no-interactive`

workspace packages get the SAME aggressive cleanup as the root (deps, configs, lint-staged)
migrate ESLint across the workspace

```
VITE+ - The Unified Toolchain for the Web
Expand Down Expand Up @@ -55,13 +55,21 @@ workspace: eslint, eslint-plugin-vue, @typescript-eslint/parser removed; @typesc

## `vpt print-file packages/lint-config/package.json`

workspace: all eslint-plugin-* removed; peerDeps.eslint scrubbed (field deleted when empty)
the shared lint config keeps its plugin dependencies and ESLint peer

```
{
"name": "@test/lint-config",
"scripts": {
"lint": "vp lint ."
},
"dependencies": {
"@stylistic/eslint-plugin": "^2.0.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-vue": "^10.0.0"
},
"peerDependencies": {
"eslint": ">=9"
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name = "migration_eslint_plugins_cleanup"
vp = "global"
steps = [
{ argv = ["vp", "migrate", "--no-interactive"], comment = "migration should remove ESLint, plugins, configs, scopes, formatters, and peer eslint", continue-on-failure = true },
{ argv = ["vpt", "print-file", "package.json"], comment = "verify the comprehensive ESLint ecosystem cleanup", continue-on-failure = true },
{ argv = ["vp", "migrate", "--no-interactive"], comment = "migrate the ESLint configuration", continue-on-failure = true },
{ argv = ["vpt", "print-file", "package.json"], comment = "remove dev-only ESLint tooling and keep both declarations of the ESLint peer", continue-on-failure = true },
{ argv = ["vpt", "stat-file", "eslint.config.mjs", "--assert-not", "file"], comment = "check eslint config is removed", continue-on-failure = true },
{ argv = ["vpt", "print-file", "vite.config.ts"], comment = "verify the generated vite.config.ts", continue-on-failure = true },
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## `vp migrate --no-interactive`

migration should remove ESLint, plugins, configs, scopes, formatters, and peer eslint
migrate the ESLint configuration

```
VITE+ - The Unified Toolchain for the Web
Expand All @@ -16,7 +16,7 @@ VITE+ - The Unified Toolchain for the Web

## `vpt print-file package.json`

verify the comprehensive ESLint ecosystem cleanup
remove dev-only ESLint tooling and keep both declarations of the ESLint peer

```
{
Expand All @@ -32,9 +32,13 @@ verify the comprehensive ESLint ecosystem cleanup
"@types/node": "^22.0.0",
"@typescript-eslint/utils": "^8.0.0",
"@vitejs/plugin-vue": "^6.0.0",
"eslint": "^9.0.0",
"vite": "catalog:",
"vue": "^3.5.0",
"vite-plus": "catalog:"
},
"peerDependencies": {
"eslint": ">=9"
}
}
```
Expand Down
63 changes: 34 additions & 29 deletions crates/vp_migration/src/import_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2066,10 +2066,10 @@ struct SkipPackages {
skip_vite: bool,
/// Skip rewriting vitest imports (vitest is in peerDependencies or dependencies)
skip_vitest: bool,
/// Skip rewriting tsdown imports (tsdown is in peerDependencies or dependencies)
/// Skip rewriting tsdown imports (tsdown is in dependencies, optionalDependencies, or peerDependencies)
skip_tsdown: bool,
/// Skip rewriting Oxlint JS-plugin API imports (`oxlint` or `@oxlint/plugins`
/// is in peerDependencies or dependencies, or @oxlint/plugins is optional).
/// is in dependencies, optionalDependencies, or peerDependencies).
/// Published plugin consumers may not have Vite+. DevDependencies alone
/// do not mark a published plugin and do not prevent rewriting.
skip_oxlint: bool,
Expand All @@ -2090,9 +2090,9 @@ pub struct RewriteImportsOptions {
/// whose nearest package.json declares `@nuxt/test-utils`.
pub preserve_vitest_in_nuxt_packages: bool,
/// Directories of packages that declared `oxlint` or `@oxlint/plugins` in
/// `dependencies` or `peerDependencies`, or optional `@oxlint/plugins`,
/// before migration. Capture these before manifest edits so ownership
/// does not depend on which dependency declarations survive those edits.
/// `dependencies`, `optionalDependencies`, or `peerDependencies` before
/// migration. Capture these before manifest edits so ownership does not
/// depend on which dependency declarations survive those edits.
pub oxlint_owner_dirs: Vec<PathBuf>,
}

Expand Down Expand Up @@ -2266,10 +2266,18 @@ fn get_package_rewrite_context(package_json_path: &Path) -> PackageRewriteContex
.and_then(|v| v.as_object())
.is_some_and(|deps| deps.contains_key(package_name))
};
// Matches `declaresRuntimeDependency` in `migrator/shared.ts`: such a package keeps its
// declaration of a bundled tool, so its imports must keep resolving to that tool.
let declares_runtime = |package_name: &str| -> bool {
["dependencies", "optionalDependencies", "peerDependencies"]
.into_iter()
.any(|key| has_package(key, package_name))
};

// Peer and runtime dependencies preserve the existing whole-package skip
// behavior. Nuxt compatibility is narrower and accepts the three install
// groups where @nuxt/test-utils is normally declared.
// behavior; bundled tools also count optional declarations. Nuxt
// compatibility is narrower and accepts the three install groups where
// @nuxt/test-utils is normally declared.
//
// `vite` is additionally skipped when the package follows a published-plugin
// naming convention: an unscoped name starting with `vite-plugin-`
Expand All @@ -2288,13 +2296,8 @@ fn get_package_rewrite_context(package_json_path: &Path) -> PackageRewriteContex
|| package_name_is_plugin(&pkg),
skip_vitest: has_package("peerDependencies", "vitest")
|| has_package("dependencies", "vitest"),
skip_tsdown: has_package("peerDependencies", "tsdown")
|| has_package("dependencies", "tsdown"),
skip_oxlint: has_package("peerDependencies", "oxlint")
|| has_package("dependencies", "oxlint")
|| has_package("peerDependencies", "@oxlint/plugins")
|| has_package("dependencies", "@oxlint/plugins")
|| has_package("optionalDependencies", "@oxlint/plugins"),
skip_tsdown: declares_runtime("tsdown"),
skip_oxlint: declares_runtime("oxlint") || declares_runtime("@oxlint/plugins"),
},
uses_nuxt_test_utils: ["dependencies", "devDependencies", "optionalDependencies"]
.into_iter()
Expand Down Expand Up @@ -5042,23 +5045,25 @@ export default defineConfig({});"#;
}

#[test]
fn test_optional_oxlint_keeps_existing_rewrite_policy() {
let temp = tempdir().unwrap();
std::fs::write(
temp.path().join("package.json"),
r#"{"optionalDependencies":{"oxlint":"^1.79.0"}}"#,
)
.unwrap();
let file = temp.path().join("plugin.js");
std::fs::write(&file, "import { defineRule } from 'oxlint';").unwrap();
fn test_optional_bundled_tools_keep_upstream_imports() {
for (package, content) in [
("oxlint", "import { defineRule } from 'oxlint';"),
("tsdown", "const { build } = await import('tsdown');"),
] {
let temp = tempdir().unwrap();
std::fs::write(
temp.path().join("package.json"),
format!(r#"{{"optionalDependencies":{{"{package}":"*"}}}}"#),
)
.unwrap();
let file = temp.path().join("index.js");
std::fs::write(&file, content).unwrap();

let result = rewrite_imports_in_directory(temp.path()).unwrap();
let result = rewrite_imports_in_directory(temp.path()).unwrap();

assert_eq!(result.modified_files, vec![file.clone()]);
assert_eq!(
std::fs::read_to_string(file).unwrap(),
"import { defineRule } from 'vite-plus/lint/plugins';"
);
assert!(result.modified_files.is_empty(), "{package}");
assert_eq!(std::fs::read_to_string(file).unwrap(), content);
}
}

#[test]
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/migrate-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ 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. Its `tsdown` imports also stay unchanged instead of moving to `vite-plus/pack`. Migration also keeps the catalog entries for these declarations, so a kept `catalog:` reference still resolves.

The same rule applies to the tools that migration replaces: ESLint and its plugins, Prettier and `prettier-plugin-*`, lint-staged, tsup, tsx, oxnode, and ts-node. A package that keeps tsup also keeps its tsup config and scripts, because migration does not run `tsdown-migrate` there.

### Version Selection

- `vite-plus` is pinned to the concrete version of the CLI running the migration, never the `latest` dist-tag.
Expand Down Expand Up @@ -239,7 +243,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`.

Expand Down
12 changes: 5 additions & 7 deletions packages/cli/src/__tests__/oxlint-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ new RuleTester({
`export { 'defineRule' as rule } from 'oxlint'`,
`import { RuleTester } from 'oxlint/plugins-dev'`,
].map((code) => ({ code, filename: oxlintOptionalPluginPackageFilename })),
// Migration keeps optional `oxlint`, so its plugin API imports stay upstream too.
{
code: `import { defineRule } from 'oxlint'`,
filename: oxlintOptionalToolPackageFilename,
},
// `declare module` keeps the upstream module identity, so augmentations
// still merge with the upstream declarations.
{
Expand Down Expand Up @@ -447,13 +452,6 @@ new RuleTester({
},
],
invalid: [
{
// Optional oxlint retains the existing tool-migration policy.
code: `import { defineRule } from 'oxlint'`,
filename: oxlintOptionalToolPackageFilename,
errors: 1,
output: `import { defineRule } from 'vite-plus/lint/plugins'`,
},
{
code: `import { definePlugin, defineRule } from '@oxlint/plugins'`,
errors: 1,
Expand Down
Loading
Loading