gpt4 book ai didi

javascript - 在 "npm i"之后的几个地方更新package.json

转载 作者:行者123 更新时间:2023-12-02 22:56:54 25 4
gpt4 key购买 nike

我希望能够根据我的 package.json 文件检测安装的任何新包,因此每当我执行“npm i”时,它都会自动添加到我的 package.json 文件的另一个部分。

例如,如果我执行“npm i axios”,它将在我的 package.json 文件上的 2 个位置更新:像往常一样,在“依赖项”上,以及我创建的新部分:“extDependency”。

有什么方法可以检测任何新安装的软件包吗?

最佳答案

看看这个:npm-scripts documentation

If you want to run a specific script at a specific lifecycle event for ALL packages, then you can use a hook script.

Place an executable file at node_modules/.hooks/{eventname}, and it’ll get run for all packages when they are going through that point in the package lifecycle for any packages installed in that root.

Hook scripts are run exactly the same way as package.json scripts. That is, they are in a separate child process, with the env described above.

您可以使用它创建一个 postinstall 脚本(bash、python、node.js 等)来读取 npm_package_namenpm_package_version环境变量,然后使用它们来更新 package.json。

关于javascript - 在 "npm i"之后的几个地方更新package.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57943382/

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