【问题标题】:npm: how to find the latest compatible version of a dependency for a node module at a specific version?npm:如何找到特定版本的节点模块的最新兼容版本?
【发布时间】:2020-08-10 08:11:01
【问题描述】:

有没有办法确定特定模块的最新版本与特定版本的另一个模块兼容?

例如,运行npm install @angular/http 会拉取依赖于rxjs@^6.0.0@angular/http@7.2.16,但是项目中已经存在rxjs 的较低版本——rxjs@5.5.11,并且碰撞这个版本需要更新很多其他模块,我想避免。

是否有命令可以显示与rxjs@5.5.11兼容的@angular/http的最新版本是x.y.z

有像npmvet这样的工具擅长显示当前项目中不匹配的版本,但找不到任何工具可以显示哪些版本可用于解决兼容性冲突。

【问题讨论】:

    标签: node.js npm version dependency-management


    【解决方案1】:

    它看起来并不存在工具,但在这一行命令中使用 npmvetnpm view 有助于我完成这项任务:

    npmvet -r json | jq '.[] | .name + "@" + .packageVersion' | sed -e 's/"//g' | awk '{print "echo "$0"; npm view "$0" dependencies"}'|sh | tee ../deps.txt
    

    输出如下:

    prismjs@1.23.0 !
    prop-types@15.7.2
    {
      'loose-envify': '^1.4.0',
      'object-assign': '^4.1.1',
      'react-is': '^16.8.1'
    }
    pug@3.0.1 !
    pug-code-gen@2.0.3 !
    raphael@2.2.8
    { 'eve-raphael': '0.5.0' }
    rc-time-picker@3.4.0
    {
      'babel-runtime': '6.x',
      classnames: '2.x',
      moment: '2.x',
      'prop-types': '^15.5.8',
      'rc-trigger': '^2.2.0'
    }
    react-collapsible@2.6.2
    

    如果您像我一样,并且已经拥有一个预先存在的 package.json,其中包含许多已允许/需要随着时间而发散的包/库,您可以使用此输出来帮助取消选择最佳匹配版本,直到npmvet 希望是绿色的。

    例如,我从 npmvet 开始:

    搜索我的deps.txt,我发现:

    prettier-eslint@11.0.0
    {
      '@typescript-eslint/parser': '^3.0.0',
      'common-tags': '^1.4.0',
      dlv: '^1.1.0',
      eslint: '^6.8.0',
      'indent-string': '^4.0.0',
      'lodash.merge': '^4.6.0',
      'loglevel-colored-level-prefix': '^1.0.0',
      prettier: '^2.0.0',
      'pretty-format': '^23.0.1',
      'require-relative': '^0.8.7',
      typescript: '^3.9.3',
      'vue-eslint-parser': '~7.1.0'
    }
    

    我在typescript@3.7.5,但prettier-eslint@11.0.0 想要typescript@3.9.3

    然后我运行npm i typescript@3.9.3 来满足依赖关系,npmvet 现在匹配该包:

    【讨论】:

      猜你喜欢
      • 2019-01-04
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 2017-04-01
      • 2018-07-07
      • 2016-06-17
      • 2021-09-30
      相关资源
      最近更新 更多