Node.js npm如何处理锁文件
因此,我在另一个npm模块的postinstall npm钩子调用的脚本中运行Node.js npm如何处理锁文件,node.js,npm,npm-install,post-install,Node.js,Npm,Npm Install,Post Install,因此,我在另一个npm模块的postinstall npm钩子调用的脚本中运行npm install xyz。(我们不必讨论为什么请,但它与npm不支持的可选依赖项有关) 当我运行脚本本身时,npm安装运行得相当快,但当我在postinstall挂钩中安装模块时,脚本会在锁定文件上等待至少1分钟(或者我假设是这样) 当我在npm中启用详细日志级别时,我得到如下输出: [a lot more lines above] npm verb addNamed "latest" is being trea
npm install xyz
。(我们不必讨论为什么请,但它与npm不支持的可选依赖项有关)
当我运行脚本本身时,npm安装运行得相当快,但当我在postinstall挂钩中安装模块时,脚本会在锁定文件上等待至少1分钟(或者我假设是这样)
当我在npm中启用详细日志级别时,我得到如下输出:
[a lot more lines above]
npm verb addNamed "latest" is being treated as a dist-tag for invert-kv
npm info addNameTag [ 'invert-kv', 'latest' ]
npm verb addNameTag registry:https://registry.npmjs.org/invert-kv already in flight; waiting
npm verb addNamed "1.0.0" is a plain semver version for invert-kv
npm verb afterAdd /Users/path/.npm/invert-kv/1.0.0/package/package.json not in flight; writing
npm verb correctMkdir /Users/path/.npm correctMkdir not in flight; initializing
npm verb afterAdd /Users/path/.npm/invert-kv/1.0.0/package/package.json written
npm verb cache add spec camelcase@^3.0.0
npm verb addNamed ">=3.0.0 <4.0.0" is a valid semver range for camelcase
npm verb addNameRange registry:https://registry.npmjs.org/camelcase not in flight; fetching
npm verb get https://registry.npmjs.org/camelcase not expired, no request
npm verb addNamed "3.0.0" is a plain semver version for camelcase
npm verb afterAdd /Users/path/.npm/camelcase/3.0.0/package/package.json not in flight; writing
npm verb correctMkdir /Users/path/.npm correctMkdir not in flight; initializing
npm verb afterAdd /Users/path/.npm/camelcase/3.0.0/package/package.json written
npm verb correctMkdir /Users/path/.npm/_locks correctMkdir not in flight; initializing
现在看一下的代码,似乎只是将/Users/path/.npm/_中的所有文件加载到内存中,并尝试修复权限?不确定
correctMkdir
由调用。这似乎是散列文件和一些加密?也不确定
在对一些npm代码进行反向工程后,我通过将缓存锁过期
,缓存锁等待
的配置更改为10ms,取得了进展。不幸的是,在正确安装之前,它仍然挂起太久。我怀疑在更改之前和npm正在飞行时没有考虑更改的配置?大概也许是完全不同的事情?:)
谁能告诉我正确的方向?我能做些什么来加快速度吗?经过一夜的睡眠,现在的安装速度似乎快多了。我猜一些缓存仍然挂在我的_locks文件夹中
所以答案是:
将cache lock stale
和cache lock wait
分别临时设置为10ms
,npm不会等待您的锁文件过期。据我所知,npm正在尝试等待_lock文件夹中的所有锁文件完成,因为我们在npm安装中运行npm install,父进程中的锁文件显然仍在使用中。这更多的是猜测,但我希望它能对将来的人有所帮助。Hello@Dominik您能为要设置的给定配置共享npm命令吗?@PranavBhagwat check和答案中提到的类似内容…:)
[a lot more lines above]
npm verb addNamed "latest" is being treated as a dist-tag for invert-kv
npm info addNameTag [ 'invert-kv', 'latest' ]
npm verb addNameTag registry:https://registry.npmjs.org/invert-kv already in flight; waiting
npm verb addNamed "1.0.0" is a plain semver version for invert-kv
npm verb afterAdd /Users/path/.npm/invert-kv/1.0.0/package/package.json not in flight; writing
npm verb correctMkdir /Users/path/.npm correctMkdir not in flight; initializing
npm verb afterAdd /Users/path/.npm/invert-kv/1.0.0/package/package.json written
npm verb cache add spec camelcase@^3.0.0
npm verb addNamed ">=3.0.0 <4.0.0" is a valid semver range for camelcase
npm verb addNameRange registry:https://registry.npmjs.org/camelcase not in flight; fetching
npm verb get https://registry.npmjs.org/camelcase not expired, no request
npm verb addNamed "3.0.0" is a plain semver version for camelcase
npm verb afterAdd /Users/path/.npm/camelcase/3.0.0/package/package.json not in flight; writing
npm verb correctMkdir /Users/path/.npm correctMkdir not in flight; initializing
npm verb afterAdd /Users/path/.npm/camelcase/3.0.0/package/package.json written
npm verb correctMkdir /Users/path/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /Users/path/.npm/_locks/staging-d21af557b41d4821.lock for /Users/path/Desktop/t/node_modules/.staging
npm verb unbuild node_modules/.staging/abbrev-ac014442
npm verb unbuild node_modules/.staging/ansi-regex-12e09986
npm verb unbuild node_modules/.staging/ansi-styles-1359ba2f
npm verb unbuild node_modules/.staging/aproba-d9971840
npm verb unbuild node_modules/.staging/array-find-index-c1ddfc4c
[a lot more lines below]