sumlyzer 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -50,6 +50,7 @@ Options:
50
50
  | `--script <name>` | `test` | npm script to run per workspace |
51
51
  | `--ff` | off | fail fast: stop at the first failing workspace |
52
52
  | `--junit <path>` | off | write an aggregated JUnit XML report to `<path>` |
53
+ | `-c, --concurrency <n>` | `1` | run up to `<n>` workspaces at once |
53
54
  | `-h, --help` | | print usage |
54
55
 
55
56
  Exit code is `1` if any workspace fails (or if the project has no
@@ -57,6 +58,16 @@ workspaces), `0` otherwise, wire it straight into CI without extra parsing.
57
58
  This also applies when `--junit` can't write its report (e.g. an invalid
58
59
  `<path>`): the exit code is `1` even if every workspace's tests passed.
59
60
 
61
+ ## Features
62
+
63
+ - Aggregated pass/fail summary table, so nothing scrolls out of the terminal
64
+ - Fail-fast (`--ff`): stop at the first failing workspace
65
+ - Aggregated JUnit XML report (`--junit`), merging every workspace's own results
66
+ - GitHub Actions log folding: each workspace's output collapsed into an
67
+ expandable group, automatically, no flag needed
68
+ - Concurrent runs (`--concurrency <n>`): run several workspaces' test scripts
69
+ at once instead of one by one
70
+
60
71
  ## Example
61
72
 
62
73
  ```
@@ -188,6 +199,22 @@ full suite output.
188
199
  No other CI provider is currently supported: GitHub is the
189
200
  only one whose log folding sumlyzer has actually verified end-to-end.
190
201
 
202
+ ### Concurrency
203
+
204
+ `--concurrency <n>` runs up to `<n>` workspaces' scripts at the same time
205
+ instead of one after another, which can noticeably cut wall-clock time on
206
+ projects with many workspaces. There is no ordering dependency to worry about
207
+ here: unlike a `build` script, one workspace's `node:test` run never depends
208
+ on another workspace's test run, so nothing needs to be sequenced.
209
+
210
+ Since workspaces can now finish in any order, their output interleaves in
211
+ whatever order they complete, rather than following the `workspaces` list
212
+ order.
213
+
214
+ With `--ff`, a failure only stops workspaces that haven't started yet; any
215
+ workspace already running when the failure is detected runs to completion
216
+ (sumlyzer doesn't kill in-flight processes).
217
+
191
218
  ## Why
192
219
 
193
220
  `npm run test --workspaces --if-present` runs every workspace but gives you
@@ -195,6 +222,14 @@ no aggregated summary and no way to fail fast early. An early failure just
195
222
  scrolls off screen once later workspaces print their own output. sumlyzer is
196
223
  a small, dependency-free tool that solves just this.
197
224
 
225
+ This exact fail-fast behavior at the `--workspaces` level has been requested
226
+ from npm more than once:
227
+ [npm/rfcs#575](https://github.com/npm/rfcs/issues/575) (open) and
228
+ [npm/rfcs#602](https://github.com/npm/rfcs/issues/602) (closed). Until it
229
+ lands (if it ever does), sumlyzer's `--ff` flag gets you there — see also
230
+ this [Stack Overflow answer](https://stackoverflow.com/questions/71300870/npm-workspace-command-does-not-stop-executing-when-command-fails-for-a-workspace/79989284#79989284)
231
+ on the same problem.
232
+
198
233
  ## Contributing
199
234
 
200
235
  See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup, conventions, and how to submit changes.
package/bin/sumlyzer.mjs CHANGED
@@ -11,6 +11,7 @@ try {
11
11
  ff: { type: "boolean", default: false },
12
12
  script: { type: "string", default: "test" },
13
13
  junit: { type: "string" },
14
+ concurrency: { type: "string", short: "c", default: "1" },
14
15
  help: { type: "boolean", short: "h", default: false }
15
16
  }
16
17
  }));
@@ -22,20 +23,33 @@ catch (error) {
22
23
  process.exit(1);
23
24
  }
24
25
 
26
+ const concurrency = Number.parseInt(values.concurrency, 10);
27
+ if (!Number.isInteger(concurrency) || concurrency < 1 || String(concurrency) !== values.concurrency) {
28
+ console.info(`--concurrency must be a positive integer, got "${values.concurrency}". Run "sumlyzer --help" for usage.`);
29
+ process.exit(1);
30
+ }
31
+
25
32
  if (values.help) {
26
33
  console.log(`sumlyzer [options]
27
34
 
28
- Runs each npm workspace's "${values.script}" script one by one. Passing
35
+ Runs each npm workspace's "${values.script}" script, ${concurrency > 1 ? `${concurrency} at a time` : "one by one"}. Passing
29
36
  workspaces collapse to a single line; failing ones print only the relevant
