You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature] Automatic hoisting of common dependencies to repo root #334
This was left out of #237 to reduce its scope, but is still a valuable improvement!
Hoisting external dependencies that are shared across packages:
dramatically speeds up bootstrap
reduces the storage footprint of a Lerna repo
handles the singleton problem where a common dependency (e.g. React) must be shared
Should this be default behavior, or an option (lerna bootstrap --hoist-external)?
It definitely needs a way to opt-out at the dependency level (we have deps internally at Redfin that can't be hoisted). What does that look like? An option like --no-hoist=<externalDep>?
Reacted by Sean Kelley, Laurent De Smet, Radosław Miernik and Sresan Thevarajah
What would be the semantics around different versions of the same dependency scattered around? If I have three packages that depend on foo at ^1.0.0, ^1.1.0 and ^2.0.0, how many versions of foo do I end up with and where are they? I'm assuming a copy of 1.1.0 since it satisfies the first two and one of 2.0.0, both hoisted. This seems to demand the need for some kind of extra-nested fake-node_modules (lerna_modules?) like lerna_modules/foo/1.1.0 and lerna_modules/foo/2.0.0.
Lerna is a library that is mostly used when you have a lot of packages to manage with a lot of dependencies between them. These kind of repos are the ones that need hoisted dependencies the most, so this is in favor of making it the default option. What are the technical reasons that you can't hoist the dependencies? I can think of dependencies that use the bin property of npm but what are other possible reasons?
@laurentdesmet there are potentially a few downsides to hoisting:
hoisted modules can conflict with existing modules at the repo root. so, where do the hoisted modules go? with Add support for configurable package locations #332 on the horizon, we can't necessarily guarantee that hoisted modules are located up the directory tree without conflicting with the root.
npm outdated becomes broken. this may not be a deal breaker.
package.json dependencies may become stale as a result of modules being installed "globally." this is more of a maintenance issue, but it has bitten me.
What are the technical reasons that you can't hoist the dependencies?
Any use of install path.
For example our module tagger generates logger names such as react-server.core.util.PageUtil using the path to a module relative to the installed location.
It may be possible to rework that specific package to use working directory, or module.parent, but I doubt we're the only module authors to have relied on the install location in some way.
even with the above potential downsides, my team and i were using hoisted modules without any major issues for a few months.
Yeah, we've been manually hoisting deps in our internal (private, not managed by Lerna) repo for a while now.
The main down-side of manual hoisting is the actual dependency relationship is lost. Which packages need React? How about lodash? Far nicer to maintain dependency relationships per package and automatically factor out the commonality (where possible) at the framework level.
That sounds like an argument for hoisting as an option rather than by default.
Given the benefits (listed above in the issue description) this is, in my opinion, actually critical for the continued success of Lerna. Long bootstrap time was a key reason for PouchDB dropping Lerna, for example. Another example is Redfin's internal monorepo, which we're hoping to manage with Lerna. Hoisting is a prerequisite for us, both due to performance and enforcement of "singleton" modules such as React.
Anything you do here is going to have inconsistency even at an option level. It's the type of feature that you could implement one of ten ways and each person using Lerna is going to want a different thing.
Lerna insists a certain structure, the more that we remove from it the more confusing the entire experience of using Lerna becomes. If people are unwilling to follow the structure they can go off in their own paths.
Well, then this means that Lerna is not usable (without tweaking it yourself) for any project that uses singleton modules like React or where each package has a lot of dependencies (resulting in performance issues). Contradictory, these are the projects that need Lerna the most.
The result of this is that a lot of people that use Lerna, are adding little ad hoc scripts to make it work for them, resulting in a fragmentation. Or others will just give up and leave Lerna altogether. I'm not sure if that will help the project's long-term success.
Isn't it then the lesser evil to provide such an option to hoist common dependencies?
Or is it an option that we symlink common modules to some common folder in the root?
@thejameskyle What is your vision for the future of Lerna?
Do you want Lerna to continue to improve in ways that make life easier for the developers who rely on it? Do you want Lerna to continue to live at the heart of diverse and important projects?
These are the sort of features that are not just worthwhile, but necessary for Lerna to continue to grow and thrive. I understand and appreciate the urge to keep software simple and focused. Part of what makes Lerna such an important tool is that it addresses a single urgent need: Working more effectively in an environment with many node packages. Features that improve that effectiveness do not detract from that focus. They enhance it.
Long bootstrap time was a key reason for PouchDB dropping Lerna, for example.
Our build time went from ~3 mins to ~8mins when we stopped hoisting. It's quickly becoming an issue. We've experimented with keeping node_modules folders around, but that's proving to be error prone when external dependencies need an update even though they meet the dependency requirements.
Features like this aren't worthwhile.
I'm not understanding this train of thought when there is clearly a need by the community. I do understand the need for consistency, but it seems that Lerna is being used for more and more use cases and the project should be open to fulfilling those needs.
If Lerna becomes a Lerna repo, this will be a non-issue as the community can create non-official commands to satisfy its needs.
The more functionality you add in Lerna the more you remove the ability to easily extend it with additional bits of functionality. When you remove guarantees you make software harder to consume.
Solve this by adding subtractive features like skipping the install step and only doing linking. A continuous stream of additive features will make it more difficult to use. Add hooks, not thirty separate feature requests.
Well, then I'm curious about how you solved it :-). In a normal setting with npm3, npm would flatten everything for you so you end up with exactly one dependency on React (if the semver ranges allow it). But that's not what will happen with the default behavior of Lerna.
But if I understand you correctly, then you agree on the fact that there are problems to solve relating to performance and singleton modules, but that there are probably better ways than the 'hoisting' solution. Maybe we should rename this issue (or make a new one) to something more general to investigate what possible strategies can be used or provided to fix the performance and singleton issues that users are experiencing right now.
We also have solved some of the problems that dependency hoisting addresses. We've manually factored deps into the repo root to improve performance. We've used webpack configuration to make React a singleton in the client bundle. It's a pain. I'd rather not have to deal with that myself. I'd rather the tool I use for managing my repo do it for me.
The problem of singleton projects doesn't appear in the monorepo. Lerna handles them just fine as they are intended to be installed. If you were working outside of a monorepo in just a bunch of folders it would work exactly this way.
This issue arises when you start using something like browserify or webpack, those are the tools that need to de-duplicate things. Set it up there and fix your entire build chain. You're just going to have to solve it twice if you push it down into Lerna.
There is always a tradeoff between power and ease of use.
That's not true, prioritize low level APIs for extension, don't build high-level APIs. High level APIs are less powerful and less easy to use. Lower level APIs allow for people to build the things that they need. Read the extensible web manifesto if you need inspiration.
What is the answer for devs who want this feature?
The answer is find a better solution, build on top of Lerna, if you need a hook request it. Don't push every bit of complexity into one location. You likely already have everything you need:
I investigated lerna bootstrap --ignore but I thought that only applied
to packages that are part of the Lerna repo.
Ah, just as easy to add flags to the bootstrap process that supports not installing them. That's a very quick and clean diff that doesn't require any bike-shedding on the exact semantics.
Locking... if you want to continue this issue in a PR, I'll look at it. If you want to add a flag for skipping install of certain modules I would be happy to add that.
@thejameskyle I think it might of been better to discuss instead of closing? I think there were some discussions on slack as well and it might of felt weird to just close it and now lock the issue like that (even if you guys disagree). (I don't have an opinion on the particular issue atm)
changed the title [-]Automatic hoisting of common dependencies to repo root[/-][+][Feature] Automatic hoisting of common dependencies to repo root[/+]on Nov 16, 2016
Activity
seansfkelley commentedon Sep 8, 2016
What would be the semantics around different versions of the same dependency scattered around? If I have three packages that depend on
fooat^1.0.0,^1.1.0and^2.0.0, how many versions offoodo I end up with and where are they? I'm assuming a copy of1.1.0since it satisfies the first two and one of2.0.0, both hoisted. This seems to demand the need for some kind of extra-nested fake-node_modules(lerna_modules?) likelerna_modules/foo/1.1.0andlerna_modules/foo/2.0.0.gigabo commentedon Sep 8, 2016
I think what @rygine originally did in #237 made sense: Hoist the most common version.
Ideally packages within a repo will generally depend on compatible versions.
A
lerna pin dep@versioncommand would help with that.laurentdesmet commentedon Sep 10, 2016
Lerna is a library that is mostly used when you have a lot of packages to manage with a lot of dependencies between them. These kind of repos are the ones that need hoisted dependencies the most, so this is in favor of making it the default option. What are the technical reasons that you can't hoist the dependencies? I can think of dependencies that use the
binproperty of npm but what are other possible reasons?rygine commentedon Sep 12, 2016
@laurentdesmet there are potentially a few downsides to hoisting:
npm outdatedbecomes broken. this may not be a deal breaker.package.jsondependencies may become stale as a result of modules being installed "globally." this is more of a maintenance issue, but it has bitten me.the last 2 issues may be solved with https://github.com/maxogden/dependency-check or https://github.com/dylang/npm-check.
even with the above potential downsides, my team and i were using hoisted modules without any major issues for a few months.
jamiebuilds commentedon Sep 12, 2016
I'd rather have consistency, hoisting dependencies has a lot of edge cases that can't be worked around in the npm model.
gigabo commentedon Sep 12, 2016
Any use of install path.
For example our module tagger generates logger names such as
react-server.core.util.PageUtilusing the path to a module relative to the installed location.It may be possible to rework that specific package to use working directory, or
module.parent, but I doubt we're the only module authors to have relied on the install location in some way.Yeah, we've been manually hoisting deps in our internal (private, not managed by Lerna) repo for a while now.
The main down-side of manual hoisting is the actual dependency relationship is lost. Which packages need React? How about lodash? Far nicer to maintain dependency relationships per package and automatically factor out the commonality (where possible) at the framework level.
Hi @thejameskyle, welcome back!
That sounds like an argument for hoisting as an option rather than by default.
Given the benefits (listed above in the issue description) this is, in my opinion, actually critical for the continued success of Lerna. Long bootstrap time was a key reason for PouchDB dropping Lerna, for example. Another example is Redfin's internal monorepo, which we're hoping to manage with Lerna. Hoisting is a prerequisite for us, both due to performance and enforcement of "singleton" modules such as React.
jamiebuilds commentedon Sep 12, 2016
Anything you do here is going to have inconsistency even at an option level. It's the type of feature that you could implement one of ten ways and each person using Lerna is going to want a different thing.
Lerna insists a certain structure, the more that we remove from it the more confusing the entire experience of using Lerna becomes. If people are unwilling to follow the structure they can go off in their own paths.
Features like this aren't worthwhile.
laurentdesmet commentedon Sep 12, 2016
Well, then this means that Lerna is not usable (without tweaking it yourself) for any project that uses singleton modules like React or where each package has a lot of dependencies (resulting in performance issues). Contradictory, these are the projects that need Lerna the most.
The result of this is that a lot of people that use Lerna, are adding little ad hoc scripts to make it work for them, resulting in a fragmentation. Or others will just give up and leave Lerna altogether. I'm not sure if that will help the project's long-term success.
Isn't it then the lesser evil to provide such an option to hoist common dependencies?
Or is it an option that we symlink common modules to some common folder in the root?
gigabo commentedon Sep 12, 2016
@thejameskyle What is your vision for the future of Lerna?
Do you want Lerna to continue to improve in ways that make life easier for the developers who rely on it? Do you want Lerna to continue to live at the heart of diverse and important projects?
These are the sort of features that are not just worthwhile, but necessary for Lerna to continue to grow and thrive. I understand and appreciate the urge to keep software simple and focused. Part of what makes Lerna such an important tool is that it addresses a single urgent need: Working more effectively in an environment with many node packages. Features that improve that effectiveness do not detract from that focus. They enhance it.
rygine commentedon Sep 12, 2016
Our build time went from ~3 mins to ~8mins when we stopped hoisting. It's quickly becoming an issue. We've experimented with keeping
node_modulesfolders around, but that's proving to be error prone when external dependencies need an update even though they meet the dependency requirements.I'm not understanding this train of thought when there is clearly a need by the community. I do understand the need for consistency, but it seems that Lerna is being used for more and more use cases and the project should be open to fulfilling those needs.
If Lerna becomes a Lerna repo, this will be a non-issue as the community can create non-official commands to satisfy its needs.
2 remaining items
jamiebuilds commentedon Sep 12, 2016
The more functionality you add in Lerna the more you remove the ability to easily extend it with additional bits of functionality. When you remove guarantees you make software harder to consume.
jamiebuilds commentedon Sep 12, 2016
Solve this by adding subtractive features like skipping the install step and only doing linking. A continuous stream of additive features will make it more difficult to use. Add hooks, not thirty separate feature requests.
laurentdesmet commentedon Sep 12, 2016
Well, then I'm curious about how you solved it :-). In a normal setting with npm3, npm would flatten everything for you so you end up with exactly one dependency on React (if the semver ranges allow it). But that's not what will happen with the default behavior of Lerna.
But if I understand you correctly, then you agree on the fact that there are problems to solve relating to performance and singleton modules, but that there are probably better ways than the 'hoisting' solution. Maybe we should rename this issue (or make a new one) to something more general to investigate what possible strategies can be used or provided to fix the performance and singleton issues that users are experiencing right now.
laurentdesmet commentedon Sep 12, 2016
Btw, forget about my symlinking proposal, because that one doesn't help with the singleton problem.
jamiebuilds commentedon Sep 12, 2016
I can't say anything right now, but just wait a bit and the performance problem should be solved soon.
gigabo commentedon Sep 12, 2016
Isn't Lerna a tool to help solve problems associated with monorepos?
There is always a tradeoff between power and ease of use.
Does an option to automatically hoist dependencies cross some threshold?
What is the answer for devs who want this feature?
We also have solved some of the problems that dependency hoisting addresses. We've manually factored deps into the repo root to improve performance. We've used webpack configuration to make React a singleton in the client bundle. It's a pain. I'd rather not have to deal with that myself. I'd rather the tool I use for managing my repo do it for me.
jamiebuilds commentedon Sep 12, 2016
The problem of singleton projects doesn't appear in the monorepo. Lerna handles them just fine as they are intended to be installed. If you were working outside of a monorepo in just a bunch of folders it would work exactly this way.
This issue arises when you start using something like browserify or webpack, those are the tools that need to de-duplicate things. Set it up there and fix your entire build chain. You're just going to have to solve it twice if you push it down into Lerna.
That's not true, prioritize low level APIs for extension, don't build high-level APIs. High level APIs are less powerful and less easy to use. Lower level APIs allow for people to build the things that they need. Read the extensible web manifesto if you need inspiration.
The answer is find a better solution, build on top of Lerna, if you need a hook request it. Don't push every bit of complexity into one location. You likely already have everything you need:
And then add your resolves to Browserify and Webpack or whatever tool you are using.
If that doesn't work, think of the minimal lowest level API you need to make it work and request that. It's more likely to be useful to others.
laurentdesmet commentedon Sep 12, 2016
I investigated
lerna bootstrap --ignorebut I thought that only appliedto packages that are part of the Lerna repo.
rygine commentedon Sep 12, 2016
this is correct.
i added a resolver to Webpack with a
rootofpath.join(process.cwd(), 'node_modules')to handle the singleton problem.jamiebuilds commentedon Sep 12, 2016
Ah, just as easy to add flags to the bootstrap process that supports not installing them. That's a very quick and clean diff that doesn't require any bike-shedding on the exact semantics.
jamiebuilds commentedon Sep 12, 2016
Locking... if you want to continue this issue in a PR, I'll look at it. If you want to add a flag for skipping install of certain modules I would be happy to add that.
hzoo commentedon Sep 13, 2016
@thejameskyle I think it might of been better to discuss instead of closing? I think there were some discussions on slack as well and it might of felt weird to just close it and now lock the issue like that (even if you guys disagree). (I don't have an opinion on the particular issue atm)
[-]Automatic hoisting of common dependencies to repo root[/-][+][Feature] Automatic hoisting of common dependencies to repo root[/+]