@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
@@ -29,7 +29,7 @@
29
29
  */
30
30
  import path from 'node:path';
31
31
  import { fileURLToPath } from 'node:url';
32
- import { LOCK_NAME, verifyMigrations } from './verify-migrations';
32
+ import { LOCK_NAME, verifyMigrations } from './verify-migrations.ts';
33
33
 
34
34
  const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
35
35
  const migrationsDir = process.argv[2] === undefined ? path.join(REPOSITORY_ROOT, 'migrations') : path.resolve(process.argv[2]);
@@ -41,7 +41,7 @@ for (const problem of report.problems) {
41
41
  }
42
42
 
43
43
  console.log(
44
- `${report.lock === null ? 'left' : 'wrote'} ${path.join(migrationsDir, LOCK_NAME)} ` + `(${report.files.length} migration(s) recorded)`,
44
+ `${report.lock === null ? 'left' : 'wrote'} ${path.join(migrationsDir, LOCK_NAME)} (${report.files.length} migration(s) recorded)`,
45
45
  );
46
46
 
47
47
  // The lock is re-checked by the caller: `verify-migrations.ts` re-reads from disk,
@@ -31,9 +31,9 @@
31
31
  * - `WRANGLER_PATCH_JSON` — top-level keys merged into the config.
32
32
  * - `WRANGLER_VARS_PATCH_JSON` — `vars` entries merged into the config.
33
33
  */
