Did you forget to tag all your npm releases in git? Yeah me too. This utility tags them retroactively.
Obviously, that's a subjective thing. So use this at your own risk.
npm install -g tag-old-releases
cd src/my-repo
tag-old-releases
To print git tag
commands without actually running them:
npm install -g tag-old-releases
cd src/my-repo
tag-old-releases --dry-run
Is your default or production branch not called master
? You can pass another branch name to use that as the reference:
tag-old-releases --branch=main
This can be used together with --dry-run
as well.
tag-old-releases
scans through git log
of the master
branch, checking out each commit as it goes backwards through time. The oldest release in which package.json
has a given version
is tagged as the release for this version, unless a tag already exists. Tags are named simply x.y.z
(version number).
The rationale is that your release process looks like this:
- People contribute changes, which get merged over various commits, all of which have the old version number
- You decide what the new version number will be when you are actually ready to release, which makes sense for semantic versioning reasons; in that commit you edit your changelog and package.json
- That stuff gets merged back to
master
- You
npm publish
If your process differs — for instance if well-meaning contributors bump the version number early and then other critical commits are made before npm publish
- then this script will make the wrong choice for those versions. Sorry - best we can do.
In future, we suggest a script like this in place of npm publish
:
#!/usr/bin/env node
var exec = require('child_process').execSync;
var version = require(process.cwd() + '/package.json').version;
exec('git tag ' + version + ' && git push --tags && npm publish');
This will keep you out of trouble by tagging releases at the time you publish.
- Adds a
--branch
option to use a reference branch other thanmaster
.
- Commented and refactored a bit. Thanks to Daniel Lando.
- Initial fix to an ordering issue. Thanks to Daniel Lando.
- Initial releases.