Forcing npm install failures on mismatched peerDependencies

只愿长相守 提交于 2021-02-17 02:50:08

问题


Does anyone have a technique for getting npm install to completely fail when peerDependency version mismatches are present? We frequently hit issues where peerDependency warnings go unheeded by developers, and semver mismatches cause breakage when insufficient testing is present. It would be nice if our CICD processes could bomb out due to error exit codes when attempting an install with unresolved version conflicts.


回答1:


You can't (as far as I'm aware) do this during npm install, but you can call npm ls afterwards - if there are "extraneous, missing, and invalid packages", including missing peer dependencies, it will exit non-zero. Using the flag --depth 0 limits the output to only things you directly depend on, e.g.:

$ npm ls --depth 0
cyf-eslint@1.0.0 path/to/dir
├── @codeyourfuture/eslint-config-standard@2.0.1
└── UNMET PEER DEPENDENCY eslint@7.5.0

npm ERR! peer dep missing: eslint@^6.0.0, required by @codeyourfuture/eslint-config-standard@2.0.1

$ echo $?
1


来源:https://stackoverflow.com/questions/63177381/forcing-npm-install-failures-on-mismatched-peerdependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!