本文翻译自:npm check and update package if needed

We need to integrate Karma test runner into TeamCity and for that I'd like to give sys-engineers small script (powershell or whatever) that would: 我们需要将Karma测试运行器集成到TeamCity中,为此我想给sys-engineer小脚本(powershell或其他):

  1. pick up desired version number from some config file (I guess I can put it as a comment right in the karma.conf.js ) 从一些配置文件中获取所需的版本号(我想我可以把它作为注释放在karma.conf.js

  2. check if the defined version of karma runner installed in npm's global repo 检查是否在npm的全局仓库中安装了定义版本的karma runner

  3. if it's not, or the installed version is older than desired: pick up and install right version 如果不是,或者安装的版本比预期版本旧:选择并安装正确的版本

  4. run it: karma start .\\Scripts-Tests\\karma.conf.js --reporters teamcity --single-run 运行它: karma start .\\Scripts-Tests\\karma.conf.js --reporters teamcity --single-run

So my real question is: "how can one check in a script, if desired version of package installed?". 所以我真正的问题是:“如果安装了所需的软件包版本,如何检查脚本?”。 Should you do the check, or it's safe to just call npm -g install everytime? 您是否应该进行检查,或者每次只能调用npm -g install是安全的?

I don't want to always check and install the latest available version, because other config values may become incompatible 我不想总是检查并安装最新的可用版本,因为其他配置值可能会变得不兼容


#1楼

参考:https://stackoom.com/question/17L1C/如果需要-npm检查并更新包


#2楼

When installing npm packages (both globally or locally) you can define a specific version by using the @version syntax to define a version to be installed. 安装npm软件包(全局或本地)时,可以使用@version语法定义特定版本以定义要安装的版本。

In other words, doing: npm install -g karma@0.9.2 will ensure that only 0.9.2 is installed and won't reinstall if it already exists. 换句话说,执行: npm install -g karma@0.9.2将确保仅安装0.9.2并且如果已经存在则不会重新安装。

As a word of a advice, I would suggest avoiding global npm installs wherever you can. 作为建议的一句话,我建议尽可能避免全局npm安装。 Many people don't realize that if a dependency defines a bin file, it gets installed to ./node_modules/.bin/. 许多人没有意识到如果依赖项定义了一个bin文件,它就会被安装到./node_modules/.bin/。 Often, its very easy to use that local version of an installed module that is defined in your package.json. 通常,它非常容易使用package.json中定义的已安装模块的本地版本。 In fact, npm scripts will add the ./node_modules/.bin onto your path. 实际上,npm脚本会将./node_modules/.bin添加到您的路径中。

As an example, here is a package.json that, when I run npm install && npm test will install the version of karma defined in my package.json, and use that version of karma (installed at node_modules/.bin/karma) when running the test script: 作为一个例子,这是一个package.json,当我运行npm install && npm test将安装我的package.json中定义的karma版本,并使用该版本的karma(安装在node_modules / .bin / karma)运行test脚本:

{"name": "myApp","main": "app.js","scripts": {"test": "karma test/*",},"dependencies": {...},"devDependencies": {"karma": "0.9.2"}
}

This gives you the benefit of your package.json defining the version of karma to use and not having to keep that config globally on your CI box. 这为您提供了package.json的好处,它定义了要使用的karma版本,而不必在CI框中全局保留该配置。


#3楼

To check if any module in a project is 'old' you should do: 要检查项目中的任何模块是否“旧”,您应该:

npm outdated

'outdated' will check every module defined in package.json and see if there is a newer version in the NPM registry. 'outdated'将检查package.json中定义的每个模块,并查看NPM注册表中是否有更新的版本。

Here is an example, showing that xml2js (that is in node_modules/ in the current directory) is outdated, because a newer version exists (0.2.7): 下面是一个示例,显示xml2js(位于当前目录中的node_modules /中)已过时,因为存在较新的版本(0.2.7):

xml2js@0.2.7 node_modules/xml2js current=0.2.6

If you want to check for outdated modules and install newer version then you can do: npm update (for all modules) or npm update xml2js (only checks/updates xml2js) 如果你想检查过时的模块并安装更新的版本,你可以这样做: npm update (适用于所有模块)或npm update xml2js (仅检查/更新xml2js)

Have a look at the NPM docs: 看看NPM文档:

  • https://docs.npmjs.com/cli/outdated https://docs.npmjs.com/cli/outdated
  • https://docs.npmjs.com/cli/update https://docs.npmjs.com/cli/update

#4楼

npm outdated will identify packages that should be updated, and npm update <package name> can be used to update each package. npm outdated将识别应更新的软件包, npm update <package name>可用于更新每个软件包。 But npm update <package name> will not update the versions in your package.json which is an issue. 但是npm update <package name>不会更新package.json中的版本,这是一个问题。

The best workflow is to: 最好的工作流程是:

  1. Identify out of date packages 确定过时的包裹
  2. Update the versions in your package.json 更新package.json中的版本
  3. Run npm update to install the latest versions of each package 运行npm update以安装每个软件包的最新版本

Check out npm-check-updates to help with this workflow. 查看npm-check-updates以帮助完成此工作流程。

  • Install npm-check-updates 安装npm-check-updates
  • Run npm-check-updates to list what packages are out of date (basically the same thing as running npm outdated ) 运行npm-check-updates列出哪些软件包已过期(与运行npm outdated基本相同)
  • Run npm-check-updates -u to update all the versions in your package.json (this is the magic sauce) 运行npm-check-updates -u来更新package.json中的所有版本(这是魔术酱)
  • Run npm update as usual to install the new versions of your packages based on the updated package.json 像往常一样运行npm update ,根据更新的package.json安装新版本的软件包

#5楼

There is also a "fresh" module called npm-check : 还有一个名为npm-check的“新鲜”模块:

npm-check NPM-检查

Check for outdated, incorrect, and unused dependencies. 检查过时,不正确和未使用的依赖项。

It also provides a convenient interactive way to update the dependencies. 它还提供了一种更新依赖关系的便捷交互方式。


#6楼

  • To update a single local package: 要更新单个本地包:

    1. First find out your outdated packages: 首先找出你过时的套餐:

      npm outdated

    2. Then update the package or packages that you want manually as: 然后手动更新您想要的软件包:

      npm update --save package_name

This way it is not necessary to update your local package.json file. 这样就没有必要更新本地的package.json文件。

Note that this will update your package to the latest version. 请注意,这会将您的包更新到最新版本。

  • If you write some version in your package.json file and do: 如果你在package.json文件中写了一些版本并执行:

    npm update package_name

    In this case you will get just the next stable version (wanted) regarding the version that you wrote in your package.json file. 在这种情况下,您将获得有关您在package.json文件中编写的版本的下一个稳定版本(通缉)。

And with npm list (package_name) you can find out the current version of your local packages. 使用npm list (package_name)您可以找到本地软件包的当前版本。

如果需要,npm检查并更新包相关推荐

  1. npm发包、更新包、删除包、回退版本号

    npm发包 1.镜像源必须为npm nrm use 镜像源 //切换镜像源 2.注册(到官网注册账号) 3.进入到你要发的包中,打开终端 4.登录 npm login 输入账号.密码. email 5 ...

  2. npm更新包(全局单个,项目单个,全局所有,项目生产环境,项目开发环境)

    npm-check检查npm依赖包是否有更新,错误以及不在使用的. 安装npm-check npm install -g npm-check npm全局更新包 npm-check -u -g npm更 ...

  3. npm和yarn 更新依赖包

    npm和yarn更新依赖包到最新版本 npm包的更新速度之快想必大家都了然于心,那么新版本发布后,怎样将依赖包更新到最新版本呢? 批量更新依赖包 ①npm更新方式 需要全局安装npm-check-up ...

  4. NPM:nodejs官方包管理工具的简介、安装、使用方法之详细攻略

    NPM:nodejs官方包管理工具的简介.安装.使用方法之详细攻略 目录 NPM之nodejs官方包管理工具的简介 NPM之nodejs官方包管理工具的安装 NPM之nodejs官方包管理工具的使用方 ...

  5. npm收录了哪些包_手把手教你制作一个小而美丽的 npm 包并发布

    第1步:npm账户 你需要一个 npm 账户,如果米有,注册地址是:npmjs.com/signup 第2步:登录 进入你自己电脑的终端(cmd)并输入: npm adduser 也可以使用以下命令: ...

  6. 以实例分析 IGP中更新源检测失败丢弃路由更新包

    遇到的BGP中更新源检测失败现象 在iBGP建立邻居关系时,往往会采用单播方式的环回口建立邻居,这样做是因为环回口有永不Down的特点.在这种情况下即使是在一个接口出现问题之后,仍然可以通过其他的可用 ...

  7. Android5更新包,Android 5.x OTA Update官方文档(四、OTA更新包解读)

    http://blog.csdn.net/huangyabin001/article/details/44873753 写在前面: 写在前面:若能直译,不会意译,意译不成,为了选择不误导他人也会漏译无 ...

  8. Android下的配置管理之道之对 OTA 更新包进行签名

    对要发布的版本进行签名 Android 操作系统映像在两个地方使用加密签名: 映像中的所有 .apk 文件都必须经过签名.Android 软件包管理器通过下列两种方式使用 .apk 签名: 更换应用时 ...

  9. npm中node更新_如何在Node中管理NPM和功能时保持理智

    npm中node更新 by Ted Gross 泰德·格罗斯(Ted Gross) 如何在Node中管理NPM和功能时保持理智 (How to keep your sanity while manag ...

最新文章

  1. 并发编程基础篇——第一章(并发相关基础概念理解)
  2. 第十六届智能车竞赛创意组比赛-筹划初稿
  3. 复数类完整实现 + 四则运算符重载
  4. C# 接口的作用浅谈举例(转)
  5. AseoZdpAseo.init(this, AseoZdpAseo.INSERT_TYPE);
  6. 基于stm32、0.96寸OLED实现的贪吃蛇小游戏(详细源码注释)
  7. 让您的Xcode键字如飞
  8. 15什么时候你最想打人
  9. 总结CSS3新特性(媒体查询篇)
  10. 通过qemu调试centos7内核
  11. 分布式文件系统_新一代分布式文件系统XGFS揭秘——元数据服务
  12. mysql5.7优化案例_MYSQL5.7函数索引优化案例【企业数据库实战优化项目】
  13. 日常投票评分:大多都是拉票
  14. atitit.session的原理以及设计 java php实现的异同
  15. python基础教程doc_python基础教程之Word Cloud (词云) - Python|python基础教程|python入门|python教程...
  16. PHICOMM路由器无线扩展的设置方法(吐槽一下)
  17. 【笔记】第2章 向量
  18. cad打开卡死_CAD点打开或者保存就卡死无响应的解决方法
  19. Tangent Convolutions 切面卷积(切线卷积)
  20. linux运维的名言,Linux之父十大名言 你曾听说过几句?

热门文章

  1. RxJava flatMap操作符用法详解
  2. 算法------------完全平方数(Java版本)
  3. android gradle.properties
  4. Android 多屏显示分析
  5. Android之自定义瀑布流式的标签列表
  6. Flutter开发之布局-3-center(17)
  7. (0034) iOS 开发之UIView动画(过渡效果)
  8. etcd 访问 锁_在系统中用etcd实现服务注册和发现
  9. uniapp - easycom模式(自动引入组件)
  10. webpack打包后自动弹出浏览器查看效果