Skip to content

Commit c509482

Browse files
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/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ mod vite_config;
1818
pub use file_walker::{WalkResult, find_ts_files};
1919
pub use import_rewriter::{BatchRewriteResult, rewrite_imports_in_directory};
2020
pub use package::{rewrite_eslint, rewrite_prettier, rewrite_scripts};
21-
pub use vite_config::{MergeResult, has_config_key, merge_json_config, merge_tsdown_config};
21+
pub use vite_config::{
22+
MergeResult, has_config_key, merge_json_config, merge_tsdown_config, wrap_lazy_plugins,
23+
};

0 commit comments

Comments
 (0)