30
37
  failure detail. Ends with an aggregated pass/fail summary table.
31
38
 
32
39
  Options:
33
- --script <name> npm script to run per workspace (default: "test")
34
- --ff fail fast: stop at the first failing workspace
35
- --junit <path> write an aggregated JUnit XML report to <path>
36
- -h, --help show this help
40
+ --script <name> npm script to run per workspace (default: "test")
41
+ --ff fail fast: stop at the first failing workspace
42
+ --junit <path> write an aggregated JUnit XML report to <path>
43
+ -c, --concurrency <n> run up to <n> workspaces at once (default: 1)
44
+ -h, --help show this help
37
45
  `);
38
46
  process.exit(0);
39
47
  }
40
48
 
41
- await main({ root: path.resolve(process.cwd()), scriptName: values.script, ff: values.ff, junitPath: values.junit });
49
+ await main({
50
+ root: path.resolve(process.cwd()),
51
+ scriptName: values.script,
52
+ ff: values.ff,
53
+ junitPath: values.junit,
54
+ concurrency
55
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumlyzer",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Run every npm workspace's test script, only show output for the ones that fail, and finish with an aggregated pass/fail summary.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/run.mjs CHANGED
@@ -92,33 +92,42 @@ async function collectJunitEntries(results) {
92
92
  return { entries, missing };
93
93
  }
94
94
 
95
- async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir }) {
96
- const results = [];
95
+ async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency }) {
96
+ const results = new Array(workspacesToRun.length);
97
97
  const ciGroup = githubGroupSyntax(process.env);
98
-
99
- for (const [index, wsPath] of workspacesToRun.entries()) {
100
- const name = workspaceName(wsPath);
101
- process.stdout.write(dim(`running ${name}\n`));
102
-
103
- const junitDestPath = junitDir ? path.join(junitDir, `${index}.xml`) : undefined;
104
-
105
- let result;
106
- try {
107
- result = await runWorkspaceScript(root, wsPath, scriptName, junitDestPath);
108
- }
109
- catch (error) {
110
- console.error(red(`✗ ${name}: could not launch "${scriptName}" (${error.message})`));
111
- process.exit(1);
112
- }
113
- results.push(result);
114
- printWorkspaceResult(name, result, ciGroup);
115
-
116
- if (result.exitCode !== 0 && ff) {
117
- break;
98
+ let stopScheduling = false;
99
+ let nextIndex = 0;
100
+
101
+ async function worker() {
102
+ while (!stopScheduling && nextIndex < workspacesToRun.length) {
103
+ const index = nextIndex++;
104
+ const wsPath = workspacesToRun[index];
105
+ const name = workspaceName(wsPath);
106
+ process.stdout.write(dim(`running ${name}\n`));
107
+
108
+ const junitDestPath = junitDir ? path.join(junitDir, `${index}.xml`) : undefined;
109
+
110
+ let result;
111
+ try {
112
+ result = await runWorkspaceScript(root, wsPath, scriptName, junitDestPath);
113
+ }
114
+ catch (error) {
115
+ console.error(red(`✗ ${name}: could not launch "${scriptName}" (${error.message})`));
116
+ process.exit(1);
117
+ }
118
+ results[index] = result;
119
+ printWorkspaceResult(name, result, ciGroup);
120
+
121
+ if (result.exitCode !== 0 && ff) {
122
+ stopScheduling = true;
123
+ }
118
124
  }
119
125
  }
120
126
 
121
- return results;
127
+ const workerCount = Math.max(1, Math.min(concurrency, workspacesToRun.length));
128
+ await Promise.all(Array.from({ length: workerCount }, worker));
129
+
130
+ return results.filter((result) => result !== undefined);
122
131
  }
123
132
 
124
133
  const DEFAULT_JUNIT_FILENAME = "junit.xml";
@@ -147,7 +156,7 @@ async function writeJunitReport(root, junitPath, results) {
147
156
  }
148
157
  }
149
158
 
150
- export async function main({ root, scriptName, ff, junitPath }) {
159
+ export async function main({ root, scriptName, ff, junitPath, concurrency = 1 }) {
151
160
 
152
161
  const { workspaces } = readJson(path.join(root, "package.json"));
153
162
 
@@ -161,7 +170,7 @@ export async function main({ root, scriptName, ff, junitPath }) {
161
170
 
162
171
  let results;
163
172
  try {
164
- results = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir });
173
+ results = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency });
165
174
 
166
175
  if (junitDir) {
167
176
  await writeJunitReport(root, junitPath, results);