纱线零安装 - 缺少拔出目录中的软件包但无法提交本地拔出目录

GoW*_*low 5 git yarnpkg yarnpkg-v2

切换到纱线零安装方法(请参阅https://yarnpkg.com/features/zero-installs),在运行 CI 管道时,我遇到了以下类型的错误:

/app/.pnp.cjs:47262
throw firstError;
      ^
 
Error: Required unplugged package missing from disk. This may happen when switching branches without running installs (unplugged packages must be fully materialized on disk to work).
 
Missing package: nodemon@npm:2.0.7
Expected package location: /app/.yarn/unplugged/nodemon-npm-2.0.7-7b95e46511/node_modules/nodemon/
.
.
.
Run Code Online (Sandbox Code Playgroud)

好的,这是预料之中的,因为这种方法不会运行yarn install,只是使用.yarn. 按照本段最后一点的建议https://yarnpkg.com/features/zero-installs#how-do-you-reach-this-zero-install-state-youre-advocating-for我调整了我的.gitignore.dockerignore文件包括这个:

.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
!.yarn/unplugged
Run Code Online (Sandbox Code Playgroud)

因此,拔出的文件夹应该能够提交到存储库,并在 CI 管道期间可用。但正如你所看到的,拔出的文件夹中每个包的文件仍然是灰色的,无法提交。

即使在检查了所有文件之后,输出git status --ignore仍然列出了目录:unplugged.gitignore

.yarn/.DS_Store
.yarn/build-state.yml
.yarn/cache/.gitignore
.yarn/install-state.gz
.yarn/unplugged/
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能将文件放入存储库或避免开头提到的错误?

纱线文件夹

tor*_*rek 5

根据评论,事实证明另一个忽略规则覆盖了所需的非忽略规则。关键的诊断是使用:

git check-ignore -v .yarn/unplugged/somedir/node_modules/somefile
Run Code Online (Sandbox Code Playgroud)

(或类似),它指向**/node_modules/导致somefilenode_modules/范围内.yarn/unplugged/被跳过的行。

这里更普遍的结论是,如果git add .跳过某些文件,您可以使用“经常使用”git check-ignore -v来找出原因。请注意,在特定的跳过文件上使用它很重要。(它对于子模块也没有多大作用,但这完全是另一个问题。)