@decohere/ci-tools 0.0.1-dev.20261123.404 → 0.0.1-dev.20261123.406

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/ci-tools",
3
- "version": "0.0.1-dev.20261123.404",
3
+ "version": "0.0.1-dev.20261123.406",
4
4
  "description": "CI utility scripts for badge generation, coverage reporting, pages artifact assembly, and GitHub API tooling",
5
5
  "keywords": [
6
6
  "typescript",
@@ -6,37 +6,7 @@
6
6
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
7
7
  import { basename, join, relative } from "node:path";
8
8
  import ts from "typescript";
9
-
10
- /** The roles a file's name may end in, from ADR 0027. */
11
- export const ROLES = new Set([
12
- "entity",
13
- "value",
14
- "service",
15
- "strategy",
16
- "factory",
17
- "repository",
18
- "port",
19
- "adapter",
20
- "provider",
21
- "plugin",
22
- "controller",
23
- "handler",
24
- "command",
25
- "action",
26
- "decorator",
27
- "event",
28
- "error",
29
- "const",
30
- "config",
31
- "module",
32
- "model",
33
- "mapping",
34
- "contract",
35
- "registry",
36
- "builder",
37
- "host",
38
- "cases",
39
- ]);
9
+ import { FileRoles } from "./file-roles.registry.mjs";
40
10
 
41
11
  /** The rules counted, and what each count means. */
42
12
  export const RULES = {
@@ -57,6 +27,8 @@ export class CodeDesign {
57
27
  /** @param {string} root the workspace root */
58
28
  constructor(root) {
59
29
  this.root = root;
30
+ /** @private */
31
+ this.roles = new FileRoles(root);
60
32
  }
61
33
 
62
34
  /**
@@ -102,7 +74,8 @@ export class CodeDesign {
102
74
  const base = basename(file).replace(/\.(ts|mts)$/, "");
103
75
  if (BANNED.test(base)) add("bannedNames", rel);
104
76
  const role = base.split(".");
105
- if (base !== "index" && (role.length < 2 || !ROLES.has(role.at(-1)))) add("noRole", rel);
77
+ if (base !== "index" && (role.length < 2 || !this.roles.has(role.at(-1))))
78
+ add("noRole", rel);
106
79
  const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
107
80
  const isPluginFile = role.at(-1) === "plugin";
108
81
  if (name !== "config" && !bins.has(relative(this.root, file))) {
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The file roles (`<thing>.<role>.ts`) the shared rules allow, read from the installed
3
+ * `@decohere/standards`, so Decohere keeps no copy of its own that can drift from them.
4
+ */
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+
8
+ /** Where the standards' table of file roles sits, from the workspace root. */
9
+ export const STANDARD_ROLES = "node_modules/@decohere/standards/rules/files-and-folders.md";
10
+
11
+ /** A row of the table: its first cell names one role or several, as `.role.ts`. */
12
+ const ROW = /^\|([^|]*)\|/;
13
+ const ROLE = /`\.([a-z][a-z-]*)\.ts`/g;
14
+
15
+ export class FileRoles {
16
+ /** @param {string} root the workspace root */
17
+ constructor(root) {
18
+ const path = join(root, STANDARD_ROLES);
19
+ if (!existsSync(path)) {
20
+ throw new Error(
21
+ `design: ${STANDARD_ROLES} is missing, so the file roles are unknown. Run pnpm install.`,
22
+ );
23
+ }
24
+ /** @private */
25
+ this.roles = new Set();
26
+ for (const line of readFileSync(path, "utf8").split("\n")) {
27
+ const cell = ROW.exec(line)?.[1] ?? "";
28
+ for (const [, role] of cell.matchAll(ROLE)) this.roles.add(role);
29
+ }
30
+ if (this.roles.size === 0) {
31
+ throw new Error(
32
+ `design: ${STANDARD_ROLES} lists no file roles; its table has changed shape.`,
33
+ );
34
+ }
35
+ }
36
+
37
+ /** @param {string} role a file name's last part before `.ts`, such as `service` */
38
+ has(role) {
39
+ return this.roles.has(role);
40
+ }
41
+ }
@@ -1,9 +1,22 @@
1
1
  import { vol } from "memfs";
2
2
  import { afterEach, describe, expect, it } from "vitest";
3
3
  import { BASELINE, runDesignCheck } from "../../src/design/design-check.command.mjs";
4
+ import { STANDARD_ROLES } from "../../src/design/file-roles.registry.mjs";
4
5
 
5
6
  const root = "/workspace";
6
7
 
8
+ /** The file roles the installed @decohere/standards lists, in the table's own format. */
9
+ const STANDARDS = [
10
+ "# Files and folders",
11
+ "",
12
+ "| Role | Holds | Example |",
13
+ "| --- | --- | --- |",
14
+ "| `.service.ts` | a class that does one job | `trading.service.ts` |",
15
+ "| `.value.ts` | a value with no identity | `money.value.ts` |",
16
+ "| `.plugin.ts`, `.state.ts` | a plugin factory; one state of a State pattern | `memory.plugin.ts` |",
17
+ "",
18
+ ].join("\n");
19
+
7
20
  /** A workspace with one package, `http`, holding these files under projects/http. */
8
21
  function seed(files, baseline) {
9
22
  vol.fromJSON({
@@ -12,6 +25,7 @@ function seed(files, baseline) {
12
25
  Object.entries(files).map(([path, text]) => [`${root}/projects/http/${path}`, text]),
13
26
  ),
14
27
  ...(baseline ? { [`${root}/${BASELINE}`]: JSON.stringify(baseline) } : {}),
28
+ [`${root}/${STANDARD_ROLES}`]: STANDARDS,
15
29
  });
16
30
  }
17
31
 
@@ -119,4 +133,23 @@ describe("design:check", () => {
119
133
  run(["--update"]);
120
134
  expect(run().code).toBe(0);
121
135
  });
136
+
137
+ it("takes the file roles from the installed standards, so a role they add needs no change here", () => {
138
+ seed({ ...CLEAN, "src/holding.state.ts": "export class HoldingState {}\n" });
139
+ expect(run()).toEqual({ code: 0, output: expect.stringContaining("design: 0 breaks") });
140
+ });
141
+
142
+ it("counts a role the installed standards don't list as a file with no role", () => {
143
+ seed({ ...CLEAN, "src/order.widget.ts": "export class OrderWidget {}\n" });
144
+ run(["--update"]);
145
+ expect(JSON.parse(vol.readFileSync(`${root}/${BASELINE}`, "utf8"))).toEqual({
146
+ http: { noRole: 1 },
147
+ });
148
+ });
149
+
150
+ it("stops when the standards aren't installed, rather than accept every name", () => {
151
+ seed(CLEAN);
152
+ vol.unlinkSync(`${root}/${STANDARD_ROLES}`);
153
+ expect(() => run()).toThrow("pnpm install");
154
+ });
122
155
  });