sumlyzer 1.5.0 → 1.6.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/CHANGELOG.md +8 -1
- package/README.md +1 -1
- package/bin/sumlyzer.mjs +8 -4
- package/package.json +5 -3
- package/src/changed.mjs +16 -33
- package/src/errors.mjs +4 -6
- package/src/junitReport.mjs +4 -9
- package/src/reporter.mjs +76 -14
- package/src/run.mjs +59 -24
- package/src/schedule.mjs +5 -7
- package/src/testEventReporter.mjs +18 -2
- package/src/watch.mjs +7 -10
- package/src/workspaceProcess.mjs +1 -1
- package/src/workspaces.mjs +14 -14
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.6.0] - 2026-11-27
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- `--changed` also runs the workspaces that depend on a changed one, like `--watch`.
|
|
14
|
+
|
|
9
15
|
## [1.5.0] - 2026-11-26
|
|
10
16
|
|
|
11
17
|
### Added
|
|
@@ -115,7 +121,8 @@ No release notes, see the [diff](https://github.com/ErwanRaulo/sumlyzer/compare/
|
|
|
115
121
|
Earlier versions (`0.1.1` to `0.5.3`) have no release notes, see the
|
|
116
122
|
[tags](https://github.com/ErwanRaulo/sumlyzer/tags).
|
|
117
123
|
|
|
118
|
-
[Unreleased]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.
|
|
124
|
+
[Unreleased]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.6.0...HEAD
|
|
125
|
+
[1.6.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.5.0...v1.6.0
|
|
119
126
|
[1.5.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.4.1...v1.5.0
|
|
120
127
|
[1.4.1]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.4.0...v1.4.1
|
|
121
128
|
[1.4.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.3.1...v1.4.0
|
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ Exit code is `1` if any workspace fails, `0` otherwise — safe to drop straight
|
|
|
68
68
|
- **JUnit** (`--junit <path>`): merges every workspace's `node:test` JUnit output into one file, each `<testsuite>` prefixed with its workspace name. A workspace whose script never produces one is left out, with a warning naming it.
|
|
69
69
|
- **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.
|
|
70
70
|
- **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.
|
|
71
|
-
- **Changed workspaces** (`--changed`): maps changed files to the workspace directory containing them
|
|
71
|
+
- **Changed workspaces** (`--changed`): maps changed files to the workspace directory containing them, then adds the workspaces that depend on those, transitively, like `--watch`. Ref auto-detection: uncommitted changes → diff against `HEAD`; clean tree with upstream → merge-base with upstream; clean tree with no upstream → `HEAD`.
|
|
72
72
|
- **Watch mode** (`--watch`): runs once, then keeps watching the workspaces directories. Re-runs the workspace that changed, plus every workspace of the same project that depends on it, directly or transitively, through `dependencies`/`devDependencies`. `node_modules`, `.git`, `coverage`, and dotfiles are ignored. Stop with `Ctrl+C`. Not compatible with `--junit`.
|
|
73
73
|
- 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.
|
|
74
74
|
|
package/bin/sumlyzer.mjs
CHANGED
|
@@ -6,10 +6,10 @@ import { availableParallelism } from "node:os";
|
|
|
6
6
|
|
|
7
7
|
import { main } from "../src/run.mjs";
|
|
8
8
|
import { NoWorkspacesError, InvalidPackageJsonError, RootPackageJsonError, WorkspaceLaunchError, GitDiffError } from "../src/errors.mjs";
|
|
9
|
-
import
|
|
9
|
+
import * as reporter from "../src/reporter.mjs";
|
|
10
10
|
|
|
11
11
|
function printWorkspaceError(message) {
|
|
12
|
-
console.error(red(message.split("\n").map((line) => `✗ ${line}`).join("\n")));
|
|
12
|
+
console.error(reporter.red(message.split("\n").map((line) => `✗ ${line}`).join("\n")));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
let args;
|
|
@@ -87,7 +87,7 @@ Options:
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
try {
|
|
90
|
-
await main({
|
|
90
|
+
const { failed } = await main({
|
|
91
91
|
root: path.resolve(process.cwd()),
|
|
92
92
|
scriptName: args.script,
|
|
93
93
|
ff: args.ff,
|
|
@@ -95,8 +95,12 @@ try {
|
|
|
95
95
|
concurrency,
|
|
96
96
|
changed: args.changed,
|
|
97
97
|
ref: args.ref,
|
|
98
|
-
watch: args.watch
|
|
98
|
+
watch: args.watch,
|
|
99
|
+
reporter
|
|
99
100
|
});
|
|
101
|
+
if (failed) {
|
|
102
|
+
process.exitCode = 1;
|
|
103
|
+
}
|
|
100
104
|
}
|
|
101
105
|
catch (error) {
|
|
102
106
|
if (error instanceof NoWorkspacesError) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sumlyzer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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": {
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"security-scan": "node scripts/security-scan.mjs",
|
|
24
24
|
"postversion": "git push && git push --tags",
|
|
25
25
|
"prepublishOnly": "npm test",
|
|
26
|
-
"release": "npm publish --dry-run"
|
|
26
|
+
"release": "npm publish --dry-run",
|
|
27
|
+
"typecheck": "tsc -p jsconfig.json"
|
|
27
28
|
},
|
|
28
29
|
"keywords": [
|
|
29
30
|
"npm workspaces test output",
|
|
@@ -56,7 +57,8 @@
|
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@nodesecure/js-x-ray": "^16.2.0",
|
|
58
59
|
"@types/node": "^26.6.10",
|
|
59
|
-
"fast-xml-parser": "^5.12.1"
|
|
60
|
+
"fast-xml-parser": "^5.12.1",
|
|
61
|
+
"typescript": "~6.0.3"
|
|
60
62
|
},
|
|
61
63
|
"dependencies": {
|
|
62
64
|
"glob": "^14.0.6"
|
package/src/changed.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
|
|
3
3
|
import { GitDiffError } from "./errors.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { buildDependentsGraph, expandWithDependents } from "./graph.mjs";
|
|
5
5
|
|
|
6
6
|
function runGit(root, args, ref) {
|
|
7
7
|
const result = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
@@ -67,40 +67,23 @@ export function selectChangedWorkspaces(resolvedWorkspaces, changedFiles) {
|
|
|
67
67
|
return { workspaces, rootChangeFiles };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const resolved = resolveDefaultRef(root);
|
|
76
|
-
console.log(dim(`--changed: no --ref given, comparing against "${resolved.label}" (${resolved.reason})`));
|
|
77
|
-
return resolved;
|
|
70
|
+
export function resolveChangedRef(root, explicitRef) {
|
|
71
|
+
return explicitRef
|
|
72
|
+
? { ref: explicitRef, label: explicitRef, reason: null, autoDetected: false }
|
|
73
|
+
: { ...resolveDefaultRef(root), autoDetected: true };
|
|
78
74
|
}
|
|
79
75
|
|
|
80
|
-
//
|
|
81
|
-
export function
|
|
82
|
-
const { ref, label } = resolveRef(root, explicitRef);
|
|
83
|
-
|
|
76
|
+
// The workspaces changed since `ref`, plus their dependents.
|
|
77
|
+
export function selectAffectedWorkspaces({ root, allPaths, workspaces, ref }) {
|
|
84
78
|
const changedFiles = getChangedFiles(root, ref);
|
|
85
|
-
if (changedFiles.length === 0) {
|
|
86
|
-
console.log(dim(`No changes detected against "${label}".`));
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
79
|
const { workspaces: changedPaths, rootChangeFiles } = selectChangedWorkspaces(allPaths, changedFiles);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (filtered.length === 0) {
|
|
101
|
-
console.log(dim("No eligible workspace changed."));
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return filtered;
|
|
80
|
+
const affectedPaths = expandWithDependents(changedPaths, buildDependentsGraph(root, allPaths));
|
|
81
|
+
const affected = workspaces.filter((workspace) => affectedPaths.has(workspace.path));
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
hasChanges: changedFiles.length > 0,
|
|
85
|
+
rootChangeFiles,
|
|
86
|
+
affected,
|
|
87
|
+
dependents: affected.filter((workspace) => !changedPaths.has(workspace.path)).map((workspace) => workspace.name)
|
|
88
|
+
};
|
|
106
89
|
}
|
package/src/errors.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { workspaceName } from "./reporter.mjs";
|
|
2
|
-
|
|
3
1
|
export class NoWorkspacesError extends Error {
|
|
4
2
|
constructor() {
|
|
5
3
|
super("Your project does not have any workspaces.");
|
|
@@ -18,17 +16,17 @@ export class RootPackageJsonError extends Error {
|
|
|
18
16
|
|
|
19
17
|
export class InvalidPackageJsonError extends Error {
|
|
20
18
|
constructor(entries) {
|
|
21
|
-
super(entries.map(({
|
|
19
|
+
super(entries.map(({ workspace, message }) => `${workspace.name}: could not read its package.json (${message})`).join("\n"));
|
|
22
20
|
this.name = "InvalidPackageJsonError";
|
|
23
21
|
this.entries = entries;
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export class WorkspaceLaunchError extends Error {
|
|
28
|
-
constructor(
|
|
29
|
-
super(`${
|
|
26
|
+
constructor(workspace, scriptName, cause) {
|
|
27
|
+
super(`${workspace.name}: could not launch "${scriptName}" (${cause.message})`, { cause });
|
|
30
28
|
this.name = "WorkspaceLaunchError";
|
|
31
|
-
this.
|
|
29
|
+
this.workspace = workspace;
|
|
32
30
|
this.scriptName = scriptName;
|
|
33
31
|
}
|
|
34
32
|
}
|
package/src/junitReport.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { readFile, stat, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
4
|
import { buildJunitReport } from "./junit.mjs";
|
|
5
|
-
import { red, dim, workspaceName } from "./reporter.mjs";
|
|
6
5
|
|
|
7
6
|
const DEFAULT_JUNIT_FILENAME = "junit.xml";
|
|
8
7
|
|
|
@@ -15,10 +14,10 @@ async function collectJunitEntries(results) {
|
|
|
15
14
|
continue;
|
|
16
15
|
}
|
|
17
16
|
try {
|
|
18
|
-
entries.push({ name:
|
|
17
|
+
entries.push({ name: result.workspace.name, xml: await readFile(result.junitDestPath, "utf8") });
|
|
19
18
|
}
|
|
20
19
|
catch {
|
|
21
|
-
missing.push(
|
|
20
|
+
missing.push(result.workspace.name);
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -36,15 +35,11 @@ export async function writeJunitReport(root, junitPath, results) {
|
|
|
36
35
|
const { entries, missing } = await collectJunitEntries(results);
|
|
37
36
|
const destination = await resolveDestination(root, junitPath);
|
|
38
37
|
|
|
39
|
-
if (missing.length > 0) {
|
|
40
|
-
console.log(dim(`${missing.length} workspace(s) missing from the JUnit report: ${missing.join(", ")}`));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
try {
|
|
44
39
|
await writeFile(destination, buildJunitReport(entries));
|
|
40
|
+
return { destination, missing, error: null };
|
|
45
41
|
}
|
|
46
42
|
catch (error) {
|
|
47
|
-
|
|
48
|
-
process.exitCode = 1;
|
|
43
|
+
return { destination, missing, error };
|
|
49
44
|
}
|
|
50
45
|
}
|
package/src/reporter.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { styleText } from "node:util";
|
|
2
2
|
|
|
3
|
+
import { workspaceName } from "./workspaces.mjs";
|
|
4
|
+
|
|
3
5
|
const green = (str) => styleText("green", str);
|
|
4
6
|
export const red = (str) => styleText("red", str);
|
|
5
7
|
const blue = (str) => styleText("blue", str);
|
|
6
|
-
|
|
8
|
+
const dim = (str) => styleText("dim", str);
|
|
7
9
|
const bold = (str) => styleText("bold", str);
|
|
8
10
|
|
|
9
11
|
export function formatSeconds(ms) {
|
|
@@ -22,10 +24,6 @@ export function githubGroupSyntax(env) {
|
|
|
22
24
|
return null;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export function workspaceName(wsPath) {
|
|
26
|
-
return (wsPath ?? "").replace(/^workspaces[\\/]/, "");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
27
|
export function ciGroupTitle(name, result) {
|
|
30
28
|
const seconds = formatSeconds(result.durationMs);
|
|
31
29
|
const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
|
|
@@ -39,7 +37,7 @@ function printWorkspaceResultCi(name, result, ciGroup) {
|
|
|
39
37
|
process.stdout.write(`${ciGroup.end()}\n`);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
export function printWorkspaceResult(name, result, ciGroup) {
|
|
40
|
+
export function printWorkspaceResult(name, result, ciGroup = githubGroupSyntax(process.env)) {
|
|
43
41
|
if (ciGroup) {
|
|
44
42
|
printWorkspaceResultCi(name, result, ciGroup);
|
|
45
43
|
return;
|
|
@@ -70,7 +68,7 @@ function summaryRow(status, duration, counts) {
|
|
|
70
68
|
function extraCountsFootnote(results, key, label) {
|
|
71
69
|
const entries = results
|
|
72
70
|
.filter(({ counts }) => Number(counts?.[key]) > 0)
|
|
73
|
-
.map(({
|
|
71
|
+
.map(({ workspace, counts }) => `${workspace.name} (${counts[key]})`);
|
|
74
72
|
|
|
75
73
|
return entries.length > 0 ? `${label}: ${entries.join(", ")}` : null;
|
|
76
74
|
}
|
|
@@ -79,11 +77,11 @@ export function printSummary(results, skipped) {
|
|
|
79
77
|
console.log(bold("\nSummary"));
|
|
80
78
|
|
|
81
79
|
const rows = {};
|
|
82
|
-
for (const {
|
|
83
|
-
rows[
|
|
80
|
+
for (const { workspace, exitCode, durationMs, counts } of results) {
|
|
81
|
+
rows[workspace.name] = summaryRow(exitCode === 0 ? "PASS" : "FAIL", formatSeconds(durationMs), counts);
|
|
84
82
|
}
|
|
85
|
-
for (const
|
|
86
|
-
rows[
|
|
83
|
+
for (const workspace of skipped) {
|
|
84
|
+
rows[workspace.name] = summaryRow("SKIPPED", "-", null);
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
console.table(rows);
|
|
@@ -96,7 +94,7 @@ export function printSummary(results, skipped) {
|
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
if (skipped.length > 0) {
|
|
99
|
-
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(
|
|
97
|
+
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map((workspace) => workspace.name).join(", ")}`));
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
100
|
|
|
@@ -110,10 +108,74 @@ export function reportOutcome(results) {
|
|
|
110
108
|
|
|
111
109
|
console.log(red(`${failed.length}/${results.length} workspace(s) failed:`));
|
|
112
110
|
for (const result of failed) {
|
|
113
|
-
console.log(red(` ${
|
|
111
|
+
console.log(red(` ${result.workspace.name}`));
|
|
114
112
|
for (const testName of result.failingTests) {
|
|
115
113
|
console.log(dim(` ✖ ${testName}`));
|
|
116
114
|
}
|
|
117
115
|
}
|
|
118
|
-
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function printWorkspaceStart(name) {
|
|
119
|
+
process.stdout.write(dim(`running ${name}\n`));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function printChangedRef({ label, reason, autoDetected }) {
|
|
123
|
+
if (autoDetected) {
|
|
124
|
+
console.log(dim(`--changed: no --ref given, comparing against "${label}" (${reason})`));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function printChangedSelection({ label, total, selection }) {
|
|
129
|
+
if (!selection.hasChanges) {
|
|
130
|
+
console.log(dim(`No changes detected against "${label}".`));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const { rootChangeFiles, affected, dependents } = selection;
|
|
135
|
+
if (rootChangeFiles.length > 0) {
|
|
136
|
+
const suffix = rootChangeFiles.length > 1 ? ` (+${rootChangeFiles.length - 1} more)` : "";
|
|
137
|
+
console.log(dim(`--changed: "${rootChangeFiles[0]}"${suffix} is outside every workspace, ignoring`));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const dependentsNote = dependents.length > 0 ? ` (incl. dependents: ${dependents.join(", ")})` : "";
|
|
141
|
+
console.log(dim(`--changed: running ${affected.length}/${total} workspace(s) with changes since "${label}"${dependentsNote}`));
|
|
142
|
+
|
|
143
|
+
if (affected.length === 0) {
|
|
144
|
+
console.log(dim("No eligible workspace changed."));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function printJunitReport({ destination, missing, error }) {
|
|
149
|
+
if (missing.length > 0) {
|
|
150
|
+
console.log(dim(`${missing.length} workspace(s) missing from the JUnit report: ${missing.join(", ")}`));
|
|
151
|
+
}
|
|
152
|
+
if (error) {
|
|
153
|
+
console.error(red(`Could not write JUnit report to "${destination}" (${error.message})`));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function printWatchRerun(changedPaths, affected) {
|
|
158
|
+
const changedNames = [...changedPaths].map(workspaceName).join(", ");
|
|
159
|
+
const affectedNames = affected.map((workspace) => workspace.name).join(", ");
|
|
160
|
+
console.log(dim(`\n[watch] change detected in ${changedNames} → re-running: ${affectedNames}\n`));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function printWatchStopping() {
|
|
164
|
+
console.log(dim("\n[watch] stopping.\n"));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function printOwnReporterSkips(scriptName, workspaces) {
|
|
168
|
+
for (const workspace of workspaces) {
|
|
169
|
+
console.log(dim(`⊘ ${workspace.name}: skipped, own --test-reporter detected in its "${scriptName}" script`));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function printNothingToRun(scriptName, ownReporterConflicts) {
|
|
174
|
+
console.log(dim(ownReporterConflicts.length > 0
|
|
175
|
+
? `All workspaces with a "${scriptName}" script were skipped (own --test-reporter detected).`
|
|
176
|
+
: `No workspace has a "${scriptName}" script.`));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function printNoJunitWritten(junitPath) {
|
|
180
|
+
console.log(dim(`--junit: no report written to "${junitPath}" (no workspace ran)`));
|
|
119
181
|
}
|
package/src/run.mjs
CHANGED
|
@@ -2,22 +2,29 @@ import { mkdtemp, rm } from "node:fs/promises";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
import { dim, workspaceName, printSummary, reportOutcome } from "./reporter.mjs";
|
|
6
5
|
import { resolveWorkspacePaths, loadWorkspaces } from "./workspaces.mjs";
|
|
7
6
|
import { runWorkspaces } from "./schedule.mjs";
|
|
8
7
|
import { writeJunitReport } from "./junitReport.mjs";
|
|
9
|
-
import {
|
|
8
|
+
import { resolveChangedRef, selectAffectedWorkspaces } from "./changed.mjs";
|
|
10
9
|
import { watchAndRerun } from "./watch.mjs";
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
// Returns whether the run failed: a workspace failed or the JUnit report couldn't be written.
|
|
12
|
+
async function runOnce({ options, reporter, workspaces, junitPath }) {
|
|
13
13
|
const junitDir = junitPath ? await mkdtemp(path.join(tmpdir(), "sumlyzer-junit-")) : null;
|
|
14
14
|
|
|
15
|
-
let completed, skipped;
|
|
15
|
+
let completed, skipped, junit;
|
|
16
16
|
try {
|
|
17
|
-
({ completed, skipped } = await runWorkspaces({
|
|
17
|
+
({ completed, skipped } = await runWorkspaces({
|
|
18
|
+
...options,
|
|
19
|
+
workspaces,
|
|
20
|
+
junitDir,
|
|
21
|
+
onStart: (workspace) => reporter.printWorkspaceStart(workspace.name),
|
|
22
|
+
onResult: (workspace, result) => reporter.printWorkspaceResult(workspace.name, result)
|
|
23
|
+
}));
|
|
18
24
|
|
|
19
25
|
if (junitDir) {
|
|
20
|
-
await writeJunitReport(options.root, junitPath, completed);
|
|
26
|
+
junit = await writeJunitReport(options.root, junitPath, completed);
|
|
27
|
+
reporter.printJunitReport(junit);
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
finally {
|
|
@@ -26,45 +33,73 @@ async function runOnce(options, workspaces, junitPath) {
|
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
printSummary(completed, skipped);
|
|
30
|
-
reportOutcome(completed);
|
|
36
|
+
reporter.printSummary(completed, skipped);
|
|
37
|
+
reporter.reportOutcome(completed);
|
|
38
|
+
|
|
39
|
+
return completed.some((result) => result.exitCode !== 0) || Boolean(junit?.error);
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
// Returns the workspaces to run, or null when nothing changed.
|
|
43
|
+
function selectChanged({ reporter, root, allPaths, workspaces, ref }) {
|
|
44
|
+
const changedRef = resolveChangedRef(root, ref);
|
|
45
|
+
reporter.printChangedRef(changedRef);
|
|
46
|
+
|
|
47
|
+
const selection = selectAffectedWorkspaces({ root, allPaths, workspaces, ref: changedRef.ref });
|
|
48
|
+
reporter.printChangedSelection({ label: changedRef.label, total: workspaces.length, selection });
|
|
49
|
+
|
|
50
|
+
return selection.affected.length > 0 ? selection.affected : null;
|
|
37
51
|
}
|
|
38
52
|
|
|
39
|
-
|
|
53
|
+
/**
|
|
54
|
+
* @param {object} params
|
|
55
|
+
* @param {string} params.root
|
|
56
|
+
* @param {string} params.scriptName
|
|
57
|
+
* @param {boolean} params.ff
|
|
58
|
+
* @param {string} [params.junitPath]
|
|
59
|
+
* @param {number} [params.concurrency]
|
|
60
|
+
* @param {boolean} [params.changed]
|
|
61
|
+
* @param {string} [params.ref]
|
|
62
|
+
* @param {boolean} [params.watch]
|
|
63
|
+
* @param {typeof import("./reporter.mjs")} params.reporter output for every step
|
|
64
|
+
* @returns {Promise<{ failed: boolean }>}
|
|
65
|
+
*/
|
|
66
|
+
export async function main({ root, scriptName, ff, junitPath, concurrency = 1, changed = false, ref, watch = false, reporter }) {
|
|
40
67
|
const options = { root, scriptName, ff, concurrency };
|
|
41
68
|
|
|
42
69
|
const allPaths = await resolveWorkspacePaths(root);
|
|
43
70
|
const { runnable, ownReporterConflicts } = loadWorkspaces(root, allPaths, scriptName);
|
|
44
71
|
|
|
45
|
-
|
|
46
|
-
|
|
72
|
+
reporter.printOwnReporterSkips(scriptName, ownReporterConflicts);
|
|
47
73
|
if (runnable.length === 0) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
: `No workspace has a "${scriptName}" script.`));
|
|
51
|
-
return;
|
|
74
|
+
reporter.printNothingToRun(scriptName, ownReporterConflicts);
|
|
75
|
+
return { failed: false };
|
|
52
76
|
}
|
|
53
77
|
|
|
54
78
|
let workspaces = runnable;
|
|
55
79
|
if (changed) {
|
|
56
|
-
workspaces =
|
|
80
|
+
workspaces = selectChanged({ reporter, root, allPaths, workspaces, ref });
|
|
57
81
|
if (workspaces === null) {
|
|
58
82
|
if (junitPath) {
|
|
59
|
-
|
|
83
|
+
reporter.printNoJunitWritten(junitPath);
|
|
60
84
|
}
|
|
61
|
-
return;
|
|
85
|
+
return { failed: false };
|
|
62
86
|
}
|
|
63
87
|
}
|
|
64
88
|
|
|
65
|
-
await runOnce(options, workspaces, junitPath);
|
|
89
|
+
let failed = await runOnce({ options, reporter, workspaces, junitPath });
|
|
66
90
|
|
|
67
91
|
if (watch) {
|
|
68
|
-
await watchAndRerun({
|
|
92
|
+
await watchAndRerun({
|
|
93
|
+
root,
|
|
94
|
+
allPaths,
|
|
95
|
+
workspaces,
|
|
96
|
+
rerun: async (affected, changedPaths) => {
|
|
97
|
+
reporter.printWatchRerun(changedPaths, affected);
|
|
98
|
+
failed = (await runOnce({ options, reporter, workspaces: affected, junitPath: undefined })) || failed;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
reporter.printWatchStopping();
|
|
69
102
|
}
|
|
103
|
+
|
|
104
|
+
return { failed };
|
|
70
105
|
}
|
package/src/schedule.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import { dim, githubGroupSyntax, printWorkspaceResult } from "./reporter.mjs";
|
|
4
3
|
import { WorkspaceLaunchError } from "./errors.mjs";
|
|
5
4
|
import { killAll, runWorkspace, withInterruptHandling } from "./workspaceProcess.mjs";
|
|
6
5
|
|
|
@@ -10,7 +9,7 @@ function partitionResults(results, workspaces) {
|
|
|
10
9
|
const skipped = [];
|
|
11
10
|
for (const [index, result] of results.entries()) {
|
|
12
11
|
if (result === undefined) {
|
|
13
|
-
skipped.push(workspaces[index]
|
|
12
|
+
skipped.push(workspaces[index]);
|
|
14
13
|
}
|
|
15
14
|
else {
|
|
16
15
|
completed.push(result);
|
|
@@ -20,9 +19,8 @@ function partitionResults(results, workspaces) {
|
|
|
20
19
|
return { completed, skipped };
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
export async function runWorkspaces({ root, workspaces, scriptName, ff, concurrency, junitDir }) {
|
|
22
|
+
export async function runWorkspaces({ root, workspaces, scriptName, ff, concurrency, junitDir, onStart, onResult }) {
|
|
24
23
|
const results = new Array(workspaces.length);
|
|
25
|
-
const ciGroup = githubGroupSyntax(process.env);
|
|
26
24
|
const activeChildren = new Set();
|
|
27
25
|
let stopScheduling = false;
|
|
28
26
|
let nextIndex = 0;
|
|
@@ -31,7 +29,7 @@ export async function runWorkspaces({ root, workspaces, scriptName, ff, concurre
|
|
|
31
29
|
while (!stopScheduling && nextIndex < workspaces.length) {
|
|
32
30
|
const index = nextIndex++;
|
|
33
31
|
const workspace = workspaces[index];
|
|
34
|
-
|
|
32
|
+
onStart(workspace);
|
|
35
33
|
|
|
36
34
|
const junitDestPath = junitDir ? path.join(junitDir, `${index}.xml`) : undefined;
|
|
37
35
|
|
|
@@ -42,10 +40,10 @@ export async function runWorkspaces({ root, workspaces, scriptName, ff, concurre
|
|
|
42
40
|
catch (error) {
|
|
43
41
|
stopScheduling = true;
|
|
44
42
|
killAll(activeChildren);
|
|
45
|
-
throw new WorkspaceLaunchError(workspace
|
|
43
|
+
throw new WorkspaceLaunchError(workspace, scriptName, error);
|
|
46
44
|
}
|
|
47
45
|
results[index] = result;
|
|
48
|
-
|
|
46
|
+
onResult(workspace, result);
|
|
49
47
|
|
|
50
48
|
if (result.exitCode !== 0 && ff) {
|
|
51
49
|
stopScheduling = true;
|
|
@@ -62,6 +62,22 @@ function pickError(error) {
|
|
|
62
62
|
return { message: error.message ?? String(error), stack: error.cause?.stack ?? error.stack ?? null };
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @param {NodeTestEvent} event
|
|
67
|
+
* @returns {event is NodeTestFailEvent}
|
|
68
|
+
*/
|
|
69
|
+
function isFailEvent(event) {
|
|
70
|
+
return event.type === "test:fail";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {NodeTestEvent} event
|
|
75
|
+
* @returns {event is NodeTestSummaryEvent}
|
|
76
|
+
*/
|
|
77
|
+
function isSummaryEvent(event) {
|
|
78
|
+
return event.type === "test:summary";
|
|
79
|
+
}
|
|
80
|
+
|
|
65
81
|
/**
|
|
66
82
|
* node:test emits a "test:summary" per file plus one aggregate at the end.
|
|
67
83
|
* the aggregate is the only one without a "file" attached.
|
|
@@ -79,7 +95,7 @@ function isAggregateSummary(data) {
|
|
|
79
95
|
*/
|
|
80
96
|
export default async function* testEventReporter(source) {
|
|
81
97
|
for await (const event of source) {
|
|
82
|
-
if (event
|
|
98
|
+
if (isFailEvent(event)) {
|
|
83
99
|
const line = {
|
|
84
100
|
type: "test:fail",
|
|
85
101
|
name: event.data.name,
|
|
@@ -90,7 +106,7 @@ export default async function* testEventReporter(source) {
|
|
|
90
106
|
continue;
|
|
91
107
|
}
|
|
92
108
|
|
|
93
|
-
if (event
|
|
109
|
+
if (isSummaryEvent(event) && isAggregateSummary(event.data)) {
|
|
94
110
|
const { counts, duration_ms: durationMs } = event.data;
|
|
95
111
|
const line = {
|
|
96
112
|
type: "test:summary",
|
package/src/watch.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { watch } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
4
|
import { buildDependentsGraph, expandWithDependents } from "./graph.mjs";
|
|
5
|
-
import { dim, workspaceName } from "./reporter.mjs";
|
|
6
5
|
|
|
7
6
|
const IGNORED_SEGMENTS = new Set(["node_modules", "coverage", ".git"]);
|
|
8
7
|
|
|
@@ -15,7 +14,7 @@ function matchWorkspace(relPath, workspaces) {
|
|
|
15
14
|
return workspaces.find((wsPath) => normalized === wsPath || normalized.startsWith(`${wsPath}/`));
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
function watchWorkspaces({ root, workspaces, onChange, debounceMs = 300
|
|
17
|
+
function watchWorkspaces({ root, workspaces, onChange, isSuppressed, debounceMs = 300 }) {
|
|
19
18
|
const pending = new Set();
|
|
20
19
|
let timer = null;
|
|
21
20
|
|
|
@@ -50,8 +49,11 @@ function watchWorkspaces({ root, workspaces, onChange, debounceMs = 300, isSuppr
|
|
|
50
49
|
// exits; ignoring them briefly stops the workspace from re-triggering itself forever.
|
|
51
50
|
const SETTLE_COOLDOWN_MS = 500;
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Calls `rerun(affected, changedPaths)` on each change, with the changed workspaces
|
|
54
|
+
* and their dependents, until SIGINT/SIGTERM.
|
|
55
|
+
* @returns {Promise<void>}
|
|
56
|
+
*/
|
|
55
57
|
export function watchAndRerun({ root, allPaths, workspaces, rerun }) {
|
|
56
58
|
const dependentsGraph = buildDependentsGraph(root, allPaths);
|
|
57
59
|
const byPath = new Map(workspaces.map((workspace) => [workspace.path, workspace]));
|
|
@@ -65,15 +67,11 @@ export function watchAndRerun({ root, allPaths, workspaces, rerun }) {
|
|
|
65
67
|
return;
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
const changedNames = [...changedPaths].map(workspaceName).join(", ");
|
|
69
|
-
const affectedNames = affected.map((workspace) => workspace.name).join(", ");
|
|
70
|
-
console.log(dim(`\n[watch] change detected in ${changedNames} → re-running: ${affectedNames}\n`));
|
|
71
|
-
|
|
72
70
|
for (const workspace of affected) {
|
|
73
71
|
settling.add(workspace.path);
|
|
74
72
|
}
|
|
75
73
|
try {
|
|
76
|
-
await rerun(affected);
|
|
74
|
+
await rerun(affected, changedPaths);
|
|
77
75
|
}
|
|
78
76
|
finally {
|
|
79
77
|
setTimeout(() => {
|
|
@@ -88,7 +86,6 @@ export function watchAndRerun({ root, allPaths, workspaces, rerun }) {
|
|
|
88
86
|
|
|
89
87
|
return new Promise((resolve) => {
|
|
90
88
|
const stop = () => {
|
|
91
|
-
console.log(dim("\n[watch] stopping.\n"));
|
|
92
89
|
watcher.close();
|
|
93
90
|
resolve();
|
|
94
91
|
};
|
package/src/workspaceProcess.mjs
CHANGED
|
@@ -99,7 +99,7 @@ export async function runWorkspace({ root, workspace, junitDestPath, activeChild
|
|
|
99
99
|
const captured = await runPhases({ root, workspace, junitDestPath, activeChildren });
|
|
100
100
|
|
|
101
101
|
return {
|
|
102
|
-
|
|
102
|
+
workspace,
|
|
103
103
|
exitCode: captured.exitCode,
|
|
104
104
|
durationMs: Date.now() - start,
|
|
105
105
|
junitDestPath,
|
package/src/workspaces.mjs
CHANGED
|
@@ -3,10 +3,13 @@ import path from "node:path";
|
|
|
3
3
|
|
|
4
4
|
import { glob } from "glob";
|
|
5
5
|
|
|
6
|
-
import { workspaceName } from "./reporter.mjs";
|
|
7
6
|
import { runner } from "./runner.mjs";
|
|
8
7
|
import { NoWorkspacesError, InvalidPackageJsonError, RootPackageJsonError } from "./errors.mjs";
|
|
9
8
|
|
|
9
|
+
export function workspaceName(wsPath) {
|
|
10
|
+
return (wsPath ?? "").replace(/^workspaces[\\/]/, "");
|
|
11
|
+
}
|
|
12
|
+
|
|
10
13
|
function readJson(file) {
|
|
11
14
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
12
15
|
}
|
|
@@ -66,24 +69,21 @@ function scriptPhases(scripts, scriptName) {
|
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
function loadWorkspace(root, wsPath, scriptName) {
|
|
69
|
-
|
|
72
|
+
const workspace = { path: wsPath, name: workspaceName(wsPath), pkg: null, phases: [] };
|
|
70
73
|
try {
|
|
71
|
-
pkg = readJson(path.join(root, wsPath, "package.json"));
|
|
74
|
+
workspace.pkg = readJson(path.join(root, wsPath, "package.json"));
|
|
72
75
|
}
|
|
73
76
|
catch (error) {
|
|
74
|
-
return error.code === "ENOENT" ? { kind: "absent" } : { kind: "invalid", message: error.message };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!pkg.scripts?.[scriptName]) {
|
|
78
|
-
return { kind: "absent" };
|
|
77
|
+
return error.code === "ENOENT" ? { kind: "absent", workspace } : { kind: "invalid", workspace, message: error.message };
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return { kind: "ownReporterConflict" };
|
|
80
|
+
if (!workspace.pkg.scripts?.[scriptName]) {
|
|
81
|
+
return { kind: "absent", workspace };
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
|
|
84
|
+
workspace.phases = scriptPhases(workspace.pkg.scripts, scriptName);
|
|
85
|
+
const kind = workspace.phases.some((phase) => runner.hasOwnReporter(phase.command)) ? "ownReporterConflict" : "runnable";
|
|
86
|
+
return { kind, workspace };
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
export function loadWorkspaces(root, wsPaths, scriptName) {
|
|
@@ -97,10 +97,10 @@ export function loadWorkspaces(root, wsPaths, scriptName) {
|
|
|
97
97
|
runnable.push(loaded.workspace);
|
|
98
98
|
}
|
|
99
99
|
else if (loaded.kind === "ownReporterConflict") {
|
|
100
|
-
ownReporterConflicts.push(
|
|
100
|
+
ownReporterConflicts.push(loaded.workspace);
|
|
101
101
|
}
|
|
102
102
|
else if (loaded.kind === "invalid") {
|
|
103
|
-
invalid.push({
|
|
103
|
+
invalid.push({ workspace: loaded.workspace, message: loaded.message });
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|