Skip to content

Commit

Permalink
feat(bootstrap): Add --strict option to enable throwing when `--hoi…
Browse files Browse the repository at this point in the history
…st` warns (#2140)
  • Loading branch information
jnielson94 authored and evocateur committed Jul 18, 2019
1 parent ae87669 commit 91437b5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions commands/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ For background on `--hoist`, see the [hoist documentation](https://github.com/le
Note: If packages depend on different _versions_ of an external dependency,
the most commonly used version will be hoisted, and a warning will be emitted.

### --strict

When used in conjunction with hoist will throw an error and stop bootstrapping after emitting the version warnings. Has no effect if you aren't hoisting, or if there are no version warnings.

```sh
$ lerna bootstrap --hoist --strict
```

### --nohoist [glob]

Do _not_ install external dependencies matching `glob` at the repo root. This
Expand Down
14 changes: 14 additions & 0 deletions commands/bootstrap/__tests__/bootstrap-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ describe("BootstrapCommand", () => {
});
});

describe("with --hoist and --strict", () => {
it("should throw if there's a hoist warning", async () => {
expect.assertions(1);

const testDir = await initFixture("basic");

try {
await lernaBootstrap(testDir)("--hoist", "--strict");
} catch (err) {
expect(err.message).toMatch("Package version inconsistencies found");
}
});
});

describe("with --ci", () => {
it("should call npmInstall with ci subCommand if on npm 5.7.0 or later", async () => {
const testDir = await initFixture("ci");
Expand Down
5 changes: 5 additions & 0 deletions commands/bootstrap/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ exports.builder = yargs => {
type: "string",
requiresArg: true,
},
strict: {
group: "Command Options:",
describe: "Don't allow warnings when hoisting as it causes longer bootstrap times and other issues.",
type: "boolean",
},
});

return filterable(yargs);
Expand Down
14 changes: 14 additions & 0 deletions commands/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ class BootstrapCommand extends Command {

const rootActions = [];
const leafActions = [];
// We don't want to exit on the first hoist issue, but log them all and then exit
let strictExitOnWarning = false;

// determine where each dependency will be installed
for (const [externalName, externalDependents] of depsToInstall) {
Expand All @@ -394,6 +396,9 @@ class BootstrapCommand extends Command {
`The repository root depends on ${externalName}@${rootVersion}, ` +
`which differs from the more common ${externalName}@${commonVersion}.`
);
if (this.options.strict) {
strictExitOnWarning = true;
}
}

const dependents = Array.from(externalDependents.get(rootVersion)).map(
Expand Down Expand Up @@ -427,6 +432,9 @@ class BootstrapCommand extends Command {
`"${leafName}" package depends on ${externalName}@${leafVersion}, ` +
`which differs from the hoisted ${externalName}@${rootVersion}.`
);
if (this.options.strict) {
strictExitOnWarning = true;
}
}

const leafNode = this.targetGraph.get(leafName);
Expand All @@ -444,6 +452,12 @@ class BootstrapCommand extends Command {
}
}
}
if (this.options.strict && strictExitOnWarning) {
throw new ValidationError(
"EHOISTSTRICT",
"Package version inconsistencies found while hoisting. Fix the above warnings and retry."
);
}

return pMapSeries([...rootActions, ...leafActions], el => el()).then(() => {
this.logger.silly("root dependencies", JSON.stringify(rootSet, null, 2));
Expand Down

0 comments on commit 91437b5

Please sign in to comment.