Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRoot lifecycle being skipped with missing root project manifest name #2064
Comments
|
Yikes, sorry about that. I'm cool with throwing an error if the project manifest (package.json that is a sibling of lerna.json, usually in the repo root) doesn't have a |
|
Can I help with this? |
|
@sturdynut Sure! |
|
Apologies for the delay, I've been a bit behind on my open source work. I got this pulled down and was going to implement what you suggested @evocateur; to throw a ValidationError if the root package.json does not have a name or the name matches the name of one of the packages. Does that sound correct? |


I ran into a use-case and I'm not sure if this is a bug or feature. Either way maybe some documentation might alleviate the confusion. Was definitely a gotcha that kept me busy for a few hours tracking it down.
For reference: pixijs/pixi.js#5635
I think this might be a regression in behavior, but I'm not 100% positive about that. Maybe I just wasn't paying close enough attention🤷♂
Expected Behavior
When doing a
publishorversioncommand when there's a missingnamefield in the root-level package.json file and where.is not apackagesentry in the lerna.json file, then lifecycle hooks (e.g.postversion,prepublishOnly, etc) should get invoked at the root-level.Current Behavior
Because the default name of the project folder can match the name of a package being published, then Lerna assumes that
hasRootedLeafis true and lifecycle methods are skipped.Possible Solution
The workaround that I found was to give the root package.json a unique name not shared by any packages.
One solution would be to explicitly require and break on a missing
namefield in the root-level package.json.Another idea: I'm not sure that using npm's default behavior in setting basename for the root
project.manifestis the best choice here. Maybe it would be more appropriate to assign it a unique name, to avoid the case that the folder name happens to overlap an internal package name. Fewer chances of conflicts and accidentally skipping lifecycle hooks.Steps to Reproduce (for bugs)
namefield from the root-levelpreversionscript at the root-level package.jsonlerna versionorlerna publishpreversionis never calledContext
Recently published a new major version of PixiJS and lifecycle method that was assumed to be hit, was never. This created a slightly botched published which we hope to correct ASAP.
Your Environment
lerna --versionnpm --versionnode --version