wp-shakedown 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 (44) hide show
  1. package/README.md +15 -3
  2. package/dist/cli.js +160 -3
  3. package/dist/diff.d.ts +2 -1
  4. package/dist/diff.js +5 -3
  5. package/dist/engines/config.js +1 -0
  6. package/dist/engines/custom.d.ts +10 -0
  7. package/dist/engines/custom.js +286 -0
  8. package/dist/engines/index.js +3 -1
  9. package/dist/engines/php-lint.js +1 -0
  10. package/dist/engines/phpstan.js +1 -0
  11. package/dist/engines/theme-check.d.ts +7 -0
  12. package/dist/engines/theme-check.js +109 -0
  13. package/dist/engines/theme-review.d.ts +24 -0
  14. package/dist/engines/theme-review.js +378 -0
  15. package/dist/engines/updates.d.ts +2 -0
  16. package/dist/engines/updates.js +6 -0
  17. package/dist/engines/wp-json.js +1 -0
  18. package/dist/hub.d.ts +32 -0
  19. package/dist/hub.js +99 -0
  20. package/dist/index.d.ts +5 -1
  21. package/dist/index.js +5 -1
  22. package/dist/mcp/tools.js +16 -2
  23. package/dist/profiles.d.ts +4 -0
  24. package/dist/profiles.js +41 -0
  25. package/dist/projects.d.ts +36 -0
  26. package/dist/projects.js +91 -0
  27. package/dist/report/html.js +1 -1
  28. package/dist/report/markdown.js +1 -1
  29. package/dist/runner.d.ts +4 -1
  30. package/dist/runner.js +16 -2
  31. package/dist/session.d.ts +4 -1
  32. package/dist/session.js +10 -2
  33. package/dist/types.d.ts +30 -0
  34. package/dist/types.js +2 -0
  35. package/dist/ui/server.js +218 -55
  36. package/package.json +2 -1
  37. package/php-tools/composer.json +29 -1
  38. package/php-tools/composer.lock +22 -1
  39. package/php-tools/theme-check.php +239 -0
  40. package/ui/dist/assets/index-DXwdz_Wu.css +2 -0
  41. package/ui/dist/assets/index-V8IOqxHa.js +54 -0
  42. package/ui/dist/index.html +2 -2
  43. package/ui/dist/assets/index-7zN46ssH.js +0 -54
  44. package/ui/dist/assets/index-B1axZya5.css +0 -2
