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,17 @@
// 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 stamp is deliberately limited to the two
// package-manager detection channels; Bun remains outside that narrow
// compatibility contract. The user-agent platform/arch tail (`linux x64`)
// and pnpm native executable suffix are normalized across platforms.
const vars = ['npm_execpath', 'npm_config_user_agent'];
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>');
} else {
value = value.replace(/pnpm\.native\.exe$/, 'pnpm.native');
}
console.log(`${name}=${value}`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "vite-task-lifecycle-env",
"private": true,
"scripts": {
"check-env": "node check-env.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[[case]]
name = "vite_task_lifecycle_env_npm"
vp = "local"
comment = """
Regression test for #2317 using Vite+'s real managed npm distribution. `vp run`
stamps npm's CLI entry and user agent for package-manager detection.
"""
steps = [
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "npm@10.9.8"], snapshot = false },
{ argv = ["npm", "--version"], comment = "Execute the pinned npm binary", timeout = 120000 },
{ argv = ["vp", "run", "check-env"] },
]

[[case]]
name = "vite_task_lifecycle_env_yarn"
vp = "local"
env = { YARN_ENABLE_TELEMETRY = "0" }
comment = """
Regression test for #2317 using Vite+'s real managed Yarn distribution. `vp run`
stamps Yarn's CLI entry and user agent for package-manager detection.
"""
steps = [
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "yarn@4.17.1"], snapshot = false },
{ argv = ["yarn", "--version"], comment = "Execute the pinned Yarn binary", timeout = 120000 },
{ argv = ["vp", "run", "check-env"] },
]

[[case]]
name = "vite_task_lifecycle_env_pnpm11"
vp = "local"
comment = """
Regression test for #2317 using Vite+'s real managed pnpm 11 distribution.
`vp run` stamps pnpm's JavaScript CLI entry and Node-backed user agent.
"""
steps = [
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "pnpm@11.20.0"], snapshot = false },
{ argv = ["pnpm", "--version"], comment = "Execute the pinned pnpm 11 binary", timeout = 120000 },
{ argv = ["vp", "run", "check-env"] },
]

[[case]]
name = "vite_task_lifecycle_env_pnpm12"
vp = "local"
comment = """
Regression test for #2317 using Vite+'s real managed native pnpm 12
distribution. `npm_execpath` uses the native entry and the user agent reports
`node/?` instead of leaking the Node.js version that hosts Vite+.
"""
steps = [
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "pnpm@12.0.0"], snapshot = false },
{ argv = ["pnpm", "--version"], comment = "Execute the pinned native pnpm 12 binary", timeout = 120000 },
{ argv = ["vp", "run", "check-env"] },
]

[[case]]
name = "vite_task_lifecycle_env_bun"
vp = "local"
comment = """
Boundary coverage with Vite+'s real managed Bun distribution. The narrow #2317
fix does not emulate Bun's lifecycle environment, so both values stay undefined.
"""
steps = [
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "bun@1.3.14"], snapshot = false },
{ argv = ["bun", "--version"], comment = "Execute the pinned Bun binary", timeout = 120000 },
{ argv = ["vp", "run", "check-env"] },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# vite_task_lifecycle_env_bun

Boundary coverage with Vite+'s real managed Bun distribution. The narrow #2317
fix does not emulate Bun's lifecycle environment, so both values stay undefined.

## `vpt json-edit package.json packageManager bun@1.3.14`


## `bun --version`

Execute the pinned Bun binary

```
1.3.14
```

## `vp run check-env`

```
$ node check-env.js ⊘ cache disabled
npm_execpath=(undefined)
npm_config_user_agent=(undefined)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# vite_task_lifecycle_env_npm

Regression test for #2317 using Vite+'s real managed npm distribution. `vp run`
stamps npm's CLI entry and user agent for package-manager detection.

## `vpt json-edit package.json packageManager npm@10.9.8`


## `npm --version`

Execute the pinned npm binary

```
<version>
```

## `vp run check-env`

```
$ node check-env.js ⊘ cache disabled
npm_execpath=<home>/.vite-plus/package_manager/npm/<version>/npm/bin/npm-cli.js
npm_config_user_agent=npm/<version> node/<version> <platform> <arch> workspaces/false
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# vite_task_lifecycle_env_pnpm11

Regression test for #2317 using Vite+'s real managed pnpm 11 distribution.
`vp run` stamps pnpm's JavaScript CLI entry and Node-backed user agent.

## `vpt json-edit package.json packageManager pnpm@11.20.0`


## `pnpm --version`

Execute the pinned pnpm 11 binary

```
11.20.0
```

## `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>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# vite_task_lifecycle_env_pnpm12

Regression test for #2317 using Vite+'s real managed native pnpm 12
distribution. `npm_execpath` uses the native entry and the user agent reports
`node/?` instead of leaking the Node.js version that hosts Vite+.

## `vpt json-edit package.json packageManager pnpm@12.0.0`


## `pnpm --version`

Execute the pinned native pnpm 12 binary

```
12.0.0
```

## `vp run check-env`

```
$ node check-env.js ⊘ cache disabled
npm_execpath=<home>/.vite-plus/package_manager/pnpm/<version>/pnpm/bin/pnpm.native
npm_config_user_agent=pnpm/<version> npm/? node/? <platform> <arch>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# vite_task_lifecycle_env_yarn

Regression test for #2317 using Vite+'s real managed Yarn distribution. `vp run`
stamps Yarn's CLI entry and user agent for package-manager detection.

## `vpt json-edit package.json packageManager yarn@4.17.1`


## `yarn --version`

Execute the pinned Yarn binary

```
4.17.1
```

## `vp run check-env`

```
$ node check-env.js ⊘ cache disabled
npm_execpath=<home>/.vite-plus/package_manager/yarn/<version>/yarn/bin/yarn.js
npm_config_user_agent=yarn/<version> npm/? node/<version> <platform> <arch>
```
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 @@ -24,6 +25,7 @@ pub use dispatch::{
dispatch_with_resolved_package_manager,
};
pub use error::Error;
pub use lifecycle_env::LifecycleEnvContext;
pub use package_manager::{
EnvironmentPackageManagerResolution, PackageManager, PackageManagerBuilder,
PackageManagerResolution, PackageManagerSource, PackageManagerType, download_package_manager,
Expand Down
Loading
Loading