Skip to content

Commit 2c1aa1a

Browse files
authored
feat(vp): refactor global cli to rust entry point (#514)
The binary can now be used as a drop-in replacement for the Node.js global CLI for package manager operations. Verification Tests - [x] [install.sh](http://install.sh) - [x] install.ps1 - [x] e2e
1 parent 4446c3c commit 2c1aa1a

300 files changed

Lines changed: 6413 additions & 4648 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/skills/add-ecosystem-ci/SKILL.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Look for common patterns in workflow files:
4141

4242
- `pnpm run <command>` / `npm run <command>` / `yarn <command>`
4343
- Commands like: `lint`, `build`, `test`, `type-check`, `typecheck`, `format`, `format:check`
44-
- Map detected commands to vite equivalents: `vite run lint`, `vite run build`, etc.
44+
- Map detected commands to `vp` equivalents: `vp run lint`, `vp run build`, etc.
4545

4646
### 2.3 Ask User to Confirm
4747

@@ -73,8 +73,8 @@ Present the auto-detected configuration and ask user to confirm or modify:
7373
node-version: 24
7474
directory: web # only if subdirectory is needed
7575
command: |
76-
vite run lint
77-
vite run build
76+
vp run lint
77+
vp run build
7878
```
7979
8080
## Step 4: Verify
@@ -109,5 +109,5 @@ node ecosystem-ci/clone.ts project-name
109109
110110
- The `directory` field is optional - only add it if the package.json is not in the project root
111111
- If `directory` is specified in repo.json, it must also be specified in the workflow matrix
112-
- `patch-project.ts` automatically handles running `vite migrate` in the correct directory
112+
- `patch-project.ts` automatically handles running `vp migrate` in the correct directory
113113
- OS exclusions are added to the existing `exclude` section in the workflow matrix

.github/actions/build-upstream/action.yml

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ inputs:
44
target:
55
description: 'The target platform'
66
required: true
7-
print-after-build:
8-
description: 'Print the output after the build'
9-
required: false
107

118
runs:
129
using: 'composite'
@@ -24,9 +21,9 @@ runs:
2421
id: cache-key
2522
shell: bash
2623
run: |
27-
echo "key=napi-binding-v1-${{ inputs.target }}-${{ env.RELEASE_BUILD }}-${{ env.DEBUG }}-${{ env.VERSION }}-${{ hashFiles('packages/tools/.upstream-versions.json', 'Cargo.lock', 'crates/**/*.rs', 'crates/*/Cargo.toml', 'packages/*/binding/**/*.rs', 'packages/*/binding/Cargo.toml', 'Cargo.toml', '.cargo/config.toml', 'packages/cli/package.json', 'packages/cli/build.ts', 'packages/global/package.json', 'packages/global/build.ts') }}" >> $GITHUB_OUTPUT
24+
echo "key=napi-binding-v2-${{ inputs.target }}-${{ env.RELEASE_BUILD }}-${{ env.DEBUG }}-${{ env.VERSION }}-${{ env.NPM_TAG }}-${{ hashFiles('packages/tools/.upstream-versions.json', 'Cargo.lock', 'crates/**/*.rs', 'crates/*/Cargo.toml', 'packages/*/binding/**/*.rs', 'packages/*/binding/Cargo.toml', 'Cargo.toml', '.cargo/config.toml', 'packages/cli/package.json', 'packages/cli/build.ts', 'packages/global/package.json', 'packages/global/build.ts') }}" >> $GITHUB_OUTPUT
2825
29-
# Cache only NAPI bindings (the slow part, especially on Windows)
26+
# Cache NAPI bindings and Rust CLI binary (the slow parts, especially on Windows)
3027
- name: Restore NAPI binding cache
3128
id: cache-restore
3229
uses: actions/cache/restore@94b89442628ad1d101e352b7ee38f30e1bef108e # v5
@@ -40,6 +37,8 @@ runs:
4037
packages/global/binding/*.node
4138
packages/global/binding/index.js
4239
packages/global/binding/index.d.ts
40+
target/${{ inputs.target }}/release/vp
41+
target/${{ inputs.target }}/release/vp.exe
4342
key: ${{ steps.cache-key.outputs.key }}
4443

4544
# Build upstream TypeScript packages first (don't depend on native bindings)
@@ -56,7 +55,7 @@ runs:
5655
5756
# NAPI builds - only run on cache miss (slow, especially on Windows)
5857
# Must run before vite-plus/vite-plus-cli TypeScript builds which depend on the bindings
59-
- name: Build NAPI bindings
58+
- name: Build NAPI bindings (x86_64-linux)
6059
shell: bash
6160
if: steps.cache-restore.outputs.cache-hit != 'true' && inputs.target == 'x86_64-unknown-linux-gnu'
6261
run: |
@@ -66,17 +65,18 @@ runs:
6665
TARGET_CC: clang
6766
DEBUG: napi:*
6867

69-
- name: Build NAPI bindings
68+
- name: Build NAPI bindings (aarch64-linux)
7069
shell: bash
7170
if: steps.cache-restore.outputs.cache-hit != 'true' && inputs.target == 'aarch64-unknown-linux-gnu'
7271
run: |
73-
TARGET_CFLAGS="-D_BSD_SOURCE" pnpm --filter=vite-plus build-native --target ${{ inputs.target }} --use-napi-cross
74-
TARGET_CFLAGS="-D_BSD_SOURCE" pnpm --filter=vite-plus-cli build-native --target ${{ inputs.target }} --use-napi-cross
72+
pnpm --filter=vite-plus build-native --target ${{ inputs.target }} --use-napi-cross
73+
pnpm --filter=vite-plus-cli build-native --target ${{ inputs.target }} --use-napi-cross
7574
env:
7675
TARGET_CC: clang
76+
TARGET_CFLAGS: '-D_BSD_SOURCE'
7777
DEBUG: napi:*
7878

79-
- name: Build NAPI bindings
79+
- name: Build NAPI bindings (non-Linux targets)
8080
shell: bash
8181
if: steps.cache-restore.outputs.cache-hit != 'true' && !contains(inputs.target, 'linux')
8282
run: |
@@ -85,16 +85,29 @@ runs:
8585
env:
8686
DEBUG: napi:*
8787

88-
- name: Print output after build
88+
- name: Build Rust CLI binary (x86_64-linux)
89+
if: steps.cache-restore.outputs.cache-hit != 'true' && inputs.target == 'x86_64-unknown-linux-gnu'
8990
shell: bash
90-
if: inputs.print-after-build == 'true'
9191
run: |
92-
pnpm vite -h
93-
pnpm vite run -h
94-
pnpm vite lint -h
95-
pnpm vite test -h
96-
pnpm vite build -h
97-
pnpm vite fmt -h
92+
pnpm exec napi build --use-napi-cross --target ${{ inputs.target }} --release -p vite_global_cli
93+
env:
94+
TARGET_CC: clang
95+
DEBUG: napi:*
96+
97+
- name: Build Rust CLI binary (aarch64-linux)
98+
if: steps.cache-restore.outputs.cache-hit != 'true' && inputs.target == 'aarch64-unknown-linux-gnu'
99+
shell: bash
100+
run: |
101+
pnpm exec napi build --use-napi-cross --target ${{ inputs.target }} --release -p vite_global_cli
102+
env:
103+
TARGET_CC: clang
104+
TARGET_CFLAGS: '-D_BSD_SOURCE'
105+
DEBUG: napi:*
106+
107+
- name: Build Rust CLI binary (non-Linux targets)
108+
if: steps.cache-restore.outputs.cache-hit != 'true' && !contains(inputs.target, 'linux')
109+
shell: bash
110+
run: cargo build --release --target ${{ inputs.target }} -p vite_global_cli
98111

99112
- name: Save NAPI binding cache
100113
if: steps.cache-restore.outputs.cache-hit != 'true'
@@ -109,4 +122,34 @@ runs:
109122
packages/global/binding/*.node
110123
packages/global/binding/index.js
111124
packages/global/binding/index.d.ts
125+
target/${{ inputs.target }}/release/vp
126+
target/${{ inputs.target }}/release/vp.exe
112127
key: ${{ steps.cache-key.outputs.key }}
128+
129+
# Copy Rust CLI binary to packages/global/bin/ (runs on both cache hit and miss)
130+
- name: Copy Rust CLI binary
131+
shell: bash
132+
run: |
133+
if [[ "${{ inputs.target }}" == *"windows"* ]]; then
134+
cp target/${{ inputs.target }}/release/vp.exe packages/global/bin/vp.exe
135+
else
136+
cp target/${{ inputs.target }}/release/vp packages/global/bin/vp
137+
fi
138+
139+
# Build vite-plus TypeScript after native bindings are ready
140+
- name: Build vite-plus TypeScript packages
141+
shell: bash
142+
run: |
143+
pnpm --filter=vite-plus build-ts
144+
pnpm --filter=vite-plus-cli build-ts
145+
146+
- name: Print output after build
147+
shell: bash
148+
if: inputs.print-after-build == 'true'
149+
run: |
150+
pnpm vite -h
151+
pnpm vite run -h
152+
pnpm vite lint -h
153+
pnpm vite test -h
154+
pnpm vite build -h
155+
pnpm vite fmt -h

.github/workflows/ci.yml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ jobs:
6767
env:
6868
RUSTFLAGS: '-D warnings --cfg tokio_unstable' # also update .cargo/config.toml
6969

70-
- run: cargo test -p vite_command -p vite_install -p vite_migration
70+
# Test all crates/* packages. New crates are automatically included.
71+
- run: cargo test $(for d in crates/*/; do echo -n "-p $(basename $d) "; done)
7172

7273
lint:
7374
name: Lint
@@ -136,13 +137,13 @@ jobs:
136137

137138
- name: Print help for built-in commands
138139
run: |
139-
which vite
140-
vite -h
141-
vite run -h
142-
vite lint -h
143-
vite test -h
144-
vite build -h
145-
vite fmt -h
140+
which vp
141+
vp -h
142+
vp run -h
143+
vp lint -h
144+
vp test -h
145+
vp build -h
146+
vp fmt -h
146147
147148
cli-e2e-test:
148149
name: CLI E2E test
@@ -194,31 +195,33 @@ jobs:
194195
- name: Build CLI
195196
run: |
196197
pnpm bootstrap-cli:ci
197-
which vite
198-
vite --version
199-
vite -h
198+
which vp
199+
vp --version
200+
vp -h
201+
202+
- name: Check CLI JS execution on Windows rust binary
203+
if: ${{ matrix.os == 'windows-latest' }}
204+
run: |
205+
ls -al packages/global/bin
206+
VITE_LOG=trace ./packages/global/bin/vp.exe -V
207+
VITE_LOG=trace ./packages/global/bin/vp.exe pm cache dir
200208
201209
- name: Run CLI fmt
202-
run: vite fmt --check
210+
run: vp fmt --check
203211

204212
- name: Run CLI lint
205-
run: vite run lint
213+
run: vp run lint
206214

207215
- name: Install Playwright browsers
208216
run: pnpx playwright install chromium
209217

210-
- name: Create vite.cmd shim file for Windows
211-
if: ${{ matrix.os == 'windows-latest' }}
212-
run: |
213-
printf '@echo off\nnode "%%~dp0vite" %%*\n' > packages/global/bin/vite.cmd
214-
215218
- name: Run CLI snapshot tests
216219
run: |
217220
RUST_BACKTRACE=1 pnpm test
218221
git diff --exit-code
219222
220223
install-e2e-test:
221-
name: vite install E2E test
224+
name: Local CLI `vite install` E2E test
222225
needs:
223226
- download-previous-rolldown-binaries
224227
runs-on: ubuntu-latest
@@ -254,7 +257,7 @@ jobs:
254257
- name: Build CLI
255258
run: pnpm bootstrap-cli:ci
256259

257-
- name: Run local CLI vite install
260+
- name: Run local CLI `vite install`
258261
run: |
259262
export PATH=$PWD/node_modules/.bin:$PATH
260263
vite -h

0 commit comments

Comments
 (0)