Lerna publish adds gitHead key to package.jsons
Asked Answered
N

1

7

I've got the following scripts in my root package.json in my lerna repo:

"scripts": {
    "lerna:changed": "npx lerna changed",
    "lerna:diff": "npx lerna diff",
    "lerna:publish": "npx lerna publish"
  }

After running npm run lerna:publish I see a gitHead key in my package.json file of all packages (not the root.json). This becomes a big problem when it comes to versioning because all packages will get bumped when this change is added. Why is this happening and how can I stop it?

I used to have a publish command in my root package.json file and I know this could have caused this problem originally but I've since removed it. Now, the package.json files for my sub packages look basically like this:

{
  "name": "@myProject/appOne",
  "version": "0.0.15-alpha.0",
  "description": "",
  "main": "index.js",
  "directories": {
    "lib": "lib"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"

}

Nightly answered 18/9, 2019 at 1:16 Comment(1)
You should add your findings as an "answer" below; you're allowed to answer your own questions on Stack Overflow — this could also get you some points. And allow the rest of us to vote you up. ;)Prevaricator
N
4

UPDATE: It seems like gitHead is added as a temporary key during the publish phase. My publish creates tags and commits them to GIT but my deployment to my registry is failing and that's probably why the cleanup isn't happening.

Nightly answered 3/2, 2021 at 13:18 Comment(2)
Yeah, I have noticed the same behavior. If the publish to the registry fails, for whatever reason, these gitHead keys are stuck in package.json like forever.Brandibrandice
In my case it looks like a different issue - publish fails with 'uncommitted changes' error and pointing to all packages package.json. This is only happy on CI not in local. I am able to publish to same registry from local code without any issues and with same commands however the same is failing from azure devops ciRauwolfia

© 2022 - 2024 — McMap. All rights reserved.