wp-shakedown 0.0.0-stage → 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 (116) hide show
  1. package/LICENSE +340 -0
  2. package/README.md +74 -2
  3. package/dist/baseline.d.ts +6 -0
  4. package/dist/baseline.js +41 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +296 -0
  7. package/dist/diff.d.ts +8 -0
  8. package/dist/diff.js +26 -0
  9. package/dist/engines/config.d.ts +3 -0
  10. package/dist/engines/config.js +134 -0
  11. package/dist/engines/custom.d.ts +10 -0
  12. package/dist/engines/custom.js +286 -0
  13. package/dist/engines/eslint.d.ts +8 -0
  14. package/dist/engines/eslint.js +96 -0
  15. package/dist/engines/index.d.ts +2 -0
  16. package/dist/engines/index.js +14 -0
  17. package/dist/engines/integrity.d.ts +2 -0
  18. package/dist/engines/integrity.js +108 -0
  19. package/dist/engines/php-compat.d.ts +2 -0
  20. package/dist/engines/php-compat.js +26 -0
  21. package/dist/engines/php-lint.d.ts +6 -0
  22. package/dist/engines/php-lint.js +42 -0
  23. package/dist/engines/phpstan.d.ts +11 -0
  24. package/dist/engines/phpstan.js +103 -0
  25. package/dist/engines/stylelint.d.ts +4 -0
  26. package/dist/engines/stylelint.js +63 -0
  27. package/dist/engines/theme-check.d.ts +7 -0
  28. package/dist/engines/theme-check.js +109 -0
  29. package/dist/engines/theme-review.d.ts +24 -0
  30. package/dist/engines/theme-review.js +378 -0
  31. package/dist/engines/updates.d.ts +6 -0
  32. package/dist/engines/updates.js +78 -0
  33. package/dist/engines/vulnerabilities.d.ts +22 -0
  34. package/dist/engines/vulnerabilities.js +128 -0
  35. package/dist/engines/wp-json.d.ts +18 -0
  36. package/dist/engines/wp-json.js +134 -0
  37. package/dist/engines/wpcs.d.ts +7 -0
  38. package/dist/engines/wpcs.js +60 -0
  39. package/dist/exec.d.ts +12 -0
  40. package/dist/exec.js +19 -0
  41. package/dist/fingerprint.d.ts +10 -0
  42. package/dist/fingerprint.js +29 -0
  43. package/dist/health/install.d.ts +16 -0
  44. package/dist/health/install.js +68 -0
  45. package/dist/home.d.ts +2 -0
  46. package/dist/home.js +6 -0
  47. package/dist/hub.d.ts +32 -0
  48. package/dist/hub.js +99 -0
  49. package/dist/index.d.ts +42 -0
  50. package/dist/index.js +36 -0
  51. package/dist/js/files.d.ts +4 -0
  52. package/dist/js/files.js +47 -0
  53. package/dist/js/tools.d.ts +3 -0
  54. package/dist/js/tools.js +67 -0
  55. package/dist/mcp/server.d.ts +9 -0
  56. package/dist/mcp/server.js +91 -0
  57. package/dist/mcp/tools.d.ts +26 -0
  58. package/dist/mcp/tools.js +163 -0
  59. package/dist/net.d.ts +18 -0
  60. package/dist/net.js +68 -0
  61. package/dist/php/files.d.ts +3 -0
  62. package/dist/php/files.js +53 -0
  63. package/dist/php/php.d.ts +4 -0
  64. package/dist/php/php.js +25 -0
  65. package/dist/php/phpcs.d.ts +25 -0
  66. package/dist/php/phpcs.js +55 -0
  67. package/dist/php/tools.d.ts +3 -0
  68. package/dist/php/tools.js +66 -0
  69. package/dist/profiles.d.ts +4 -0
  70. package/dist/profiles.js +41 -0
  71. package/dist/progress.d.ts +3 -0
  72. package/dist/progress.js +13 -0
  73. package/dist/projects.d.ts +36 -0
  74. package/dist/projects.js +91 -0
  75. package/dist/report/escape.d.ts +1 -0
  76. package/dist/report/escape.js +4 -0
  77. package/dist/report/html.d.ts +2 -0
  78. package/dist/report/html.js +100 -0
  79. package/dist/report/json.d.ts +2 -0
  80. package/dist/report/json.js +3 -0
  81. package/dist/report/markdown.d.ts +5 -0
  82. package/dist/report/markdown.js +92 -0
  83. package/dist/report/sarif.d.ts +2 -0
  84. package/dist/report/sarif.js +44 -0
  85. package/dist/report/write.d.ts +9 -0
  86. package/dist/report/write.js +48 -0
  87. package/dist/runner.d.ts +14 -0
  88. package/dist/runner.js +166 -0
  89. package/dist/session.d.ts +22 -0
  90. package/dist/session.js +39 -0
  91. package/dist/target.d.ts +5 -0
  92. package/dist/target.js +114 -0
  93. package/dist/types.d.ts +165 -0
  94. package/dist/types.js +6 -0
  95. package/dist/ui/server.d.ts +13 -0
  96. package/dist/ui/server.js +458 -0
  97. package/dist/version.d.ts +1 -0
  98. package/dist/version.js +3 -0
  99. package/dist/versions.d.ts +9 -0
  100. package/dist/versions.js +35 -0
  101. package/js-tools/eslint.config.mjs +19 -0
  102. package/js-tools/package-lock.json +7004 -0
  103. package/js-tools/package.json +13 -0
  104. package/js-tools/stylelint.config.mjs +4 -0
  105. package/package.json +58 -4
  106. package/php-tools/composer.json +68 -0
  107. package/php-tools/composer.lock +889 -0
  108. package/php-tools/theme-check.php +239 -0
  109. package/ui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  110. package/ui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  111. package/ui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  112. package/ui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  113. package/ui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  114. package/ui/dist/assets/index-DXwdz_Wu.css +2 -0
  115. package/ui/dist/assets/index-V8IOqxHa.js +54 -0
  116. package/ui/dist/index.html +14 -0
