V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hiw2016
V2EX  ›  前端开发

请教大家一个 npm update 的基础问题

  •  
  •   hiw2016 · 68 天前 · 523 次点击
    这是一个创建于 68 天前的主题,其中的信息可能已经有所发展或是发生改变。

    关于 npm update 是否会递归更新的说明

    官网 v6 的说明 https://docs.npmjs.com/cli/v6/commands/npm-update#description As of [email protected].1, the npm update will only inspect top-level packages. Prior versions of npm would also recursively inspect all dependencies. To get the old behavior, use npm --depth 9999 update.

    官网 v7 的说明 https://docs.npmjs.com/cli/v7/commands/npm-update This command will update all the packages listed to the latest version (specified by the tag config), respecting the semver constraints of both your package and its dependencies (if they also require the same package).

    我理解的结论 意味着 npm 的版本在执行 npm update 时

    <2.6.1:默认会递归更新
    2.6.1-6:默认不会递归,可以使用 depth 指定深度
    >=7:默认会
    

    关于 npm update 是否会影响 package.json 的说明

    官网 v6 的说明 https://docs.npmjs.com/cli/v6/commands/npm-update#description As of [email protected].0, the npm update will change package.json to save the new version as the minimum required dependency. To get the old behavior, use npm update --no-save.

    官网 v8 的说明 https://docs.npmjs.com/cli/v8/commands/npm-update Note that by default npm update will not update the semver values of direct dependencies in your project package.json, if you want to also update values in package.json you can run: npm update --save (or add the save=true option to a configuration file to make that the default behavior).

    我理解的结论 意味着 npm 的版本在执行 npm update 时

    <5:默认不会更新 package.json
    5-7:默认会
    >=8:默认不会
    
    • 请教一下大家,我这这样理解正确么?
    • 但是我做实验,和我的理解不一样,搞不懂为什么了?

    关于第一点

    我使用 volta install node@8 ,默认匹配的 npm 版本是 6.13.4 ,按照我的理解 npm update 不应该更新包所依赖的包,但是我观察了 pacakge-json.lock ,它更新了,不太理解为什么。

    关于第二点

    同样使用 6.13.4 的 npm ,不会更新 package.json ,也不太理解为什么。

    所以请教一下各位大佬,是不是我看文档的理解有问题?提前感谢大家了,谢谢🙏

    1 条回复    2024-07-02 08:55:23 +08:00
    netnr
        1
    netnr  
       67 天前 via Android
    一直在用 ncu -i
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1842 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 00:41 · PVG 08:41 · LAX 17:41 · JFK 20:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.