feat: add package.json script migration with ast-grep#310
Merged
Conversation
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
e2173bb to
d747942
Compare
e4306ab to
5357614
Compare
9e1afab to
4b2e3eb
Compare
6fb1c73 to
8d75c5a
Compare
928a9ef to
9d028cb
Compare
8d75c5a to
20a796b
Compare
9d028cb to
d9a5276
Compare
a04b955 to
98e1a6f
Compare
f401f08 to
ad339ca
Compare
98e1a6f to
247fb5c
Compare
ad339ca to
c05e3b9
Compare
57e4937 to
b84fae8
Compare
c05e3b9 to
0568a0a
Compare
b84fae8 to
c4fd1b4
Compare
03f7e76 to
c1f8f75
Compare
c4fd1b4 to
d95159e
Compare
b2efe90 to
ffb9f05
Compare
ffb9f05 to
fcd5cbf
Compare
92ac6e0 to
864b698
Compare
fcd5cbf to
88272ab
Compare
88272ab to
7b89d29
Compare
Contributor
There 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.
7b89d29 to
349685c
Compare
349685c to
b6ca06e
Compare
42964a7 to
4468d78
Compare
branchseer
reviewed
Nov 21, 2025
4468d78 to
68eea42
Compare
b6ca06e to
c109707
Compare
68eea42 to
e77ade4
Compare
c109707 to
9eae888
Compare
e77ade4 to
17ce987
Compare
6d0c02e to
da1d4d3
Compare
branchseer
approved these changes
Nov 24, 2025
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.