Skip to content

Commit

Permalink
refactor(run): Ensure lexical execution respects concurrency and stre…
Browse files Browse the repository at this point in the history
…aming options
  • Loading branch information
evocateur committed May 11, 2019
1 parent ea7c20d commit 98e77cf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
19 changes: 19 additions & 0 deletions commands/run/__tests__/run-command.test.js
Expand Up @@ -187,6 +187,25 @@ describe("RunCommand", () => {
"package-standalone",
]);
});

it("optionally streams output", async () => {
const testDir = await initFixture("toposort");

await lernaRun(testDir)("env", "--no-sort", "--stream");

expect(ranInPackagesStreaming(testDir)).toMatchInlineSnapshot(`
Array [
"packages/package-cycle-1 npm run env (prefixed: true)",
"packages/package-cycle-2 npm run env (prefixed: true)",
"packages/package-cycle-extraneous npm run env (prefixed: true)",
"packages/package-dag-1 npm run env (prefixed: true)",
"packages/package-dag-2a npm run env (prefixed: true)",
"packages/package-dag-2b npm run env (prefixed: true)",
"packages/package-dag-3 npm run env (prefixed: true)",
"packages/package-standalone npm run env (prefixed: true)",
]
`);
});
});

describe("in a cyclical repo", () => {
Expand Down
19 changes: 12 additions & 7 deletions commands/run/index.js
Expand Up @@ -73,10 +73,12 @@ class RunCommand extends Command {
let chain = Promise.resolve();
const getElapsed = timer();

if (this.options.parallel || !this.toposort) {
if (this.options.parallel) {
chain = chain.then(() => this.runScriptInPackagesParallel());
} else {
} else if (this.toposort) {
chain = chain.then(() => this.runScriptInPackagesTopological());
} else {
chain = chain.then(() => this.runScriptInPackagesLexical());
}

if (this.bail) {
Expand Down Expand Up @@ -158,12 +160,15 @@ class RunCommand extends Command {
}

runScriptInPackagesParallel() {
const runner =
this.options.parallel || this.options.stream
? pkg => this.runScriptInPackageStreaming(pkg)
: pkg => this.runScriptInPackageCapturing(pkg);
return pMap(this.packagesWithScript, pkg => this.runScriptInPackageStreaming(pkg));
}

runScriptInPackagesLexical() {
const runner = this.options.stream
? pkg => this.runScriptInPackageStreaming(pkg)
: pkg => this.runScriptInPackageCapturing(pkg);

return pMap(this.packagesWithScript, runner);
return pMap(this.packagesWithScript, runner, { concurrency: this.concurrency });
}

runScriptInPackageStreaming(pkg) {
Expand Down

0 comments on commit 98e77cf

Please sign in to comment.