sumlyzer 1.4.0 → 1.5.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 +128 -0
- package/README.md +11 -6
- package/bin/sumlyzer.mjs +12 -3
- package/package.json +13 -7
- package/src/changed.mjs +42 -3
- package/src/errors.mjs +9 -0
- package/src/junitReport.mjs +50 -0
- package/src/npmScriptEnv.mjs +43 -0
- package/src/pathEnv.mjs +12 -0
- package/src/reporter.mjs +3 -3
- package/src/run.mjs +23 -465
- package/src/runner.mjs +2 -0
- package/src/runners/nodeTest.mjs +9 -5
- package/src/schedule.mjs +60 -0
- package/src/scriptEnv.mjs +35 -0
- package/src/watch.mjs +55 -1
- package/src/workspaceProcess.mjs +108 -0
- package/src/workspaces.mjs +112 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based
|
|
4
|
+
on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
|
+
follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [1.5.0] - 2026-11-26
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `-v, --version` prints the installed version.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Scripts and their `pre`/`post` hooks get the same `npm_package_*` and
|
|
18
|
+
`npm_lifecycle_*` variables as with `npm run`.
|
|
19
|
+
- A missing or invalid root `package.json` prints a one-line error instead
|
|
20
|
+
of a stack trace.
|
|
21
|
+
- Windows: `node:test` workspaces crashed, `--junit` paths lost their
|
|
22
|
+
separators, `--changed`/`--watch` matched no workspace.
|
|
23
|
+
|
|
24
|
+
## [1.4.1] - 2026-11-25
|
|
25
|
+
|
|
26
|
+
### Security
|
|
27
|
+
|
|
28
|
+
- `--ref` can no longer be parsed by `git diff` as an option or a pathspec.
|
|
29
|
+
A value such as `--ref=--output=<file>` used to make git create or
|
|
30
|
+
overwrite `<file>`, and a ref matching a file name was silently treated as
|
|
31
|
+
a path ([#46](https://github.com/ErwanRaulo/sumlyzer/pull/46)).
|
|
32
|
+
- Bump `glob` to `^14.0.6` (runtime) and dev dependencies to clear the
|
|
33
|
+
`glob`, `minimatch`, `brace-expansion` and `fast-xml-parser` advisories
|
|
34
|
+
reported by `npm audit` ([#43](https://github.com/ErwanRaulo/sumlyzer/pull/43)).
|
|
35
|
+
|
|
36
|
+
### Documentation
|
|
37
|
+
|
|
38
|
+
- Add this changelog, a CI badge and a security section to the README.
|
|
39
|
+
- Fix outdated statements in `SECURITY.md` and `CONTRIBUTING.md`.
|
|
40
|
+
|
|
41
|
+
## [1.4.0] - 2026-09-08
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- `--watch` mode: re-runs changed workspaces and the workspaces that depend
|
|
46
|
+
on them ([#26](https://github.com/ErwanRaulo/sumlyzer/pull/26)).
|
|
47
|
+
|
|
48
|
+
## [1.3.1]
|
|
49
|
+
|
|
50
|
+
No release notes, see the [diff](https://github.com/ErwanRaulo/sumlyzer/compare/v1.3.0...v1.3.1).
|
|
51
|
+
|
|
52
|
+
## [1.3.0] - 2026-09-03
|
|
53
|
+
|
|
54
|
+
### Added
|
|
55
|
+
|
|
56
|
+
- `--changed` / `--ref`: only run workspaces with changes, via git diff
|
|
57
|
+
([#18](https://github.com/ErwanRaulo/sumlyzer/pull/18)).
|
|
58
|
+
- Support npm `pre`/`post` lifecycle hooks of the test script
|
|
59
|
+
([#20](https://github.com/ErwanRaulo/sumlyzer/pull/20)).
|
|
60
|
+
|
|
61
|
+
### Changed
|
|
62
|
+
|
|
63
|
+
- Spawn fewer processes per workspace ([#19](https://github.com/ErwanRaulo/sumlyzer/pull/19)).
|
|
64
|
+
|
|
65
|
+
## [1.2.0] - 2026-08-20
|
|
66
|
+
|
|
67
|
+
### Changed
|
|
68
|
+
|
|
69
|
+
- Skip/todo/cancelled counts moved to a footnote; duplicate duration and
|
|
70
|
+
test-count output removed.
|
|
71
|
+
- Internal refactor of workspace listing, output capture and run loop.
|
|
72
|
+
|
|
73
|
+
### Fixed
|
|
74
|
+
|
|
75
|
+
- README example of sumlyzer's output.
|
|
76
|
+
|
|
77
|
+
## [1.1.0] - 2026-08-19
|
|
78
|
+
|
|
79
|
+
### Added
|
|
80
|
+
|
|
81
|
+
- Resolve `workspaces` glob patterns.
|
|
82
|
+
- Clear message when no workspace is eligible.
|
|
83
|
+
|
|
84
|
+
### Changed
|
|
85
|
+
|
|
86
|
+
- Runner logic decoupled from `node:test`.
|
|
87
|
+
- More reliable skipped-workspace count.
|
|
88
|
+
|
|
89
|
+
## [1.0.1] - 2026-08-11
|
|
90
|
+
|
|
91
|
+
### Added
|
|
92
|
+
|
|
93
|
+
- Own `node:test` reporter; workspaces using a custom reporter are detected.
|
|
94
|
+
- All workspaces with an invalid `package.json` are listed at once.
|
|
95
|
+
|
|
96
|
+
### Changed
|
|
97
|
+
|
|
98
|
+
- Output read as stream chunks instead of being buffered in memory.
|
|
99
|
+
|
|
100
|
+
### Fixed
|
|
101
|
+
|
|
102
|
+
- Child processes are cleaned up properly instead of being killed mid-flight.
|
|
103
|
+
|
|
104
|
+
## [1.0.0]
|
|
105
|
+
|
|
106
|
+
No release notes, see the [diff](https://github.com/ErwanRaulo/sumlyzer/compare/v0.6.0...v1.0.0).
|
|
107
|
+
|
|
108
|
+
## [0.6.0] - 2026-08-05
|
|
109
|
+
|
|
110
|
+
### Changed
|
|
111
|
+
|
|
112
|
+
- `--concurrency` is clamped to the OS available parallelism.
|
|
113
|
+
- Fewer regex instances and less string splitting when parsing large outputs.
|
|
114
|
+
|
|
115
|
+
Earlier versions (`0.1.1` to `0.5.3`) have no release notes, see the
|
|
116
|
+
[tags](https://github.com/ErwanRaulo/sumlyzer/tags).
|
|
117
|
+
|
|
118
|
+
[Unreleased]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.5.0...HEAD
|
|
119
|
+
[1.5.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.4.1...v1.5.0
|
|
120
|
+
[1.4.1]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.4.0...v1.4.1
|
|
121
|
+
[1.4.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.3.1...v1.4.0
|
|
122
|
+
[1.3.1]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.3.0...v1.3.1
|
|
123
|
+
[1.3.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.2.0...v1.3.0
|
|
124
|
+
[1.2.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.1.0...v1.2.0
|
|
125
|
+
[1.1.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.0.1...v1.1.0
|
|
126
|
+
[1.0.1]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.0.0...v1.0.1
|
|
127
|
+
[1.0.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v0.6.0...v1.0.0
|
|
128
|
+
[0.6.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v0.5.3...v0.6.0
|
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
<h1 align="center">Sumlyzer</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
+
<a href="https://github.com/ErwanRaulo/sumlyzer/actions/workflows/ci.yml"><img src="https://github.com/ErwanRaulo/sumlyzer/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI" /></a>
|
|
8
9
|
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/npm/v/sumlyzer.svg" alt="npm version" /></a>
|
|
9
10
|
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/npm/dm/sumlyzer.svg" alt="npm downloads" /></a>
|
|
10
11
|
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/node/v/sumlyzer.svg" alt="node engine" /></a>
|
|
@@ -19,7 +20,8 @@ output. Sumlyzer fixes that, and runs workspaces concurrently too (~3.5x
|
|
|
19
20
|
faster, see [Benchmark](#benchmark)).
|
|
20
21
|
|
|
21
22
|
Scope: **npm workspaces** running **`node:test`** only, for now. No
|
|
22
|
-
pnpm/yarn, no Jest/Vitest/Mocha.
|
|
23
|
+
pnpm/yarn, no Jest/Vitest/Mocha. Tested on Linux, macOS and Windows, with
|
|
24
|
+
Node.js 22, 24 and 26.
|
|
23
25
|
|
|
24
26
|
## Install
|
|
25
27
|
|
|
@@ -44,6 +46,7 @@ Run from the root of an npm workspaces project.
|
|
|
44
46
|
| `--junit <path>` | off | write an aggregated JUnit XML report |
|
|
45
47
|
| `--ref <ref>` | auto-detect | git ref to diff against for `--changed` |
|
|
46
48
|
| `-w, --watch` | off | re-run on file change (can't be combined with `--junit`) |
|
|
49
|
+
| `-v, --version` | | print the sumlyzer version |
|
|
47
50
|
| `-h, --help` | | print usage |
|
|
48
51
|
|
|
49
52
|
Exit code is `1` if any workspace fails, `0` otherwise — safe to drop straight into CI.
|
|
@@ -66,7 +69,7 @@ Exit code is `1` if any workspace fails, `0` otherwise — safe to drop straight
|
|
|
66
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.
|
|
67
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.
|
|
68
71
|
- **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
|
|
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`.
|
|
70
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.
|
|
71
74
|
|
|
72
75
|
npm doesn't have native fail-fast on `--workspaces` yet — discussed in
|
|
@@ -77,13 +80,15 @@ Sumlyzer's `--ff` gets you there in the meantime.
|
|
|
77
80
|
|
|
78
81
|
## Roadmap
|
|
79
82
|
|
|
80
|
-
**
|
|
81
|
-
|
|
82
|
-
**MCP server**: allow LLM agent to run the fail fast mode on any project organized with npm workspaces.
|
|
83
|
+
**MCP server**: allow LLM agents to run the fail fast mode on any project organized with npm workspaces.
|
|
83
84
|
|
|
84
85
|
## Contributing
|
|
85
86
|
|
|
86
|
-
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
87
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md). Release history is in [CHANGELOG.md](./CHANGELOG.md).
|
|
88
|
+
|
|
89
|
+
## Security
|
|
90
|
+
|
|
91
|
+
Please report vulnerabilities privately, see [SECURITY.md](./SECURITY.md).
|
|
87
92
|
|
|
88
93
|
## License
|
|
89
94
|
|
package/bin/sumlyzer.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
2
3
|
import { parseArgs } from "node:util";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { availableParallelism } from "node:os";
|
|
5
6
|
|
|
6
7
|
import { main } from "../src/run.mjs";
|
|
7
|
-
import { NoWorkspacesError, InvalidPackageJsonError, WorkspaceLaunchError, GitDiffError } from "../src/errors.mjs";
|
|
8
|
+
import { NoWorkspacesError, InvalidPackageJsonError, RootPackageJsonError, WorkspaceLaunchError, GitDiffError } from "../src/errors.mjs";
|
|
8
9
|
import { red } from "../src/reporter.mjs";
|
|
9
10
|
|
|
10
11
|
function printWorkspaceError(message) {
|
|
@@ -22,7 +23,8 @@ try {
|
|
|
22
23
|
changed: { type: "boolean", default: false },
|
|
23
24
|
ref: { type: "string" },
|
|
24
25
|
watch: { type: "boolean", short: "w", default: false },
|
|
25
|
-
help: { type: "boolean", short: "h", default: false }
|
|
26
|
+
help: { type: "boolean", short: "h", default: false },
|
|
27
|
+
version: { type: "boolean", short: "v", default: false }
|
|
26
28
|
}
|
|
27
29
|
}));
|
|
28
30
|
}
|
|
@@ -33,6 +35,12 @@ catch (error) {
|
|
|
33
35
|
process.exit(1);
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
if (args.version) {
|
|
39
|
+
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
40
|
+
console.log(version);
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
let concurrency = Number.parseInt(args.concurrency, 10);
|
|
37
45
|
if (!Number.isInteger(concurrency) || concurrency < 1 || String(concurrency) !== args.concurrency) {
|
|
38
46
|
console.info(`--concurrency must be a positive integer, got "${args.concurrency}". Run "sumlyzer --help" for usage.`);
|
|
@@ -72,6 +80,7 @@ Options:
|
|
|
72
80
|
-w, --watch re-run on file change, only for changed workspaces
|
|
73
81
|
and the ones that depend on them (can't be combined
|
|
74
82
|
with --junit)
|
|
83
|
+
-v, --version print the sumlyzer version
|
|
75
84
|
-h, --help show this help
|
|
76
85
|
`);
|
|
77
86
|
process.exit(0);
|
|
@@ -93,7 +102,7 @@ catch (error) {
|
|
|
93
102
|
if (error instanceof NoWorkspacesError) {
|
|
94
103
|
console.info(error.message);
|
|
95
104
|
}
|
|
96
|
-
else if (error instanceof InvalidPackageJsonError || error instanceof WorkspaceLaunchError || error instanceof GitDiffError) {
|
|
105
|
+
else if (error instanceof RootPackageJsonError || error instanceof InvalidPackageJsonError || error instanceof WorkspaceLaunchError || error instanceof GitDiffError) {
|
|
97
106
|
printWorkspaceError(error.message);
|
|
98
107
|
}
|
|
99
108
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sumlyzer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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": {
|
|
@@ -10,15 +10,16 @@
|
|
|
10
10
|
"bin",
|
|
11
11
|
"src",
|
|
12
12
|
"README.md",
|
|
13
|
+
"CHANGELOG.md",
|
|
13
14
|
"LICENSE"
|
|
14
15
|
],
|
|
15
16
|
"engines": {
|
|
16
17
|
"node": ">=22.0.0"
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
19
|
-
"test": "node --test \"./test/*.spec.mjs\"",
|
|
20
|
+
"test": "node --test --test-timeout=60000 \"./test/*.spec.mjs\"",
|
|
20
21
|
"pretest:coverage": "mkdir -p coverage",
|
|
21
|
-
"test:coverage": "node --no-warnings --experimental-test-coverage --test-coverage-lines=95 --test-coverage-functions=95 --test-coverage-branches=85 --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"./test/*.spec.mjs\"",
|
|
22
|
+
"test:coverage": "node --no-warnings --experimental-test-coverage --test-coverage-lines=95 --test-coverage-functions=95 --test-coverage-branches=85 --test-timeout=60000 --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test \"./test/*.spec.mjs\"",
|
|
22
23
|
"security-scan": "node scripts/security-scan.mjs",
|
|
23
24
|
"postversion": "git push && git push --tags",
|
|
24
25
|
"prepublishOnly": "npm test",
|
|
@@ -53,11 +54,16 @@
|
|
|
53
54
|
},
|
|
54
55
|
"homepage": "https://github.com/ErwanRaulo/sumlyzer#readme",
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@nodesecure/js-x-ray": "^16.
|
|
57
|
-
"@types/node": "^26.
|
|
58
|
-
"fast-xml-parser": "^5.
|
|
57
|
+
"@nodesecure/js-x-ray": "^16.2.0",
|
|
58
|
+
"@types/node": "^26.6.10",
|
|
59
|
+
"fast-xml-parser": "^5.12.1"
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
61
|
-
"glob": "^
|
|
62
|
+
"glob": "^14.0.6"
|
|
63
|
+
},
|
|
64
|
+
"overrides": {
|
|
65
|
+
"@typescript-eslint/typescript-estree": {
|
|
66
|
+
"minimatch": "^11.0.1"
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
}
|
package/src/changed.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
|
|
3
3
|
import { GitDiffError } from "./errors.mjs";
|
|
4
|
+
import { dim } from "./reporter.mjs";
|
|
4
5
|
|
|
5
6
|
function runGit(root, args, ref) {
|
|
6
7
|
const result = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
@@ -21,7 +22,8 @@ function tryGit(root, args) {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export function getChangedFiles(root, ref) {
|
|
24
|
-
|
|
25
|
+
// The ref can't be read as an option (--end-of-options) or a pathspec (--).
|
|
26
|
+
const tracked = runGit(root, ["diff", "--name-only", "--end-of-options", ref, "--"], ref);
|
|
25
27
|
const untracked = runGit(root, ["ls-files", "--others", "--exclude-standard"], ref);
|
|
26
28
|
|
|
27
29
|
return [...new Set([...tracked, ...untracked])];
|
|
@@ -46,8 +48,7 @@ export function resolveDefaultRef(root) {
|
|
|
46
48
|
return { ref: upstream, label: upstream, reason: "no merge-base found" };
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
//
|
|
50
|
-
// it. A file outside every workspace directory is reported as "rootChangeFiles"
|
|
51
|
+
// Maps each changed file to its innermost workspace; the rest are root changes.
|
|
51
52
|
export function selectChangedWorkspaces(resolvedWorkspaces, changedFiles) {
|
|
52
53
|
const sorted = [...resolvedWorkspaces].sort((a, b) => b.length - a.length);
|
|
53
54
|
const workspaces = new Set();
|
|
@@ -65,3 +66,41 @@ export function selectChangedWorkspaces(resolvedWorkspaces, changedFiles) {
|
|
|
65
66
|
|
|
66
67
|
return { workspaces, rootChangeFiles };
|
|
67
68
|
}
|
|
69
|
+
|
|
70
|
+
function resolveRef(root, explicitRef) {
|
|
71
|
+
if (explicitRef) {
|
|
72
|
+
return { ref: explicitRef, label: explicitRef };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const resolved = resolveDefaultRef(root);
|
|
76
|
+
console.log(dim(`--changed: no --ref given, comparing against "${resolved.label}" (${resolved.reason})`));
|
|
77
|
+
return resolved;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Returns the workspaces with changes, or null when there's nothing to run (already reported).
|
|
81
|
+
export function filterChangedWorkspaces({ root, allPaths, workspaces, ref: explicitRef }) {
|
|
82
|
+
const { ref, label } = resolveRef(root, explicitRef);
|
|
83
|
+
|
|
84
|
+
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
|
+
const { workspaces: changedPaths, rootChangeFiles } = selectChangedWorkspaces(allPaths, changedFiles);
|
|
91
|
+
|
|
92
|
+
if (rootChangeFiles.length > 0) {
|
|
93
|
+
const suffix = rootChangeFiles.length > 1 ? ` (+${rootChangeFiles.length - 1} more)` : "";
|
|
94
|
+
console.log(dim(`--changed: "${rootChangeFiles[0]}"${suffix} is outside every workspace, ignoring`));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const filtered = workspaces.filter((workspace) => changedPaths.has(workspace.path));
|
|
98
|
+
console.log(dim(`--changed: running ${filtered.length}/${workspaces.length} workspace(s) with changes since "${label}"`));
|
|
99
|
+
|
|
100
|
+
if (filtered.length === 0) {
|
|
101
|
+
console.log(dim("No eligible workspace changed."));
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return filtered;
|
|
106
|
+
}
|
package/src/errors.mjs
CHANGED
|
@@ -7,6 +7,15 @@ export class NoWorkspacesError extends Error {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export class RootPackageJsonError extends Error {
|
|
11
|
+
constructor(root, cause) {
|
|
12
|
+
super(cause.code === "ENOENT"
|
|
13
|
+
? `No package.json found in ${root}. Run sumlyzer from the root of an npm workspaces project.`
|
|
14
|
+
: `could not read the root package.json (${cause.message})`, { cause });
|
|
15
|
+
this.name = "RootPackageJsonError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
10
19
|
export class InvalidPackageJsonError extends Error {
|
|
11
20
|
constructor(entries) {
|
|
12
21
|
super(entries.map(({ wsPath, message }) => `${workspaceName(wsPath)}: could not read its package.json (${message})`).join("\n"));
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { buildJunitReport } from "./junit.mjs";
|
|
5
|
+
import { red, dim, workspaceName } from "./reporter.mjs";
|
|
6
|
+
|
|
7
|
+
const DEFAULT_JUNIT_FILENAME = "junit.xml";
|
|
8
|
+
|
|
9
|
+
async function collectJunitEntries(results) {
|
|
10
|
+
const entries = [];
|
|
11
|
+
const missing = [];
|
|
12
|
+
|
|
13
|
+
for (const result of results) {
|
|
14
|
+
if (!result.junitDestPath) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
entries.push({ name: workspaceName(result.wsPath), xml: await readFile(result.junitDestPath, "utf8") });
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
missing.push(workspaceName(result.wsPath));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return { entries, missing };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function resolveDestination(root, junitPath) {
|
|
29
|
+
const destination = path.resolve(root, junitPath);
|
|
30
|
+
const isDirectory = await stat(destination).then((stats) => stats.isDirectory(), () => false);
|
|
31
|
+
|
|
32
|
+
return isDirectory ? path.join(destination, DEFAULT_JUNIT_FILENAME) : destination;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function writeJunitReport(root, junitPath, results) {
|
|
36
|
+
const { entries, missing } = await collectJunitEntries(results);
|
|
37
|
+
const destination = await resolveDestination(root, junitPath);
|
|
38
|
+
|
|
39
|
+
if (missing.length > 0) {
|
|
40
|
+
console.log(dim(`${missing.length} workspace(s) missing from the JUnit report: ${missing.join(", ")}`));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await writeFile(destination, buildJunitReport(entries));
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error(red(`Could not write JUnit report to "${destination}" (${error.message})`));
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
// Mirrors @npmcli/run-script: package fields flattened to npm_package_<path>,
|
|
4
|
+
// with arrays indexed, null/false as "" and undefined skipped.
|
|
5
|
+
function flattenPackageFields(fields, prefix, env = {}) {
|
|
6
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
7
|
+
if (value === undefined) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (value === null || value === false) {
|
|
11
|
+
env[`${prefix}${key}`] = "";
|
|
12
|
+
}
|
|
13
|
+
else if (Array.isArray(value)) {
|
|
14
|
+
value.forEach((item, index) => flattenPackageFields({ [`${key}_${index}`]: item }, prefix, env));
|
|
15
|
+
}
|
|
16
|
+
else if (typeof value === "object") {
|
|
17
|
+
flattenPackageFields(value, `${prefix}${key}_`, env);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
env[`${prefix}${key}`] = String(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return env;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The variables npm run sets for a lifecycle script, so a workspace script behaves
|
|
28
|
+
// the same under sumlyzer. Only the fields npm itself exposes (npm/rfcs#183).
|
|
29
|
+
export function npmScriptEnv({ pkg, pkgDir, event, script }) {
|
|
30
|
+
return {
|
|
31
|
+
...flattenPackageFields({
|
|
32
|
+
name: pkg.name,
|
|
33
|
+
version: pkg.version,
|
|
34
|
+
config: pkg.config,
|
|
35
|
+
engines: pkg.engines,
|
|
36
|
+
// npm exposes nothing for a string "bin", only for the object form.
|
|
37
|
+
bin: typeof pkg.bin === "object" ? pkg.bin : undefined
|
|
38
|
+
}, "npm_package_"),
|
|
39
|
+
npm_package_json: path.resolve(pkgDir, "package.json"),
|
|
40
|
+
npm_lifecycle_event: event,
|
|
41
|
+
npm_lifecycle_script: script
|
|
42
|
+
};
|
|
43
|
+
}
|
package/src/pathEnv.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Windows env names are case-insensitive ("Path"): replace the key instead of adding a duplicate.
|
|
2
|
+
export function withPath(env, value, platform = process.platform) {
|
|
3
|
+
if (platform !== "win32") {
|
|
4
|
+
return { ...env, PATH: value };
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const isPathKey = (key) => key.toUpperCase() === "PATH";
|
|
8
|
+
const key = Object.keys(env).find(isPathKey) ?? "Path";
|
|
9
|
+
const rest = Object.fromEntries(Object.entries(env).filter(([name]) => !isPathKey(name)));
|
|
10
|
+
|
|
11
|
+
return { ...rest, [key]: value };
|
|
12
|
+
}
|
package/src/reporter.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { styleText } from "node:util";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const green = (str) => styleText("green", str);
|
|
4
4
|
export const red = (str) => styleText("red", str);
|
|
5
|
-
|
|
5
|
+
const blue = (str) => styleText("blue", str);
|
|
6
6
|
export const dim = (str) => styleText("dim", str);
|
|
7
|
-
|
|
7
|
+
const bold = (str) => styleText("bold", str);
|
|
8
8
|
|
|
9
9
|
export function formatSeconds(ms) {
|
|
10
10
|
const seconds = Number.isFinite(ms) ? ms / 1000 : 0;
|