Skip to content

Remove yarn check - #106

Merged
arcanis merged 1 commit into
yarnpkg:masterfrom
arcanis:remove-yarn-check
Feb 18, 2019
Merged

arcanis merged 1 commit into
yarnpkg:masterfrom
arcanis:remove-yarn-check

Conversation

@arcanis

@arcanis arcanis commented Oct 30, 2018

Copy link
Copy Markdown
Member

Cf document for motivations; in short this command is of little to no use to us, but contributes to our users being confused by its buggy behavior.

@cprussin

cprussin commented Oct 30, 2018 •

Copy link
Copy Markdown

@arcanis our current use case for yarn check is to catch cases where developers are switching between branches and not running yarn, causing them to write code against library versions that don't match what goes to prod (we run yarn check on pre-push and fail the push if the developer is in an inconsistent state). Without yarn check, what is yarn's suggested mechanism for avoiding these types of issues?

Things we considered:

  1. Run yarn on post-merge. This is impractical because, while yarn is fast, we have a large app with many dependencies and the yarn install is slow enough to be a burden.
  2. Ignore inconsistent states and let CI catch issues. This is impractical because it requires an extremely high bar of automated testing, and it's likely that new code that developers write will have untested components.

How do you guys typically handle this scenario?

cc @betaorbust

@arcanis

arcanis commented Oct 31, 2018

Copy link
Copy Markdown
Member Author

How do you guys typically handle this scenario?

Right now we simply make our development server restart (and run yarn install again) when they detect that the package.json or yarn.lock is modified.


I think the solution will eventually be in the form of the project-local cache folder. It's currently a work in progress (which will probably be shipped as an experimental feature early next year), but the idea I'm working on is to make Yarn a development-only tool: you wouldn't need to run it at all on production / CI. In fact, you wouldn't have to run it at all except when running yarn add/remove/upgrade.

In order to do this, the cache folder (that would be reworked to only contain zip files) along with the .pnp.js file would have to be checked-in within your repository. By doing this, your developers wouldn't be able to forget running yarn install: they would get the right versions of everything just by switching branches.

@alloy

alloy commented Oct 31, 2018

Copy link
Copy Markdown

How do you guys typically handle this scenario?

In CocoaPods we solved this by having a manifest of what got installed inside the dependencies directory that CocoaPods would check for and compare to the lockfile in the project during a build.

In the case of Yarn when running a command through yarn [command] I can see it check node_modules for a copy of yarn.lock or a checksum of yarn.lock and compare it to the one in the project.


## 2. Detailed Design

We'll remove the `yarn check` command in Yarn 2.0.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well as yarn install --check-files, I assume?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So --check-files is a bit different - it doesn't actually check 😅

It has to do with the way we make an early bailout if the node_modules is already there (to avoid running an installation if there is no need). Without --check-files Yarn will only checks for the various folders to exist (plus various other settings), whereas with --check-files it will also check for all the registered files to exist. It's not super useful anymore, but it's not as redundant as yarn check.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. That’s unfortunate, I like the integrity check of —check-files, but for most people I can see checking of the expected directories exist is probably enough.

@alloy

alloy commented Oct 31, 2018

Copy link
Copy Markdown

At Artsy we’ve been telling everybody to run yarn install --check-files all the time, so I’m very much in favour of yarn install ensuring a correct installation by default 👍


## 4. Drawbacks

- The one use of `yarn check` is to provide debug information when installs aren't properly made. In practice it's never used this way, even by maintainers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha true, it'd point out any glaring issues but I'd agree the results aren't reliable at all, esp with workspaces and resolutions

@hibachrach

Copy link
Copy Markdown

Why isn't this mentioned anywhere on the website or in the yarn repo for 1.x? A little frustrated as we lost a day to this and had to do some sizable reverts.

YourFin added a commit to AlexanderOtavka/ride-board that referenced this pull request Jan 11, 2020
They have been deprecated by yarn:
yarnpkg/rfcs#106
@ndbroadbent

Copy link
Copy Markdown

Hello,

