lerna-update-wizard icon indicating copy to clipboard operation
lerna-update-wizard copied to clipboard

support hoisting

Open oliveti opened this issue 8 years ago • 6 comments

Hi,

Thank you a lot for this nice tool.

Do you think it would be possible to add the support of hoisted dependencies ?

Thank you.

oliveti avatar Mar 19 '18 14:03 oliveti

Hi @oliveti !

Sorry for the late reply. I was not watching the repo by some mistake. I'd be happy to add support for what you're asking.

Can you be a bit more specific about the issue, though? Are you talking about hoisted dependencies in context of Yarn Workspaces?

Anifacted avatar May 18 '18 09:05 Anifacted

I believe he meant just the standard lerna hoisting.

maritz avatar Jun 08 '18 11:06 maritz

@oliveti @maritz

I think this will be tricky to implement since the program would have to make a guess on whether or not a dependency is a hoisted dependency before choosing whether to install it. This guess would be a combination of looking for "hoist": true in lerna.jsonand looking for the dependency in the root directory node_modules/ folder.

I suppose one solution could be to simply write to the package.json's dependencies entry for the target package, without installing anything, and then execute lerna bootstrap in the root directory, and Lerna will take care of the installation, but this sounds a bit hacky and it a bit like it could easily break in some setups.

Would love to hear if you could think of a viable approach :)

For now, the user will simply have to manually run lerna bootstrap --hoist after the wizard completes, which should do the job, even if the script has wasted some time with the installs.

Anifacted avatar Sep 03 '18 16:09 Anifacted

but this sounds a bit hacky and it a bit like it could easily break in some setups.

I can understand the feeling, though I don't know exactly how such problems would look like. Do you have any specific examples in mind?

Maybe add a step of checking if hoist is true, if yes add a log message after doing the update to tell the user that they have to run lerna bootstrap to get the updated dependencies hoisted? Or ask for automatic bootstrapping and exit if answered with "n".

There is another small problem other than the time wasted on installing: It creates package-lock.json for each package, where a normal lerna bootstrap would only have those for the cases where it cannot hoist all dependencies for a package.

maritz avatar Sep 04 '18 14:09 maritz

add a log message after doing the update to tell the user that they have to run lerna bootstrap to get the updated dependencies hoisted?

I could definitely add a prompt after installation offering the user to auto-run lerna bootstrap when hoisting is enabled.

The challenge I see, is about determining whether to hoist a dependency up-front (before installation), since I suppose this would bring the most value (No wasted time for duplicate installations)?

If the script curated the package.json file directly instead of running npm install, we wouldn't have the problem with the added package-lock.json file either, but it would be dependent on the dependency being specified in the root node_modules/ folder and would basically be replicating the work that Lerna's own hoisting functionality is doing, which intuitively sounds like a treacherous path to go down.

I will try to spike on it and see if I can make it work. It may not be as complicated as I think. I do not use lerna hoisting myself, and only have experience with Yarn Workspaces which is able to automatically hoist dependencies at install-time, even when installing a dependency directly in a sub-package. Lerna hoisting does not seem to do this.

Anifacted avatar Sep 04 '18 18:09 Anifacted

Wouldn't the solution just be to run lerna add vs npm install ?

matthew-dean avatar Nov 21 '19 23:11 matthew-dean