Skip to content

Commit

Permalink
fix(bootstrap): Use run-lifecycle factory instead of manual filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Dec 18, 2018
1 parent d422167 commit d32feaa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
26 changes: 8 additions & 18 deletions commands/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ const pWaterfall = require("p-waterfall");
const Command = require("@lerna/command");
const rimrafDir = require("@lerna/rimraf-dir");
const hasNpmVersion = require("@lerna/has-npm-version");
const npmConf = require("@lerna/npm-conf");
const npmInstall = require("@lerna/npm-install");
const runLifecycle = require("@lerna/run-lifecycle");
const { createRunner } = require("@lerna/run-lifecycle");
const batchPackages = require("@lerna/batch-packages");
const runParallelBatches = require("@lerna/run-parallel-batches");
const symlinkBinary = require("@lerna/symlink-binary");
Expand Down Expand Up @@ -63,7 +62,7 @@ class BootstrapCommand extends Command {
);
}

this.conf = npmConf({ registry });
this.runPackageLifecycle = createRunner({ registry });
this.npmConfig = {
registry,
npmClient,
Expand Down Expand Up @@ -176,24 +175,15 @@ class BootstrapCommand extends Command {
return;
}

const packagesWithScript = new Set(this.filteredPackages.filter(pkg => pkg.scripts[stage]));

if (!packagesWithScript.size) {
return;
}

const tracker = this.logger.newItem(stage);

const mapPackageWithScript = pkg => {
if (packagesWithScript.has(pkg)) {
return runLifecycle(pkg, stage, this.conf).then(() => {
tracker.silly("lifecycle", "finished", pkg.name);
tracker.completeWork(1);
});
}
};
const mapPackageWithScript = pkg =>
this.runPackageLifecycle(pkg, stage).then(() => {
tracker.silly("lifecycle", "finished %j in %s", stage, pkg.name);
tracker.completeWork(1);
});

tracker.addWork(packagesWithScript.size);
tracker.addWork(this.filteredPackages.length);

return pFinally(runParallelBatches(this.batchedPackages, this.concurrency, mapPackageWithScript), () =>
tracker.finish()
Expand Down
1 change: 0 additions & 1 deletion commands/bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@lerna/command": "file:../../core/command",
"@lerna/filter-options": "file:../../core/filter-options",
"@lerna/has-npm-version": "file:../../utils/has-npm-version",
"@lerna/npm-conf": "file:../../utils/npm-conf",
"@lerna/npm-install": "file:../../utils/npm-install",
"@lerna/package-graph": "file:../../core/package-graph",
"@lerna/rimraf-dir": "file:../../utils/rimraf-dir",
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d32feaa

Please sign in to comment.