@jfalava/ts-standard 0.1.0 → 0.2.3

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/src/workflows.ts CHANGED
@@ -11,7 +11,9 @@ const PINNED = /^\s*(?:-\s+)?uses:\s*([^@\s]+)@([0-9a-f]{40})\s+#\s*v\d/;
11
11
  const USES = /^\s*(?:-\s+)?uses:\s*(\S+)/;
12
12
 
13
13
  const stripRef = (v: any): any => {
14
- if (Array.isArray(v)) return v.map(stripRef);
14
+ if (Array.isArray(v)) {
15
+ return v.map(stripRef);
16
+ }
15
17
  if (v && typeof v === "object") {
16
18
  return Object.fromEntries(
17
19
  Object.entries(v).map(([k, x]) => [
@@ -24,7 +26,9 @@ const stripRef = (v: any): any => {
24
26
  };
25
27
 
26
28
  const diffPaths = (a: any, b: any, path = ""): string[] => {
27
- if (JSON.stringify(a) === JSON.stringify(b)) return [];
29
+ if (JSON.stringify(a) === JSON.stringify(b)) {
30
+ return [];
31
+ }
28
32
  if (
29
33
  a &&
30
34
  b &&
@@ -42,17 +46,27 @@ const diffPaths = (a: any, b: any, path = ""): string[] => {
42
46
  const normalizeCi = (ci: any, repo: Repo): any => {
43
47
  const c = structuredClone(ci);
44
48
  const extra = repo.config.ci ?? {};
45
- for (const k of extra.env ?? []) delete c.env?.[k];
46
- if (c.env && Object.keys(c.env).length === 0) delete c.env;
47
- for (const j of extra.jobs ?? []) delete c.jobs?.[j];
49
+ for (const k of extra.env ?? []) {
50
+ delete c.env?.[k];
51
+ }
52
+ if (c.env && Object.keys(c.env).length === 0) {
53
+ delete c.env;
54
+ }
55
+ for (const j of extra.jobs ?? []) {
56
+ delete c.jobs?.[j];
57
+ }
48
58
  const changes = c.jobs?.changes;
49
- for (const k of extra.filters ?? []) delete changes?.outputs?.[k];
59
+ for (const k of extra.filters ?? []) {
60
+ delete changes?.outputs?.[k];
61
+ }
50
62
  const step = changes?.steps?.find(
51
63
  (s: any) => typeof s.uses === "string" && s.uses.startsWith("dorny/paths-filter"),
52
64
  );
53
65
  if (step?.with?.filters) {
54
66
  const filters: any = Bun.YAML.parse(step.with.filters);
55
- for (const k of extra.filters ?? []) delete filters[k];
67
+ for (const k of extra.filters ?? []) {
68
+ delete filters[k];
69
+ }
56
70
  if (Array.isArray(filters.code)) {
57
71
  const added = new Set((extra.ignoreAdd ?? []).map((p) => `!${p}`));
58
72
  const code = filters.code.filter((p: string) => !added.has(p));
@@ -77,7 +91,9 @@ const takeCode = (ci: any): string[] => {
77
91
  s.uses?.startsWith?.("dorny/paths-filter"),
78
92
  );
79
93
  const code = step?.with?.filters?.code;
80
- if (!Array.isArray(code)) return [];
94
+ if (!Array.isArray(code)) {
95
+ return [];
96
+ }
81
97
  delete step.with.filters.code;
82
98
  return code;
83
99
  };
@@ -98,18 +114,20 @@ export const workflowRules = (repo: Repo): Finding[] => {
98
114
  const files = existsSync(dir) ? readdirSync(dir).filter((n) => /\.ya?ml$/.test(n)) : [];
99
115
  const visibility = repo.config.visibility ?? "public";
100
116
 
101
- if (visibility === "public" && !files.includes("ci.yml"))
117
+ if (visibility === "public" && !files.includes("ci.yml")) {
102
118
  f(
103
119
  "workflows/ci-reference",
104
120
  ".github/workflows/ci.yml",
105
121
  "public repos gate on `ci.yml`; it is missing",
106
122
  );
107
- if (visibility === "private" && files.includes("ci.yml"))
123
+ }
124
+ if (visibility === "private" && files.includes("ci.yml")) {
108
125
  f(
109
126
  "workflows/ci-reference",
110
127
  ".github/workflows/ci.yml",
111
128
  "private repos gate on Workers Builds, not `ci.yml`",
112
129
  );
130
+ }
113
131
 
114
132
  const depPath = join(repo.root, ".github", "dependabot.yml");
115
133
  const dep: any = existsSync(depPath) ? Bun.YAML.parse(readFileSync(depPath, "utf8")) : undefined;
@@ -128,7 +146,9 @@ export const workflowRules = (repo: Repo): Finding[] => {
128
146
  const refPins = new Map<string, string>();
129
147
  for (const line of readFileSync(REFERENCE, "utf8").split("\n")) {
130
148
  const m = PINNED.exec(line);
131
- if (m) refPins.set(m[1]!, m[2]!);
149
+ if (m) {
150
+ refPins.set(m[1]!, m[2]!);
151
+ }
132
152
  }
133
153
 
134
154
  for (const name of files) {
@@ -139,28 +159,35 @@ export const workflowRules = (repo: Repo): Finding[] => {
139
159
  // Pins are read from the text: the version comment is not in the parsed YAML.
140
160
  text.split("\n").forEach((line, i) => {
141
161
  const u = USES.exec(line);
142
- if (!u || u[1]!.startsWith("./")) return;
162
+ if (!u || u[1]!.startsWith("./")) {
163
+ return;
164
+ }
143
165
  const p = PINNED.exec(line);
144
- if (!p)
166
+ if (!p) {
145
167
  f(
146
168
  "workflows/actions-pinned",
147
169
  `${where}:${i + 1}`,
148
170
  `\`${u[1]}\` is not pinned to a commit SHA with a \`# v…\` comment`,
149
171
  );
150
- else if (refPins.has(p[1]!) && refPins.get(p[1]!) !== p[2])
172
+ } else if (refPins.has(p[1]!) && refPins.get(p[1]!) !== p[2]) {
151
173
  f(
152
174
  "workflows/reference-pins",
153
175
  `${where}:${i + 1}`,
154
176
  `\`${p[1]}\` is at ${p[2]!.slice(0, 7)}, the reference at ${refPins.get(p[1]!)!.slice(0, 7)}`,
155
177
  );
178
+ }
156
179
  });
157
180
 
158
- if (wf.permissions === undefined) f("workflows/hygiene", where, "no top-level `permissions`");
159
- if (wf.concurrency === undefined && wf.on?.workflow_call === undefined)
181
+ if (wf.permissions === undefined) {
182
+ f("workflows/hygiene", where, "no top-level `permissions`");
183
+ }
184
+ if (wf.concurrency === undefined && wf.on?.workflow_call === undefined) {
160
185
  f("workflows/hygiene", where, "no `concurrency` group");
186
+ }
161
187
  for (const [job, j] of Object.entries<any>(wf.jobs ?? {})) {
162
- if (j.uses === undefined && j["timeout-minutes"] === undefined)
188
+ if (j.uses === undefined && j["timeout-minutes"] === undefined) {
163
189
  f("workflows/hygiene", where, `job \`${job}\` has no \`timeout-minutes\``);
190
+ }
164
191
  for (const s of j.steps ?? []) {
165
192
  if (
166
193
  typeof s.uses === "string" &&
@@ -178,20 +205,21 @@ export const workflowRules = (repo: Repo): Finding[] => {
178
205
  for (const { job, line } of runLines(wf)) {
179
206
  for (const cmd of parseScript(line)) {
180
207
  const [bin, sub] = cmd.argv;
181
- if (bin === "bunx" || (bin === "bun" && sub === "x"))
208
+ if (bin === "bunx" || (bin === "bun" && sub === "x")) {
182
209
  f("workflows/scripts-only", where, `job \`${job}\`: \`${cmd.raw}\`; call a script`);
183
- else if (bin === "bun" && sub === "install" && !cmd.argv.includes("--frozen-lockfile"))
210
+ } else if (bin === "bun" && sub === "install" && !cmd.argv.includes("--frozen-lockfile")) {
184
211
  f(
185
212
  "workflows/scripts-only",
186
213
  where,
187
214
  `job \`${job}\`: \`${cmd.raw}\` without \`--frozen-lockfile\``,
188
215
  );
189
- else if (bin === "bun" && sub !== "install" && !asBunRun(cmd))
216
+ } else if (bin === "bun" && sub !== "install" && !asBunRun(cmd)) {
190
217
  f(
191
218
  "workflows/scripts-only",
192
219
  where,
193
220
  `job \`${job}\`: \`${cmd.raw}\` is inline; make it a script`,
194
221
  );
222
+ }
195
223
  if (
196
224
  bin === "bun" &&
197
225
  (sub === "install" || sub === "i") &&
@@ -211,23 +239,29 @@ export const workflowRules = (repo: Repo): Finding[] => {
211
239
  const want = stripRef(structuredClone(ref));
212
240
  const gotCode = new Set(takeCode(got));
213
241
  const wantCode = takeCode(want);
214
- for (const p of wantCode.filter((x) => !gotCode.has(x)))
242
+ for (const p of wantCode.filter((x) => !gotCode.has(x))) {
215
243
  f(
216
244
  "workflows/ci-reference",
217
245
  where,
218
246
  `the \`code\` filter lacks "${p}"; declare it in \`ci.ignoreRemove\` if intended`,
219
247
  );
220
- for (const p of [...gotCode].filter((x) => !wantCode.includes(x)))
248
+ }
249
+ for (const p of [...gotCode].filter((x) => !wantCode.includes(x))) {
221
250
  f(
222
251
  "workflows/ci-reference",
223
252
  where,
224
253
  `the \`code\` filter has "${p}"; declare it in \`ci.ignoreAdd\` if intended`,
225
254
  );
226
- for (const d of diffPaths(want, got)) f("workflows/ci-reference", where, d);
255
+ }
256
+ for (const d of diffPaths(want, got)) {
257
+ f("workflows/ci-reference", where, d);
258
+ }
227
259
  }
228
260
 
229
261
  const tags = wf.on?.push?.tags;
230
- if (tags !== undefined) out.push(...releaseRules(repo, where, wf));
262
+ if (tags !== undefined) {
263
+ out.push(...releaseRules(repo, where, wf));
264
+ }
231
265
  }
232
266
  return out;
233
267
  };
@@ -238,25 +272,28 @@ const releaseRules = (repo: Repo, where: string, wf: any): Finding[] => {
238
272
  const runs = lines.flatMap(({ job, line }) =>
239
273
  parseScript(line).map((cmd) => ({ job, cmd, run: asBunRun(cmd) })),
240
274
  );
241
- if (!runs.some((r) => r.run?.script === "check"))
275
+ if (!runs.some((r) => r.run?.script === "check")) {
242
276
  out.push({
243
277
  rule: "workflows/release-check",
244
278
  where,
245
279
  message: "no job runs `bun run check` before releasing",
246
280
  });
247
- if (!lines.some(({ line }) => line.includes("GITHUB_REF_NAME#v")))
281
+ }
282
+ if (!lines.some(({ line }) => line.includes("GITHUB_REF_NAME#v"))) {
248
283
  out.push({
249
284
  rule: "workflows/release-version",
250
285
  where,
251
286
  message: "no step checks the tag against the package version",
252
287
  });
288
+ }
253
289
  const builds = runs.filter((r) => r.run?.script.startsWith("build:"));
254
- if (builds.length === 0)
290
+ if (builds.length === 0) {
255
291
  out.push({
256
292
  rule: "workflows/release-build",
257
293
  where,
258
294
  message: "no step calls a `build:<target>` script",
259
295
  });
296
+ }
260
297
  for (const b of builds) {
261
298
  const pkg = repo.pkgAt(b.run!.cwd ?? ".");
262
299
  const job = wf.jobs[b.job];
@@ -267,12 +304,13 @@ const releaseRules = (repo: Repo, where: string, wf: any): Finding[] => {
267
304
  ? targets.map((t) => b.run!.script.replace("${{ matrix.target }}", t))
268
305
  : [b.run!.script];
269
306
  for (const n of names) {
270
- if (pkg?.scripts[n] === undefined)
307
+ if (pkg?.scripts[n] === undefined) {
271
308
  out.push({
272
309
  rule: "workflows/release-build",
273
310
  where,
274
311
  message: `calls \`${n}\`, which ${pkg?.dir ?? b.run!.cwd} does not define`,
275
312
  });
313
+ }
276
314
  }
277
315
  }
278
316
  return out;
package/README.md DELETED
@@ -1,198 +0,0 @@
1
- # @jfalava/ts-standard
2
-
3
- Checks a Bun repo against the TypeScript scripts and workflows standard: the `package.json` scripts of the root and every workspace, version pins, `bunfig.toml`, the tsconfig files and the GitHub workflows. It reads files and changes nothing.
4
-
5
- It is a standalone checker, not an oxlint plugin, because oxlint only lints JavaScript and TypeScript: given a `package.json`, a `tsconfig.json` or a workflow, oxlint 1.95.0 reports `No files found to lint`, and its plugin API has no hook for other file types.
6
-
7
- ## Wiring it into a repo
8
-
9
- 1. Add it, with an exact version as the standard requires:
10
-
11
- ```sh
12
- bun add --dev --exact @jfalava/ts-standard
13
- ```
14
-
15
- In a workspace repo, put it in the root `catalogs` and reference it as `catalog:`.
16
-
17
- 2. Exclude the scope from the release-age wait in `bunfig.toml`, or every new version waits a day before it installs. The `pins/bunfig` rule requires this entry:
18
-
19
- ```toml
20
- [install]
21
- minimumReleaseAge = 86400
22
- minimumReleaseAgeExcludes = [
23
- "@jfalava/*",
24
- # …
25
- ]
26
- ```
27
-
28
- 3. Add the script and end the root `check` with it:
29
-
30
- ```json
31
- {
32
- "scripts": {
33
- "check": "bun run --workspaces check && bun run standard:check",
34
- "standard:check": "ts-standard"
35
- }
36
- }
37
- ```
38
-
39
- In a single-package repo, append `&& bun run standard:check` to `check` after `bun run test`.
40
-
41
- 4. If the repo differs from the standard anywhere, add a `standard.config.ts` at its root. Without one, every rule applies with the defaults.
42
-
43
- `ts-standard [dir] [--config <file>] [--json]` checks `dir` (default `.`) with `<dir>/standard.config.ts`. It exits 1 when an error is left, and 0 when only warnings are.
44
-
45
- ## `standard.config.ts`
46
-
47
- ```ts
48
- import { defineStandard } from "@jfalava/ts-standard";
49
-
50
- export default defineStandard({
51
- // "private" repos gate on Workers Builds and must not have a ci.yml. Default "public".
52
- visibility: "public",
53
- // Which column of the standard's script table a package follows. Unlisted packages are "oxc".
54
- toolchains: { docs: "astro" },
55
- // What this repo's ci.yml adds to the reference.
56
- ci: {
57
- ignoreAdd: ["docs/AGENT.md", "LICENSES/**"], // extra negations in the `code` filter, no "!"
58
- ignoreRemove: ["**/README.md"], // standard negations this repo counts as code
59
- filters: ["rust"], // filters beside `code` in the `changes` step
60
- jobs: ["advisories", "rust"], // jobs beside `changes` and `check`
61
- env: ["CARGO_TERM_COLOR"], // top-level env keys
62
- },
63
- exceptions: [
64
- {
65
- rule: "scripts/check-runs-own-checks",
66
- where: "docs", // package directory ("." for the root) or repo-relative file
67
- script: "licenses:check", // optional, for script rules
68
- why: "Needs cargo and the network, which Workers Builds lacks.",
69
- },
70
- ],
71
- });
72
- ```
73
-
74
- Toolchains set what `typecheck` must be: `effect-tsgo tsrs --noEmit` for `oxc` and `vite-plus`, `astro check` for `astro`, and `tsc --noEmit` for `pulumi`. `astro` and `pulumi` packages may also depend on `typescript`, and are not held to the tsconfig base rules.
75
-
76
- ### Exceptions
77
-
78
- An exception covers every finding with the same `rule` whose `where` and `script` match. Omitting `where` or `script` matches any. A `where` of a file also covers its line findings, such as `.github/workflows/ci.yml:33`. Each needs a `why`; keep it in step with the exceptions table in the repo's README.
79
-
80
- An exception that covers nothing is itself an error, `standard/stale-exception`, so the list shrinks when the repo catches up with the standard.
81
-
82
- ## Rules
83
-
84
- Every rule is an error except `workflows/reference-pins`, which is a warning: it prints and does not fail.
85
-
86
- A package is a workspace package in a workspace repo, or the root in a single-package repo.
87
-
88
- ### Scripts
89
-
90
- | Rule | Checks |
91
- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
92
- | `scripts/required` | Every package has `check`, `fix`, `lint`, `lint:fix`, `format`, `format:check` and `typecheck`. A workspace root also has `test`. |
93
- | `scripts/check-body` | A package's `check` is `bun run lint && bun run format:check && bun run typecheck && bun run test` (`test` only if it has one), followed only by `bun run <thing>:check`. |
94
- | `scripts/check-read-only` | Nothing reached from any `check`, following `bun run`, `--cwd` and `--workspaces`, writes files: no `--fix`, `--write`, bare `oxfmt` or `vp fmt`. |
95
- | `scripts/check-runs-own-checks` | Every `<thing>:check` script is reached from that package's `check`. |
96
- | `scripts/no-bare-bun-test` | Only `test` and `test:*` call `bun test`; aggregates call `bun run test`. |
97
- | `scripts/fix-body` | `fix` is `bun run lint:fix && bun run format`. |
98
- | `scripts/fix-pairs` | Every `lint*:fix` is its `lint*` with `--fix`, or calls the `:fix` variants. |
99
- | `scripts/format-pair` | `format:check` is `format` in check mode (`--check` in place of `--write`, or appended). |
100
- | `scripts/lint-type-aware` | Every `oxlint` reached from `lint` in an `oxc` or `astro` package passes `--type-aware --type-check`. |
101
- | `scripts/lint-body` | An Astro package's `lint` is `bun run lint:oxlint && bun run lint:astro && bun run lint:docs`. |
102
- | `scripts/typecheck` | `typecheck` is the toolchain's command. |
103
- | `scripts/test-runs-once` | `test` does not start watch mode: `vitest run`, not `vitest`. |
104
- | `scripts/root-fan-out` | Each root verb fans out with `bun run --workspaces`; `check` without `--if-present`, the others with it. Only a repo-wide prerequisite such as `bun run build:types` may run before the fan-out. Every package has a `check`. |
105
- | `scripts/no-global-suffix` | No script name ends in `:global`. |
106
- | `scripts/no-root-shortcuts` | No root script is only `bun run --cwd <pkg> <script>`, except `dev` and the deploy scripts. |
107
- | `scripts/no-filter` | No `bun run --filter`: it does not pass stdin. |
108
- | `scripts/no-bunx` | No `bunx` or `bun x`. |
109
- | `scripts/no-hooks` | No `pre<script>` hooks beside `prepare`. |
110
- | `scripts/ci-build` | The root `ci:build` is `bun run check` or `bun run check && bun run build`, it exists when `ci:deploy` does, and no package has one. |
111
-
112
- ### Deploy
113
-
114
- These apply to `plan`, `deploy`, `ci:deploy` and `destroy` commands that run `alchemy` or `pulumi`.
115
-
116
- | Rule | Checks |
117
- | ------------------------ | ------------------------------------------------------------------------------------------- |
118
- | `deploy/explicit-target` | The command names its target: `--stage`, `--stack` or a variable assignment in front of it. |
119
- | `deploy/same-target` | All four scripts in a package name the same target. |
120
- | `deploy/interactive` | `ci:deploy` passes `--yes`; `deploy` and `destroy` do not. |
121
- | `deploy/plan` | `plan` is `alchemy plan`, and exists when `deploy` does. |
122
- | `deploy/no-checks` | `deploy` and `ci:deploy` run none of the check verbs and rewrite no files. |
123
-
124
- ### Pins
125
-
126
- | Rule | Checks |
127
- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
128
- | `pins/package-manager` | The root `packageManager` is `bun@<exact>`. |
129
- | `pins/exact` | Every catalog entry and dependency is an exact version (`npm:` aliases and SHA-pinned git URLs included), and every `catalog:` reference resolves. |
130
- | `pins/use-catalog` | In a workspace repo, a dependency that a root catalog lists uses `catalog:`. |
131
- | `pins/toolchain-deps` | The root has `@effect/tsgo`, `@oxlint/plugins`, `oxfmt`, `oxlint` and `tsrs`; nothing has `oxlint-tsgolint`; only Astro and Pulumi packages have `typescript`. |
132
- | `pins/bun-types` | `bun-types` or `@types/bun` is the `packageManager` version. |
133
- | `pins/prepare` | The root `prepare` is `effect-tsgo patch --no-typescript --tsrs --oxlint`. |
134
- | `pins/bunfig` | `bunfig.toml` exists, sets `minimumReleaseAge` to at least 86400, and excludes `@effect/tsgo`, its seven platform packages and `@jfalava/*`. |
135
-
136
- ### tsconfig
137
-
138
- The base is `tsconfig.base.json` in a workspace repo and `tsconfig.json` otherwise.
139
-
140
- | Rule | Checks |
141
- | ------------------------------------ | ------------------------------------------------------------------------------------------------------ |
142
- | `tsconfig/base` | The base exists and its `$schema` is `./node_modules/@effect/tsgo/schema.json`. |
143
- | `tsconfig/effect-plugin` | The base has the `@effect/language-service` plugin entry, and no package tsconfig overrides `plugins`. |
144
- | `tsconfig/no-emit` | The base sets `noEmit: true`. |
145
- | `tsconfig/strict-in-base` | The base sets `strict` and `noUncheckedIndexedAccess`; package tsconfigs set no strict flags. |
146
- | `tsconfig/extends-base` | Each `oxc` or `vite-plus` package has a `tsconfig.json` that extends the base. |
147
- | `tsconfig/one-per-package` | No `tsconfig.*.json` beside a package's `tsconfig.json`. |
148
- | `tsconfig/no-ignore-effect-warnings` | No tsconfig sets `ignoreEffectWarningsInTscExitCode: true`. |
149
-
150
- ### Workflows
151
-
152
- | Rule | Checks |
153
- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
154
- | `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. |
155
- | `workflows/actions-pinned` | Every `uses:` outside the repo is pinned to a 40-character SHA with a `# v…` comment. |
156
- | `workflows/reference-pins` | Warning. An action the reference also uses is at the reference's SHA. |
157
- | `workflows/dependabot` | `.github/dependabot.yml` has a `github-actions` entry. |
158
- | `workflows/hygiene` | Every workflow has top-level `permissions` and a `concurrency` group (reusable workflows excepted), and every job that runs steps has `timeout-minutes`. |
159
- | `workflows/bun-from-package-manager` | No `setup-bun` step sets `bun-version`. |
160
- | `workflows/scripts-only` | `run:` steps call bun only as `bun install --frozen-lockfile` or `bun run <script>`, never `bunx`, and never `--ignore-scripts`. |
161
- | `workflows/release-check` | A tag-triggered workflow runs `bun run check`. |
162
- | `workflows/release-version` | A tag-triggered workflow checks the tag against the package version (`${GITHUB_REF_NAME#v}`). |
163
- | `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. |
164
-
165
- ## Developing
166
-
167
- `bun run check` is the gate; `bun run fix` rewrites. The tests in `test/check.test.ts` run the checker on copies of six repos' files (`test/fixtures/repos`, with the commits in `test/fixtures/README.md`) against reviewed results in `test/golden/`, and on three fixtures built to break specific rules. After a rule change, compare the new output with the golden by hand before updating it.
168
-
169
- `reference/ci.yml` is the shared `ci.yml`, copied from lazyotp. Update it here first; every repo's `workflows/ci-reference` then reports the difference until its copy matches.
170
-
171
- ## Releasing
172
-
173
- Bump `version` in `package.json`, commit, then tag and push `v<version>`. `.github/workflows/release.yml` checks that the tag matches, runs `bun run check`, and publishes to npm through trusted publishing, with a provenance attestation and no stored npm token.
174
-
175
- The first version cannot go through the workflow: npm attaches a trusted publisher only to a package that already exists. See the setup below.
176
-
177
- ### npm setup (once)
178
-
179
- 1. On npmjs.com, enable two-factor authentication on the account that owns the `@jfalava` scope.
180
- 2. Create the package with one version from a logged-in npm CLI (npm 11.15.0 or later, Node 22.14.0 or later), from a clean checkout of the tagged commit:
181
-
182
- ```sh
183
- npm login
184
- npm publish --access public
185
- ```
186
-
187
- Or stage it instead, which creates the package without a live release: `npm stage publish`, then approve it with 2FA through `npm stage approve <stage-id>` or the **Staged Packages** tab. Until approval the package shows a public `0.0.0-stage` placeholder.
188
-
189
- 3. Open npmjs.com → Packages → `@jfalava/ts-standard` → Settings → Trusted publishing, choose **GitHub Actions**, and enter:
190
- - Organization or user: `jfalava`
191
- - Repository: `ts-standard`
192
- - Workflow filename: `release.yml`
193
- - Environment name: empty
194
- - Allowed actions: **Allow npm publish** (new configurations allow only `npm stage publish` by default, and the workflow runs `npm publish`)
195
- 4. Push the next `v<version>` tag within 2 days. A new trusted publisher that has not published successfully within 2 days expires and must be deleted and recreated. The tag of the version published by hand can be pushed at any time: its release run finds that version on npm and skips the publish.
196
- 5. Once that release has published, set Settings → Publishing access to **Require two-factor authentication and disallow tokens**, and revoke any npm token used in step 2.
197
-
198
- npm does not check these values when they are saved. A mismatch, such as a different workflow filename, fails only at publish time, often as a 404. `repository.url` in `package.json` must stay `git+https://github.com/jfalava/ts-standard.git`.