Skip to content

Commit 91437b5

Browse files
jnielson94evocateur
authored andcommitted
feat(bootstrap): Add --strict option to enable throwing when --hoist warns (#2140)
1 parent ae87669 commit 91437b5

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

commands/bootstrap/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ For background on `--hoist`, see the [hoist documentation](https://github.com/le
5656
Note: If packages depend on different _versions_ of an external dependency,
5757
the most commonly used version will be hoisted, and a warning will be emitted.
5858

59+
### --strict
60+
61+
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.
62+
63+
```sh
64+
$ lerna bootstrap --hoist --strict
65+
```
66+
5967
### --nohoist [glob]
6068

6169
Do _not_ install external dependencies matching `glob` at the repo root. This

commands/bootstrap/__tests__/bootstrap-command.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ describe("BootstrapCommand", () => {
208208
});
209209
});
210210

211+
describe("with --hoist and --strict", () => {
212+
it("should throw if there's a hoist warning", async () => {
213+
expect.assertions(1);
214+
215+
const testDir = await initFixture("basic");
216+
217+
try {
218+
await lernaBootstrap(testDir)("--hoist", "--strict");
219+
} catch (err) {
220+
expect(err.message).toMatch("Package version inconsistencies found");
221+
}
222+
});
223+
});
224+
211225
describe("with --ci", () => {
212226
it("should call npmInstall with ci subCommand if on npm 5.7.0 or later", async () => {
213227
const testDir = await initFixture("ci");

commands/bootstrap/command.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ exports.builder = yargs => {
5353
type: "string",
5454
requiresArg: true,
5555
},
56+
strict: {
57+
group: "Command Options:",
58+
describe: "Don't allow warnings when hoisting as it causes longer bootstrap times and other issues.",
59+
type: "boolean",
60+
},
5661
});
5762

5863
return filterable(yargs);

commands/bootstrap/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ class BootstrapCommand extends Command {
373373

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

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

399404
const dependents = Array.from(externalDependents.get(rootVersion)).map(
@@ -427,6 +432,9 @@ class BootstrapCommand extends Command {
427432
`"${leafName}" package depends on ${externalName}@${leafVersion}, ` +
428433
`which differs from the hoisted ${externalName}@${rootVersion}.`
429434
);
435+
if (this.options.strict) {
436+
strictExitOnWarning = true;
437+
}
430438
}
431439

432440
const leafNode = this.targetGraph.get(leafName);
@@ -444,6 +452,12 @@ class BootstrapCommand extends Command {
444452
}
445453
}
446454
}
455+
if (this.options.strict && strictExitOnWarning) {
456+
throw new ValidationError(
457+
"EHOISTSTRICT",
458+
"Package version inconsistencies found while hoisting. Fix the above warnings and retry."
459+
);
460+
}
447461

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

0 commit comments

Comments
 (0)