Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Package.json script tasks don't expose npm lifecycle env; cache-enabled tasks strip host-stamped values

未关闭
#692 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
nodejs, rust

调研方向

从 vt_plan 中的 plan_spawn_execution 开始,检查 EnvFingerprints::resolve、DEFAULT_UNTRACKED_ENV 以及现有的 MARKER_ENV_NAME 插入。然后端到端阅读 vp_run_env fixture,包括其缓存用例。完成标准是:package.json 中的任务保留相关的 npm 生命周期环境,包括启用缓存的任务,并覆盖所报告的行为。

由索引模型根据 Issue 内容生成。

描述

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 checkrun-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:

  1. Cache-enabled tasks strip the stamped vars again. plan_spawn_execution runs EnvFingerprints::resolve(&mut spawn_envs, &cache_config.env_config) before spawning, and DEFAULT_UNTRACKED_ENV contains no lowercase npm_* name (matching is case-sensitive on Unix). So for cache: { 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. The VP_RUN marker had this exact problem and is re-inserted after the filter, with a comment explaining why.
  2. npm_lifecycle_event / npm_lifecycle_script are 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_NAME insert in vt_plan (or add them to DEFAULT_UNTRACKED_ENV), so host-provided lifecycle env survives cache-enabled tasks.
  • Optionally set npm_lifecycle_event (and npm_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).

主要语言
Rust
星标
466
派生
42
平均合并
1 天 20 小时
30 天内合并 PR
21

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

voidzero-dev/vite-task 的其他 Issue

查看 voidzero-dev/vite-task 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。