@akanjs/devkit 3.3.0 → 3.3.1-rc.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.
@@ -191,6 +191,32 @@ export const scratch = () => new StatusError(502, "not committed");
191
191
  ]);
192
192
  });
193
193
 
194
+ test("reads the package sources on disk of a folder in no git repository", async () => {
195
+ const root = await makeTempRoot();
196
+ await writeText(
197
+ path.join(root, "base/akanError.ts"),
198
+ await Bun.file(path.join(akanjsDir, "base/akanError.ts")).text(),
199
+ );
200
+ await writeText(path.join(root, "signal/statusError.ts"), statusError);
201
+ await writeText(
202
+ path.join(root, "server/useStatus.ts"),
203
+ `import { StatusError } from "../signal/statusError";
204
+ export const clash = () => new StatusError(409, "taken");
205
+ `,
206
+ );
207
+ await writeText(
208
+ path.join(root, "server/useStatus.test.ts"),
209
+ `import { StatusError } from "../signal/statusError";
210
+ throw new StatusError(410, "only in a test");
211
+ `,
212
+ );
213
+
214
+ expect(ErrorCodeReference.collect(root).map(({ code, error }) => `${code} ${error}`)).toEqual([
215
+ "conflict StatusError",
216
+ "notFound StatusError.NotFound",
217
+ ]);
218
+ });
219
+
194
220
  test("reads a forwarded getter that compares this.code to a literal per code", async () => {
195
221
  const root = await fixtureOf({
196
222
  "service/queryError.ts": `import { AkanError } from "../base/akanError";
@@ -477,12 +477,29 @@ export class ErrorCodeScan {
477
477
 
478
478
  //? Tracked files only, unlike the gate: an untracked scratch file would otherwise shift the page CI compares.
479
479
  static #sourcesOf(dir: string) {
480
- const listed = Bun.spawnSync(["git", "ls-files", "-z", "--", "."], { cwd: dir, stdout: "pipe", stderr: "pipe" });
481
- if (listed.exitCode !== 0) throw new Error(`git ls-files failed in ${dir}: ${listed.stderr.toString().trim()}`);
482
- return listed.stdout
483
- .toString()
484
- .split("\0")
485
- .filter((file) => file && !file.includes("node_modules/") && MaintainabilityLimits.isPackageSource(file));
480
+ return (ErrorCodeScan.#trackedIn(dir) ?? ErrorCodeScan.#onDiskIn(dir)).filter(
481
+ (file) => file && !file.includes("node_modules/") && MaintainabilityLimits.isPackageSource(file),
482
+ );
483
+ }
484
+
485
+ static #trackedIn(dir: string) {
486
+ try {
487
+ const listed = Bun.spawnSync(["git", "ls-files", "-z", "--", "."], {
488
+ cwd: dir,
489
+ stdout: "pipe",
490
+ stderr: "ignore",
491
+ });
492
+ return listed.exitCode === 0 ? listed.stdout.toString().split("\0") : null;
493
+ } catch {
494
+ return null;
495
+ }
496
+ }
497
+
498
+ //? A deploy host unpacks the sources without their repository, where git lists nothing and no file is untracked.
499
+ static #onDiskIn(dir: string) {
500
+ return [...new Bun.Glob("**/*.{ts,tsx}").scanSync({ cwd: dir, onlyFiles: true })]
501
+ .map((file) => file.split(path.sep).join("/"))
502
+ .sort(byCodeUnit);
486
503
  }
487
504
 
488
505
  //? Parsing every source costs seconds; a file that names no AkanError descendant can neither declare nor build one.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "3.3.0",
3
+ "version": "3.3.1-rc.0",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -52,10 +52,10 @@
52
52
  "./workspace/getRelatedCnsts": "./workspace/getRelatedCnsts.ts"
53
53
  },
54
54
  "dependencies": {
55
- "@akanjs/language": "3.3.0",
55
+ "@akanjs/language": "3.3.1-rc.0",
56
56
  "@inquirer/prompts": "^8.7.3",
57
57
  "@tailwindcss/node": "^4.3.3",
58
- "akanjs": "3.3.0",
58
+ "akanjs": "3.3.1-rc.0",
59
59
  "chalk": "^6.0.1",
60
60
  "commander": "^15.0.0",
61
61
  "dayjs": "^1.11.23",