Commit 0131832
authored
feat: migration config to vite.config.ts (#320)
This PR adds functionality to migrate standalone configuration files (`.oxlintrc`, `.oxfmtrc`) into the unified vite.config.ts format. The implementation:
- Adds TypeScript language support to ast-grep for parsing config files
- Creates AST-based rules for merging JSON configs into vite.config.ts
- Handles various config formats including object literals, function callbacks, and plain exports
- Properly converts JSON to TypeScript object literals with correct formatting
- Exposes a new `mergeJsonConfig` function in the binding API
- Updates the migration process to automatically merge configs when detected
The implementation handles edge cases like trailing commas, function callbacks, and different export styles to ensure reliable migration.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds AST-driven migration that merges .oxlintrc/.oxfmtrc into vite.config, rewrites vite/vitest imports to vite-plus, exposes merge/rewrite APIs in bindings, and updates CLI with version checks and new workflow with tests.
>
> - **Migration Engine (Rust `vite_migration`)**:
> - Add TypeScript parsing support via `ast-grep` features.
> - Implement `merge_json_config` and `rewrite_import` with AST rules to:
> - Merge `.oxlintrc`/`.oxfmtrc` into `defineConfig` (supports object, function callbacks, plain exports, return vars, satisfies).
> - Rewrite `import ... from 'vite'` and `'vitest/config'` to `'@voidzero-dev/vite-plus'`.
> - Include reusable rule files: `rules/oxlint-*.yaml`, `rules/rewrite-import.yaml`.
> - **Bindings (NAPI + JS)**:
> - Expose `mergeJsonConfig` and `rewriteImport` in `packages/cli/binding` (TS defs and JS exports).
> - **CLI Migration Flow (`packages/global/src/migration`)**:
> - Detect `vite.config.*`/`vitest.config.*` and rewrite imports.
> - Auto-create `vite.config.ts` when missing and merge oxlint/oxfmt configs; remove old files.
> - Enforce minimum versions (`vite>=7`, `vitest>=4`) with clear errors; upgrade Yarn <4.10 when needed.
> - Apply package manager overrides/resolutions and update scripts; handle monorepos and root workspace files.
> - **Detection & Utilities**:
> - Add package metadata/version detection; config file detection extended to Vitest.
> - **Tests & Docs**:
> - Add snapshot tests covering TS/JS, monorepo (pnpm/yarn), auto-create config, and unsupported versions.
> - Update RFC with import rewrite and merged config examples.
> - **Deps**:
> - Add `tree-sitter-typescript` via `ast-grep-language` feature; add `tempfile` for tests.
>
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3d3af8c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 5f8edc2 commit 0131832
88 files changed
Lines changed: 3311 additions & 141 deletions
File tree
- crates/vite_migration
- src
- packages
- cli/binding
- src
- global
- snap-tests
- gen-check
- gen-create-tsdown
- gen-create-vite-with-scope-name
- gen-create-vite
- gen-vite-monorepo
- migration-auto-create-vite-config
- migration-lintstagedrc-json
- migration-lintstagedrc-not-support
- migration-merge-vite-config-js
- migration-merge-vite-config-ts
- migration-monorepo-pnpm-overrides-dependency-selector
- packages/app
- migration-monorepo-pnpm
- packages
- app
- only-oxlint
- utils
- migration-monorepo-yarn4
- packages
- app
- utils
- migration-not-supported-npm8.2
- migration-not-supported-pnpm9.4
- migration-not-supported-vite6
- migration-not-supported-vitest3
- src
- migration
- __tests__
- __snapshots__
- utils
- rfcs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
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 | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 6 | + | |
13 | 7 | | |
14 | 8 | | |
15 | 9 | | |
| |||
22 | 16 | | |
23 | 17 | | |
24 | 18 | | |
25 | | - | |
| 19 | + | |
26 | 20 | | |
27 | 21 | | |
28 | 22 | | |
29 | 23 | | |
30 | 24 | | |
31 | 25 | | |
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 | | - | |
| 26 | + | |
67 | 27 | | |
68 | 28 | | |
69 | | - | |
| 29 | + | |
70 | 30 | | |
71 | 31 | | |
72 | 32 | | |
73 | 33 | | |
74 | 34 | | |
75 | | - | |
| 35 | + | |
76 | 36 | | |
77 | 37 | | |
78 | 38 | | |
| |||
156 | 116 | | |
157 | 117 | | |
158 | 118 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 119 | + | |
162 | 120 | | |
163 | 121 | | |
164 | 122 | | |
| |||
0 commit comments