@dcaldeira/tooling 0.1.0 → 0.2.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.
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 +126 -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 +977 -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,30 +1,30 @@
1
- #!/usr/bin/env node
2
- import { mkdirSync, writeFileSync, readFileSync } from 'node:fs';
3
- import { loadConfig } from '../runner/config.mjs';
4
- import { git, clean } from '../runner/git.mjs';
5
- import { invoke } from '../runner/execute.mjs';
6
-
7
- const root = process.cwd();
8
- const { config } = loadConfig(root);
9
- if (!clean(root)) throw new Error('Commit all files before preparing a release');
10
- if (!config.release?.prepare) throw new Error('Configure release.prepare');
11
- const source = git(root, 'rev-parse', 'HEAD');
12
- const level = process.argv[2] ?? process.env.RELEASE_LEVEL;
13
- if (process.argv.length > 3 || !['major', 'minor', 'patch'].includes(level))
14
- throw new Error('Usage: prepare.mjs <patch|minor|major> or set RELEASE_LEVEL');
15
- mkdirSync('.tooling', { recursive: true });
16
- const result = await invoke(config.release.prepare, root, { extra: [level] });
17
- if (result.status !== 'passed') throw new Error('Release preparation failed');
18
- git(root, 'add', '--', ...config.release.files);
19
- git(root, 'commit', '-m', `Release ${JSON.parse(readFileSync('package.json', 'utf8')).version}`);
20
- if (!clean(root)) throw new Error('Release preparation modified files outside release.files');
21
- const candidate = {
22
- source,
23
- head: git(root, 'rev-parse', 'HEAD'),
24
- tree: git(root, 'rev-parse', 'HEAD^{tree}'),
25
- };
26
- writeFileSync('.tooling/candidate.json', JSON.stringify(candidate));
27
- if (process.env.GITHUB_OUTPUT)
28
- writeFileSync(process.env.GITHUB_OUTPUT, `head=${candidate.head}\nsource=${source}\n`, {
29
- flag: 'a',
30
- });
1
+ #!/usr/bin/env node
2
+ import { mkdirSync, writeFileSync, readFileSync } from 'node:fs';
3
+ import { loadConfig } from '../runner/config.mjs';
4
+ import { git, clean } from '../runner/git.mjs';
5
+ import { invoke } from '../runner/execute.mjs';
6
+
7
+ const root = process.cwd();
8
+ const { config } = loadConfig(root);
9
+ if (!clean(root)) throw new Error('Commit all files before preparing a release');
10
+ if (!config.release?.prepare) throw new Error('Configure release.prepare');
11
+ const source = git(root, 'rev-parse', 'HEAD');
12
+ const level = process.argv[2] ?? process.env.RELEASE_LEVEL;
13
+ if (process.argv.length > 3 || !['major', 'minor', 'patch'].includes(level))
14
+ throw new Error('Usage: prepare.mjs <patch|minor|major> or set RELEASE_LEVEL');
15
+ mkdirSync('.tooling', { recursive: true });
16
+ const result = await invoke(config.release.prepare, root, { extra: [level] });
17
+ if (result.status !== 'passed') throw new Error('Release preparation failed');
18
+ git(root, 'add', '--', ...config.release.files);
19
+ git(root, 'commit', '-m', `Release ${JSON.parse(readFileSync('package.json', 'utf8')).version}`);
20
+ if (!clean(root)) throw new Error('Release preparation modified files outside release.files');
21
+ const candidate = {
22
+ source,
23
+ head: git(root, 'rev-parse', 'HEAD'),
24
+ tree: git(root, 'rev-parse', 'HEAD^{tree}'),
25
+ };
26
+ writeFileSync('.tooling/candidate.json', JSON.stringify(candidate));
27
+ if (process.env.GITHUB_OUTPUT)
28
+ writeFileSync(process.env.GITHUB_OUTPUT, `head=${candidate.head}\nsource=${source}\n`, {
29
+ flag: 'a',
30
+ });
@@ -1,73 +1,73 @@
1
- import { appendFileSync, readFileSync } from 'node:fs';
2
- import { createRequire } from 'node:module';
3
- import { pathToFileURL } from 'node:url';
4
- import { executable, invoke, packageManifest } from './execute.mjs';
5
- import { inside } from './config.mjs';
6
-
7
- export function browserChecks(selection) {
8
- return selection.checks.filter(
9
- (check) =>
10
- !check.excluded && ['e2e', 'visual', 'a11y', 'lighthouse'].includes(check.kind ?? check.id),
11
- );
12
- }
13
-
14
- export async function provisionBrowsers(
15
- root,
16
- selection,
17
- {
18
- run = invoke,
19
- find = executable,
20
- manifest = packageManifest,
21
- load = (path) => createRequire(path)('@playwright/test'),
22
- env = process.env,
23
- } = {},
24
- ) {
25
- const checks = browserChecks(selection);
26
- if (!checks.length) return {};
27
- const installed = new Set();
28
- let playwrightChrome;
29
- for (const check of checks.filter((check) =>
30
- ['e2e', 'visual', 'a11y'].includes(check.kind ?? check.id),
31
- )) {
32
- const cwd = inside(root, check.cwd ?? '.');
33
- const packagePath = manifest(cwd, '@playwright/test');
34
- if (!packagePath)
35
- throw new Error(`${check.id}: install a locked @playwright/test in ${check.cwd ?? '.'}`);
36
- if (!installed.has(packagePath)) {
37
- const result = await run(['playwright', 'install', '--with-deps', 'chromium'], root, { cwd });
38
- if (result.status !== 'passed') throw new Error(`${check.id}: Chromium installation failed`);
39
- installed.add(packagePath);
40
- }
41
- playwrightChrome = load(packagePath).chromium.executablePath();
42
- }
43
- if (!checks.some((check) => (check.kind ?? check.id) === 'lighthouse')) return {};
44
- // Lighthouse-only projects can use the runner's native Chrome without installing Playwright.
45
- const native =
46
- env.CHROME_PATH ||
47
- ['google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser']
48
- .map((name) => find(root, name)?.[0])
49
- .find(Boolean);
50
- if (native) return { CHROME_PATH: native };
51
- if (playwrightChrome) return { CHROME_PATH: playwrightChrome };
52
- const cwd = inside(
53
- root,
54
- checks.find((check) => (check.kind ?? check.id) === 'lighthouse').cwd ?? '.',
55
- );
56
- const packagePath = manifest(cwd, '@playwright/test');
57
- if (!packagePath)
58
- throw new Error(
59
- 'Lighthouse requires CHROME_PATH, a native Chrome installation, or locked @playwright/test for Chromium provisioning',
60
- );
61
- const result = await run(['playwright', 'install', '--with-deps', 'chromium'], root, { cwd });
62
- if (result.status !== 'passed') throw new Error('Lighthouse Chromium installation failed');
63
- return { CHROME_PATH: load(packagePath).chromium.executablePath() };
64
- }
65
-
66
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
67
- const selection = JSON.parse(readFileSync(process.argv[2], 'utf8'));
68
- const variables = await provisionBrowsers(process.cwd(), selection);
69
- for (const [key, value] of Object.entries(variables)) {
70
- if (/[\r\n]/.test(value)) throw new Error(`Invalid ${key}`);
71
- if (process.env.GITHUB_ENV) appendFileSync(process.env.GITHUB_ENV, `${key}=${value}\n`);
72
- }
73
- }
1
+ import { appendFileSync, readFileSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { executable, invoke, packageManifest } from './execute.mjs';
5
+ import { inside } from './config.mjs';
6
+
7
+ export function browserChecks(selection) {
8
+ return selection.checks.filter(
9
+ (check) =>
10
+ !check.excluded && ['e2e', 'visual', 'a11y', 'lighthouse'].includes(check.kind ?? check.id),
11
+ );
12
+ }
13
+
14
+ export async function provisionBrowsers(
15
+ root,
16
+ selection,
17
+ {
18
+ run = invoke,
19
+ find = executable,
20
+ manifest = packageManifest,
21
+ load = (path) => createRequire(path)('@playwright/test'),
22
+ env = process.env,
23
+ } = {},
24
+ ) {
25
+ const checks = browserChecks(selection);
26
+ if (!checks.length) return {};
27
+ const installed = new Set();
28
+ let playwrightChrome;
29
+ for (const check of checks.filter((check) =>
30
+ ['e2e', 'visual', 'a11y'].includes(check.kind ?? check.id),
31
+ )) {
32
+ const cwd = inside(root, check.cwd ?? '.');
33
+ const packagePath = manifest(cwd, '@playwright/test');
34
+ if (!packagePath)
35
+ throw new Error(`${check.id}: install a locked @playwright/test in ${check.cwd ?? '.'}`);
36
+ if (!installed.has(packagePath)) {
37
+ const result = await run(['playwright', 'install', '--with-deps', 'chromium'], root, { cwd });
38
+ if (result.status !== 'passed') throw new Error(`${check.id}: Chromium installation failed`);
39
+ installed.add(packagePath);
40
+ }
41
+ playwrightChrome = load(packagePath).chromium.executablePath();
42
+ }
43
+ if (!checks.some((check) => (check.kind ?? check.id) === 'lighthouse')) return {};
44
+ // Lighthouse-only projects can use the runner's native Chrome without installing Playwright.
45
+ const native =
46
+ env.CHROME_PATH ||
47
+ ['google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser']
48
+ .map((name) => find(root, name)?.[0])
49
+ .find(Boolean);
50
+ if (native) return { CHROME_PATH: native };
51
+ if (playwrightChrome) return { CHROME_PATH: playwrightChrome };
52
+ const cwd = inside(
53
+ root,
54
+ checks.find((check) => (check.kind ?? check.id) === 'lighthouse').cwd ?? '.',
55
+ );
56
+ const packagePath = manifest(cwd, '@playwright/test');
57
+ if (!packagePath)
58
+ throw new Error(
59
+ 'Lighthouse requires CHROME_PATH, a native Chrome installation, or locked @playwright/test for Chromium provisioning',
60
+ );
61
+ const result = await run(['playwright', 'install', '--with-deps', 'chromium'], root, { cwd });
62
+ if (result.status !== 'passed') throw new Error('Lighthouse Chromium installation failed');
63
+ return { CHROME_PATH: load(packagePath).chromium.executablePath() };
64
+ }
65
+
66
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
67
+ const selection = JSON.parse(readFileSync(process.argv[2], 'utf8'));
68
+ const variables = await provisionBrowsers(process.cwd(), selection);
69
+ for (const [key, value] of Object.entries(variables)) {
70
+ if (/[\r\n]/.test(value)) throw new Error(`Invalid ${key}`);
71
+ if (process.env.GITHUB_ENV) appendFileSync(process.env.GITHUB_ENV, `${key}=${value}\n`);
72
+ }
73
+ }
package/runner/cache.mjs CHANGED
@@ -1,121 +1,121 @@
1
- import { createHash, randomUUID } from 'node:crypto';
2
- import { mkdirSync, readFileSync, writeFileSync, renameSync } from 'node:fs';
3
- import { join, resolve } from 'node:path';
4
- import { builtins, classify, matches, workspaceFiles } from './graph.mjs';
5
-
6
- const diagnostics = new Set(['format', 'lint', 'styles', 'translations', 'deadcode', 'workflows']);
7
- const fresh = new Set([
8
- 'security',
9
- 'build',
10
- 'size',
11
- 'unit',
12
- 'e2e',
13
- 'visual',
14
- 'lighthouse',
15
- 'database',
16
- 'a11y',
17
- 'dependency-consistency',
18
- ]);
19
-
20
- export function checkCache(root, config, selection, state, { disabled = false } = {}) {
21
- const pending = new Map();
22
- const directory = join(root, '.tooling/state/checks');
23
- function eligible(check) {
24
- const kind = check.kind ?? check.id;
25
- if (
26
- disabled ||
27
- config.execution?.checkCache === false ||
28
- fresh.has(kind) ||
29
- check.dependsOn?.length ||
30
- check.cache === false
31
- )
32
- return false;
33
- const overrides = config.checks?.[check.id];
34
- if (
35
- !check.cache &&
36
- (!diagnostics.has(kind) ||
37
- ['command', 'devCommand', 'devAllCommand'].some((name) => overrides?.[name] !== undefined))
38
- )
39
- return false;
40
- return Boolean(check.cache || builtins[kind]);
41
- }
42
- function key(check, command, files) {
43
- if (!eligible(check)) return null;
44
- const all = Object.keys(state.files);
45
- const scoped = new Set(workspaceFiles(config, check.workspaces, all));
46
- const patterns = typeof check.cache === 'object' ? check.cache.inputs : null;
47
- const input = all
48
- .filter((file) => {
49
- // Config, lockfiles and unknown paths always invalidate, even for narrowed input sets.
50
- const global = classify([file], config).some((group) =>
51
- ['tooling', 'dependencies', 'unknown'].includes(group),
52
- );
53
- return (
54
- global ||
55
- (patterns ? patterns.some((pattern) => matches(file, pattern)) : scoped.has(file))
56
- );
57
- })
58
- .sort()
59
- .map((file) => [file, state.files[file]]);
60
- const tools = new Set([
61
- ...(check.tools ?? []),
62
- ...(Array.isArray(command) ? [command[0]] : []),
63
- ]);
64
- const identities = state.tools.filter(
65
- (tool) => tools.has(tool.name) && tool.cwd === resolve(root, check.cwd ?? '.'),
66
- );
67
- const { files: _selection, ...definition } = check;
68
- return createHash('sha256')
69
- .update(
70
- JSON.stringify({
71
- schemaVersion: 1,
72
- context: state.context,
73
- check: definition,
74
- command,
75
- profile: selection.profile,
76
- files,
77
- input,
78
- tools: identities,
79
- }),
80
- )
81
- .digest('hex');
82
- }
83
- return {
84
- reusablePass: selection.checks.every(eligible),
85
- get(check, command, files) {
86
- const fingerprint = key(check, command, files);
87
- if (!fingerprint) return null;
88
- pending.set(check.id, fingerprint);
89
- try {
90
- const record = JSON.parse(readFileSync(join(directory, `${fingerprint}.json`), 'utf8'));
91
- if (
92
- record.schemaVersion === 1 &&
93
- record.fingerprint === fingerprint &&
94
- record.id === check.id &&
95
- record.status === 'passed'
96
- )
97
- return {
98
- status: 'passed',
99
- cached: true,
100
- milliseconds: 0,
101
- reason: 'Matching deterministic check inputs',
102
- };
103
- } catch {}
104
- return null;
105
- },
106
- commit(results) {
107
- for (const result of results) {
108
- const fingerprint = pending.get(result.id);
109
- if (!fingerprint || result.status !== 'passed' || result.cached) continue;
110
- mkdirSync(directory, { recursive: true });
111
- const target = join(directory, `${fingerprint}.json`);
112
- const temporary = `${target}.${randomUUID()}.tmp`;
113
- writeFileSync(
114
- temporary,
115
- JSON.stringify({ schemaVersion: 1, id: result.id, fingerprint, status: 'passed' }),
116
- );
117
- renameSync(temporary, target);
118
- }
119
- },
120
- };
121
- }
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { mkdirSync, readFileSync, writeFileSync, renameSync } from 'node:fs';
3
+ import { join, resolve } from 'node:path';
4
+ import { builtins, classify, matches, workspaceFiles } from './graph.mjs';
5
+
6
+ const diagnostics = new Set(['format', 'lint', 'styles', 'translations', 'deadcode', 'workflows']);
7
+ const fresh = new Set([
8
+ 'security',
9
+ 'build',
10
+ 'size',
11
+ 'unit',
12
+ 'e2e',
13
+ 'visual',
14
+ 'lighthouse',
15
+ 'database',
16
+ 'a11y',
17
+ 'dependency-consistency',
18
+ ]);
19
+
20
+ export function checkCache(root, config, selection, state, { disabled = false } = {}) {
21
+ const pending = new Map();
22
+ const directory = join(root, '.tooling/state/checks');
23
+ function eligible(check) {
24
+ const kind = check.kind ?? check.id;
25
+ if (
26
+ disabled ||
27
+ config.execution?.checkCache === false ||
28
+ fresh.has(kind) ||
29
+ check.dependsOn?.length ||
30
+ check.cache === false
31
+ )
32
+ return false;
33
+ const overrides = config.checks?.[check.id];
34
+ if (
35
+ !check.cache &&
36
+ (!diagnostics.has(kind) ||
37
+ ['command', 'devCommand', 'devAllCommand'].some((name) => overrides?.[name] !== undefined))
38
+ )
39
+ return false;
40
+ return Boolean(check.cache || builtins[kind]);
41
+ }
42
+ function key(check, command, files) {
43
+ if (!eligible(check)) return null;
44
+ const all = Object.keys(state.files);
45
+ const scoped = new Set(workspaceFiles(config, check.workspaces, all));
46
+ const patterns = typeof check.cache === 'object' ? check.cache.inputs : null;
47
+ const input = all
48
+ .filter((file) => {
49
+ // Config, lockfiles and unknown paths always invalidate, even for narrowed input sets.
50
+ const global = classify([file], config).some((group) =>
51
+ ['tooling', 'dependencies', 'unknown'].includes(group),
52
+ );
53
+ return (
54
+ global ||
55
+ (patterns ? patterns.some((pattern) => matches(file, pattern)) : scoped.has(file))
56
+ );
57
+ })
58
+ .sort()
59
+ .map((file) => [file, state.files[file]]);
60
+ const tools = new Set([
61
+ ...(check.tools ?? []),
62
+ ...(Array.isArray(command) ? [command[0]] : []),
63
+ ]);
64
+ const identities = state.tools.filter(
65
+ (tool) => tools.has(tool.name) && tool.cwd === resolve(root, check.cwd ?? '.'),
66
+ );
67
+ const { files: _selection, ...definition } = check;
68
+ return createHash('sha256')
69
+ .update(
70
+ JSON.stringify({
71
+ schemaVersion: 1,
72
+ context: state.context,
73
+ check: definition,
74
+ command,
75
+ profile: selection.profile,
76
+ files,
77
+ input,
78
+ tools: identities,
79
+ }),
80
+ )
81
+ .digest('hex');
82
+ }
83
+ return {
84
+ reusablePass: selection.checks.every(eligible),
85
+ get(check, command, files) {
86
+ const fingerprint = key(check, command, files);
87
+ if (!fingerprint) return null;
88
+ pending.set(check.id, fingerprint);
89
+ try {
90
+ const record = JSON.parse(readFileSync(join(directory, `${fingerprint}.json`), 'utf8'));
91
+ if (
92
+ record.schemaVersion === 1 &&
93
+ record.fingerprint === fingerprint &&
94
+ record.id === check.id &&
95
+ record.status === 'passed'
96
+ )
97
+ return {
98
+ status: 'passed',
99
+ cached: true,
100
+ milliseconds: 0,
101
+ reason: 'Matching deterministic check inputs',
102
+ };
103
+ } catch {}
104
+ return null;
105
+ },
106
+ commit(results) {
107
+ for (const result of results) {
108
+ const fingerprint = pending.get(result.id);
109
+ if (!fingerprint || result.status !== 'passed' || result.cached) continue;
110
+ mkdirSync(directory, { recursive: true });
111
+ const target = join(directory, `${fingerprint}.json`);
112
+ const temporary = `${target}.${randomUUID()}.tmp`;
113
+ writeFileSync(
114
+ temporary,
115
+ JSON.stringify({ schemaVersion: 1, id: result.id, fingerprint, status: 'passed' }),
116
+ );
117
+ renameSync(temporary, target);
118
+ }
119
+ },
120
+ };
121
+ }
@@ -1,54 +1,54 @@
1
- import { appendFileSync, existsSync, readFileSync } from 'node:fs';
2
- import { createHash, randomUUID } from 'node:crypto';
3
- import { pathToFileURL } from 'node:url';
4
- import { join } from 'node:path';
5
- import { browserChecks } from './browsers.mjs';
6
- import { inside, loadConfig } from './config.mjs';
7
-
8
- export function planMetadata(root, selection, config, lock = {}) {
9
- const active = Boolean(selection.checks.length || selection.excluded.length);
10
- const browsers = browserChecks(selection).length > 0;
11
- const versions = Object.entries(lock.packages ?? {})
12
- .filter(([path]) => /node_modules\/(?:@playwright\/test|playwright(?:-core)?)$/.test(path))
13
- .map(([path, entry]) => [path, entry.version]);
14
- const paths = ['.tooling/cache/eslint/'];
15
- for (const path of config.execution?.typeScriptBuildInfo ?? []) {
16
- inside(root, path);
17
- if (/[\r\n]/.test(path) || !path.endsWith('.tsbuildinfo'))
18
- throw new Error('TypeScript cache paths must be repository-relative .tsbuildinfo patterns');
19
- paths.push(path);
20
- }
21
- return {
22
- active: String(active),
23
- browsers: String(browsers),
24
- history: String(config.history?.enabled !== false),
25
- 'browser-key': createHash('sha256')
26
- .update(JSON.stringify(versions.sort()))
27
- .digest('hex')
28
- .slice(0, 20),
29
- 'tool-cache-paths': paths.join('\n'),
30
- };
31
- }
32
-
33
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
34
- const root = process.cwd();
35
- const selection = JSON.parse(readFileSync(process.argv[2], 'utf8'));
36
- const { config } = loadConfig(root, process.env.CONFIG ?? 'tooling.config.json');
37
- const lockPath = join(root, 'package-lock.json');
38
- const metadata = planMetadata(
39
- root,
40
- selection,
41
- config,
42
- existsSync(lockPath) ? JSON.parse(readFileSync(lockPath, 'utf8')) : {},
43
- );
44
- for (const [name, value] of Object.entries(metadata)) {
45
- const delimiter = `tooling_${randomUUID()}`;
46
- if (process.env.GITHUB_OUTPUT)
47
- appendFileSync(process.env.GITHUB_OUTPUT, `${name}<<${delimiter}\n${value}\n${delimiter}\n`);
48
- }
49
- console.log(
50
- metadata.active === 'true'
51
- ? 'Plan requires validation'
52
- : 'Empty plan: installation and validation skipped',
53
- );
54
- }
1
+ import { appendFileSync, existsSync, readFileSync } from 'node:fs';
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { join } from 'node:path';
5
+ import { browserChecks } from './browsers.mjs';
6
+ import { inside, loadConfig } from './config.mjs';
7
+
8
+ export function planMetadata(root, selection, config, lock = {}) {
9
+ const active = Boolean(selection.checks.length || selection.excluded.length);
10
+ const browsers = browserChecks(selection).length > 0;
11
+ const versions = Object.entries(lock.packages ?? {})
12
+ .filter(([path]) => /node_modules\/(?:@playwright\/test|playwright(?:-core)?)$/.test(path))
13
+ .map(([path, entry]) => [path, entry.version]);
14
+ const paths = ['.tooling/cache/eslint/'];
15
+ for (const path of config.execution?.typeScriptBuildInfo ?? []) {
16
+ inside(root, path);
17
+ if (/[\r\n]/.test(path) || !path.endsWith('.tsbuildinfo'))
18
+ throw new Error('TypeScript cache paths must be repository-relative .tsbuildinfo patterns');
19
+ paths.push(path);
20
+ }
21
+ return {
22
+ active: String(active),
23
+ browsers: String(browsers),
24
+ history: String(config.history?.enabled !== false),
25
+ 'browser-key': createHash('sha256')
26
+ .update(JSON.stringify(versions.sort()))
27
+ .digest('hex')
28
+ .slice(0, 20),
29
+ 'tool-cache-paths': paths.join('\n'),
30
+ };
31
+ }
32
+
33
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
34
+ const root = process.cwd();
35
+ const selection = JSON.parse(readFileSync(process.argv[2], 'utf8'));
36
+ const { config } = loadConfig(root, process.env.CONFIG ?? 'tooling.config.json');
37
+ const lockPath = join(root, 'package-lock.json');
38
+ const metadata = planMetadata(
39
+ root,
40
+ selection,
41
+ config,
42
+ existsSync(lockPath) ? JSON.parse(readFileSync(lockPath, 'utf8')) : {},
43
+ );
44
+ for (const [name, value] of Object.entries(metadata)) {
45
+ const delimiter = `tooling_${randomUUID()}`;
46
+ if (process.env.GITHUB_OUTPUT)
47
+ appendFileSync(process.env.GITHUB_OUTPUT, `${name}<<${delimiter}\n${value}\n${delimiter}\n`);
48
+ }
49
+ console.log(
50
+ metadata.active === 'true'
51
+ ? 'Plan requires validation'
52
+ : 'Empty plan: installation and validation skipped',
53
+ );
54
+ }