package/dist/runner.js ADDED
@@ -0,0 +1,166 @@
1
+ import { statSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { applyBaseline } from './baseline.js';
4
+ import { assignIds } from './fingerprint.js';
5
+ import { unitLabel } from './target.js';
6
+ import { VERSION } from './version.js';
7
+ import { EngineSkipped } from './types.js';
8
+ const DEPTH_RANK = { quick: 1, standard: 2, deep: 3 };
9
+ const posix = (p) => p.split('\\').join('/');
10
+ /** An absolute path inside base becomes relative to it. Anything else stays as given. */
11
+ function relInside(base, p) {
12
+ if (!path.isAbsolute(p))
13
+ return p;
14
+ const r = path.relative(base, p);
15
+ return r === '' || r.startsWith('..') || path.isAbsolute(r) ? p : r;
16
+ }
17
+ function normaliseFile(file, job, root) {
18
+ if (job.unit) {
19
+ const unitRel = path.relative(root.path, job.unit.path);
20
+ // A one-file plugin: every finding points at the plugin file itself.
21
+ if (statSync(job.unit.path, { throwIfNoEntry: false })?.isFile())
22
+ return posix(unitRel);
23
+ return posix(path.join(unitRel, relInside(job.target.path, file)));
24
+ }
25
+ return posix(relInside(job.target.path, file));
26
+ }
27
+ function sortKey(f) {
28
+ return [f.location.file ?? f.location.url ?? '', f.location.line ?? 0, f.location.column ?? 0, f.engine, f.rule];
29
+ }
30
+ function compare(a, b) {
31
+ const x = sortKey(a);
32
+ const y = sortKey(b);
33
+ return ((x[0] < y[0] ? -1 : x[0] > y[0] ? 1 : 0) ||
34
+ x[1] - y[1] ||
35
+ x[2] - y[2] ||
36
+ (x[3] < y[3] ? -1 : x[3] > y[3] ? 1 : 0) ||
37
+ (x[4] < y[4] ? -1 : x[4] > y[4] ? 1 : 0));
38
+ }
39
+ export async function run(target, opts) {
40
+ const known = opts.engines.map((e) => e.id);
41
+ for (const id of opts.only ?? []) {
42
+ if (!known.includes(id))
43
+ throw new Error(`Unknown engine "${id}". Known engines: ${known.join(', ') || 'none'}.`);
44
+ }
45
+ const depth = opts.depth ?? 'standard';
46
+ const named = opts.only ? opts.engines.filter((e) => opts.only.includes(e.id)) : opts.engines;
47
+ // Engines named by hand skip the depth filter. A profile names engines too, but it keeps the filter.
48
+ const byHand = opts.only !== undefined && opts.profile === undefined;
49
+ const passes = (e) => byHand || (DEPTH_RANK[e.depth ?? 'standard'] <= DEPTH_RANK[depth] && (!e.experimental || opts.experimental === true));
50
+ const active = named.filter(passes);
51
+ const kindsHere = new Set([target.kind, ...target.units.map((u) => u.kind)]);
52
+ const leftOut = named.some((e) => !passes(e) && e.kinds.some((k) => kindsHere.has(k)));
53
+ const now = opts.now ?? (() => new Date());
54
+ const emit = opts.onEvent ?? (() => { });
55
+ const jobs = active.filter((e) => e.kinds.includes(target.kind)).map((engine) => ({ engine, target }));
56
+ if (target.kind === 'install') {
57
+ for (const unit of target.units) {
58
+ for (const engine of active)
59
+ if (engine.kinds.includes(unit.kind))
60
+ jobs.push({ engine, target: unit, unit });
61
+ }
62
+ }
63
+ const startedAt = now().toISOString();
64
+ emit({
65
+ type: 'run:start',
66
+ target,
67
+ jobs: jobs.map((j) => ({ engine: j.engine.id, ...(j.unit ? { unit: unitLabel(j.unit) } : {}) })),
68
+ });
69
+ const engineRuns = [];
70
+ const raw = [];
71
+ // shortcut: engines run one at a time. Run them in parallel once real engines make a run slow.
72
+ for (const job of jobs) {
73
+ if (opts.signal?.aborted)
74
+ break;
75
+ const unit = job.unit ? unitLabel(job.unit) : undefined;
76
+ emit({ type: 'engine:start', engine: job.engine.id, ...(unit ? { unit } : {}) });
77
+ const t0 = performance.now();
78
+ let status = 'ok';
79
+ let reason;
80
+ let found = [];
81
+ try {
82
+ found = await job.engine.run({
83
+ target: job.target,
84
+ ...(opts.profile ? { profile: opts.profile } : {}),
85
+ note: (message) => emit({ type: 'engine:note', engine: job.engine.id, ...(unit ? { unit } : {}), message }),
86
+ ...(opts.signal ? { signal: opts.signal } : {}),
87
+ });
88
+ }
89
+ catch (err) {
90
+ if (err instanceof EngineSkipped)
91
+ status = 'skipped';
92
+ else
93
+ status = 'failed';
94
+ reason = err instanceof Error ? err.message : String(err);
95
+ }
96
+ const variant = job.engine.variant?.(opts.profile);
97
+ const er = {
98
+ engine: job.engine.id,
99
+ ...(unit ? { unit } : {}),
100
+ status,
101
+ durationMs: Math.round(performance.now() - t0),
102
+ findings: found.length,
103
+ ...(reason !== undefined ? { reason } : {}),
104
+ ...(variant !== undefined ? { variant } : {}),
105
+ };
106
+ engineRuns.push(er);
107
+ for (const f of found) {
108
+ const location = { ...f.location };
109
+ if (location.file !== undefined)
110
+ location.file = normaliseFile(location.file, job, target);
111
+ raw.push({
112
+ ...f,
113
+ location,
114
+ engine: job.engine.id,
115
+ ...(unit ? { unit } : {}),
116
+ rerun: `wp-shakedown run "${target.path}" --engine ${job.engine.id}`,
117
+ });
118
+ }
119
+ emit({ type: 'engine:end', run: er });
120
+ }
121
+ let findings = assignIds(raw).sort(compare);
122
+ let staleBaseline = [];
123
+ if (opts.baseline) {
124
+ const applied = applyBaseline(findings, opts.baseline);
125
+ findings = applied.findings;
126
+ // An entry is only stale when every engine ran. After a partial run it may belong to an engine that did not.
127
+ const complete = !opts.only && !leftOut && engineRuns.length === jobs.length && engineRuns.every((e) => e.status === 'ok');
128
+ staleBaseline = complete ? applied.stale : [];
129
+ }
130
+ const summary = { error: 0, warning: 0, info: 0, suppressed: 0 };
131
+ for (const f of findings) {
132
+ if (f.suppressed)
133
+ summary.suppressed++;
134
+ else
135
+ summary[f.severity]++;
136
+ }
137
+ const result = {
138
+ schema: 1,
139
+ tool: { name: 'wp-shakedown', version: VERSION },
140
+ target: {
141
+ kind: target.kind,
142
+ path: target.path,
143
+ name: target.name,
144
+ units: target.units.map((u) => ({ kind: u.kind, name: u.name, path: posix(path.relative(target.path, u.path)) })),
145
+ },
146
+ ...(opts.profile ? { profile: opts.profile } : {}),
147
+ depth,
148
+ ...(opts.experimental ? { experimental: true } : {}),
149
+ startedAt,
150
+ finishedAt: now().toISOString(),
151
+ engines: engineRuns,
152
+ findings,
153
+ summary,
154
+ staleBaseline,
155
+ };
156
+ emit({ type: 'run:end', result });
157
+ return result;
158
+ }
159
+ const RANK = { error: 3, warning: 2, info: 1 };
160
+ export function exitCode(result, failOn) {
161
+ if (result.engines.some((e) => e.status === 'failed'))
162
+ return 2;
163
+ if (failOn !== 'never' && result.findings.some((f) => !f.suppressed && RANK[f.severity] >= RANK[failOn]))
164
+ return 1;
165
+ return 0;
166
+ }
@@ -0,0 +1,22 @@
1
+ import type { Depth, Engine, RunDiff, RunEvent, RunResult } from './types.ts';
2
+ export interface SessionOptions {
3
+ input: string;
4
+ type?: 'theme' | 'plugin' | 'install';
5
+ only?: string[];
6
+ profile?: string;
7
+ depth?: Depth;
8
+ experimental?: boolean;
9
+ out?: string;
10
+ baselineFile?: string;
11
+ engines: Engine[];
12
+ onEvent?: (e: RunEvent) => void;
13
+ signal?: AbortSignal;
14
+ }
15
+ export interface SessionResult {
16
+ result: RunResult;
17
+ diff?: RunDiff;
18
+ files: string[];
19
+ dir: string;
20
+ }
21
+ /** The steps from a path to written reports. The command line and the local server share them. */
22
+ export declare function runSession(opts: SessionOptions): Promise<SessionResult>;
@@ -0,0 +1,39 @@
1
+ import { existsSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { loadBaseline } from './baseline.js';
4
+ import { diffRuns } from './diff.js';
5
+ import { assertReportDir, defaultReportDir, readPreviousRun, writeReports } from './report/write.js';
6
+ import { profileEngines } from './profiles.js';
7
+ import { customEngines } from './engines/custom.js';
8
+ import { run } from './runner.js';
9
+ import { detectTarget } from './target.js';
10
+ /** The steps from a path to written reports. The command line and the local server share them. */
11
+ export async function runSession(opts) {
12
+ const target = detectTarget(opts.input, opts.type ? { type: opts.type } : {});
13
+ if (opts.profile && opts.only)
14
+ throw new Error('Use a profile or a list of engines, not both.');
15
+ const only = opts.profile ? profileEngines(opts.profile, target) : opts.only;
16
+ let baselineFile = opts.baselineFile;
17
+ if (!baselineFile && target.kind !== 'url') {
18
+ const candidate = path.join(target.path, 'wp-shakedown-baseline.json');
19
+ if (existsSync(candidate))
20
+ baselineFile = candidate;
21
+ }
22
+ const baseline = baselineFile ? loadBaseline(baselineFile) : undefined;
23
+ const dir = opts.out ?? defaultReportDir(target);
24
+ assertReportDir(target, dir);
25
+ const previous = readPreviousRun(dir);
26
+ const result = await run(target, {
27
+ engines: [...opts.engines, ...customEngines(target)],
28
+ ...(only ? { only } : {}),
29
+ ...(opts.profile ? { profile: opts.profile } : {}),
30
+ ...(opts.depth ? { depth: opts.depth } : {}),
31
+ ...(opts.experimental ? { experimental: true } : {}),
32
+ ...(baseline ? { baseline } : {}),
33
+ ...(opts.onEvent ? { onEvent: opts.onEvent } : {}),
34
+ ...(opts.signal ? { signal: opts.signal } : {}),
35
+ });
36
+ const diff = previous ? diffRuns(previous, result) : undefined;
37
+ const files = writeReports(result, dir, diff);
38
+ return { result, ...(diff ? { diff } : {}), files, dir };
39
+ }
@@ -0,0 +1,5 @@
1
+ import type { Target } from './types.ts';
2
+ export declare function detectTarget(input: string, opts?: {
3
+ type?: 'theme' | 'plugin' | 'install';
4
+ }): Target;
5
+ export declare function unitLabel(unit: Target): string;
package/dist/target.js ADDED
@@ -0,0 +1,114 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync, openSync, readSync, closeSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ const THEME_RE = /^[ \t\/*#@]*Theme Name:\s*(.+)$/im;
4
+ const PLUGIN_RE = /^[ \t\/*#@]*Plugin Name:\s*(.+)$/im;
5
+ function head(file) {
6
+ const fd = openSync(file, 'r');
7
+ try {
8
+ const buf = Buffer.alloc(8192);
9
+ const n = readSync(fd, buf, 0, 8192, 0);
10
+ return buf.subarray(0, n).toString('utf8');
11
+ }
12
+ finally {
13
+ closeSync(fd);
14
+ }
15
+ }
16
+ function isDir(p) {
17
+ try {
18
+ return statSync(p).isDirectory();
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ function isFile(p) {
25
+ try {
26
+ return statSync(p).isFile();
27
+ }
28
+ catch {
29
+ return false;
30
+ }
31
+ }
32
+ /** The header value, without the comment end of a one-line header. */
33
+ function headerValue(re, file) {
34
+ return re.exec(head(file))?.[1]?.replace(/\*\/\s*$/, '').trim() || undefined;
35
+ }
36
+ function themeName(dir) {
37
+ const css = path.join(dir, 'style.css');
38
+ if (!isFile(css))
39
+ return undefined;
40
+ return headerValue(THEME_RE, css);
41
+ }
42
+ function visible(dir) {
43
+ try {
44
+ return readdirSync(dir).filter((n) => !n.startsWith('.')).sort();
45
+ }
46
+ catch {
47
+ return [];
48
+ }
49
+ }
50
+ /** First top-level PHP file with a Plugin Name header, in sorted order. */
51
+ function pluginName(dir) {
52
+ for (const n of visible(dir)) {
53
+ const f = path.join(dir, n);
54
+ if (!n.endsWith('.php') || !isFile(f))
55
+ continue;
56
+ const name = headerValue(PLUGIN_RE, f);
57
+ if (name)
58
+ return name;
59
+ }
60
+ return undefined;
61
+ }
62
+ function discoverUnits(root) {
63
+ const units = [];
64
+ // shortcut: reads wp-content at the install root and skips mu-plugins. Read WP_CONTENT_DIR from wp-config.php when someone has a relocated content folder.
65
+ const themes = path.join(root, 'wp-content', 'themes');
66
+ for (const n of visible(themes)) {
67
+ const p = path.join(themes, n);
68
+ if (!isDir(p))
69
+ continue;
70
+ units.push({ kind: 'theme', path: p, name: themeName(p) ?? n, units: [] });
71
+ }
72
+ const plugins = path.join(root, 'wp-content', 'plugins');
73
+ for (const n of visible(plugins)) {
74
+ const p = path.join(plugins, n);
75
+ if (isDir(p)) {
76
+ units.push({ kind: 'plugin', path: p, name: pluginName(p) ?? n, units: [] });
77
+ }
78
+ else if (n.endsWith('.php') && isFile(p)) {
79
+ const name = headerValue(PLUGIN_RE, p);
80
+ if (name)
81
+ units.push({ kind: 'plugin', path: p, name, units: [] });
82
+ }
83
+ }
84
+ return units;
85
+ }
86
+ export function detectTarget(input, opts = {}) {
87
+ if (/^https?:\/\//.test(input)) {
88
+ return { kind: 'url', path: input, name: new URL(input).host, units: [] };
89
+ }
90
+ const abs = path.resolve(input);
91
+ if (!isDir(abs))
92
+ throw new Error(`"${input}" is not a folder.`);
93
+ const base = path.basename(abs);
94
+ let kind = opts.type;
95
+ let name;
96
+ if (!kind) {
97
+ if (existsSync(path.join(abs, 'wp-includes', 'version.php')))
98
+ kind = 'install';
99
+ else if ((name = themeName(abs)))
100
+ kind = 'theme';
101
+ else if ((name = pluginName(abs)))
102
+ kind = 'plugin';
103
+ else {
104
+ throw new Error(`Cannot tell what "${input}" is. It has no wp-includes/version.php, no style.css with a Theme Name header and no PHP file with a Plugin Name header. Pass --type theme, --type plugin or --type install.`);
105
+ }
106
+ }
107
+ if (kind === 'install')
108
+ return { kind, path: abs, name: base, units: discoverUnits(abs) };
109
+ name ??= kind === 'theme' ? themeName(abs) : pluginName(abs);
110
+ return { kind, path: abs, name: name ?? base, units: [] };
111
+ }
112
+ export function unitLabel(unit) {
113
+ return `${unit.kind}:${path.basename(unit.path).replace(/\.php$/, '')}`;
114
+ }
@@ -0,0 +1,165 @@
1
+ export declare const SEVERITIES: readonly ['error', 'warning', 'info'];
2
+ export type Severity = (typeof SEVERITIES)[number];
3
+ export type Category = 'security' | 'compatibility' | 'standards' | 'correctness' | 'performance' | 'accessibility' | 'i18n' | 'health' | 'other';
4
+ /** How thorough a run is. Each depth runs everything the one before it runs. */
5
+ export declare const DEPTHS: readonly ['quick', 'standard', 'deep'];
6
+ export type Depth = (typeof DEPTHS)[number];
7
+ export type TargetKind = 'theme' | 'plugin' | 'install' | 'url';
8
+ export interface Target {
9
+ kind: TargetKind;
10
+ /** Absolute path of the folder. A one-file plugin has the path of its PHP file. A 'url' target has the URL. */
11
+ path: string;
12
+ /** Name from the theme or plugin header, the folder name otherwise. */
13
+ name: string;
14
+ /** Themes and plugins found inside an install. Empty for every other kind. */
15
+ units: Target[];
16
+ }
17
+ export interface Location {
18
+ /** POSIX path relative to the root target. */
19
+ file?: string;
20
+ line?: number;
21
+ column?: number;
22
+ url?: string;
23
+ selector?: string;
24
+ }
25
+ /** What an engine returns. `location.file` is relative to the target the engine was given. */
26
+ export interface RawFinding {
27
+ rule: string;
28
+ severity: Severity;
29
+ category: Category;
30
+ message: string;
31
+ location: Location;
32
+ hint?: string;
33
+ docs?: string;
34
+ }
35
+ export interface Finding extends RawFinding {
36
+ /** Stable between runs. The line is not part of it, so edits above a finding keep its ID. */
37
+ id: string;
38
+ engine: string;
39
+ /** Set when the finding belongs to a theme or plugin inside an install, as `theme:<folder>` or `plugin:<folder>`. */
40
+ unit?: string;
41
+ /** Command that runs the engine that produced this finding again. */
42
+ rerun: string;
43
+ suppressed?: {
44
+ reason: string;
45
+ };
46
+ }
47
+ export interface EngineContext {
48
+ target: Target;
49
+ /** ID of the profile the run uses, when it uses one. */
50
+ profile?: string;
51
+ signal?: AbortSignal;
52
+ /** Tells the user something while the engine runs, for example that tools are being installed. */
53
+ note(message: string): void;
54
+ }
55
+ export interface Engine {
56
+ id: string;
57
+ title: string;
58
+ kinds: readonly TargetKind[];
59
+ /** The lightest depth that runs the engine. Absent means standard. */
60
+ depth?: Depth;
61
+ /** Runs only when the user turns experimental checks on, or names the engine. */
62
+ experimental?: true;
63
+ /** Names the variant of its tool the engine runs under a profile. Two runs are compared only when the variants match. */
64
+ variant?(profile: string | undefined): string | undefined;
65
+ run(ctx: EngineContext): Promise<RawFinding[]>;
66
+ }
67
+ /** The engines that matter for one gate, for example the theme directory of wordpress.org. */
68
+ export interface Profile {
69
+ id: string;
70
+ title: string;
71
+ /** One sentence that says what the profile is for. */
72
+ summary: string;
73
+ /** The kinds of target the profile fits. */
74
+ kinds: readonly TargetKind[];
75
+ /** IDs of the engines the profile runs. */
76
+ engines: readonly string[];
77
+ }
78
+ /** An engine throws this when it cannot run here, for example when PHP is missing. The run continues. */
79
+ export declare class EngineSkipped extends Error {
80
+ }
81
+ export type EngineStatus = 'ok' | 'skipped' | 'failed';
82
+ export interface EngineRun {
83
+ engine: string;
84
+ unit?: string;
85
+ status: EngineStatus;
86
+ durationMs: number;
87
+ findings: number;
88
+ /** Why the engine was skipped or how it failed. */
89
+ reason?: string;
90
+ /** Set when the engine ran a variant of its tool, for example the Envato fork of Theme Check. */
91
+ variant?: string;
92
+ }
93
+ export interface Summary {
94
+ error: number;
95
+ warning: number;
96
+ info: number;
97
+ suppressed: number;
98
+ }
99
+ export interface RunResult {
100
+ schema: 1;
101
+ tool: {
102
+ name: 'wp-shakedown';
103
+ version: string;
104
+ };
105
+ target: {
106
+ kind: TargetKind;
107
+ path: string;
108
+ name: string;
109
+ /** `path` here is relative to the root target. */
110
+ units: {
111
+ kind: TargetKind;
112
+ name: string;
113
+ path: string;
114
+ }[];
115
+ };
116
+ /** ID of the profile the run used. Absent when the run used none. */
117
+ profile?: string;
118
+ /** Absent in a report written before depth existed. Read that as standard. */
119
+ depth?: Depth;
120
+ /** True when the run had experimental checks on. */
121
+ experimental?: true;
122
+ startedAt: string;
123
+ finishedAt: string;
124
+ engines: EngineRun[];
125
+ findings: Finding[];
126
+ summary: Summary;
127
+ /** Baseline entries that matched no finding in this run. */
128
+ staleBaseline: string[];
129
+ }
130
+ export type RunEvent = {
131
+ type: 'run:start';
132
+ target: Target;
133
+ jobs: {
134
+ engine: string;
135
+ unit?: string;
136
+ }[];
137
+ } | {
138
+ type: 'engine:start';
139
+ engine: string;
140
+ unit?: string;
141
+ } | {
142
+ type: 'engine:note';
143
+ engine: string;
144
+ unit?: string;
145
+ message: string;
146
+ } | {
147
+ type: 'engine:end';
148
+ run: EngineRun;
149
+ } | {
150
+ type: 'run:end';
151
+ result: RunResult;
152
+ };
153
+ export interface BaselineEntry {
154
+ id: string;
155
+ reason: string;
156
+ }
157
+ export interface Baseline {
158
+ schema: 1;
159
+ entries: BaselineEntry[];
160
+ }
161
+ export interface RunDiff {
162
+ fixed: Finding[];
163
+ added: Finding[];
164
+ open: Finding[];
165
+ }
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ export const SEVERITIES = ['error', 'warning', 'info'];
2
+ /** How thorough a run is. Each depth runs everything the one before it runs. */
3
+ export const DEPTHS = ['quick', 'standard', 'deep'];
4
+ /** An engine throws this when it cannot run here, for example when PHP is missing. The run continues. */
5
+ export class EngineSkipped extends Error {
6
+ }
@@ -0,0 +1,13 @@
1
+ import type { Engine } from '../types.ts';
2
+ export interface UiServer {
3
+ url: string;
4
+ port: number;
5
+ token: string;
6
+ close(): Promise<void>;
7
+ }
8
+ export declare function startUi(opts: {
9
+ engines: Engine[];
10
+ port?: number;
11
+ startDir?: string;
12
+ token?: string;
13
+ }): Promise<UiServer>;