Uh oh!
There was an error while loading. Please reload this page.
feat: add package.json script migration with ast-grep - #310
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
e2173bb to
d747942Comparee4306ab to
5357614Compare9e1afab to
4b2e3ebCompare6fb1c73 to
8d75c5aCompare928a9ef to
9d028cbCompare8d75c5a to
20a796bCompare9d028cb to
d9a5276Comparea04b955 to
98e1a6fComparef401f08 to
ad339caCompare98e1a6f to
247fb5cComparead339ca to
c05e3b9Compare57e4937 to
b84fae8Comparec05e3b9 to
0568a0aCompareb84fae8 to
c4fd1b4Compare03f7e76 to
c1f8f75Comparec4fd1b4 to
d95159eCompareb2efe90 to
ffb9f05Compareffb9f05 to
fcd5cbfCompare92ac6e0 to
864b698Comparefcd5cbf to
88272abCompare88272ab to
7b89d29CompareThere was a problem hiding this comment.
Pull Request Overview
This PR introduces an AST-based migration system for package.json scripts to facilitate transitioning from standalone Vite tools to the unified vite-plus package. The migration uses ast-grep with bash parsing to intelligently transform npm scripts while preserving complex command structures.
Key changes:
- Created new
vite_migrationRust crate with AST-grep integration for parsing and transforming bash scripts in package.json - Replaced simple string replacements with pattern-based rules defined in YAML (vite → vite dev, oxlint → vite lint, etc.)
- Converted migration functions to async to accommodate the Rust async operations
Reviewed Changes
Copilot reviewed 16 out of 18 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
crates/vite_migration/src/package.rs | Core migration logic implementing AST-based script rewriting with rule matching and replacement |
crates/vite_migration/src/lib.rs | Module entry point exposing the rewrite_package_json_scripts function |
crates/vite_migration/Cargo.toml | Declares dependencies on ast-grep crates and tokio for async file operations |
packages/cli/binding/src/migration.rs | NAPI binding that exposes the Rust migration function to JavaScript |
packages/cli/binding/src/lib.rs | Registers the migration module and exports the binding function |
packages/cli/binding/index.js | Exports the rewritePackageJsonScripts function to JavaScript consumers |
packages/cli/binding/index.d.ts | TypeScript type definitions for the new binding function |
packages/global/src/gen/migration.ts | Orchestrates the migration by calling Rust binding and managing package.json updates |
packages/global/src/gen/templates/monorepo.ts | Adds await to migrateToVitePlus calls to handle async migration |
packages/global/rules/package-json-scripts.yml | Defines AST-grep transformation rules for common script patterns |
packages/global/package.json | Includes the rules directory in published package files |
packages/global/src/gen/__tests__/migration.spec.ts | Tests the end-to-end migration functionality with complex script examples |
packages/global/src/gen/__tests__/__snapshots__/migration.spec.ts.snap | Expected test output showing transformed scripts |
crates/vite_error/src/lib.rs | Adds error variant for ast-grep configuration errors |
crates/vite_error/Cargo.toml | Adds ast-grep-config dependency for error handling |
Cargo.toml | Updates workspace dependencies to include ast-grep crates and bumps vite-task revision |
Cargo.lock | Lock file updates for new dependencies and revised git references |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
7b89d29 to
349685cCompare349685c to
b6ca06eCompare42964a7 to
4468d78CompareUh oh!
There was an error while loading. Please reload this page.
4468d78 to
68eea42Compareb6ca06e to
c109707Compare68eea42 to
e77ade4Comparec109707 to
9eae888Comparee77ade4 to
17ce987Compare6d0c02e to
da1d4d3Compare
TL;DR
Added AST-based migration tool for package.json scripts to help users transition to vite-plus.
What changed?
vite_migrationcrate with functionality to rewrite package.json scripts using AST-grep rulesrewritePackageJsonScriptsfunction exposed to JavaScript via NAPIHow to test?
"dev": "vite"or"lint": "oxlint"vp gen migration"dev": "vite dev","lint": "vite lint")Why make this change?
The previous migration approach used simple string replacements which couldn't handle complex script commands. Using AST-grep provides more robust script transformations by properly parsing the bash syntax and applying targeted replacements. This ensures a smoother transition for users migrating from standalone tools to vite-plus, especially for projects with complex npm scripts.