@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
package/runner/graph.mjs CHANGED
@@ -1,243 +1,250 @@
1
- import { defaults } from './config.mjs';
2
- import { fileURLToPath } from 'node:url';
3
-
4
- const script = (name) => ['node', fileURLToPath(new URL(`../checks/${name}.mjs`, import.meta.url))];
5
- const patterns = new Map();
6
-
7
- function compile(pattern) {
8
- let regex = '^';
9
- for (let i = 0; i < pattern.length; i++) {
10
- const c = pattern[i];
11
- if (c === '*' && pattern[i + 1] === '*') {
12
- i++;
13
- if (pattern[i + 1] === '/') {
14
- i++;
15
- regex += '(?:.*/)?';
16
- } else regex += '.*';
17
- } else if (c === '*') regex += '[^/]*';
18
- else if (c === '?') regex += '[^/]';
19
- else regex += c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
20
- }
21
- return new RegExp(`${regex}$`);
22
- }
23
-
24
- export function matches(file, pattern) {
25
- let regex = patterns.get(pattern);
26
- if (!regex) {
27
- regex = compile(pattern);
28
- if (patterns.size >= 2048) patterns.clear();
29
- patterns.set(pattern, regex);
30
- }
31
- return regex.test(file.replaceAll('\\', '/'));
32
- }
33
-
34
- export function workspaceClosure(config, names) {
35
- const closure = new Set();
36
- const visit = (name, chain = []) => {
37
- const workspace = config.workspaces?.[name];
38
- if (!workspace) throw new Error(`Unknown workspace: ${name}`);
39
- if (chain.includes(name))
40
- throw new Error(`Cyclic workspaces: ${[...chain, name].join(' -> ')}`);
41
- if (closure.has(name)) return;
42
- for (const dependency of workspace.dependsOn ?? []) visit(dependency, [...chain, name]);
43
- closure.add(name);
44
- };
45
- names.forEach((name) => visit(name));
46
- return [...closure];
47
- }
48
-
49
- export function workspaceFiles(config, names, files) {
50
- if (files === 'all' || !names?.length) return files;
51
- const paths = workspaceClosure(config, names).flatMap((name) => config.workspaces[name].paths);
52
- return files.filter((file) => {
53
- if (paths.some((pattern) => matches(file, pattern))) return true;
54
- const owned = Object.values(config.workspaces ?? {}).some((workspace) =>
55
- workspace.paths.some((pattern) => matches(file, pattern)),
56
- );
57
- // Unassigned source is conservatively shared; root documentation remains formatting-only.
58
- return !owned && classify([file], config).some((group) => group !== 'docs');
59
- });
60
- }
61
-
62
- export function classify(files, config = {}) {
63
- if (files === 'all') return ['all'];
64
- const paths = { ...defaults, ...config.paths };
65
- const groups = new Set();
66
- for (const file of files) {
67
- const found = Object.entries(paths)
68
- .filter(([, patterns]) => patterns.some((p) => matches(file, p)))
69
- .map(([key]) => key);
70
- if (found.includes('docs')) groups.add('docs');
71
- else if (found.includes('styles')) groups.add('styles');
72
- else if (found.includes('translations')) groups.add('translations');
73
- else if (found.length) found.forEach((g) => groups.add(g));
74
- else if (
75
- Object.values(config.workspaces ?? {}).some((workspace) =>
76
- workspace.paths.some((pattern) => matches(file, pattern)),
77
- )
78
- )
79
- groups.add('app');
80
- else groups.add('unknown');
81
- }
82
- return [...groups].sort();
83
- }
84
-
85
- const full = ['push', 'ci'];
86
- const all = ['dev', ...full];
87
- const check = (command, groups, extra = {}) => ({ command, groups, profiles: full, ...extra });
88
- export const builtins = {
89
- format: check(
90
- ['prettier', '--check', '.'],
91
- ['docs', 'styles', 'translations', 'app', 'database', 'functions', 'workflows'],
92
- {
93
- profiles: all,
94
- devCommand: ['prettier', '--check', '--ignore-unknown', '--'],
95
- devFiles: ['**/*'],
96
- },
97
- ),
98
- lint: check(
99
- ['eslint', '.', '--max-warnings', '0', '--cache', '--cache-strategy', 'content'],
100
- ['app', 'functions'],
101
- {
102
- profiles: all,
103
- devCommand: ['eslint', '--max-warnings', '0', '--cache', '--cache-strategy', 'content', '--'],
104
- devFiles: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.mjs'],
105
- },
106
- ),
107
- styles: check(script('lint-scss'), ['styles', 'app'], {
108
- profiles: all,
109
- devCommand: script('lint-scss'),
110
- devFiles: ['**/*.scss'],
111
- }),
112
- types: check(['tsc', '--build', '--pretty', 'false'], ['app', 'functions'], {
113
- resources: ['build'],
114
- }),
115
- unit: check(['vitest', 'run', '--coverage'], ['app', 'functions'], {
116
- profiles: all,
117
- devCommand: ['vitest', 'related', '--run', '--passWithNoTests'],
118
- devAllCommand: ['vitest', 'run'],
119
- devFiles: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.mjs'],
120
- }),
121
- translations: check(script('translations'), ['translations', 'app'], { profiles: all }),
122
- build: check(['npm', 'run', 'build'], ['app'], { resources: ['build'] }),
123
- size: check(['npm', 'run', 'size'], ['app'], { dependsOn: ['build'] }),
124
- deadcode: check(['knip'], ['app']),
125
- security: check(
126
- 'npm audit --audit-level=high && gitleaks git --redact',
127
- ['app', 'database', 'functions'],
128
- { tools: ['gitleaks'] },
129
- ),
130
- e2e: check(['playwright', 'test', '--grep-invert', '@visual'], ['app'], {
131
- dependsOn: ['build'],
132
- platforms: ['linux'],
133
- resources: ['browser'],
134
- }),
135
- visual: check(['playwright', 'test', '--grep', '@visual'], ['app'], {
136
- dependsOn: ['build'],
137
- platforms: ['linux'],
138
- resources: ['browser'],
139
- }),
140
- lighthouse: check(['lhci', 'autorun'], ['app'], {
141
- dependsOn: ['build'],
142
- tools: ['lhci'],
143
- platforms: ['linux'],
144
- resources: ['browser'],
145
- }),
146
- workflows: check(['actionlint', '-color'], ['workflows'], { tools: ['actionlint'] }),
147
- sass: check(script('sass'), ['styles', 'app'], { profiles: all }),
148
- architecture: check(script('architecture'), ['app', 'functions'], { profiles: all }),
149
- 'dependency-consistency': check(script('dependencies'), ['app', 'functions', 'dependencies']),
150
- a11y: check(script('a11y'), ['app'], {
151
- dependsOn: ['build'],
152
- resources: ['browser'],
153
- platforms: ['linux'],
154
- }),
155
- };
156
-
157
- const optIn = {
158
- sass: 'sass',
159
- architecture: 'architecture',
160
- 'dependency-consistency': 'dependencyConsistency',
161
- a11y: 'a11y',
162
- };
163
-
164
- export function plan(config, { files = 'all', profile = 'ci', only = [], skip = [] } = {}) {
165
- if (!['dev', 'push', 'ci'].includes(profile)) throw new Error(`Unknown profile: ${profile}`);
166
- const checks = Object.fromEntries(
167
- Object.entries({ ...builtins, ...config.checks })
168
- .filter(
169
- ([id, c]) =>
170
- c !== false &&
171
- (!optIn[c.extends ?? id] ||
172
- config[optIn[c.extends ?? id]] ||
173
- Object.hasOwn(config.checks ?? {}, id)),
174
- )
175
- .map(([id, c]) => {
176
- if (c.extends && !builtins[c.extends])
177
- throw new Error(`Unknown check preset: ${c.extends}`);
178
- return [id, { ...builtins[c.extends ?? id], ...c, kind: c.extends ?? id }];
179
- }),
180
- );
181
- for (const id of [...only, ...skip]) if (!checks[id]) throw new Error(`Unknown check: ${id}`);
182
- for (const [id, c] of Object.entries(checks))
183
- if (!c.command || !c.groups || !c.profiles)
184
- throw new Error(`Custom check ${id} needs command, groups and profiles`);
185
- const groups = classify(files, config);
186
- const broad = groups.some((g) => ['all', 'tooling', 'dependencies', 'unknown'].includes(g));
187
- const workspaces = Object.keys(config.workspaces ?? {});
188
- workspaceClosure(config, workspaces);
189
- for (const check of Object.values(checks)) workspaceClosure(config, check.workspaces ?? []);
190
- const affectedWorkspaces = workspaces.filter(
191
- (name) => broad || workspaceFiles(config, [name], files).length,
192
- );
193
- const scopedFiles = (c) => (broad ? files : workspaceFiles(config, c.workspaces, files));
194
- const required = new Set(
195
- Object.entries(checks)
196
- .filter(
197
- ([id, c]) =>
198
- c.profiles.includes(profile) &&
199
- (profile !== 'dev' ||
200
- c.kind !== 'translations' ||
201
- broad ||
202
- groups.includes('translations')) &&
203
- (broad || c.groups.some((g) => classify(scopedFiles(c), config).includes(g))),
204
- )
205
- .map(([id]) => id),
206
- );
207
- const wanted = new Set(only.length ? only : required);
208
- const expanded = new Set();
209
- const visit = (id, chain = []) => {
210
- if (!checks[id]) throw new Error(`Missing dependency: ${id}`);
211
- if (chain.includes(id)) throw new Error(`Cyclic checks: ${[...chain, id].join(' -> ')}`);
212
- if (expanded.has(id)) return;
213
- for (const dep of checks[id].dependsOn ?? []) {
214
- wanted.add(dep);
215
- visit(dep, [...chain, id]);
216
- }
217
- expanded.add(id);
218
- };
219
- [...wanted].forEach((id) => visit(id));
220
- const ordered = [];
221
- const seen = new Set();
222
- const order = (id) => {
223
- if (seen.has(id)) return;
224
- for (const dep of checks[id].dependsOn ?? []) order(dep);
225
- seen.add(id);
226
- ordered.push(id);
227
- };
228
- [...wanted].forEach(order);
229
- return {
230
- profile,
231
- groups,
232
- files,
233
- affectedWorkspaces,
234
- checks: ordered.map((id) => ({
235
- id,
236
- ...checks[id],
237
- files: scopedFiles(checks[id]),
238
- excluded: skip.includes(id),
239
- })),
240
- required: [...required],
241
- excluded: [...required].filter((id) => !wanted.has(id) || skip.includes(id)),
242
- };
243
- }
1
+ import { defaults } from './config.mjs';
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ const script = (name) => ['node', fileURLToPath(new URL(`../checks/${name}.mjs`, import.meta.url))];
5
+ const patterns = new Map();
6
+
7
+ function compile(pattern) {
8
+ let regex = '^';
9
+ for (let i = 0; i < pattern.length; i++) {
10
+ const c = pattern[i];
11
+ if (c === '*' && pattern[i + 1] === '*') {
12
+ i++;
13
+ if (pattern[i + 1] === '/') {
14
+ i++;
15
+ regex += '(?:.*/)?';
16
+ } else regex += '.*';
17
+ } else if (c === '*') regex += '[^/]*';
18
+ else if (c === '?') regex += '[^/]';
19
+ else regex += c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
20
+ }
21
+ return new RegExp(`${regex}$`);
22
+ }
23
+
24
+ export function matches(file, pattern) {
25
+ let regex = patterns.get(pattern);
26
+ if (!regex) {
27
+ regex = compile(pattern);
28
+ if (patterns.size >= 2048) patterns.clear();
29
+ patterns.set(pattern, regex);
30
+ }
31
+ return regex.test(file.replaceAll('\\', '/'));
32
+ }
33
+
34
+ export function workspaceClosure(config, names) {
35
+ const closure = new Set();
36
+ const visit = (name, chain = []) => {
37
+ const workspace = config.workspaces?.[name];
38
+ if (!workspace) throw new Error(`Unknown workspace: ${name}`);
39
+ if (chain.includes(name))
40
+ throw new Error(`Cyclic workspaces: ${[...chain, name].join(' -> ')}`);
41
+ if (closure.has(name)) return;
42
+ for (const dependency of workspace.dependsOn ?? []) visit(dependency, [...chain, name]);
43
+ closure.add(name);
44
+ };
45
+ names.forEach((name) => visit(name));
46
+ return [...closure];
47
+ }
48
+
49
+ export function workspaceFiles(config, names, files) {
50
+ if (files === 'all' || !names?.length) return files;
51
+ const paths = workspaceClosure(config, names).flatMap((name) => config.workspaces[name].paths);
52
+ return files.filter((file) => {
53
+ if (paths.some((pattern) => matches(file, pattern))) return true;
54
+ const owned = Object.values(config.workspaces ?? {}).some((workspace) =>
55
+ workspace.paths.some((pattern) => matches(file, pattern)),
56
+ );
57
+ // Unassigned source is conservatively shared; root documentation remains formatting-only.
58
+ return !owned && classify([file], config).some((group) => group !== 'docs');
59
+ });
60
+ }
61
+
62
+ export function classify(files, config = {}) {
63
+ if (files === 'all') return ['all'];
64
+ const paths = { ...defaults, ...config.paths };
65
+ const groups = new Set();
66
+ for (const file of files) {
67
+ const found = Object.entries(paths)
68
+ .filter(([, patterns]) => patterns.some((p) => matches(file, p)))
69
+ .map(([key]) => key);
70
+ if (found.includes('docs')) groups.add('docs');
71
+ else if (found.includes('styles')) groups.add('styles');
72
+ else if (found.includes('translations')) groups.add('translations');
73
+ else if (found.length) found.forEach((g) => groups.add(g));
74
+ else if (
75
+ Object.values(config.workspaces ?? {}).some((workspace) =>
76
+ workspace.paths.some((pattern) => matches(file, pattern)),
77
+ )
78
+ )
79
+ groups.add('app');
80
+ else groups.add('unknown');
81
+ }
82
+ return [...groups].sort();
83
+ }
84
+
85
+ const full = ['push', 'ci'];
86
+ const all = ['dev', ...full];
87
+ const check = (command, groups, extra = {}) => ({ command, groups, profiles: full, ...extra });
88
+ export const builtins = {
89
+ format: check(
90
+ ['prettier', '--check', '.'],
91
+ ['docs', 'styles', 'translations', 'app', 'database', 'functions', 'workflows'],
92
+ {
93
+ profiles: all,
94
+ devCommand: ['prettier', '--check', '--ignore-unknown', '--'],
95
+ devFiles: ['**/*'],
96
+ },
97
+ ),
98
+ lint: check(
99
+ ['eslint', '.', '--max-warnings', '0', '--cache', '--cache-strategy', 'content'],
100
+ ['app', 'functions'],
101
+ {
102
+ profiles: all,
103
+ devCommand: ['eslint', '--max-warnings', '0', '--cache', '--cache-strategy', 'content', '--'],
104
+ devFiles: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.mjs'],
105
+ },
106
+ ),
107
+ styles: check(script('lint-scss'), ['styles', 'app'], {
108
+ profiles: all,
109
+ devCommand: script('lint-scss'),
110
+ devFiles: ['**/*.scss'],
111
+ }),
112
+ types: check(['tsc', '--build', '--pretty', 'false'], ['app', 'functions'], {
113
+ resources: ['build'],
114
+ }),
115
+ unit: check(['vitest', 'run', '--coverage'], ['app', 'functions'], {
116
+ profiles: all,
117
+ devCommand: ['vitest', 'related', '--run', '--passWithNoTests'],
118
+ devAllCommand: ['vitest', 'run'],
119
+ devFiles: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.mjs'],
120
+ }),
121
+ translations: check(script('translations'), ['translations', 'app'], { profiles: all }),
122
+ build: check(['npm', 'run', 'build'], ['app'], { resources: ['build'] }),
123
+ size: check(['npm', 'run', 'size'], ['app'], { dependsOn: ['build'] }),
124
+ deadcode: check(['knip'], ['app']),
125
+ security: check(
126
+ 'npm audit --audit-level=high && gitleaks git --redact',
127
+ ['app', 'database', 'functions'],
128
+ { tools: ['gitleaks'] },
129
+ ),
130
+ e2e: check(['playwright', 'test', '--grep-invert', '@visual'], ['app'], {
131
+ dependsOn: ['build'],
132
+ platforms: ['linux'],
133
+ resources: ['browser'],
134
+ }),
135
+ visual: check(['playwright', 'test', '--grep', '@visual'], ['app'], {
136
+ dependsOn: ['build'],
137
+ platforms: ['linux'],
138
+ resources: ['browser'],
139
+ }),
140
+ lighthouse: check(['lhci', 'autorun'], ['app'], {
141
+ dependsOn: ['build'],
142
+ tools: ['lhci'],
143
+ platforms: ['linux'],
144
+ resources: ['browser'],
145
+ }),
146
+ workflows: check(['actionlint', '-color'], ['workflows'], { tools: ['actionlint'] }),
147
+ sass: check(script('sass'), ['styles', 'app'], { profiles: all }),
148
+ architecture: check(script('architecture'), ['app', 'functions'], { profiles: all }),
149
+ 'dependency-consistency': check(script('dependencies'), ['app', 'functions', 'dependencies']),
150
+ a11y: check(script('a11y'), ['app'], {
151
+ dependsOn: ['build'],
152
+ resources: ['browser'],
153
+ platforms: ['linux'],
154
+ }),
155
+ duplication: check(script('duplication'), ['app', 'styles'], {
156
+ profiles: all,
157
+ devCommand: script('duplication'),
158
+ devFiles: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx', '**/*.mjs', '**/*.scss', '**/*.css'],
159
+ tools: ['jscpd'],
160
+ }),
161
+ };
162
+
163
+ const optIn = {
164
+ sass: 'sass',
165
+ architecture: 'architecture',
166
+ 'dependency-consistency': 'dependencyConsistency',
167
+ a11y: 'a11y',
168
+ duplication: 'duplication',
169
+ };
170
+
171
+ export function plan(config, { files = 'all', profile = 'ci', only = [], skip = [] } = {}) {
172
+ if (!['dev', 'push', 'ci'].includes(profile)) throw new Error(`Unknown profile: ${profile}`);
173
+ const checks = Object.fromEntries(
174
+ Object.entries({ ...builtins, ...config.checks })
175
+ .filter(
176
+ ([id, c]) =>
177
+ c !== false &&
178
+ (!optIn[c.extends ?? id] ||
179
+ config[optIn[c.extends ?? id]] ||
180
+ Object.hasOwn(config.checks ?? {}, id)),
181
+ )
182
+ .map(([id, c]) => {
183
+ if (c.extends && !builtins[c.extends])
184
+ throw new Error(`Unknown check preset: ${c.extends}`);
185
+ return [id, { ...builtins[c.extends ?? id], ...c, kind: c.extends ?? id }];
186
+ }),
187
+ );
188
+ for (const id of [...only, ...skip]) if (!checks[id]) throw new Error(`Unknown check: ${id}`);
189
+ for (const [id, c] of Object.entries(checks))
190
+ if (!c.command || !c.groups || !c.profiles)
191
+ throw new Error(`Custom check ${id} needs command, groups and profiles`);
192
+ const groups = classify(files, config);
193
+ const broad = groups.some((g) => ['all', 'tooling', 'dependencies', 'unknown'].includes(g));
194
+ const workspaces = Object.keys(config.workspaces ?? {});
195
+ workspaceClosure(config, workspaces);
196
+ for (const check of Object.values(checks)) workspaceClosure(config, check.workspaces ?? []);
197
+ const affectedWorkspaces = workspaces.filter(
198
+ (name) => broad || workspaceFiles(config, [name], files).length,
199
+ );
200
+ const scopedFiles = (c) => (broad ? files : workspaceFiles(config, c.workspaces, files));
201
+ const required = new Set(
202
+ Object.entries(checks)
203
+ .filter(
204
+ ([id, c]) =>
205
+ c.profiles.includes(profile) &&
206
+ (profile !== 'dev' ||
207
+ c.kind !== 'translations' ||
208
+ broad ||
209
+ groups.includes('translations')) &&
210
+ (broad || c.groups.some((g) => classify(scopedFiles(c), config).includes(g))),
211
+ )
212
+ .map(([id]) => id),
213
+ );
214
+ const wanted = new Set(only.length ? only : required);
215
+ const expanded = new Set();
216
+ const visit = (id, chain = []) => {
217
+ if (!checks[id]) throw new Error(`Missing dependency: ${id}`);
218
+ if (chain.includes(id)) throw new Error(`Cyclic checks: ${[...chain, id].join(' -> ')}`);
219
+ if (expanded.has(id)) return;
220
+ for (const dep of checks[id].dependsOn ?? []) {
221
+ wanted.add(dep);
222
+ visit(dep, [...chain, id]);
223
+ }
224
+ expanded.add(id);
225
+ };
226
+ [...wanted].forEach((id) => visit(id));
227
+ const ordered = [];
228
+ const seen = new Set();
229
+ const order = (id) => {
230
+ if (seen.has(id)) return;
231
+ for (const dep of checks[id].dependsOn ?? []) order(dep);
232
+ seen.add(id);
233
+ ordered.push(id);
234
+ };
235
+ [...wanted].forEach(order);
236
+ return {
237
+ profile,
238
+ groups,
239
+ files,
240
+ affectedWorkspaces,
241
+ checks: ordered.map((id) => ({
242
+ id,
243
+ ...checks[id],
244
+ files: scopedFiles(checks[id]),
245
+ excluded: skip.includes(id),
246
+ })),
247
+ required: [...required],
248
+ excluded: [...required].filter((id) => !wanted.has(id) || skip.includes(id)),
249
+ };
250
+ }