I would like to add a yarn check stage to my CI builds, and fail if there are any warnings or errors. For example, here are some current issues that I'm fixing:

$ yarn check
yarn check v1.19.2
error "acorn" is wrong version: expected "6.4.1", got "7.2.0"
error "espree#acorn" not installed
warning "jest-environment-jsdom#jest-util#@jest/source-map@^24.9.0" could be deduped from "24.9.0" to "@jest/source-map@24.9.0"
warning "babel-jest#@jest/transform#jest-util#@jest/source-map@^24.9.0" could be deduped from "24.9.0" to "@jest/source-map@24.9.0"
error "espree#acorn-jsx" not installed
warning "babel-jest#jest-util#@jest/console#@jest/source-map@^24.9.0" could be deduped from "24.9.0" to "@jest/source-map@24.9.0"
warning "jest-environment-jsdom#jest-util#@jest/console#@jest/source-map@^24.9.0" could be deduped from "24.9.0" to "@jest/source-map@24.9.0"
warning "@jest/fake-timers#@jest/test-result#@jest/console#@jest/source-map@^24.9.0" could be deduped from "24.9.0" to "@jest/source-map@24.9.0"
error "jest-config#jsdom#acorn" not installed
info Found 5 warnings.
error Found 4 errors.
info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.

I read the page at https://yarnpkg.com/en/docs/cli/check, and found this issue. But it looks like yarn install check-files doesn't have the same behavior:

$ yarn install --check-files
yarn install v1.19.2
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 2.66s.

Also I'm trying to get some other warnings/errors to show up with a CLI flag, but it seems like I need to run: rm yarn.lock && yarn to get these to appear:

$ yarn
yarn install v1.19.2
info No lockfile found.
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
warning @babel/cli > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning @babel/cli > chokidar > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
warning @babel/cli > chokidar > braces > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
warning @babel/cli > chokidar > braces > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning @babel/polyfill@7.8.7: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning @babel/polyfill > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning babel-jest > @jest/transform > jest-haste-map > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
warning jest > @jest/core > jest-config > jest-environment-jsdom > jsdom > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning jest-environment-enzyme > jest-environment-jsdom > jsdom > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning jest-environment-enzyme > jest-environment-jsdom > jsdom > left-pad@1.3.0: use String.prototype.padStart()
warning node-sass > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning node-sass > node-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning rc-slider > babel-runtime > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning react-on-rails > @babel/runtime-corejs2 > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning resolve-url-loader > rework > css > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning webpack > watchpack > watchpack-chokidar2 > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning webpack-dev-server > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
[3/5] 🚚  Fetching packages...
[4/5] 🔗  Linking dependencies...
[5/5] 🔨  Building fresh packages...
success Saved lockfile.
✨  Done in 94.72s.

I would like to check for all of these warnings and errors in my CI builds, and fail the build if there are any problems with my package.json or yarn.lock. What would be the best way to do this without using yarn check? (and maybe also without rm yarn.lock)

kogekiplay added a commit to kogekiplay/pd-openweb that referenced this pull request Sep 12, 2026
依赖图零变化:迁移前后 node_modules 里唯一 name@version 都是 1526 个,逐条 diff
完全一致。实例数 1568 → 1565,少的 3 个是 Berry 把 @babel/generator、
@types/d3-timer 等重复副本去重上提,同一版本换了摆放位置,不是版本变动。
门禁:67/67 行为 spec 通过;语义差分 4914 key(基线 4916,无新增,去重反而消掉 2 条)。

