@dcaldeira/tooling 0.1.0 → 0.2.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.
Files changed (49) hide show
  1. package/README.md +34 -34
  2. package/checks/a11y.mjs +206 -206
  3. package/checks/architecture.mjs +137 -137
  4. package/checks/audit.mjs +121 -121
  5. package/checks/bundle.mjs +128 -126
  6. package/checks/dependencies.mjs +277 -277
  7. package/checks/duplication.mjs +135 -0
  8. package/checks/lint-scss.mjs +363 -349
  9. package/checks/package.mjs +30 -30
  10. package/checks/playwright-summary.mjs +53 -53
  11. package/checks/sass.mjs +67 -67
  12. package/checks/scan-secrets.mjs +58 -58
  13. package/checks/shared.mjs +86 -86
  14. package/checks/translations.mjs +55 -55
  15. package/checks/visual-compare.mjs +148 -148
  16. package/checks/visual-report-html.mjs +470 -470
  17. package/checks/visual-report.mjs +13 -13
  18. package/config.schema.json +999 -927
  19. package/configs/eslint.mjs +27 -27
  20. package/configs/knip.json +11 -11
  21. package/configs/playwright.mjs +15 -15
  22. package/configs/vitest.mjs +16 -16
  23. package/package.json +105 -105
  24. package/release/finalize.mjs +65 -65
  25. package/release/github.mjs +64 -64
  26. package/release/prepare.mjs +30 -30
  27. package/runner/browsers.mjs +73 -73
  28. package/runner/cache.mjs +121 -121
  29. package/runner/ci-plan.mjs +54 -54
  30. package/runner/cli.mjs +250 -248
  31. package/runner/config.mjs +148 -148
  32. package/runner/docs-install.mjs +93 -93
  33. package/runner/execute.mjs +298 -286
  34. package/runner/generate.mjs +122 -122
  35. package/runner/git.mjs +122 -122
  36. package/runner/graph.mjs +250 -243
  37. package/runner/insights.mjs +313 -313
  38. package/runner/provision.mjs +53 -53
  39. package/runner/repo-standard.mjs +104 -0
  40. package/runner/report.mjs +35 -35
  41. package/runner/serve-static.mjs +76 -76
  42. package/runner/setup.mjs +241 -237
  43. package/runner/summary.mjs +112 -112
  44. package/runner/watch.mjs +82 -82
  45. package/templates/ci.yml +25 -25
  46. package/templates/dependabot-merge.yml +13 -13
  47. package/templates/dependabot.yml +26 -26
  48. package/templates/pre-push +13 -13
  49. package/templates/release.yml +23 -23
