Skip to content

Automatic hoisting of common dependencies to repo root - #36

Merged
gigabo merged 25 commits into
asini:masterfrom
gigabo:hoist
Oct 25, 2016
Merged

gigabo merged 25 commits into
asini:masterfrom
gigabo:hoist

Conversation

@gigabo

@gigabo gigabo commented Oct 12, 2016

Copy link
Copy Markdown
Contributor

This adds a pair of options to govern installing some or all external dependencies at the repo root instead of distributed in package directories.

From the original proposal for this:

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

The options may be set on the command lined or in asini.json.

This addresses #14.

Comment thread test/PackageUtilities.js
PackageUtilities.filterPackages(packages, "").map((pkg) => pkg.name),
["package-3", "package-4", "package-a-1", "package-a-2"]
);
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an change in edge-case behavior due to the way filtration is factored to support hoisting as well as scope/ignore. Previously --scope= was an error. Now it's a noop.

@roblg roblg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm not super-familiar with the code, but the big things seem to be there, and look reasonable (hoisting/semver matching/warn on differing versions/.bin hangling).

@gigabo

gigabo commented Oct 13, 2016 •

Copy link
Copy Markdown
Contributor Author

Thanks for looking at this @roblg. I've since pushed two small fixes for minor issues I discovered while playing around bootstrapping babel, but they're pretty trivial.

The bigger news is hoisting makes bootstrap twice as fast for babel! 🚀

@roblg

roblg commented Oct 13, 2016

Copy link
Copy Markdown
Contributor

The bigger news is hoisting makes bootstrap twice as fast for babel! 🚀

That's awesome!

@gigabo

gigabo commented Oct 14, 2016

Copy link
Copy Markdown
Contributor Author

Just made it even faster! Starting the root install first since it's likely to take longest.

Now babel bootstrap takes 12s with hoisting compared to 30s without on my laptop!

These will be present when deps are already satisfied at the root.
@gigabo

gigabo commented Oct 14, 2016

Copy link
Copy Markdown
Contributor Author

For comparison: With yarn (on an experimental branch I'm working on) it's ~17s without hoisting (slower than the ~12s of npm with hoisting). With yarn plus hoisting... under 7 seconds. :godmode:

@gigabo

gigabo commented Oct 14, 2016

Copy link
Copy Markdown
Contributor Author

This will be easier to see in ascii art form:

              hoist

            no    yes
          +-----+-----+
        no| 30s | 12s |
yarn      |-----+-----+
       yes| 17s |  7s |
          +-----+-----+

@gigabo

gigabo commented Oct 25, 2016

Copy link
Copy Markdown
Contributor Author

Been using this with React Server for a couple of days locally. Do want.

Going to merge this afternoon, barring objections.

Comment thread src/PackageUtilities.js
import path from "path";
import {sync as globSync} from "glob";
import minimatch from "minimatch";
import isArray from "isarray";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not util.isArray (node < 4), or Array.isArray (node >= 4)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, didn't know about util.isArray.

This is still easier, though... :D


// Add this version if it's the first time we've seen it.
if (!dep.versions[version]) {
dep.versions [version] = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whitespace hurts my brain! 😝

.map((pkgName) => ({pkg: this.packageGraph.get(pkgName).package, deps: leaves[pkgName]}))
.forEach(({pkg, deps}) => actions.push(
(cb) => NpmUtilities.installInDir(pkg.location, deps, (err) => {
this.progressBar.tick(pkg.name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am i missing something, or is this tick not captured in the progress bar length specified below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The progress bar is just initialized with the number of actions we're going to run.

this.progressBar.init(actions.length);

There's a vestigial comment down there, though. I'll clean that up.


// Get the most common version.
const commonVersion = Object.keys(versions)
.reduce((a, b) => versions[a] > versions[b] ? a : b);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is much more elegant than what i did. 👍

@rygine rygine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gigabo

gigabo commented Oct 25, 2016

Copy link
Copy Markdown
Contributor Author

Thanks for looking at this. Bombs away!

@gigabo
gigabo merged commit 6f6f8aa into asini:master Oct 25, 2016
@gigabo gigabo mentioned this pull request Nov 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants