@rexezuge/tooling 1.2.0 → 1.4.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.
Files changed (153) hide show
  1. package/README.md +66 -10
  2. package/dist/eslint-boundaries.d.ts +31 -7
  3. package/dist/eslint-boundaries.d.ts.map +1 -1
  4. package/dist/eslint-boundaries.js +1 -138
  5. package/dist/eslint-boundaries.js.map +7 -1
  6. package/dist/eslint-rules.js +1 -273
  7. package/dist/eslint-rules.js.map +7 -1
  8. package/dist/eslint.d.ts +12 -7
  9. package/dist/eslint.d.ts.map +1 -1
  10. package/dist/eslint.js +1 -189
  11. package/dist/eslint.js.map +7 -1
  12. package/dist/functions/pages-proxy.d.ts.map +1 -1
  13. package/dist/functions/pages-proxy.js +1 -131
  14. package/dist/functions/pages-proxy.js.map +7 -1
  15. package/dist/index.d.ts +20 -14
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -28
  18. package/dist/index.js.map +7 -1
  19. package/dist/scripts/backup/d1-target.d.ts +15 -5
  20. package/dist/scripts/backup/d1-target.d.ts.map +1 -1
  21. package/dist/scripts/backup/d1-target.js +1 -31
  22. package/dist/scripts/backup/d1-target.js.map +7 -1
  23. package/dist/scripts/backup/destination-config.d.ts +24 -8
  24. package/dist/scripts/backup/destination-config.d.ts.map +1 -1
  25. package/dist/scripts/backup/destination-config.js +1 -57
  26. package/dist/scripts/backup/destination-config.js.map +7 -1
  27. package/dist/scripts/backup/encrypt-backup.js +2 -97
  28. package/dist/scripts/backup/encrypt-backup.js.map +7 -1
  29. package/dist/scripts/backup/naming.d.ts +3 -1
  30. package/dist/scripts/backup/naming.d.ts.map +1 -1
  31. package/dist/scripts/backup/naming.js +1 -58
  32. package/dist/scripts/backup/naming.js.map +7 -1
  33. package/dist/scripts/check-god-files.d.ts +40 -14
  34. package/dist/scripts/check-god-files.d.ts.map +1 -1
  35. package/dist/scripts/check-god-files.js +2 -271
  36. package/dist/scripts/check-god-files.js.map +7 -1
  37. package/dist/scripts/ensure-spa-shell-stub.js +1 -29
  38. package/dist/scripts/ensure-spa-shell-stub.js.map +7 -1
  39. package/dist/scripts/init-secrets.d.ts +0 -16
  40. package/dist/scripts/init-secrets.d.ts.map +1 -1
  41. package/dist/scripts/init-secrets.js +2 -239
  42. package/dist/scripts/init-secrets.js.map +7 -1
  43. package/dist/scripts/lib/cli-args.d.ts.map +1 -1
  44. package/dist/scripts/lib/cli-args.js +1 -116
  45. package/dist/scripts/lib/cli-args.js.map +7 -1
  46. package/dist/scripts/lib/github-actions.js +3 -38
  47. package/dist/scripts/lib/github-actions.js.map +7 -1
  48. package/dist/scripts/lib/wrangler-table.d.ts.map +1 -1
  49. package/dist/scripts/lib/wrangler-table.js +2 -99
  50. package/dist/scripts/lib/wrangler-table.js.map +7 -1
  51. package/dist/scripts/migrations-lock.js +1 -44
  52. package/dist/scripts/migrations-lock.js.map +7 -1
  53. package/dist/scripts/prepare-wrangler-config.js +1 -49
  54. package/dist/scripts/prepare-wrangler-config.js.map +7 -1
  55. package/dist/scripts/spa-shell.d.ts +12 -4
  56. package/dist/scripts/spa-shell.d.ts.map +1 -1
  57. package/dist/scripts/spa-shell.js +3 -160
  58. package/dist/scripts/spa-shell.js.map +7 -1
  59. package/dist/scripts/validate-locales.d.ts +13 -5
  60. package/dist/scripts/validate-locales.d.ts.map +1 -1
  61. package/dist/scripts/validate-locales.js +4 -350
  62. package/dist/scripts/validate-locales.js.map +7 -1
  63. package/dist/scripts/verify-migrations.d.ts +27 -9
  64. package/dist/scripts/verify-migrations.d.ts.map +1 -1
  65. package/dist/scripts/verify-migrations.js +2 -312
  66. package/dist/scripts/verify-migrations.js.map +7 -1
  67. package/dist/scripts/verify-spa-shell.js +1 -52
  68. package/dist/scripts/verify-spa-shell.js.map +7 -1
  69. package/dist/scripts/wrangler-config/cli.js +3 -51
  70. package/dist/scripts/wrangler-config/cli.js.map +7 -1
  71. package/dist/scripts/wrangler-config/patches.d.ts +10 -4
  72. package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
  73. package/dist/scripts/wrangler-config/patches.js +4 -141
  74. package/dist/scripts/wrangler-config/patches.js.map +7 -1
  75. package/dist/scripts/wrangler-config/resources.d.ts +19 -7
  76. package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
  77. package/dist/scripts/wrangler-config/resources.js +1 -290
  78. package/dist/scripts/wrangler-config/resources.js.map +7 -1
  79. package/dist/scripts/wrangler-config/types.d.ts +24 -8
  80. package/dist/scripts/wrangler-config/types.d.ts.map +1 -1
  81. package/dist/scripts/wrangler-config/types.js +1 -49
  82. package/dist/scripts/wrangler-config/types.js.map +7 -1
  83. package/dist/test/integration-migrations.d.ts +29 -12
  84. package/dist/test/integration-migrations.d.ts.map +1 -1
  85. package/dist/test/integration-migrations.js +2 -171
  86. package/dist/test/integration-migrations.js.map +7 -1
  87. package/dist/test/mocks/cloudflare-workers.js +1 -90
  88. package/dist/test/mocks/cloudflare-workers.js.map +7 -1
  89. package/dist/vite.d.ts +5 -3
  90. package/dist/vite.d.ts.map +1 -1
  91. package/dist/vite.js +3 -125
  92. package/dist/vite.js.map +7 -1
  93. package/dist/vitest-aliases.d.ts +90 -0
  94. package/dist/vitest-aliases.d.ts.map +1 -0
  95. package/dist/vitest-aliases.js +1 -0
  96. package/dist/vitest-aliases.js.map +7 -0
  97. package/dist/vitest-integration.d.ts +96 -0
  98. package/dist/vitest-integration.d.ts.map +1 -0
  99. package/dist/vitest-integration.js +1 -0
  100. package/dist/vitest-integration.js.map +7 -0
  101. package/dist/vitest-repo.d.ts +154 -0
  102. package/dist/vitest-repo.d.ts.map +1 -0
  103. package/dist/vitest-repo.js +1 -0
  104. package/dist/vitest-repo.js.map +7 -0
  105. package/dist/vitest-web.d.ts +76 -19
  106. package/dist/vitest-web.d.ts.map +1 -1
  107. package/dist/vitest-web.js +1 -72
  108. package/dist/vitest-web.js.map +7 -1
  109. package/dist/vitest.d.ts +70 -19
  110. package/dist/vitest.d.ts.map +1 -1
  111. package/dist/vitest.js +1 -128
  112. package/dist/vitest.js.map +7 -1
  113. package/package.json +9 -3
  114. package/src/eslint-boundaries.ts +112 -11
  115. package/src/eslint.test.ts +40 -9
  116. package/src/eslint.ts +14 -9
  117. package/src/functions/pages-proxy.test.ts +3 -3
  118. package/src/functions/pages-proxy.ts +4 -2
  119. package/src/index.ts +23 -14
  120. package/src/scripts/backup/backup-rules.test.ts +4 -4
  121. package/src/scripts/backup/d1-target.ts +16 -6
  122. package/src/scripts/backup/destination-config.ts +27 -9
  123. package/src/scripts/backup/encrypt-backup.ts +12 -10
  124. package/src/scripts/backup/naming.ts +3 -1
  125. package/src/scripts/check-god-files.test.ts +19 -19
  126. package/src/scripts/check-god-files.ts +62 -33
  127. package/src/scripts/ensure-spa-shell-stub.ts +1 -1
  128. package/src/scripts/init-secrets.ts +20 -10
  129. package/src/scripts/lib/cli-args.ts +6 -3
  130. package/src/scripts/lib/wrangler-table.ts +5 -3
  131. package/src/scripts/migrations-lock.ts +2 -2
  132. package/src/scripts/prepare-wrangler-config.ts +3 -3
  133. package/src/scripts/spa-shell.test.ts +18 -18
  134. package/src/scripts/spa-shell.ts +26 -14
  135. package/src/scripts/validate-locales.test.ts +18 -18
  136. package/src/scripts/validate-locales.ts +43 -25
  137. package/src/scripts/verify-migrations.test.ts +8 -8
  138. package/src/scripts/verify-migrations.ts +47 -24
  139. package/src/scripts/verify-spa-shell.ts +1 -1
  140. package/src/scripts/wrangler-config/patches.ts +13 -5
  141. package/src/scripts/wrangler-config/resources.ts +34 -18
  142. package/src/scripts/wrangler-config/types.ts +24 -8
  143. package/src/test/integration-migrations.test.ts +7 -7
  144. package/src/test/integration-migrations.ts +33 -14
  145. package/src/vite.test.ts +25 -14
  146. package/src/vite.ts +5 -5
  147. package/src/vitest-aliases.test.ts +53 -0
  148. package/src/vitest-aliases.ts +125 -0
  149. package/src/vitest-factories.test.ts +127 -0
  150. package/src/vitest-integration.ts +118 -0
  151. package/src/vitest-repo.ts +269 -0
  152. package/src/vitest-web.ts +110 -28
  153. package/src/vitest.ts +96 -47
