sumlyzer 1.0.0 → 1.0.1
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/bin/sumlyzer.mjs +6 -1
- package/package.json +1 -1
- package/src/errors.mjs +3 -3
- package/src/run.mjs +30 -31
package/bin/sumlyzer.mjs
CHANGED
|
@@ -5,6 +5,11 @@ import { availableParallelism } from "node:os";
|
|
|
5
5
|
|
|
6
6
|
import { main } from "../src/run.mjs";
|
|
7
7
|
import { NoWorkspacesError, InvalidPackageJsonError, WorkspaceLaunchError } from "../src/errors.mjs";
|
|
8
|
+
import { red } from "../src/reporter.mjs";
|
|
9
|
+
|
|
10
|
+
function printWorkspaceError(message) {
|
|
11
|
+
console.error(red(message.split("\n").map((line) => `✗ ${line}`).join("\n")));
|
|
12
|
+
}
|
|
8
13
|
|
|
9
14
|
let args;
|
|
10
15
|
try {
|
|
@@ -68,7 +73,7 @@ catch (error) {
|
|
|
68
73
|
console.info(error.message);
|
|
69
74
|
}
|
|
70
75
|
else if (error instanceof InvalidPackageJsonError || error instanceof WorkspaceLaunchError) {
|
|
71
|
-
|
|
76
|
+
printWorkspaceError(error.message);
|
|
72
77
|
}
|
|
73
78
|
else {
|
|
74
79
|
throw error;
|
package/package.json
CHANGED
package/src/errors.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { workspaceName } from "./reporter.mjs";
|
|
2
2
|
|
|
3
3
|
export class NoWorkspacesError extends Error {
|
|
4
4
|
constructor() {
|
|
@@ -9,7 +9,7 @@ export class NoWorkspacesError extends Error {
|
|
|
9
9
|
|
|
10
10
|
export class InvalidPackageJsonError extends Error {
|
|
11
11
|
constructor(entries) {
|
|
12
|
-
super(entries.map(({ wsPath, message }) =>
|
|
12
|
+
super(entries.map(({ wsPath, message }) => `${workspaceName(wsPath)}: could not read its package.json (${message})`).join("\n"));
|
|
13
13
|
this.name = "InvalidPackageJsonError";
|
|
14
14
|
this.entries = entries;
|
|
15
15
|
}
|
|
@@ -17,7 +17,7 @@ export class InvalidPackageJsonError extends Error {
|
|
|
17
17
|
|
|
18
18
|
export class WorkspaceLaunchError extends Error {
|
|
19
19
|
constructor(wsPath, scriptName, cause) {
|
|
20
|
-
super(
|
|
20
|
+
super(`${workspaceName(wsPath)}: could not launch "${scriptName}" (${cause.message})`, { cause });
|
|
21
21
|
this.name = "WorkspaceLaunchError";
|
|
22
22
|
this.wsPath = wsPath;
|
|
23
23
|
this.scriptName = scriptName;
|
package/src/run.mjs
CHANGED
|
@@ -86,7 +86,7 @@ function killWorkspaceChild(child) {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
async function captureWorkspaceOutput(root, wsPath, scriptName, junitDestPath, activeChildren) {
|
|
89
|
+
async function captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath, activeChildren }) {
|
|
90
90
|
const options = {
|
|
91
91
|
cwd: root,
|
|
92
92
|
shell: process.platform === "win32",
|
|
@@ -119,6 +119,30 @@ async function captureWorkspaceOutput(root, wsPath, scriptName, junitDestPath, a
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
function killActiveChildren(activeChildren) {
|
|
123
|
+
for (const child of activeChildren) {
|
|
124
|
+
killWorkspaceChild(child);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function withInterruptHandling(activeChildren, run) {
|
|
129
|
+
function onInterrupt(signal) {
|
|
130
|
+
killActiveChildren(activeChildren);
|
|
131
|
+
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
process.once("SIGINT", onInterrupt);
|
|
135
|
+
process.once("SIGTERM", onInterrupt);
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
return await run();
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
process.off("SIGINT", onInterrupt);
|
|
142
|
+
process.off("SIGTERM", onInterrupt);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
122
146
|
function buildWorkspaceResult(wsPath, junitDestPath, durationMs, { exitCode, stdout, stderr }) {
|
|
123
147
|
const { counts, failingTests, failures } = parseReporterEvents(stdout);
|
|
124
148
|
|
|
@@ -139,9 +163,9 @@ function buildWorkspaceResult(wsPath, junitDestPath, durationMs, { exitCode, std
|
|
|
139
163
|
};
|
|
140
164
|
}
|
|
141
165
|
|
|
142
|
-
async function runWorkspaceScript(root, wsPath, scriptName, junitDestPath, activeChildren) {
|
|
166
|
+
async function runWorkspaceScript({ root, wsPath, scriptName, junitDestPath, activeChildren }) {
|
|
143
167
|
const start = Date.now();
|
|
144
|
-
const captured = await captureWorkspaceOutput(root, wsPath, scriptName, junitDestPath, activeChildren);
|
|
168
|
+
const captured = await captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath, activeChildren });
|
|
145
169
|
return buildWorkspaceResult(wsPath, junitDestPath, Date.now() - start, captured);
|
|
146
170
|
}
|
|
147
171
|
|
|
@@ -171,14 +195,6 @@ async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir,
|
|
|
171
195
|
let stopScheduling = false;
|
|
172
196
|
let nextIndex = 0;
|
|
173
197
|
|
|
174
|
-
// --ff only stops scheduling new workspaces; ones already running are left to
|
|
175
|
-
// finish and report their real result. A launch error is different: it means
|
|
176
|
-
// sumlyzer itself can't go on, so nothing still running should keep spawning.
|
|
177
|
-
function killActiveChildren() {
|
|
178
|
-
for (const child of activeChildren) {
|
|
179
|
-
killWorkspaceChild(child);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
198
|
|
|
183
199
|
async function worker() {
|
|
184
200
|
while (!stopScheduling && nextIndex < workspacesToRun.length) {
|
|
@@ -191,11 +207,11 @@ async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir,
|
|
|
191
207
|
|
|
192
208
|
let result;
|
|
193
209
|
try {
|
|
194
|
-
result = await runWorkspaceScript(root, wsPath, scriptName, junitDestPath, activeChildren);
|
|
210
|
+
result = await runWorkspaceScript({ root, wsPath, scriptName, junitDestPath, activeChildren });
|
|
195
211
|
}
|
|
196
212
|
catch (error) {
|
|
197
213
|
stopScheduling = true;
|
|
198
|
-
killActiveChildren();
|
|
214
|
+
killActiveChildren(activeChildren);
|
|
199
215
|
throw new WorkspaceLaunchError(wsPath, scriptName, error);
|
|
200
216
|
}
|
|
201
217
|
results[index] = result;
|
|
@@ -207,25 +223,8 @@ async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir,
|
|
|
207
223
|
}
|
|
208
224
|
}
|
|
209
225
|
|
|
210
|
-
// Spawned children run detached (their own process group) so a launch error can kill
|
|
211
|
-
// a whole npm subtree via killWorkspaceChild. That isolation means Ctrl-C no longer
|
|
212
|
-
// reaches them for free the way it would in the same group, so handle it explicitly:
|
|
213
|
-
// kill whatever's still running, then exit with the conventional 128+signal code.
|
|
214
|
-
function onInterrupt(signal) {
|
|
215
|
-
killActiveChildren();
|
|
216
|
-
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
217
|
-
}
|
|
218
|
-
process.once("SIGINT", onInterrupt);
|
|
219
|
-
process.once("SIGTERM", onInterrupt);
|
|
220
|
-
|
|
221
226
|
const workerCount = Math.max(1, Math.min(concurrency, workspacesToRun.length));
|
|
222
|
-
|
|
223
|
-
await Promise.all(Array.from({ length: workerCount }, worker));
|
|
224
|
-
}
|
|
225
|
-
finally {
|
|
226
|
-
process.off("SIGINT", onInterrupt);
|
|
227
|
-
process.off("SIGTERM", onInterrupt);
|
|
228
|
-
}
|
|
227
|
+
await withInterruptHandling(activeChildren, () => Promise.all(Array.from({ length: workerCount }, worker)));
|
|
229
228
|
|
|
230
229
|
return results.filter((result) => result !== undefined);
|
|
231
230
|
}
|