Npm install ignores tilde (~) in version number

后端 未结 1 1198
野性不改
野性不改 2020-12-21 17:05

I would like to install 1.8.x version a package, and be able to later automatically update this dependency inside the >=1.8.0 <1.9.0 range.

I tried to run this co

1条回答
  •  礼貌的吻别
    2020-12-21 18:03

    The semver prefix is defined by the save-prefix config. The default value is a caret (^) which you can check by running the following npm config command:

    npm config get save-prefix
    

    Unfortunately, the npm install command has no option to specify this, so what you'll need to do is:

    1. Set the save-prefix value to a tilde (~) by running:

      npm config set save-prefix="~"
      
    2. Install your package by running:

      npm i example-package@1.8.0 --save
      

      Note: The tilde (~) must not be included in the install command.

    3. Finally, set the save-prefix value back to it's default, i.e. a caret (^) by running:

      npm config delete save-prefix
      

      Note: You wouldn't do this last step if you wanted all future npm install's to use the tilde (~) prefix instead of a caret (^).

    The above steps will add the following record in package.json:

    "example-package" : "~1.8.0"
    

    Note the tilde ~ instead of the default caret ^


    You can utilize the && operator to combine the aforementioned commands into a compound command. For instance:

    npm config set save-prefix="~" && npm i example-package@1.8.0 --save && npm config delete save-prefix
    

    0 讨论(0)
提交回复
热议问题