在 "npm i" 之后的几个地方更新 package.json
Update package.json in several places after "npm i"
我希望能够根据我的 package.json 文件检测安装的任何新包,所以每当我这样做时 "npm i",它会自动添加到我的 package.json 的另一个部分] 文件.
例如,如果我执行 "npm i axios",它将在我的 package.json 文件中的 2 个位置进行更新:
像往常一样在 "dependencies" 上,在我创建的新部分上:"extDependencies".
有什么方法可以检测任何新安装的软件包吗?
看看这个: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_name
和 npm_package_version
环境变量,然后使用它们更新 package.json.
我希望能够根据我的 package.json 文件检测安装的任何新包,所以每当我这样做时 "npm i",它会自动添加到我的 package.json 的另一个部分] 文件.
例如,如果我执行 "npm i axios",它将在我的 package.json 文件中的 2 个位置进行更新:
像往常一样在 "dependencies" 上,在我创建的新部分上:"extDependencies".
有什么方法可以检测任何新安装的软件包吗?
看看这个: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_name
和 npm_package_version
环境变量,然后使用它们更新 package.json.