Skip to content

Commit 23736e5

Browse files
committedMay 13, 2019
feat(exec): Add just-in-time queue management
1 parent 3a8b175 commit 23736e5

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed
 

‎commands/exec/index.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"use strict";
22

3+
const pMap = require("p-map");
4+
35
const ChildProcessUtilities = require("@lerna/child-process");
46
const Command = require("@lerna/command");
5-
const batchPackages = require("@lerna/batch-packages");
6-
const runParallelBatches = require("@lerna/run-parallel-batches");
7+
const runTopologically = require("@lerna/run-topologically");
78
const ValidationError = require("@lerna/validation-error");
89
const { getFilteredPackages } = require("@lerna/filter-options");
910

@@ -47,10 +48,6 @@ class ExecCommand extends Command {
4748
this.count = this.filteredPackages.length;
4849
this.packagePlural = this.count === 1 ? "package" : "packages";
4950
this.joinedCommand = [this.command].concat(this.args).join(" ");
50-
51-
this.batchedPackages = this.toposort
52-
? batchPackages(this.filteredPackages, this.options.rejectCycles)
53-
: [this.filteredPackages];
5451
});
5552
}
5653

@@ -67,8 +64,10 @@ class ExecCommand extends Command {
6764

6865
if (this.options.parallel) {
6966
chain = chain.then(() => this.runCommandInPackagesParallel());
67+
} else if (this.toposort) {
68+
chain = chain.then(() => this.runCommandInPackagesTopological());
7069
} else {
71-
chain = chain.then(() => this.runCommandInPackagesBatched());
70+
chain = chain.then(() => this.runCommandInPackagesLexical());
7271
}
7372

7473
if (this.bail) {
@@ -120,18 +119,29 @@ class ExecCommand extends Command {
120119
};
121120
}
122121

123-
runCommandInPackagesBatched() {
122+
runCommandInPackagesTopological() {
124123
const runner = this.options.stream
125124
? pkg => this.runCommandInPackageStreaming(pkg)
126125
: pkg => this.runCommandInPackageCapturing(pkg);
127126

128-
return runParallelBatches(this.batchedPackages, this.concurrency, runner).then(batchedResults =>
129-
batchedResults.reduce((arr, batch) => arr.concat(batch), [])
130-
);
127+
return runTopologically({
128+
packages: this.filteredPackages,
129+
concurrency: this.concurrency,
130+
rejectCycles: this.options.rejectCycles,
131+
runner,
132+
});
131133
}
132134

133135
runCommandInPackagesParallel() {
134-
return Promise.all(this.filteredPackages.map(pkg => this.runCommandInPackageStreaming(pkg)));
136+
return pMap(this.filteredPackages, pkg => this.runCommandInPackageStreaming(pkg));
137+
}
138+
139+
runCommandInPackagesLexical() {
140+
const runner = this.options.stream
141+
? pkg => this.runCommandInPackageStreaming(pkg)
142+
: pkg => this.runCommandInPackageCapturing(pkg);
143+
144+
return pMap(this.filteredPackages, runner, { concurrency: this.concurrency });
135145
}
136146

137147
runCommandInPackageStreaming(pkg) {

‎commands/exec/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
"populate--": true
3636
},
3737
"dependencies": {
38-
"@lerna/batch-packages": "file:../../utils/batch-packages",
3938
"@lerna/child-process": "file:../../core/child-process",
4039
"@lerna/command": "file:../../core/command",
4140
"@lerna/filter-options": "file:../../core/filter-options",
42-
"@lerna/run-parallel-batches": "file:../../utils/run-parallel-batches",
43-
"@lerna/validation-error": "file:../../core/validation-error"
41+
"@lerna/run-topologically": "file:../../utils/run-topologically",
42+
"@lerna/validation-error": "file:../../core/validation-error",
43+
"p-map": "^1.2.0"
4444
}
4545
}

‎package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.