Lifecycle hooks are hidden from the script list but never run in Yarn 2+ projects
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
调研方向
Start with lib/workspace.js and lib/package-managers.js to trace script grouping and package manager detection, then follow their callers in cli.js. Read the existing script and detection tests, and run them before adding coverage for Yarn 2+ signals and hook execution. Done when Yarn 2+ lists hooks separately while Yarn 1 and other managers still group hooks, with the README updated.
由索引模型根据 Issue 内容生成。
描述
Description
Since #4, the script list attaches pre/post hooks to their main script: build is shown with (+ prebuild, postbuild), and prebuild / postbuild are no longer listed. The README explains why:
Running
buildruns its hooks too, as the package manager normally does.
That is true for npm, pnpm, Bun and Yarn 1. Since version 2, Yarn no longer runs custom pre/post scripts, by design (Yarn migration guide). In a Yarn 2+ project, the CLI therefore:
- announces hooks that don't run:
buildis described as(+ prebuild, postbuild), but onlybuildruns; - hides scripts with no way to reach them:
prebuildandpostbuildare removed from the list, so they can't be run from the CLI at all.
Steps to reproduce
Requires Corepack to be enabled (corepack enable). On Node.js versions that don't bundle it, run npm install --global corepack first.
-
Create a project inside a scratch workspace:
mkdir -p /tmp/dws-repro/berry-hooks cd /tmp/dws-repro/berry-hooks -
Add this
package.json:{ "name": "berry-hooks", "packageManager": "[email protected]", "scripts": { "prebuild": "echo prebuild ran", "build": "echo build ran", "postbuild": "echo postbuild ran" } } -
Install, which creates
yarn.lock, then start the published CLI.DEV_WORKSPACE_CONFIGkeeps your own saved workspace untouched:yarn install DEV_WORKSPACE_CONFIG=/tmp/dws-repro/config.json \ npx -p @modulane/[email protected] dws --workspace /tmp/dws-repro -
Select
berry-hooks, thenbuild.
Actual behaviour
Package manager: yarn (from the packageManager field)
? Select a script
❯ ▶ build
↩ Back to projects
echo build ran (+ prebuild, postbuild)
----------------------------------------
Running: yarn run build
Directory: /tmp/dws-repro/berry-hooks
----------------------------------------
build ran
Command completed successfully.
prebuild and postbuild neither run nor appear in the list. Both still work when run directly, for example with yarn run prebuild.
Expected behaviour
In a Yarn 2+ project, prebuild and postbuild appear as ordinary scripts, and build doesn't claim to run them.
Behaviour by package manager
Running <tool> run build on the same package.json:
| Package manager | Runs prebuild / postbuild |
|---|---|
| npm 10.9.7 | Yes |
| pnpm 9 and 10 | Yes |
| Bun 1.4.4 | Yes |
| Yarn 1.22.22 | Yes |
| Yarn 2.4.2, 3.8.7 and 4.18.1 | No |
Projects that follow Yarn's advice and chain hooks explicitly ("build": "yarn prebuild && …") are partly affected: the chained hooks run, but postbuild is still announced and still hidden.
Cause
groupLifecycleScripts()runs insidegetScripts(), before the package manager is known, so hooks are always grouped.detectPackageManager()reportsyarnfor both Yarn 1 and Yarn 2+.- CI doesn't catch it:
- it installs Yarn 1 through
npm install --global yarn; - the real-script test checks which tool ran a script, not whether hooks ran.
- it installs Yarn 1 through
Suggested fix
-
Tell Yarn 2+ apart from Yarn 1 during detection. Two signals hold for Yarn 2, 3 and 4:
- a
packageManagerfield set toyarn@2or later; - a
yarn.lockthat contains a__metadata:block. Yarn 1 lockfiles never have one.
A
.yarnrc.ymlfile is not a reliable signal on its own: the reproduction above has none. - a
-
Group hooks only when the detected tool runs them. For example, the grouping could move out of
getScripts()to after detection incli.js, orgetScripts()could receive the package manager. -
Add tests:
- detection of Yarn 2+ from both signals;
- a real-script case that checks whether hooks ran, with a Yarn 2+ project in CI.
-
Update the README paragraph to mention that Yarn 2+ lists these hooks separately.
I'd be glad to open a PR for this if the approach suits you.
Environment
@modulane/dev-workspace-cli0.5.0, installed from npm.lib/is identical onmainat dfccb6b.- Node.js 22.22.2, Linux x64
- Yarn 4.18.1 through Corepack 0.34.6, plus Yarn 2.4.2 and 3.8.7 for the comparison table
- 主要语言
- JavaScript
- 星标
- 0
- 派生
- 0
- 平均合并
- 55 分钟
- 30 天内合并 PR
- 12
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modulane/dev-workspace-cli 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
modulane/dev-workspace-cli#15 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
modulane/dev-workspace-cli#14 ·
维护者通常 1 天内回复
查看 modulane/dev-workspace-cli 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 76/100
apex-dev-tools/apex-log-parser#199 ·
维护者通常 1 天内回复
-
enhancement good first issue hacktoberfest help wanted
难度 2/5 1-3 小时 新手友好度 78/100
-
ReadBufferStream.addBuffer adds the full ArrayBuffer of a typed array view, and ignores its byteOffset可能已有人在做 @wayfarer3130 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Expo 57 example: pnpm install fails with ERR_PNPM_TRUST_DOWNGRADE可能已有人在做 @github-actions 今天认领。 未关闭bug react-native team/client-libraries
难度 2/5 1-3 小时 新手友好度 68/100
PostHog/posthog-js#5442 · 1 条评论 ·
维护者通常 1 天内回复