Workaround for snapshot versions in Npm

Viewed 2724

After searching on the net for solutions to simulate the behaviour of Maven snapshot versions in Npm, I have made some test and found a workaround that works to me.

I would like you to give me some feedback if you please, and let me know if you know of any other possible workarounds or if there is something I'm missing on this one.

The only downside I see is that the actual version of the installed dependency has to be checked in the node_modules folder, because I'm using npm update --no-save to avoid replacing my range expression in package.json after installs or updates.

You can find the code and doc in my github.

Workaround for snapshots in Npm

Publish and use snapshot versions

Libraries:

  1. (only in first project setup) Set version in package.json to:
    "version": "0.0.0-snapshot.0"
    
  2. Use these command to publish snapshots and tag as snapshot:
    "scripts": {
        "publish:snapshot": "npm run version:snapshot && npm publish --tag snapshot",
        "version:snapshot": "npm version prerelease --preid snapshot"
    }
    
  3. Check that snapshot number is incremented in package.json

Application:

  1. (only in first project setup) Delete package-lock.json and npm install
  2. Set dependency to snapshot version in development:
    "dependencies": {
        "npm-test-lib-a": ">=0.0.0-snapshot.0"
    }
    
  3. To get the latest snapshot version use this command:
    npm update <package> --no-save
    
  4. To see version actually installed see node_modules

Publish and use release versions

Libraries:

  1. Use these commands to publish releases and tag as latest:
    "scripts": {
        "publish:release": "npm run version:release && npm publish",
        "version:release": "npm version 1.0.0"
    }
    
  2. Always set version back to snapshot after publishing a release

Application:

  1. To get the latest release version use npm install:
    npm install <package>
    
  2. To see version actually installed see node_modules

Many thanks!

1 Answers
Related