@vvedantb/config 0.9.0 → 0.10.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#296](https://github.com/vvedantb/packages/pull/296) [`5a84fe6`](https://github.com/vvedantb/packages/commit/5a84fe67f326782ed533f7247b63c58b653eb887) Thanks [@vvedantb](https://github.com/vvedantb)! - `vvedantb-doctor` has two new checks. `ci-runner` fails on a job that runs on the small `boat` runner (use `boat-large`). `ci-commands` fails on a CI command that is not `lint`, `typecheck` or `test` and has no written reason under `ciCommands` in `.vvedantb-doctor.json`.
8
+
3
9
  ## 0.9.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -202,6 +202,16 @@ Each check has a stable id:
202
202
  | `oxlint-script` | No `lint` script that runs `oxlint`. |
203
203
  | `config-version` | The `@vvedantb/config` range floor is an older minor than the running `vvedantb-doctor` version. |
204
204
  | `ci-reusable-workflow` | No workflow calls `vvedantb/packages/.github/workflows/ci-app.yml`. |
205
+ | `ci-runner` | A workflow has `runs-on: boat` or `runs_on: boat`. Every boat.dev job runs on `boat-large`. GitHub-hosted labels pass. |
206
+ | `ci-commands` | A line in the `commands` input of the shared workflow is not `lint`, `typecheck` or `test` and has no written reason, or a reason names a command that CI does not run. |
207
+
208
+ **CI commands.** The standard commands are `pnpm lint`, `pnpm typecheck` and `pnpm test` (`npm run` or `bun run` also pass, and so does `--filter <package>`). Every other line needs a reason, keyed by the exact command, in `.vvedantb-doctor.json` or under `vvedantbDoctor.ciCommands` in the root `package.json`:
209
+
210
+ ```json
211
+ { "ciCommands": { "pnpm --filter web build": "the web app deploys from this build" } }
212
+ ```
213
+
214
+ A repo cannot add a check that the other repos do not have, or keep one after its reason has gone, without a line in this file.
205
215
 
206
216
  `--json` prints `{ root, runningVersion, ok, warnings, results }`, where each result is `{ id, title, status, details }` (plus `waiver` when waived) and `status` is `pass`, `fail` or `waived`.
207
217
 
package/dist/doctor.d.ts CHANGED
@@ -15,7 +15,7 @@ export interface CheckResult {
15
15
  waiver?: string;
16
16
  }
17
17
  /** The ordered ids of every check the doctor runs. */
18
- export declare const CHECK_IDS: readonly ["no-eslint", "no-prettier", "no-plain-tsc", "tsrs-present", "oxlint-dep", "oxlint-script", "config-version", "ci-reusable-workflow"];
18
+ export declare const CHECK_IDS: readonly ["no-eslint", "no-prettier", "no-plain-tsc", "tsrs-present", "oxlint-dep", "oxlint-script", "config-version", "ci-reusable-workflow", "ci-runner", "ci-commands"];
19
19
  export type CheckId = (typeof CHECK_IDS)[number];
20
20
  interface PackageJson {
21
21
  name?: string;
@@ -29,7 +29,8 @@ interface PackageJson {
29
29
  };
30
30
  prettier?: unknown;
31
31
  vvedantbDoctor?: {
32
- waivers?: Record<string, string>;
32
+ waivers?: Record<string, unknown>;
33
+ ciCommands?: Record<string, unknown>;
33
34
  };
34
35
  }