package/src/index.ts CHANGED
@@ -15,30 +15,39 @@
15
15
  * alongside `@rexezuge/d1`.
16
16
  */
17
17
 
18
- export { defineRepoLintConfig } from './eslint';
19
- export type { RepoLintConfigOptions } from './eslint';
18
+ export { defineRepoLintConfig } from './eslint.ts';
19
+ export type { RepoLintConfigOptions } from './eslint.ts';
20
20
 
21
- export { defineUnitVitestConfig } from './vitest';
22
- export type { CoverageThresholds, UnitVitestConfigOptions, VitestAlias } from './vitest';
21
+ export { defineUnitVitestConfig } from './vitest.ts';
22
+ export type { CoverageThresholds, UnitVitestConfigOptions, VitestAlias } from './vitest.ts';
23
23
 
24
- export { defineWebVitestConfig } from './vitest-web';
25
- export type { WebVitestConfigOptions } from './vitest-web';
24
+ export { defineWebVitestConfig } from './vitest-web.ts';
25
+ export type { WebVitestConfigOptions } from './vitest-web.ts';
26
26
 
27
- export { defineWebViteConfig, spaShellEmbedPlugin } from './vite';
28
- export type { ProxyEntry, SpaShellTarget, WebViteConfigOptions } from './vite';
27
+ export { defineRepoVitestConfig } from './vitest-repo.ts';
28
+ export type { RepoBackendOptions, RepoVitestConfigOptions, RepoWebOptions } from './vitest-repo.ts';
29
29
 
30
- export { createPagesProxy } from './functions/pages-proxy';
31
- export type { Fetcher, PagesFunction, PagesFunctionContext, PagesProxyEnv, PagesProxyOptions } from './functions/pages-proxy';
30
+ export { defineIntegrationVitestConfig } from './vitest-integration.ts';
31
+ export type { IntegrationVitestConfigOptions } from './vitest-integration.ts';
32
+
33
+ export { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
34
+ export type { VitestAlias as WorkspaceAlias, WorkspaceAliasesOptions } from './vitest-aliases.ts';
35
+
36
+ export { defineWebViteConfig, spaShellEmbedPlugin } from './vite.ts';
37
+ export type { ProxyEntry, SpaShellTarget, WebViteConfigOptions } from './vite.ts';
38
+
39
+ export { createPagesProxy } from './functions/pages-proxy.ts';
40
+ export type { Fetcher, PagesFunction, PagesFunctionContext, PagesProxyEnv, PagesProxyOptions } from './functions/pages-proxy.ts';
32
41
 
33
42
  // --- Test helpers ---------------------------------------------------------
34
43
  //
35
44
  // Aliased in a Vitest config, not imported by application code, so the mocks stay
36
45
  // where the suites can reach them.
37
46
 
38
- export { DurableObject, RpcTarget, WorkflowEntrypoint } from './test/mocks/cloudflare-workers';
39
- export type { DurableObjectState, ExecutionContext } from './test/mocks/cloudflare-workers';
47
+ export { DurableObject, RpcTarget, WorkflowEntrypoint } from './test/mocks/cloudflare-workers.ts';
48
+ export type { DurableObjectState, ExecutionContext } from './test/mocks/cloudflare-workers.ts';
40
49
 
41
- export { createMigrationHelper, readMigrationFiles, splitSql } from './test/integration-migrations';
50
+ export { createMigrationHelper, readMigrationFiles, splitSql } from './test/integration-migrations.ts';
42
51
  export type {
43
52
  D1DatabaseLike,
44
53
  D1PreparedStatementLike,
@@ -46,4 +55,4 @@ export type {
46
55
  MigrationHelper,
47
56
  MigrationHelperOptions,
48
57
  MigrationRange,
49
- } from './test/integration-migrations';
58
+ } from './test/integration-migrations.ts';
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { resolveD1Target } from './d1-target';
3
- import { evaluateConfig } from './destination-config';
4
- import { backupFileName, backupStamp, requireRetentionDays, retentionCutoff } from './naming';
2
+ import { resolveD1Target } from './d1-target.ts';
3
+ import { evaluateConfig } from './destination-config.ts';
4
+ import { backupFileName, backupStamp, requireRetentionDays, retentionCutoff } from './naming.ts';
5
5
 
6
6
  describe('resolveD1Target', () => {
7
7
  it('prefers database_name, falling back to the binding', () => {
@@ -67,7 +67,7 @@ describe('evaluateConfig', () => {
67
67
  });
68
68
 
69
69
  it('treats whitespace-only secrets as absent', () => {
70
- expect(evaluateConfig({ S3_ACCESS_KEY_ID: ' ', S3_SECRET_ACCESS_KEY: ' ', S3_BUCKET: '\t' }).s3).toBe(false);
70
+ expect(evaluateConfig({ S3_ACCESS_KEY_ID: ' '.repeat(3), S3_SECRET_ACCESS_KEY: ' ', S3_BUCKET: '\t' }).s3).toBe(false);
71
71
  });
72
72
  });
73
73
 
@@ -6,22 +6,32 @@
6
6
  * account.
7
7
  */
8
8
 
9
- import { DEFAULT_UUID } from '../wrangler-config/types';
9
+ import { DEFAULT_UUID } from '../wrangler-config/types.ts';
10
10
 
11
- /** A D1 binding as a parsed wrangler config carries one. */
11
+ /**
12
+ A D1 binding as a parsed wrangler config carries one.
13
+ */
12
14
  export interface D1DatabaseBinding {
13
15
  binding?: string;
14
16
  database_id?: string;
15
17
  database_name?: string;
16
18
  }
17
19
 
18
- /** The resolved export target. */
20
+ /**
21
+ The resolved export target.
22
+ */
19
23
  export interface D1Target {
20
- /** The binding name, used for log output and as the export fallback. */
24
+ /**
25
+ The binding name, used for log output and as the export fallback.
26
+ */
21
27
  binding: string;
22
- /** The database id, verified against Cloudflare by the caller. */
28
+ /**
29
+ The database id, verified against Cloudflare by the caller.
30
+ */
23
31
  databaseId: string;
24
- /** What `wrangler d1 export` should be pointed at. */
32
+ /**
33
+ What `wrangler d1 export` should be pointed at.
34
+ */
25
35
  target: string;
26
36
  }
27
37
 
@@ -6,7 +6,9 @@
6
6
  * Actions.
7
7
  */
8
8
 
9
- /** The environment the `check-secrets` job is given, as repository secrets. */
9
+ /**
10
+ The environment the `check-secrets` job is given, as repository secrets.
11
+ */
10
12
  export interface BackupSecretEnvironment {
11
13
  CLOUDFLARE_API_TOKEN?: string;
12
14
  CLOUDFLARE_ACCOUNT_ID?: string;
@@ -19,23 +21,39 @@ export interface BackupSecretEnvironment {
19
21
  WEBDAV_PASSWORD?: string;
20
22
  }
21
23
 
22
- /** What is configured, and why the run cannot proceed when it is not. */
24
+ /**
25
+ What is configured, and why the run cannot proceed when it is not.
26
+ */
23
27
  export interface DestinationConfig {
24
- /** Cloudflare credentials present, so the export job can run. */
28
+ /**
29
+ Cloudflare credentials present, so the export job can run.
30
+ */
25
31
  cloudflare: boolean;
26
- /** An encryption passphrase is available. */
32
+ /**
33
+ An encryption passphrase is available.
34
+ */
27
35
  encryption: boolean;
28
- /** At least one upload destination is configured. */
36
+ /**
37
+ At least one upload destination is configured.
38
+ */
29
39
  anyDestination: boolean;
30
- /** The S3 destination is fully configured. */
40
+ /**
41
+ The S3 destination is fully configured.
42
+ */
31
43
  s3: boolean;
32
- /** The WebDAV destination is fully configured. */
44
+ /**
45
+ The WebDAV destination is fully configured.
46
+ */
33
47
  webdav: boolean;
34
- /** Human-readable reasons the run cannot proceed, empty when it can. */
48
+ /**
49
+ Human-readable reasons the run cannot proceed, empty when it can.
50
+ */
35
51
  errors: string[];
36
52
  }
37
53
 
38
- /** A secret counts as set only when it has non-whitespace content. */
54
+ /**
55
+ A secret counts as set only when it has non-whitespace content.
56
+ */
39
57
  function isSet(value: string | undefined): boolean {
40
58
  return typeof value === 'string' && value.trim().length > 0;
41
59
  }
@@ -35,11 +35,13 @@
35
35
  import { encryptSecret } from '@rexezuge/d1';
36
36
  import { execFileSync } from 'node:child_process';
37
37
  import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
38
- import { basename } from 'node:path';
39
- import { fail, setOutput } from '../lib/github-actions';
40
- import { backupFileName } from './naming';
38
+ import path from 'node:path';
39
+ import { fail, setOutput } from '../lib/github-actions.ts';
40
+ import { backupFileName } from './naming.ts';
41
41
 
42
- /** The dump the export step leaves in the working directory. */
42
+ /**
43
+ The dump the export step leaves in the working directory.
44
+ */
43
45
  const SOURCE_FILE = 'backup.sql';
44
46
 
45
47
  /**
@@ -50,10 +52,6 @@ const SOURCE_FILE = 'backup.sql';
50
52
  */
51
53
  const XZ_ARGS = ['-T0', '-6'];
52
54
 
53
- function run(command: string, args: readonly string[]): void {
54
- execFileSync(command, [...args], { stdio: ['ignore', 'inherit', 'inherit'] });
55
- }
56
-
57
55
  if (!process.env['BACKUP_ENCRYPTION_KEY']) {
58
56
  fail('BACKUP_ENCRYPTION_KEY is not set. Refusing to export an unencrypted database.');
59
57
  }
@@ -62,7 +60,7 @@ if (!existsSync(SOURCE_FILE)) {
62
60
  fail(`Expected ${SOURCE_FILE} from the export step, but it does not exist.`);
63
61
  }
64
62
 
65
- const key = process.env['BACKUP_ENCRYPTION_KEY'] as string;
63
+ const key = process.env['BACKUP_ENCRYPTION_KEY'];
66
64
  const file = backupFileName(new Date());
67
65
 
68
66
  let plaintext: string;
@@ -86,6 +84,10 @@ if (plaintext === '') {
86
84
  */
87
85
  let compressed: Buffer;
88
86
  try {
87
+ // `xz` is resolved from PATH deliberately: the script runs wherever the
88
+ // operator compresses backups, and pinning an absolute path would break
89
+ // every platform but one.
90
+ // eslint-disable-next-line sonarjs/no-os-command-from-path
89
91
  compressed = execFileSync('xz', [...XZ_ARGS, '--keep', '--stdout', SOURCE_FILE], { maxBuffer: 512 * 1024 * 1024 });
90
92
  } catch (error: unknown) {
91
93
  fail(`xz failed on ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);
@@ -100,7 +102,7 @@ try {
100
102
  fail(`Could not encrypt the dump: ${error instanceof Error ? error.message : String(error)}`);
101
103
  }
102
104
 
103
- writeFileSync(file, `${JSON.stringify({ ...envelope, source: basename(SOURCE_FILE) }, null, 2)}\n`, 'utf8');
105
+ writeFileSync(file, `${JSON.stringify({ ...envelope, source: path.basename(SOURCE_FILE) }, null, 2)}\n`, 'utf8');
104
106
  rmSync(SOURCE_FILE, { force: true });
105
107
 
106
108
  console.log(`Backup encrypted: ${file} (${compressed.byteLength} compressed bytes)`);
@@ -30,7 +30,9 @@ export function backupStamp(date: Date): string {
30
30
  return `${iso.slice(0, 10)}_${iso.slice(11, 19).replaceAll(':', '-')}`;
31
31
  }
32
32
 
33
- /** The full artifact name: `<prefix><stamp>.sql.xz.enc`. */
33
+ /**
34
+ The full artifact name: `<prefix><stamp>.sql.xz.enc`.
35
+ */
34
36
  export function backupFileName(date: Date): string {
35
37
  return `${BACKUP_FILE_PREFIX}${backupStamp(date)}.sql.xz.enc`;
36
38
  }
@@ -1,15 +1,15 @@
1
1
  import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
3
+ import path from 'node:path';
4
4
  import { describe, expect, it, vi } from 'vitest';
5
- import { checkGodFiles, checkGodFilesCli, readAllowlist, HARD_LIMIT, SOFT_LIMIT } from './check-god-files';
5
+ import { checkGodFiles, checkGodFilesCli, readAllowlist, HARD_LIMIT, SOFT_LIMIT } from './check-god-files.ts';
6
6
 
7
7
  function tempTree(files: Record<string, string>): string {
8
- const root = mkdtempSync(join(tmpdir(), 'god-files-'));
8
+ const root = mkdtempSync(path.join(tmpdir(), 'god-files-'));
9
9
  for (const [name, content] of Object.entries(files)) {
10
- const path = join(root, name);
11
- mkdirSync(join(path, '..'), { recursive: true });
12
- writeFileSync(path, content, 'utf8');
10
+ const file = path.join(root, name);
11
+ mkdirSync(path.join(file, '..'), { recursive: true });
12
+ writeFileSync(file, content, 'utf8');
13
13
  }
14
14
  return root;
15
15
  }
@@ -84,24 +84,24 @@ describe('readAllowlist', () => {
84
84
  });
85
85
 
86
86
  it('rejects a malformed allowlist rather than reading it as empty', () => {
87
- const root = mkdtempSync(join(tmpdir(), 'god-allow-'));
88
- const path = join(root, 'allowlist.json');
89
- writeFileSync(path, '{ not: an array }', 'utf8');
90
- expect(() => readAllowlist(path)).toThrow(/not valid JSON/);
87
+ const root = mkdtempSync(path.join(tmpdir(), 'god-allow-'));
88
+ const file = path.join(root, 'allowlist.json');
89
+ writeFileSync(file, '{ not: an array }', 'utf8');
90
+ expect(() => readAllowlist(file)).toThrow(/not valid JSON/);
91
91
  });
92
92
 
93
93
  it('rejects a non-array allowlist', () => {
94
- const root = mkdtempSync(join(tmpdir(), 'god-allow-'));
95
- const path = join(root, 'allowlist.json');
96
- writeFileSync(path, '{"src/a.ts": 400}', 'utf8');
97
- expect(() => readAllowlist(path)).toThrow(/JSON array of repo-relative path strings/);
94
+ const root = mkdtempSync(path.join(tmpdir(), 'god-allow-'));
95
+ const file = path.join(root, 'allowlist.json');
96
+ writeFileSync(file, '{"src/a.ts": 400}', 'utf8');
97
+ expect(() => readAllowlist(file)).toThrow(/JSON array of repo-relative path strings/);
98
98
  });
99
99
 
100
100
  it('reads a valid allowlist', () => {
101
- const root = mkdtempSync(join(tmpdir(), 'god-allow-'));
102
- const path = join(root, 'allowlist.json');
103
- writeFileSync(path, '["a.ts", "b.ts"]', 'utf8');
104
- expect(readAllowlist(path)).toStrictEqual(['a.ts', 'b.ts']);
101
+ const root = mkdtempSync(path.join(tmpdir(), 'god-allow-'));
102
+ const file = path.join(root, 'allowlist.json');
103
+ writeFileSync(file, '["a.ts", "b.ts"]', 'utf8');
104
+ expect(readAllowlist(file)).toStrictEqual(['a.ts', 'b.ts']);
105
105
  });
106
106
  });
107
107
 
@@ -112,7 +112,7 @@ describe('checkGodFilesCli', () => {
112
112
  });
113
113
 
114
114
  it('exits non-zero with --fail-on-hard over the hard limit', () => {
115
- const exit = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as never);
115
+ const exit = vi.spyOn(process, 'exit').mockImplementation((() => {}) as never);
116
116
  const root = tempTree({ 'src/huge.ts': pad(450) });
117
117
  checkGodFilesCli(['--root', root, '--fail-on-hard']);
118
118
  expect(exit).toHaveBeenCalledWith(1);
@@ -48,19 +48,25 @@
48
48
 
49
49
  import { readdirSync, readFileSync, statSync } from 'node:fs';
50
50
  import { pathToFileURL } from 'node:url';
51
- import { join, relative } from 'node:path';
52
- import { fail } from './lib/github-actions';
53
- import { isSet, parseFlags, splitPositional, valueOf } from './lib/cli-args';
51
+ import path from 'node:path';
52
+ import { fail } from './lib/github-actions.ts';
53
+ import { isSet, parseFlags, splitPositional, valueOf } from './lib/cli-args.ts';
54
54
 
55
55
  /**
56
56
  * A file past a size the guard reports on.
57
57
  */
58
58
  export interface GodFileFinding {
59
- /** Path relative to the root the check ran against. */
59
+ /**
60
+ Path relative to the root the check ran against.
61
+ */
60
62
  readonly file: string;
61
- /** Lines it has. */
63
+ /**
64
+ Lines it has.
65
+ */
62
66
  readonly lines: number;
63
- /** `warn` past the soft limit, `critical` past the hard one. */
67
+ /**
68
+ `warn` past the soft limit, `critical` past the hard one.
69
+ */
64
70
  readonly level: 'warn' | 'critical';
65
71
  }
66
72
 
@@ -68,11 +74,17 @@ export interface GodFileFinding {
68
74
  * The outcome of one run.
69
75
  */
70
76
  export interface GodFileReport {
71
- /** Files over a limit, worst first, minus the allowlisted. */
77
+ /**
78
+ Files over a limit, worst first, minus the allowlisted.
79
+ */
72
80
  readonly findings: readonly GodFileFinding[];
73
- /** How many files the walk measured. */
81
+ /**
82
+ How many files the walk measured.
83
+ */
74
84
  readonly scanned: number;
75
- /** Allowlisted files that are over a limit — reported, never counted. */
85
+ /**
86
+ Allowlisted files that are over a limit — reported, never counted.
87
+ */
76
88
  readonly allowlisted: readonly GodFileFinding[];
77
89
  /**
78
90
  * Whether the tree may be committed as it stands.
@@ -81,7 +93,9 @@ export interface GodFileReport {
81
93
  * only when the caller asked for the gate.
82
94
  */
83
95
  readonly passed: boolean;
84
- /** The message to print, either way. */
96
+ /**
97
+ The message to print, either way.
98
+ */
85
99
  readonly reported: string;
86
100
  }
87
101
 
@@ -89,7 +103,9 @@ export interface GodFileReport {
89
103
  * What `checkGodFiles` accepts.
90
104
  */
91
105
  export interface GodFileOptions {
92
- /** Directory to walk. */
106
+ /**
107
+ Directory to walk.
108
+ */
93
109
  readonly root: string;
94
110
  /**
95
111
  * Repo-relative paths (or directory prefixes ending in `/`) exempt from the
@@ -97,17 +113,27 @@ export interface GodFileOptions {
97
113
  * when that file exists — see `readAllowlist`.
98
114
  */
99
115
  readonly allowlist?: readonly string[];
100
- /** Soft limit, past which a file is reported as `warn`. */
116
+ /**
117
+ Soft limit, past which a file is reported as `warn`.
118
+ */
101
119
  readonly soft?: number;
102
- /** Hard limit, past which a file is reported as `critical`. */
120
+ /**
121
+ Hard limit, past which a file is reported as `critical`.
122
+ */
103
123
  readonly hard?: number;
104
- /** Make a `critical` finding fail the run. */
124
+ /**
125
+ Make a `critical` finding fail the run.
126
+ */
105
127
  readonly failOnHard?: boolean;
106
128
  }
107
129
 
108
- /** Default soft limit, as every source repo uses. */
130
+ /**
131
+ Default soft limit, as every source repo uses.
132
+ */
109
133
  export const SOFT_LIMIT = 300;
110
- /** Default hard limit, as every source repo uses. */
134
+ /**
135
+ Default hard limit, as every source repo uses.
136
+ */
111
137
  export const HARD_LIMIT = 400;
112
138
 
113
139
  /**
@@ -154,15 +180,18 @@ const TEST_SUFFIXES: readonly string[] = ['test', 'spec'].flatMap((kind) =>
154
180
  * that dead pattern.
155
181
  */
156
182
  export function shouldSkip(rel: string): boolean {
157
- if (/(?:^|\/)(?:locales|generated)\//.test(rel)) return true;
158
- if (/(?:^|\/)__(?:tests|mocks)__(?:\/|$)/.test(rel)) return true;
159
- if (/(?:^|\/)scripts\//.test(rel)) return true;
160
- if (/(?:^|\/)(?:test|tests|__tests__)\//.test(rel)) return true;
161
- if (/\.config\.(?:m?[jt]s|cjs)$/.test(rel)) return true;
162
- if (rel.endsWith('.d.ts')) return true;
163
- if (rel.endsWith('.json')) return true;
164
- if (rel.endsWith('.sql')) return true;
165
- if (rel.endsWith('.md')) return true;
183
+ if (
184
+ /(?:^|\/)(?:locales|generated)\//.test(rel) ||
185
+ /(?:^|\/)__(?:tests|mocks)__(?:\/|$)/.test(rel) ||
186
+ /(?:^|\/)scripts\//.test(rel) ||
187
+ /(?:^|\/)(?:test|tests|__tests__)\//.test(rel) ||
188
+ /\.config\.(?:m?[jt]s|cjs)$/.test(rel) ||
189
+ rel.endsWith('.d.ts') ||
190
+ rel.endsWith('.json') ||
191
+ rel.endsWith('.sql') ||
192
+ rel.endsWith('.md')
193
+ )
194
+ return true;
166
195
  return TEST_SUFFIXES.some((suffix) => rel.endsWith(suffix));
167
196
  }
168
197
 
@@ -186,7 +215,7 @@ export function walk(root: string): string[] {
186
215
  const out: string[] = [];
187
216
  const visit = (dir: string): void => {
188
217
  for (const entry of readdirSync(dir)) {
189
- const full = join(dir, entry);
218
+ const full = path.join(dir, entry);
190
219
  let stat;
191
220
  try {
192
221
  stat = statSync(full);
@@ -197,7 +226,7 @@ export function walk(root: string): string[] {
197
226
  if (EXCLUDE_DIRS.has(entry)) continue;
198
227
  visit(full);
199
228
  } else if (SOURCE_EXTENSIONS.test(entry)) {
200
- out.push(relative(root, full));
229
+ out.push(path.relative(root, full));
201
230
  }
202
231
  }
203
232
  };
@@ -221,7 +250,7 @@ export function checkGodFiles(options: GodFileOptions): GodFileReport {
221
250
  const allowlisted: GodFileFinding[] = [];
222
251
 
223
252
  for (const rel of scanned) {
224
- const lines = readFileSync(join(options.root, rel), 'utf8').split('\n').length;
253
+ const lines = readFileSync(path.join(options.root, rel), 'utf8').split('\n').length;
225
254
  if (lines <= soft) continue;
226
255
  const finding: GodFileFinding = { file: rel, lines, level: lines > hard ? 'critical' : 'warn' };
227
256
  if (isAllowlisted(rel, allowlist)) {
@@ -255,10 +284,10 @@ export function checkGodFiles(options: GodFileOptions): GodFileReport {
255
284
  * A malformed file is an error rather than an empty list, because "the allowlist
256
285
  * is empty" silently un-reports every known offender.
257
286
  */
258
- export function readAllowlist(path: string): string[] {
287
+ export function readAllowlist(file: string): string[] {
259
288
  let raw: string;
260
289
  try {
261
- raw = readFileSync(path, 'utf8');
290
+ raw = readFileSync(file, 'utf8');
262
291
  } catch {
263
292
  return [];
264
293
  }
@@ -266,10 +295,10 @@ export function readAllowlist(path: string): string[] {
266
295
  try {
267
296
  parsed = JSON.parse(raw);
268
297
  } catch (error: unknown) {
269
- throw new Error(`${path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
298
+ throw new Error(`${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
270
299
  }
271
300
  if (!Array.isArray(parsed) || parsed.some((entry) => typeof entry !== 'string')) {
272
- throw new Error(`${path} must be a JSON array of repo-relative path strings.`);
301
+ throw new Error(`${file} must be a JSON array of repo-relative path strings.`);
273
302
  }
274
303
  return parsed as string[];
275
304
  }
@@ -296,7 +325,7 @@ export function checkGodFilesCli(argv: readonly string[] = process.argv.slice(2)
296
325
  boolean: ['fail-on-hard'],
297
326
  });
298
327
  const root = valueOf(flags, 'root') ?? positional[0] ?? '.';
299
- const allowlistPath = valueOf(flags, 'allowlist') ?? join(root, 'scripts/god-files.allowlist.json');
328
+ const allowlistPath = valueOf(flags, 'allowlist') ?? path.join(root, 'scripts/god-files.allowlist.json');
300
329
  const report = checkGodFiles({
301
330
  root,
302
331
  allowlist: readAllowlist(allowlistPath),
@@ -20,7 +20,7 @@
20
20
  */
21
21
  import path from 'node:path';
22
22
  import { fileURLToPath } from 'node:url';
23
- import { ensureSpaShellStub } from './spa-shell';
23
+ import { ensureSpaShellStub } from './spa-shell.ts';
24
24
 
25
25
  const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
26
26
  const root = process.argv[2] === undefined ? REPOSITORY_ROOT : path.resolve(process.argv[2]);
@@ -47,9 +47,9 @@
47
47
  import { execFileSync } from 'node:child_process';
48
48
  import { existsSync, readFileSync } from 'node:fs';
49
49
  import { parse } from 'jsonc-parser';
50
- import { fail } from './lib/github-actions';
51
- import { isEmptySecretsStoreListing, parseWranglerNames } from './lib/wrangler-table';
52
- import { CONFIG_PATH, type WranglerConfig } from './wrangler-config/types';
50
+ import { fail } from './lib/github-actions.ts';
51
+ import { isEmptySecretsStoreListing, parseWranglerNames } from './lib/wrangler-table.ts';
52
+ import { CONFIG_PATH, type WranglerConfig } from './wrangler-config/types.ts';
53
53
 
54
54
  /**
55
55
  * The secret names the AES-GCM key generator produces, matched by **shape**.
@@ -61,10 +61,14 @@ import { CONFIG_PATH, type WranglerConfig } from './wrangler-config/types';
61
61
  */
62
62
  const ENCRYPTION_KEY_SUFFIX = '-encryption-key';
63
63
 
64
- /** The secret names the random signing secret generator produces. */
64
+ /**
65
+ The secret names the random signing secret generator produces.
66
+ */
65
67
  const SIGNING_SECRET_SUFFIX = '-signing-secret';
66
68
 
67
- /** A 256-bit AES-GCM key, base64-encoded — the shape the worker's crypto layer accepts. */
69
+ /**
70
+ A 256-bit AES-GCM key, base64-encoded — the shape the worker's crypto layer accepts.
71
+ */
68
72
  async function generateAESGCMKey(): Promise<string> {
69
73
  const key = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
70
74
  const exported = await crypto.subtle.exportKey('raw', key);
@@ -77,7 +81,9 @@ async function generateAESGCMKey(): Promise<string> {
77
81
  return btoa(binary);
78
82
  }
79
83
 
80
- /** A 256-bit random signing secret for internal self-calls, hex-encoded. */
84
+ /**
85
+ A 256-bit random signing secret for internal self-calls, hex-encoded.
86
+ */
81
87
  function generateSigningSecret(): Promise<string> {
82
88
  let hex = '';
83
89
  for (const byte of crypto.getRandomValues(new Uint8Array(32))) {
@@ -102,8 +108,10 @@ function generatorFor(secretName: string): () => Promise<string> {
102
108
  );
103
109
  }
104
110
 
105
- /** Whether this script can produce a value for `secretName`. */
106
- export function canProvisionSecret(secretName: string): boolean {
111
+ /**
112
+ Whether this script can produce a value for `secretName`.
113
+ */
114
+ function canProvisionSecret(secretName: string): boolean {
107
115
  try {
108
116
  generatorFor(secretName);
109
117
  return true;
@@ -150,7 +158,9 @@ function parseWranglerConfig(): WranglerConfig {
150
158
  return config;
151
159
  }
152
160
 
153
- /** One secret to create, as the plan names it. */
161
+ /**
162
+ One secret to create, as the plan names it.
163
+ */
154
164
  interface PlannedSecret {
155
165
  storeId: string;
156
166
  secretName: string;
@@ -163,7 +173,7 @@ interface PlannedSecret {
163
173
  * unprovisionable secret fails the step in milliseconds instead of after some other
164
174
  * secret has already been created.
165
175
  */
166
- export function planSecrets(config: WranglerConfig): PlannedSecret[] {
176
+ function planSecrets(config: WranglerConfig): PlannedSecret[] {
167
177
  const plan: PlannedSecret[] = [];
168
178
  for (const [index, secret] of (config.secrets_store_secrets ?? []).entries()) {
169
179
  const label = secret.binding ?? `index ${index}`;
@@ -59,7 +59,7 @@ export function parseFlags(argv: readonly string[], spec: FlagSpec): ParsedFlags
59
59
  const flags: ParsedFlags = new Map();
60
60
 
61
61
  for (let index = 0; index < argv.length; index += 1) {
62
- const arg = argv[index] as string;
62
+ const arg = argv[index];
63
63
  if (!arg.startsWith('-')) {
64
64
  throw new Error(`Unexpected argument: ${arg}`);
65
65
  }
@@ -81,7 +81,10 @@ export function parseFlags(argv: readonly string[], spec: FlagSpec): ParsedFlags
81
81
  throw new Error(`--${name} was given more than once`);
82
82
  }
83
83
 
84
- const value = argv[index + 1];
84
+ // `argv[index + 1]` is statically a string, but a value flag in last
85
+ // position has no next element at runtime — the length check is what makes
86
+ // the `undefined` below reachable rather than dead.
87
+ const value = index + 1 < argv.length ? argv[index + 1] : undefined;
85
88
  // A value that starts with `-` is treated as a missing value so that
86
89
  // `--to --dry-run` reports the real problem instead of capturing the flag.
87
90
  if (value === undefined || value.startsWith('-')) {
@@ -132,7 +135,7 @@ export function splitPositional(
132
135
  const rest: string[] = [];
133
136
 
134
137
  for (let index = 0; index < argv.length; index += 1) {
135
- const arg = argv[index] as string;
138
+ const arg = argv[index];
136
139
  if (arg.startsWith('-')) {
137
140
  rest.push(arg);
138
141
  continue;
@@ -56,10 +56,10 @@ export function parseWranglerTableRows(output: string): string[][] {
56
56
  .split(COLUMN_SEPARATOR)
57
57
  .map((cell) => cell.trim())
58
58
  .filter(Boolean);
59
- const firstCell = cells[0];
60
- if (firstCell === undefined || cells.length < 2) {
59
+ if (cells.length < 2) {
61
60
  continue;
62
61
  }
62
+ const firstCell = cells[0];
63
63
  // The header row and the horizontal rules are frame, not data.
64
64
  if (firstCell === HEADER_FIRST_CELL || firstCell.includes(RULE_CHARACTER)) {
65
65
  continue;
@@ -78,7 +78,9 @@ export function parseWranglerTableRows(output: string): string[][] {
78
78
  export function parseWranglerNames(output: string): Set<string> {
79
79
  const names = new Set<string>();
80
80
  for (const row of parseWranglerTableRows(output)) {
81
- const name = row[0];
81
+ // `.at()` rather than `[0]`: the absence case is real for a hand-built row
82
+ // in a test double, and the guard below is what keeps it out of the set.
83
+ const name = row.at(0);
82
84
  if (name !== undefined) names.add(name);
83
85
  }
84
86
  return names;