Skip to content

feat: add package.json script migration with ast-grep#310

Merged
fengmk2 merged 1 commit intomainfrom
11-18-feat_add_vite_migration_crate
Nov 25, 2025
Merged

feat: add package.json script migration with ast-grep#310
fengmk2 merged 1 commit intomainfrom
11-18-feat_add_vite_migration_crate

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented Nov 18, 2025

TL;DR

Added AST-based migration tool for package.json scripts to help users transition to vite-plus.

What changed?

  • Created a new vite_migration crate with functionality to rewrite package.json scripts using AST-grep rules
  • Added AST-grep dependencies to support parsing and transforming bash scripts
  • Implemented rewritePackageJsonScripts function exposed to JavaScript via NAPI
  • Added YAML rules file for common script migrations (vite → vite dev, oxlint → vite lint, etc.)
  • Updated the migration process to use AST-based transformation instead of simple string replacements
  • Fixed template snapshots to reflect the new script transformations

How to test?

  1. Create a project with package.json containing scripts like "dev": "vite" or "lint": "oxlint"
  2. Run the migration tool: vp gen migration
  3. Verify that scripts are properly transformed (e.g., "dev": "vite dev", "lint": "vite lint")
  4. Test with complex scripts containing pipes, conditionals, and multiple commands

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.

Copy link
Copy Markdown
Member Author

fengmk2 commented Nov 18, 2025

@fengmk2 fengmk2 changed the title feat: add vite_migration crate feat: add package.json script migration with ast-grep Nov 18, 2025
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch 3 times, most recently from e2173bb to d747942 Compare November 18, 2025 11:39
@fengmk2 fengmk2 force-pushed the 11-05-feat_code_generator branch 2 times, most recently from e4306ab to 5357614 Compare November 19, 2025 03:23
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch 2 times, most recently from 9e1afab to 4b2e3eb Compare November 19, 2025 06:27
@fengmk2 fengmk2 force-pushed the 11-05-feat_code_generator branch 2 times, most recently from 6fb1c73 to 8d75c5a Compare November 19, 2025 06:53
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch 2 times, most recently from 928a9ef to 9d028cb Compare November 19, 2025 07:04
@fengmk2 fengmk2 force-pushed the 11-05-feat_code_generator branch from 8d75c5a to 20a796b Compare November 19, 2025 07:04
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from 9d028cb to d9a5276 Compare November 19, 2025 07:09
@fengmk2 fengmk2 force-pushed the 11-05-feat_code_generator branch 2 times, most recently from a04b955 to 98e1a6f Compare November 19, 2025 08:21
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch 2 times, most recently from f401f08 to ad339ca Compare November 19, 2025 08:24
@fengmk2 fengmk2 force-pushed the 11-05-feat_code_generator branch from 98e1a6f to 247fb5c Compare November 19, 2025 08:24
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from ad339ca to c05e3b9 Compare November 19, 2025 09:00
@fengmk2 fengmk2 force-pushed the 11-05-feat_code_generator branch from 57e4937 to b84fae8 Compare November 19, 2025 09:49
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from c05e3b9 to 0568a0a Compare November 19, 2025 09:49
@fengmk2 fengmk2 force-pushed the 11-05-feat_code_generator branch from b84fae8 to c4fd1b4 Compare November 19, 2025 10:03
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch 3 times, most recently from 03f7e76 to c1f8f75 Compare November 19, 2025 11:05
@fengmk2 fengmk2 force-pushed the 11-05-feat_code_generator branch from c4fd1b4 to d95159e Compare November 19, 2025 11:05
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from b2efe90 to ffb9f05 Compare November 21, 2025 05:35
@fengmk2 fengmk2 changed the base branch from 11-05-feat_code_generator to graphite-base/310 November 21, 2025 07:26
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from ffb9f05 to fcd5cbf Compare November 21, 2025 07:27
@graphite-app graphite-app bot changed the base branch from graphite-base/310 to main November 21, 2025 07:28
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from fcd5cbf to 88272ab Compare November 21, 2025 07:28
Copilot AI review requested due to automatic review settings November 21, 2025 07:30
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from 88272ab to 7b89d29 Compare November 21, 2025 07:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_migration Rust 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.

@fengmk2 fengmk2 changed the base branch from main to graphite-base/310 November 21, 2025 07:37
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from 7b89d29 to 349685c Compare November 21, 2025 07:37
@fengmk2 fengmk2 changed the base branch from graphite-base/310 to 11-21-chore_update_vite-task_and_remove_x86_64-unknown-linux-gnu-cc November 21, 2025 07:37
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from 349685c to b6ca06e Compare November 21, 2025 07:51
@fengmk2 fengmk2 force-pushed the 11-21-chore_update_vite-task_and_remove_x86_64-unknown-linux-gnu-cc branch from 42964a7 to 4468d78 Compare November 21, 2025 07:51
@fengmk2 fengmk2 force-pushed the 11-21-chore_update_vite-task_and_remove_x86_64-unknown-linux-gnu-cc branch from 4468d78 to 68eea42 Compare November 21, 2025 08:25
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from b6ca06e to c109707 Compare November 21, 2025 08:25
@fengmk2 fengmk2 force-pushed the 11-21-chore_update_vite-task_and_remove_x86_64-unknown-linux-gnu-cc branch from 68eea42 to e77ade4 Compare November 21, 2025 08:47
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch from c109707 to 9eae888 Compare November 21, 2025 08:47
@fengmk2 fengmk2 force-pushed the 11-21-chore_update_vite-task_and_remove_x86_64-unknown-linux-gnu-cc branch from e77ade4 to 17ce987 Compare November 21, 2025 08:59
@fengmk2 fengmk2 force-pushed the 11-18-feat_add_vite_migration_crate branch 2 times, most recently from 6d0c02e to da1d4d3 Compare November 21, 2025 09:47
Copy link
Copy Markdown
Member Author

fengmk2 commented Nov 25, 2025

Merge activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants