Commit c509482
authored
fix(create/migrate): wrap migrated Vite plugins with lazyPlugins (#1752)
## Summary
Fixes #1739 by preventing Vite plugin factories from being eagerly
executed during lint/format/check workflows.
This teaches create/migrate to wrap safe inline Vite plugin arrays with
`lazyPlugins`, so commands like `vp check --fix` and `vp staged` do not
hang when a plugin leaves open handles during config loading.
## Changes
- Add a conservative Rust transform for Vite configs:
- wraps direct inline `plugins: [...]` arrays as `lazyPlugins(() =>
[...])`
- uses `lazyPlugins(async () => [...])` when the array contains `await`
- skips CommonJS configs, dynamic plugin references, nested unsupported
shapes, and existing conflicting `lazyPlugins` bindings
- reuses or adds `lazyPlugins` imports from `vite-plus` without
duplicating imports
- Expose the transform through the CLI NAPI binding.
- Apply the rewrite in standalone and monorepo create/migrate paths.
- Surface the rewrite in migration reporting.
- Add regression coverage for standalone, monorepo, unsupported
expressions, `staged`, and import edge cases.
## Why
Issue #1739 showed this path:
```txt
vp staged
→ vp check --fix
→ vp lint
→ loads vite.config.ts
→ plugin factories execute eagerly
→ plugins like nitro can leave open handles
→ command hangs
```
Wrapping generated/migrated inline plugins with `lazyPlugins` keeps
plugin factories from running for `lint`, `fmt`, `check`, and `staged`,
while preserving normal plugin execution for `dev`, `build`, `test`, and
`preview`.
## Validation
- `cargo fmt --check`
- `cargo test -p vite_migration`
- `vp test packages/cli/src/migration/__tests__/migrator.spec.ts
packages/cli/src/__tests__/index.spec.ts`1 parent 1dc01bb commit c509482
21 files changed
Lines changed: 991 additions & 24 deletions
File tree
- crates/vite_migration/src
- packages/cli
- binding
- src
- snap-tests-global
- migration-lazy-plugins-await
- migration-merge-vite-config-js
- migration-merge-vite-config-ts
- migration-monorepo-bun
- migration-monorepo-pnpm-overrides-dependency-selector
- migration-monorepo-pnpm
- migration-monorepo-yarn4
- new-create-vite-migrates-eslint-prettier
- src
- __tests__
- migration
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments