gpt4 book ai didi

node.js - npm如何处理锁文件

转载 作者:搜寻专家 更新时间:2023-10-31 23:59:08 29 4
gpt4 key购买 nike

因此,我在脚本中运行 npm install xyz,该脚本由另一个 npm 模块的安装后 npm Hook 调用。 (我们不要讨论为什么,但它与 npm 不支持的可选依赖项有关)

npm install moduleA
-> installing moduleA
-> running postinstall hook (my script)
-> my script runs npm install xyz

当我运行脚本本身时,npm install 运行得相当快,但是当我在 postinstall Hook 中安装模块时,脚本等待锁定文件至少 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

在这里至少等一分钟

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]

现在看correctMkdir的代码似乎只是将 /Users/path/.npm/_locks 中的所有文件加载到内存中并尝试修复权限?不确定。

correctMkdirlock 调用.这似乎对文件进行了散列和一些加密?也不确定。

在对一些 npm 代码进行逆向工程后,我通过将 cache-lock-stalecache-lock-wait 的配置更改为 10ms 取得了进展。不幸的是,在正确安装所有内容之前它仍然挂起太久。我怀疑在之前更改并且 npm 正在运行时没有考虑更改的配置?或许?也许这是完全不同的东西? :)

谁能给我提示正确的方向?我可以做些什么来加快速度吗?

最佳答案

经过一夜的 sleep ,现在安装速度似乎快多了。我猜某些缓存仍然卡在我的 _locks 文件夹中。

所以答案是:

暂时将 cache-lock-stalecache-lock-wait 设置为 10ms 并且 npm 不会等待您的锁定文件直到到期为止。据我了解,npm 正在尝试等待 _lock 文件夹中的所有锁定文件完成,并且因为我们在 npm install 中运行 npm install,父进程中的锁定文件显然仍在使用中。这更像是一个猜测,但我希望它能帮助将来的人。

关于node.js - npm如何处理锁文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43108745/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com