@decohere/ci-tools 0.0.1-dev.20261123.370 → 0.0.1-dev.20261123.374

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.370",
3
+ "version": "0.0.1-dev.20261123.374",
4
4
  "description": "CI utility scripts for badge generation, coverage reporting, pages artifact assembly, and GitHub API tooling",
5
5
  "keywords": [
6
6
  "typescript",
@@ -103,18 +103,20 @@ export class CodeDesign {
103
103
  if (BANNED.test(base)) add("bannedNames", rel);
104
104
  const role = base.split(".");
105
105
  if (base !== "index" && (role.length < 2 || !ROLES.has(role.at(-1)))) add("noRole", rel);
106
- const env = text.match(/process\.env\b/g)?.length ?? 0;
107
- if (env > 0 && name !== "config" && !bins.has(relative(this.root, file))) {
108
- for (let i = 0; i < env; i++) add("envReads", rel);
109
- }
110
106
  const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
107
+ const isPluginFile = role.at(-1) === "plugin";
108
+ if (name !== "config" && !bins.has(relative(this.root, file))) {
109
+ for (let i = countEnvReads(source); i > 0; i--) add("envReads", rel);
110
+ }
111
111
  let classes = 0;
112
112
  for (const statement of source.statements) {
113
113
  if (ts.isClassDeclaration(statement)) classes++;
114
114
  if (!isExported(statement)) continue;
115
115
  if (ts.isFunctionDeclaration(statement)) {
116
116
  const fn = statement.name?.text ?? "default";
117
- if (!isAllowedFunction(fn, statement)) add("looseFunctions", `${rel}: ${fn}`);
117
+ // A .plugin.ts file holds a plugin factory, whatever writer or module it returns.
118
+ if (!isPluginFile && !isAllowedFunction(fn, statement))
119
+ add("looseFunctions", `${rel}: ${fn}`);
118
120
  }
119
121
  if (ts.isVariableStatement(statement)) {
120
122
  for (const declaration of statement.declarationList.declarations) {
@@ -195,6 +197,28 @@ export class CodeDesign {
195
197
  }
196
198
 
197
199
  /** @param {ts.Statement} statement */
200
+ /**
201
+ * `process.env` in code: a property read, so the words in a string (a template for generated
202
+ * code) or a comment don't count.
203
+ *
204
+ * @param {ts.Node} node
205
+ * @returns {number}
206
+ */
207
+ function countEnvReads(node) {
208
+ const here =
209
+ ts.isPropertyAccessExpression(node) &&
210
+ node.name.text === "env" &&
211
+ ts.isIdentifier(node.expression) &&
212
+ node.expression.text === "process"
213
+ ? 1
214
+ : 0;
215
+ let below = 0;
216
+ node.forEachChild((child) => {
217
+ below += countEnvReads(child);
218
+ });
219
+ return here + below;
220
+ }
221
+
198
222
  function isExported(statement) {
199
223
  return (
200
224
  ts.canHaveModifiers(statement) &&
@@ -75,6 +75,27 @@ describe("design:check", () => {
75
75
  });
76
76
  });
77
77
 
78
+ it("counts environment reads in code, not the words in a string or a comment", () => {
79
+ seed({
80
+ "src/app.service.ts":
81
+ "// reads process.env.PORT\nexport class AppService {\n" +
82
+ '\tpublic readonly text = "const port = process.env.PORT;";\n' +
83
+ "\tpublic readonly port = process.env.PORT;\n}\n",
84
+ });
85
+ expect(run(["--update"]).code).toBe(0);
86
+ expect(JSON.parse(vol.readFileSync(`${root}/${BASELINE}`, "utf8"))).toEqual({
87
+ http: { envReads: 1 },
88
+ });
89
+ });
90
+
91
+ it("keeps the factory in a .plugin.ts file, whatever it returns", () => {
92
+ seed({
93
+ "src/pino.plugin.ts":
94
+ "export function pino(): PinoAdapter {\n\treturn new PinoAdapter();\n}\n",
95
+ });
96
+ expect(run()).toEqual({ code: 0, output: expect.stringContaining("design: 0 breaks") });
97
+ });
98
+
78
99
  it("keeps plugin factories, decorators, define helpers and predicates", () => {
79
100
  seed({
80
101
  ...CLEAN,