package/dist/hub.js ADDED
@@ -0,0 +1,99 @@
1
+ import path from 'node:path';
2
+ import { summaryLine } from './report/markdown.js';
3
+ import { exitCode } from './runner.js';
4
+ import { runSession } from './session.js';
5
+ /** Runs the sessions with at most `jobs` at a time. One run that throws makes that row failed and nothing more. */
6
+ export async function runMany(inputs, opts) {
7
+ const rows = inputs.map((p) => ({ name: path.basename(path.resolve(p)), path: p, state: 'waiting', total: 0, done: 0 }));
8
+ const change = (row, event) => opts.onChange?.(rows, row, event);
9
+ let next = 0;
10
+ const worker = async () => {
11
+ while (next < rows.length) {
12
+ const i = next++;
13
+ const row = rows[i];
14
+ row.state = 'running';
15
+ change(row);
16
+ try {
17
+ const s = await runSession({
18
+ ...opts.session,
19
+ input: inputs[i],
20
+ onEvent: (e) => {
21
+ if (e.type === 'run:start') {
22
+ row.name = e.target.name;
23
+ row.total = e.jobs.length;
24
+ }
25
+ else if (e.type === 'engine:start') {
26
+ row.current = `${e.engine}${e.unit ? ' ' + e.unit : ''}`;
27
+ }
28
+ else if (e.type === 'engine:end') {
29
+ row.done++;
30
+ delete row.current;
31
+ }
32
+ change(row, e);
33
+ },
34
+ });
35
+ row.state = 'done';
36
+ row.result = s.result;
37
+ row.name = s.result.target.name;
38
+ if (s.files[0])
39
+ row.reportFile = s.files[0];
40
+ }
41
+ catch (err) {
42
+ row.state = 'failed';
43
+ row.error = err instanceof Error ? err.message : String(err);
44
+ }
45
+ delete row.current;
46
+ change(row);
47
+ }
48
+ };
49
+ await Promise.all(Array.from({ length: Math.max(1, Math.min(opts.jobs, rows.length)) }, worker));
50
+ return rows;
51
+ }
52
+ /** One line per row for the live view. */
53
+ export function hubLines(rows, width) {
54
+ const pad = Math.max(0, ...rows.map((r) => r.name.length));
55
+ return rows.map((r) => {
56
+ const name = r.name.padEnd(pad);
57
+ let text;
58
+ if (r.state === 'waiting')
59
+ text = ` ${name} waiting`;
60
+ else if (r.state === 'running')
61
+ text = ` ${name} ${r.done}/${r.total}${r.current ? ' ' + r.current : ''}`;
62
+ else if (r.state === 'failed')
63
+ text = ` ${name} failed: ${r.error}`;
64
+ else {
65
+ const failed = r.result.engines.filter((e) => e.status === 'failed').length;
66
+ text = ` ${name} ${summaryLine(r.result)}${failed ? ` ${failed} ${failed === 1 ? 'engine' : 'engines'} failed.` : ''}`;
67
+ }
68
+ return text.slice(0, width);
69
+ });
70
+ }
71
+ /** 2 when a run failed or any run's exit code is 2, else 1 when any is 1, else 0. */
72
+ export function hubExitCode(rows, failOn) {
73
+ let code = 0;
74
+ for (const r of rows) {
75
+ const c = r.state === 'done' && r.result ? exitCode(r.result, failOn) : 2;
76
+ if (c > code)
77
+ code = c;
78
+ }
79
+ return code;
80
+ }
81
+ const pad2 = (n) => String(n).padStart(2, '0');
82
+ function localTime(iso) {
83
+ const d = new Date(iso);
84
+ return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
85
+ }
86
+ /** The text table of the project list: a header row and one row per project, columns padded with spaces. */
87
+ export function projectTable(projects) {
88
+ const kinds = { theme: 'theme', plugin: 'plugin', install: 'WordPress folder', url: 'site URL' };
89
+ const rows = [
90
+ ['ID', 'Name', 'Kind', 'Last run', 'Errors', 'Warnings', 'Notes', 'Path'],
91
+ ...projects.map((p) => {
92
+ const counts = p.last ? [p.last.summary.error, p.last.summary.warning, p.last.summary.info].map(String) : ['-', '-', '-'];
93
+ const when = p.problem ?? (p.last ? localTime(p.last.finishedAt) : 'never');
94
+ return [p.id, p.name, p.kind ? kinds[p.kind] : '-', when, ...(p.problem ? ['-', '-', '-'] : counts), p.path];
95
+ }),
96
+ ];
97
+ const widths = rows[0].map((_, c) => Math.max(...rows.map((r) => r[c].length)));
98
+ return rows.map((r) => r.map((cell, c) => (c === r.length - 1 ? cell : cell.padEnd(widths[c]))).join(' ').trimEnd()).join('\n');
99
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type * from './types.ts';
2
- export { SEVERITIES, EngineSkipped } from './types.ts';
2
+ export { SEVERITIES, DEPTHS, EngineSkipped } from './types.ts';
3
3
  export { detectTarget, unitLabel } from './target.ts';
4
4
  export { run, exitCode } from './runner.ts';
5
5
  export type { RunOptions } from './runner.ts';
@@ -20,8 +20,12 @@ export { toSarif } from './report/sarif.ts';
20
20
  export { toHtml } from './report/html.ts';
21
21
  export { assertReportDir, defaultReportDir, readPreviousRun, writeReports } from './report/write.ts';
22
22
  export { engines } from './engines/index.ts';
23
+ export { customEngines, globToRegExp } from './engines/custom.ts';
24
+ export { profiles, profileEngines } from './profiles.ts';
23
25
  export { home } from './home.ts';
24
26
  export { phpLint } from './engines/php-lint.ts';
27
+ export { themeCheck } from './engines/theme-check.ts';
28
+ export { themeReview } from './engines/theme-review.ts';
25
29
  export { wpcs } from './engines/wpcs.ts';
26
30
  export { phpCompat } from './engines/php-compat.ts';
27
31
  export { phpstan } from './engines/phpstan.ts';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { SEVERITIES, EngineSkipped } from './types.js';
1
+ export { SEVERITIES, DEPTHS, EngineSkipped } from './types.js';
2
2
  export { detectTarget, unitLabel } from './target.js';
3
3
  export { run, exitCode } from './runner.js';
4
4
  export { runSession } from './session.js';
@@ -14,8 +14,12 @@ export { toSarif } from './report/sarif.js';
14
14
  export { toHtml } from './report/html.js';
15
15
  export { assertReportDir, defaultReportDir, readPreviousRun, writeReports } from './report/write.js';
16
16
  export { engines } from './engines/index.js';
17
+ export { customEngines, globToRegExp } from './engines/custom.js';
18
+ export { profiles, profileEngines } from './profiles.js';
17
19
  export { home } from './home.js';
18
20
  export { phpLint } from './engines/php-lint.js';
21
+ export { themeCheck } from './engines/theme-check.js';
22
+ export { themeReview } from './engines/theme-review.js';
19
23
  export { wpcs } from './engines/wpcs.js';
20
24
  export { phpCompat } from './engines/php-compat.js';
21
25
  export { phpstan } from './engines/phpstan.js';
package/dist/mcp/tools.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import path from 'node:path';
2
2
  import { defaultReportDir, readPreviousRun } from '../report/write.js';
3
3
  import { toMarkdown } from '../report/markdown.js';
4
+ import { customEngines } from '../engines/custom.js';
5
+ import { profiles } from '../profiles.js';
4
6
  import { runSession } from '../session.js';
5
7
  import { detectTarget } from '../target.js';
6
8
  const MAX_TEXT = 60000;
@@ -50,7 +52,7 @@ export const tools = [
50
52
  description: 'Lists the checks wp-shakedown can run, with the ID to pass to run_checks.',
51
53
  inputSchema: schema({}, []),
52
54
  annotations: { readOnlyHint: true },
53
- handler: async (_args, ctx) => JSON.stringify(ctx.engines.map(({ id, title, kinds }) => ({ id, title, kinds })), null, 2),
55
+ handler: async (_args, ctx) => JSON.stringify([...ctx.engines, ...customEngines()].map(({ id, title, kinds, depth, experimental }) => ({ id, title, kinds, depth: depth ?? 'standard', ...(experimental ? { experimental: true } : {}) })), null, 2),
54
56
  },
55
57
  {
56
58
  name: 'run_checks',
@@ -59,6 +61,13 @@ export const tools = [
59
61
  inputSchema: schema({
60
62
  path: { type: 'string', description: 'Absolute path of the folder to test.' },
61
63
  engines: { type: 'array', items: { type: 'string' }, description: 'Engine IDs to run. Leave out to run all that fit.' },
64
+ profile: {
65
+ type: 'string',
66
+ enum: profiles.map((p) => p.id),
67
+ description: 'Run only the engines for one gate. ' + profiles.map((p) => `${p.id}: ${p.summary}`).join(' '),
68
+ },
69
+ depth: { type: 'string', enum: ['quick', 'standard', 'deep'], description: 'How thorough the run is. quick runs the fast checks, standard is the default, deep adds static analysis.' },
70
+ experimental: { type: 'boolean', description: 'Also run the experimental engines, such as theme-review.' },
62
71
  type: { type: 'string', enum: ['theme', 'plugin', 'install'], description: 'Use only when detection is wrong.' },
63
72
  }, ['path']),
64
73
  annotations: { readOnlyHint: false },
@@ -66,8 +75,9 @@ export const tools = [
66
75
  if (running)
67
76
  throw new Error('A run is in progress. Wait for it to finish.');
68
77
  const only = args.engines;
78
+ const all = [...ctx.engines, ...customEngines()];
69
79
  for (const id of only ?? []) {
70
- if (!ctx.engines.some((e) => e.id === id))
80
+ if (!all.some((e) => e.id === id))
71
81
  throw new Error(`Unknown engine "${id}". Call list_engines for the IDs.`);
72
82
  }
73
83
  running = true;
@@ -75,10 +85,14 @@ export const tools = [
75
85
  let total = 0;
76
86
  let done = 0;
77
87
  const type = args.type;
88
+ const depth = args.depth;
78
89
  const s = await runSession({
79
90
  input: args.path,
80
91
  ...(type ? { type } : {}),
81
92
  ...(only?.length ? { only } : {}),
93
+ ...(args.profile ? { profile: args.profile } : {}),
94
+ ...(depth ? { depth } : {}),
95
+ ...(args.experimental ? { experimental: true } : {}),
82
96
  engines: ctx.engines,
83
97
  signal: ctx.signal,
84
98
  onEvent: (e) => {
@@ -0,0 +1,4 @@
1
+ import type { Profile, Target } from './types.ts';
2
+ export declare const profiles: Profile[];
3
+ /** The engine IDs a profile runs on this target. Throws when the profile is unknown or does not fit the target. */
4
+ export declare function profileEngines(id: string, target: Target): string[];
@@ -0,0 +1,41 @@
1
+ export const profiles = [
2
+ {
3
+ id: 'wporg-theme',
4
+ title: 'WordPress.org theme directory',
5
+ summary: 'What the theme directory of wordpress.org checks before a review: Theme Check, PHP that parses, the WordPress standards and theme.json. With experimental checks on, also what reviewers ask for most.',
6
+ kinds: ['theme'],
7
+ engines: ['php-lint', 'theme-check', 'theme-review', 'wpcs', 'php-compat', 'wp-json'],
8
+ },
9
+ {
10
+ id: 'envato',
11
+ title: 'ThemeForest',
12
+ summary: 'What Envato checks on a theme for ThemeForest: its own version of Theme Check, PHP that parses, the WordPress standards and theme.json.',
13
+ kinds: ['theme'],
14
+ engines: ['php-lint', 'theme-check', 'wpcs', 'php-compat', 'wp-json'],
15
+ },
16
+ {
17
+ id: 'wporg-plugin',
18
+ title: 'WordPress.org plugin directory',
19
+ summary: 'What the plugin directory of wordpress.org checks in code: PHP that parses, the Plugin Check review rules and PHP versions.',
20
+ kinds: ['plugin'],
21
+ engines: ['php-lint', 'wpcs', 'php-compat'],
22
+ },
23
+ {
24
+ id: 'site',
25
+ title: 'WordPress site',
26
+ summary: 'Whether a WordPress folder is intact, current and safe to run. Leaves out code style in themes and plugins.',
27
+ kinds: ['install'],
28
+ engines: ['integrity', 'updates', 'vulnerabilities', 'config', 'php-lint', 'php-compat'],
29
+ },
30
+ ];
31
+ const KIND = { theme: 'a theme', plugin: 'a plugin', install: 'a WordPress folder', url: 'a site URL' };
32
+ /** The engine IDs a profile runs on this target. Throws when the profile is unknown or does not fit the target. */
33
+ export function profileEngines(id, target) {
34
+ const profile = profiles.find((p) => p.id === id);
35
+ if (!profile)
36
+ throw new Error(`Unknown profile "${id}". Known profiles: ${profiles.map((p) => p.id).join(', ')}.`);
37
+ if (!profile.kinds.includes(target.kind)) {
38
+ throw new Error(`The ${id} profile checks ${profile.kinds.map((k) => KIND[k]).join(' or ')}. "${target.name}" is ${KIND[target.kind]}.`);
39
+ }
40
+ return [...profile.engines];
41
+ }
@@ -0,0 +1,36 @@
1
+ import type { Depth, Summary, TargetKind } from './types.ts';
2
+ /** A folder the user keeps in the hub, with what the last run found. */
3
+ export interface Project {
4
+ /** Stable for a path. Short enough to type. */
5
+ id: string;
6
+ path: string;
7
+ name: string;
8
+ /** Absent when the folder is gone or is no longer a theme, a plugin or a WordPress folder. */
9
+ kind?: TargetKind;
10
+ /** Themes and plugins inside a WordPress folder. */
11
+ units: number;
12
+ /** Why the folder cannot be tested now. */
13
+ problem?: string;
14
+ last?: {
15
+ finishedAt: string;
16
+ summary: Summary;
17
+ /** Engines that failed, so the report is incomplete. */
18
+ failed: number;
19
+ profile?: string;
20
+ depth?: Depth;
21
+ /** The folder that holds the report files. */
22
+ dir: string;
23
+ };
24
+ }
25
+ export declare const projectId: (p: string) => string;
26
+ /** The projects in the order they were added, each with the result of its last run. */
27
+ export declare function listProjects(): Project[];
28
+ /** Adds a folder. Throws when it is not a theme, a plugin or a WordPress folder. `added` is false when it was there already. */
29
+ export declare function addProject(input: string, now?: () => Date): {
30
+ project: Project;
31
+ added: boolean;
32
+ };
33
+ /** Finds a project by its ID, its path or its name. A name that fits more than one project fits none. */
34
+ export declare function findProject(key: string): Project | undefined;
35
+ /** Takes a project off the list. Its reports stay. Returns false when no project fits. */
36
+ export declare function removeProject(key: string): boolean;
@@ -0,0 +1,91 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { home } from './home.js';
5
+ import { defaultReportDir, readPreviousRun } from './report/write.js';
6
+ import { detectTarget } from './target.js';
7
+ const file = () => path.join(home(), 'projects.json');
8
+ export const projectId = (p) => createHash('sha256').update(p).digest('hex').slice(0, 8);
9
+ function read() {
10
+ try {
11
+ const data = JSON.parse(readFileSync(file(), 'utf8'));
12
+ if (data?.schema === 1 && Array.isArray(data.projects)) {
13
+ return { schema: 1, projects: data.projects.filter((p) => typeof p?.path === 'string' && path.isAbsolute(p.path)) };
14
+ }
15
+ }
16
+ catch {
17
+ // No file yet, or one that cannot be read. Both mean an empty list.
18
+ }
19
+ return { schema: 1, projects: [] };
20
+ }
21
+ function write(data) {
22
+ mkdirSync(home(), { recursive: true });
23
+ // Write next to the file and rename, so a reader never sees half a file.
24
+ const tmp = `${file()}.${process.pid}.tmp`;
25
+ writeFileSync(tmp, JSON.stringify(data, null, 2) + '\n');
26
+ renameSync(tmp, file());
27
+ }
28
+ function describe(p) {
29
+ let target;
30
+ try {
31
+ target = detectTarget(p);
32
+ }
33
+ catch (err) {
34
+ return { id: projectId(p), path: p, name: path.basename(p), units: 0, problem: err instanceof Error ? err.message : String(err) };
35
+ }
36
+ const dir = defaultReportDir(target);
37
+ const run = readPreviousRun(dir);
38
+ return {
39
+ id: projectId(p),
40
+ path: p,
41
+ name: target.name,
42
+ kind: target.kind,
43
+ units: target.units.length,
44
+ ...(run
45
+ ? {
46
+ last: {
47
+ finishedAt: run.finishedAt,
48
+ summary: run.summary,
49
+ failed: run.engines.filter((e) => e.status === 'failed').length,
50
+ ...(run.profile ? { profile: run.profile } : {}),
51
+ ...(run.depth ? { depth: run.depth } : {}),
52
+ dir,
53
+ },
54
+ }
55
+ : {}),
56
+ };
57
+ }
58
+ /** The projects in the order they were added, each with the result of its last run. */
59
+ export function listProjects() {
60
+ return read().projects.map((p) => describe(p.path));
61
+ }
62
+ /** Adds a folder. Throws when it is not a theme, a plugin or a WordPress folder. `added` is false when it was there already. */
63
+ export function addProject(input, now = () => new Date()) {
64
+ const target = detectTarget(input);
65
+ const data = read();
66
+ const added = !data.projects.some((p) => p.path === target.path);
67
+ if (added) {
68
+ data.projects.push({ path: target.path, addedAt: now().toISOString() });
69
+ write(data);
70
+ }
71
+ return { project: describe(target.path), added };
72
+ }
73
+ /** Finds a project by its ID, its path or its name. A name that fits more than one project fits none. */
74
+ export function findProject(key) {
75
+ const all = listProjects();
76
+ const abs = path.resolve(key);
77
+ const exact = all.find((p) => p.id === key || p.path === abs);
78
+ if (exact)
79
+ return exact;
80
+ const named = all.filter((p) => p.name.toLowerCase() === key.toLowerCase());
81
+ return named.length === 1 ? named[0] : undefined;
82
+ }
83
+ /** Takes a project off the list. Its reports stay. Returns false when no project fits. */
84
+ export function removeProject(key) {
85
+ const found = findProject(key);
86
+ if (!found)
87
+ return false;
88
+ const data = read();
89
+ write({ schema: 1, projects: data.projects.filter((p) => p.path !== found.path) });
90
+ return true;
91
+ }
@@ -27,7 +27,7 @@ export function toHtml(result, diff) {
27
27
  const t = result.target;
28
28
  let body = `<h1>wp-shakedown report</h1>
29
29
  <p>Target: ${e(t.kind)} "${e(t.name)}" at ${e(t.path)}<br>
30
- Run: ${e(result.finishedAt)}, wp-shakedown ${e(result.tool.version)}</p>
30
+ ${result.profile ? `Profile: ${e(result.profile)}<br>\n` : ''}${result.depth && result.depth !== 'standard' ? `Depth: ${e(result.depth)}<br>\n` : ''}${result.experimental ? 'Experimental checks: on<br>\n' : ''}Run: ${e(result.finishedAt)}, wp-shakedown ${e(result.tool.version)}</p>
31
31
  <h2>Summary</h2>
32
32
  <p>${e(summaryLine(result))}</p>
33
33
  `;
@@ -20,7 +20,7 @@ function findingText(f) {
20
20
  export function toMarkdown(result, diff) {
21
21
  const out = [];
22
22
  out.push('# wp-shakedown report');
23
- out.push(`- Target: ${result.target.kind} "${result.target.name}" at ${result.target.path}\n- Run: ${result.finishedAt}, wp-shakedown ${result.tool.version}`);
23
+ out.push(`- Target: ${result.target.kind} "${result.target.name}" at ${result.target.path}${result.profile ? `\n- Profile: ${result.profile}` : ''}${result.depth && result.depth !== 'standard' ? `\n- Depth: ${result.depth}` : ''}${result.experimental ? '\n- Experimental checks: on' : ''}\n- Run: ${result.finishedAt}, wp-shakedown ${result.tool.version}`);
24
24
  const summary = ['## Summary', summaryLine(result)];
25
25
  if (result.engines.length === 0) {
26
26
  summary.push(noEngineLine(result));
package/dist/runner.d.ts CHANGED
@@ -1,7 +1,10 @@
1
- import type { Baseline, Engine, RunEvent, RunResult, Severity, Target } from './types.ts';
1
+ import type { Baseline, Depth, Engine, RunEvent, RunResult, Severity, Target } from './types.ts';
2
2
  export interface RunOptions {
3
3
  engines: Engine[];
4
4
  only?: string[];
5
+ profile?: string;
6
+ depth?: Depth;
7
+ experimental?: boolean;
5
8
  baseline?: Baseline;
6
9
  signal?: AbortSignal;
7
10
  onEvent?: (e: RunEvent) => void;
package/dist/runner.js CHANGED
@@ -5,6 +5,7 @@ import { assignIds } from './fingerprint.js';
5
5
  import { unitLabel } from './target.js';
6
6
  import { VERSION } from './version.js';
7
7
  import { EngineSkipped } from './types.js';
8
+ const DEPTH_RANK = { quick: 1, standard: 2, deep: 3 };
8
9
  const posix = (p) => p.split('\\').join('/');
9
10
  /** An absolute path inside base becomes relative to it. Anything else stays as given. */
10
11
  function relInside(base, p) {
@@ -41,7 +42,14 @@ export async function run(target, opts) {
41
42
  if (!known.includes(id))
42
43
  throw new Error(`Unknown engine "${id}". Known engines: ${known.join(', ') || 'none'}.`);
43
44
  }
44
- const active = opts.only ? opts.engines.filter((e) => opts.only.includes(e.id)) : opts.engines;
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)));
45
53
  const now = opts.now ?? (() => new Date());
46
54
  const emit = opts.onEvent ?? (() => { });
47
55
  const jobs = active.filter((e) => e.kinds.includes(target.kind)).map((engine) => ({ engine, target }));
@@ -73,6 +81,7 @@ export async function run(target, opts) {
73
81
  try {
74
82
  found = await job.engine.run({
75
83
  target: job.target,
84
+ ...(opts.profile ? { profile: opts.profile } : {}),
76
85
  note: (message) => emit({ type: 'engine:note', engine: job.engine.id, ...(unit ? { unit } : {}), message }),
77
86
  ...(opts.signal ? { signal: opts.signal } : {}),
78
87
  });
@@ -84,6 +93,7 @@ export async function run(target, opts) {
84
93
  status = 'failed';
85
94
  reason = err instanceof Error ? err.message : String(err);
86
95
  }
96
+ const variant = job.engine.variant?.(opts.profile);
87
97
  const er = {
88
98
  engine: job.engine.id,
89
99
  ...(unit ? { unit } : {}),
@@ -91,6 +101,7 @@ export async function run(target, opts) {
91
101
  durationMs: Math.round(performance.now() - t0),
92
102
  findings: found.length,
93
103
  ...(reason !== undefined ? { reason } : {}),
104
+ ...(variant !== undefined ? { variant } : {}),
94
105
  };
95
106
  engineRuns.push(er);
96
107
  for (const f of found) {
@@ -113,7 +124,7 @@ export async function run(target, opts) {
113
124
  const applied = applyBaseline(findings, opts.baseline);
114
125
  findings = applied.findings;
115
126
  // An entry is only stale when every engine ran. After a partial run it may belong to an engine that did not.
116
- const complete = !opts.only && engineRuns.length === jobs.length && engineRuns.every((e) => e.status === 'ok');
127
+ const complete = !opts.only && !leftOut && engineRuns.length === jobs.length && engineRuns.every((e) => e.status === 'ok');
117
128
  staleBaseline = complete ? applied.stale : [];
118
129
  }
119
130
  const summary = { error: 0, warning: 0, info: 0, suppressed: 0 };
@@ -132,6 +143,9 @@ export async function run(target, opts) {
132
143
  name: target.name,
133
144
  units: target.units.map((u) => ({ kind: u.kind, name: u.name, path: posix(path.relative(target.path, u.path)) })),
134
145
  },
146
+ ...(opts.profile ? { profile: opts.profile } : {}),
147
+ depth,
148
+ ...(opts.experimental ? { experimental: true } : {}),
135
149
  startedAt,
136
150
  finishedAt: now().toISOString(),
137
151
  engines: engineRuns,
package/dist/session.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- import type { Engine, RunDiff, RunEvent, RunResult } from './types.ts';
1
+ import type { Depth, Engine, RunDiff, RunEvent, RunResult } from './types.ts';
2
2
  export interface SessionOptions {
3
3
  input: string;
4
4
  type?: 'theme' | 'plugin' | 'install';
5
5
  only?: string[];
6
+ profile?: string;
7
+ depth?: Depth;
8
+ experimental?: boolean;
6
9
  out?: string;
7
10
  baselineFile?: string;
8
11
  engines: Engine[];
package/dist/session.js CHANGED
@@ -3,11 +3,16 @@ import path from 'node:path';
3
3
  import { loadBaseline } from './baseline.js';
4
4
  import { diffRuns } from './diff.js';
5
5
  import { assertReportDir, defaultReportDir, readPreviousRun, writeReports } from './report/write.js';
6
+ import { profileEngines } from './profiles.js';
7
+ import { customEngines } from './engines/custom.js';
6
8
  import { run } from './runner.js';
7
9
  import { detectTarget } from './target.js';
8
10
  /** The steps from a path to written reports. The command line and the local server share them. */
9
11
  export async function runSession(opts) {
10
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;
11
16
  let baselineFile = opts.baselineFile;
12
17
  if (!baselineFile && target.kind !== 'url') {
13
18
  const candidate = path.join(target.path, 'wp-shakedown-baseline.json');
@@ -19,8 +24,11 @@ export async function runSession(opts) {
19
24
  assertReportDir(target, dir);
20
25
  const previous = readPreviousRun(dir);
21
26
  const result = await run(target, {
22
- engines: opts.engines,
23
- ...(opts.only ? { only: opts.only } : {}),
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 } : {}),
24
32
  ...(baseline ? { baseline } : {}),
25
33
  ...(opts.onEvent ? { onEvent: opts.onEvent } : {}),
26
34
  ...(opts.signal ? { signal: opts.signal } : {}),
package/dist/types.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export declare const SEVERITIES: readonly ['error', 'warning', 'info'];
2
2
  export type Severity = (typeof SEVERITIES)[number];
3
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];
4
7
  export type TargetKind = 'theme' | 'plugin' | 'install' | 'url';
5
8
  export interface Target {
6
9
  kind: TargetKind;
@@ -43,6 +46,8 @@ export interface Finding extends RawFinding {
43
46
  }
44
47
  export interface EngineContext {
45
48
  target: Target;
49
+ /** ID of the profile the run uses, when it uses one. */
50
+ profile?: string;
46
51
  signal?: AbortSignal;
47
52
  /** Tells the user something while the engine runs, for example that tools are being installed. */
48
53
  note(message: string): void;
@@ -51,8 +56,25 @@ export interface Engine {
51
56
  id: string;
52
57
  title: string;
53
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;
54
65
  run(ctx: EngineContext): Promise<RawFinding[]>;
55
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
+ }
56
78
  /** An engine throws this when it cannot run here, for example when PHP is missing. The run continues. */
57
79
  export declare class EngineSkipped extends Error {
58
80
  }
@@ -65,6 +87,8 @@ export interface EngineRun {
65
87
  findings: number;
66
88
  /** Why the engine was skipped or how it failed. */
67
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;
68
92
  }
69
93
  export interface Summary {
70
94
  error: number;
@@ -89,6 +113,12 @@ export interface RunResult {
89
113
  path: string;
90
114
  }[];
91
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;
92
122
  startedAt: string;
93
123
  finishedAt: string;
94
124
  engines: EngineRun[];
package/dist/types.js CHANGED
@@ -1,4 +1,6 @@
1
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'];
2
4
  /** An engine throws this when it cannot run here, for example when PHP is missing. The run continues. */
3
5
  export class EngineSkipped extends Error {
4
6
  }