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?
Asked
Active
Viewed 676 times
0

Mike F
- 309
- 1
- 8
- 18
-
for what it's worth, you can find something describing your situation there: https://github.com/semantic-release/semantic-release/blob/caribou/docs/support/FAQ.md#how-can-i-use-a-npm-build-script-that-requires-the-packagejsons-version-. I however am looking at how to implement that in my flow, and it's hard to find examples I find. – Moustachiste Nov 21 '18 at 16:18
1 Answers
0
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 ?

Pierre Vanduynslager
- 811
- 7
- 7