Skip to content

Commit bc4c4b0

Browse files
authored
Merge branch 'main' into fix/bundled-dev-runtime
2 parents 9a3c8e7 + a42d40a commit bc4c4b0

7 files changed

Lines changed: 852 additions & 22 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import assert from 'node:assert/strict';
2+
import { cpSync, lstatSync, mkdirSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
3+
import { dirname, join, resolve } from 'node:path';
4+
5+
// Keep global npm installs out of the runner's shared runtime seed.
6+
const runtimeLink = join(process.env.VP_HOME, 'js_runtime');
7+
assert(lstatSync(runtimeLink).isSymbolicLink());
8+
const privateRuntime = resolve('private-runtime');
9+
const nodePrefix = join(privateRuntime, 'node', process.versions.node);
10+
mkdirSync(dirname(nodePrefix), { recursive: true });
11+
cpSync(dirname(dirname(process.execPath)), nodePrefix, { recursive: true, verbatimSymlinks: true });
12+
unlinkSync(runtimeLink);
13+
symlinkSync(privateRuntime, runtimeLink, 'dir');
14+
symlinkSync(nodePrefix, 'node-prefix', 'dir');
15+
writeFileSync('.node-version', process.versions.node);

‎crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/npm_global_uninstall_prefix/snapshots.toml‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,117 @@ steps = [
1111
{ argv = ["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli"], comment = "Should be gone", continue-on-failure = true },
1212
{ argv = ["vpt", "rm", "-rf", "custom-prefix"], comment = "Cleanup", continue-on-failure = true },
1313
]
14+
15+
[[case]]
16+
name = "npm_global_uninstall_dry_run"
17+
vp = "global"
18+
skip-platforms = ["windows"]
19+
steps = [
20+
{ tty = false, argv = ["npm", "install", "-g", "--prefix", "./custom-prefix", "./npm-global-prefix-pkg"], comment = "Install a local package and create its Vite+ link" },
21+
{ tty = false, argv = ["npm", "uninstall", "-g", "--prefix", "./custom-prefix", "npm-global-prefix-pkg", "--dry-run"], comment = "CLI dry-run must preserve the package, npm binary, link, and BinConfig" },
22+
["vpt", "stat-file", "custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json", "--assert", "file"],
23+
["vpt", "stat-file", "custom-prefix/bin/npm-global-prefix-cli", "--assert", "symlink"],
24+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "symlink"],
25+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
26+
["npm-global-prefix-cli"],
27+
{ tty = false, argv = ["npm", "uninstall", "-g", "--prefix", "./custom-prefix", "npm-global-prefix-pkg"], envs = [["npm_config_dry_run", "true"]], comment = "Environment-configured dry-run must also preserve installed state" },
28+
["vpt", "stat-file", "custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json", "--assert", "file"],
29+
["vpt", "stat-file", "custom-prefix/bin/npm-global-prefix-cli", "--assert", "symlink"],
30+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "symlink"],
31+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
32+
["npm-global-prefix-cli"],
33+
["vpt", "write-file", "dry-run.npmrc", "dry-run=true\n"],
34+
{ tty = false, argv = ["npm", "uninstall", "-g", "--prefix", "./custom-prefix", "npm-global-prefix-pkg"], envs = [["npm_config_userconfig", "${workspace}/dry-run.npmrc"]], comment = "User npmrc dry-run must also preserve installed state" },
35+
["vpt", "stat-file", "custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json", "--assert", "file"],
36+
["vpt", "stat-file", "custom-prefix/bin/npm-global-prefix-cli", "--assert", "symlink"],
37+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "symlink"],
38+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
39+
["npm-global-prefix-cli"],
40+
{ tty = false, argv = ["npm", "uninstall", "-g", "--prefix", "./custom-prefix", "npm-global-prefix-pkg"], comment = "A real uninstall must still clean up the package, npm binary, link, and BinConfig" },
41+
["vpt", "stat-file", "custom-prefix/lib/node_modules/npm-global-prefix-pkg", "--assert", "missing"],
42+
["vpt", "stat-file", "custom-prefix/bin/npm-global-prefix-cli", "--assert", "missing"],
43+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "missing"],
44+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "missing"],
45+
]
46+
47+
[[case]]
48+
name = "npm_global_uninstall_preserves_local_copy"
49+
vp = "global"
50+
skip-platforms = ["windows"]
51+
steps = [
52+
["vpt", "mkdir", "-p", "custom-prefix"],
53+
["vpt", "write-file", "custom-prefix/package.json", "{\"private\":true}"],
54+
{ tty = false, argv = ["npm", "install", "--prefix", "./custom-prefix", "--ignore-scripts", "--no-save", "--no-package-lock", "--no-audit", "./npm-global-prefix-pkg"], comment = "Install a local copy under the same prefix" },
55+
{ tty = false, argv = ["npm", "install", "-g", "--prefix", "./custom-prefix", "./npm-global-prefix-pkg"], comment = "Install a separate global copy and create its Vite+ link" },
56+
["vpt", "stat-file", "custom-prefix/node_modules/npm-global-prefix-pkg/package.json", "--assert", "file"],
57+
["vpt", "stat-file", "custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json", "--assert", "file"],
58+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "symlink"],
59+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
60+
{ tty = false, argv = ["npm", "uninstall", "-g", "--prefix", "./custom-prefix", "npm-global-prefix-pkg", "--dry-run"], comment = "Dry-run must preserve the global command even when a local copy also exists" },
61+
["npm-global-prefix-cli"],
62+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
63+
{ tty = false, argv = ["npm", "uninstall", "-g", "--prefix", "./custom-prefix", "npm-global-prefix-pkg"], comment = "Real uninstall must remove the global links without confusing the remaining local copy for the global installation" },
64+
["vpt", "stat-file", "custom-prefix/lib/node_modules/npm-global-prefix-pkg", "--assert", "missing"],
65+
["vpt", "stat-file", "custom-prefix/bin/npm-global-prefix-cli", "--assert", "missing"],
66+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "missing"],
67+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "missing"],
68+
["vpt", "stat-file", "custom-prefix/node_modules/npm-global-prefix-pkg/package.json", "--assert", "file"],
69+
["node", "custom-prefix/node_modules/npm-global-prefix-pkg/cli.js"],
70+
]
71+
72+
[[case]]
73+
name = "npm_global_uninstall_userconfig_fallback"
74+
vp = "global"
75+
skip-platforms = ["windows"]
76+
# Require the seeded runtime instead of downloading one for this case.
77+
env = { VP_NODE_DIST_MIRROR = "http://127.0.0.1:9" }
78+
unset-env = ["NPM_CONFIG_PREFIX"]
79+
steps = [
80+
["node", "private-runtime.mjs"],
81+
{ tty = false, argv = ["npm", "install", "-g", "./npm-global-prefix-pkg"], comment = "Install into a private copy of the selected Node runtime" },
82+
["vpt", "stat-file", "node-prefix/lib/node_modules/npm-global-prefix-pkg/package.json", "--assert", "file"],
83+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "symlink"],
84+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
85+
{ tty = false, argv = ["npm", "config", "set", "prefix", "./other-prefix", "--location=user"], comment = "Make the normal user config point to another prefix" },
86+
["vpt", "write-file", "empty.npmrc", ""],
87+
{ tty = false, argv = ["npm", "uninstall", "-g", "--userconfig=empty.npmrc", "npm-global-prefix-pkg", "--dry-run"], comment = "A config override dry-run must preserve the fallback installation" },
88+
["npm-global-prefix-cli"],
89+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
90+
{ tty = false, argv = ["npm", "uninstall", "-g", "npm-global-prefix-pkg"], comment = "Uninstalling from an empty prefix must not remove links to the surviving fallback package" },
91+
["npm-global-prefix-cli"],
92+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
93+
{ tty = false, argv = ["npm", "uninstall", "-g", "--userconfig", "empty.npmrc", "npm-global-prefix-pkg"], comment = "A real uninstall using the override must clean up the fallback package's links" },
94+
["vpt", "stat-file", "node-prefix/lib/node_modules/npm-global-prefix-pkg", "--assert", "missing"],
95+
["vpt", "stat-file", "node-prefix/bin/npm-global-prefix-cli", "--assert", "missing"],
96+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "missing"],
97+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "missing"],
98+
]
99+
100+
[[case]]
101+
name = "npm_global_uninstall_prefix_shorthand"
102+
vp = "global"
103+
skip-platforms = ["windows"]
104+
unset-env = ["NPM_CONFIG_PREFIX"]
105+
steps = [
106+
{ tty = false, argv = ["npm", "install", "-g", "--prefix", "./custom-prefix", "./npm-global-prefix-pkg"] },
107+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "symlink"],
108+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
109+
{ tty = false, argv = ["npm", "uninstall", "-g", "-C", "./custom-prefix", "npm-global-prefix-pkg", "--dry-run"], envs = [["NPM_CONFIG_PREFIX", "${workspace}/other-prefix"]], comment = "A shorthand prefix override must still preserve links during dry-run" },
110+
["npm-global-prefix-cli"],
111+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
112+
{ tty = false, argv = ["npm", "uninstall", "-g", "-C", "./custom-prefix", "npm-global-prefix-pkg"], envs = [["NPM_CONFIG_PREFIX", "${workspace}/other-prefix"]], comment = "-C must override the environment prefix for uninstall link cleanup" },
113+
["vpt", "stat-file", "custom-prefix/lib/node_modules/npm-global-prefix-pkg", "--assert", "missing"],
114+
["vpt", "stat-file", "custom-prefix/bin/npm-global-prefix-cli", "--assert", "missing"],
115+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "missing"],
116+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "missing"],
117+
["vpt", "write-file", "prefix.npmrc", "prefix=${HOME}/npm-prefix\n"],
118+
{ tty = false, argv = ["npm", "install", "-g", "-C=./custom-prefix", "./npm-global-prefix-pkg"], envs = [["npm_config_userconfig", "${workspace}/prefix.npmrc"]], comment = "-C= must override the user npmrc prefix when creating links" },
119+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "symlink"],
120+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "file"],
121+
["npm-global-prefix-cli"],
122+
{ tty = false, argv = ["npm", "-C", "./custom-prefix", "uninstall", "-g", "npm-global-prefix-pkg"], envs = [["npm_config_userconfig", "${workspace}/prefix.npmrc"]], comment = "-C before the subcommand must also override the user npmrc prefix for cleanup" },
123+
["vpt", "stat-file", "custom-prefix/lib/node_modules/npm-global-prefix-pkg", "--assert", "missing"],
124+
["vpt", "stat-file", "custom-prefix/bin/npm-global-prefix-cli", "--assert", "missing"],
125+
["vpt", "stat-file", "$VP_HOME/bin/npm-global-prefix-cli", "--assert", "missing"],
126+
["vpt", "stat-file", "$VP_HOME/bins/npm-global-prefix-cli.json", "--assert", "missing"],
127+
]
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# npm_global_uninstall_dry_run
2+
3+
## `npm install -g --prefix ./custom-prefix ./npm-global-prefix-pkg`
4+
5+
Install a local package and create its Vite+ link
6+
7+
```
8+
9+
added 1 package in <duration>
10+
Linked 'npm-global-prefix-cli' to <home>/.vite-plus/bin/npm-global-prefix-cli
11+
```
12+
13+
## `npm uninstall -g --prefix ./custom-prefix npm-global-prefix-pkg --dry-run`
14+
15+
CLI dry-run must preserve the package, npm binary, link, and BinConfig
16+
17+
```
18+
remove npm-global-prefix-pkg 1.0.0
19+
20+
removed 1 package in <duration>
21+
```
22+
23+
## `vpt stat-file custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json --assert file`
24+
25+
```
26+
custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json: file
27+
```
28+
29+
## `vpt stat-file custom-prefix/bin/npm-global-prefix-cli --assert symlink`
30+
31+
```
32+
custom-prefix/bin/npm-global-prefix-cli: symlink
33+
```
34+
35+
## `vpt stat-file $VP_HOME/bin/npm-global-prefix-cli --assert symlink`
36+
37+
```
38+
<home>/.vite-plus/bin/npm-global-prefix-cli: symlink
39+
```
40+
41+
## `vpt stat-file $VP_HOME/bins/npm-global-prefix-cli.json --assert file`
42+
43+
```
44+
<home>/.vite-plus/bins/npm-global-prefix-cli.json: file
45+
```
46+
47+
## `npm-global-prefix-cli`
48+
49+
```
50+
npm-global-prefix-cli works
51+
```
52+
53+
## `npm_config_dry_run=true npm uninstall -g --prefix ./custom-prefix npm-global-prefix-pkg`
54+
55+
Environment-configured dry-run must also preserve installed state
56+
57+
```
58+
remove npm-global-prefix-pkg 1.0.0
59+
60+
removed 1 package in <duration>
61+
```
62+
63+
## `vpt stat-file custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json --assert file`
64+
65+
```
66+
custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json: file
67+
```
68+
69+
## `vpt stat-file custom-prefix/bin/npm-global-prefix-cli --assert symlink`
70+
71+
```
72+
custom-prefix/bin/npm-global-prefix-cli: symlink
73+
```
74+
75+
## `vpt stat-file $VP_HOME/bin/npm-global-prefix-cli --assert symlink`
76+
77+
```
78+
<home>/.vite-plus/bin/npm-global-prefix-cli: symlink
79+
```
80+
81+
## `vpt stat-file $VP_HOME/bins/npm-global-prefix-cli.json --assert file`
82+
83+
```
84+
<home>/.vite-plus/bins/npm-global-prefix-cli.json: file
85+
```
86+
87+
## `npm-global-prefix-cli`
88+
89+
```
90+
npm-global-prefix-cli works
91+
```
92+
93+
## `vpt write-file dry-run.npmrc 'dry-run=true
94+
'`
95+
96+
```
97+
```
98+
99+
## `npm_config_userconfig=${workspace}/dry-run.npmrc npm uninstall -g --prefix ./custom-prefix npm-global-prefix-pkg`
100+
101+
User npmrc dry-run must also preserve installed state
102+
103+
```
104+
remove npm-global-prefix-pkg 1.0.0
105+
106+
removed 1 package in <duration>
107+
```
108+
109+
## `vpt stat-file custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json --assert file`
110+
111+
```
112+
custom-prefix/lib/node_modules/npm-global-prefix-pkg/package.json: file
113+
```
114+
115+
## `vpt stat-file custom-prefix/bin/npm-global-prefix-cli --assert symlink`
116+
117+
```
118+
custom-prefix/bin/npm-global-prefix-cli: symlink
119+
```
120+
121+
## `vpt stat-file $VP_HOME/bin/npm-global-prefix-cli --assert symlink`
122+
123+
```
124+
<home>/.vite-plus/bin/npm-global-prefix-cli: symlink
125+
```
126+
127+
## `vpt stat-file $VP_HOME/bins/npm-global-prefix-cli.json --assert file`
128+
129+
```
130+
<home>/.vite-plus/bins/npm-global-prefix-cli.json: file
131+
```
132+
133+
## `npm-global-prefix-cli`
134+
135+
```
136+
npm-global-prefix-cli works
137+
```
138+
139+
## `npm uninstall -g --prefix ./custom-prefix npm-global-prefix-pkg`
140+
141+
A real uninstall must still clean up the package, npm binary, link, and BinConfig
142+
143+
```
144+
145+
removed 1 package in <duration>
146+
Removed link 'npm-global-prefix-cli' from <home>/.vite-plus/bin/npm-global-prefix-cli
147+
```
148+
149+
## `vpt stat-file custom-prefix/lib/node_modules/npm-global-prefix-pkg --assert missing`
150+
151+
```
152+
custom-prefix/lib/node_modules/npm-global-prefix-pkg: missing
153+
```
154+
155+
## `vpt stat-file custom-prefix/bin/npm-global-prefix-cli --assert missing`
156+
157+
```
158+
custom-prefix/bin/npm-global-prefix-cli: missing
159+
```
160+
161+
## `vpt stat-file $VP_HOME/bin/npm-global-prefix-cli --assert missing`
162+
163+
```
164+
<home>/.vite-plus/bin/npm-global-prefix-cli: missing
165+
```
166+
167+
## `vpt stat-file $VP_HOME/bins/npm-global-prefix-cli.json --assert missing`
168+
169+
```
170+
<home>/.vite-plus/bins/npm-global-prefix-cli.json: missing
171+
```

0 commit comments

Comments
 (0)