`corepack use` in monorepo targets root not project package.json
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- node.js, typescript
调研方向
从 corepack use 命令的实现开始,在嵌套项目目录中使用 issue 里的命令重现该行为。跟踪它如何查找 package.json 文件,以及如何选择用于写入和安装的文件。完成的标准是:嵌套项目的 package.json 被创建或更新,同时不修改仓库根目录的 package.json,并通过重现确认结果。
由索引模型根据 Issue 内容生成。
描述
Current behavior
In a monorepo if corepack use is executed in a project directory, which is a sub-directory of a monorepo root directory containing an existing package.json, it does not create or update the package.json in the project directory. Instead it makes changes to the package.json in the root of the monorepo.
The monorepo is not a workspace. Each project is separate.
Expected behavior
If corepack use is executed in a monorepo project directory, it should operate on or create a package.json in that directory not in the root directory of the monorepo.
The corepack README does not discuss how corepack use is supposed to behave in a hierarchy of directories containing their own package.json files. It says simply:
When run, this command will retrieve the latest release matching the provided descriptor, assign it to the project's package.json file, and automatically perform an install.
The Node.js documentation for corepack Configuring a package says:
The Corepack proxies will find the closest package.json file in your current directory hierarchy to extract its "packageManager" property.
I would understand this to mean that if there is a package.json in the current working directory, then corepack use should act on this package.json, and not search up the hierarchy to change a higher level package.json
Step to reproduce
Ubuntu 24.04.1 LTS, Node.js 22.13.0 LTS, Corepack 0.30.0
rm -rf ~/.cache/node/corepack
corepack enable yarn
git clone https://github.com/cypress-io/github-action
cd github-action
git clean -xfd # if repeating
cd examples/yarn-classic
corepack use yarn@1.22.22
git status
package.json in the root of the repo has been modified (not examples/yarn-classic/package.json) with the addition of
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
yarn install has been run in examples/yarn-classic, creating a new examples/yarn-classic/node_modules directory there.
Logs
The debug logs do not show which directory is being used to write a package.json file, nor which directory yarn install is being run in:
$ corepack use yarn@1.22.22
Installing yarn@1.22.22 in the project...
corepack Installing yarn@1.22.22 from https://registry.yarnpkg.com/yarn/-/yarn-1.22.22.tgz +0ms
corepack Downloading to /home/mike/.cache/node/corepack/v1/corepack-5003-f7268cee.b6ed3 +1ms
corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +802ms
corepack No LastKnownGood version found in Corepack home. +0ms
corepack Download and install of yarn@1.22.22 is finished +0ms
corepack Checking /home/mike/github/cypress-io/github-action/examples/yarn-classic/package.json +1ms
corepack Checking /home/mike/github/cypress-io/github-action/examples/package.json +0ms
corepack Checking /home/mike/github/cypress-io/github-action/package.json +0ms
corepack Checking /home/mike/github/cypress-io/package.json +1ms
corepack Checking /home/mike/github/package.json +0ms
corepack Checking /home/mike/package.json +0ms
corepack Checking /home/package.json +0ms
corepack Checking /package.json +0ms
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
- 主要语言
- TypeScript
- 星标
- 3.8k
- 派生
- 279
- 平均合并
- 1 小时 47 分钟
- 30 天内合并 PR
- 2
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nodejs/corepack 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 4/5 3-5 天 新手友好度 68/100
-
难度 3/5 1-2 天 新手友好度 52/100
-
难度 3/5 1-2 天 新手友好度 68/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
safetrustcr/dApp-SafeTrust#426 ·
-
area:workflow bug ready-for-agent
难度 2/5 1-3 小时 新手友好度 75/100
fil-donadoni/tolaria#4409 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
Fission-AI/OpenSpec#1960 ·
-
Add dependabot 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
corsairdev/corsair#1764 ·