Skip to content

Commit

Permalink
refactor(run-topologically): Pass packages and runner in parameters, …
Browse files Browse the repository at this point in the history
…not figgy config
  • Loading branch information
evocateur committed May 14, 2019
1 parent 6ada0e3 commit 2691bb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
4 changes: 1 addition & 3 deletions commands/exec/index.js
Expand Up @@ -124,11 +124,9 @@ class ExecCommand extends Command {
? pkg => this.runCommandInPackageStreaming(pkg)
: pkg => this.runCommandInPackageCapturing(pkg);

return runTopologically({
packages: this.filteredPackages,
return runTopologically(this.filteredPackages, runner, {
concurrency: this.concurrency,
rejectCycles: this.options.rejectCycles,
runner,
});
}

Expand Down
4 changes: 1 addition & 3 deletions commands/run/index.js
Expand Up @@ -132,11 +132,9 @@ class RunCommand extends Command {
? pkg => this.runScriptInPackageStreaming(pkg)
: pkg => this.runScriptInPackageCapturing(pkg);

return runTopologically({
packages: this.packagesWithScript,
return runTopologically(this.packagesWithScript, runner, {
concurrency: this.concurrency,
rejectCycles: this.options.rejectCycles,
runner,
});
}

Expand Down
4 changes: 1 addition & 3 deletions commands/version/index.js
Expand Up @@ -548,11 +548,9 @@ class VersionCommand extends Command {
const mapUpdate = pPipe(actions);

chain = chain.then(() =>
runTopologically({
packages: this.packagesToVersion,
runTopologically(this.packagesToVersion, mapUpdate, {
concurrency: this.concurrency,
rejectCycles: this.options.rejectCycles,
runner: mapUpdate,
})
);

Expand Down
27 changes: 17 additions & 10 deletions utils/run-topologically/run-topologically.js
Expand Up @@ -7,19 +7,26 @@ const QueryGraph = require("@lerna/query-graph");
module.exports = runTopologically;

const TopologicalConfig = figgyPudding({
packages: {},
// p-queue options
concurrency: {},
"reject-cycles": {},
rejectCycles: "reject-cycles",
runner: {},
// query-graph options handled elsewhere
});

function runTopologically(_opts) {
const opts = TopologicalConfig(_opts);
const { packages, concurrency, rejectCycles, runner } = opts;

const queue = new PQueue({ concurrency });
const graph = new QueryGraph(packages, { rejectCycles });
/**
* Run callback in maximally-saturated topological order.
*
* @param {Array<Package>} packages List of `Package` instances
* @param {Function} runner Callback to map each `Package` with
* @param {Number} [opts.concurrency] Concurrency of execution
* @param {String} [opts.graphType] "allDependencies" or "dependencies"
* @param {Boolean} [opts.rejectCycles] Whether or not to reject cycles
* @returns {Promise<Array<*>>} when all executions complete
*/
function runTopologically(packages, runner, opts) {
const options = TopologicalConfig(opts);

const queue = new PQueue(options);
const graph = new QueryGraph(packages, options);

return new Promise((resolve, reject) => {
const returnValues = [];
Expand Down

0 comments on commit 2691bb8

Please sign in to comment.