@@ -1,286 +1,298 @@
1
- import { spawn } from 'node:child_process';
2
- import { existsSync, readFileSync } from 'node:fs';
3
- import { delimiter, dirname, isAbsolute, join, resolve } from 'node:path';
4
- import { inside } from './config.mjs';
5
- import { matches } from './graph.mjs';
6
-
7
- const bins = {
8
- prettier: 'prettier',
9
- eslint: 'eslint',
10
- vitest: 'vitest',
11
- playwright: '@playwright/test',
12
- knip: 'knip',
13
- tsc: 'typescript',
14
- lhci: '@lhci/cli',
15
- };
16
-
17
- export function packageManifest(root, name) {
18
- for (let directory = resolve(root); ; directory = dirname(directory)) {
19
- const manifest = join(directory, 'node_modules', name, 'package.json');
20
- if (existsSync(manifest)) return manifest;
21
- if (dirname(directory) === directory) return null;
22
- }
23
- }
24
-
25
- export function executable(root, name) {
26
- if (isAbsolute(name)) return existsSync(name) ? [name] : null;
27
- if (name === 'initdb' && process.env.PG_BIN) {
28
- const target = join(process.env.PG_BIN, process.platform === 'win32' ? 'initdb.exe' : 'initdb');
29
- if (existsSync(target)) return [target];
30
- }
31
- if (name === 'node') return [process.execPath];
32
- if (name === 'npm') {
33
- const candidates = [
34
- process.env.npm_execpath,
35
- join(dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js'),
36
- ];
37
- const cli = candidates.find((p) => p && /npm-cli\.js$/.test(p) && existsSync(p));
38
- if (cli) return [process.execPath, cli];
39
- }
40
- const pkg = bins[name] ?? name;
41
- for (let directory = resolve(root); ; directory = dirname(directory)) {
42
- const manifest = join(directory, 'node_modules', pkg, 'package.json');
43
- if (existsSync(manifest)) {
44
- const { bin } = JSON.parse(readFileSync(manifest, 'utf8'));
45
- const entry = typeof bin === 'string' ? bin : bin?.[name];
46
- if (entry) return [process.execPath, resolve(dirname(manifest), entry)];
47
- }
48
- if (dirname(directory) === directory) break;
49
- }
50
- const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
51
- for (const directory of (process.env.PATH ?? '').split(delimiter))
52
- for (const extension of extensions) {
53
- const candidate = join(directory, `${name}${extension}`);
54
- if (existsSync(candidate)) return [candidate];
55
- }
56
- return null;
57
- }
58
-
59
- export function invoke(command, root, { cwd = root, extra = [], quiet = false, env = {} } = {}) {
60
- let file, args, shell;
61
- if (Array.isArray(command)) {
62
- const binary = executable(cwd, command[0]);
63
- if (!binary)
64
- return Promise.resolve({
65
- status: 'unavailable',
66
- reason: `Missing executable: ${command[0]}`,
67
- });
68
- [file, ...args] = [...binary, ...command.slice(1), ...extra];
69
- shell = false;
70
- } else {
71
- if (extra.length) throw new Error('Changed-file commands must use an argument array');
72
- file = command;
73
- args = [];
74
- shell = true;
75
- }
76
- return new Promise((done) => {
77
- const started = Date.now();
78
- let settled = false;
79
- const finish = (result) => {
80
- if (!settled) {
81
- settled = true;
82
- done({ ...result, milliseconds: Date.now() - started });
83
- }
84
- };
85
- const child = spawn(file, args, {
86
- cwd,
87
- shell,
88
- stdio: quiet ? 'ignore' : 'inherit',
89
- env: {
90
- ...process.env,
91
- ...env,
92
- PATH: `${join(cwd, 'node_modules/.bin')}${delimiter}${join(root, 'node_modules/.bin')}${delimiter}${process.env.PATH}`,
93
- },
94
- });
95
- child.once('error', (error) => finish({ status: 'unavailable', reason: error.message }));
96
- child.once('exit', (code, signal) =>
97
- finish({
98
- status: code === 0 ? 'passed' : 'failed',
99
- code,
100
- ...(signal ? { reason: signal } : {}),
101
- }),
102
- );
103
- });
104
- }
105
-
106
- export async function execute(
107
- root,
108
- selection,
109
- {
110
- bail = false,
111
- concurrency = bail ? 1 : 2,
112
- platform = process.platform,
113
- run = invoke,
114
- cache,
115
- toolCache = true,
116
- } = {},
117
- ) {
118
- if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 16)
119
- throw new Error('Concurrency must be an integer between 1 and 16');
120
- const excluded = new Set([
121
- ...selection.excluded,
122
- ...selection.checks.filter((c) => c.excluded).map((c) => c.id),
123
- ]);
124
- const statuses = new Map([...excluded].map((id) => [id, 'excluded']));
125
- const outcomes = new Map(
126
- [...excluded].map((id) => [
127
- id,
128
- { id, status: 'excluded', reason: 'Required check intentionally excluded' },
129
- ]),
130
- );
131
- const pending = selection.checks.filter((c) => !c.excluded);
132
- const running = new Map();
133
- const resources = new Set();
134
- let stopped = false;
135
- const broad = selection.groups.some((g) =>
136
- ['all', 'tooling', 'dependencies', 'unknown'].includes(g),
137
- );
138
-
139
- async function perform(check) {
140
- const cwd = inside(root, check.cwd ?? '.');
141
- const selectedFiles = check.files ?? selection.files;
142
- if (check.platforms && !check.platforms.includes(platform))
143
- return {
144
- status: 'unavailable',
145
- reason: 'Requires ' + check.platforms.join('/') + '; use Linux via WSL or a container',
146
- };
147
- const missing = (check.tools ?? []).filter((tool) => !executable(cwd, tool));
148
- if (missing.length)
149
- return { status: 'unavailable', reason: 'Missing tools: ' + missing.join(', ') };
150
- const deleted =
151
- selectedFiles !== 'all' &&
152
- check.devAllCommand &&
153
- selectedFiles.some(
154
- (file) =>
155
- check.devFiles?.some((pattern) => matches(file, pattern)) &&
156
- !existsSync(inside(root, file)),
157
- );
158
- const devFiles =
159
- selection.profile === 'dev' && !broad && !deleted && check.devCommand && check.devFiles;
160
- const files = devFiles
161
- ? selectedFiles.filter(
162
- (file) =>
163
- check.devFiles.some((pattern) => matches(file, pattern)) &&
164
- existsSync(inside(root, file)),
165
- )
166
- : [];
167
- if (devFiles && !files.length)
168
- return {
169
- status: 'passed',
170
- reason: 'No remaining matching files (deleted files are checked by full profiles)',
171
- };
172
- let command = devFiles
173
- ? check.devCommand
174
- : selection.profile === 'dev'
175
- ? (check.devAllCommand ?? check.command)
176
- : check.command;
177
- if (!toolCache && Array.isArray(command) && command[0] === 'eslint') {
178
- command = command.filter(
179
- (value, index, args) =>
180
- value !== '--cache' &&
181
- value !== '--cache-strategy' &&
182
- args[index - 1] !== '--cache-strategy',
183
- );
184
- }
185
- if (
186
- !toolCache &&
187
- Array.isArray(command) &&
188
- command[0] === 'tsc' &&
189
- command.includes('--build') &&
190
- !command.includes('--force')
191
- )
192
- command = [...command, '--force'];
193
- if (
194
- Array.isArray(command) &&
195
- command[0] === 'eslint' &&
196
- command.includes('--cache') &&
197
- !command.includes('--cache-location')
198
- ) {
199
- command = [...command];
200
- const end = command.indexOf('--');
201
- command.splice(
202
- end === -1 ? command.length : end,
203
- 0,
204
- '--cache-location',
205
- join(root, '.tooling/cache/eslint', `${check.id}.cache`),
206
- );
207
- }
208
- const cached = cache?.get(check, command, files);
209
- if (cached) return cached;
210
- console.log(
211
- '\n> ' +
212
- check.id +
213
- ': ' +
214
- (Array.isArray(command) ? command.join(' ') : command) +
215
- (files.length ? ' (' + files.length + ' files)' : ''),
216
- );
217
- const env = {
218
- TOOLING_ROOT: root,
219
- TOOLING_CHECK_ID: check.id,
220
- TOOLING_BUILT: (check.dependsOn ?? ['build']).some(
221
- (id) =>
222
- statuses.get(id) === 'passed' &&
223
- selection.checks.some(
224
- (candidate) => candidate.id === id && (candidate.kind ?? candidate.id) === 'build',
225
- ),
226
- )
227
- ? '1'
228
- : '',
229
- };
230
- if ((check.kind ?? check.id) === 'unit' && process.env.TOOLING_REPORT_DIR)
231
- env.TOOLING_UNIT_OUTPUT_DIR = join(process.env.TOOLING_REPORT_DIR, `${check.id}-results`);
232
- if (['e2e', 'visual'].includes(check.kind ?? check.id) && process.env.TOOLING_REPORT_DIR) {
233
- env.PLAYWRIGHT_HTML_OUTPUT_DIR = join(process.env.TOOLING_REPORT_DIR, check.id);
234
- env.TOOLING_TEST_OUTPUT_DIR = join(process.env.TOOLING_REPORT_DIR, check.id + '-results');
235
- }
236
- return run(command, root, { cwd, extra: files.map((file) => resolve(root, file)), env });
237
- }
238
-
239
- function record(check, result) {
240
- outcomes.set(check.id, { id: check.id, kind: check.kind ?? check.id, ...result });
241
- statuses.set(check.id, result.status);
242
- if (bail && result.status !== 'passed') stopped = true;
243
- }
244
-
245
- while (pending.length || running.size) {
246
- for (let i = 0; i < pending.length;) {
247
- const check = pending[i];
248
- const deps = check.dependsOn ?? [];
249
- if (stopped || deps.some((id) => statuses.has(id) && statuses.get(id) !== 'passed')) {
250
- pending.splice(i, 1);
251
- record(check, {
252
- status: 'unavailable',
253
- reason: stopped ? 'Not run after --bail' : 'Dependency did not pass',
254
- });
255
- continue;
256
- }
257
- if (
258
- running.size >= concurrency ||
259
- deps.some((id) => !statuses.has(id)) ||
260
- (check.resources ?? []).some((key) => resources.has(key))
261
- ) {
262
- i++;
263
- continue;
264
- }
265
- pending.splice(i, 1);
266
- for (const key of check.resources ?? []) resources.add(key);
267
- const task = Promise.resolve()
268
- .then(() => perform(check))
269
- .catch((error) => ({ status: 'unavailable', reason: error.message }))
270
- .then((result) => {
271
- record(check, result);
272
- running.delete(check.id);
273
- for (const key of check.resources ?? []) resources.delete(key);
274
- });
275
- running.set(check.id, task);
276
- }
277
- if (running.size) await Promise.race(running.values());
278
- else if (pending.length) {
279
- for (const check of pending.splice(0))
280
- record(check, { status: 'unavailable', reason: 'Unresolved dependencies' });
281
- }
282
- }
283
- const ids = [...new Set([...excluded, ...selection.checks.map((c) => c.id)])];
284
- const results = ids.map((id) => outcomes.get(id));
285
- return { results, complete: results.every((r) => r.status === 'passed') };
286
- }
1
+ import { spawn } from 'node:child_process';
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { delimiter, dirname, isAbsolute, join, resolve } from 'node:path';
4
+ import { inside } from './config.mjs';
5
+ import { matches } from './graph.mjs';
6
+
7
+ const bins = {
8
+ prettier: 'prettier',
9
+ eslint: 'eslint',
10
+ vitest: 'vitest',
11
+ playwright: '@playwright/test',
12
+ knip: 'knip',
13
+ tsc: 'typescript',
14
+ lhci: '@lhci/cli',
15
+ };
16
+
17
+ export function packageManifest(root, name) {
18
+ for (let directory = resolve(root); ; directory = dirname(directory)) {
19
+ const manifest = join(directory, 'node_modules', name, 'package.json');
20
+ if (existsSync(manifest)) return manifest;
21
+ if (dirname(directory) === directory) return null;
22
+ }
23
+ }
24
+
25
+ export function executable(root, name) {
26
+ if (isAbsolute(name)) return existsSync(name) ? [name] : null;
27
+ if (name === 'initdb' && process.env.PG_BIN) {
28
+ const target = join(process.env.PG_BIN, process.platform === 'win32' ? 'initdb.exe' : 'initdb');
29
+ if (existsSync(target)) return [target];
30
+ }
31
+ if (name === 'node') return [process.execPath];
32
+ if (name === 'npm') {
33
+ const candidates = [
34
+ process.env.npm_execpath,
35
+ join(dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js'),
36
+ ];
37
+ const cli = candidates.find((p) => p && /npm-cli\.js$/.test(p) && existsSync(p));
38
+ if (cli) return [process.execPath, cli];
39
+ }
40
+ const pkg = bins[name] ?? name;
41
+ for (let directory = resolve(root); ; directory = dirname(directory)) {
42
+ const manifest = join(directory, 'node_modules', pkg, 'package.json');
43
+ if (existsSync(manifest)) {
44
+ const { bin } = JSON.parse(readFileSync(manifest, 'utf8'));
45
+ const entry = typeof bin === 'string' ? bin : bin?.[name];
46
+ if (entry) return [process.execPath, resolve(dirname(manifest), entry)];
47
+ }
48
+ if (dirname(directory) === directory) break;
49
+ }
50
+ const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
51
+ for (const directory of (process.env.PATH ?? '').split(delimiter))
52
+ for (const extension of extensions) {
53
+ const candidate = join(directory, `${name}${extension}`);
54
+ if (existsSync(candidate)) return [candidate];
55
+ }
56
+ return null;
57
+ }
58
+
59
+ export function invoke(command, root, { cwd = root, extra = [], quiet = false, env = {} } = {}) {
60
+ let file, args, shell;
61
+ if (Array.isArray(command)) {
62
+ const binary = executable(cwd, command[0]);
63
+ if (!binary)
64
+ return Promise.resolve({
65
+ status: 'unavailable',
66
+ reason: `Missing executable: ${command[0]}`,
67
+ });
68
+ [file, ...args] = [...binary, ...command.slice(1), ...extra];
69
+ shell = false;
70
+ } else {
71
+ if (extra.length) throw new Error('Changed-file commands must use an argument array');
72
+ file = command;
73
+ args = [];
74
+ shell = true;
75
+ }
76
+ return new Promise((done) => {
77
+ const started = Date.now();
78
+ let settled = false;
79
+ const finish = (result) => {
80
+ if (!settled) {
81
+ settled = true;
82
+ done({ ...result, milliseconds: Date.now() - started });
83
+ }
84
+ };
85
+ const child = spawn(file, args, {
86
+ cwd,
87
+ shell,
88
+ stdio: quiet ? 'ignore' : 'inherit',
89
+ env: {
90
+ ...process.env,
91
+ ...env,
92
+ PATH: `${join(cwd, 'node_modules/.bin')}${delimiter}${join(root, 'node_modules/.bin')}${delimiter}${process.env.PATH}`,
93
+ },
94
+ });
95
+ child.once('error', (error) => finish({ status: 'unavailable', reason: error.message }));
96
+ child.once('exit', (code, signal) =>
97
+ finish({
98
+ status: code === 0 ? 'passed' : 'failed',
99
+ code,
100
+ ...(signal ? { reason: signal } : {}),
101
+ }),
102
+ );
103
+ });
104
+ }
105
+
106
+ export async function execute(
107
+ root,
108
+ selection,
109
+ {
110
+ bail = false,
111
+ concurrency = bail ? 1 : 2,
112
+ platform = process.platform,
113
+ run = invoke,
114
+ cache,
115
+ toolCache = true,
116
+ } = {},
117
+ ) {
118
+ if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 16)
119
+ throw new Error('Concurrency must be an integer between 1 and 16');
120
+ const excluded = new Set([
121
+ ...selection.excluded,
122
+ ...selection.checks.filter((c) => c.excluded).map((c) => c.id),
123
+ ]);
124
+ const statuses = new Map([...excluded].map((id) => [id, 'excluded']));
125
+ const outcomes = new Map(
126
+ [...excluded].map((id) => [
127
+ id,
128
+ { id, status: 'excluded', reason: 'Required check intentionally excluded' },
129
+ ]),
130
+ );
131
+ const pending = selection.checks.filter((c) => !c.excluded);
132
+ const running = new Map();
133
+ const resources = new Set();
134
+ let stopped = false;
135
+ const broad = selection.groups.some((g) =>
136
+ ['all', 'tooling', 'dependencies', 'unknown'].includes(g),
137
+ );
138
+
139
+ async function perform(check) {
140
+ const cwd = inside(root, check.cwd ?? '.');
141
+ const selectedFiles = check.files ?? selection.files;
142
+ if (check.platforms && !check.platforms.includes(platform))
143
+ return {
144
+ status: 'unavailable',
145
+ reason: 'Requires ' + check.platforms.join('/') + '; use Linux via WSL or a container',
146
+ };
147
+ const missing = (check.tools ?? []).filter((tool) => !executable(cwd, tool));
148
+ if (missing.length)
149
+ return { status: 'unavailable', reason: 'Missing tools: ' + missing.join(', ') };
150
+ const deleted =
151
+ selectedFiles !== 'all' &&
152
+ check.devAllCommand &&
153
+ selectedFiles.some(
154
+ (file) =>
155
+ check.devFiles?.some((pattern) => matches(file, pattern)) &&
156
+ !existsSync(inside(root, file)),
157
+ );
158
+ const devFiles =
159
+ selection.profile === 'dev' && !broad && !deleted && check.devCommand && check.devFiles;
160
+ const files = devFiles
161
+ ? selectedFiles.filter(
162
+ (file) =>
163
+ check.devFiles.some((pattern) => matches(file, pattern)) &&
164
+ existsSync(inside(root, file)),
165
+ )
166
+ : [];
167
+ if (devFiles && !files.length)
168
+ return {
169
+ status: 'passed',
170
+ reason: 'No remaining matching files (deleted files are checked by full profiles)',
171
+ };
172
+ let command = devFiles
173
+ ? check.devCommand
174
+ : selection.profile === 'dev'
175
+ ? (check.devAllCommand ?? check.command)
176
+ : check.command;
177
+ if (!toolCache && Array.isArray(command) && command[0] === 'eslint') {
178
+ command = command.filter(
179
+ (value, index, args) =>
180
+ value !== '--cache' &&
181
+ value !== '--cache-strategy' &&
182
+ args[index - 1] !== '--cache-strategy',
183
+ );
184
+ }
185
+ if (
186
+ !toolCache &&
187
+ Array.isArray(command) &&
188
+ command[0] === 'tsc' &&
189
+ command.includes('--build') &&
190
+ !command.includes('--force')
191
+ )
192
+ command = [...command, '--force'];
193
+ if (
194
+ Array.isArray(command) &&
195
+ command[0] === 'eslint' &&
196
+ command.includes('--cache') &&
197
+ !command.includes('--cache-location')
198
+ ) {
199
+ command = [...command];
200
+ const end = command.indexOf('--');
201
+ command.splice(
202
+ end === -1 ? command.length : end,
203
+ 0,
204
+ '--cache-location',
205
+ join(root, '.tooling/cache/eslint', `${check.id}.cache`),
206
+ );
207
+ }
208
+ const cached = cache?.get(check, command, files);
209
+ if (cached) return cached;
210
+ console.log(
211
+ '\n> ' +
212
+ check.id +
213
+ ': ' +
214
+ (Array.isArray(command) ? command.join(' ') : command) +
215
+ (files.length ? ' (' + files.length + ' files)' : ''),
216
+ );
217
+ const env = {
218
+ TOOLING_ROOT: root,
219
+ TOOLING_CHECK_ID: check.id,
220
+ TOOLING_BUILT: (check.dependsOn ?? ['build']).some(
221
+ (id) =>
222
+ statuses.get(id) === 'passed' &&
223
+ selection.checks.some(
224
+ (candidate) => candidate.id === id && (candidate.kind ?? candidate.id) === 'build',
225
+ ),
226
+ )
227
+ ? '1'
228
+ : '',
229
+ };
230
+ // Full-profile runs of change-scoped checks still get the selected files, as a list file
231
+ // (a command line could overflow on large diffs). `--all` runs leave it unset.
232
+ if (
233
+ (check.kind ?? check.id) === 'duplication' &&
234
+ Array.isArray(selectedFiles) &&
235
+ !files.length
236
+ ) {
237
+ const list = join(root, '.tooling/state', `${check.id}-changed.txt`);
238
+ mkdirSync(dirname(list), { recursive: true });
239
+ writeFileSync(list, selectedFiles.join('\n'));
240
+ env.TOOLING_CHANGED_FILES = list;
241
+ }
242
+ if ((check.kind ?? check.id) === 'unit' && process.env.TOOLING_REPORT_DIR)
243
+ env.TOOLING_UNIT_OUTPUT_DIR = join(process.env.TOOLING_REPORT_DIR, `${check.id}-results`);
244
+ if (['e2e', 'visual'].includes(check.kind ?? check.id) && process.env.TOOLING_REPORT_DIR) {
245
+ env.PLAYWRIGHT_HTML_OUTPUT_DIR = join(process.env.TOOLING_REPORT_DIR, check.id);
246
+ env.TOOLING_TEST_OUTPUT_DIR = join(process.env.TOOLING_REPORT_DIR, check.id + '-results');
247
+ }
248
+ return run(command, root, { cwd, extra: files.map((file) => resolve(root, file)), env });
249
+ }
250
+
251
+ function record(check, result) {
252
+ outcomes.set(check.id, { id: check.id, kind: check.kind ?? check.id, ...result });
253
+ statuses.set(check.id, result.status);
254
+ if (bail && result.status !== 'passed') stopped = true;
255
+ }
256
+
257
+ while (pending.length || running.size) {
258
+ for (let i = 0; i < pending.length;) {
259
+ const check = pending[i];
260
+ const deps = check.dependsOn ?? [];
261
+ if (stopped || deps.some((id) => statuses.has(id) && statuses.get(id) !== 'passed')) {
262
+ pending.splice(i, 1);
263
+ record(check, {
264
+ status: 'unavailable',
265
+ reason: stopped ? 'Not run after --bail' : 'Dependency did not pass',
266
+ });
267
+ continue;
268
+ }
269
+ if (
270
+ running.size >= concurrency ||
271
+ deps.some((id) => !statuses.has(id)) ||
272
+ (check.resources ?? []).some((key) => resources.has(key))
273
+ ) {
274
+ i++;
275
+ continue;
276
+ }
277
+ pending.splice(i, 1);
278
+ for (const key of check.resources ?? []) resources.add(key);
279
+ const task = Promise.resolve()
280
+ .then(() => perform(check))
281
+ .catch((error) => ({ status: 'unavailable', reason: error.message }))
282
+ .then((result) => {
283
+ record(check, result);
284
+ running.delete(check.id);
285
+ for (const key of check.resources ?? []) resources.delete(key);
286
+ });
287
+ running.set(check.id, task);
288
+ }
289
+ if (running.size) await Promise.race(running.values());
290
+ else if (pending.length) {
291
+ for (const check of pending.splice(0))
292
+ record(check, { status: 'unavailable', reason: 'Unresolved dependencies' });
293
+ }
294
+ }
295
+ const ids = [...new Set([...excluded, ...selection.checks.map((c) => c.id)])];
296
+ const results = ids.map((id) => outcomes.get(id));
297
+ return { results, complete: results.every((r) => r.status === 'passed') };
298
+ }