Skip to content
Merged
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
39 changes: 38 additions & 1 deletion crates/vp_migration/src/import_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ rule:
pattern: $STR
kind: string
regex: ^['"]vite/.+['"]$
not:
regex: ^['"]vite/rolldown(/.*)?['"]$
inside:
kind: import_statement
transform:
Expand All @@ -128,6 +130,8 @@ rule:
pattern: $STR
kind: string
regex: ^['"]vite/.+['"]$
not:
regex: ^['"]vite/rolldown(/.*)?['"]$
inside:
kind: export_statement
transform:
Expand All @@ -144,6 +148,8 @@ rule:
pattern: $STR
kind: string
regex: ^['"]vite/.+['"]$
not:
regex: ^['"]vite/rolldown(/.*)?['"]$
inside:
kind: arguments
inside:
Expand All @@ -165,6 +171,8 @@ rule:
pattern: $STR
kind: string
regex: ^['"]vite/.+['"]$
not:
regex: ^['"]vite/rolldown(/.*)?['"]$
inside:
kind: arguments
inside:
Expand Down Expand Up @@ -202,6 +210,8 @@ rule:
pattern: $STR
kind: string
regex: ^['\"]vite/.+['\"]$
not:
regex: ^['"]vite/rolldown(/.*)?['"]$
inside:
kind: module
transform:
Expand Down Expand Up @@ -1738,6 +1748,11 @@ static RE_REF_VITE_SUBPATH: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"^(\s*///\s*<reference\s+types\s*=\s*["'])vite/(.+?)(["']\s*/>)"#).unwrap()
});

/// `vite/rolldown[/...]` is not re-exported by `vite-plus`, so it stays untouched.
static RE_REF_VITE_ROLLDOWN: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"^\s*///\s*<reference\s+types\s*=\s*["']vite/rolldown(/[^"']*)?["']"#).unwrap()
});

/// bare `tsdown` → `vite-plus/pack`
static RE_REF_TSDOWN: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"^(\s*///\s*<reference\s+types\s*=\s*["'])tsdown(["']\s*/>)"#).unwrap()
Expand Down Expand Up @@ -1986,7 +2001,9 @@ fn rewrite_reference_types(
}
}
if !skip_packages.skip_vite {
if apply_regex_replace(line, &RE_REF_VITE_SUBPATH, "${1}vite-plus/${2}${3}") {
if !RE_REF_VITE_ROLLDOWN.is_match(line)
&& apply_regex_replace(line, &RE_REF_VITE_SUBPATH, "${1}vite-plus/${2}${3}")
{
changed = true;
continue;
}
Expand Down Expand Up @@ -3305,6 +3322,26 @@ export default ModuleRunner;"#
);
}

#[test]
fn test_rewrite_import_content_vite_rolldown_subpath_is_kept() {
let vite_config = r#"/// <reference types="vite/rolldown/plugins" />
import "vite/rolldown/plugins";
import { viteAliasPlugin } from 'vite/rolldown/plugins';
import 'vite/rolldown';
export * from "vite/rolldown/utils";
const a = require('vite/rolldown/plugins');
const b = await import('vite/rolldown/plugins');
declare module 'vite/rolldown/plugins' {}
import { ModuleRunner } from 'vite/module-runner';"#;

let result = rewrite_import_content(vite_config, &SkipPackages::default()).unwrap();
assert!(result.updated);
assert_eq!(
result.content,
vite_config.replace("'vite/module-runner'", "'vite-plus/module-runner'")
);
}

#[test]
fn test_rewrite_import_content_vite_subpath_double_quotes() {
let vite_config = r#"import { ModuleRunner } from "vite/module-runner";
Expand Down
2 changes: 2 additions & 0 deletions docs/guide/migrate-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ Object-valued nested npm and Bun overrides are preserved: they are user-defined

Plugin packages (an unscoped name starting with `vite-plugin-` or `unplugin-`, or `vite` in `peerDependencies`/`dependencies`) skip the rewrite even in config files. Only the `vite` specifier is in scope for this rule.

`vite/rolldown` and `vite/rolldown/*` are never rewritten, because `vite-plus` does not export those subpaths; they keep resolving through the core alias.

`declare module 'vite'` augmentations follow the same rule and are preserved outside config files. Through the core alias they reach the same `@voidzero-dev/vite-plus-core` module whose `UserConfig` types `defineConfig` from `vite-plus`, so they keep working after migration; `vite-plus` itself exports no `UserConfig` symbol, so a rewritten `declare module 'vite-plus'` augmentation would merge with nothing. Extensions aimed at `vite-plus`'s own surface are written against `vite-plus` by hand.

### `vitest` and Browser Imports
Expand Down
Loading