不用 PnP。理由不是保守,是三条会当场断的具体依赖,写在 .yarnrc.yml 里:
scripts/*.js 全以 `node ./xxx` 调用(PnP 下必须 `yarn node`)、@ant-design/cli
按 node_modules 布局找包、排障要能直接读 node_modules/antd/es/**(antd 6 迁移
里 showSearch 传对象=强制开搜索、Select 的 CSS 变量来源都是这么查出来的)。

── yarn check 的替代(本次的主要工作量)────────────────────────────────
yarn 2 删掉了 `yarn check`(yarnpkg/rfcs#106,2019-02-18 合入),pre-push 里那条
node_modules 一致性预检失去依据。那条预检不是装饰,钩子注释记着它栽过三次,最近
一次 2026-09-11 吐出 131 条指向业务文件的假类型错。所以补 scripts/install-stamp.js:
安装时把「依赖声明 + yarn.lock」的 sha256 落到 node_modules/.install-stamp.json,
push 前比对。

能力不缩水,有依据:读 yarn 1 的 lib/cli.js 可确认
InstallationIntegrityChecker.check() 比对的就是 .yarn-integrity 这个 JSON,最后只
判断 node_modules 这个【目录】在不在,从不逐包走盘(走盘的是另一个开关
--check-files,而 --integrity 明确把它从比对里过滤掉)。
反过来还更好:不再需要 yarn 在 PATH 上,只要 node——而 node 本来就是其余门禁的前提。
5 个反例验证过:改依赖版本/改 resolutions/改 lock 都拦下,只改 scripts/version 不误报,
戳缺失时给警告而不是拦。

── 戳为什么挂插件而不是 postinstall(踩过的坑)────────────────────────
先用的 postinstall,实测有死局:Berry 按依赖树哈希缓存 build 结果,树没变就不重跑
workspace 的 postinstall。于是改了 package.json(如 "antd": "6.6.3" → "^6.6.3",
解析结果同版本但 lock 内容变了)→ 指纹变 → 门禁喊"跑 yarn install" → 跑了 → yarn
判定无需 rebuild、不执行 postinstall → 戳还是旧的 → 继续喊。一个永远过不去、提示还
是错的门禁比没有更糟:它教会所有人用 --no-verify,把行为门禁和类型门禁一起带走。
改用官方的 afterAllInstalled 钩子(.yarn/plugins/install-stamp.cjs),不参与 build
缓存,每次 install 必跑。已验证:同样条件下戳正常刷新,死局解除。

── 迁移工具动过、但没说的两处 ─────────────────────────────────────────
1. 静默删掉 resolutions 里的 "mermaid/**/d3-color": "3.1.0",日志一个字没有。原因是
   Berry 的 resolutions 只支持一层嵌套,不认 ** 跨层 glob。结论是不用补,但依据不是
   "反正版本没变":树里 d3-color 只有 `1 - 3` 和 `3` 两个 descriptor,都封顶在 4 以下,
   未来也漂不出 3.x,这条 pin 自始至终是空操作(跟 .yarnrc 一样是 7.4.0 上游带进来的)。
2. 自动写入两条 v1 兼容垫片,均已删除并记在 .yarnrc.yml:
   - approvedGitRepositories: ["**"] —— 本仓 git/github 协议依赖 0 条,这条不解决任何
     问题,只是把"任意 git 仓库都能当依赖装进来"的口子敞开。
   - npmMinimalAgeGate: 0 —— 关掉 Yarn 4 的供应链防护(默认 1440 分钟,即拒绝安装发布
     不足 24h 的版本;npm 包被投毒后的攻击窗口正是头几小时)。本仓是全公司 OA 的部署源,
     依赖升级一向显式逐个走,等一天不影响节奏,恢复默认。
教训:yarn 迁移会不告而删自己看不懂的配置,迁完必须逐条对账,不能只看 install 报没报错。

其它:.yarnrc(ignore-engines) 删除,Berry 无此开关也不需要(engines 不满足只警告不
失败,且 node 26 满足树里全部 717 条 engines.node);engines.yarn 1.22.22 → >=4.18.0;
packageManager 补回 corepack 完整性哈希(yarn set version 默认不写,是 set version 的
一次静默降级);.gitignore 用白名单收 .yarn/,只提交 plugins,1.7MB 的 install-state.gz
不进仓库。

验证:yarn install exit 0 → webpack Compiled successfully in 22.96s,0 error,
:30001 HTTP 301 正常。16 条 resolutions 逐条核对全部生效。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants