You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(migrate): reuse native shell parsing for literal command analysis #3136
packages/cli/src/utils/shell-command.ts extracts the existing literal command parser from the Vitest v5 migration code so that Vitest migration and Git hooks migration can share it. This removes duplication between the TypeScript consumers, but shell parsing still overlaps with existing native migration code:
crates/vp_migration/src/script_rewrite.rs uses brush-parser and already has command traversal, word collection, and single-command parsing helpers.
crates/vp_migration/src/ast_grep.rs uses the Bash AST to apply edits at source ranges.
The current migration binding exposes script rewrite operations, but no general interface for reading literal arguments and their source positions. Maintaining a separate TypeScript parser can cause quoting and command-boundary behavior to diverge.
Suggested solution
Reuse the existing native parsing infrastructure and expose a small binding for the literal command analysis needed by both consumers. Evaluate brush-parser and the existing Bash AST support against the source-position and conservative-analysis requirements before choosing the implementation.
Replace the TypeScript parsing loops with that shared interface. Keep caller-specific policies in the callers, including hooks flag handling and Vitest migration rules.
Acceptance criteria:
Preserve the current supported literal commands, command lists, and package-manager wrappers.
Preserve conservative handling of expansions, pipelines, environment overrides, and directory-changing commands. Parsing more syntax must not automatically make it safe to rewrite.
Return argument values and original source positions so edits preserve unrelated text, quoting, and spacing. Account for Rust byte offsets versus JavaScript UTF-16 offsets, including non-ASCII input.
Keep literal text such as echo vp config --no-hooks distinct from an actual invocation, and keep hooks setup idempotent.
Retain the Git hooks and Vitest v5 migration regression coverage and unchanged CLI snapshots. Add focused coverage for the shared binding and source-position conversion.
Alternative
Keep the extracted TypeScript parser as a restricted implementation. This avoids a binding change but retains overlapping parsing logic and its maintenance cost.
Additional context
This is a follow-up refactor to #3118. It does not require broader shell evaluation or a new parser dependency.
Validations
Read the contributing guidelines.
Confirm this request is for Vite+ itself.
Check that there is no existing open issue requesting the same change.
Activity
fix(migrate): skip git hooks setup when already configured (#3118)
refactor(migrate): reuse native shell parsing for literal commands (v…