@jfalava/ts-standard 0.3.6 → 0.3.8

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/docs/workflows.md CHANGED
@@ -1,14 +1,15 @@
1
1
  # Workflow rules
2
2
 
3
- | Rule | Checks |
4
- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5
- | `workflows/ci-reference` | A public repo has `ci.yml` and a private one does not. `ci.yml` equals `reference/ci.yml` once the additions in `ci` are taken out, ignoring action refs. Filter differences name the pattern. |
6
- | `workflows/actions-pinned` | Every `uses:` outside the repo is pinned to a 40-character SHA with a `# v…` comment. |
7
- | `workflows/reference-pins` | Warning. An action the reference also uses is at the reference's SHA. |
8
- | `workflows/dependabot` | `.github/dependabot.yml` has a `github-actions` entry. |
9
- | `workflows/hygiene` | Every workflow has top-level `permissions` and a `concurrency` group (reusable workflows excepted), and every job that runs steps has `timeout-minutes`. |
10
- | `workflows/bun-from-package-manager` | No `setup-bun` step sets `bun-version`. |
11
- | `workflows/scripts-only` | `run:` steps call bun only as `bun install --frozen-lockfile` or `bun run <script>`, never `bunx`, and never `--ignore-scripts`. |
12
- | `workflows/release-check` | A tag-triggered workflow runs `bun run check`. |
13
- | `workflows/release-version` | A tag-triggered workflow checks the tag against the package version (`${GITHUB_REF_NAME#v}`). |
14
- | `workflows/release-build` | A tag-triggered workflow calls `build:<target>` scripts, and every matrix target exists as a script in the package it runs in. |
3
+ | Rule | Checks |
4
+ | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5
+ | `workflows/ci-reference` | A public repo has `ci.yml` and a private one does not. `ci.yml` equals `reference/ci.yml` once the additions in `ci` are taken out, ignoring action refs. Filter differences name the pattern. |
6
+ | `workflows/actions-pinned` | Every `uses:` outside the repo is pinned to a 40-character SHA with a `# v…` comment. |
7
+ | `workflows/reference-pins` | Warning. An action the reference also uses is at the reference's SHA. |
8
+ | `workflows/dependabot` | `.github/dependabot.yml` has a `github-actions` entry. |
9
+ | `workflows/hygiene` | Every workflow has top-level `permissions` and a `concurrency` group (reusable workflows excepted), and every job that runs steps has `timeout-minutes`. |
10
+ | `workflows/bun-from-package-manager` | No `setup-bun` step sets `bun-version`. |
11
+ | `workflows/scripts-only` | `run:` steps call bun only as `bun install --frozen-lockfile` or `bun run <script>`, never `bunx`, and never `--ignore-scripts`. |
12
+ | `workflows/release-trigger` | A release workflow triggers on `push: tags: ["v*"]` and nothing else. A workflow is a release workflow when it is named `release.yml` or `<prefix>-release.yml`, is triggered by tags, or publishes (`npm`, `bun`, `pnpm` or `yarn publish`, `gh release create`, `softprops/action-gh-release`). |
13
+ | `workflows/release-check` | A tag-triggered workflow runs `bun run check`. |
14
+ | `workflows/release-version` | A tag-triggered workflow checks the tag against the package version (`${GITHUB_REF_NAME#v}`). |
15
+ | `workflows/release-build` | A tag-triggered workflow calls `build:<target>` scripts, and every matrix target exists as a script in the package it runs in. |
@@ -26,7 +26,7 @@
26
26
  "devDependencies": {
27
27
  "@cloudflare/oxlint-config": "0.2.0",
28
28
  "@effect/tsgo": "0.74.1",
29
- "@jfalava/ts-standard": "0.3.6",
29
+ "@jfalava/ts-standard": "0.3.8",
30
30
  "@oxlint/plugins": "1.95.0",
31
31
  "bun-types": "1.4.5",
32
32
  "oxfmt": "0.80.0",
@@ -11,7 +11,7 @@
11
11
  "build": {
12
12
  "@cloudflare/oxlint-config": "0.2.0",
13
13
  "@effect/tsgo": "0.74.1",
14
- "@jfalava/ts-standard": "0.3.6",
14
+ "@jfalava/ts-standard": "0.3.8",
15
15
  "@oxlint/plugins": "1.95.0",
16
16
  "bun-types": "1.4.5",
17
17
  "oxfmt": "0.80.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jfalava/ts-standard",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "Checks a Bun repo against the TypeScript scripts and workflows standard: package.json scripts, pins, tsconfig, lint setup and GitHub workflows. Also ships the anti-slop oxlint plugins the standard uses.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -15,6 +15,7 @@
15
15
  "reference",
16
16
  "docs",
17
17
  "examples",
18
+ "skills",
18
19
  "dist",
19
20
  "oxlint/LICENSE",
20
21
  "oxlint/UPSTREAM.md"
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: applying-ts-standard
3
+ description: "Applies jfalava's TypeScript scripts and workflows standard, enforced by @jfalava/ts-standard, to a Bun repo: package.json script names and fan-out, exact pins, effect-tsgo typecheck, oxlint with the anti-slop plugins and the zero-pending policy, GitHub ci.yml, release.yml and Dependabot, Cloudflare Workers Builds triggers and watch-path excludes, and standard.config.ts. Use when setting up a new TypeScript repo, bringing an existing one into line, fixing `standard:check` or lint findings, adding or renaming scripts, editing CI workflows or oxlint config, or deciding a Workers Builds exclude list. Not for Rust, Astro-only content edits, or Cloudflare product choice."
4
+ ---
5
+
6
+ # TypeScript scripts and workflows standard
7
+
8
+ The checker is `@jfalava/ts-standard`. Its docs (`docs/` in https://github.com/jfalava/ts-standard, indexed from the README, and in an installed repo at `node_modules/@jfalava/ts-standard/docs/` from 0.3.4) list every rule and are the detail behind this skill; read the page for the area you are changing when a case below is not covered. `bun run standard:check` decides whether a repo complies, so run it instead of reasoning about compliance.
9
+
10
+ Copy from the examples the package ships instead of writing from memory. They are in `node_modules/@jfalava/ts-standard/examples/` once the package is installed (from 0.3.5), and in `examples/` in the GitHub repo before that. Each passes `ts-standard` with no findings:
11
+
12
+ - `examples/package/`: a single package without `effect` (`package.json`, `bunfig.toml`, `tsconfig.json`, `oxlint.config.ts`).
13
+ - `examples/workspace/`: a workspace with a root catalog, `tsconfig.base.json`, a root `oxlint.config.ts` exporting `base` and `antiSlopEffect`, two packages that depend on `effect`, and an Alchemy `iac` package.
14
+ - `examples/github/`: `dependabot.yml` and a tag-triggered `release.yml`. `ci.yml` is `reference/ci.yml`.
15
+
16
+ ## Scripts
17
+
18
+ Every package with TypeScript defines these names, each with one meaning. A package leaves a verb out only when it has nothing to do, such as `test` with no tests.
19
+
20
+ - `lint`: read-only, `oxlint --type-aware --type-check`. `lint:fix` is the same with `--fix`.
21
+ - `format`: writes, `oxfmt`. `format:check` is `oxfmt --check`.
22
+ - `typecheck`: `effect-tsgo tsrs --noEmit`, never plain `tsrs --noEmit`, which silently passes when the patch did not run. Astro packages use `astro check`; Pulumi packages use `tsc --noEmit`.
23
+ - `test`: runs once and exits (`vitest run` or `bun test`), with no network, credentials or deployed infrastructure. Suites that need those are `test:integration` and stay out of `test`.
24
+ - `check`: the read-only gate, exactly `bun run lint && bun run format:check && bun run typecheck && bun run test`, followed only by the package's `bun run <thing>:check` scripts. Every `<thing>:check` must be reached from `check`. Nothing reached from `check` may write a tracked file.
25
+ - `fix`: exactly `bun run lint:fix && bun run format`. This is the only command that rewrites files.
26
+ - `build`: produces the artifact and nothing else. Release targets are `build:<os>-<arch>`.
27
+ - `ci:build` and `ci:deploy`: root only, for Workers Builds. `ci:build` is `bun run check`, or `bun run check && bun run build` when the deploy needs built output. `ci:deploy` is the non-interactive deploy (`--yes`) and runs no checks.
28
+ - `plan`, `deploy`, `destroy`: `plan` is `alchemy plan`; `deploy` and `destroy` are interactive. All four deploy scripts name the same explicit target (`--stage prod`, `--stack`, or a variable assignment in front). Read the deployed stage from `alchemy state` before adding a `--stage`, because a new name creates a second stack.
29
+
30
+ Names for everything else: a variant is `<verb>:<variant>` (`test:workers`, `lint:astro`); a read-only verifier of a generator is `<thing>:check`. Aggregates call `bun run test`, never bare `bun test`. No `bunx` or `bun x`, no `pre<script>` hooks besides `prepare`, no `--filter`, no `:global` suffix. A script works on a fresh clone after `bun install`, generating any input it needs.
31
+
32
+ In a workspace repo the root uses the same names and fans out:
33
+
34
+ - `check` is `bun run --workspaces check` with no `--if-present`, so a package without `check` fails the gate. Repo-wide checks (root `oxfmt --check`, `bun run standard:check`) chain after it. Only a repo-wide prerequisite may run before it.
35
+ - Every other verb is `bun run --workspaces --if-present <verb>`.
36
+ - Delegating to one package uses `bun run --cwd <pkg> <script>`, and only for `dev` and the deploy scripts. There are no root shortcuts such as `test:cli`.
37
+ - Workspace package `lint` and `lint:fix` also pass `--report-unused-disable-directives-severity=error`, because the preset's unused-directive option is root-only.
38
+
39
+ When `check` used to be a fixer in a repo, update its `AGENTS.md` and README in the same change, or agents keep running `check` expecting autofixes.
40
+
41
+ ## Typecheck and pins
42
+
43
+ - Root `prepare` is exactly `effect-tsgo patch --no-typescript --tsrs --oxlint`. It runs on every `bun install`. `--no-typescript` is required when no native `typescript` package is installed, and only Astro and Pulumi packages may depend on `typescript`. Never install with `--ignore-scripts`.
44
+ - Root `packageManager` is `bun@1.4.5`, the only place the bun version lives. `bun-types` or `@types/bun` uses the same version. Workflows and Workers Builds read it; remove `bun-version:` inputs and `BUN_VERSION` build variables.
45
+ - Workspace repos keep tool versions exact in a root catalog and reference them as `catalog:build`. The current set is `@cloudflare/oxlint-config` 0.2.0, `@effect/tsgo` 0.74.1, `@jfalava/ts-standard` 0.3.8, `@oxlint/plugins` 1.95.0, `oxfmt` 0.80.0, `oxlint` 1.95.0, `tsrs` 7.1.0-beta.tsrs5. All seven are root `devDependencies`. Single-package repos use the same exact versions in `devDependencies`. Every dependency is an exact version. No `oxlint-tsgolint`.
46
+ - Bump `@effect/tsgo`, `tsrs` and `oxlint` (with `@oxlint/plugins`) in one change; `prepare` fails the install with `UnsupportedTargetPackageVersionError` on an unsupported pair. Take the pins from the examples of the installed ts-standard version, and check npm for newer supported sets before a bump.
47
+ - `bunfig.toml` sets `minimumReleaseAge = 86400` and lists in `minimumReleaseAgeExcludes`, by exact name, `@jfalava/ts-standard`, `@effect/tsgo` and its seven `@effect/tsgo-<platform>` packages. A scope glob such as `@jfalava/*` excludes nothing.
48
+ - tsconfig: one base (`tsconfig.base.json` in a workspace repo, `tsconfig.json` otherwise) with `$schema` `./node_modules/@effect/tsgo/schema.json`, `noEmit: true`, `strict`, `noUncheckedIndexedAccess`, and a `plugins` entry named `@effect/language-service`. Without that entry Effect diagnostics are off and typecheck passes on a floating Effect. Each package has one `tsconfig.json` that extends the base, sets no strict flags or `plugins`, and includes its tests; no `tsconfig.test.json`. Never set `ignoreEffectWarningsInTscExitCode`.
49
+
50
+ ## Lint
51
+
52
+ The root `oxlint.config.ts` builds on `@cloudflare/oxlint-config`: it splits off the preset's root-only options with `const { options: presetOptions, ...preset } = cloudflare`, exports an options-free `base`, and its default export spreads `base` with `options: { ...presetOptions, typeAware: true, typeCheck: true }`. It sets `categories.correctness`. Effect repos add `recommended` from `@effect/tsgo/oxlint-presets`. Package configs spread `base`; never use `extends`, which drops `env` and `overrides`.
53
+
54
+ The anti-slop rules come from the package, loaded by absolute path so every workspace config resolves them the same way:
55
+
56
+ - `anti-slop`, from `fileURLToPath(import.meta.resolve("@jfalava/ts-standard/oxlint"))`, in every config: `no-module-mocking` and `require-safety-comment-for-type-assertion`.
57
+ - `anti-slop-effect`, from `@jfalava/ts-standard/oxlint/effect`, in exactly the packages whose `package.json` lists `effect` as a direct dependency, and nowhere else, because its rules match code shape and report non-Effect code: `no-manual-effect-error-tag`, `no-manual-tag-comparison`, `no-manual-tagged-construction`, `no-service-constructor-imports`, `prefer-effect-match`. Copy the `antiSlopEffect` export from `examples/workspace/oxlint.config.ts` and add it in those packages.
58
+ - Every kept rule is at `error`. Delete any vendored `tools/oxlint/anti-slop` folder; the checker fails while it exists.
59
+
60
+ Zero pending is the policy for every lint rule. A rule that fails when first turned on may go into a pending map as `"<rule>": "off", // <count>`, but the map is a to-do list that ends empty. A rule at `warn` counts as pending too, because warnings fail nothing. Clear each finding by fixing it, or silence it with one of three forms, each naming one rule and carrying a reason after `--`:
61
+
62
+ - Default: `// oxlint-disable-next-line <rule> -- <reason>` on the line above.
63
+ - A file that is one repeated pattern: one `// oxlint-disable <rule> -- <reason>` at the top of the file.
64
+ - A single if/else chain: `// oxlint-disable <rule> -- <reason>` before it and `// oxlint-enable <rule>` after it. A pair without its enable disables to the end of the file.
65
+
66
+ Unused disables are errors, so a disable goes when its finding does. Moving a rule from the pending map into the policy map as a plain `off` passes the checker; treat it as a policy change the user decides, not a way to empty the map.
67
+
68
+ Accepted gaps, which pass the checker and need no fix: a `categories: { suspicious: "warn" }` entry may stay where a repo has one, and no check sees a category; pending counts are not compared with a lint run; packages that lint through `vp lint` are skipped by the lint rules; `@effect/tsgo` preset rules at `warn` are the preset's policy; `oxfmt --check` reads Markdown and YAML on the skip list, so a badly formatted README-only change passes until the next code change.
69
+
70
+ ## Workflows
71
+
72
+ Public repos gate on GitHub. Copy `reference/ci.yml` from the ts-standard package (`node_modules/@jfalava/ts-standard/reference/ci.yml`) unchanged: it runs on every branch push and pull request, its `changes` job (pinned `dorny/paths-filter`, `predicate-quantifier: some-with-excludes`) decides whether `check` runs, and `check` runs `bun install --frozen-lockfile` then `bun run check`. Edit only the filter list or add jobs and filters, and declare each addition in `standard.config.ts` under `ci`. Never add `paths-ignore` to the trigger: a skipped workflow leaves the required check pending. The branch rule requires the job named `check`, never `changes`.
73
+
74
+ - Pin every action to a 40-character SHA with a `# v<version>` comment, and add `.github/dependabot.yml` with a `github-actions` entry so the pins move.
75
+ - Every workflow has top-level `permissions`, a `concurrency` group and `timeout-minutes` on each job. `run:` steps call bun only as `bun install --frozen-lockfile` or `bun run <script>`.
76
+ - `release.yml` triggers on tags `v*` only. Release tags are plain `v<version>`, monorepos included; there is no `cli-v` or other prefix. It checks the tag against the released package's version (`test "${GITHUB_REF_NAME#v}" = "$(jq -r .version package.json)"`), runs `bun run check`, builds with the `build:<target>` scripts in a matrix, and deploys nothing.
77
+
78
+ Private repos set `visibility: "private"` in `standard.config.ts`, have no `ci.yml`, and use Workers Builds as their only check.
79
+
80
+ Deploys always run on Workers Builds; no workflow deploys and no Cloudflare token goes into GitHub secrets.
81
+
82
+ - Public repo: one trigger, on the deploy branch (`main`, or a release branch such as `stable`), build command `bun run ci:build`, deploy command `bun run ci:deploy`. Delete a non-production trigger only after `ci.yml` and the branch rule exist.
83
+ - Private repo: production trigger on the deploy branch with `bun run ci:build` and `bun run ci:deploy`, plus a non-production trigger on every other branch with `bun run ci:build` and deploy command `true`.
84
+ - Both: build cache on, no `BUN_VERSION` variable.
85
+
86
+ ## Workers Builds watch paths
87
+
88
+ Every trigger includes `*` and carries an exclude list. Cloudflare evaluates excludes first, so a push touching only excluded paths starts no build, and a new path builds by default. Patterns match from the start of the path and take a wildcard only at the start or end: `oxlint.config.ts` is the root file only, `*README.md` is every README, a directory needs `/*` (`common/` without it is a literal path and matches nothing).
89
+
90
+ Derive the excludes from what the build reads:
91
+
92
+ 1. Start from the base list. Public: `*README.md`, `*AGENTS.md`, `*CLAUDE.md`, `STANDARD.md`, `LICENSE*`, `.agents/*`, `.zed/*`, `.vscode/*`, `.github/*`, `.gitignore`, `tools/*`, `oxlint.config.ts`, `oxfmt.config.ts`, `.oxfmtrc.json`, `standard.config.ts`. Private: only the first ten, `*README.md` through `.gitignore`, because the build is the only check and lint, format and standard configs change what `check` reports. Drop entries for paths the repo does not have.
93
+ 2. Public only: add packages and paths the deploy never reads, such as `cli/*` or `test/*`. Trace `ci:deploy` through every script it runs, every file those scripts copy into assets, and every import of the deployed packages. A deploy that runs `scripts/*` or copies `LICENSE` into its assets must not exclude them.
94
+ 3. Private only: add host files that no package reads and `check` does not cover, such as backup manifests or `*.nix` host config. Leave `.github/*` off when the repo has workflow files and runs `standard:check`, which reads them.
95
+ 4. Never exclude `package.json`, `bun.lock`, `bunfig.toml` or `tsconfig*`.
96
+ 5. Give every entry a reason, and record the triggers, commands and exclude list as a table in the repo's README. A new path that is not code goes on the list in the same change.
97
+
98
+ You write the repo side: scripts, the README settings table and the exclude list with reasons. The user changes Cloudflare: triggers, commands, watch paths, variables and cache are dashboard settings. End with the exact settings to enter, and say that renaming a script the dashboard calls breaks the build until the dashboard changes too. Branch rules on GitHub are shared state; ask before changing them.
99
+
100
+ ## `standard.config.ts`
101
+
102
+ A repo needs it only where it differs from the defaults (public, every package `oxc`):
103
+
104
+ ```ts
105
+ import { defineStandard } from "@jfalava/ts-standard";
106
+
107
+ export default defineStandard({
108
+ visibility: "private",
109
+ toolchains: { docs: "astro" },
110
+ ci: { ignoreAdd: ["LICENSES/**"], jobs: ["rust"] },
111
+ exceptions: [
112
+ {
113
+ rule: "scripts/check-runs-own-checks",
114
+ where: "docs",
115
+ script: "licenses:check",
116
+ why: "Needs the network.",
117
+ },
118
+ ],
119
+ });
120
+ ```
121
+
122
+ Every exception has a `why` and a matching row in the exceptions table of the repo's root `STANDARD.md` (`| Rule | Where | Script | Why |`, format in `docs/configuration.md`), changed in the same change as the exception. The README keeps only the Workers Builds tables. An exception that matches nothing fails as `standard/stale-exception`. Exceptions for `lint/anti-slop` or `lint/pending` must name exactly `<pkg>:<plugin>/<rule>` or `<pkg>:<rule>`; a broader `where` fails as `standard/broad-exception`. Prefer fixing the repo to adding an exception.
123
+
124
+ Root `check` ends with `bun run standard:check`, and `standard:check` is `ts-standard`. It exits 1 on any error; `workflows/reference-pins` is the only warning. `ts-standard --json` gives machine-readable findings.
125
+
126
+ ## Applying the standard to a repo
127
+
128
+ 1. Read the repo: `git status`, `gh repo view --json visibility`, workspace or single package, which packages list `effect`, the deploy branch, and the current scripts, workflows, README settings table and `STANDARD.md`. Move an exceptions table still in the README to `STANDARD.md`. For a new repo, copy the matching example instead of starting blank.
129
+ 2. Add the pins, `prepare`, `bunfig.toml` and tsconfig base, then run `bun install`. Confirm `node_modules/.bin/tsrs --version` contains `+effect-tsgo`; without it the patch did not run.
130
+ 3. Rename and rewrite scripts, then the root fan-out and `ci:build` and `ci:deploy`.
131
+ 4. Write `oxlint.config.ts` and the package configs with the anti-slop plugins. Run `bun run lint` and clear every finding by the zero-pending policy.
132
+ 5. Add the workflows and Dependabot (public) or set `visibility: "private"`, add `standard.config.ts` only if needed with its exceptions in `STANDARD.md`, and update the README tables and any `AGENTS.md` that names the old scripts.
133
+ 6. Verify: `bun run fix`, then `bun run check` from a clean tree, then `git status --porcelain` empty (proves `check` is read-only), then `bun run standard:check` with 0 errors. For a public repo, confirm the `check` job is green on the pushed commit.
134
+ 7. Report the Cloudflare and GitHub settings the user must change, with the exact values.
package/src/workflows.ts CHANGED
@@ -107,6 +107,24 @@ const runLines = (wf: any): { job: string; line: string }[] =>
107
107
  ),
108
108
  );
109
109
 
110
+ /** `release.yml`, or a prefixed one such as `manifold-cli-release.yml`. */
111
+ const RELEASE_NAME = /(?:^|-)release\.ya?ml$/;
112
+
113
+ /** Publishes a package or a GitHub release, whatever the workflow is named. */
114
+ const publishes = (wf: any): boolean =>
115
+ Object.values<any>(wf.jobs ?? {}).some((j) =>
116
+ (j.steps ?? []).some(
117
+ (s: any) => typeof s.uses === "string" && s.uses.startsWith("softprops/action-gh-release"),
118
+ ),
119
+ ) ||
120
+ runLines(wf).some(({ line }) =>
121
+ parseScript(line).some(({ argv: [bin, sub, arg] }) =>
122
+ ["npm", "bun", "pnpm", "yarn"].includes(bin!)
123
+ ? sub === "publish"
124
+ : bin === "gh" && sub === "release" && arg === "create",
125
+ ),
126
+ );
127
+
110
128
  export const workflowRules = (repo: Repo): Finding[] => {
111
129
  const out: Finding[] = [];
112
130
  const f = (rule: string, where: string, message: string) => out.push({ rule, where, message });
@@ -259,6 +277,16 @@ export const workflowRules = (repo: Repo): Finding[] => {
259
277
  }
260
278
 
261
279
  const tags = wf.on?.push?.tags;
280
+ if (
281
+ (tags !== undefined || RELEASE_NAME.test(name) || publishes(wf)) &&
282
+ JSON.stringify(wf.on) !== JSON.stringify({ push: { tags: ["v*"] } })
283
+ ) {
284
+ f(
285
+ "workflows/release-trigger",
286
+ where,
287
+ `triggers on \`${JSON.stringify(wf.on)}\`; a release workflow runs on \`push: tags: ["v*"]\` only`,
288
+ );
289
+ }
262
290
  if (tags !== undefined) {
263
291
  out.push(...releaseRules(repo, where, wf));
264
292
  }