@ref0/workspace 0.7.0 → 0.9.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/README.md CHANGED
@@ -24,6 +24,8 @@ export const lint = merge(base.lint, {
24
24
 
25
25
  - `base.fmt` and `base.lint`: the shared format and lint settings. `REF0_LINT_TYPES=none` turns off
26
26
  the type-aware rules, for a local check that runs them only on changed files.
27
+ - `base.staged`: what `vp staged` runs before each commit, `vp check --fix` on the staged files,
28
+ which a repo's `vite.config.ts` takes as `staged: base.staged` for its `pre-commit` hook.
27
29
  - `merge(base, local)`: base first, local last. Ignores, plugins and overrides are joined, rules
28
30
  and options merged, so a local rule wins; any other setting is local's.
29
31
  - `@ref0/workspace/lint/plugins`: each plugin's file, as an absolute path for `jsPlugins`.
@@ -94,6 +96,9 @@ entry point's source:
94
96
  published changed." The section it prints holds at most `--most-bytes`, 50,000 unless given, for
95
97
  a release's pull request to carry: a longer one leaves out its oldest listed changes and ends with
96
98
  a line linking the changelog, and the section `--prepend` writes is always whole.
99
+ - `pre-commit`: Git's pre-commit hook, which a repo runs from `.vite-hooks/pre-commit`. It runs
100
+ the repo's `vp staged`, which reads `staged` from its `vite.config.ts`: `vp check --fix` on the
101
+ staged files only, whose fixes it stages again. A problem `--fix` can't fix refuses the commit.
97
102
  - `pre-push <remote> <url>`: Git's pre-push hook, which a repo runs from `.vite-hooks/pre-push`
98
103
  with the ref lines Git writes on stdin. It refuses a push that deletes `main`, a `deploy/*` or a
99
104
  `release/*` branch, or moves one to a commit that doesn't descend from where it is, and names each
@@ -101,8 +106,27 @@ entry point's source:
101
106
  `<repo>` is the remote's repo name, the last part of its URL without `.git`, lets a refused push
102
107
  through, so a rewrite meant for one repo opens no other.
103
108
 
104
- `pre-push` stops accidents and isn't a boundary: `git push --no-verify` skips it, as it does every
105
- hook, and so do `VP_GIT_HOOKS=0` and `HUSKY=0`, which turn off every Vite+ hook, and a checkout
109
+ Then a push that sends a commit runs the checks the root `package.json` names, each a script, run
110
+ through `vp run --cache` so one whose inputs haven't changed since it passed replays:
111
+
112
+ ```json
113
+ "ref0-workspace": {
114
+ "prePush": {
115
+ "always": ["check", "check:types"],
116
+ "packages": { "paths": ["packages/"], "run": ["test:lint"] }
117
+ }
118
+ }
119
+ ```
120
+
121
+ `always` runs on every such push, and `packages.run` too when a pushed commit no remote-tracking
122
+ branch holds changes a path `packages.paths` names, as Git's pathspecs. A key it doesn't know, or
123
+ a script `package.json` doesn't have, refuses the push and names it. The first check that fails
124
+ refuses the push, and the hook prints each check's time. It waits first, up to 10 minutes, for
125
+ the machine's 1-minute load to drop under 18, and refuses the push when it hasn't.
126
+ `REF0_SKIP_PUSH_CHECKS=1` skips the checks, and says which, but not the refusals above.
127
+
128
+ `pre-commit` and `pre-push` stop accidents and aren't a boundary: `git commit --no-verify` and
129
+ `git push --no-verify` skip them, as they do every hook, and so do `VP_GIT_HOOKS=0` and `HUSKY=0`, which turn off every Vite+ hook, and a checkout
106
130
  that never installed the repo's hooks. A job that force-pushes a
107
131
  `release/*` branch, as a release workflow's `release/next` does, doesn't install the hooks or sets
108
132
  `VP_GIT_HOOKS=0`, and a repo's adoption checks each of its workflows for one.
package/dist/bin.mjs CHANGED
@@ -3,6 +3,7 @@ import { changelog } from "./changelog.mjs";
3
3
  import { commitMessage } from "./commit-message.mjs";
4
4
  import { docsBudget } from "./docs-budget.mjs";
5
5
  import { defaultCondition, packageExports } from "./package-exports.mjs";
6
+ import { preCommit } from "./pre-commit.mjs";
6
7
  import { prePush } from "./pre-push.mjs";
7
8
  import { symbolsCheck } from "./symbols/check.mjs";
8
9
  import { symbolsFind } from "./symbols/find.mjs";
@@ -30,8 +31,10 @@ import { parseArgs } from "node:util";
30
31
  * ref0-workspace changelog --repo <owner/name> [--path <pathspec>]... [--version <version>
31
32
  * [--date <yyyy-mm-dd>]] [--prepend <file>] [--most-bytes <n>] <range>
32
33
  * a release's notes, from main's subjects
34
+ * ref0-workspace pre-commit Git's pre-commit hook: `vp staged`
33
35
  * ref0-workspace pre-push <remote> <url> Git's pre-push hook: no force-push or delete
34
- * of main, deploy/* or release/*
36
+ * of main, deploy/* or release/*, then the
37
+ * repo's checks
35
38
  */
36
39
  /** The root of the Git checkout the command runs in, or where it runs outside one. */
37
40
  const root = () => {
@@ -111,6 +114,7 @@ const checks = /* @__PURE__ */ new Map([
111
114
  return packageExports(root(), parsed);
112
115
  }
113
116
  }],
117
+ ["pre-commit", plain("Git's pre-commit hook: vp check --fix on the staged files", preCommit)],
114
118
  ["commit-message", {
115
119
  args: "<message-file> | --title <title>",
116
120
  about: "a commit's subject, or a pull request's title, is type(scope): subject",
@@ -123,10 +127,10 @@ const checks = /* @__PURE__ */ new Map([
123
127
  }],
124
128
  ["pre-push", {
125
129
  args: "<remote> <url>",
126
- about: "Git's pre-push hook: refuses a force-push or delete of main, deploy/* or release/*",
130
+ about: "Git's pre-push hook: refuses a force-push or delete of main, deploy/* or release/*, then runs the checks the root package.json names",
127
131
  run: ([remote, url, ...extra]) => {
128
132
  if (remote === void 0 || url === void 0 || extra.length > 0) return usageError();
129
- return prePush(cwd(), url, readFileSync(0, "utf8"), env.REF0_REWRITE);
133
+ return prePush(root(), url, readFileSync(0, "utf8"), env);
130
134
  }
131
135
  }]
132
136
  ]);
@@ -1,4 +1,4 @@
1
- import { commitTypes } from "./commit-message.mjs";
1
+ import { commitTypes } from "./subject.mjs";
2
2
  import { execFileSync, spawnSync } from "node:child_process";
3
3
  import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { execPath, stdout } from "node:process";
@@ -1,3 +1,4 @@
1
+ import { commitTypes, isScopeName, subjectProblem } from "./subject.mjs";
1
2
  import { readFileSync } from "node:fs";
2
3
  import { join } from "node:path";
3
4
  import { Option, Schema } from "effect";
@@ -13,66 +14,13 @@ import { Option, Schema } from "effect";
13
14
  * says. Each repo names its own scopes in its root `package.json`, under `ref0-workspace`, as
14
15
  * `{ "commitScopes": ["git", "cli"] }`, and its `.agents/repo/commits.md` says what each names.
15
16
  *
16
- * A commit may also carry one of git's own subjects: a merge's, `Merge branch …`,
17
- * `Merge remote-tracking branch …`, `Merge commit '…'` or `Merge tag '…'`, or the plural git writes
18
- * for an octopus merge, such as `Merge branches 'a' and 'b'`, an autosquash's,
19
- * `fixup! …`, `squash! …` or `amend! …`, and a revert's, `Revert "…"` or `Reapply "…"`, which
20
- * `git revert` writes without running `commit-msg`. A title may not, since it becomes main's
21
- * subject.
17
+ * The rule for one line is `subject.ts`'s, which needs nothing installed. A commit may also carry
18
+ * one of git's own subjects: a merge's, `Merge branch …`, `Merge remote-tracking branch …`,
19
+ * `Merge commit '…'` or `Merge tag '…'`, or the plural git writes for an octopus merge, such as
20
+ * `Merge branches 'a' and 'b'`, an autosquash's, `fixup! …`, `squash! …` or `amend! …`, and a
21
+ * revert's, `Revert "…"` or `Reapply "…"`, which `git revert` writes without running `commit-msg`.
22
+ * A title may not, since it becomes main's subject.
22
23
  */
23
- /** The kinds of change, in the order the release notes list them. */
24
- const commitTypes = [
25
- "feat",
26
- "fix",
27
- "perf",
28
- "refactor",
29
- "test",
30
- "docs",
31
- "build",
32
- "ci",
33
- "chore",
34
- "revert"
35
- ];
36
- /**
37
- * git's own subjects, which a commit may carry and a title may not: a merge's, as `fmt-merge-msg`
38
- * writes it for one or several of a kind, an autosquash's and a revert's.
39
- */
40
- const gitsOwn = /^(?:Merge (?:branch(?:es)? |remote-tracking branch(?:es)? |commits? '|tags? ')|(?:fixup|squash|amend)! |(?:Revert|Reapply) ")/u;
41
- /** `type`, then `(scope)` or nothing, then `!` or nothing, then `: ` and the words. */
42
- const subjectLine = /^([^\s(!:]+)(?:\(([^()]*)\))?!?: (\S(?:.*\S)?)$/u;
43
- /** A scope's name, as a repo may give it: lower case words joined by `-`. */
44
- const scopeName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
45
- const read = (line, scopes) => {
46
- const match = subjectLine.exec(line);
47
- if (match === null) return {
48
- valid: false,
49
- problem: `"${line}" isn't "type(scope): subject", or "type: subject" for a change across the repo`
50
- };
51
- const [, word = "", named, text = ""] = match;
52
- const type = commitTypes.find((each) => each === word);
53
- if (type === void 0) return {
54
- valid: false,
55
- problem: `"${word}" isn't a type: use one of ${commitTypes.join(", ")}`
56
- };
57
- if (named !== void 0 && !scopes.includes(named)) return {
58
- valid: false,
59
- problem: `"${named}" isn't a scope: ${scopes.length === 0 ? "this repo names none, so leave it off" : `use one of ${scopes.join(", ")}, or none`}`
60
- };
61
- return {
62
- valid: true,
63
- subject: {
64
- type,
65
- scope: named,
66
- text
67
- }
68
- };
69
- };
70
- /** What's wrong with `line` as a commit's subject or a pull request's title, or undefined. */
71
- const subjectProblem = (line, checked, scopes) => {
72
- if (checked === "commit" && gitsOwn.test(line)) return void 0;
73
- const subject = read(line, scopes);
74
- return subject.valid ? void 0 : subject.problem;
75
- };
76
24
  /**
77
25
  * A comment as git's editor and a commit template write one: `#` alone, or `#` and a space. `-m`
78
26
  * keeps every line, so a line such as `#123: a fix` is a subject, never a comment. In the editor,
@@ -113,7 +61,7 @@ const commitScopes = (root) => {
113
61
  const manifest = decodeManifest(text);
114
62
  if (Option.isNone(manifest)) return { problem: `${where} isn't a list of words: name the repo's scopes, or [] for none` };
115
63
  const scopes = manifest.value["ref0-workspace"].commitScopes;
116
- const wrong = scopes.find((scope) => !scopeName.test(scope));
64
+ const wrong = scopes.find((scope) => !isScopeName(scope));
117
65
  if (wrong !== void 0) return { problem: `${where} holds ${JSON.stringify(wrong)}: a scope is lower case words joined by -` };
118
66
  return { scopes };
119
67
  };
@@ -135,4 +83,4 @@ const commitMessage = (args, root) => {
135
83
  console.error(`${title ? "The pull request's title" : "The commit's subject"}: ${problem}. .agents/repo/commits.md says how.`);
136
84
  return 1;
137
85
  };
138
- export { commitMessage, commitScopes, commitTypes, messageProblem, messageSubject, subjectProblem };
86
+ export { commitMessage, commitScopes, commitTypes, messageProblem, messageSubject };
@@ -1,14 +1,17 @@
1
1
  import { ViteUserConfig } from "vite-plus";
2
2
  type Format = NonNullable<ViteUserConfig['fmt']>;
3
3
  type Lint = NonNullable<ViteUserConfig['lint']>;
4
- /** A repo's format and lint settings, as Vite+'s config takes them. */
4
+ type Staged = NonNullable<ViteUserConfig['staged']>;
5
+ /** A repo's format, lint and staged-file settings, as Vite+'s config takes them. */
5
6
  export interface Settings {
6
7
  readonly fmt: Format;
7
8
  readonly lint: Lint;
9
+ readonly staged: Staged;
8
10
  }
9
11
  /**
10
- * The format and lint settings every ref-0 repo shares. A repo's `lint/config.ts` merges its own
11
- * over them with `merge`, and registers the shared plugins beside its own.
12
+ * The format, lint and staged-file settings every ref-0 repo shares. A repo's `lint/config.ts`
13
+ * merges its own over them with `merge`, and registers the shared plugins beside its own, and its
14
+ * `vite.config.ts` takes `staged` as it is.
12
15
  */
13
16
  export declare const base: Settings;
14
17
  /**
@@ -22,8 +22,9 @@ const unsafeAnyRules = [
22
22
  ];
23
23
  const typeAware = process.env["REF0_LINT_TYPES"] !== "none";
24
24
  /**
25
- * The format and lint settings every ref-0 repo shares. A repo's `lint/config.ts` merges its own
26
- * over them with `merge`, and registers the shared plugins beside its own.
25
+ * The format, lint and staged-file settings every ref-0 repo shares. A repo's `lint/config.ts`
26
+ * merges its own over them with `merge`, and registers the shared plugins beside its own, and its
27
+ * `vite.config.ts` takes `staged` as it is.
27
28
  */
28
29
  const base = {
29
30
  fmt: {
@@ -101,7 +102,8 @@ const base = {
101
102
  }
102
103
  }
103
104
  ]
104
- }
105
+ },
106
+ staged: { "*": "vp check --fix" }
105
107
  };
106
108
  /** Two lists, the shared one first, or nothing when neither config sets it. */
107
109
  const lists = (shared, own) => shared == null && own == null ? void 0 : [...shared ?? [], ...own ?? []];
@@ -0,0 +1,23 @@
1
+ import { vitePlusAt } from "./types/projects.mjs";
2
+ import { spawnSync } from "node:child_process";
3
+ import { execPath } from "node:process";
4
+ // src/pre-commit.ts
5
+ /**
6
+ * Checks what a commit stages, run as Git's pre-commit hook:
7
+ *
8
+ * ref0-workspace pre-commit
9
+ *
10
+ * It runs the repo's own `vp staged`, which reads the `staged` block of its `vite.config.ts`, the
11
+ * shared `base.staged` from `./lint/config`: `vp check --fix` on the staged files only, whatever
12
+ * the repo's size. lint-staged, which `vp staged` bundles, stages each fix again, so the commit
13
+ * holds the fixed file, and hides the unstaged part of a partly staged file while it runs. A
14
+ * problem `--fix` can't fix refuses the commit, and so does a repo with no `staged` block.
15
+ *
16
+ * `git commit --no-verify` skips it, as it skips every commit hook.
17
+ */
18
+ /** Runs `vp staged` in the checkout at `root`, and answers the hook's exit code. */
19
+ const preCommit = (root) => spawnSync(execPath, [vitePlusAt(root), "staged"], {
20
+ cwd: root,
21
+ stdio: "inherit"
22
+ }).status ?? 1;
23
+ export { preCommit };
package/dist/pre-push.mjs CHANGED
@@ -1,21 +1,14 @@
1
+ import { vitePlusAt } from "./types/projects.mjs";
1
2
  import { spawnSync } from "node:child_process";
2
- // src/pre-push.ts
3
- /**
4
- * Refuses a push that deletes, or moves to a commit that doesn't descend from where it is, `main`,
5
- * a `deploy/` branch or a `release/` branch, run as Git's pre-push hook:
6
- *
7
- * ref0-workspace pre-push <remote> <url> the ref lines on stdin, as Git writes them
8
- *
9
- * Git writes a line for each ref the push updates, `<local ref> <local sha> <remote ref> <remote
10
- * sha>`. A local sha of zeros deletes the remote ref, and a remote sha of zeros creates it, which
11
- * moves nothing back, so it passes. Any other update of a guarded ref passes only when `git
12
- * merge-base --is-ancestor` finds the remote sha in the local sha's history, which it can't when the
13
- * checkout hasn't fetched it.
14
- *
15
- * `REF0_REWRITE=<repo>` lets the push through when `<repo>` is the remote's repo name, the last part
16
- * of its URL without `.git`, so a rewrite meant for one repo opens no other. `git push --no-verify`
17
- * skips every hook, this one too: it stops accidents, and isn't a boundary.
18
- */
3
+ import { readFileSync } from "node:fs";
4
+ import { execPath } from "node:process";
5
+ import { loadavg } from "node:os";
6
+ import { join } from "node:path";
7
+ import { Result, Schema } from "effect";
8
+ /** How long the checks wait for the load to drop, in milliseconds, before refusing the push. */
9
+ const loadWait = 6e5;
10
+ /** How often the wait reads the load again, in milliseconds. */
11
+ const loadPoll = 15e3;
19
12
  /** The branches a push may only move forward. */
20
13
  const isGuarded = (ref) => ref === "refs/heads/main" || /^refs\/heads\/(?:deploy|release)\/./s.test(ref);
21
14
  /**
@@ -55,11 +48,154 @@ const refusal = (at, { local, ref, remote }) => {
55
48
  if (isZero(remote) || isAncestor(at, remote, local)) return void 0;
56
49
  return `moves ${ref} from ${remote.slice(0, 12)} to ${local.slice(0, 12)}, not a descendant`;
57
50
  };
51
+ /** The checks a repo names, under its root `package.json`'s `"ref0-workspace"."prePush"`. */
52
+ const Checks = Schema.Struct({
53
+ always: Schema.Array(Schema.String),
54
+ packages: Schema.optionalKey(Schema.Struct({
55
+ paths: Schema.Array(Schema.String),
56
+ run: Schema.Array(Schema.String)
57
+ }))
58
+ });
59
+ /** The root `package.json`, as far as the checks read it. */
60
+ const Manifest = Schema.Struct({
61
+ scripts: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
62
+ "ref0-workspace": Schema.optionalKey(Schema.Unknown)
63
+ });
64
+ /** The repo's `"ref0-workspace"`, every key it may hold, so a misspelt one is named. */
65
+ const Settings = Schema.Struct({
66
+ commitScopes: Schema.optionalKey(Schema.Unknown),
67
+ prePush: Schema.optionalKey(Checks)
68
+ });
69
+ const decodeManifest = Schema.decodeUnknownResult(Schema.fromJsonString(Manifest));
70
+ const decodeSettings = Schema.decodeUnknownResult(Settings, { onExcessProperty: "error" });
71
+ /**
72
+ * The checks the repo at `root` names, none when it names none, or what's wrong with how it names
73
+ * them.
74
+ */
75
+ const checksAt = (root) => {
76
+ const file = join(root, "package.json");
77
+ const text = (() => {
78
+ try {
79
+ return readFileSync(file, "utf8");
80
+ } catch {
81
+ return;
82
+ }
83
+ })();
84
+ if (text === void 0) return { checks: void 0 };
85
+ const manifest = decodeManifest(text);
86
+ if (Result.isFailure(manifest)) return { problem: `${file} isn't JSON a manifest holds` };
87
+ const settings = decodeSettings(manifest.success["ref0-workspace"] ?? {});
88
+ if (Result.isFailure(settings)) return { problem: `${file}'s "ref0-workspace": ${settings.failure.message}` };
89
+ const checks = settings.success.prePush;
90
+ if (checks === void 0) return { checks: void 0 };
91
+ const scripts = manifest.success.scripts ?? {};
92
+ const missing = [...checks.always, ...checks.packages?.run ?? []].filter((name) => !Object.hasOwn(scripts, name));
93
+ if (missing.length > 0) return { problem: `${file}'s "ref0-workspace"."prePush" names ${missing.join(", ")}, not a script it has` };
94
+ return { checks };
95
+ };
96
+ /** Whether a commit the updates push, held by no remote-tracking branch, changes `paths`. */
97
+ const changes = (at, updates, paths) => paths.length > 0 && updates.some(({ local, remote }) => {
98
+ const held = !isZero(remote) && spawnSync("git", [
99
+ "cat-file",
100
+ "-e",
101
+ `${remote}^{commit}`
102
+ ], {
103
+ cwd: at,
104
+ stdio: "ignore"
105
+ }).status === 0;
106
+ const { stdout } = spawnSync("git", [
107
+ "rev-list",
108
+ "-1",
109
+ local,
110
+ ...held ? [`^${remote}`] : [],
111
+ "--not",
112
+ "--remotes",
113
+ "--",
114
+ ...paths
115
+ ], {
116
+ cwd: at,
117
+ encoding: "utf8"
118
+ });
119
+ return stdout.trim() !== "";
120
+ });
121
+ const host = {
122
+ load: () => loadavg()[0] ?? 0,
123
+ sleep: (ms) => {
124
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
125
+ }
126
+ };
127
+ /** Whether the machine's load drops under `loadCeiling` within `loadWait`, saying when it waits. */
128
+ const loadDrops = (machine) => {
129
+ const load = machine.load();
130
+ if (load < 18) return true;
131
+ console.error(`ref0-workspace pre-push: the load is ${load.toFixed(1)}, so the checks wait up to ${loadWait / 6e4} min for it to drop under 18`);
132
+ const dropped = Array.from({ length: Math.ceil(loadWait / loadPoll) }).some(() => {
133
+ machine.sleep(loadPoll);
134
+ return machine.load() < 18;
135
+ });
136
+ if (!dropped) console.error(`ref0-workspace pre-push: refused, the load stayed at 18 or more for ${loadWait / 6e4} min. Push again later, or set REF0_SKIP_PUSH_CHECKS=1 to push without the checks.`);
137
+ return dropped;
138
+ };
139
+ /** Runs the script `name` through the task cache, and answers whether it passed and how long it took. */
140
+ const runScript = (root, name) => {
141
+ const started = performance.now();
142
+ const { status } = spawnSync(execPath, [
143
+ vitePlusAt(root),
144
+ "run",
145
+ "--cache",
146
+ name
147
+ ], {
148
+ cwd: root,
149
+ stdio: [
150
+ "ignore",
151
+ "inherit",
152
+ "inherit"
153
+ ]
154
+ });
155
+ return {
156
+ name,
157
+ status,
158
+ seconds: (performance.now() - started) / 1e3
159
+ };
160
+ };
161
+ /** Runs the checks the repo at `root` names for the updates, and answers the hook's exit code. */
162
+ const runChecks = (root, updates, skip, machine) => {
163
+ const sent = updates.filter(({ local }) => !isZero(local));
164
+ if (sent.length === 0) return 0;
165
+ const named = checksAt(root);
166
+ if ("problem" in named) {
167
+ console.error(`ref0-workspace pre-push: refused, ${named.problem}`);
168
+ return 1;
169
+ }
170
+ const { checks } = named;
171
+ if (checks === void 0) return 0;
172
+ const extra = checks.packages !== void 0 && changes(root, sent, checks.packages.paths) ? checks.packages.run : [];
173
+ const names = [...checks.always, ...extra];
174
+ if (skip === "1") {
175
+ console.error(`ref0-workspace pre-push: REF0_SKIP_PUSH_CHECKS=1, so these didn't run: ${names.join(", ")}`);
176
+ return 0;
177
+ }
178
+ if (!loadDrops(machine)) return 1;
179
+ const ran = [];
180
+ const failed = names.find((name) => {
181
+ const result = runScript(root, name);
182
+ ran.push(result);
183
+ return result.status !== 0;
184
+ });
185
+ const times = ran.map(({ name, seconds }) => `${name} ${seconds.toFixed(1)} s`).join(", ");
186
+ if (failed !== void 0) {
187
+ console.error(`ref0-workspace pre-push: refused, ${failed} failed (${times}). Fix it and push again, or set REF0_SKIP_PUSH_CHECKS=1 to push without the checks.`);
188
+ return 1;
189
+ }
190
+ const why = extra.length > 0 ? `, ${extra.join(", ")} since it changes the packages` : "";
191
+ console.error(`ref0-workspace pre-push: ran ${times}${why}`);
192
+ return 0;
193
+ };
58
194
  /**
59
195
  * Answers the hook's exit code for the push to `url`, whose ref lines are `input`, from the checkout
60
- * at `at`, printing each refusal.
196
+ * at `at`, printing each refusal, then each check's result.
61
197
  */
62
- const prePush = (at, url, input, rewrite) => {
198
+ const prePush = (at, url, input, env, machine = host) => {
63
199
  const lines = input.split("\n").filter((line) => line.trim() !== "");
64
200
  const updates = lines.map(parse);
65
201
  const malformed = lines.find((_, index) => updates[index] === void 0);
@@ -67,10 +203,17 @@ const prePush = (at, url, input, rewrite) => {
67
203
  console.error(`ref0-workspace pre-push: can't read the ref line "${malformed}"`);
68
204
  return 2;
69
205
  }
70
- const refused = updates.flatMap((update) => {
71
- const found = update === void 0 ? void 0 : refusal(at, update);
206
+ const read = updates.filter((update) => update !== void 0);
207
+ const refused = read.flatMap((update) => {
208
+ const found = refusal(at, update);
72
209
  return found === void 0 ? [] : [found];
73
210
  });
211
+ const guarded = guard(url, refused, env.REF0_REWRITE);
212
+ if (guarded !== 0) return guarded;
213
+ return runChecks(at, read, env.REF0_SKIP_PUSH_CHECKS, machine);
214
+ };
215
+ /** Answers the guard's exit code for the refusals it found, printing them. */
216
+ const guard = (url, refused, rewrite) => {
74
217
  if (refused.length === 0) return 0;
75
218
  const repo = repoName(url);
76
219
  if (repo !== "" && rewrite === repo) {
@@ -82,4 +225,4 @@ const prePush = (at, url, input, rewrite) => {
82
225
  console.error(`Only a rewrite of ${repo} itself, on purpose, moves these back: set REF0_REWRITE=${repo}.${other}`);
83
226
  return 1;
84
227
  };
85
- export { isGuarded, prePush, repoName };
228
+ export { checksAt, isGuarded, loadDrops, loadPoll, loadWait, prePush, repoName };
@@ -0,0 +1,63 @@
1
+ // src/subject.ts
2
+ /**
3
+ * The commit format's rule for one line, `type(scope): subject`, with nothing but the language:
4
+ * no `effect` and no file reads. `commit-message.ts` reads a message and a repo's scopes around it,
5
+ * and `scripts/save-subject.ts` runs it with Node's own type stripping, from `home.sh save` and
6
+ * `wiki.sh save`, where no `node_modules` may be installed.
7
+ */
8
+ /** The kinds of change, in the order the release notes list them. */
9
+ const commitTypes = [
10
+ "feat",
11
+ "fix",
12
+ "perf",
13
+ "refactor",
14
+ "test",
15
+ "docs",
16
+ "build",
17
+ "ci",
18
+ "chore",
19
+ "revert"
20
+ ];
21
+ /**
22
+ * git's own subjects, which a commit may carry and a title may not: a merge's, as `fmt-merge-msg`
23
+ * writes it for one or several of a kind, an autosquash's and a revert's.
24
+ */
25
+ const gitsOwn = /^(?:Merge (?:branch(?:es)? |remote-tracking branch(?:es)? |commits? '|tags? ')|(?:fixup|squash|amend)! |(?:Revert|Reapply) ")/u;
26
+ /** `type`, then `(scope)` or nothing, then `!` or nothing, then `: ` and the words. */
27
+ const subjectLine = /^([^\s(!:]+)(?:\(([^()]*)\))?!?: (\S(?:.*\S)?)$/u;
28
+ /** A scope's name, as a repo may give it: lower case words joined by `-`. */
29
+ const scopeName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
30
+ /** Whether `scope` is a name a repo may give a scope: lower case words joined by `-`. */
31
+ const isScopeName = (scope) => scopeName.test(scope);
32
+ const read = (line, scopes) => {
33
+ const match = subjectLine.exec(line);
34
+ if (match === null) return {
35
+ valid: false,
36
+ problem: `"${line}" isn't "type(scope): subject", or "type: subject" for a change across the repo`
37
+ };
38
+ const [, word = "", named, text = ""] = match;
39
+ const type = commitTypes.find((each) => each === word);
40
+ if (type === void 0) return {
41
+ valid: false,
42
+ problem: `"${word}" isn't a type: use one of ${commitTypes.join(", ")}`
43
+ };
44
+ if (named !== void 0 && !scopes.includes(named)) return {
45
+ valid: false,
46
+ problem: `"${named}" isn't a scope: ${scopes.length === 0 ? "this repo names none, so leave it off" : `use one of ${scopes.join(", ")}, or none`}`
47
+ };
48
+ return {
49
+ valid: true,
50
+ subject: {
51
+ type,
52
+ scope: named,
53
+ text
54
+ }
55
+ };
56
+ };
57
+ /** What's wrong with `line` as a commit's subject or a pull request's title, or undefined. */
58
+ const subjectProblem = (line, checked, scopes) => {
59
+ if (checked === "commit" && gitsOwn.test(line)) return void 0;
60
+ const subject = read(line, scopes);
61
+ return subject.valid ? void 0 : subject.problem;
62
+ };
63
+ export { commitTypes, isScopeName, subjectProblem };
@@ -1,8 +1,8 @@
1
- import { fromRoot, reachedProjects } from "./types/projects.mjs";
1
+ import { reachedProjects, vitePlusAt } from "./types/projects.mjs";
2
2
  import { execFile } from "node:child_process";
3
3
  import { execPath } from "node:process";
4
4
  import { promisify } from "node:util";
5
- import { dirname, join } from "node:path";
5
+ import { join } from "node:path";
6
6
  // src/type-coverage.ts
7
7
  /**
8
8
  * Fails when a tracked TypeScript file is in no project the root `tsconfig.json` reaches, or when
@@ -25,9 +25,8 @@ const run = promisify(execFile);
25
25
  const generated = /\.gen\.(?:d\.)?ts$/u;
26
26
  /** The files lint reads in the workspace at `root`, by path from it. */
27
27
  const lintedFiles = async (root) => {
28
- const vp = join(dirname(fromRoot(root, "vite-plus/package.json")), "bin/vp");
29
28
  const { stdout } = await run(execPath, [
30
- vp,
29
+ vitePlusAt(root),
31
30
  "lint",
32
31
  "--debug=files"
33
32
  ], {
@@ -16,6 +16,8 @@ const run = promisify(execFile);
16
16
  * tools a check runs are the repo's, at the versions it pins, and this package's peers.
17
17
  */
18
18
  const fromRoot = (root, specifier) => createRequire(join(root, "package.json")).resolve(specifier);
19
+ /** The repo's own `vp`, the Vite+ it pins, run with Node's `execPath`. */
20
+ const vitePlusAt = (root) => join(dirname(fromRoot(root, "vite-plus/package.json")), "bin/vp");
19
21
  /** A project's config as TypeScript resolves it: the files it includes, and its references. */
20
22
  const decodeConfig = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Struct({
21
23
  files: Schema.optionalKey(Schema.Array(Schema.String)),
@@ -62,4 +64,4 @@ const reachedProjects = async (root, config) => {
62
64
  }
63
65
  return projects;
64
66
  };
65
- export { fromRoot, reachedProjects };
67
+ export { fromRoot, reachedProjects, vitePlusAt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ref0/workspace",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "The lint and workspace checks every ref-0 repo shares",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -34,21 +34,21 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "effect": "4.1.4",
37
+ "effect": "4.1.7",
38
38
  "git-cliff": "2.14.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@effect/tsgo": "0.70.0",
42
- "@types/node": "24.19.2",
43
- "tsrs": "7.1.0-beta.tsrs2",
41
+ "@effect/tsgo": "0.74.0",
42
+ "@types/node": "24.19.4",
43
+ "tsrs": "7.1.0-beta.tsrs4",
44
44
  "typescript": "7.0.2",
45
- "vite-plus": "1.7.0"
45
+ "vite-plus": "1.8.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "@effect/tsgo": "0.70.0",
49
- "tsrs": "7.1.0-beta.tsrs2",
48
+ "@effect/tsgo": "0.74.0",
49
+ "tsrs": "7.1.0-beta.tsrs4",
50
50
  "typescript": "7.0.2",
51
- "vite-plus": "1.7.0"
51
+ "vite-plus": "1.8.0"
52
52
  },
53
53
  "peerDependenciesMeta": {
54
54
  "@effect/tsgo": {