34
- import { setOutput } from './lib/github-actions';
35
- import { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches';
36
- import { provisionWranglerResources } from './wrangler-config/resources';
34
+ import { setOutput } from './lib/github-actions.ts';
35
+ import { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches.ts';
36
+ import { provisionWranglerResources } from './wrangler-config/resources.ts';
37
37
 
38
38
  prepareConfigFile();
39
39
  ensureMinimumConfigVersion();
@@ -1,22 +1,22 @@
1
1
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
- import { dirname, join } from 'node:path';
3
+ import path from 'node:path';
4
4
  import { describe, expect, it } from 'vitest';
5
- import { ensureSpaShellStub, spaShellCli, verifySpaShell } from './spa-shell';
5
+ import { ensureSpaShellStub, spaShellCli, verifySpaShell } from './spa-shell.ts';
6
6
 
7
7
  function tempTree(): string {
8
- return mkdtempSync(join(tmpdir(), 'spa-shell-'));
8
+ return mkdtempSync(path.join(tmpdir(), 'spa-shell-'));
9
9
  }
10
10
 
11
11
  function writeBuild(root: string, html: string): void {
12
- const shell = join(root, 'apps/api/src/generated');
12
+ const shell = path.join(root, 'apps/api/src/generated');
13
13
  mkdirSync(shell, { recursive: true });
14
- writeFileSync(join(shell, 'spa-shell.ts'), `export const SPA_HTML: string = ${JSON.stringify(html)};\n`, 'utf8');
15
- const distAssets = join(root, 'apps/web/dist/assets');
14
+ writeFileSync(path.join(shell, 'spa-shell.ts'), `export const SPA_HTML: string = ${JSON.stringify(html)};\n`, 'utf8');
15
+ const distAssets = path.join(root, 'apps/web/dist/assets');
16
16
  mkdirSync(distAssets, { recursive: true });
17
- writeFileSync(join(root, 'apps/web/dist/index.html'), html, 'utf8');
17
+ writeFileSync(path.join(root, 'apps/web/dist/index.html'), html, 'utf8');
18
18
  for (const asset of html.matchAll(/\/assets\/([^"]+)/g)) {
19
- writeFileSync(join(distAssets, asset[1] as string), 'console.log(1)', 'utf8');
19
+ writeFileSync(path.join(distAssets, asset[1] as string), 'console.log(1)', 'utf8');
20
20
  }
21
21
  }
22
22
 
@@ -27,18 +27,18 @@ describe('ensureSpaShellStub', () => {
27
27
  const root = tempTree();
28
28
  const result = ensureSpaShellStub({ root });
29
29
  expect(result.created).toBe(true);
30
- expect(existsSync(join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
30
+ expect(existsSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
31
31
  expect(readFileSync(result.path, 'utf8')).toContain("SPA_HTML: string = ''");
32
32
  });
33
33
 
34
34
  it('never overwrites an existing file', () => {
35
35
  const root = tempTree();
36
- const path = join(root, 'apps/api/src/generated', 'spa-shell.ts');
37
- mkdirSync(dirname(path), { recursive: true });
38
- writeFileSync(path, 'real content', 'utf8');
36
+ const file = path.join(root, 'apps/api/src/generated', 'spa-shell.ts');
37
+ mkdirSync(path.dirname(file), { recursive: true });
38
+ writeFileSync(file, 'real content', 'utf8');
39
39
  const result = ensureSpaShellStub({ root });
40
40
  expect(result.created).toBe(false);
41
- expect(readFileSync(path, 'utf8')).toBe('real content');
41
+ expect(readFileSync(file, 'utf8')).toBe('real content');
42
42
  });
43
43
  });
44
44
 
@@ -57,23 +57,23 @@ describe('verifySpaShell', () => {
57
57
 
58
58
  it('reports the postinstall stub', () => {
59
59
  const root = tempTree();
60
- const path = join(root, 'apps/api/src/generated', 'spa-shell.ts');
61
- mkdirSync(dirname(path), { recursive: true });
62
- writeFileSync(path, "export const SPA_HTML: string = '';\n", 'utf8');
60
+ const file = path.join(root, 'apps/api/src/generated', 'spa-shell.ts');
61
+ mkdirSync(path.dirname(file), { recursive: true });
62
+ writeFileSync(file, "export const SPA_HTML: string = '';\n", 'utf8');
63
63
  expect(verifySpaShell({ root }).problems.join('\n')).toContain('postinstall stub');
64
64
  });
65
65
 
66
66
  it('reports referenced-but-missing assets', () => {
67
67
  const root = tempTree();
68
68
  writeBuild(root, REAL_HTML);
69
- rmSync(join(root, 'apps/web/dist/assets'), { recursive: true, force: true });
69
+ rmSync(path.join(root, 'apps/web/dist/assets'), { recursive: true, force: true });
70
70
  expect(verifySpaShell({ root }).problems.join('\n')).toContain('/assets/index-abc123.js');
71
71
  });
72
72
 
73
73
  it('reports a shell that disagrees with dist/index.html', () => {
74
74
  const root = tempTree();
75
75
  writeBuild(root, REAL_HTML);
76
- writeFileSync(join(root, 'apps/web/dist/index.html'), '<!doctype html><html>different</html>', 'utf8');
76
+ writeFileSync(path.join(root, 'apps/web/dist/index.html'), '<!doctype html><html>different</html>', 'utf8');
77
77
  expect(verifySpaShell({ root }).problems.join('\n')).toContain('does not match');
78
78
  });
79
79
  });
@@ -15,14 +15,20 @@
15
15
  */
16
16
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
17
17
  import { pathToFileURL } from 'node:url';
18
- import { dirname, join, resolve } from 'node:path';
18
+ import path from 'node:path';
19
19
 
20
20
  interface SpaShellPaths {
21
- /** Repo root. */
21
+ /**
22
+ Repo root.
23
+ */
22
24
  root: string;
23
- /** Generated TS module path, relative to root. */
25
+ /**
26
+ Generated TS module path, relative to root.
27
+ */
24
28
  shellPath?: string;
25
- /** Built SPA index.html path, relative to root. */
29
+ /**
30
+ Built SPA index.html path, relative to root.
31
+ */
26
32
  distIndexPath?: string;
27
33
  }
28
34
 
@@ -35,14 +41,16 @@ const DEFAULT_DIST_INDEX = 'apps/web/dist/index.html';
35
41
  const STUB_CONTENT =
36
42
  "// Auto-generated stub - real content is produced by the build step via the Vite plugin.\nexport const SPA_HTML: string = '';\n";
37
43
 
38
- /** A built shell is a full Vite index.html; any small threshold rejects the stub. */
44
+ /**
45
+ A built shell is a full Vite index.html; any small threshold rejects the stub.
46
+ */
39
47
  const MIN_HTML_CHARS = 200;
40
48
 
41
49
  function resolvePaths(options: SpaShellPaths): { shell: string; distIndex: string; distAssets: string } {
42
- const root = resolve(options.root);
43
- const shell = join(root, options.shellPath ?? DEFAULT_SHELL);
44
- const distIndex = join(root, options.distIndexPath ?? DEFAULT_DIST_INDEX);
45
- return { shell, distIndex, distAssets: join(dirname(distIndex), 'assets') };
50
+ const root = path.resolve(options.root);
51
+ const shell = path.join(root, options.shellPath ?? DEFAULT_SHELL);
52
+ const distIndex = path.join(root, options.distIndexPath ?? DEFAULT_DIST_INDEX);
53
+ return { shell, distIndex, distAssets: path.join(path.dirname(distIndex), 'assets') };
46
54
  }
47
55
 
48
56
  /**
@@ -53,7 +61,7 @@ function resolvePaths(options: SpaShellPaths): { shell: string; distIndex: strin
53
61
  */
54
62
  function ensureSpaShellStub(options: SpaShellPaths): { created: boolean; path: string } {
55
63
  const { shell } = resolvePaths(options);
56
- mkdirSync(dirname(shell), { recursive: true });
64
+ mkdirSync(path.dirname(shell), { recursive: true });
57
65
  try {
58
66
  writeFileSync(shell, STUB_CONTENT, { encoding: 'utf8', flag: 'wx' });
59
67
  } catch (error) {
@@ -65,7 +73,9 @@ function ensureSpaShellStub(options: SpaShellPaths): { created: boolean; path: s
65
73
  return { created: true, path: shell };
66
74
  }
67
75
 
68
- /** The `SPA_HTML` string literal, decoded from the generated TS module. */
76
+ /**
77
+ The `SPA_HTML` string literal, decoded from the generated TS module.
78
+ */
69
79
  function readEmbeddedHtml(shell: string, problems: string[]): string | null {
70
80
  if (!existsSync(shell)) {
71
81
  problems.push(`${shell} is missing — run the build (only apps/web has a build step).`);
@@ -120,12 +130,12 @@ function verifySpaShell(options: SpaShellPaths): VerifyResult {
120
130
  if (html === null) {
121
131
  return { problems };
122
132
  }
123
- const referenced = [...html.matchAll(/(?:src|href)="\/assets\/([^"]+)"/g)].map((match) => match[1] as string);
133
+ const referenced = [...html.matchAll(/(?:src|href)="\/assets\/([^"]+)"/g)].map((match) => match[1]);
124
134
  if (referenced.length === 0) {
125
135
  problems.push('The embedded shell references no /assets/ bundles — it is not a real build output.');
126
136
  }
127
137
  for (const asset of new Set(referenced)) {
128
- if (!existsSync(join(distAssets, asset))) {
138
+ if (!existsSync(path.join(distAssets, asset))) {
129
139
  problems.push(`The embedded shell references /assets/${asset}, which is not in ${distAssets} — run the build.`);
130
140
  }
131
141
  }
@@ -139,7 +149,9 @@ function verifySpaShell(options: SpaShellPaths): VerifyResult {
139
149
 
140
150
  const CLI_SHAPES = 'verify|ensure';
141
151
 
142
- /** CLI entry: `spaShellCli(['verify'|'ensure', 'repo-root?'])`. */
152
+ /**
153
+ CLI entry: `spaShellCli(['verify'|'ensure', 'repo-root?'])`.
154
+ */
143
155
  function spaShellCli(argv: readonly string[] = process.argv.slice(2)): number {
144
156
  const mode = argv[0] ?? 'verify';
145
157
  if (!CLI_SHAPES.split('|').includes(mode)) {
@@ -1,13 +1,13 @@
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 } from 'vitest';
5
- import { parseObjectLiteral, validateLocales, validateLocalesCli } from './validate-locales';
5
+ import { parseObjectLiteral, validateLocales, validateLocalesCli } from './validate-locales.ts';
6
6
 
7
7
  function writeBundles(root: string, locale: string, bundle: Record<string, unknown>): string {
8
- const dir = join(root, locale);
8
+ const dir = path.join(root, locale);
9
9
  mkdirSync(dir, { recursive: true });
10
- writeFileSync(join(dir, 'translation.json'), JSON.stringify(bundle), 'utf8');
10
+ writeFileSync(path.join(dir, 'translation.json'), JSON.stringify(bundle), 'utf8');
11
11
  return root;
12
12
  }
13
13
 
@@ -15,7 +15,7 @@ const EN = { common: { unauthorized: 'Unauthorized', forbidden: 'Forbidden' } };
15
15
 
16
16
  describe('validateLocales', () => {
17
17
  it('passes when every locale mirrors the base keys', () => {
18
- const root = mkdtempSync(join(tmpdir(), 'locales-'));
18
+ const root = mkdtempSync(path.join(tmpdir(), 'locales-'));
19
19
  writeBundles(root, 'en', EN);
20
20
  writeBundles(root, 'de', { common: { unauthorized: 'Nicht autorisiert', forbidden: 'Verboten' } });
21
21
  const report = validateLocales(root);
@@ -25,7 +25,7 @@ describe('validateLocales', () => {
25
25
  });
26
26
 
27
27
  it('reports both missing and extra keys', () => {
28
- const root = mkdtempSync(join(tmpdir(), 'locales-'));
28
+ const root = mkdtempSync(path.join(tmpdir(), 'locales-'));
29
29
  writeBundles(root, 'en', EN);
30
30
  writeBundles(root, 'de', { common: { unauthorized: 'x', oops: 'y' } });
31
31
  const problems = validateLocales(root).problems;
@@ -37,38 +37,38 @@ describe('validateLocales', () => {
37
37
 
38
38
  it('reports a missing directory and a missing base locale', () => {
39
39
  expect(validateLocales('/nonexistent-xyz').problems.length).toBeGreaterThan(0);
40
- const root = mkdtempSync(join(tmpdir(), 'locales-'));
40
+ const root = mkdtempSync(path.join(tmpdir(), 'locales-'));
41
41
  writeBundles(root, 'de', EN);
42
42
  expect(validateLocales(root).problems[0]?.problem).toContain('base locale');
43
43
  });
44
44
 
45
45
  it('supports flat <locale>.json bundles', () => {
46
- const root = mkdtempSync(join(tmpdir(), 'locales-'));
47
- writeFileSync(join(root, 'en.json'), JSON.stringify(EN), 'utf8');
48
- writeFileSync(join(root, 'de.json'), JSON.stringify({ common: { unauthorized: 'x', forbidden: 'y' } }), 'utf8');
46
+ const root = mkdtempSync(path.join(tmpdir(), 'locales-'));
47
+ writeFileSync(path.join(root, 'en.json'), JSON.stringify(EN), 'utf8');
48
+ writeFileSync(path.join(root, 'de.json'), JSON.stringify({ common: { unauthorized: 'x', forbidden: 'y' } }), 'utf8');
49
49
  expect(validateLocales(root).problems).toStrictEqual([]);
50
50
  });
51
51
 
52
52
  it('CLI returns 1 with problems and 0 without', () => {
53
- const root = mkdtempSync(join(tmpdir(), 'locales-'));
53
+ const root = mkdtempSync(path.join(tmpdir(), 'locales-'));
54
54
  writeBundles(root, 'en', EN);
55
55
  writeBundles(root, 'de', { common: { unauthorized: 'x' } });
56
56
  expect(validateLocalesCli([root])).toBe(1);
57
- writeFileSync(join(root, 'de', 'translation.json'), JSON.stringify(EN), 'utf8');
57
+ writeFileSync(path.join(root, 'de', 'translation.json'), JSON.stringify(EN), 'utf8');
58
58
  expect(validateLocalesCli([root])).toBe(0);
59
59
  });
60
60
 
61
61
  it('reads the module shape the kit i18n bundles use', () => {
62
62
  // `@rexezuge/i18n` ships `const enStrings: BackendStrings = { … }` per file, so
63
63
  // the same gate covers the backend catalogs and the SPA JSON bundles.
64
- const root = mkdtempSync(join(tmpdir(), 'locales-'));
64
+ const root = mkdtempSync(path.join(tmpdir(), 'locales-'));
65
65
  writeFileSync(
66
- join(root, 'en.ts'),
66
+ path.join(root, 'en.ts'),
67
67
  "import type { BackendStrings } from '../BackendStrings';\n\nconst enStrings: BackendStrings = {\n common: {\n unauthorized: 'Authentication Required.',\n forbidden: 'Access Denied.',\n },\n};\n\nexport { enStrings };\n",
68
68
  'utf8',
69
69
  );
70
70
  writeFileSync(
71
- join(root, 'de.ts'),
71
+ path.join(root, 'de.ts'),
72
72
  "const deStrings = {\n common: {\n unauthorized: 'Authentifizierung Erforderlich.',\n forbidden: 'Zugriff Verweigert.',\n },\n};\n",
73
73
  'utf8',
74
74
  );
@@ -80,7 +80,7 @@ describe('validateLocales', () => {
80
80
  "import type { BackendStrings } from '../BackendStrings';",
81
81
  '',
82
82
  'const enStrings: BackendStrings = {',
83
- " common: { unauthorized: 'It\\'s fine', },",
83
+ String.raw` common: { unauthorized: 'It\'s fine', },`,
84
84
  '};',
85
85
  '',
86
86
  'export { enStrings };',
@@ -89,8 +89,8 @@ describe('validateLocales', () => {
89
89
  });
90
90
 
91
91
  it('reports an unparseable module rather than passing it silently', () => {
92
- const root = mkdtempSync(join(tmpdir(), 'locales-'));
93
- writeFileSync(join(root, 'en.ts'), 'const enStrings = {};\n', 'utf8');
92
+ const root = mkdtempSync(path.join(tmpdir(), 'locales-'));
93
+ writeFileSync(path.join(root, 'en.ts'), 'const enStrings = {};\n', 'utf8');
94
94
  const problems = validateLocales(root).problems;
95
95
  expect(problems[0]?.problem).toMatch(/no keys|object literal/);
96
96
  });
@@ -37,25 +37,33 @@
37
37
  */
38
38
  import { existsSync, readdirSync, readFileSync } from 'node:fs';
39
39
  import { pathToFileURL } from 'node:url';
40
- import { join } from 'node:path';
40
+ import path from 'node:path';
41
41
 
42
- /** The bundle layouts the checker understands. */
42
+ /**
43
+ The bundle layouts the checker understands.
44
+ */
43
45
  type LocaleShape = 'auto' | 'dir' | 'file' | 'module';
44
46
 
45
- /** One defect, kept as a locale plus a message so a caller can group them. */
47
+ /**
48
+ One defect, kept as a locale plus a message so a caller can group them.
49
+ */
46
50
  interface LocaleProblem {
47
51
  locale: string;
48
52
  problem: string;
49
53
  }
50
54
 
51
- /** The outcome of one run. */
55
+ /**
56
+ The outcome of one run.
57
+ */
52
58
  interface LocaleReport {
53
59
  locales: string[];
54
60
  keys: number;
55
61
  problems: LocaleProblem[];
56
62
  }
57
63
 
58
- /** Every dotted key path in a bundle, depth first. */
64
+ /**
65
+ Every dotted key path in a bundle, depth first.
66
+ */
59
67
  function flatten(value: unknown, prefix = ''): string[] {
60
68
  if (value === null || typeof value !== 'object' || Array.isArray(value)) {
61
69
  return prefix ? [prefix] : [];
@@ -73,12 +81,12 @@ function flatten(value: unknown, prefix = ''): string[] {
73
81
  * the module is the point — a validator that imported the bundle would typecheck it
74
82
  * against the kit's own types, and therefore agree with whatever it was given.
75
83
  */
76
- function readBundle(path: string): unknown {
77
- const source = readFileSync(path, 'utf8');
84
+ function readBundle(file: string): unknown {
85
+ const source = readFileSync(file, 'utf8');
78
86
  // Decided by the file's extension, not by the caller's `shape`: under `auto` a
79
87
  // `.ts` bundle is found, and reading it as JSON would report a parse error for a
80
88
  // file that is perfectly well-formed.
81
- return path.endsWith('.ts') ? parseObjectLiteral(source, path) : (JSON.parse(source) as unknown);
89
+ return file.endsWith('.ts') ? parseObjectLiteral(source, file) : (JSON.parse(source) as unknown);
82
90
  }
83
91
 
84
92
  /**
@@ -106,13 +114,13 @@ function objectLiteralStart(source: string): number {
106
114
  let inLineComment = false;
107
115
  let inBlockComment = false;
108
116
  for (let index = 0; index < source.length; index += 1) {
109
- const char = source[index] as string;
110
- const next = source[index + 1];
117
+ const char = source[index];
111
118
 
112
119
  if (inLineComment) {
113
120
  if (char === '\n') inLineComment = false;
114
121
  continue;
115
122
  }
123
+ const next = source[index + 1];
116
124
  if (inBlockComment) {
117
125
  if (char === '*' && next === '/') {
118
126
  inBlockComment = false;
@@ -151,10 +159,10 @@ function objectLiteralStart(source: string): number {
151
159
  return -1;
152
160
  }
153
161
 
154
- function parseObjectLiteral(source: string, path: string): unknown {
162
+ function parseObjectLiteral(source: string, file: string): unknown {
155
163
  const start = objectLiteralStart(source);
156
164
  if (start === -1) {
157
- throw new Error(`${path} has no object literal`);
165
+ throw new Error(`${file} has no object literal`);
158
166
  }
159
167
 
160
168
  let depth = 0;
@@ -163,13 +171,13 @@ function parseObjectLiteral(source: string, path: string): unknown {
163
171
  let inLineComment = false;
164
172
  let inBlockComment = false;
165
173
  for (let index = start; index < source.length; index += 1) {
166
- const char = source[index] as string;
167
- const next = source[index + 1];
174
+ const char = source[index];
168
175
 
169
176
  if (inLineComment) {
170
177
  if (char === '\n') inLineComment = false;
171
178
  continue;
172
179
  }
180
+ const next = source[index + 1];
173
181
  if (inBlockComment) {
174
182
  if (char === '*' && next === '/') {
175
183
  inBlockComment = false;
@@ -209,7 +217,7 @@ function parseObjectLiteral(source: string, path: string): unknown {
209
217
  }
210
218
  }
211
219
  if (end === -1) {
212
- throw new Error(`${path} has an unterminated object literal`);
220
+ throw new Error(`${file} has an unterminated object literal`);
213
221
  }
214
222
 
215
223
  const literal = source.slice(start, end + 1);
@@ -219,17 +227,19 @@ function parseObjectLiteral(source: string, path: string): unknown {
219
227
  // commas are dropped. A translator file that needs more than that is not a
220
228
  // translator file.
221
229
  const doubleQuoted = literal.replaceAll(/'((?:[^'\\]|\\.)*)'/g, (_match, body: string) => JSON.stringify(unescapeLiteral(body)));
222
- const quotedKeys = doubleQuoted.replaceAll(/([{,]\s*)([A-Za-z_$][\w$]*)(\s*:)/g, '$1"$2"$3');
230
+ const quotedKeys = doubleQuoted.replaceAll(/([{,]\s*)([A-Z_$][\w$]*)(\s*:)/gi, '$1"$2"$3');
223
231
  const withoutTrailingCommas = quotedKeys.replaceAll(/,(\s*[}\]])/g, '$1');
224
232
 
225
233
  try {
226
234
  return JSON.parse(withoutTrailingCommas) as unknown;
227
235
  } catch (error: unknown) {
228
- throw new Error(`${path} object literal could not be parsed: ${error instanceof Error ? error.message : String(error)}`);
236
+ throw new Error(`${file} object literal could not be parsed: ${error instanceof Error ? error.message : String(error)}`);
229
237
  }
230
238
  }
231
239
 
232
- /** The escapes a translator file actually uses; anything else is passed through. */
240
+ /**
241
+ The escapes a translator file actually uses; anything else is passed through.
242
+ */
233
243
  function unescapeLiteral(body: string): string {
234
244
  return body
235
245
  .replaceAll(String.raw`\'`, "'")
@@ -239,15 +249,21 @@ function unescapeLiteral(body: string): string {
239
249
  .replaceAll(String.raw`\\`, '\\');
240
250
  }
241
251
 
242
- /** The extensions a flat layout uses, keyed by shape. */
252
+ /**
253
+ The extensions a flat layout uses, keyed by shape.
254
+ */
243
255
  const FLAT_EXTENSION: Record<'file' | 'module', string> = { file: 'json', module: 'ts' };
244
256
 
245
- /** The layouts `shape` covers. `auto` covers all three, in the order they are tried. */
257
+ /**
258
+ The layouts `shape` covers. `auto` covers all three, in the order they are tried.
259
+ */
246
260
  function layouts(shape: LocaleShape): Array<'dir' | 'file' | 'module'> {
247
261
  return shape === 'auto' ? ['dir', 'file', 'module'] : [shape];
248
262
  }
249
263
 
250
- /** The tags on disk, in whichever layouts `shape` covers. */
264
+ /**
265
+ The tags on disk, in whichever layouts `shape` covers.
266
+ */
251
267
  function tagsOnDisk(localesDir: string, shape: LocaleShape): string[] {
252
268
  const tags: string[] = [];
253
269
  if (layouts(shape).includes('dir')) {
@@ -280,11 +296,11 @@ function tagsOnDisk(localesDir: string, shape: LocaleShape): string[] {
280
296
  function bundleFor(localesDir: string, locale: string, shape: LocaleShape): string | undefined {
281
297
  const candidates: string[] = [];
282
298
  if (layouts(shape).includes('dir')) {
283
- candidates.push(join(localesDir, locale, 'translation.json'));
299
+ candidates.push(path.join(localesDir, locale, 'translation.json'));
284
300
  }
285
301
  for (const layout of layouts(shape)) {
286
302
  if (layout === 'dir') continue;
287
- candidates.push(join(localesDir, `${locale}.${FLAT_EXTENSION[layout]}`));
303
+ candidates.push(path.join(localesDir, `${locale}.${FLAT_EXTENSION[layout]}`));
288
304
  }
289
305
  return candidates.find((candidate) => existsSync(candidate));
290
306
  }
@@ -324,7 +340,7 @@ function validateLocales(localesDir: string, baseLocale = 'en', shape: LocaleSha
324
340
  return { locales: [baseLocale], keys: 0, problems };
325
341
  }
326
342
 
327
- const locales = [...new Set([...tagsOnDisk(localesDir, shape), baseLocale])].sort();
343
+ const locales = [...new Set([...tagsOnDisk(localesDir, shape), baseLocale])].sort((a, b) => a.localeCompare(b));
328
344
  for (const locale of locales) {
329
345
  const file = bundleFor(localesDir, locale, shape);
330
346
  if (file === undefined) {
@@ -349,7 +365,9 @@ function validateLocales(localesDir: string, baseLocale = 'en', shape: LocaleSha
349
365
  return { locales, keys: baseKeys.size, problems };
350
366
  }
351
367
 
352
- /** CLI entry: `validateLocalesCli(['[locales-dir]?', '--shape=auto|dir|file|module'?, '--base=<tag>'?])`. */
368
+ /**
369
+ CLI entry: `validateLocalesCli(['[locales-dir]?', '--shape=auto|dir|file|module'?, '--base=<tag>'?])`.
370
+ */
353
371
  function validateLocalesCli(argv: readonly string[] = process.argv.slice(2)): number {
354
372
  const dir = argv.find((arg) => !arg.startsWith('--')) ?? 'apps/web/src/locales';
355
373
  const shape = (argv.find((arg) => arg.startsWith('--shape='))?.slice('--shape='.length) ?? 'auto') as LocaleShape;
@@ -1,13 +1,13 @@
1
- import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { mkdtempSync, readFileSync, 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 } from 'vitest';
5
- import { verifyMigrations, verifyMigrationsCli, LOCK_NAME } from './verify-migrations';
5
+ import { verifyMigrations, verifyMigrationsCli, LOCK_NAME } from './verify-migrations.ts';
6
6
 
7
7
  function tempMigrations(files: Record<string, string>): string {
8
- const root = mkdtempSync(join(tmpdir(), 'migrations-'));
8
+ const root = mkdtempSync(path.join(tmpdir(), 'migrations-'));
9
9
  for (const [name, content] of Object.entries(files)) {
10
- writeFileSync(join(root, name), content, 'utf8');
10
+ writeFileSync(path.join(root, name), content, 'utf8');
11
11
  }
12
12
  return root;
13
13
  }
@@ -33,7 +33,7 @@ describe('verifyMigrations', () => {
33
33
  it('fails when a migration changed after locking', () => {
34
34
  const root = tempMigrations({ '0001_init.sql': ONE });
35
35
  verifyMigrations(root, { write: true });
36
- writeFileSync(join(root, '0001_init.sql'), 'CREATE TABLE changed (id TEXT);', 'utf8');
36
+ writeFileSync(path.join(root, '0001_init.sql'), 'CREATE TABLE changed (id TEXT);', 'utf8');
37
37
  const report = verifyMigrations(root);
38
38
  expect(report.problems.map((problem) => problem.problem).join('\n')).toContain('changed after locking');
39
39
  });
@@ -58,7 +58,7 @@ describe('verifyMigrations', () => {
58
58
  const root = tempMigrations({ '0001_init.sql': ONE, '0002_more.sql': TWO });
59
59
  verifyMigrations(root, { write: true });
60
60
  const { rmSync } = await import('node:fs');
61
- rmSync(join(root, '0002_more.sql'));
61
+ rmSync(path.join(root, '0002_more.sql'));
62
62
  expect(
63
63
  verifyMigrations(root)
64
64
  .problems.map((problem) => problem.problem)
@@ -70,7 +70,7 @@ describe('verifyMigrations', () => {
70
70
  const root = tempMigrations({ '0001_init.sql': ONE });
71
71
  const report = verifyMigrations(root, { write: true });
72
72
  expect(report.problems).toStrictEqual([]);
73
- const lock = JSON.parse(readFileSync(join(root, LOCK_NAME), 'utf8')) as { migrations: { sha256: string }[] };
73
+ const lock = JSON.parse(readFileSync(path.join(root, LOCK_NAME), 'utf8')) as { migrations: { sha256: string }[] };
74
74
  expect(lock.migrations[0]?.sha256).toMatch(/^[a-f0-9]{64}$/);
75
75
  });
76
76