-
Notifications
You must be signed in to change notification settings - Fork 256
feat(env): disable pnpm runtime for managed node #2469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
liangmiQwQ
wants to merge
8
commits into
voidzero-dev:main
from
liangmiQwQ:liang/codex/inject-pnpm-runtime-env
Closed
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1f7b1f6
feat(env): disable pnpm runtime for managed node
liangmiQwQ edfa6d5
Merge branch 'main' into liang/codex/inject-pnpm-runtime-env
liangmiQwQ 53dee88
fix(env): preserve pnpm runtime boundaries
liangmiQwQ 1996c5a
Merge remote-tracking branch 'origin/liang/codex/inject-pnpm-runtime-…
liangmiQwQ c7f6bc2
fix(env): verify managed node runtime
liangmiQwQ d2b6d48
fix(env): align pnpm runtime target
liangmiQwQ c853694
fix(env): preserve pnpm runtime intent
liangmiQwQ e93d951
Merge branch 'main' into liang/codex/inject-pnpm-runtime-env
liangmiQwQ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/pnpm_runtime_management/snapshots.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| [[case]] | ||
| name = "pnpm_runtime_disabled_for_managed_node" | ||
| vp = "global" | ||
| seed-runtime = false | ||
| skip-platforms = ["windows"] | ||
| comment = "Vite+ owns Node.js runtime management independently from the selected pnpm binary." | ||
| steps = [ | ||
| { argv = ["vpt", "write-file", "package.json", "{\"name\":\"pnpm-runtime-management\",\"private\":true,\"packageManager\":\"pnpm@10.18.0\",\"devEngines\":{\"runtime\":{\"name\":\"node\",\"version\":\"20.18.0\",\"onFail\":\"download\"}}}\n"], snapshot = false }, | ||
| { argv = ["vpt", "write-file", "$VP_HOME/js_runtime/node/20.18.0/bin/node", "#!/bin/sh\n"], snapshot = false }, | ||
| { argv = ["vpt", "chmod", "+x", "$VP_HOME/js_runtime/node/20.18.0/bin/node"], snapshot = false }, | ||
| { argv = ["vpt", "chmod", "+x", "system-bin/pnpm"], snapshot = false }, | ||
| { argv = ["vp", "env", "on", "node"], snapshot = false }, | ||
| { argv = ["vp", "env", "off", "pnpm"], snapshot = false }, | ||
| { argv = ["pnpm", "install"], envs = [["PATH", "${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH}"], ["PNPM_CONFIG_RUNTIME", "from-user"]], comment = "direct system-first pnpm disables its duplicate Node.js runtime" }, | ||
| { argv = ["vp", "install"], envs = [["PATH", "${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH}"], ["PNPM_CONFIG_RUNTIME", "from-user"]], comment = "pnpm-backed vp install applies the same system-first policy" }, | ||
| { argv = ["vpt", "write-file", "$VP_HOME/package_manager/pnpm/10.18.0/pnpm/bin/pnpm", "#!/bin/sh\nif [ \"$1\" = \"--version\" ]; then printf '10.18.0\\n'; else printf 'PNPM_CONFIG_RUNTIME=%s\\n' \"${PNPM_CONFIG_RUNTIME-unset}\"; fi\n"], snapshot = false }, | ||
| { argv = ["vpt", "write-file", "$VP_HOME/package_manager/pnpm/10.18.0/pnpm/bin/pnpx", "#!/bin/sh\n"], snapshot = false }, | ||
| { argv = ["vpt", "chmod", "+x", "$VP_HOME/package_manager/pnpm/10.18.0/pnpm/bin/pnpm"], snapshot = false }, | ||
| { argv = ["vpt", "chmod", "+x", "$VP_HOME/package_manager/pnpm/10.18.0/pnpm/bin/pnpx"], snapshot = false }, | ||
| { argv = ["vp", "env", "on", "pnpm"], snapshot = false }, | ||
| { argv = ["pnpm", "install"], envs = [["PNPM_CONFIG_RUNTIME", "from-user"]], comment = "direct managed pnpm disables its duplicate Node.js runtime" }, | ||
| { argv = ["vp", "install"], envs = [["PNPM_CONFIG_RUNTIME", "from-user"]], comment = "pnpm-backed vp install applies the same managed-pnpm policy" }, | ||
| ] | ||
|
|
||
| [[case]] | ||
| name = "pnpm_runtime_preserved_for_mixed_runtimes" | ||
| vp = "global" | ||
| seed-runtime = false | ||
| skip-platforms = ["windows"] | ||
| comment = "Vite+ must not disable pnpm runtimes that it cannot manage." | ||
| steps = [ | ||
| { argv = ["vpt", "write-file", "package.json", "{\"name\":\"pnpm-runtime-management\",\"private\":true,\"packageManager\":\"pnpm@10.18.0\",\"devEngines\":{\"runtime\":[{\"name\":\"node\",\"version\":\"20.18.0\",\"onFail\":\"download\"},{\"name\":\"deno\",\"version\":\"2.0.0\",\"onFail\":\"download\"}]}}\n"], snapshot = false }, | ||
| { argv = ["vpt", "write-file", "$VP_HOME/js_runtime/node/20.18.0/bin/node", "#!/bin/sh\n"], snapshot = false }, | ||
| { argv = ["vpt", "chmod", "+x", "$VP_HOME/js_runtime/node/20.18.0/bin/node"], snapshot = false }, | ||
| { argv = ["vpt", "chmod", "+x", "system-bin/pnpm"], snapshot = false }, | ||
| { argv = ["vp", "env", "on", "node"], snapshot = false }, | ||
| { argv = ["vp", "env", "off", "pnpm"], snapshot = false }, | ||
| { argv = ["pnpm", "install"], envs = [["PATH", "${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH}"], ["PNPM_CONFIG_RUNTIME", "from-user"]], comment = "direct pnpm preserves runtime management for a mixed declaration" }, | ||
| { argv = ["vp", "install"], envs = [["PATH", "${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH}"], ["PNPM_CONFIG_RUNTIME", "from-user"]], comment = "vp install preserves the same mixed-runtime setting" }, | ||
| ] | ||
|
|
||
| [[case]] | ||
| name = "pnpm_runtime_preserved_for_system_first_node" | ||
| vp = "global" | ||
| seed-runtime = false | ||
| skip-platforms = ["windows"] | ||
| comment = "pnpm keeps runtime ownership when Vite+ does not manage Node.js." | ||
| steps = [ | ||
| { argv = ["vpt", "write-file", "package.json", "{\"name\":\"pnpm-runtime-management\",\"private\":true,\"packageManager\":\"pnpm@10.18.0\",\"devEngines\":{\"runtime\":{\"name\":\"node\",\"version\":\"20.18.0\",\"onFail\":\"download\"}}}\n"], snapshot = false }, | ||
| { argv = ["vpt", "chmod", "+x", "system-bin/node"], snapshot = false }, | ||
| { argv = ["vpt", "chmod", "+x", "system-bin/pnpm"], snapshot = false }, | ||
| { argv = ["vp", "env", "off", "node"], snapshot = false }, | ||
| { argv = ["vp", "env", "off", "pnpm"], snapshot = false }, | ||
| { argv = ["pnpm", "install"], envs = [["PATH", "${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH}"], ["PNPM_CONFIG_RUNTIME", "from-user"]], comment = "direct pnpm preserves runtime management with system-first Node.js" }, | ||
| { argv = ["vp", "install"], envs = [["PATH", "${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH}"], ["PNPM_CONFIG_RUNTIME", "from-user"]], comment = "vp install preserves the same system-first Node.js policy" }, | ||
| ] |
77 changes: 77 additions & 0 deletions
77
...res/pnpm_runtime_management/snapshots/pnpm_runtime_disabled_for_managed_node.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # pnpm_runtime_disabled_for_managed_node | ||
|
|
||
| Vite+ owns Node.js runtime management independently from the selected pnpm binary. | ||
|
|
||
| ## `vpt write-file package.json '{"name":"pnpm-runtime-management","private":true,"packageManager":"pnpm@10.18.0","devEngines":{"runtime":{"name":"node","version":"20.18.0","onFail":"download"}}} | ||
| '` | ||
|
|
||
|
|
||
| ## `vpt write-file $VP_HOME/js_runtime/node/20.18.0/bin/node '#'\!'/bin/sh | ||
| '` | ||
|
|
||
|
|
||
| ## `vpt chmod +x $VP_HOME/js_runtime/node/20.18.0/bin/node` | ||
|
|
||
|
|
||
| ## `vpt chmod +x system-bin/pnpm` | ||
|
|
||
|
|
||
| ## `vp env on node` | ||
|
|
||
|
|
||
| ## `vp env off pnpm` | ||
|
|
||
|
|
||
| ## `PATH=${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH} PNPM_CONFIG_RUNTIME=from-user pnpm install` | ||
|
|
||
| direct system-first pnpm disables its duplicate Node.js runtime | ||
|
|
||
| ``` | ||
| PNPM_CONFIG_RUNTIME=false | ||
| ``` | ||
|
|
||
| ## `PATH=${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH} PNPM_CONFIG_RUNTIME=from-user vp install` | ||
|
|
||
| pnpm-backed vp install applies the same system-first policy | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| PNPM_CONFIG_RUNTIME=false | ||
| ``` | ||
|
|
||
| ## `vpt write-file $VP_HOME/package_manager/pnpm/10.18.0/pnpm/bin/pnpm '#'\!'/bin/sh | ||
| if [ "$1" = "--version" ]; then printf '\''10.18.0\n'\''; else printf '\''PNPM_CONFIG_RUNTIME=%s\n'\'' "${PNPM_CONFIG_RUNTIME-unset}"; fi | ||
| '` | ||
|
|
||
|
|
||
| ## `vpt write-file $VP_HOME/package_manager/pnpm/10.18.0/pnpm/bin/pnpx '#'\!'/bin/sh | ||
| '` | ||
|
|
||
|
|
||
| ## `vpt chmod +x $VP_HOME/package_manager/pnpm/10.18.0/pnpm/bin/pnpm` | ||
|
|
||
|
|
||
| ## `vpt chmod +x $VP_HOME/package_manager/pnpm/10.18.0/pnpm/bin/pnpx` | ||
|
|
||
|
|
||
| ## `vp env on pnpm` | ||
|
|
||
|
|
||
| ## `PNPM_CONFIG_RUNTIME=from-user pnpm install` | ||
|
|
||
| direct managed pnpm disables its duplicate Node.js runtime | ||
|
|
||
| ``` | ||
| PNPM_CONFIG_RUNTIME=false | ||
| ``` | ||
|
|
||
| ## `PNPM_CONFIG_RUNTIME=from-user vp install` | ||
|
|
||
| pnpm-backed vp install applies the same managed-pnpm policy | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| PNPM_CONFIG_RUNTIME=false | ||
| ``` |
41 changes: 41 additions & 0 deletions
41
.../pnpm_runtime_management/snapshots/pnpm_runtime_preserved_for_mixed_runtimes.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # pnpm_runtime_preserved_for_mixed_runtimes | ||
|
|
||
| Vite+ must not disable pnpm runtimes that it cannot manage. | ||
|
|
||
| ## `vpt write-file package.json '{"name":"pnpm-runtime-management","private":true,"packageManager":"pnpm@10.18.0","devEngines":{"runtime":[{"name":"node","version":"20.18.0","onFail":"download"},{"name":"deno","version":"2.0.0","onFail":"download"}]}} | ||
| '` | ||
|
|
||
|
|
||
| ## `vpt write-file $VP_HOME/js_runtime/node/20.18.0/bin/node '#'\!'/bin/sh | ||
| '` | ||
|
|
||
|
|
||
| ## `vpt chmod +x $VP_HOME/js_runtime/node/20.18.0/bin/node` | ||
|
|
||
|
|
||
| ## `vpt chmod +x system-bin/pnpm` | ||
|
|
||
|
|
||
| ## `vp env on node` | ||
|
|
||
|
|
||
| ## `vp env off pnpm` | ||
|
|
||
|
|
||
| ## `PATH=${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH} PNPM_CONFIG_RUNTIME=from-user pnpm install` | ||
|
|
||
| direct pnpm preserves runtime management for a mixed declaration | ||
|
|
||
| ``` | ||
| PNPM_CONFIG_RUNTIME=from-user | ||
| ``` | ||
|
|
||
| ## `PATH=${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH} PNPM_CONFIG_RUNTIME=from-user vp install` | ||
|
|
||
| vp install preserves the same mixed-runtime setting | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| PNPM_CONFIG_RUNTIME=from-user | ||
| ``` |
37 changes: 37 additions & 0 deletions
37
...pm_runtime_management/snapshots/pnpm_runtime_preserved_for_system_first_node.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # pnpm_runtime_preserved_for_system_first_node | ||
|
|
||
| pnpm keeps runtime ownership when Vite+ does not manage Node.js. | ||
|
|
||
| ## `vpt write-file package.json '{"name":"pnpm-runtime-management","private":true,"packageManager":"pnpm@10.18.0","devEngines":{"runtime":{"name":"node","version":"20.18.0","onFail":"download"}}} | ||
| '` | ||
|
|
||
|
|
||
| ## `vpt chmod +x system-bin/node` | ||
|
|
||
|
|
||
| ## `vpt chmod +x system-bin/pnpm` | ||
|
|
||
|
|
||
| ## `vp env off node` | ||
|
|
||
|
|
||
| ## `vp env off pnpm` | ||
|
|
||
|
|
||
| ## `PATH=${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH} PNPM_CONFIG_RUNTIME=from-user pnpm install` | ||
|
|
||
| direct pnpm preserves runtime management with system-first Node.js | ||
|
|
||
| ``` | ||
| PNPM_CONFIG_RUNTIME=from-user | ||
| ``` | ||
|
|
||
| ## `PATH=${VP_HOME}/bin${PATH_SEPARATOR}${workspace}/system-bin${PATH_SEPARATOR}${PATH} PNPM_CONFIG_RUNTIME=from-user vp install` | ||
|
|
||
| vp install preserves the same system-first Node.js policy | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| PNPM_CONFIG_RUNTIME=from-user | ||
| ``` |
2 changes: 2 additions & 0 deletions
2
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/pnpm_runtime_management/system-bin/node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/sh | ||
| printf 'v20.18.0\n' |
6 changes: 6 additions & 0 deletions
6
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/pnpm_runtime_management/system-bin/pnpm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/bin/sh | ||
| if [ "$1" = "--version" ]; then | ||
| printf '10.18.0\n' | ||
| else | ||
| printf 'PNPM_CONFIG_RUNTIME=%s\n' "${PNPM_CONFIG_RUNTIME-unset}" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| use vp_shared::PackageJson; | ||
| use vt_path::AbsolutePath; | ||
|
|
||
| use super::env::config::ShimMode; | ||
| use crate::error::Error; | ||
|
|
||
| pub(crate) const PNPM_CONFIG_RUNTIME: &str = "PNPM_CONFIG_RUNTIME"; | ||
| pub(crate) const PNPM_CONFIG_RUNTIME_DISABLED: &str = "false"; | ||
|
liangmiQwQ marked this conversation as resolved.
|
||
|
|
||
| pub(crate) async fn should_disable( | ||
| cwd: &AbsolutePath, | ||
| node_shim_mode: ShimMode, | ||
| ) -> Result<bool, Error> { | ||
| if node_shim_mode != ShimMode::Managed { | ||
| return Ok(false); | ||
|
liangmiQwQ marked this conversation as resolved.
|
||
| } | ||
|
|
||
| let workspace = match vt_workspace::find_workspace_root(cwd) { | ||
| Ok((workspace, _)) => workspace, | ||
| Err(vt_workspace::Error::PackageJsonNotFound(_)) => return Ok(false), | ||
| Err(error) => return Err(error.into()), | ||
| }; | ||
| let content = tokio::fs::read_to_string(workspace.path.join("package.json")).await?; | ||
| let package_json: PackageJson = serde_json::from_str(&content)?; | ||
|
liangmiQwQ marked this conversation as resolved.
Outdated
|
||
| let Some(runtime) = package_json.dev_engines.and_then(|engines| engines.runtime) else { | ||
|
liangmiQwQ marked this conversation as resolved.
Outdated
|
||
| return Ok(false); | ||
| }; | ||
| let entries = runtime.entries(); | ||
|
|
||
| // pnpm's runtime opt-out covers Node.js, Bun, and Deno together, so Vite+ | ||
| // can use it only when every declared runtime is one Vite+ manages. | ||
| Ok(!entries.is_empty() && entries.iter().all(|entry| entry.name == "node")) | ||
|
liangmiQwQ marked this conversation as resolved.
Outdated
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.