@ref0/workspace 0.8.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.
@@ -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 };
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ref0/workspace",
3
- "version": "0.8.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": {