Ed Stephenson
Ed Stephenson

Reputation: 774

How to configure npm package to auto-update

I have made this package: https://www.npmjs.com/package/nestjs-notifications

When I run npm install nestjs-notifications --save it will install ok and add to the registry, but will save it as:

"nestjs-notifications": "0.0.10"

How do I configure it to so it will install with semantic version as:

"nestjs-notifications": "^0.0.10".

Currently I can't pick up the new version automatically, I have to manually change the version in package.json.


Edit: My pertinent config settings are as follows (essentially they're default). So it should be saving with a caret:

save = true
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-prefix = "^"
save-prod = false
...

Upvotes: 2

Views: 686

Answers (1)

RobC
RobC

Reputation: 24982

What you're encountering is expected behavior. Installing any pkg with a 0.0.x semver doesn't get the default caret (^) prefix in package.json, nor will your package be updated.

In the npm docs for caret ranges it states:

"Allows changes that do not modify the left-most non-zero digit in the [major, minor, patch] tuple. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X."

Note The bold emphasis in the excerpt (above) was added by me.

Essentially once you've bumped your package's semver to >=0.1.0 only then will you begin to get the desired behavior.


Demonstration showing when the caret (^) IS and IS NOT added to package.json:

  1. Install a version of a package that is <0.1.0. For demo purposes we'll install eslint version 0.0.7 by running the following command:

    npm i [email protected] --save
    

    The preceding command adds the following to package.json:

    "eslint": "0.0.7"
    

    Note The caret (^) was not included.

  2. Now uninstall eslint by running the following command:

    npm un eslint --save
    
  3. Next install the first version available of eslint that is >=0.1.0, i.e run the following:

    run npm i [email protected] --save
    

    This time the preceding command adds the following to package.json::

    "eslint": "^0.1.0"
    

    Note The caret (^) has been included.

Upvotes: 2

Related Questions