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:
- (only in first project setup) Set version in
package.jsonto:"version": "0.0.0-snapshot.0" - 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" } - Check that snapshot number is incremented in
package.json
Application:
- (only in first project setup) Delete
package-lock.jsonandnpm install - Set dependency to snapshot version in development:
"dependencies": { "npm-test-lib-a": ">=0.0.0-snapshot.0" } - To get the latest snapshot version use this command:
npm update <package> --no-save - To see version actually installed see
node_modules
Publish and use release versions
Libraries:
- 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" } - Always set version back to snapshot after publishing a release
Application:
- To get the latest release version use npm install:
npm install <package> - To see version actually installed see
node_modules
Many thanks!