Skip to content

Commit

Permalink
feat(add): Add --no-bootstrap option
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Dec 3, 2018
1 parent 38097d8 commit 89bb928
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
4 changes: 4 additions & 0 deletions commands/add/README.md
Expand Up @@ -37,6 +37,10 @@ Add the new package with an exact version (e.g., `1.0.1`) rather than the defaul

Use a custom registry to install the targeted package.

### `--no-bootstrap`

Skip the chained `lerna bootstrap`.

## Examples

```sh
Expand Down
9 changes: 9 additions & 0 deletions commands/add/__tests__/add-command.test.js
Expand Up @@ -251,6 +251,15 @@ describe("AddCommand", () => {
expect(bootstrap).not.toHaveBeenCalled();
});

it("skips bootstrap with --no-bootstrap", async () => {
const testDir = await initFixture("basic");

await lernaAdd(testDir)("@test/package-1", "--no-bootstrap");

expect(bootstrap).not.toHaveBeenCalled();
expect(await readPkg(testDir, "packages/package-2")).toDependOn("@test/package-1", "^1.0.0");
});

it("should reset a dependency from caret to exact", async () => {
const testDir = await initFixture("basic");

Expand Down
7 changes: 7 additions & 0 deletions commands/add/command.js
Expand Up @@ -38,6 +38,12 @@ exports.builder = yargs => {
type: "string",
requiresArg: true,
},
bootstrap: {
group: "Command Options:",
describe: "Automatically chain `lerna bootstrap`.\nPass --no-bootstrap to avoid this.",
type: "boolean",
defaultDescription: "true",
},
})
.example(
"$0 add module-1 packages/prefix-*",
Expand All @@ -46,6 +52,7 @@ exports.builder = yargs => {
.example("$0 add module-1 --scope=module-2", "Install module-1 to module-2")
.example("$0 add module-1 --scope=module-2 --dev", "Install module-1 to module-2 in devDependencies")
.example("$0 add module-1", "Install module-1 in all modules except module-1")
.example("$0 add module-1 --no-bootstrap", "Skip automatic `lerna bootstrap`")
.example("$0 add babel-core", "Install babel-core in all modules");

return filterable(yargs);
Expand Down
26 changes: 17 additions & 9 deletions commands/add/index.js
Expand Up @@ -81,17 +81,25 @@ class AddCommand extends Command {

this.logger.info("", `Adding ${this.spec.name} in ${numberOfPackages}`);

return this.makeChanges().then(() => {
const argv = Object.assign({}, this.options, {
args: [],
cwd: this.project.rootPath,
scope: this.packagesToChange.map(pkg => pkg.name),
// silence initial cli version logging, etc
composed: "add",
let chain = Promise.resolve();

chain = chain.then(() => this.makeChanges());

if (this.options.bootstrap !== false) {
chain = chain.then(() => {
const argv = Object.assign({}, this.options, {
args: [],
cwd: this.project.rootPath,
scope: this.packagesToChange.map(pkg => pkg.name),
// silence initial cli version logging, etc
composed: "add",
});

return bootstrap(argv);
});
}

return bootstrap(argv);
});
return chain;
}

collectPackagesToChange() {
Expand Down

0 comments on commit 89bb928

Please sign in to comment.