sumlyzer 1.3.1 → 1.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 +5 -1
- package/bin/sumlyzer.mjs +11 -1
- package/package.json +1 -1
- package/src/graph.mjs +60 -0
- package/src/run.mjs +81 -17
- package/src/testEventReporter.mjs +3 -7
- package/src/watch.mjs +44 -0
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ Run from the root of an npm workspaces project.
|
|
|
43
43
|
| `--changed` | off | only run workspaces with changed files |
|
|
44
44
|
| `--junit <path>` | off | write an aggregated JUnit XML report |
|
|
45
45
|
| `--ref <ref>` | auto-detect | git ref to diff against for `--changed` |
|
|
46
|
+
| `-w, --watch` | off | re-run on file change (can't be combined with `--junit`) |
|
|
46
47
|
| `-h, --help` | | print usage |
|
|
47
48
|
|
|
48
49
|
Exit code is `1` if any workspace fails, `0` otherwise — safe to drop straight into CI.
|
|
@@ -65,6 +66,7 @@ Exit code is `1` if any workspace fails, `0` otherwise — safe to drop straight
|
|
|
65
66
|
- **GitHub Actions**: on `GITHUB_ACTIONS=true`, each workspace's output is auto-wrapped in a collapsible `::group::` block. No other CI provider has folding support yet.
|
|
66
67
|
- **Concurrency** (`--concurrency <n>`): workspaces finish in whatever order they complete, so output interleaves. With `--ff`, only workspaces that haven't started yet are skipped — in-flight ones run to completion.
|
|
67
68
|
- **Changed workspaces** (`--changed`): maps changed files to the workspace directory containing them. Ref auto-detection: uncommitted changes → diff against `HEAD`; clean tree with upstream → merge-base with upstream; clean tree with no upstream → `HEAD`.
|
|
69
|
+
- **Watch mode** (`--watch`): runs once, then keeps watching the workspaces directories. Re-runs the workspace that changed and Whatever else, in the same project, declares it as a `dependencies`/`devDependencies` entry . `node_modules`, `.git`, `coverage`, and dotfiles are ignored. Stop with `Ctrl+C`. Not compatible with `--junit`.
|
|
68
70
|
- Own `--test-reporter` in a workspace's script is detected ahead of time and that workspace is skipped, to avoid colliding with sumlyzer's own reporter.
|
|
69
71
|
|
|
70
72
|
npm doesn't have native fail-fast on `--workspaces` yet — discussed in
|
|
@@ -75,7 +77,9 @@ Sumlyzer's `--ff` gets you there in the meantime.
|
|
|
75
77
|
|
|
76
78
|
## Roadmap
|
|
77
79
|
|
|
78
|
-
**Watch mode
|
|
80
|
+
**Watch mode**: walk the workspace dependency graph so a change in one workspace also re-runs the ones that depend on it.
|
|
81
|
+
|
|
82
|
+
**MCP server**: allow LLM agent to run the fail fast mode on any project organized with npm workspaces.
|
|
79
83
|
|
|
80
84
|
## Contributing
|
|
81
85
|
|
package/bin/sumlyzer.mjs
CHANGED
|
@@ -21,6 +21,7 @@ try {
|
|
|
21
21
|
concurrency: { type: "string", short: "c", default: "1" },
|
|
22
22
|
changed: { type: "boolean", default: false },
|
|
23
23
|
ref: { type: "string" },
|
|
24
|
+
watch: { type: "boolean", short: "w", default: false },
|
|
24
25
|
help: { type: "boolean", short: "h", default: false }
|
|
25
26
|
}
|
|
26
27
|
}));
|
|
@@ -49,6 +50,11 @@ if (args.ref && !args.changed) {
|
|
|
49
50
|
process.exit(1);
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
if (args.watch && args.junit) {
|
|
54
|
+
console.info(`--watch and --junit can't be combined. Run "sumlyzer --help" for usage.`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
if (args.help) {
|
|
53
59
|
console.log(`sumlyzer [options]
|
|
54
60
|
|
|
@@ -63,6 +69,9 @@ Options:
|
|
|
63
69
|
-c, --concurrency <n> run up to <n> workspaces at once (default: 1)
|
|
64
70
|
--changed only run workspaces with changes (git ref auto-detected, see --ref)
|
|
65
71
|
--ref <ref> git ref to diff against for --changed (default: auto-detect)
|
|
72
|
+
-w, --watch re-run on file change, only for changed workspaces
|
|
73
|
+
and the ones that depend on them (can't be combined
|
|
74
|
+
with --junit)
|
|
66
75
|
-h, --help show this help
|
|
67
76
|
`);
|
|
68
77
|
process.exit(0);
|
|
@@ -76,7 +85,8 @@ try {
|
|
|
76
85
|
junitPath: args.junit,
|
|
77
86
|
concurrency,
|
|
78
87
|
changed: args.changed,
|
|
79
|
-
ref: args.ref
|
|
88
|
+
ref: args.ref,
|
|
89
|
+
watch: args.watch
|
|
80
90
|
});
|
|
81
91
|
}
|
|
82
92
|
catch (error) {
|
package/package.json
CHANGED
package/src/graph.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
function readJson(file) {
|
|
5
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function buildDependentsGraph(root, workspaces) {
|
|
9
|
+
const nameToPath = new Map();
|
|
10
|
+
const depsByPath = new Map();
|
|
11
|
+
|
|
12
|
+
for (const wsPath of workspaces) {
|
|
13
|
+
let pkg;
|
|
14
|
+
try {
|
|
15
|
+
pkg = readJson(path.join(root, wsPath, "package.json"));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (pkg.name) {
|
|
22
|
+
nameToPath.set(pkg.name, wsPath);
|
|
23
|
+
}
|
|
24
|
+
depsByPath.set(wsPath, { ...pkg.dependencies, ...pkg.devDependencies });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const dependents = new Map(workspaces.map((wsPath) => [wsPath, new Set()]));
|
|
28
|
+
|
|
29
|
+
for (const [wsPath, deps] of depsByPath) {
|
|
30
|
+
for (const depName of Object.keys(deps)) {
|
|
31
|
+
const depPath = nameToPath.get(depName);
|
|
32
|
+
if (depPath && depPath !== wsPath) {
|
|
33
|
+
dependents.get(depPath).add(wsPath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return dependents;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function expandWithDependents(changedPaths, dependentsGraph) {
|
|
42
|
+
const result = new Set();
|
|
43
|
+
const queue = [...changedPaths];
|
|
44
|
+
|
|
45
|
+
while (queue.length > 0) {
|
|
46
|
+
const wsPath = queue.pop();
|
|
47
|
+
if (result.has(wsPath)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
result.add(wsPath);
|
|
51
|
+
|
|
52
|
+
for (const dependent of dependentsGraph.get(wsPath) ?? []) {
|
|
53
|
+
if (!result.has(dependent)) {
|
|
54
|
+
queue.push(dependent);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|
package/src/run.mjs
CHANGED
|
@@ -7,6 +7,8 @@ import path from "node:path";
|
|
|
7
7
|
import { glob } from "glob";
|
|
8
8
|
|
|
9
9
|
import { buildJunitReport } from "./junit.mjs";
|
|
10
|
+
import { buildDependentsGraph, expandWithDependents } from "./graph.mjs";
|
|
11
|
+
import { watchWorkspaces } from "./watch.mjs";
|
|
10
12
|
import { red, dim, workspaceName, githubGroupSyntax, printWorkspaceResult, printSummary, reportOutcome } from "./reporter.mjs";
|
|
11
13
|
import { NoWorkspacesError, InvalidPackageJsonError, WorkspaceLaunchError } from "./errors.mjs";
|
|
12
14
|
import { hasOwnReporter, prepareEnv, parseResult } from "./runners/nodeTest.mjs";
|
|
@@ -389,7 +391,82 @@ async function writeJunitReport(root, junitPath, results) {
|
|
|
389
391
|
}
|
|
390
392
|
}
|
|
391
393
|
|
|
392
|
-
|
|
394
|
+
async function runOnce({ root, workspacesToRun, scriptName, scriptCommands, ff, junitPath, concurrency }) {
|
|
395
|
+
const junitDir = junitPath ? await mkdtemp(path.join(tmpdir(), "sumlyzer-junit-")) : null;
|
|
396
|
+
|
|
397
|
+
let completed, skipped;
|
|
398
|
+
try {
|
|
399
|
+
({ completed, skipped } = await runWorkspaces({ root, workspacesToRun, scriptName, scriptCommands, ff, junitDir, concurrency }));
|
|
400
|
+
|
|
401
|
+
if (junitDir) {
|
|
402
|
+
await writeJunitReport(root, junitPath, completed);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
if (junitDir) {
|
|
407
|
+
await rm(junitDir, { recursive: true, force: true });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
printSummary(completed, skipped);
|
|
412
|
+
reportOutcome(completed);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// A workspace's own test run can write files inside itself (e.g. coverage, though that's
|
|
416
|
+
// already ignored) shortly after it exits. Without this, those trailing writes get picked
|
|
417
|
+
// up as a fresh change and the workspace re-runs itself indefinitely.
|
|
418
|
+
const SETTLE_COOLDOWN_MS = 500;
|
|
419
|
+
|
|
420
|
+
async function handleWatchChange({ changedPaths, dependentsGraph, settling, workspacesToRun, root, scriptName, scriptCommands, ff, concurrency }) {
|
|
421
|
+
const affected = [...expandWithDependents(changedPaths, dependentsGraph)]
|
|
422
|
+
.filter((wsPath) => workspacesToRun.includes(wsPath));
|
|
423
|
+
|
|
424
|
+
if (affected.length === 0) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const changedNames = [...changedPaths].map(workspaceName).join(", ");
|
|
429
|
+
const affectedNames = affected.map(workspaceName).join(", ");
|
|
430
|
+
console.log(dim(`\n[watch] change detected in ${changedNames} → re-running: ${affectedNames}\n`));
|
|
431
|
+
|
|
432
|
+
for (const wsPath of affected) {
|
|
433
|
+
settling.add(wsPath);
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
await runOnce({ root, workspacesToRun: affected, scriptName, scriptCommands, ff, junitPath: undefined, concurrency });
|
|
437
|
+
}
|
|
438
|
+
finally {
|
|
439
|
+
setTimeout(() => {
|
|
440
|
+
for (const wsPath of affected) {
|
|
441
|
+
settling.delete(wsPath);
|
|
442
|
+
}
|
|
443
|
+
}, SETTLE_COOLDOWN_MS).unref();
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function runWatchMode({ root, workspaces, workspacesToRun, scriptName, scriptCommands, ff, concurrency }) {
|
|
448
|
+
const dependentsGraph = buildDependentsGraph(root, workspaces);
|
|
449
|
+
const settling = new Set();
|
|
450
|
+
|
|
451
|
+
const watcher = watchWorkspaces({
|
|
452
|
+
root,
|
|
453
|
+
workspaces,
|
|
454
|
+
isSuppressed: (wsPath) => settling.has(wsPath),
|
|
455
|
+
onChange: (changedPaths) => handleWatchChange({ changedPaths, dependentsGraph, settling, workspacesToRun, root, scriptName, scriptCommands, ff, concurrency })
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
return new Promise((resolve) => {
|
|
459
|
+
const stop = () => {
|
|
460
|
+
console.log(dim("\n[watch] stopping.\n"));
|
|
461
|
+
watcher.close();
|
|
462
|
+
resolve();
|
|
463
|
+
};
|
|
464
|
+
process.once("SIGINT", stop);
|
|
465
|
+
process.once("SIGTERM", stop);
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export async function main({ root, scriptName, ff, junitPath, concurrency = 1, changed = false, ref, watch = false }) {
|
|
393
470
|
|
|
394
471
|
const { workspaces } = readJson(path.join(root, "package.json"));
|
|
395
472
|
|
|
@@ -427,22 +504,9 @@ export async function main({ root, scriptName, ff, junitPath, concurrency = 1, c
|
|
|
427
504
|
}
|
|
428
505
|
}
|
|
429
506
|
|
|
430
|
-
|
|
507
|
+
await runOnce({ root, workspacesToRun: finalWorkspacesToRun, scriptName, scriptCommands, ff, junitPath, concurrency });
|
|
431
508
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
({ completed, skipped } = await runWorkspaces({ root, workspacesToRun: finalWorkspacesToRun, scriptName, scriptCommands, ff, junitDir, concurrency }));
|
|
435
|
-
|
|
436
|
-
if (junitDir) {
|
|
437
|
-
await writeJunitReport(root, junitPath, completed);
|
|
438
|
-
}
|
|
509
|
+
if (watch) {
|
|
510
|
+
await runWatchMode({ root, workspaces: resolvedWorkspaces, workspacesToRun: finalWorkspacesToRun, scriptName, scriptCommands, ff, concurrency });
|
|
439
511
|
}
|
|
440
|
-
finally {
|
|
441
|
-
if (junitDir) {
|
|
442
|
-
await rm(junitDir, { recursive: true, force: true });
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
printSummary(completed, skipped);
|
|
447
|
-
reportOutcome(completed);
|
|
448
512
|
}
|
|
@@ -63,7 +63,7 @@ function pickError(error) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
* node:test emits a "test:summary" per file plus one aggregate at the end
|
|
66
|
+
* node:test emits a "test:summary" per file plus one aggregate at the end.
|
|
67
67
|
* the aggregate is the only one without a "file" attached.
|
|
68
68
|
* @param {NodeTestSummaryEvent["data"]} data
|
|
69
69
|
* @returns {boolean}
|
|
@@ -73,9 +73,7 @@ function isAggregateSummary(data) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* The node:test custom reporter
|
|
77
|
-
* spawned workspace's process; only test:fail and the aggregate test:summary are kept,
|
|
78
|
-
* each re-emitted as one JSON line on stdout for the parent process to read back.
|
|
76
|
+
* The node:test custom reporter. Runs inside the spawned workspace's process.
|
|
79
77
|
* @param {AsyncIterable<NodeTestEvent>} source
|
|
80
78
|
* @returns {AsyncGenerator<string>}
|
|
81
79
|
*/
|
|
@@ -113,9 +111,7 @@ export default async function* testEventReporter(source) {
|
|
|
113
111
|
|
|
114
112
|
/**
|
|
115
113
|
* Parses the JSON lines emitted by {@link testEventReporter} back out of a workspace's
|
|
116
|
-
* captured stdout, running in the parent process.
|
|
117
|
-
* or a workspace script that never runs node:test at all) are silently skipped rather than
|
|
118
|
-
* treated as a parsing error.
|
|
114
|
+
* captured stdout, running in the parent process.
|
|
119
115
|
* @param {string} output
|
|
120
116
|
* @returns {{ counts: ReportedCounts | null, failingTests: string[], failures: ReportedFailure[] }}
|
|
121
117
|
*/
|
package/src/watch.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { watch } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
const IGNORED_SEGMENTS = new Set(["node_modules", "coverage", ".git"]);
|
|
5
|
+
|
|
6
|
+
function isIgnored(relPath) {
|
|
7
|
+
return relPath.split(path.sep).some((segment) => IGNORED_SEGMENTS.has(segment) || segment.startsWith("."));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function matchWorkspace(relPath, workspaces) {
|
|
11
|
+
const normalized = relPath.split(path.sep).join("/");
|
|
12
|
+
return workspaces.find((wsPath) => normalized === wsPath || normalized.startsWith(`${wsPath}/`));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function watchWorkspaces({ root, workspaces, onChange, debounceMs = 300, isSuppressed = () => false }) {
|
|
16
|
+
const pending = new Set();
|
|
17
|
+
let timer = null;
|
|
18
|
+
|
|
19
|
+
const watcher = watch(root, { recursive: true }, (eventType, filename) => {
|
|
20
|
+
if (!filename || isIgnored(filename)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const wsPath = matchWorkspace(filename, workspaces);
|
|
25
|
+
if (!wsPath || isSuppressed(wsPath)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
pending.add(wsPath);
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
timer = setTimeout(() => {
|
|
32
|
+
const changed = new Set(pending);
|
|
33
|
+
pending.clear();
|
|
34
|
+
onChange(changed);
|
|
35
|
+
}, debounceMs);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
close() {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
watcher.close();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|