Skip to content

Commit 194c0dc

Browse files
authored
feat(env): implement vp env command for Node.js version management (#524)
Add shim-based Node.js version management with the following features: - `vp env setup`: Create shims (node, npm, npx) in ~/.vite-plus/bin - `vp env doctor`: Diagnostics for environment configuration - `vp env default [VERSION]`: Set/show global default Node.js version - `vp env which <TOOL>`: Show path to tool binary - `vp env --current [--json]`: Show current environment info - `vp env --print`: Print shell snippet for session The shims intercept node/npm/npx commands and automatically resolve the correct Node.js version based on: 1. .node-version file 2. package.json#engines.node 3. package.json#devEngines.runtime 4. User default from config 5. Latest LTS fallback Implementation includes: - Shim detection via argv[0] or VITE_PLUS_SHIM_TOOL env var - Resolution cache with mtime validation for fast repeated invocations - Platform-specific execution (execve on Unix, spawn on Windows) - Conflict detection for other version managers (nvm, fnm, volta, etc.) - Updated install.sh with shim setup and PATH configuration prompt
1 parent 2c1aa1a commit 194c0dc

146 files changed

Lines changed: 13663 additions & 1005 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.

.github/workflows/ci.yml

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ jobs:
133133
target: x86_64-unknown-linux-gnu
134134

135135
- name: Build CLI
136-
run: pnpm bootstrap-cli:ci
136+
run: |
137+
pnpm bootstrap-cli:ci
138+
echo "$HOME/.vite-plus-dev/bin" >> $GITHUB_PATH
137139
138140
- name: Print help for built-in commands
139141
run: |
@@ -195,6 +197,14 @@ jobs:
195197
- name: Build CLI
196198
run: |
197199
pnpm bootstrap-cli:ci
200+
if [[ "$RUNNER_OS" == "Windows" ]]; then
201+
echo "$USERPROFILE\.vite-plus-dev\bin" >> $GITHUB_PATH
202+
else
203+
echo "$HOME/.vite-plus-dev/bin" >> $GITHUB_PATH
204+
fi
205+
206+
- name: Verify CLI installation
207+
run: |
198208
which vp
199209
vp --version
200210
vp -h
@@ -212,6 +222,137 @@ jobs:
212222
- name: Run CLI lint
213223
run: vp run lint
214224

225+
- name: Test global package install (powershell)
226+
if: ${{ matrix.os == 'windows-latest' }}
227+
shell: pwsh
228+
run: |
229+
echo "PATH: $env:Path"
230+
where.exe node
231+
where.exe npm
232+
where.exe npx
233+
where.exe vp
234+
vp env doctor
235+
236+
# Test 1: Install a JS-based CLI (typescript)
237+
vp install -g typescript
238+
tsc --version
239+
where.exe tsc
240+
241+
# Test 2: Verify the package was installed correctly
242+
Get-ChildItem "$env:USERPROFILE\.vite-plus-dev\packages\typescript\"
243+
Get-ChildItem "$env:USERPROFILE\.vite-plus-dev\bin\"
244+
245+
# Test 3: Uninstall
246+
vp uninstall -g typescript
247+
248+
# Test 4: Verify uninstall removed shim
249+
Write-Host "Checking bin dir after uninstall:"
250+
Get-ChildItem "$env:USERPROFILE\.vite-plus-dev\bin\"
251+
$shimPath = "$env:USERPROFILE\.vite-plus-dev\bin\tsc.cmd"
252+
if (Test-Path $shimPath) {
253+
Write-Error "tsc shim file still exists at $shimPath"
254+
exit 1
255+
}
256+
Write-Host "tsc shim removed successfully"
257+
258+
# Test 5: use session
259+
vp env use 18
260+
node --version
261+
vp env doctor
262+
vp env use --unset
263+
node --version
264+
265+
- name: Test global package install (cmd)
266+
if: ${{ matrix.os == 'windows-latest' }}
267+
shell: cmd
268+
run: |
269+
echo "PATH: %PATH%"
270+
where.exe node
271+
where.exe npm
272+
where.exe npx
273+
where.exe vp
274+
275+
vp env use 18
276+
node --version
277+
vp env use --unset
278+
node --version
279+
280+
vp env doctor
281+
282+
REM Test 1: Install a JS-based CLI (typescript)
283+
vp install -g typescript
284+
tsc --version
285+
where.exe tsc
286+
287+
REM Test 2: Verify the package was installed correctly
288+
dir "%USERPROFILE%\.vite-plus-dev\packages\typescript\"
289+
dir "%USERPROFILE%\.vite-plus-dev\bin\"
290+
291+
REM Test 3: Uninstall
292+
vp uninstall -g typescript
293+
294+
REM Test 4: Verify uninstall removed shim (.cmd wrapper)
295+
echo Checking bin dir after uninstall:
296+
dir "%USERPROFILE%\.vite-plus-dev\bin\"
297+
if exist "%USERPROFILE%\.vite-plus-dev\bin\tsc.cmd" (
298+
echo Error: tsc.cmd shim file still exists
299+
exit /b 1
300+
)
301+
echo tsc.cmd shim removed successfully
302+
303+
REM Test 5: Verify shell script was also removed (for Git Bash)
304+
if exist "%USERPROFILE%\.vite-plus-dev\bin\tsc" (
305+
echo Error: tsc shell script still exists
306+
exit /b 1
307+
)
308+
echo tsc shell script removed successfully
309+
310+
REM Test 6: use session
311+
vp env use 18
312+
node --version
313+
vp env doctor
314+
vp env use --unset
315+
node --version
316+
317+
- name: Test global package install (bash)
318+
run: |
319+
echo "PATH: $PATH"
320+
ls -la ~/.vite-plus-dev/
321+
ls -la ~/.vite-plus-dev/bin/
322+
which node
323+
which npm
324+
which npx
325+
which vp
326+
vp env doctor
327+
328+
# Test 1: Install a JS-based CLI (typescript)
329+
vp install -g typescript
330+
tsc --version
331+
which tsc
332+
333+
# Test 2: Verify the package was installed correctly
334+
ls -la ~/.vite-plus-dev/packages/typescript/
335+
ls -la ~/.vite-plus-dev/bin/
336+
337+
# Test 3: Uninstall
338+
vp uninstall -g typescript
339+
340+
# Test 4: Verify uninstall removed shim
341+
echo "Checking bin dir after uninstall:"
342+
ls -la ~/.vite-plus-dev/bin/
343+
if [ -f ~/.vite-plus-dev/bin/tsc ]; then
344+
echo "Error: tsc shim file still exists at ~/.vite-plus-dev/bin/tsc"
345+
exit 1
346+
fi
347+
echo "tsc shim removed successfully"
348+
349+
# Test 5: use session
350+
vp env use 18
351+
node --version
352+
vp env doctor
353+
vp env use --unset
354+
node --version
355+
215356
- name: Install Playwright browsers
216357
run: pnpx playwright install chromium
217358

@@ -255,7 +396,9 @@ jobs:
255396
target: x86_64-unknown-linux-gnu
256397

257398
- name: Build CLI
258-
run: pnpm bootstrap-cli:ci
399+
run: |
400+
pnpm bootstrap-cli:ci
401+
echo "$HOME/.vite-plus-dev/bin" >> $GITHUB_PATH
259402
260403
- name: Run local CLI `vite install`
261404
run: |

.github/workflows/e2e-test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103

104104
- name: Pack packages into tgz
105105
run: |
106-
pnpm bootstrap-cli:ci
106+
pnpm copy-cli-binding
107107
mkdir -p tmp/tgz
108108
cd packages/core && pnpm pack --pack-destination ../../tmp/tgz && cd ../..
109109
cd packages/test && pnpm pack --pack-destination ../../tmp/tgz && cd ../..
@@ -263,11 +263,15 @@ jobs:
263263
name: vite-plus-packages-${{ matrix.os }}
264264
path: tmp/tgz
265265

266-
- name: Install vite-plus from tgz in ${{ matrix.project.name }}
266+
- name: Install vp CLI
267+
shell: bash
268+
run: |
269+
node $GITHUB_WORKSPACE/packages/tools/src/install-global-cli.ts vp --tgz $GITHUB_WORKSPACE/tmp/tgz/vite-plus-cli-0.0.0.tgz
270+
echo "$HOME/.vite-plus-dev/bin" >> $GITHUB_PATH
271+
272+
- name: Migrate in ${{ matrix.project.name }}
267273
working-directory: ${{ runner.temp }}/vite-plus-ecosystem-ci/${{ matrix.project.name }}${{ matrix.project.directory && format('/{0}', matrix.project.directory) || '' }}
268274
run: |
269-
# install global CLI first
270-
npm install -g $GITHUB_WORKSPACE/tmp/tgz/vite-plus-cli-0.0.0.tgz
271275
node $GITHUB_WORKSPACE/ecosystem-ci/patch-project.ts ${{ matrix.project.name }}
272276
vp install --no-frozen-lockfile
273277

.github/workflows/release.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
run: |
7979
pnpm exec tool replace-file-content packages/cli/binding/Cargo.toml 'version = "0.0.0"' 'version = "${{ env.VERSION }}"'
8080
pnpm exec tool replace-file-content packages/global/binding/Cargo.toml 'version = "0.0.0"' 'version = "${{ env.VERSION }}"'
81+
pnpm exec tool replace-file-content crates/vite_global_cli/Cargo.toml 'version = "0.0.0"' 'version = "${{ env.VERSION }}"'
8182
8283
- name: Configure Git for access to vite-task
8384
run: git config --global url."https://x-access-token:${{ secrets.VITE_TASK_TOKEN }}@github.com/".insteadOf "ssh://git@github.com/"
@@ -265,11 +266,11 @@ jobs:
265266
- name: Create release body
266267
run: |
267268
if [[ "${{ inputs.npm_tag }}" == "latest" ]]; then
268-
INSTALL_BASH="curl -fsSL https://viteplus.dev/install.sh | bash"
269-
INSTALL_PS1="irm https://viteplus.dev/install.ps1 | iex"
269+
INSTALL_BASH="curl -fsSL https://staging.viteplus.dev/install.sh | bash"
270+
INSTALL_PS1="irm https://staging.viteplus.dev/install.ps1 | iex"
270271
else
271-
INSTALL_BASH="curl -fsSL https://viteplus.dev/install.sh | VITE_PLUS_VERSION=${{ env.VERSION }} bash"
272-
INSTALL_PS1="\\\$env:VITE_PLUS_VERSION=\\\"${{ env.VERSION }}\\\"; irm https://viteplus.dev/install.ps1 | iex"
272+
INSTALL_BASH="curl -fsSL https://staging.viteplus.dev/install.sh | VITE_PLUS_VERSION=${{ env.VERSION }} bash"
273+
INSTALL_PS1="\\\$env:VITE_PLUS_VERSION=\\\"${{ env.VERSION }}\\\"; irm https://staging.viteplus.dev/install.ps1 | iex"
273274
fi
274275
cat > ./RELEASE_BODY.md <<EOF
275276
## vite-plus v${{ env.VERSION }}
@@ -326,6 +327,6 @@ jobs:
326327
• vite-plus-cli@${{ env.VERSION }}
327328
328329
**Install:**
329-
• macOS/Linux: `curl -fsSL https://viteplus.dev/install.sh | bash`
330-
• Windows: `irm https://viteplus.dev/install.ps1 | iex`
330+
• macOS/Linux: `curl -fsSL https://staging.viteplus.dev/install.sh | bash`
331+
• Windows: `irm https://staging.viteplus.dev/install.ps1 | iex`
331332
embed-url: https://github.com/${{ github.repository }}/releases/tag/v${{ env.VERSION }}

.github/workflows/test-install.yml

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)