Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install the latest possible version of an npm package

Tags:

How do I install the latest available version of an npm package? '@latest' sure doesn't fetch the latest - I assume it means the latest stable or something.

I've been using a hack for a while because I cannot seem to find any info on this:

npm i extract-text-webpack-plugin@X 

The 'X' causes it to fail and dump all possible versions where I then copy and paste the correct one instead of the 'X'. Kinda ridiculous.

I've tried 3rd party packages like 'latest-version' but they all fail to get the very latest version.

There doesn't seem to be an official to do this. For example at the time of writing the latest version of extract-text-webpack-plugin is 2.0.0-beta.4. However doing:

npm i extract-text-webpack-plugin@latest

Will install '1.0.1'

I can see the latest version by doing

npm info pkg versions --json (without --json it will cut off when there are many versions)

For lack of an actual tool I guess its going to be some grep work.

like image 851
cyberwombat Avatar asked Sep 23 '16 00:09

cyberwombat


People also ask

Does npm install update package versions?

The npm install installs all modules that are listed on package. json file and their dependencies. npm update updates all packages in the node_modules directory and their dependencies.


1 Answers

Version 1.0.1 is the 'latest' version of that package - published to the npm registry at least (tagged as latest)

From the docs for cli/dist-tag. Emphasis mine.

Tags can be used to provide an alias instead of version numbers.

For example, a project might choose to have multiple streams of development and use a different tag for each stream, e.g., stable, beta, dev, canary.

By default, the latest tag is used by npm to identify the current version of a package, and npm install (without any @ or @ specifier) installs the latest tag. Typically, projects only use the latest tag for stable release versions, and use other tags for unstable versions such as prereleases.

By default, other than latest, no tag has any special significance to npm itself.

If you want the beta releases, then install from GitHub, or use the tags explicitly.

$ npm install webpack/extract-text-webpack-plugin

This is made pretty clear by reading the manual.

Even more clear:

latest is an implicit tag, attached to any published version of a package that was not published with an explicit tag (--tag).

Installing xyz@latest simply looks up the release tagged as latest in the registry. In the case of this package, that's release 1.0.1. That's it. There's nothing special going on here. @latest does not pull the most recent version published to npm

The versions listed as betas were tagged differently. Obviously none of them were tagged as latest, so trying to use @latest to get one is pointless.

From the registry:

'dist-tags': { latest: '1.0.1', beta: '2.0.0-beta.4' }

Again, use the GitHub releases for the bleeding edge, or use the versions/tags explicitly.

$ npm install extract-text-webpack-plugin@beta

Here you go, made especially for you:

  • recent-version
  • recent-version-cli

Condense this into a shell script, and you're good to go:

$ npm install extract-text-webpack-plugin@$(recent-version extract-text-webpack-plugin)
like image 70
Oka Avatar answered Oct 11 '22 14:10

Oka