npm in depth All In One
npm in depth All In One
corepack
Zero-runtime-dependency package acting as bridge
between Node projects
and their package managers
零运行时依赖包充当 Node 项目
与其包管理器
之间的桥梁
https://github.com/nodejs/corepack
https://nodejs.org/api/corepack.html
$ brew ls | grep "node"
node
node@16
$ node -v
v16.14.2
$ which node
/Users/xgqfrms-mbp/.nvm/versions/node/v16.14.2/bin/node
$ nvm ls
-> v16.14.2
system
default -> 16.14.2 (-> v16.14.2)
node -> stable (-> v16.14.2) (default)
stable -> 16.14 (-> v16.14.2) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/hydrogen (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.1 (-> N/A)
lts/gallium -> v16.18.1 (-> N/A)
lts/hydrogen -> v18.12.1 (-> N/A)
$ which brew
$ cd /usr/local/bin
$ ls
$ ls | grep 'node'
node
$ ls -al | grep 'node'
$ ls -al | grep 'node'
lrwxr-xr-x 1 xgqfrms-mbp admin 68 Sep 8 16:08 ane -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/ane
lrwxr-xr-x 1 root admin 32 Jan 2 2019 app -> ../lib/node_modules/admin/app.sh
lrwxr-xr-x 1 root admin 44 Mar 1 2019 browser-sync -> ../lib/node_modules/browser-sync/dist/bin.js
lrwxr-xr-x 1 root wheel 45 Apr 19 2022 corepack -> ../lib/node_modules/corepack/dist/corepack.js
lrwxr-xr-x 1 xgqfrms-mbp admin 75 Sep 8 16:08 create-egg -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/create-egg
lrwxr-xr-x 1 xgqfrms-mbp admin 80 Sep 8 16:08 create-next-app -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/create-next-app
lrwxr-xr-x 1 xgqfrms-mbp admin 80 Sep 8 16:08 create-nuxt-app -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/create-nuxt-app
lrwxr-xr-x 1 xgqfrms-mbp admin 81 Sep 8 16:08 create-react-app -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/create-react-app
lrwxr-xr-x 1 xgqfrms-mbp admin 76 Sep 8 16:08 create-vite -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/create-vite
lrwxr-xr-x 1 xgqfrms-mbp admin 68 Sep 8 16:08 cva -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/cva
lrwxr-xr-x 1 root admin 32 Jan 2 2019 dev -> ../lib/node_modules/admin/dev.sh
lrwxr-xr-x 1 root admin 43 Apr 16 2019 gatsby -> ../lib/node_modules/gatsby-cli/lib/index.js
lrwxr-xr-x 1 xgqfrms-mbp admin 69 Sep 8 16:08 jest -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/jest
lrwxr-xr-x 1 root admin 38 Apr 3 2019 light -> ../lib/node_modules/lighting/bin/light
lrwxr-xr-x 1 root admin 40 Apr 3 2019 light4g -> ../lib/node_modules/lighting/bin/light4g
lrwxr-xr-x 1 xgqfrms-mbp admin 69 Sep 8 16:08 nest -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/nest
lrwxr-xr-x 1 xgqfrms-mbp admin 67 Sep 8 16:08 ng -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/ng
-rwxr-xr-x 1 root wheel 156596368 Mar 18 2022 node
lrwxr-xr-x 1 root admin 38 Apr 19 2022 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxr-xr-x 1 root admin 38 Apr 19 2022 npx -> ../lib/node_modules/npm/bin/npx-cli.js
lrwxr-xr-x 1 xgqfrms-mbp admin 68 Sep 8 16:08 pm2 -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/pm2
lrwxr-xr-x 1 xgqfrms-mbp admin 72 Sep 8 16:08 pm2-dev -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/pm2-dev
lrwxr-xr-x 1 xgqfrms-mbp admin 75 Sep 8 16:08 pm2-docker -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/pm2-docker
lrwxr-xr-x 1 xgqfrms-mbp admin 76 Sep 8 16:08 pm2-runtime -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/pm2-runtime
lrwxr-xr-x 1 xgqfrms-mbp admin 68 Sep 8 16:08 spe -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/spe
lrwxr-xr-x 1 xgqfrms-mbp admin 69 Sep 8 16:08 taro -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/taro
lrwxr-xr-x 1 xgqfrms-mbp admin 68 Sep 8 16:08 tsc -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/tsc
lrwxr-xr-x 1 xgqfrms-mbp admin 73 Sep 8 16:08 tsserver -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/tsserver
lrwxr-xr-x 1 xgqfrms-mbp admin 68 Sep 8 16:08 vue -> ../../../Users/xgqfrms-mbp/.config/yarn/global/node_modules/.bin/vue
npm 包管理工具的演进
npm( Node.js 直接内置, corepack 内置)、yarn (corepack 内置) 以及 pnpm (corepack 内置)
其实关于 npm、yarn 以及 pnpm 的迭代演进远远不只是做了上面提到的工作,比如:
npm 在 v5.x 版本中增加了 npx
命令,
yarn v2 紧跟其后的 yarn dlx
命令,pnp
模式
pnpm v6.x 也新增了 pnpm dlx
命令 以及在 v7 版本又增加了 pnpx
pnpm 在 v5.x 版本中也支持了 pnp
模式
yarn 在 v3.1 版本中支持了 pnpm 模式的 nodeLinker
yarn 在 v3.1 版本中支持了 optionalDependencies 依赖分
https://mp.weixin.qq.com/s/beP1bxgbTT1Z91KS3svDvw
refs
https://github.com/nodejs/node-v0.x-archive/issues/6960
https://developer.mozilla.org/zh-CN/docs/Web/Security/Subresource_Integrity
https://github.com/babel/babel/discussions/12622
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16898025.html
未经授权禁止转载,违者必究!