Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Surfaces the package-manager lifecycle env that `vp run` stamps for
// package.json scripts (#2317): before the fix every variable below printed
// `(undefined)`, so child tooling (npm-run-all, `ni`) could not detect pnpm
// and fell back to npm. The user-agent platform/arch tail (`linux x64`) is
// the one machine-dependent value the suite redaction does not mask, so it
// is normalized here from the runtime's own platform/arch.
const vars = ['npm_execpath', 'npm_config_user_agent', 'INIT_CWD'];
for (const name of vars) {
let value = process.env[name] ?? '(undefined)';
if (name === 'npm_config_user_agent') {
value = value.replace(`${process.platform} ${process.arch}`, '<platform> <arch>');
}
console.log(`${name}=${value}`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "vite-task-lifecycle-env",
"private": true,
"scripts": {
"check-env": "node check-env.js"
},
"packageManager": "pnpm@11.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { chmodSync, mkdirSync, writeFileSync } = require('node:fs');
const { join } = require('node:path');

const vpHome = process.env.VP_HOME;
if (!vpHome) {
throw new Error('VP_HOME is required');
}

// The layout of a managed pnpm install: the JS CLI entry `pnpm.cjs` plus the
// platform shims, so package-manager resolution finds pnpm@11.0.0 without a
// download and `npm_execpath` resolves to the real JS CLI entry.
const binDir = join(vpHome, 'package_manager', 'pnpm', '11.0.0', 'pnpm', 'bin');
mkdirSync(binDir, { recursive: true });

writeFileSync(
join(binDir, 'pnpm.cjs'),
"console.log('pnpm ' + process.argv.slice(2).join(' '));\n",
);

const unixShim = join(binDir, 'pnpm');
writeFileSync(unixShim, "#!/usr/bin/env node\nrequire('./pnpm.cjs');\n");
chmodSync(unixShim, 0o755);

writeFileSync(join(binDir, 'pnpm.cmd'), '@echo off\r\nnode "%~dp0pnpm.cjs" %*\r\n');
writeFileSync(
join(binDir, 'pnpm.ps1'),
'node "$PSScriptRoot/pnpm.cjs" @args\nexit $LASTEXITCODE\n',
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[case]]
name = "vite_task_lifecycle_env"
vp = "local"
comment = """
Regression test for #2317: `vp run` stamps the package-manager lifecycle env
(npm_execpath, npm_config_user_agent, INIT_CWD) for package.json scripts, so
child tooling like npm-run-all detects pnpm instead of falling back to npm.
Pre-fix every variable printed `(undefined)`. The fake managed pnpm install
under VP_HOME keeps the case offline; the script normalizes the user-agent
platform/arch tail that suite redaction does not mask.
"""
steps = [
{ argv = ["node", "scripts/setup-fake-pnpm.cjs"], snapshot = false },
{ argv = ["vp", "run", "check-env"] },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# vite_task_lifecycle_env

Regression test for #2317: `vp run` stamps the package-manager lifecycle env
(npm_execpath, npm_config_user_agent, INIT_CWD) for package.json scripts, so
child tooling like npm-run-all detects pnpm instead of falling back to npm.
Pre-fix every variable printed `(undefined)`. The fake managed pnpm install
under VP_HOME keeps the case offline; the script normalizes the user-agent
platform/arch tail that suite redaction does not mask.

## `node scripts/setup-fake-pnpm.cjs`


## `vp run check-env`

```
$ node check-env.js ⊘ cache disabled
npm_execpath=<home>/.vite-plus/package_manager/pnpm/<version>/pnpm/bin/pnpm.cjs
npm_config_user_agent=pnpm/<version> npm/? node/<version> <platform> <arch>
INIT_CWD=<workspace>
```
2 changes: 2 additions & 0 deletions crates/vp_pm_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod config;
mod dispatch;
mod error;
mod helpers;
mod lifecycle_env;
mod package_manager;
mod request;
pub(crate) mod resolution;
Expand All @@ -21,6 +22,7 @@ pub use cli::{ManagedGlobalCommand, PackageManagerCommand, PmCommand};
pub use config::npm_registry;
pub use dispatch::dispatch;
pub use error::Error;
pub use lifecycle_env::LifecycleEnvContext;
pub use package_manager::{
PackageManager, PackageManagerBuilder, PackageManagerResolution, PackageManagerSource,
PackageManagerType, download_package_manager, get_package_manager_type_and_version,
Expand Down
Loading