Skip to content

Commit 29897cd

Browse files
authored
feat(migration): add declare module rewriting support (#357)
Add support for rewriting TypeScript `declare module` statements from vite/vitest to @voidzero-dev/vite-plus. This mirrors the existing import rewriting functionality but targets module declarations. Changes: - Add 6 new ast-grep rules for declare module statements - Update documentation to include declare module examples - Add 19 comprehensive tests covering all patterns - Support all variants: base modules, subpaths, and scoped packages The implementation uses ast-grep with `kind: module` to match declare module statements and rewrites module names using the same transformation logic as import statements. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds declare-module rewriting alongside existing import rewrites. > > - **Rules**: +6 ast-grep rules targeting `declare module` for `vite`, `vite/*`, `vitest`, `vitest/config`, `vitest/*`, and `@vitest/*` variants; matches with `kind: module` and rewrites to the corresponding `@voidzero-dev/vite-plus` targets > - **Code**: Updates `import_rewriter.rs` rule set and docs to include declare-module cases; core rewrite pipeline unchanged > - **Tests**: +new unit tests covering single, subpath, scoped, mixed import+declare scenarios, and edge cases (quotes, complex interfaces) > - **Snap tests**: Adds scenarios `migration-from-vitest-config`, `migration-from-vitest-files`, and `migration-rewrite-declare-module` with updated expected outputs (rewritten module declarations and imports) > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit e3a2603. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent b8bd487 commit 29897cd

13 files changed

Lines changed: 753 additions & 19 deletions

File tree

crates/vite_migration/src/import_rewriter.rs

Lines changed: 569 additions & 1 deletion
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "migration-from-vitest-config",
3+
"devDependencies": {
4+
"vite": "^7.0.0",
5+
"vitest": "^4.0.0",
6+
"@vitest/browser": "^4.0.0",
7+
"@vitest/browser-playwright": "^4.0.0"
8+
},
9+
"scripts": {
10+
"test:run": "vitest run",
11+
"test:ui": "vitest --ui",
12+
"test:coverage": "vitest run --coverage",
13+
"test:watch": "vitest --watch",
14+
"test": "vitest"
15+
}
16+
}

packages/global/snap-tests/migration-from-vitest/snap.txt renamed to packages/global/snap-tests/migration-from-vitest-config/snap.txt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
88
● pnpm@<semver> installed
99
10-
◆ ✅ Rewrote imports in 2 file(s)
10+
◆ ✅ Rewrote imports in 1 file(s)
1111
12-
● test/hello.ts
13-
│ vitest.config.ts
12+
● vitest.config.ts
1413
1514
└ ✨ Migration completed!
1615

@@ -42,7 +41,7 @@ export default defineConfig({
4241

4342
> cat package.json # check package.json
4443
{
45-
"name": "migration-from-vitest",
44+
"name": "migration-from-vitest-config",
4645
"devDependencies": {
4746
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
4847
"vitest": "npm:@voidzero-dev/vite-plus-test@latest",
@@ -63,15 +62,3 @@ export default defineConfig({
6362
},
6463
"packageManager": "pnpm@<semver>"
6564
}
66-
67-
> cat test/hello.ts # check test/hello.ts
68-
import { server } from '@voidzero-dev/vite-plus/test/browser-playwright/context';
69-
import { test, describe, expect, it } from '@voidzero-dev/vite-plus/test';
70-
71-
const { readFile } = server.commands;
72-
73-
describe('Hello', () => {
74-
it('should return the correct result', () => {
75-
expect(true).toBe(true);
76-
});
77-
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"env": {
3+
"VITE_DISABLE_AUTO_INSTALL": "1"
4+
},
5+
"commands": [
6+
"vp migration # migration should rewrite imports to vite-plus",
7+
"cat vitest.config.ts # check vitest.config.ts",
8+
"cat package.json # check package.json"
9+
]
10+
}

packages/global/snap-tests/migration-from-vitest/vitest.config.ts renamed to packages/global/snap-tests/migration-from-vitest-config/vitest.config.ts

File renamed without changes.

packages/global/snap-tests/migration-from-vitest/package.json renamed to packages/global/snap-tests/migration-from-vitest-files/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "migration-from-vitest",
2+
"name": "migration-from-vitest-files",
33
"devDependencies": {
44
"vite": "^7.0.0",
55
"vitest": "^4.0.0",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
> vp migration # migration should rewrite imports to vite-plus
2+
┌ Vite+ Migration
3+
4+
● Using default package manager: pnpm
5+
6+
● pnpm@latest installing...
7+
8+
● pnpm@<semver> installed
9+
10+
◆ ✅ Rewrote imports in 1 file(s)
11+
12+
● test/hello.ts
13+
14+
└ ✨ Migration completed!
15+
16+
17+
> cat package.json # check package.json
18+
{
19+
"name": "migration-from-vitest-files",
20+
"devDependencies": {
21+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
22+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest",
23+
"@voidzero-dev/vite-plus": "latest"
24+
},
25+
"scripts": {
26+
"test:run": "vite test run",
27+
"test:ui": "vite test --ui",
28+
"test:coverage": "vite test run --coverage",
29+
"test:watch": "vite test --watch",
30+
"test": "vite test"
31+
},
32+
"pnpm": {
33+
"overrides": {
34+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
35+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
36+
}
37+
},
38+
"packageManager": "pnpm@<semver>"
39+
}
40+
41+
> cat test/hello.ts # check test/hello.ts
42+
import { server } from '@voidzero-dev/vite-plus/test/browser-playwright/context';
43+
import { test, describe, expect, it } from '@voidzero-dev/vite-plus/test';
44+
45+
const { readFile } = server.commands;
46+
47+
describe('Hello', () => {
48+
it('should return the correct result', () => {
49+
expect(true).toBe(true);
50+
});
51+
});

packages/global/snap-tests/migration-from-vitest/steps.json renamed to packages/global/snap-tests/migration-from-vitest-files/steps.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
},
55
"commands": [
66
"vp migration # migration should rewrite imports to vite-plus",
7-
"cat vitest.config.ts # check vitest.config.ts",
87
"cat package.json # check package.json",
98
"cat test/hello.ts # check test/hello.ts"
109
]

packages/global/snap-tests/migration-from-vitest/test/hello.ts renamed to packages/global/snap-tests/migration-from-vitest-files/test/hello.ts

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "migration-rewrite-declare-module"
3+
}

0 commit comments

Comments
 (0)