Commit b8bd487
authored
feat(migration): rewrite vitest imports (#350)
Add support for rewriting imports from vite/vitest to @voidzero-dev/vite-plus across an entire project:
- Add `ignore` crate dependency for gitignore-aware directory walking
- Create `file_walker.rs` module with `find_ts_files()` function to locate TypeScript/JavaScript files
- Create `import_rewriter.rs` module with comprehensive import rewriting rules:
- `vite` → `@voidzero-dev/vite-plus`
- `vite/{name}` → `@voidzero-dev/vite-plus/{name}`
- `vitest` → `@voidzero-dev/vite-plus/test`
- `vitest/config` → `@voidzero-dev/vite-plus`
- `vitest/{name}` → `@voidzero-dev/vite-plus/test/{name}`
- `@vitest/browser` → `@voidzero-dev/vite-plus/test/browser`
- `@vitest/browser/{name}` → `@voidzero-dev/vite-plus/test/browser/{name}`
- `@vitest/browser-playwright` → `@voidzero-dev/vite-plus/test/browser-playwright`
- `@vitest/browser-playwright/{name}` → `@voidzero-dev/vite-plus/test/browser-playwright/{name}`
- Add `rewrite_imports_in_directory()` function for batch processing all files
- Add snap test for vitest migration
- Update RFC documentation with detailed import rewriting rules
This enables the migration command to automatically rewrite all imports in a project, making it much easier for users to migrate from vite/vitest to vite-plus.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Introduces automated, project-wide import rewriting from `vite`/`vitest` (incl. subpaths and `@vitest/*`) to `@voidzero-dev/vite-plus`.
>
> - **New**: `find_ts_files()` in `vite_migration/file_walker.rs` using `ignore` to respect `.gitignore`/global/exclude
> - **New**: `import_rewriter.rs` with ast-grep rules covering `vite`, `vite/{name}`, `vitest`, `vitest/config`, `vitest/{name}`, and `@vitest/...` → mapped `@voidzero-dev/vite-plus` equivalents
> - **API**: Expose `rewrite_imports_in_directory()` from Rust and NAPI (`rewriteImportsInDirectory`), plus `BatchRewriteResult`/`BatchRewriteError` types; add `ignore::Error` to `vite_error::Error`
> - **CLI**: Migration now runs project-wide rewriting and logs modified files; removes per-file rewrite path; extends package removal to `@vitest/browser*`
> - **Tests/Docs**: Add unit tests for walker/rewriter, update snap tests to assert new output, and expand RFC with detailed rewrite rules
>
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 4653d5e. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 317d019 commit b8bd487
26 files changed
Lines changed: 1320 additions & 313 deletions
File tree
- crates
- vite_error
- src
- vite_migration
- src
- packages/global
- binding
- src
- snap-tests
- migration-from-vitest
- test
- migration-merge-vite-config-ts
- migration-monorepo-pnpm-overrides-dependency-selector
- migration-monorepo-pnpm
- migration-monorepo-yarn4
- src/migration
- rfcs
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
0 commit comments