12

I am deploying a private npm module for internal use at our company. Since the module is handled internally, we can trust version bumps etc.

How can I install the module in various projects so that the latest version of the module will always be installed with every single npm install, so that I don't have to go through a bunch of projects and update the version inside each package.json every time we deploy?

Please note that this should only be for selected packages, not all packages - i.e. only those hosted on our private server.

Steve Land
  • 4,852
  • 2
  • 17
  • 36
john maccarthy
  • 5,463
  • 3
  • 11
  • 14
  • 2
    Hi @Steveland83. I don't think it's a duplicate. I don't want to manually update each dep, I simply want to automatically install the latest release of that dep on each `npm install`. – john maccarthy Jan 18 '18 at 13:14
  • Setting the version to "*" works for me, when I want to use the latest for private repos. For example: ```"async": "*"```. --EDIT-- made a formal answer below... – binarymax Jan 18 '18 at 13:56

3 Answers3

8

Use "*" as your version in your package.json file. For example:

"dependencies": {
 "my-awesome-repo": "*"
}

Upon npm install this will automatically install the latest version for "my-awesome-repo" that is availabile on npm.

binarymax
  • 3,147
  • 3
  • 20
  • 16
  • 1
    Great, this is the solution I was looking for. Any idea how this behaves in the context of yarn.lock or npm lockfiles? – john maccarthy Jan 18 '18 at 14:10
  • I don't know - I haven't used yarn and never pay attention to npm lockfiles. – binarymax Jan 18 '18 at 14:29
  • 1
    @johnmaccarthy if you have a `yarn.lock` file that already contains the package, running `yarn` will *not* update the package to the latest. If you remove your `yarn.lock` file then it will update the package to the latest. – Benjamin May 03 '19 at 12:53
3

One way is to run this before each install.

npm i -g npm-check-updates
npm-check-updates -u
npm install

On npm < 3.11:

"dependencies": {
 "express": "~3.2.0",
 "mongodb": "~1.2.14",
 "underscore": "~1.4.4",
 "rjs": "~2.10.0",
 "jade": "~0.29.0",
 "async": "~0.2.7"
}
Hiplobbe
  • 138
  • 6
  • 1
    Cannot flag, but was answered in https://stackoverflow.com/questions/16073603/how-do-i-update-each-dependency-in-package-json-to-the-latest-version – Hiplobbe Jan 18 '18 at 12:51
  • But... this is not an appropriate answer at all. I _don't_ want to update all my deps, that would certainly break builds. I just want to update specific private modules in a separate @example namespace. – john maccarthy Jan 18 '18 at 13:12
  • My understanding is that this is sadly the only ways to do it, please let us know if anything better comes up. – Hiplobbe Jan 18 '18 at 13:17
  • Feel free to check the accepted answer for a solution. – john maccarthy Jan 18 '18 at 14:17
2

You could try using the following package, which allows version selection by dist tag rather than a semantic version (e.g. latest).

https://www.npmjs.com/package/package-json

Steve Land
  • 4,852
  • 2
  • 17
  • 36