getting version during preversion step

814 Views Asked by At

I am using a package called babel-plugin-inline-package-json to pull out my version number during my build step. Currently using semantic-release the package version is always 0.0.0 instead of the correct version number. I setup semantic-release to trigger a build using the npm preversion command. I was under the impression that by the time semantic-release triggered preversion it would already have the new version inserted into the package.json, but I keep getting 0.0.0 instead. What would be the correct way to pull out the version number so I can get it during my build step?

1

There are 1 best solutions below

0
On BEST ANSWER

semantic-release doesn't trigger the npm preversion directly, it runs npm version then npm publish. The npm hook scripts (preversion, postversion, prepack, postpack, prepublish, prepublishOnly, postpublish, prepare) are triggered by npm itself.

As suggested by it's name the hook preversion run just before the version is updated. You need to use the postversion hook which run after the version is updated.

For more details see: How can I use a npm build script that requires the package.json’s version ?