@vvedantb/config 0.8.1 → 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 +15 -0
- package/README.md +72 -0
- package/dist/doctor-cli.d.ts +2 -0
- package/dist/doctor-cli.js +7 -0
- package/dist/doctor.d.ts +109 -0
- package/dist/doctor.js +576 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/vitest-shared-setup.d.ts +1 -0
- package/dist/vitest-shared-setup.js +12 -0
- package/dist/vitest-shared.d.ts +49 -0
- package/dist/vitest-shared.js +46 -0
- package/package.json +10 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
|
|
9
|
+
## 0.9.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#292](https://github.com/vvedantb/packages/pull/292) [`dfd2849`](https://github.com/vvedantb/packages/commit/dfd2849e95d2f55e2a697767d3de171aaf1fe763) Thanks [@vvedantb](https://github.com/vvedantb)! - Add a shared-worker Vitest preset and a `vvedantb-doctor` CLI.
|
|
14
|
+
|
|
15
|
+
- `sharedWorkerVitestConfig` (and `SHARED_WORKER_SETUP`): an opt-in Vitest preset that lets test files share a worker (`isolate: false`), shuffles file order, and resets mocks, env stubs, global stubs and fake timers after each test. Trades per-file isolation for a faster run; adopt it per repo where tests are independent.
|
|
16
|
+
- `vvedantb-doctor`: a dependency-free CLI that inspects a repo for drift from the shared CI and tooling house rules (ESLint, Prettier, plain `tsc`, missing `tsrs`, missing `oxlint` dep or script, an older `@vvedantb/config` minor, a CI workflow that does not call the shared reusable workflow). It walks workspace packages, supports `--json` and a per-repo waiver file, makes no network requests, and exits non-zero on drift.
|
|
17
|
+
|
|
3
18
|
## 0.8.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -179,6 +179,50 @@ pnpm exec vvedantb-check-no-source-text apps/web --skip landing --skip-file no-s
|
|
|
179
179
|
|
|
180
180
|
Put `allow-source-read: <reason>` in a comment on the same or the previous line to allow one read that feeds code under test. The directories `node_modules`, `dist`, `build`, `.git`, `.expo`, `.next`, `android`, `ios`, `out` and `release` are skipped; `--skip <dir>` adds more and `--skip-file <name>` skips one test file by name. Exit code: 0 clean, 1 findings, 2 bad usage.
|
|
181
181
|
|
|
182
|
+
## vvedantb-doctor
|
|
183
|
+
|
|
184
|
+
`vvedantb-doctor` inspects a repo for drift from the shared CI and tooling house rules and exits non-zero with a list of what to fix. It reads the root `package.json`, walks the workspace packages (from `pnpm-workspace.yaml` and npm `workspaces`), and reads `.github/workflows/*`. It makes no network requests.
|
|
185
|
+
|
|
186
|
+
```sh
|
|
187
|
+
pnpm exec vvedantb-doctor # inspect the current directory
|
|
188
|
+
pnpm exec vvedantb-doctor path/to/repo --json
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Exit code: 0 clean (waived checks still count as clean), 1 drift, 2 bad usage.
|
|
192
|
+
|
|
193
|
+
Each check has a stable id:
|
|
194
|
+
|
|
195
|
+
| Id | Fails when |
|
|
196
|
+
| --- | --- |
|
|
197
|
+
| `no-eslint` | An `eslint`, `eslint-*`, `@eslint/*` or `@typescript-eslint/*` dependency, or an ESLint config file, is present. |
|
|
198
|
+
| `no-prettier` | A `prettier` dependency, a Prettier config file, or a `prettier` key in a `package.json` is present. |
|
|
199
|
+
| `no-plain-tsc` | A `typecheck` or `lint` script calls plain `tsc` (use `tsrs`). Only `typecheck`/`lint` scripts are checked, not `build`. |
|
|
200
|
+
| `tsrs-present` | The repo has TypeScript but no `tsrs` dependency. |
|
|
201
|
+
| `oxlint-dep` | No `oxlint` dependency. |
|
|
202
|
+
| `oxlint-script` | No `lint` script that runs `oxlint`. |
|
|
203
|
+
| `config-version` | The `@vvedantb/config` range floor is an older minor than the running `vvedantb-doctor` version. |
|
|
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.
|
|
215
|
+
|
|
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`.
|
|
217
|
+
|
|
218
|
+
**Waivers.** A repo can waive a named check, with a written reason, in `.vvedantb-doctor.json`:
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
{ "waivers": { "no-eslint": "legacy config, migration tracked in TICKET-123" } }
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
or under a `vvedantbDoctor.waivers` key in the root `package.json` (the file wins over `package.json`). A waiver needs a non-empty reason; an unknown id or an empty reason is dropped with a warning. A waived check prints as `waived` (with its reason), never silently.
|
|
225
|
+
|
|
182
226
|
## Vite and Vitest presets
|
|
183
227
|
|
|
184
228
|
The root never imports Vite or a plugin. The app imports its plugins and passes the factories in, so the versions stay the app's own. The functions return plain objects; spread them into Vite's `defineConfig` and add `server`, `base` or `root` there.
|
|
@@ -220,6 +264,34 @@ Keys that are not asked for are left out, so `resolve` and `build` appear only w
|
|
|
220
264
|
|
|
221
265
|
`defineWebVitestConfig` takes `plugins`, `tsconfigPaths`, `alias`, `automaticJsx` (`esbuild: { jsx: "automatic" }`), `include` (default `["src/**/*.test.ts"]`) and `inline` (`test.server.deps.inline`). It always sets `test.environment: "node"`. Pass the result to `defineConfig` from `vitest/config`.
|
|
222
266
|
|
|
267
|
+
### Shared-worker Vitest preset (opt-in, faster)
|
|
268
|
+
|
|
269
|
+
`sharedWorkerVitestConfig` is an opt-in wrapper that trades per-file isolation for speed: test files that land on the same worker share its loaded modules instead of each starting fresh. Vitest still uses every core. It is a named export, so a repo adopts it only where it wants the trade-off.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
import { defineConfig } from "vitest/config";
|
|
273
|
+
import { defineWebVitestConfig, sharedWorkerVitestConfig } from "@vvedantb/config";
|
|
274
|
+
|
|
275
|
+
export default defineConfig(
|
|
276
|
+
sharedWorkerVitestConfig(defineWebVitestConfig({ include: ["src/**/*.test.ts"] })),
|
|
277
|
+
);
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
It takes a base config (any `defineWebVitestConfig` result, or none) and an options object, and sets:
|
|
281
|
+
|
|
282
|
+
| Field | Value | Why |
|
|
283
|
+
| --- | --- | --- |
|
|
284
|
+
| `test.isolate` | `false` | Files on a worker share its modules. This is the speed win and the reason the cleanup rules below matter. |
|
|
285
|
+
| `test.sequence.shuffle` | `{ files: true, tests: options.shuffleTests ?? false }` | Randomise file order so hidden cross-file order dependencies surface. Test order within a file stays stable unless you pass `shuffleTests: true`. |
|
|
286
|
+
| `test.restoreMocks` / `unstubEnvs` / `unstubGlobals` | `true` | Reset mocks, `vi.stubEnv` and `vi.stubGlobal` after each test so state does not leak between files. |
|
|
287
|
+
| `test.setupFiles` | `[SHARED_WORKER_SETUP, ...(options.setupFiles ?? [])]` | `SHARED_WORKER_SETUP` runs `vi.useRealTimers()` after each test (fake timers have no config flag). Your own setup files are appended. |
|
|
288
|
+
|
|
289
|
+
The base config's `test.environment`, `include`, `server`, and its `plugins` / `esbuild` / `resolve` are carried through.
|
|
290
|
+
|
|
291
|
+
**Cleanup rules.** With isolation off, module-level state is shared for the whole run. The config flags reset mocks, env stubs, global stubs and fake timers for you, but they do **not** reset a module's own top-level variables, caches or singletons created on import. A test file that mutates that state must restore it itself (`afterEach` / `afterAll`). If a file cannot be made independent, keep it on the default (isolated) Vitest config instead of this preset.
|
|
292
|
+
|
|
293
|
+
**Supported Vitest range.** Tested with Vitest 3. It sets top-level `test` fields only and does not use `poolOptions`, which Vitest 4 removed. Check a run when you adopt it on Vitest 4 or 5. `vitest` is an optional peer (the setup file imports it). The preset does not set `pool` or the worker count (left to the repo) and does not support the `vmThreads` / `vmForks` pools, where `isolate` behaves differently.
|
|
294
|
+
|
|
223
295
|
## Chrome extensions (WXT)
|
|
224
296
|
|
|
225
297
|
`@vvedantb/config/extension` holds the shared part of an extension's `wxt.config.ts`. Like the Vite presets, it never imports WXT, Vite or a plugin: the app passes the plugin factories in. WXT is not a peer.
|
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export type DoctorIo = {
|
|
2
|
+
log: (message: string) => void;
|
|
3
|
+
error: (message: string) => void;
|
|
4
|
+
cwd: () => string;
|
|
5
|
+
};
|
|
6
|
+
export type CheckStatus = "pass" | "fail" | "waived";
|
|
7
|
+
export interface CheckResult {
|
|
8
|
+
/** Stable id used for waivers and `--json`. */
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
status: CheckStatus;
|
|
12
|
+
/** Problem lines (empty when the check passes). */
|
|
13
|
+
details: string[];
|
|
14
|
+
/** The written reason, when the check is waived. */
|
|
15
|
+
waiver?: string;
|
|
16
|
+
}
|
|
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", "ci-runner", "ci-commands"];
|
|
19
|
+
export type CheckId = (typeof CHECK_IDS)[number];
|
|
20
|
+
interface PackageJson {
|
|
21
|
+
name?: string;
|
|
22
|
+
dependencies?: Record<string, string>;
|
|
23
|
+
devDependencies?: Record<string, string>;
|
|
24
|
+
optionalDependencies?: Record<string, string>;
|
|
25
|
+
peerDependencies?: Record<string, string>;
|
|
26
|
+
scripts?: Record<string, string>;
|
|
27
|
+
workspaces?: string[] | {
|
|
28
|
+
packages?: string[];
|
|
29
|
+
};
|
|
30
|
+
prettier?: unknown;
|
|
31
|
+
vvedantbDoctor?: {
|
|
32
|
+
waivers?: Record<string, unknown>;
|
|
33
|
+
ciCommands?: Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface PackageEntry {
|
|
37
|
+
/** Absolute directory holding the package.json. */
|
|
38
|
+
dir: string;
|
|
39
|
+
/** Path relative to the repo root, forward slashes. The root is ".". */
|
|
40
|
+
rel: string;
|
|
41
|
+
json: PackageJson;
|
|
42
|
+
}
|
|
43
|
+
export interface RepoModel {
|
|
44
|
+
root: string;
|
|
45
|
+
packages: PackageEntry[];
|
|
46
|
+
}
|
|
47
|
+
/** Read the repo: the root package.json and every workspace package.json. */
|
|
48
|
+
export declare function loadRepo(root: string): RepoModel;
|
|
49
|
+
export declare function checkNoEslint(repo: RepoModel): CheckResult;
|
|
50
|
+
export declare function checkNoPrettier(repo: RepoModel): CheckResult;
|
|
51
|
+
export declare function checkNoPlainTsc(repo: RepoModel): CheckResult;
|
|
52
|
+
export declare function checkTsrsPresent(repo: RepoModel): CheckResult;
|
|
53
|
+
export declare function checkOxlintDep(repo: RepoModel): CheckResult;
|
|
54
|
+
export declare function checkOxlintScript(repo: RepoModel): CheckResult;
|
|
55
|
+
/** The leading major.minor of a version range, or undefined for a non-numeric range (workspace:*, *, latest). */
|
|
56
|
+
export declare function rangeMinorFloor(range: string): {
|
|
57
|
+
major: number;
|
|
58
|
+
minor: number;
|
|
59
|
+
} | undefined;
|
|
60
|
+
/** True when `range`'s minimum is older than `running`'s major.minor. */
|
|
61
|
+
export declare function isOlderMinor(range: string, running: string): boolean;
|
|
62
|
+
export declare function checkConfigVersion(repo: RepoModel, runningVersion: string): CheckResult;
|
|
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;
|
|
86
|
+
export interface DoctorCheckOptions {
|
|
87
|
+
runningVersion: string;
|
|
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>;
|
|
91
|
+
}
|
|
92
|
+
/** Run every check against the repo at `root`, applying waivers. */
|
|
93
|
+
export declare function runDoctorChecks(root: string, options: DoctorCheckOptions): CheckResult[];
|
|
94
|
+
export interface LoadedWaivers {
|
|
95
|
+
waivers: Record<string, string>;
|
|
96
|
+
/** Written reasons for extra CI commands, keyed by the exact command. */
|
|
97
|
+
ciCommands: Record<string, string>;
|
|
98
|
+
warnings: string[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Waivers and CI command reasons from `.vvedantb-doctor.json`
|
|
102
|
+
* (`{ "waivers": { "<id>": "<reason>" }, "ciCommands": { "<command>": "<reason>" } }`) or the root
|
|
103
|
+
* package.json `vvedantbDoctor.waivers`. The file wins over package.json. A waiver needs a
|
|
104
|
+
* non-empty reason and a known id; one that does not is dropped with a warning.
|
|
105
|
+
*/
|
|
106
|
+
export declare function loadWaivers(root: string): LoadedWaivers;
|
|
107
|
+
/** Run the CLI. Returns the process exit code. */
|
|
108
|
+
export declare function runDoctor(argv: readonly string[], io: DoctorIo): number;
|
|
109
|
+
export {};
|
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
|
+
/** The ordered ids of every check the doctor runs. */
|
|
4
|
+
export const CHECK_IDS = [
|
|
5
|
+
"no-eslint",
|
|
6
|
+
"no-prettier",
|
|
7
|
+
"no-plain-tsc",
|
|
8
|
+
"tsrs-present",
|
|
9
|
+
"oxlint-dep",
|
|
10
|
+
"oxlint-script",
|
|
11
|
+
"config-version",
|
|
12
|
+
"ci-reusable-workflow",
|
|
13
|
+
"ci-runner",
|
|
14
|
+
"ci-commands",
|
|
15
|
+
];
|
|
16
|
+
const DEP_FIELDS = [
|
|
17
|
+
"dependencies",
|
|
18
|
+
"devDependencies",
|
|
19
|
+
"optionalDependencies",
|
|
20
|
+
"peerDependencies",
|
|
21
|
+
];
|
|
22
|
+
const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", ".next", ".expo", "out"]);
|
|
23
|
+
function subdirs(dir) {
|
|
24
|
+
try {
|
|
25
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
26
|
+
.filter((entry) => entry.isDirectory() && !SKIP_DIRS.has(entry.name))
|
|
27
|
+
.map((entry) => entry.name);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function stripQuotes(value) {
|
|
34
|
+
const trimmed = value.trim();
|
|
35
|
+
if (trimmed.length >= 2 && (trimmed[0] === '"' || trimmed[0] === "'") && trimmed.at(-1) === trimmed[0]) {
|
|
36
|
+
return trimmed.slice(1, -1);
|
|
37
|
+
}
|
|
38
|
+
return trimmed;
|
|
39
|
+
}
|
|
40
|
+
function readJson(path) {
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Workspace globs from pnpm-workspace.yaml, parsed without a YAML dependency. */
|
|
49
|
+
function parsePnpmWorkspace(root) {
|
|
50
|
+
const file = join(root, "pnpm-workspace.yaml");
|
|
51
|
+
if (!existsSync(file))
|
|
52
|
+
return [];
|
|
53
|
+
const globs = [];
|
|
54
|
+
let inPackages = false;
|
|
55
|
+
for (const raw of readFileSync(file, "utf8").split(/\r?\n/)) {
|
|
56
|
+
if (/^packages\s*:/.test(raw)) {
|
|
57
|
+
inPackages = true;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!inPackages)
|
|
61
|
+
continue;
|
|
62
|
+
const item = raw.match(/^\s+-\s+(.+?)\s*$/);
|
|
63
|
+
if (item?.[1]) {
|
|
64
|
+
globs.push(stripQuotes(item[1]));
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (raw.trim() === "")
|
|
68
|
+
continue;
|
|
69
|
+
// A dedented or indented non-list line ends the `packages:` block.
|
|
70
|
+
inPackages = false;
|
|
71
|
+
}
|
|
72
|
+
return globs;
|
|
73
|
+
}
|
|
74
|
+
/** Workspace globs from a root package.json `workspaces` field. */
|
|
75
|
+
function npmWorkspaceGlobs(json) {
|
|
76
|
+
const field = json?.workspaces;
|
|
77
|
+
if (Array.isArray(field))
|
|
78
|
+
return field;
|
|
79
|
+
if (field?.packages)
|
|
80
|
+
return field.packages;
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
function segmentMatch(segment, name) {
|
|
84
|
+
if (!segment.includes("*"))
|
|
85
|
+
return segment === name;
|
|
86
|
+
const pattern = segment.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("*", "[^/]*");
|
|
87
|
+
return new RegExp(`^${pattern}$`).test(name);
|
|
88
|
+
}
|
|
89
|
+
/** Directories under `base` matching the `/`-split glob segments. */
|
|
90
|
+
function walkGlob(base, segments) {
|
|
91
|
+
if (segments.length === 0)
|
|
92
|
+
return [base];
|
|
93
|
+
const [segment, ...rest] = segments;
|
|
94
|
+
if (segment === undefined)
|
|
95
|
+
return [base];
|
|
96
|
+
const results = [];
|
|
97
|
+
if (segment === "**") {
|
|
98
|
+
results.push(...walkGlob(base, rest));
|
|
99
|
+
for (const child of subdirs(base))
|
|
100
|
+
results.push(...walkGlob(join(base, child), segments));
|
|
101
|
+
return results;
|
|
102
|
+
}
|
|
103
|
+
for (const child of subdirs(base)) {
|
|
104
|
+
if (segmentMatch(segment, child))
|
|
105
|
+
results.push(...walkGlob(join(base, child), rest));
|
|
106
|
+
}
|
|
107
|
+
return results;
|
|
108
|
+
}
|
|
109
|
+
function matchGlob(root, pattern) {
|
|
110
|
+
return walkGlob(root, pattern.split("/").filter((s) => s.length > 0));
|
|
111
|
+
}
|
|
112
|
+
/** Expand workspace globs to the absolute directories they match, honouring `!` excludes. */
|
|
113
|
+
function expandWorkspaces(root, globs) {
|
|
114
|
+
const include = new Set();
|
|
115
|
+
const exclude = new Set();
|
|
116
|
+
for (const glob of globs) {
|
|
117
|
+
const negated = glob.startsWith("!");
|
|
118
|
+
const target = negated ? exclude : include;
|
|
119
|
+
for (const dir of matchGlob(root, negated ? glob.slice(1) : glob))
|
|
120
|
+
target.add(dir);
|
|
121
|
+
}
|
|
122
|
+
return [...include].filter((dir) => !exclude.has(dir));
|
|
123
|
+
}
|
|
124
|
+
/** Read the repo: the root package.json and every workspace package.json. */
|
|
125
|
+
export function loadRepo(root) {
|
|
126
|
+
const rootJson = readJson(join(root, "package.json"));
|
|
127
|
+
const packages = [{ dir: root, rel: ".", json: rootJson ?? {} }];
|
|
128
|
+
const globs = [...new Set([...parsePnpmWorkspace(root), ...npmWorkspaceGlobs(rootJson)])];
|
|
129
|
+
for (const dir of expandWorkspaces(root, globs)) {
|
|
130
|
+
if (dir === root)
|
|
131
|
+
continue;
|
|
132
|
+
const json = readJson(join(dir, "package.json"));
|
|
133
|
+
if (!json)
|
|
134
|
+
continue;
|
|
135
|
+
packages.push({ dir, rel: relative(root, dir).replaceAll("\\", "/"), json });
|
|
136
|
+
}
|
|
137
|
+
return { root, packages };
|
|
138
|
+
}
|
|
139
|
+
function depNames(json) {
|
|
140
|
+
const names = [];
|
|
141
|
+
for (const field of DEP_FIELDS) {
|
|
142
|
+
const map = json[field];
|
|
143
|
+
if (map)
|
|
144
|
+
names.push(...Object.keys(map));
|
|
145
|
+
}
|
|
146
|
+
return names;
|
|
147
|
+
}
|
|
148
|
+
function depRange(json, name) {
|
|
149
|
+
for (const field of DEP_FIELDS) {
|
|
150
|
+
const map = json[field];
|
|
151
|
+
if (map && name in map)
|
|
152
|
+
return map[name];
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
function hasFile(dir, names) {
|
|
157
|
+
for (const name of names) {
|
|
158
|
+
if (existsSync(join(dir, name)))
|
|
159
|
+
return name;
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
const ESLINT_CONFIG_FILES = [
|
|
164
|
+
".eslintrc",
|
|
165
|
+
".eslintrc.js",
|
|
166
|
+
".eslintrc.cjs",
|
|
167
|
+
".eslintrc.mjs",
|
|
168
|
+
".eslintrc.json",
|
|
169
|
+
".eslintrc.yml",
|
|
170
|
+
".eslintrc.yaml",
|
|
171
|
+
"eslint.config.js",
|
|
172
|
+
"eslint.config.mjs",
|
|
173
|
+
"eslint.config.cjs",
|
|
174
|
+
"eslint.config.ts",
|
|
175
|
+
"eslint.config.mts",
|
|
176
|
+
];
|
|
177
|
+
const PRETTIER_CONFIG_FILES = [
|
|
178
|
+
".prettierrc",
|
|
179
|
+
".prettierrc.json",
|
|
180
|
+
".prettierrc.json5",
|
|
181
|
+
".prettierrc.yml",
|
|
182
|
+
".prettierrc.yaml",
|
|
183
|
+
".prettierrc.toml",
|
|
184
|
+
".prettierrc.js",
|
|
185
|
+
".prettierrc.cjs",
|
|
186
|
+
".prettierrc.mjs",
|
|
187
|
+
"prettier.config.js",
|
|
188
|
+
"prettier.config.cjs",
|
|
189
|
+
"prettier.config.mjs",
|
|
190
|
+
];
|
|
191
|
+
function isEslintDep(name) {
|
|
192
|
+
return (name === "eslint" ||
|
|
193
|
+
name.startsWith("eslint-") ||
|
|
194
|
+
name.startsWith("@eslint/") ||
|
|
195
|
+
name.startsWith("@typescript-eslint/"));
|
|
196
|
+
}
|
|
197
|
+
function isPrettierDep(name) {
|
|
198
|
+
return name === "prettier" || name.startsWith("prettier-") || name.startsWith("@prettier/");
|
|
199
|
+
}
|
|
200
|
+
function runs(command, bin) {
|
|
201
|
+
return new RegExp(`(?:^|[\\s&|;(])${bin}(?=\\s|$|[&|;)])`).test(command);
|
|
202
|
+
}
|
|
203
|
+
function result(id, title, details) {
|
|
204
|
+
return { id, title, status: details.length > 0 ? "fail" : "pass", details };
|
|
205
|
+
}
|
|
206
|
+
export function checkNoEslint(repo) {
|
|
207
|
+
const details = [];
|
|
208
|
+
for (const pkg of repo.packages) {
|
|
209
|
+
for (const name of depNames(pkg.json)) {
|
|
210
|
+
if (isEslintDep(name))
|
|
211
|
+
details.push(`${pkg.rel} depends on ${name}`);
|
|
212
|
+
}
|
|
213
|
+
const file = hasFile(pkg.dir, ESLINT_CONFIG_FILES);
|
|
214
|
+
if (file)
|
|
215
|
+
details.push(`${pkg.rel === "." ? "" : `${pkg.rel}/`}${file}: ESLint config file`);
|
|
216
|
+
}
|
|
217
|
+
return result("no-eslint", "No ESLint dependency or config", details);
|
|
218
|
+
}
|
|
219
|
+
export function checkNoPrettier(repo) {
|
|
220
|
+
const details = [];
|
|
221
|
+
for (const pkg of repo.packages) {
|
|
222
|
+
for (const name of depNames(pkg.json)) {
|
|
223
|
+
if (isPrettierDep(name))
|
|
224
|
+
details.push(`${pkg.rel} depends on ${name}`);
|
|
225
|
+
}
|
|
226
|
+
const file = hasFile(pkg.dir, PRETTIER_CONFIG_FILES);
|
|
227
|
+
if (file)
|
|
228
|
+
details.push(`${pkg.rel === "." ? "" : `${pkg.rel}/`}${file}: Prettier config file`);
|
|
229
|
+
if (pkg.json.prettier !== undefined)
|
|
230
|
+
details.push(`${pkg.rel} package.json has a "prettier" key`);
|
|
231
|
+
}
|
|
232
|
+
return result("no-prettier", "No Prettier dependency or config", details);
|
|
233
|
+
}
|
|
234
|
+
function isTypecheckOrLintScript(name) {
|
|
235
|
+
return name === "typecheck" || name === "lint" || name.startsWith("typecheck:") || name.startsWith("lint:");
|
|
236
|
+
}
|
|
237
|
+
export function checkNoPlainTsc(repo) {
|
|
238
|
+
const details = [];
|
|
239
|
+
for (const pkg of repo.packages) {
|
|
240
|
+
for (const [name, command] of Object.entries(pkg.json.scripts ?? {})) {
|
|
241
|
+
if (isTypecheckOrLintScript(name) && runs(command, "tsc")) {
|
|
242
|
+
details.push(`${pkg.rel} script "${name}" runs plain tsc: ${command}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return result("no-plain-tsc", "No typecheck or lint script runs plain tsc", details);
|
|
247
|
+
}
|
|
248
|
+
function repoHasTypeScript(repo) {
|
|
249
|
+
for (const pkg of repo.packages) {
|
|
250
|
+
if (depNames(pkg.json).includes("typescript"))
|
|
251
|
+
return true;
|
|
252
|
+
if (hasFile(pkg.dir, ["tsconfig.json"]))
|
|
253
|
+
return true;
|
|
254
|
+
const scripts = pkg.json.scripts ?? {};
|
|
255
|
+
if (Object.keys(scripts).some((name) => name === "typecheck" || name.startsWith("typecheck:")))
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
export function checkTsrsPresent(repo) {
|
|
261
|
+
if (!repoHasTypeScript(repo))
|
|
262
|
+
return result("tsrs-present", "tsrs is the typechecker where the repo has TypeScript", []);
|
|
263
|
+
const hasTsrs = repo.packages.some((pkg) => depNames(pkg.json).includes("tsrs"));
|
|
264
|
+
const details = hasTsrs ? [] : ["repo has TypeScript but no package declares a tsrs dependency"];
|
|
265
|
+
return result("tsrs-present", "tsrs is the typechecker where the repo has TypeScript", details);
|
|
266
|
+
}
|
|
267
|
+
export function checkOxlintDep(repo) {
|
|
268
|
+
const hasOxlint = repo.packages.some((pkg) => depNames(pkg.json).includes("oxlint"));
|
|
269
|
+
const details = hasOxlint ? [] : ["no package declares an oxlint dependency"];
|
|
270
|
+
return result("oxlint-dep", "oxlint is a dependency", details);
|
|
271
|
+
}
|
|
272
|
+
export function checkOxlintScript(repo) {
|
|
273
|
+
const hasLint = repo.packages.some((pkg) => Object.values(pkg.json.scripts ?? {}).some((command) => runs(command, "oxlint")));
|
|
274
|
+
const details = hasLint ? [] : ["no package has a script that runs oxlint"];
|
|
275
|
+
return result("oxlint-script", "A lint script runs oxlint", details);
|
|
276
|
+
}
|
|
277
|
+
/** The leading major.minor of a version range, or undefined for a non-numeric range (workspace:*, *, latest). */
|
|
278
|
+
export function rangeMinorFloor(range) {
|
|
279
|
+
const match = range.match(/(\d+)\.(\d+)(?:\.\d+)?/);
|
|
280
|
+
if (!match?.[1] || match[2] === undefined)
|
|
281
|
+
return undefined;
|
|
282
|
+
return { major: Number(match[1]), minor: Number(match[2]) };
|
|
283
|
+
}
|
|
284
|
+
/** True when `range`'s minimum is older than `running`'s major.minor. */
|
|
285
|
+
export function isOlderMinor(range, running) {
|
|
286
|
+
const floor = rangeMinorFloor(range);
|
|
287
|
+
const runningFloor = rangeMinorFloor(running);
|
|
288
|
+
if (!floor || !runningFloor)
|
|
289
|
+
return false;
|
|
290
|
+
if (floor.major !== runningFloor.major)
|
|
291
|
+
return floor.major < runningFloor.major;
|
|
292
|
+
return floor.minor < runningFloor.minor;
|
|
293
|
+
}
|
|
294
|
+
export function checkConfigVersion(repo, runningVersion) {
|
|
295
|
+
const details = [];
|
|
296
|
+
for (const pkg of repo.packages) {
|
|
297
|
+
const range = depRange(pkg.json, "@vvedantb/config");
|
|
298
|
+
if (range && isOlderMinor(range, runningVersion)) {
|
|
299
|
+
details.push(`${pkg.rel} has @vvedantb/config ${range}, older than the running ${runningVersion}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return result("config-version", "@vvedantb/config is current to the running minor", details);
|
|
303
|
+
}
|
|
304
|
+
const CI_WORKFLOW_REF = "vvedantb/packages/.github/workflows/ci-app.yml";
|
|
305
|
+
export function checkCiReusableWorkflow(repo) {
|
|
306
|
+
const dir = join(repo.root, ".github", "workflows");
|
|
307
|
+
if (!existsSync(dir)) {
|
|
308
|
+
return result("ci-reusable-workflow", "CI calls the shared ci-app.yml workflow", ["no .github/workflows directory"]);
|
|
309
|
+
}
|
|
310
|
+
let found = false;
|
|
311
|
+
for (const name of readdirSync(dir)) {
|
|
312
|
+
if (!/\.ya?ml$/.test(name))
|
|
313
|
+
continue;
|
|
314
|
+
try {
|
|
315
|
+
if (readFileSync(join(dir, name), "utf8").includes(CI_WORKFLOW_REF))
|
|
316
|
+
found = true;
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
// Unreadable workflow file: ignore and keep scanning.
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const details = found ? [] : [`no workflow calls ${CI_WORKFLOW_REF}`];
|
|
323
|
+
return result("ci-reusable-workflow", "CI calls the shared ci-app.yml workflow", details);
|
|
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
|
+
}
|
|
432
|
+
/** Run every check against the repo at `root`, applying waivers. */
|
|
433
|
+
export function runDoctorChecks(root, options) {
|
|
434
|
+
const repo = loadRepo(root);
|
|
435
|
+
const waivers = options.waivers ?? {};
|
|
436
|
+
const results = [
|
|
437
|
+
checkNoEslint(repo),
|
|
438
|
+
checkNoPrettier(repo),
|
|
439
|
+
checkNoPlainTsc(repo),
|
|
440
|
+
checkTsrsPresent(repo),
|
|
441
|
+
checkOxlintDep(repo),
|
|
442
|
+
checkOxlintScript(repo),
|
|
443
|
+
checkConfigVersion(repo, options.runningVersion),
|
|
444
|
+
checkCiReusableWorkflow(repo),
|
|
445
|
+
checkCiRunner(repo),
|
|
446
|
+
checkCiCommands(repo, options.ciCommandReasons ?? {}),
|
|
447
|
+
];
|
|
448
|
+
return results.map((r) => {
|
|
449
|
+
const reason = waivers[r.id];
|
|
450
|
+
return reason === undefined ? r : { ...r, status: "waived", waiver: reason };
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
const KNOWN_IDS = new Set(CHECK_IDS);
|
|
454
|
+
/**
|
|
455
|
+
* Waivers and CI command reasons from `.vvedantb-doctor.json`
|
|
456
|
+
* (`{ "waivers": { "<id>": "<reason>" }, "ciCommands": { "<command>": "<reason>" } }`) or the root
|
|
457
|
+
* package.json `vvedantbDoctor.waivers`. The file wins over package.json. A waiver needs a
|
|
458
|
+
* non-empty reason and a known id; one that does not is dropped with a warning.
|
|
459
|
+
*/
|
|
460
|
+
export function loadWaivers(root) {
|
|
461
|
+
const warnings = [];
|
|
462
|
+
const raw = {};
|
|
463
|
+
const rawCommands = {};
|
|
464
|
+
const pkg = readJson(join(root, "package.json"));
|
|
465
|
+
Object.assign(raw, pkg?.vvedantbDoctor?.waivers ?? {});
|
|
466
|
+
Object.assign(rawCommands, pkg?.vvedantbDoctor?.ciCommands ?? {});
|
|
467
|
+
const file = join(root, ".vvedantb-doctor.json");
|
|
468
|
+
if (existsSync(file)) {
|
|
469
|
+
try {
|
|
470
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
471
|
+
Object.assign(raw, parsed.waivers ?? {});
|
|
472
|
+
Object.assign(rawCommands, parsed.ciCommands ?? {});
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
warnings.push(".vvedantb-doctor.json is not valid JSON; ignoring it");
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const waivers = {};
|
|
479
|
+
for (const [id, reason] of Object.entries(raw)) {
|
|
480
|
+
if (!KNOWN_IDS.has(id)) {
|
|
481
|
+
warnings.push(`waiver for unknown check "${id}" ignored`);
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (typeof reason !== "string" || reason.trim() === "") {
|
|
485
|
+
warnings.push(`waiver for "${id}" has no written reason; not applied`);
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
waivers[id] = reason.trim();
|
|
489
|
+
}
|
|
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 };
|
|
499
|
+
}
|
|
500
|
+
function readRunningVersion() {
|
|
501
|
+
try {
|
|
502
|
+
const json = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
503
|
+
return json.version ?? "0.0.0";
|
|
504
|
+
}
|
|
505
|
+
catch {
|
|
506
|
+
return "0.0.0";
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
const USAGE = `Usage: vvedantb-doctor [root] [--json]
|
|
510
|
+
|
|
511
|
+
root Repo root to inspect. Default: current directory.
|
|
512
|
+
--json Print the results as JSON.
|
|
513
|
+
|
|
514
|
+
Checks (each has a stable id): ${CHECK_IDS.join(", ")}.
|
|
515
|
+
Waive a check in .vvedantb-doctor.json ({ "waivers": { "<id>": "<reason>" } }) or the
|
|
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>" } }.
|
|
519
|
+
|
|
520
|
+
Exit code: 0 no drift, 1 drift found, 2 bad usage.`;
|
|
521
|
+
/** Run the CLI. Returns the process exit code. */
|
|
522
|
+
export function runDoctor(argv, io) {
|
|
523
|
+
let root = io.cwd();
|
|
524
|
+
let json = false;
|
|
525
|
+
let gotRoot = false;
|
|
526
|
+
for (const arg of argv) {
|
|
527
|
+
if (arg === "--help" || arg === "-h") {
|
|
528
|
+
io.log(USAGE);
|
|
529
|
+
return 0;
|
|
530
|
+
}
|
|
531
|
+
if (arg === "--json") {
|
|
532
|
+
json = true;
|
|
533
|
+
}
|
|
534
|
+
else if (arg.startsWith("--")) {
|
|
535
|
+
io.error(`Unknown option: ${arg}\n${USAGE}`);
|
|
536
|
+
return 2;
|
|
537
|
+
}
|
|
538
|
+
else if (!gotRoot) {
|
|
539
|
+
root = resolve(io.cwd(), arg);
|
|
540
|
+
gotRoot = true;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
io.error(`Unexpected argument: ${arg}\n${USAGE}`);
|
|
544
|
+
return 2;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const runningVersion = readRunningVersion();
|
|
548
|
+
const { waivers, ciCommands: ciCommandReasons, warnings } = loadWaivers(root);
|
|
549
|
+
const results = runDoctorChecks(root, { runningVersion, waivers, ciCommandReasons });
|
|
550
|
+
const failed = results.filter((r) => r.status === "fail");
|
|
551
|
+
if (json) {
|
|
552
|
+
io.log(JSON.stringify({ root, runningVersion, ok: failed.length === 0, warnings, results }, null, 2));
|
|
553
|
+
return failed.length > 0 ? 1 : 0;
|
|
554
|
+
}
|
|
555
|
+
for (const warning of warnings)
|
|
556
|
+
io.error(`warning: ${warning}`);
|
|
557
|
+
for (const r of results) {
|
|
558
|
+
if (r.status === "waived") {
|
|
559
|
+
io.log(`waived ${r.id} ${r.title} — ${r.waiver ?? ""}`);
|
|
560
|
+
}
|
|
561
|
+
else if (r.status === "pass") {
|
|
562
|
+
io.log(`ok ${r.id} ${r.title}`);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
io.error(`DRIFT ${r.id} ${r.title}`);
|
|
566
|
+
for (const line of r.details)
|
|
567
|
+
io.error(` ${line}`);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (failed.length > 0) {
|
|
571
|
+
io.error(`\n${failed.length} check(s) found drift in ${root}. Fix them or waive with a reason.`);
|
|
572
|
+
return 1;
|
|
573
|
+
}
|
|
574
|
+
io.log(`\nNo drift in ${root}.`);
|
|
575
|
+
return 0;
|
|
576
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export { CHECK_ASAR_CHILD_ENV, findBareImports, findSpecifiers, packageName, run
|
|
|
5
5
|
export { DEFAULT_SKIP_DIRS, findSourceTextReads, runCheckNoSourceText, type CheckNoSourceTextIo, type SourceTextViolation, } from "./check-no-source-text.js";
|
|
6
6
|
export { checkSharedUi, runCheckSharedUi, type CheckSharedUiIo, type CheckSharedUiOptions, } from "./check-shared-ui.js";
|
|
7
7
|
export { runClerkAllow, type ClerkAllowFetch, type ClerkAllowIo, type ClerkAllowResponse, } from "./clerk-allow.js";
|
|
8
|
+
export { SHARED_WORKER_SETUP, sharedWorkerVitestConfig, type SharedWorkerOptions, type SharedWorkerTestConfig, type SharedWorkerVitestConfig, } from "./vitest-shared.js";
|
|
9
|
+
export { CHECK_IDS, checkCiReusableWorkflow, checkConfigVersion, checkNoEslint, checkNoPlainTsc, checkNoPrettier, checkOxlintDep, checkOxlintScript, checkTsrsPresent, isOlderMinor, loadRepo, loadWaivers, rangeMinorFloor, runDoctor, runDoctorChecks, type CheckId, type CheckResult, type CheckStatus, type DoctorCheckOptions, type DoctorIo, type LoadedWaivers, type PackageEntry, type RepoModel, } from "./doctor.js";
|
|
8
10
|
export { REACT_DEDUPE, defineWebViteConfig, defineWebVitestConfig, reactPlugins, srcAlias, vendorChunkBuild, type AliasOptions, type BabelReactCompiler, type PathOptions, type ReactSetup, type ResolveConfig, type RouterPluginOptions, type VendorChunk, type VendorChunkGroup, type VitePlugin, type VitePluginOption, type WebBuildConfig, type WebViteConfig, type WebViteOptions, type WebVitestConfig, type WebVitestOptions, } from "./vite.js";
|
|
9
11
|
export { defineExpoMetroConfig, expoBabelConfig, type BabelApi, type ExpoBabelConfig, type ExpoMetroOptions, type MetroConfigLike, type MetroResolveContext, type MetroResolveRequest, type NativeWindMetroOptions, } from "./expo.js";
|
|
10
12
|
export { DEFAULT_RELEASE_SIGNING_MARKER, appendReleaseSigning, releaseSigningGradle, withReleaseSigning, type AppBuildGradleMod, type ReleaseSigningOptions, type ReleaseSigningPropertyKeys, type WithAppBuildGradle, type WithReleaseSigningOptions, } from "./release-signing.js";
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,8 @@ export { CHECK_ASAR_CHILD_ENV, findBareImports, findSpecifiers, packageName, run
|
|
|
5
5
|
export { DEFAULT_SKIP_DIRS, findSourceTextReads, runCheckNoSourceText, } from "./check-no-source-text.js";
|
|
6
6
|
export { checkSharedUi, runCheckSharedUi, } from "./check-shared-ui.js";
|
|
7
7
|
export { runClerkAllow, } from "./clerk-allow.js";
|
|
8
|
+
export { SHARED_WORKER_SETUP, sharedWorkerVitestConfig, } from "./vitest-shared.js";
|
|
9
|
+
export { CHECK_IDS, checkCiReusableWorkflow, checkConfigVersion, checkNoEslint, checkNoPlainTsc, checkNoPrettier, checkOxlintDep, checkOxlintScript, checkTsrsPresent, isOlderMinor, loadRepo, loadWaivers, rangeMinorFloor, runDoctor, runDoctorChecks, } from "./doctor.js";
|
|
8
10
|
export { REACT_DEDUPE, defineWebViteConfig, defineWebVitestConfig, reactPlugins, srcAlias, vendorChunkBuild, } from "./vite.js";
|
|
9
11
|
export { defineExpoMetroConfig, expoBabelConfig, } from "./expo.js";
|
|
10
12
|
export { DEFAULT_RELEASE_SIGNING_MARKER, appendReleaseSigning, releaseSigningGradle, withReleaseSigning, } from "./release-signing.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { afterEach, vi } from "vitest";
|
|
2
|
+
// Added to `setupFiles` by `sharedWorkerVitestConfig`. With isolation off, every test
|
|
3
|
+
// file shares one worker, so state set in one test can leak into the next. The preset's
|
|
4
|
+
// config flags (`restoreMocks`, `unstubEnvs`, `unstubGlobals`) reset mocks, env stubs and
|
|
5
|
+
// global stubs after each test; fake timers have no config flag, so reset them here.
|
|
6
|
+
//
|
|
7
|
+
// This does NOT reset module-level state: a module's own top-level variables, caches or
|
|
8
|
+
// singletons created on import persist for the whole run. A test file that mutates that
|
|
9
|
+
// state must restore it itself (see the README cleanup rules).
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
vi.useRealTimers();
|
|
12
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { WebVitestConfig } from "./vite.js";
|
|
2
|
+
/** Absolute path to the setup file that resets per-test state. Added to `setupFiles`. */
|
|
3
|
+
export declare const SHARED_WORKER_SETUP: string;
|
|
4
|
+
/** The `test` fields the shared-worker preset sets. */
|
|
5
|
+
export interface SharedWorkerTestConfig {
|
|
6
|
+
/** Files on the same worker share one environment instead of reloading per file. */
|
|
7
|
+
isolate: false;
|
|
8
|
+
/** Random file order so cross-file state leaks surface. `tests` stays stable by default. */
|
|
9
|
+
sequence: {
|
|
10
|
+
shuffle: {
|
|
11
|
+
files: boolean;
|
|
12
|
+
tests: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/** Restore spied/mocked implementations after each test. */
|
|
16
|
+
restoreMocks: true;
|
|
17
|
+
/** Undo `vi.stubEnv` after each test. */
|
|
18
|
+
unstubEnvs: true;
|
|
19
|
+
/** Undo `vi.stubGlobal` after each test. */
|
|
20
|
+
unstubGlobals: true;
|
|
21
|
+
/** The shared reset setup first, then any the caller passed. */
|
|
22
|
+
setupFiles: string[];
|
|
23
|
+
/** Carried over from the base config when present. */
|
|
24
|
+
environment?: string;
|
|
25
|
+
include?: string[];
|
|
26
|
+
server?: {
|
|
27
|
+
deps: {
|
|
28
|
+
inline: string[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** The config the shared-worker preset returns. Spread into `defineConfig` from `vitest/config`. */
|
|
33
|
+
export interface SharedWorkerVitestConfig {
|
|
34
|
+
plugins?: WebVitestConfig["plugins"];
|
|
35
|
+
esbuild?: WebVitestConfig["esbuild"];
|
|
36
|
+
resolve?: WebVitestConfig["resolve"];
|
|
37
|
+
test: SharedWorkerTestConfig;
|
|
38
|
+
}
|
|
39
|
+
export interface SharedWorkerOptions {
|
|
40
|
+
/** Also shuffle test order within each file. Default `false` (only file order shuffles). */
|
|
41
|
+
shuffleTests?: boolean;
|
|
42
|
+
/** Extra setup files, run after the shared reset setup. */
|
|
43
|
+
setupFiles?: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The shared-worker Vitest config. Pass the output of `defineWebVitestConfig` to keep its
|
|
47
|
+
* `include`, `environment`, plugins and resolve, or call it with no base for a standalone config.
|
|
48
|
+
*/
|
|
49
|
+
export declare function sharedWorkerVitestConfig(base?: WebVitestConfig, options?: SharedWorkerOptions): SharedWorkerVitestConfig;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
// An opt-in Vitest preset that trades isolation for speed. Vitest normally reloads
|
|
3
|
+
// every test file in a fresh environment; with this preset the files that land on a
|
|
4
|
+
// worker share its module graph. Files run in a shuffled order and the common state
|
|
5
|
+
// sinks are reset between tests, so a leak surfaces as a failure instead of hiding.
|
|
6
|
+
// The number of workers is left alone: Vitest still uses every core.
|
|
7
|
+
//
|
|
8
|
+
// Turning isolation off is a real behaviour change, so this is a named export a repo
|
|
9
|
+
// opts into, not part of `defineWebVitestConfig`. See the README section
|
|
10
|
+
// "Shared-worker Vitest preset" for the adoption snippet and the cleanup rules a test
|
|
11
|
+
// file must follow when isolation is off.
|
|
12
|
+
//
|
|
13
|
+
// Only top-level `test` fields are set (`isolate`, `sequence.shuffle`, `restoreMocks`,
|
|
14
|
+
// `unstubEnvs`, `unstubGlobals`, `setupFiles`). `poolOptions` is not used: Vitest 4
|
|
15
|
+
// removed it. `pool` and the worker count are left to the repo. The preset does not
|
|
16
|
+
// support the `vmThreads` / `vmForks` pools, where `isolate` behaves differently.
|
|
17
|
+
/** Absolute path to the setup file that resets per-test state. Added to `setupFiles`. */
|
|
18
|
+
export const SHARED_WORKER_SETUP = fileURLToPath(new URL("./vitest-shared-setup.js", import.meta.url));
|
|
19
|
+
/**
|
|
20
|
+
* The shared-worker Vitest config. Pass the output of `defineWebVitestConfig` to keep its
|
|
21
|
+
* `include`, `environment`, plugins and resolve, or call it with no base for a standalone config.
|
|
22
|
+
*/
|
|
23
|
+
export function sharedWorkerVitestConfig(base, options = {}) {
|
|
24
|
+
const test = {
|
|
25
|
+
isolate: false,
|
|
26
|
+
sequence: { shuffle: { files: true, tests: options.shuffleTests ?? false } },
|
|
27
|
+
restoreMocks: true,
|
|
28
|
+
unstubEnvs: true,
|
|
29
|
+
unstubGlobals: true,
|
|
30
|
+
setupFiles: [SHARED_WORKER_SETUP, ...(options.setupFiles ?? [])],
|
|
31
|
+
};
|
|
32
|
+
if (base?.test.environment)
|
|
33
|
+
test.environment = base.test.environment;
|
|
34
|
+
if (base?.test.include)
|
|
35
|
+
test.include = base.test.include;
|
|
36
|
+
if (base?.test.server)
|
|
37
|
+
test.server = base.test.server;
|
|
38
|
+
const config = { test };
|
|
39
|
+
if (base?.plugins)
|
|
40
|
+
config.plugins = base.plugins;
|
|
41
|
+
if (base?.esbuild)
|
|
42
|
+
config.esbuild = base.esbuild;
|
|
43
|
+
if (base?.resolve)
|
|
44
|
+
config.resolve = base.resolve;
|
|
45
|
+
return config;
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/config",
|
|
3
|
-
"version": "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",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"vvedantb-clerk-allow": "./dist/clerk-allow-cli.js",
|
|
20
20
|
"vvedantb-android-release": "./dist/android-release-cli.js",
|
|
21
21
|
"vvedantb-check-shared-ui": "./dist/check-shared-ui-cli.js",
|
|
22
|
-
"vvedantb-check-no-source-text": "./dist/check-no-source-text-cli.js"
|
|
22
|
+
"vvedantb-check-no-source-text": "./dist/check-no-source-text-cli.js",
|
|
23
|
+
"vvedantb-doctor": "./dist/doctor-cli.js"
|
|
23
24
|
},
|
|
24
25
|
"exports": {
|
|
25
26
|
".": {
|
|
@@ -53,7 +54,8 @@
|
|
|
53
54
|
],
|
|
54
55
|
"peerDependencies": {
|
|
55
56
|
"@electron/asar": "^3.2.0 || ^4.0.0",
|
|
56
|
-
"@expo/config-plugins": ">=9.0.0"
|
|
57
|
+
"@expo/config-plugins": ">=9.0.0",
|
|
58
|
+
"vitest": ">=3.0.0"
|
|
57
59
|
},
|
|
58
60
|
"peerDependenciesMeta": {
|
|
59
61
|
"@electron/asar": {
|
|
@@ -61,6 +63,9 @@
|
|
|
61
63
|
},
|
|
62
64
|
"@expo/config-plugins": {
|
|
63
65
|
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"vitest": {
|
|
68
|
+
"optional": true
|
|
64
69
|
}
|
|
65
70
|
},
|
|
66
71
|
"devDependencies": {
|
|
@@ -74,8 +79,8 @@
|
|
|
74
79
|
"vitest": "^3.2.0"
|
|
75
80
|
},
|
|
76
81
|
"scripts": {
|
|
77
|
-
"build": "
|
|
78
|
-
"typecheck": "
|
|
82
|
+
"build": "tsrs -p tsconfig.json",
|
|
83
|
+
"typecheck": "tsrs --noEmit --fast -p tsconfig.test.json",
|
|
79
84
|
"test": "vitest run"
|
|
80
85
|
}
|
|
81
86
|
}
|