35
36
  export interface PackageEntry {
@@ -60,18 +61,45 @@ export declare function rangeMinorFloor(range: string): {
60
61
  export declare function isOlderMinor(range: string, running: string): boolean;
61
62
  export declare function checkConfigVersion(repo: RepoModel, runningVersion: string): CheckResult;
62
63
  export declare function checkCiReusableWorkflow(repo: RepoModel): CheckResult;
64
+ /**
65
+ * Fails on a job that names the small `boat` runner, as `runs-on: boat` or as the `runs_on: boat`
66
+ * input of a reusable workflow. GitHub-hosted labels and `boat-large` pass.
67
+ */
68
+ export declare function checkCiRunner(repo: RepoModel): CheckResult;
69
+ /** The lines of every `commands: |` block in the workflows that call the shared ci-app.yml. */
70
+ export declare function ciCommands(repo: RepoModel): {
71
+ file: string;
72
+ command: string;
73
+ }[];
74
+ /**
75
+ * True for the commands every repo runs: `pnpm lint`, `pnpm typecheck` and `pnpm test`, with
76
+ * `npm run` or `bun run` in place of `pnpm`, and with an optional `--filter <package>`.
77
+ * Anything else (a script with a suffix, a `node` script, a build) is an extra.
78
+ */
79
+ export declare function isStandardCiCommand(command: string): boolean;
80
+ /**
81
+ * Fails on a CI command that is not one of the standard three and has no written reason, and on
82
+ * a reason for a command that CI no longer runs. This stops one repo from carrying a check that
83
+ * no other repo has without a record of why.
84
+ */
85
+ export declare function checkCiCommands(repo: RepoModel, reasons: Record<string, string>): CheckResult;
63
86
  export interface DoctorCheckOptions {
64
87
  runningVersion: string;
65
88
  waivers?: Record<string, string>;
89
+ /** Written reasons for CI commands beyond the standard three, keyed by the exact command. */
90
+ ciCommandReasons?: Record<string, string>;
66
91
  }
67
92
  /** Run every check against the repo at `root`, applying waivers. */
68
93
  export declare function runDoctorChecks(root: string, options: DoctorCheckOptions): CheckResult[];
69
94
  export interface LoadedWaivers {
70
95
  waivers: Record<string, string>;
96
+ /** Written reasons for extra CI commands, keyed by the exact command. */
97
+ ciCommands: Record<string, string>;
71
98
  warnings: string[];
72
99
  }
73
100
  /**
74
- * Waivers from `.vvedantb-doctor.json` (`{ "waivers": { "<id>": "<reason>" } }`) or the root
101
+ * Waivers and CI command reasons from `.vvedantb-doctor.json`
102
+ * (`{ "waivers": { "<id>": "<reason>" }, "ciCommands": { "<command>": "<reason>" } }`) or the root
75
103
  * package.json `vvedantbDoctor.waivers`. The file wins over package.json. A waiver needs a
76
104
  * non-empty reason and a known id; one that does not is dropped with a warning.
77
105
  */
package/dist/doctor.js CHANGED
@@ -10,6 +10,8 @@ export const CHECK_IDS = [
10
10
  "oxlint-script",
11
11
  "config-version",
12
12
  "ci-reusable-workflow",
13
+ "ci-runner",
14
+ "ci-commands",
13
15
  ];
14
16
  const DEP_FIELDS = [
15
17
  "dependencies",
@@ -320,6 +322,113 @@ export function checkCiReusableWorkflow(repo) {
320
322
  const details = found ? [] : [`no workflow calls ${CI_WORKFLOW_REF}`];
321
323
  return result("ci-reusable-workflow", "CI calls the shared ci-app.yml workflow", details);
322
324
  }
325
+ function workflowFiles(root) {
326
+ const dir = join(root, ".github", "workflows");
327
+ if (!existsSync(dir))
328
+ return [];
329
+ const files = [];
330
+ for (const name of readdirSync(dir).sort()) {
331
+ if (!/\.ya?ml$/.test(name))
332
+ continue;
333
+ try {
334
+ files.push({ name, text: readFileSync(join(dir, name), "utf8") });
335
+ }
336
+ catch {
337
+ // Unreadable workflow file: ignore and keep scanning.
338
+ }
339
+ }
340
+ return files;
341
+ }
342
+ /** The plain `boat` runner label. Every boat.dev job runs on `boat-large` (8 cores, 15 GB). */
343
+ const SMALL_RUNNER = "boat";
344
+ /**
345
+ * Fails on a job that names the small `boat` runner, as `runs-on: boat` or as the `runs_on: boat`
346
+ * input of a reusable workflow. GitHub-hosted labels and `boat-large` pass.
347
+ */
348
+ export function checkCiRunner(repo) {
349
+ const details = [];
350
+ for (const file of workflowFiles(repo.root)) {
351
+ file.text.split(/\r?\n/).forEach((line, index) => {
352
+ const match = line.match(/^\s*(?:-\s+)?(runs[-_]on)\s*:\s*(.+?)\s*(?:#.*)?$/);
353
+ if (!match?.[1] || match[2] === undefined)
354
+ return;
355
+ const labels = match[2]
356
+ .replace(/^\[|\]$/g, "")
357
+ .split(",")
358
+ .map((label) => stripQuotes(label));
359
+ if (labels.includes(SMALL_RUNNER)) {
360
+ details.push(`.github/workflows/${file.name}:${index + 1} ${match[1]} is ${SMALL_RUNNER}; use boat-large`);
361
+ }
362
+ });
363
+ }
364
+ return result("ci-runner", "No job runs on the small boat runner", details);
365
+ }
366
+ /** The lines of every `commands: |` block in the workflows that call the shared ci-app.yml. */
367
+ export function ciCommands(repo) {
368
+ const found = [];
369
+ for (const file of workflowFiles(repo.root)) {
370
+ if (!file.text.includes(CI_WORKFLOW_REF))
371
+ continue;
372
+ let blockIndent = -1;
373
+ for (const line of file.text.split(/\r?\n/)) {
374
+ const indent = line.length - line.trimStart().length;
375
+ if (blockIndent >= 0) {
376
+ if (line.trim() === "")
377
+ continue;
378
+ if (indent > blockIndent) {
379
+ const command = line.trim();
380
+ if (!command.startsWith("#"))
381
+ found.push({ file: file.name, command });
382
+ continue;
383
+ }
384
+ blockIndent = -1;
385
+ }
386
+ if (/^\s*commands\s*:\s*[|>][-+]?\s*$/.test(line))
387
+ blockIndent = indent;
388
+ }
389
+ }
390
+ return found;
391
+ }
392
+ const STANDARD_SCRIPTS = new Set(["lint", "typecheck", "test"]);
393
+ /**
394
+ * True for the commands every repo runs: `pnpm lint`, `pnpm typecheck` and `pnpm test`, with
395
+ * `npm run` or `bun run` in place of `pnpm`, and with an optional `--filter <package>`.
396
+ * Anything else (a script with a suffix, a `node` script, a build) is an extra.
397
+ */
398
+ export function isStandardCiCommand(command) {
399
+ const words = command.trim().split(/\s+/);
400
+ const runner = words.shift();
401
+ if (runner !== "pnpm" && runner !== "npm" && runner !== "bun")
402
+ return false;
403
+ if (words[0] === "--filter" || words[0] === "-F")
404
+ words.splice(0, 2);
405
+ else if (words[0]?.startsWith("--filter="))
406
+ words.shift();
407
+ if (words[0] === "run")
408
+ words.shift();
409
+ const [script] = words;
410
+ return words.length === 1 && script !== undefined && STANDARD_SCRIPTS.has(script);
411
+ }
412
+ /**
413
+ * Fails on a CI command that is not one of the standard three and has no written reason, and on
414
+ * a reason for a command that CI no longer runs. This stops one repo from carrying a check that
415
+ * no other repo has without a record of why.
416
+ */
417
+ export function checkCiCommands(repo, reasons) {
418
+ const details = [];
419
+ const seen = new Set();
420
+ for (const { file, command } of ciCommands(repo)) {
421
+ seen.add(command);
422
+ if (isStandardCiCommand(command) || reasons[command] !== undefined)
423
+ continue;
424
+ details.push(`.github/workflows/${file} runs "${command}" with no reason in ciCommands`);
425
+ }
426
+ for (const command of Object.keys(reasons)) {
427
+ if (!seen.has(command))
428
+ details.push(`ciCommands has a reason for "${command}", which CI does not run; remove it`);
429
+ }
430
+ return result("ci-commands", "Every CI command beyond lint, typecheck and test has a written reason", details);
431
+ }
323
432
  /** Run every check against the repo at `root`, applying waivers. */
324
433
  export function runDoctorChecks(root, options) {
325
434
  const repo = loadRepo(root);
@@ -333,6 +442,8 @@ export function runDoctorChecks(root, options) {
333
442
  checkOxlintScript(repo),
334
443
  checkConfigVersion(repo, options.runningVersion),
335
444
  checkCiReusableWorkflow(repo),
445
+ checkCiRunner(repo),
446
+ checkCiCommands(repo, options.ciCommandReasons ?? {}),
336
447
  ];
337
448
  return results.map((r) => {
338
449
  const reason = waivers[r.id];
@@ -341,20 +452,24 @@ export function runDoctorChecks(root, options) {
341
452
  }
342
453
  const KNOWN_IDS = new Set(CHECK_IDS);
343
454
  /**
344
- * Waivers from `.vvedantb-doctor.json` (`{ "waivers": { "<id>": "<reason>" } }`) or the root
455
+ * Waivers and CI command reasons from `.vvedantb-doctor.json`
456
+ * (`{ "waivers": { "<id>": "<reason>" }, "ciCommands": { "<command>": "<reason>" } }`) or the root
345
457
  * package.json `vvedantbDoctor.waivers`. The file wins over package.json. A waiver needs a
346
458
  * non-empty reason and a known id; one that does not is dropped with a warning.
347
459
  */
348
460
  export function loadWaivers(root) {
349
461
  const warnings = [];
350
462
  const raw = {};
463
+ const rawCommands = {};
351
464
  const pkg = readJson(join(root, "package.json"));
352
465
  Object.assign(raw, pkg?.vvedantbDoctor?.waivers ?? {});
466
+ Object.assign(rawCommands, pkg?.vvedantbDoctor?.ciCommands ?? {});
353
467
  const file = join(root, ".vvedantb-doctor.json");
354
468
  if (existsSync(file)) {
355
469
  try {
356
470
  const parsed = JSON.parse(readFileSync(file, "utf8"));
357
471
  Object.assign(raw, parsed.waivers ?? {});
472
+ Object.assign(rawCommands, parsed.ciCommands ?? {});
358
473
  }
359
474
  catch {
360
475
  warnings.push(".vvedantb-doctor.json is not valid JSON; ignoring it");
@@ -372,7 +487,15 @@ export function loadWaivers(root) {
372
487
  }
373
488
  waivers[id] = reason.trim();
374
489
  }
375
- return { waivers, warnings };
490
+ const ciCommands = {};
491
+ for (const [command, reason] of Object.entries(rawCommands)) {
492
+ if (typeof reason !== "string" || reason.trim() === "") {
493
+ warnings.push(`ciCommands entry "${command}" has no written reason; not applied`);
494
+ continue;
495
+ }
496
+ ciCommands[command.trim()] = reason.trim();
497
+ }
498
+ return { waivers, ciCommands, warnings };
376
499
  }
377
500
  function readRunningVersion() {
378
501
  try {
@@ -391,6 +514,8 @@ const USAGE = `Usage: vvedantb-doctor [root] [--json]
391
514
  Checks (each has a stable id): ${CHECK_IDS.join(", ")}.
392
515
  Waive a check in .vvedantb-doctor.json ({ "waivers": { "<id>": "<reason>" } }) or the
393
516
  root package.json "vvedantbDoctor".waivers. A waived check prints as waived.
517
+ Give each CI command beyond lint, typecheck and test a reason in the same file:
518
+ { "ciCommands": { "<command>": "<reason>" } }.
394
519
 
395
520
  Exit code: 0 no drift, 1 drift found, 2 bad usage.`;
396
521
  /** Run the CLI. Returns the process exit code. */
@@ -420,8 +545,8 @@ export function runDoctor(argv, io) {
420
545
  }
421
546
  }
422
547
  const runningVersion = readRunningVersion();
423
- const { waivers, warnings } = loadWaivers(root);
424
- const results = runDoctorChecks(root, { runningVersion, waivers });
548
+ const { waivers, ciCommands: ciCommandReasons, warnings } = loadWaivers(root);
549
+ const results = runDoctorChecks(root, { runningVersion, waivers, ciCommandReasons });
425
550
  const failed = results.filter((r) => r.status === "fail");
426
551
  if (json) {
427
552
  io.log(JSON.stringify({ root, runningVersion, ok: failed.length === 0, warnings, results }, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/config",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
5
  "description": "Shared tsconfig bases, oxlint base, Vite, Vitest, Babel and Metro presets, a WXT preset and host-permission helper for Chrome extensions, pinned tool versions, a sync CLI for Claude commands, CLAUDE.md, Cursor environment and Convex tsconfig, a packaged Electron app.asar module check, a shared header and footer check, a no-source-text-in-tests check, shared oxlint JS plugins and a CLI that adds an extension to Clerk's allowed origins.",
6
6
  "type": "module",