voidzero-dev / voidzero-dev/vite-task
Package.json script tasks don't expose npm lifecycle env; cache-enabled tasks strip host-stamped values
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Rust
- Sterne
- 466
- Forks
- 42
- Ø Merge
- 1 T. 15 Std.
- Gemergte PRs (30 T.)
- 19
Beschreibung
Summary
When vite-task spawns a package.json script, the child gets none of the npm lifecycle environment variables (npm_execpath, npm_config_user_agent, npm_lifecycle_event, npm_node_execpath, …) that npm, pnpm, and Yarn all set when they run scripts. Tools that detect their invoking package manager from that env — npm-run-all2/run-p being the common one — silently fall back to npm, which then fails devEngines.packageManager enforcement in pnpm projects.
Downstream report: voidzero-dev/vite-plus#2317 (vpr check → run-p → npm → EBADDEVENGINES). Reproduced there with a minimal project: pnpm run check sets npm_execpath=<pnpm>/bin/pnpm.mjs, npm_config_user_agent=pnpm/11.20.0 …, npm_lifecycle_event=probe for the child; the same script through the task runner gets none of them.
Why a vite-plus-side fix can't fully cover it
voidzero-dev/vite-plus#2385 stamps npm_execpath / npm_config_user_agent / npm_node_execpath / INIT_CWD into the process env before Session::init snapshots it. That works for plain scripts (which default to cache: scripts: false), but two pieces need the planner:
- Cache-enabled tasks strip the stamped vars again.
plan_spawn_executionrunsEnvFingerprints::resolve(&mut spawn_envs, &cache_config.env_config)before spawning, andDEFAULT_UNTRACKED_ENVcontains no lowercasenpm_*name (matching is case-sensitive on Unix). So forcache: { scripts: true }or config-defined tasks (cached by default), the session-level stamp is filtered out and the npm fallback returns — only in the cached case, which no fixture currently exercises. TheVP_RUNmarker had this exact problem and is re-inserted after the filter, with a comment explaining why. npm_lifecycle_event/npm_lifecycle_scriptare per-task values (script name / script body). Only the planner knows them; a session-level stamp can't provide them. pnpm sets both for every script it runs.
Suggested direction
- Re-insert the lifecycle names post-filter next to the existing
MARKER_ENV_NAMEinsert invt_plan(or add them toDEFAULT_UNTRACKED_ENV), so host-provided lifecycle env survives cache-enabled tasks. - Optionally set
npm_lifecycle_event(andnpm_lifecycle_script) from the task itself when spawning package.json scripts, which vite-plus cannot do from outside.
Happy to send a PR for either or both if the direction sounds right — the vp_run_env e2e fixture looks like the natural place for coverage (its cached case already demonstrates the marker surviving the env filter).
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in vt_plan bei plan_spawn_execution und untersuche EnvFingerprints::resolve, DEFAULT_UNTRACKED_ENV und die bestehende Einfügung von MARKER_ENV_NAME. Lies anschließend das End-to-End-Fixture von vp_run_env vollständig durch, einschließlich seines gecachten Falls. Erledigt ist die Aufgabe, wenn die Aufgaben in package.json die relevante npm-Lifecycle-Umgebung beibehalten, einschließlich cache-aktivierter Aufgaben, mit Abdeckung für das gemeldete Verhalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- nodejs, rust
- Bereich
- build-system, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 65/100