如何自动更新所有Node.js模块? [英] How to update all Node.js modules automatically?

查看:410
本文介绍了如何自动更新所有Node.js模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Node.js环境的过程中,我遇到了Node.js模块的版本维护问题.我想确保所有内部Node.js模块都已更新.

During my work with the Node.js environment, I faced the issue of version maintenance of Node.js modules. I would like to be sure that all internal Node.js modules are updated.

许多现有手册仅关注如何更新Node.js模块,而不关注如何自动化这样的例程.

Many of existing manuals focus just on how to update Node.js modules, but not how to automate such routine.

问题:
如何将所有Node.js模块自动更新到最新版本?
理想情况下,应该是一些脚本,工作或任务.

The question:
How to update all Node.js modules automatically to the latest version?
Ideally, it should be some script, job, or task.

推荐答案

要手动更新所有Node.js模块:

  1. 具有 管理 权限的打开控制台
  2. 转到Node.js安装文件夹:cd C:\Program Files\nodejs
  3. 更新npm:npm i npm@latest
  4. 转到模块文件夹:cd C:\Program Files\nodejs\node_modules\npm
  5. 安装所有需要的模块:npm i %MODULE_NAME%@latest
  6. 安装更新管理器:npm i npm-check@latest -g
  7. 本地已安装模块的可用更新:npm-check -u
  8. 全局已安装模块的可用更新:npm-check -u -g
  9. 所有 local 个已安装模块的递归更新:npm update --depth 9999 --dev
  10. 所有全局已安装模块的递归更新:npm update --depth 9999 --dev -g
  11. 清除缓存:npm cache clear --force
  1. Open console with administrative permissions
  2. Go to Node.js installation folder: cd C:\Program Files\nodejs
  3. Update npm: npm i npm@latest
  4. Go to modules folder: cd C:\Program Files\nodejs\node_modules\npm
  5. Install all desired modules: npm i %MODULE_NAME%@latest
  6. Install update manager: npm i npm-check@latest -g
  7. Available updates for locally installed modules: npm-check -u
  8. Available updates for globally installed modules: npm-check -u -g
  9. Recursive update of all locally installed modules: npm update --depth 9999 --dev
  10. Recursive update of all globally installed modules: npm update --depth 9999 --dev -g
  11. Clear the cache: npm cache clear --force


要自动更新所有Node.js模块:

  1. 创建一个package.json:

{
    "_cmd-update-all-modules": "npm run update-all-modules",
    "scripts": {
        "create-global-node-modules-folder": "if not exist \"%appdata%\\npm\\node_modules\" mkdir %appdata%\\npm\\node_modules",
        "npm-i-g": "npm i npm@latest -g",
        "npm-check-i-g": "npm i npm-check@latest -g",
        "eslint-i-g": "npm i eslint@latest -g",
        "stylelint-i-g": "npm i stylelint@latest -g",
        "npm-check-u-l": "npm-check \"C:\\Program Files\\nodejs\\node_modules\\npm\" -y",
        "npm-check-u-g": "npm-check \"C:\\Program Files\\nodejs\\node_modules\\npm\" -y -g",
        "npm-deep-update-l": "npm update --depth 9999 --dev",
        "npm-deep-update-g": "npm update --depth 9999 --dev -g",
        "npm-cache-clear": "npm cache clear --force",
        "update-all-modules": "npm run create-global-node-modules-folder && npm run npm-i-g && npm run npm-check-i-g && npm run eslint-i-g && npm run stylelint-i-g && npm run npm-check-u-l && npm run npm-check-u-g && npm run npm-deep-update-l && npm run npm-deep-update-g && npm run npm-cache-clear"
    }
}

  1. scripts部分中指定要安装的所有所需模块
  2. 确保通过环境变量将带有Node.js的文件夹(例如 C:\ Program Files \ nodejs )添加到 PATH 中. em>
  3. 从步骤3开始使用Node.js将package.json复制到文件夹中
  4. 具有 管理 权限的打开控制台
  5. 在控制台中,从第3步转到包含package.json的文件夹
  6. 执行:npm run update-all-modules
  1. Specify all desired modules to be installed in the scripts section
  2. Assure that the folder with Node.js, e.g., C:\Program Files\nodejs, is added to the PATH through the Environment Variables
  3. Copy package.json to the folder with Node.js from step #3
  4. Open console with administrative permissions
  5. In the console, go to the folder with package.json from step #3
  6. Execute: npm run update-all-modules

这两种方法都允许您将所有Node.js模块更新为最新版本,无论它是在本地还是在全球安装的.

Both of these approaches allow you keeping all Node.js modules updated to the latest version, wherever it is installed locally or globally.

注意:

  1. 要运行此package.json,请调用npm run update-all-modules,它作为提示存储在_cmd-update-all-modules属性中.
  2. ESLint&的安装脚本中的Stylelint仅供参考.
  1. To run this package.json, call npm run update-all-modules, stored as a hint inside of the _cmd-update-all-modules property.
  2. An installation of ESLint & Stylelint in the script is for the reference only.

这篇关于如何自动更新所有Node.js模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