Skip to content

refactor(migrate): reuse native shell parsing for literal command analysis #3136

Closed

Description

@fengmk2

Description

Follow-up to #3118.

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

  1. self-assigned this
    on Oct 20, 2026
  2. added theissue type on Oct 20, 2026
  3. added a commit that references this issue on Oct 20, 2026
    47c8c99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Fields

Priority

None yet

Effort

None yet

Target date

None yet

Start date

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions