@rexezuge/tooling 1.13.0 → 1.15.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 (138) hide show
  1. package/README.md +67 -34
  2. package/dist/eslint-options.d.ts +54 -0
  3. package/dist/eslint-options.d.ts.map +1 -0
  4. package/dist/eslint-options.js +0 -0
  5. package/dist/eslint-options.js.map +7 -0
  6. package/dist/eslint-rules.d.ts.map +1 -1
  7. package/dist/eslint-rules.js +1 -1
  8. package/dist/eslint-rules.js.map +2 -2
  9. package/dist/eslint-strict.d.ts +2 -1
  10. package/dist/eslint-strict.d.ts.map +1 -1
  11. package/dist/eslint-strict.js +2 -1
  12. package/dist/eslint-strict.js.map +3 -3
  13. package/dist/eslint.d.ts +2 -53
  14. package/dist/eslint.d.ts.map +1 -1
  15. package/dist/eslint.js.map +2 -2
  16. package/dist/manifest-validate.d.ts.map +1 -1
  17. package/dist/manifest-validate.js +1 -1
  18. package/dist/manifest-validate.js.map +3 -3
  19. package/dist/manifest.d.ts +21 -0
  20. package/dist/manifest.d.ts.map +1 -1
  21. package/dist/manifest.js.map +2 -2
  22. package/dist/pages-proxy.d.ts +2 -0
  23. package/dist/pages-proxy.d.ts.map +1 -0
  24. package/dist/pages-proxy.js +1 -0
  25. package/dist/pages-proxy.js.map +7 -0
  26. package/dist/plugin-option.d.ts +15 -0
  27. package/dist/plugin-option.d.ts.map +1 -0
  28. package/dist/plugin-option.js +1 -0
  29. package/dist/plugin-option.js.map +7 -0
  30. package/dist/scripts/backup/destinations.d.ts +40 -0
  31. package/dist/scripts/backup/destinations.d.ts.map +1 -0
  32. package/dist/scripts/backup/destinations.js +1 -0
  33. package/dist/scripts/backup/destinations.js.map +7 -0
  34. package/dist/scripts/backup/encrypt-backup.d.ts +5 -2
  35. package/dist/scripts/backup/encrypt-backup.d.ts.map +1 -1
  36. package/dist/scripts/backup/encrypt-backup.js +2 -3
  37. package/dist/scripts/backup/encrypt-backup.js.map +3 -3
  38. package/dist/scripts/backup/naming.d.ts +1 -1
  39. package/dist/scripts/backup/naming.d.ts.map +1 -1
  40. package/dist/scripts/backup/naming.js +1 -1
  41. package/dist/scripts/backup/naming.js.map +3 -3
  42. package/dist/scripts/ensure-spa-shell-stub.d.ts +4 -2
  43. package/dist/scripts/ensure-spa-shell-stub.d.ts.map +1 -1
  44. package/dist/scripts/ensure-spa-shell-stub.js +1 -2
  45. package/dist/scripts/ensure-spa-shell-stub.js.map +3 -3
  46. package/dist/scripts/init-secrets.d.ts +1 -2
  47. package/dist/scripts/init-secrets.d.ts.map +1 -1
  48. package/dist/scripts/init-secrets.js +2 -3
  49. package/dist/scripts/init-secrets.js.map +3 -3
  50. package/dist/scripts/migrations-lock.d.ts +6 -2
  51. package/dist/scripts/migrations-lock.d.ts.map +1 -1
  52. package/dist/scripts/migrations-lock.js +1 -2
  53. package/dist/scripts/migrations-lock.js.map +3 -3
  54. package/dist/scripts/prepare-wrangler-config.d.ts +6 -2
  55. package/dist/scripts/prepare-wrangler-config.d.ts.map +1 -1
  56. package/dist/scripts/prepare-wrangler-config.js +1 -2
  57. package/dist/scripts/prepare-wrangler-config.js.map +3 -3
  58. package/dist/scripts/validate-locales.d.ts +20 -2
  59. package/dist/scripts/validate-locales.d.ts.map +1 -1
  60. package/dist/scripts/validate-locales.js +5 -5
  61. package/dist/scripts/validate-locales.js.map +3 -3
  62. package/dist/scripts/verify-spa-shell.d.ts +7 -2
  63. package/dist/scripts/verify-spa-shell.d.ts.map +1 -1
  64. package/dist/scripts/verify-spa-shell.js +1 -2
  65. package/dist/scripts/verify-spa-shell.js.map +3 -3
  66. package/dist/scripts/wrangler-config/resources.d.ts +11 -2
  67. package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
  68. package/dist/scripts/wrangler-config/resources.js +1 -1
  69. package/dist/scripts/wrangler-config/resources.js.map +3 -3
  70. package/dist/vite.d.ts +2 -1
  71. package/dist/vite.d.ts.map +1 -1
  72. package/dist/vite.js +3 -3
  73. package/dist/vite.js.map +3 -3
  74. package/dist/vitest-aliases.d.ts +7 -1
  75. package/dist/vitest-aliases.d.ts.map +1 -1
  76. package/dist/vitest-aliases.js +1 -1
  77. package/dist/vitest-aliases.js.map +3 -3
  78. package/dist/vitest-integration.d.ts +3 -2
  79. package/dist/vitest-integration.d.ts.map +1 -1
  80. package/dist/vitest-integration.js +1 -1
  81. package/dist/vitest-integration.js.map +3 -3
  82. package/dist/vitest-repo.d.ts +3 -2
  83. package/dist/vitest-repo.d.ts.map +1 -1
  84. package/dist/vitest-repo.js +1 -1
  85. package/dist/vitest-repo.js.map +3 -3
  86. package/dist/vitest-web.d.ts +3 -2
  87. package/dist/vitest-web.d.ts.map +1 -1
  88. package/dist/vitest-web.js +1 -1
  89. package/dist/vitest-web.js.map +3 -3
  90. package/dist/vitest.d.ts +4 -3
  91. package/dist/vitest.d.ts.map +1 -1
  92. package/dist/vitest.js +1 -1
  93. package/dist/vitest.js.map +3 -3
  94. package/package.json +3 -3
  95. package/presets/tsconfig/web.json +2 -2
  96. package/schema/manifest.schema.json +28 -1
  97. package/src/eslint-options.ts +54 -0
  98. package/src/eslint-rules.ts +4 -0
  99. package/src/eslint-strict.test.ts +29 -0
  100. package/src/eslint-strict.ts +36 -4
  101. package/src/eslint.ts +2 -53
  102. package/src/github/dependabot.yml +14 -4
  103. package/src/github/workflows/backup-d1.yml +15 -0
  104. package/src/github/workflows/backup-main.yml +9 -126
  105. package/src/github/workflows/continuous-deployment.yml +11 -180
  106. package/src/github/workflows/continuous-integration.yml +9 -249
  107. package/src/github/workflows/scheduled-version-update.yml +8 -31
  108. package/src/github/workflows/upstream-sync.yml +8 -49
  109. package/src/manifest-validate.ts +31 -2
  110. package/src/manifest.test.ts +22 -0
  111. package/src/manifest.ts +22 -0
  112. package/src/pages-proxy.test.ts +8 -0
  113. package/src/pages-proxy.ts +13 -0
  114. package/src/plugin-option.test.ts +13 -0
  115. package/src/plugin-option.ts +18 -0
  116. package/src/presets.test.ts +5 -1
  117. package/src/scripts/backup/backup-rules.test.ts +22 -0
  118. package/src/scripts/backup/destinations.ts +59 -0
  119. package/src/scripts/backup/encrypt-backup.ts +58 -48
  120. package/src/scripts/backup/naming.ts +2 -2
  121. package/src/scripts/ensure-spa-shell-stub.ts +18 -10
  122. package/src/scripts/entrypoints.test.ts +55 -0
  123. package/src/scripts/init-secrets.ts +8 -6
  124. package/src/scripts/migrations-lock.ts +22 -17
  125. package/src/scripts/prepare-wrangler-config.ts +34 -14
  126. package/src/scripts/validate-locales.ts +39 -17
  127. package/src/scripts/verify-spa-shell.ts +21 -20
  128. package/src/scripts/wrangler-config/resources.test.ts +10 -0
  129. package/src/scripts/wrangler-config/resources.ts +21 -4
  130. package/src/vite.ts +5 -3
  131. package/src/vitest-aliases.test.ts +33 -0
  132. package/src/vitest-aliases.ts +37 -7
  133. package/src/vitest-integration.ts +7 -8
  134. package/src/vitest-repo.ts +7 -5
  135. package/src/vitest-web.ts +7 -5
  136. package/src/vitest.ts +8 -6
  137. package/src/github/actions/retry-step/action.yml +0 -55
  138. package/src/github/actions/setup-env/action.yml +0 -20
@@ -720,6 +720,42 @@ function validateLocalesCli(argv: readonly string[] = process.argv.slice(2)): nu
720
720
  const callSiteDir = argv.find((arg) => arg.startsWith('--call-sites='))?.slice('--call-sites='.length);
721
721
  const tagsFile = argv.find((arg) => arg.startsWith('--tags='))?.slice('--tags='.length);
722
722
 
723
+ const { report, problems } = collectLocaleProblems({ dir, base, shape, callSiteDir, tagsFile });
724
+ const failures = problems.filter((problem) => problem.advisory !== true);
725
+ const advisories = problems.filter((problem) => problem.advisory === true);
726
+
727
+ if (failures.length > 0) {
728
+ console.error(`Locale validation failed for ${dir} (${failures.length} problem(s)):`);
729
+ for (const problem of failures) console.error(` - ${problem.locale}: ${problem.problem}`);
730
+ return 1;
731
+ }
732
+ if (advisories.length > 0) {
733
+ console.warn(`Locale validation passed for ${dir} with ${advisories.length} advisory finding(s):`);
734
+ for (const problem of advisories) console.warn(` - ${problem.locale}: ${problem.problem}`);
735
+ }
736
+ console.log(`Locale validation passed (${report.locales.length} locales, ${report.keys} keys each, shape ${shape}).`);
737
+ return 0;
738
+ }
739
+
740
+ /**
741
+ What `collectLocaleProblems` checks: the bundles, and optionally the declared tags and the `t()` call sites.
742
+ */
743
+ interface LocaleCheckOptions {
744
+ dir: string;
745
+ base?: string;
746
+ shape?: LocaleShape;
747
+ callSiteDir?: string;
748
+ tagsFile?: string;
749
+ }
750
+
751
+ /**
752
+ * Every finding for one locales directory, as data. The CLI prints it and `rexezuge locales validate --json` serializes it;
753
+ * advisories carry `advisory: true`, everything else is a failure.
754
+ */
755
+ function collectLocaleProblems(options: LocaleCheckOptions): { report: LocaleReport; problems: LocaleProblem[] } {
756
+ const { dir, callSiteDir, tagsFile } = options;
757
+ const base = options.base ?? 'en';
758
+ const shape = options.shape ?? 'auto';
723
759
  const report = validateLocales(dir, base, shape);
724
760
  const problems = [...report.problems];
725
761
 
@@ -744,25 +780,11 @@ function validateLocalesCli(argv: readonly string[] = process.argv.slice(2)): nu
744
780
  problems.push({ locale: 'call-site', problem: `${callSiteDir}: ${error instanceof Error ? error.message : String(error)}` });
745
781
  }
746
782
  }
747
-
748
- const failures = problems.filter((problem) => problem.advisory !== true);
749
- const advisories = problems.filter((problem) => problem.advisory === true);
750
-
751
- if (failures.length > 0) {
752
- console.error(`Locale validation failed for ${dir} (${failures.length} problem(s)):`);
753
- for (const problem of failures) console.error(` - ${problem.locale}: ${problem.problem}`);
754
- return 1;
755
- }
756
- if (advisories.length > 0) {
757
- console.warn(`Locale validation passed for ${dir} with ${advisories.length} advisory finding(s):`);
758
- for (const problem of advisories) console.warn(` - ${problem.locale}: ${problem.problem}`);
759
- }
760
- console.log(`Locale validation passed (${report.locales.length} locales, ${report.keys} keys each, shape ${shape}).`);
761
- return 0;
783
+ return { report, problems };
762
784
  }
763
785
 
764
- export { parseObjectLiteral, validateLocales, validateLocalesCli };
765
- export type { LocaleProblem, LocaleReport, LocaleShape };
786
+ export { collectLocaleProblems, parseObjectLiteral, validateLocales, validateLocalesCli };
787
+ export type { LocaleCheckOptions, LocaleProblem, LocaleReport, LocaleShape };
766
788
 
767
789
  // Run only when this file is the entrypoint.
768
790
  //
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env tsx
2
1
  /**
3
2
  * Fail when the SPA shell the API worker serves is missing or self-inconsistent.
4
3
  *
@@ -31,28 +30,30 @@
31
30
  */
32
31
  import path from 'node:path';
33
32
  import { fileURLToPath } from 'node:url';
33
+ import { isEntrypoint } from './lib/entrypoint.ts';
34
34
  import { verifySpaShell } from './spa-shell.ts';
35
35
 
36
36
  /**
37
- * The repository root, derived from this file rather than from `process.cwd()`.
38
- *
39
- * Two levels up, because this file sits in `scripts/`. Deriving it means the gate
40
- * reads the same tree whatever directory it is invoked from — which is the
41
- * difference between a gate and a gate that passes because nobody ran it from the
42
- * right place.
37
+ * Verify the shell. `args[0]` is the repo root, derived from this file when absent
38
+ * rather than from `process.cwd()`: the gate reads the same tree whatever directory
39
+ * it is invoked from, which is the difference between a gate and a gate that passes
40
+ * because nobody ran it from the right place. Returns the exit code.
43
41
  */
44
- const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
45
-
46
- const root = process.argv[2] === undefined ? REPOSITORY_ROOT : path.resolve(process.argv[2]);
47
-
48
- const { problems } = verifySpaShell({ root });
49
-
50
- if (problems.length > 0) {
51
- console.error('SPA shell check failed:');
52
- for (const problem of problems) console.error(` - ${problem}`);
53
- process.exit(1);
42
+ export function main(args: readonly string[] = process.argv.slice(2)): number {
43
+ const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
44
+ const root = args[0] === undefined ? repositoryRoot : path.resolve(args[0]);
45
+ const { problems } = verifySpaShell({ root });
46
+ if (problems.length > 0) {
47
+ console.error('SPA shell check failed:');
48
+ for (const problem of problems) console.error(` - ${problem}`);
49
+ return 1;
50
+ }
51
+ console.log(
52
+ `SPA shell check passed (${path.join(root, 'apps/api/src/generated/spa-shell.ts')} matches ${path.join(root, 'apps/web/dist')}).`,
53
+ );
54
+ return 0;
54
55
  }
55
56
 
56
- console.log(
57
- `SPA shell check passed (${path.join(root, 'apps/api/src/generated/spa-shell.ts')} matches ${path.join(root, 'apps/web/dist')}).`,
58
- );
57
+ if (isEntrypoint(import.meta.url)) {
58
+ process.exit(main());
59
+ }
@@ -41,6 +41,16 @@ describe('ensureRequiredKvBindings', () => {
41
41
  expect(bindings).toEqual(['RECORD_CACHE']);
42
42
  });
43
43
 
44
+ it('adds no binding when the manifest declares none (no phantom CACHE)', () => {
45
+ const content = '{\n "kv_namespaces": []\n}';
46
+ expect(ensureRequiredKvBindings(content, { kv_namespaces: [] }, {}, [])).toBe(content);
47
+ });
48
+
49
+ it('adds the manifest-declared bindings, namespace names or not', () => {
50
+ const patched = ensureRequiredKvBindings('{\n "kv_namespaces": []\n}', { kv_namespaces: [] }, {}, ['SESSIONS']);
51
+ expect((JSON.parse(patched) as WranglerConfig).kv_namespaces?.map((namespace) => namespace.binding)).toEqual(['SESSIONS']);
52
+ });
53
+
44
54
  it('adds the default binding when no map is given', () => {
45
55
  const patched = ensureRequiredKvBindings('{\n "kv_namespaces": []\n}', { kv_namespaces: [] });
46
56
  const bindings = (JSON.parse(patched) as WranglerConfig).kv_namespaces?.map((namespace) => namespace.binding);
@@ -79,6 +79,7 @@ export function listKVNamespaces(): KVNamespace[] {
79
79
  /**
80
80
  * The namespace name a binding's namespace is created under.
81
81
  *
82
+ * Takes either {@link ProvisionOptions} or (legacy) the bare binding → namespace map. `requiredKvBindings` defaults to the map's keys.
82
83
  * `namespaceNames` is the binding → namespace map, defaulting to the kit's
83
84
  * `DEFAULT_KV_NAMESPACE_NAMES`. A consumer whose namespaces predate that convention
84
85
  * passes its own, so provisioning finds the namespace that already holds the data
@@ -123,6 +124,15 @@ export function getRequiredKvBindings(namespaceNames: Record<string, string> = D
123
124
  return Object.keys(namespaceNames);
124
125
  }
125
126
 
127
+ /**
128
+ What `prepare-wrangler` provisions beyond the placeholders a config already carries: the manifest-declared KV bindings
129
+ (`features.kv`). Nothing declared means no KV binding is added.
130
+ */
131
+ export interface ProvisionOptions {
132
+ readonly namespaceNames?: Record<string, string>;
133
+ readonly requiredKvBindings?: readonly string[];
134
+ }
135
+
126
136
  /**
127
137
  * Add the always-needed KV bindings a hand-written config left out.
128
138
  *
@@ -133,9 +143,10 @@ export function ensureRequiredKvBindings(
133
143
  content: string,
134
144
  config: WranglerConfig,
135
145
  namespaceNames: Record<string, string> = DEFAULT_KV_NAMESPACE_NAMES,
146
+ requiredBindings: readonly string[] = getRequiredKvBindings(namespaceNames),
136
147
  ): string {
137
148
  const existing = new Set((config.kv_namespaces ?? []).map((namespace) => namespace.binding).filter((binding) => binding !== undefined));
138
- const missing = getRequiredKvBindings(namespaceNames).filter((binding) => !existing.has(binding));
149
+ const missing = requiredBindings.filter((binding) => !existing.has(binding));
139
150
  if (missing.length === 0) {
140
151
  return content;
141
152
  }
@@ -315,6 +326,10 @@ function provisionSecretStore(content: string, config: WranglerConfig, created:
315
326
  );
316
327
  }
317
328
 
329
+ function isProvisionOptions(value: ProvisionOptions | Record<string, string>): value is ProvisionOptions {
330
+ return 'namespaceNames' in value || 'requiredKvBindings' in value;
331
+ }
332
+
318
333
  /**
319
334
  * Create every resource the config names, and write the real ids over the
320
335
  * placeholders.
@@ -329,11 +344,13 @@ function provisionSecretStore(content: string, config: WranglerConfig, created:
329
344
  * that appears here, since one created moments ago holds no user data and an empty
330
345
  * dump uploaded on schedule is a false sense of safety.
331
346
  */
332
- export function provisionWranglerResources(namespaceNames: Record<string, string> = DEFAULT_KV_NAMESPACE_NAMES): string[] {
347
+ export function provisionWranglerResources(options: ProvisionOptions | Record<string, string> = DEFAULT_KV_NAMESPACE_NAMES): string[] {
348
+ const { namespaceNames, requiredKvBindings }: ProvisionOptions = isProvisionOptions(options) ? options : { namespaceNames: options };
349
+ const names = namespaceNames ?? {};
333
350
  const created: string[] = [];
334
351
  let { content, config } = readConfig();
335
352
 
336
- content = ensureRequiredKvBindings(content, config, namespaceNames);
353
+ content = ensureRequiredKvBindings(content, config, names, requiredKvBindings ?? getRequiredKvBindings(names));
337
354
  config = parse(content) as WranglerConfig;
338
355
 
339
356
  // Each of the three below re-parses before it patches, because each writes into
@@ -344,7 +361,7 @@ export function provisionWranglerResources(namespaceNames: Record<string, string
344
361
  content = provisionD1Databases(content, config, created);
345
362
  config = parse(content) as WranglerConfig;
346
363
 
347
- content = provisionKvNamespaces(content, config, created, namespaceNames);
364
+ content = provisionKvNamespaces(content, config, created, names);
348
365
  config = parse(content) as WranglerConfig;
349
366
 
350
367
  content = provisionSecretStore(content, config, created);
package/src/vite.ts CHANGED
@@ -33,6 +33,8 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
33
33
  import path from 'node:path';
34
34
  import { fileURLToPath, pathToFileURL } from 'node:url';
35
35
  import { defineConfig, type Plugin, type ViteUserConfig } from 'vitest/config';
36
+ import { asVitePlugins } from './plugin-option.ts';
37
+ import type { PluginOption } from './plugin-option.ts';
36
38
 
37
39
  /**
38
40
  * One dev-server proxy entry, as Vite's `server.proxy` accepts it.
@@ -104,7 +106,7 @@ export interface WebViteConfigOptions {
104
106
  * needs. Applied before the spa-shell plugin so the shell is written after the
105
107
  * bundle exists.
106
108
  */
107
- readonly plugins?: readonly Plugin[];
109
+ readonly plugins?: readonly PluginOption[];
108
110
  /**
109
111
  * Dev-server proxy entries. Keyed by path prefix.
110
112
  */
@@ -236,13 +238,13 @@ export function spaShellEmbedPlugin(target: SpaShellTarget): Plugin & { closeBun
236
238
  * ```
237
239
  */
238
240
  export function defineWebViteConfig(options: WebViteConfigOptions = {}): ViteUserConfig {
239
- const plugins: Plugin[] = [...(options.plugins ?? [])];
241
+ const plugins: PluginOption[] = [...(options.plugins ?? [])];
240
242
  if (options.spaShell !== undefined) {
241
243
  plugins.push(spaShellEmbedPlugin(options.spaShell));
242
244
  }
243
245
 
244
246
  return defineConfig({
245
- ...(plugins.length > 0 && { plugins }),
247
+ ...(plugins.length > 0 && { plugins: asVitePlugins(plugins) }),
246
248
  ...(options.proxy !== undefined && { server: { proxy: { ...options.proxy } } }),
247
249
  build: {
248
250
  outDir: options.outDir ?? 'dist',
@@ -54,6 +54,39 @@ describe('workspaceAliases', () => {
54
54
  expect(sockets?.replacement).toMatch(/test[/\\]mocks[/\\]cloudflare-sockets\.ts$/);
55
55
  });
56
56
 
57
+ it('includes the shared contracts package by default', () => {
58
+ expect(DEFAULT_WORKSPACE_PACKAGES).toContain('contracts');
59
+ expect(finds(workspaceAliases({ scope: '@fixture', root: ROOT }))).toContain('@fixture/contracts');
60
+ });
61
+
62
+ it('derives the aliases from the manifest layers when there is one, and lets explicit packages win', () => {
63
+ const dir = mkdtempSync(path.join(tmpdir(), 'aliases-manifest-'));
64
+ const root = pathToFileURL(`${dir}/`).href;
65
+ writeFileSync(
66
+ path.join(dir, '.rexezuge.jsonc'),
67
+ JSON.stringify({
68
+ name: 'demo',
69
+ scope: '@fixture',
70
+ layers: [
71
+ { name: 'contracts', dir: 'packages/contracts', mayImport: [] },
72
+ { name: 'core', dir: 'packages/backend-core', package: 'core', mayImport: [] },
73
+ { name: 'web', dir: 'apps/web', mayImport: [] },
74
+ ],
75
+ }),
76
+ );
77
+ const byFind = new Map(
78
+ workspaceAliases({ scope: '@fixture', root, mocks: [] }).map((alias) => [String(alias.find), alias.replacement]),
79
+ );
80
+ expect(byFind.get('@fixture/contracts')).toBe(path.join(dir, 'packages/contracts/src'));
81
+ expect(byFind.get('@fixture/core')).toBe(path.join(dir, 'packages/backend-core/src'));
82
+ expect(byFind.get('@fixture/web')).toBe(path.join(dir, 'apps/web/src'));
83
+ expect(byFind.has('@fixture/shared')).toBe(false); // not a layer of this repo
84
+ expect(finds(workspaceAliases({ scope: '@fixture', root, packages: ['shared'], mocks: [] }))).toContain('@fixture/shared');
85
+ writeFileSync(path.join(dir, '.rexezuge.jsonc'), '{ "name": 1 }');
86
+ expect(finds(workspaceAliases({ scope: '@fixture', root, mocks: [] }))).toContain('@fixture/shared'); // invalid manifest: family list
87
+ rmSync(dir, { recursive: true, force: true });
88
+ });
89
+
57
90
  it('lets a repo narrow the package and mock sets', () => {
58
91
  const aliases = workspaceAliases({ scope: '@fixture', root: ROOT, packages: ['shared'], mocks: ['workers'] });
59
92
  expect(finds(aliases)).toContain('@fixture/shared');
@@ -1,6 +1,8 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { createRequire } from 'node:module';
3
+ import path from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
5
+ import { loadManifest } from './manifest.ts';
4
6
 
5
7
  /**
6
8
  * One `{ find, replacement }` pair for Vitest's resolver.
@@ -27,12 +29,17 @@ export interface VitestAlias {
27
29
  * source repo, so they are not listed — a repo that needs them passes
28
30
  * `packages` explicitly or appends `aliases`.
29
31
  *
32
+ * `contracts` is the shared endpoint-contracts package the API and the SPA both import. A repo with a manifest
33
+ * that declares `layers` does not use this list at all: its aliases come from `layers[].package` / `dir`
34
+ * (see {@link WorkspaceAliasesOptions.packages}).
35
+ *
30
36
  * A superset is safe: an alias for a package the consumer does not have never
31
37
  * matches a specifier, and Vite only resolves the replacement when something
32
38
  * imports it.
33
39
  */
34
40
  export const DEFAULT_WORKSPACE_PACKAGES: readonly string[] = [
35
41
  'shared',
42
+ 'contracts',
36
43
  'backend-errors',
37
44
  'backend-runtime',
38
45
  'backend-data',
@@ -102,7 +109,9 @@ export interface WorkspaceAliasesOptions {
102
109
  readonly root: string;
103
110
  /**
104
111
  * Workspace package directory names under `packages/` plus `background`
105
- * (which lives under `apps/`). Defaults to {@link DEFAULT_WORKSPACE_PACKAGES}.
112
+ * (which lives under `apps/`). When omitted: the manifest's `layers` if `<root>/.rexezuge.jsonc` declares any
113
+ * (each layer `dir` is aliased as `<scope>/<package or basename of dir>`), else {@link DEFAULT_WORKSPACE_PACKAGES}.
114
+ * An explicit list always wins.
106
115
  */
107
116
  readonly packages?: readonly string[];
108
117
  /**
@@ -127,6 +136,28 @@ function kitWorkersMock(): string | null {
127
136
  }
128
137
  }
129
138
 
139
+ interface AliasTarget {
140
+ readonly find: string;
141
+ readonly dir: string;
142
+ }
143
+
144
+ /**
145
+ * The manifest's layers as alias targets, or `null` when there is no readable manifest with layers.
146
+ */
147
+ function manifestTargets(scope: string, root: string): AliasTarget[] | null {
148
+ try {
149
+ const layers = loadManifest(fileURLToPath(root))?.layers;
150
+ if (layers === undefined || layers.length === 0) return null;
151
+ return layers.map((layer) => ({ find: `${scope}/${layer.package ?? path.posix.basename(layer.dir)}`, dir: `${layer.dir}/src` }));
152
+ } catch {
153
+ return null; // an invalid manifest is doctor's to report; the aliases fall back to the family list
154
+ }
155
+ }
156
+
157
+ function defaultTargets(scope: string, names: readonly string[]): AliasTarget[] {
158
+ return names.map((name) => ({ find: `${scope}/${name}`, dir: name === 'background' ? 'apps/background/src' : `packages/${name}/src` }));
159
+ }
160
+
130
161
  /**
131
162
  * Build the workspace alias table for a consumer repo.
132
163
  *
@@ -141,14 +172,13 @@ function kitWorkersMock(): string | null {
141
172
  */
142
173
  export function workspaceAliases(options: WorkspaceAliasesOptions): VitestAlias[] {
143
174
  const { scope, root } = options;
144
- const packages = options.packages ?? DEFAULT_WORKSPACE_PACKAGES;
175
+ const targets =
176
+ options.packages === undefined
177
+ ? (manifestTargets(scope, root) ?? defaultTargets(scope, DEFAULT_WORKSPACE_PACKAGES))
178
+ : defaultTargets(scope, options.packages);
145
179
  const mocks = options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS;
146
180
  const at = (relative: string): string => fileURLToPath(new URL(relative, root));
147
- const aliases: VitestAlias[] = [];
148
- for (const name of packages) {
149
- const dir = name === 'background' ? 'apps/background/src' : `packages/${name}/src`;
150
- aliases.push({ find: `${scope}/${name}`, replacement: at(dir) });
151
- }
181
+ const aliases: VitestAlias[] = Array.from(targets, (target) => ({ find: target.find, replacement: at(target.dir) }));
152
182
  for (const mock of mocks) {
153
183
  const local = at(`test/mocks/cloudflare-${mock}.ts`);
154
184
  // A repo with no copy of its own gets the kit's: the `workers` mock is a
@@ -17,9 +17,11 @@
17
17
  * `node:sqlite`, no coverage); the workerd suites pass all three.
18
18
  */
19
19
 
20
- import { defineConfig, type Plugin } from 'vitest/config';
20
+ import { defineConfig } from 'vitest/config';
21
+ import { asVitePlugins } from './plugin-option.ts';
22
+ import type { PluginOption } from './plugin-option.ts';
21
23
  import type { Pool } from 'vitest/node';
22
- import { DEFAULT_WORKSPACE_PACKAGES, workspaceAliases } from './vitest-aliases.ts';
24
+ import { workspaceAliases } from './vitest-aliases.ts';
23
25
  import type { VitestAlias } from './vitest-aliases.ts';
24
26
 
25
27
  /**
@@ -54,7 +56,7 @@ export interface IntegrationVitestConfigOptions {
54
56
  * runner's own plugin so a workerd plugin is accepted and nothing new is
55
57
  * imported — this package stays dependency-free.
56
58
  */
57
- readonly plugins?: readonly Plugin[];
59
+ readonly plugins?: readonly PluginOption[];
58
60
  /**
59
61
  * The pool (the workerd `cloudflarePool()`). The runner's own `Pool` type,
60
62
  * so a custom pool is accepted without importing its provider.
@@ -98,14 +100,11 @@ export interface IntegrationVitestConfigOptions {
98
100
  */
99
101
  export function defineIntegrationVitestConfig(options: IntegrationVitestConfigOptions): ReturnType<typeof defineConfig> {
100
102
  const root = options.root ?? new URL('.', import.meta.url).href;
101
- const aliases = [
102
- ...workspaceAliases({ scope: options.scope, root, packages: options.packages ?? DEFAULT_WORKSPACE_PACKAGES, mocks: [] }),
103
- ...(options.aliases ?? []),
104
- ];
103
+ const aliases = [...workspaceAliases({ scope: options.scope, root, packages: options.packages, mocks: [] }), ...(options.aliases ?? [])];
105
104
 
106
105
  return defineConfig({
107
106
  ...(options.define !== undefined && { define: { ...options.define } }),
108
- ...(options.plugins !== undefined && { plugins: [...options.plugins] }),
107
+ ...(options.plugins !== undefined && { plugins: asVitePlugins(options.plugins) }),
109
108
  resolve: { alias: aliases },
110
109
  test: {
111
110
  globals: true,
@@ -23,10 +23,12 @@
23
23
  * 'node'` and `server.deps.inline` from `defineUnitVitestConfig()`.
24
24
  */
25
25
 
26
- import { defineConfig, type Plugin } from 'vitest/config';
26
+ import { defineConfig } from 'vitest/config';
27
+ import { asVitePlugins } from './plugin-option.ts';
28
+ import type { PluginOption } from './plugin-option.ts';
27
29
  import { fileURLToPath } from 'node:url';
28
30
  import { manifestCoverageThresholds } from './manifest.ts';
29
- import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
31
+ import { DEFAULT_CLOUDFLARE_MOCKS, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
30
32
  import type { VitestAlias } from './vitest-aliases.ts';
31
33
  import type { CoverageThresholds } from './vitest.ts';
32
34
 
@@ -81,7 +83,7 @@ export interface RepoWebOptions {
81
83
  /**
82
84
  * Vite plugins the SPA needs (`react()` for JSX).
83
85
  */
84
- readonly plugins?: readonly Plugin[];
86
+ readonly plugins?: readonly PluginOption[];
85
87
  /**
86
88
  * Extra resolver entries for the web project only.
87
89
  */
@@ -209,7 +211,7 @@ const INDEX_BARREL_EXCLUDE = '**/index.ts';
209
211
  export function defineRepoVitestConfig(options: RepoVitestConfigOptions): ReturnType<typeof defineConfig> {
210
212
  const root = options.root ?? new URL('.', import.meta.url).href;
211
213
  const thresholds = options.thresholds ?? manifestCoverageThresholds(root);
212
- const packages = options.packages ?? DEFAULT_WORKSPACE_PACKAGES;
214
+ const packages = options.packages;
213
215
  const mocks = options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS;
214
216
  const noExternal = [...KIT_NO_EXTERNAL, ...(options.noExternal ?? [])];
215
217
  const backend = options.backend ?? {};
@@ -250,7 +252,7 @@ export function defineRepoVitestConfig(options: RepoVitestConfigOptions): Return
250
252
  },
251
253
  },
252
254
  {
253
- ...(web.plugins !== undefined && { plugins: [...web.plugins] }),
255
+ ...(web.plugins !== undefined && { plugins: asVitePlugins(web.plugins) }),
254
256
  resolve: { alias: webAliases, noExternal },
255
257
  test: {
256
258
  name: 'web',
package/src/vitest-web.ts CHANGED
@@ -39,9 +39,11 @@
39
39
  * packages, so web tests reach shared logic the same way backend tests do.
40
40
  */
41
41
 
42
- import { defineConfig, type Plugin } from 'vitest/config';
42
+ import { defineConfig } from 'vitest/config';
43
+ import { asVitePlugins } from './plugin-option.ts';
44
+ import type { PluginOption } from './plugin-option.ts';
43
45
  import { fileURLToPath } from 'node:url';
44
- import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
46
+ import { DEFAULT_CLOUDFLARE_MOCKS, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
45
47
  import type { VitestAlias } from './vitest-aliases.ts';
46
48
  import type { CoverageThresholds } from './vitest.ts';
47
49
 
@@ -68,7 +70,7 @@ export interface WebVitestConfigOptions {
68
70
  * by the consumer rather than imported here, because the kit must stay
69
71
  * zero-dependency and the plugin belongs to the app, not the harness.
70
72
  */
71
- readonly plugins?: readonly Plugin[];
73
+ readonly plugins?: readonly PluginOption[];
72
74
  /**
73
75
  * Extra resolver entries, applied after the canonical ones.
74
76
  */
@@ -152,7 +154,7 @@ export function defineWebVitestConfig(options: WebVitestConfigOptions = {}): Ret
152
154
  const scopePart = workspaceAliases({
153
155
  scope: options.scope ?? '@unused',
154
156
  root,
155
- packages: options.packages ?? DEFAULT_WORKSPACE_PACKAGES,
157
+ packages: options.packages,
156
158
  mocks: options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS,
157
159
  }).filter((alias) => typeof alias.find === 'string' && !alias.find.startsWith('@unused'));
158
160
  const aliases: VitestAlias[] = [
@@ -163,7 +165,7 @@ export function defineWebVitestConfig(options: WebVitestConfigOptions = {}): Ret
163
165
  ];
164
166
 
165
167
  return defineConfig({
166
- ...(options.plugins !== undefined && { plugins: [...options.plugins] }),
168
+ ...(options.plugins !== undefined && { plugins: asVitePlugins(options.plugins) }),
167
169
  resolve: { alias: aliases, noExternal: [...KIT_NO_EXTERNAL, ...(options.noExternal ?? [])] },
168
170
  test: {
169
171
  globals: true,
package/src/vitest.ts CHANGED
@@ -33,9 +33,11 @@
33
33
  * resolver that bundles the worker).
34
34
  */
35
35
 
36
- import { defineConfig, type Plugin } from 'vitest/config';
36
+ import { defineConfig } from 'vitest/config';
37
+ import { asVitePlugins } from './plugin-option.ts';
38
+ import type { PluginOption } from './plugin-option.ts';
37
39
  import { manifestCoverageThresholds } from './manifest.ts';
38
- import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_DEDUPE, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
40
+ import { DEFAULT_CLOUDFLARE_MOCKS, KIT_DEDUPE, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
39
41
  import type { VitestAlias } from './vitest-aliases.ts';
40
42
 
41
43
  export type { VitestAlias } from './vitest-aliases.ts';
@@ -45,7 +47,7 @@ export type { VitestAlias } from './vitest-aliases.ts';
45
47
  // kit's components. Exporting it only from the root meant that import failed with
46
48
  // `does not provide an export named 'KIT_DEDUPE'` at config-load time, which is a
47
49
  // build failure before any test runs and no error that names the install.
48
- export { KIT_DEDUPE, KIT_NO_EXTERNAL } from './vitest-aliases.ts';
50
+ export { DEFAULT_WORKSPACE_PACKAGES, KIT_DEDUPE, KIT_NO_EXTERNAL } from './vitest-aliases.ts';
49
51
 
50
52
  /**
51
53
  * Coverage thresholds, in the four figures Vitest gates on.
@@ -116,7 +118,7 @@ export interface UnitVitestConfigOptions {
116
118
  * Vite plugins for the suite (rare on the backend half; the SPA half passes
117
119
  * `react()` here).
118
120
  */
119
- readonly plugins?: readonly Plugin[];
121
+ readonly plugins?: readonly PluginOption[];
120
122
  /**
121
123
  * Setup files run before each test file (e.g. AWS's floci guard, Meow's
122
124
  * backend/web setups).
@@ -228,7 +230,7 @@ export function defineUnitVitestConfig(options: UnitVitestConfigOptions = {}): R
228
230
  const baseAliases = workspaceAliases({
229
231
  scope: options.scope ?? '@unused',
230
232
  root,
231
- packages: options.scope === undefined ? [] : (options.packages ?? DEFAULT_WORKSPACE_PACKAGES),
233
+ packages: options.scope === undefined ? [] : options.packages,
232
234
  mocks: options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS,
233
235
  });
234
236
  // A placeholder scope contributes no `@unused/*` entries; the mocks plus
@@ -239,7 +241,7 @@ export function defineUnitVitestConfig(options: UnitVitestConfigOptions = {}): R
239
241
  ];
240
242
 
241
243
  return defineConfig({
242
- ...(options.plugins !== undefined && { plugins: [...options.plugins] }),
244
+ ...(options.plugins !== undefined && { plugins: asVitePlugins(options.plugins) }),
243
245
  resolve: {
244
246
  alias: aliases,
245
247
  noExternal: [...KIT_NO_EXTERNAL, ...(options.noExternal ?? [])],
@@ -1,55 +0,0 @@
1
- name: Retry Step
2
- description: Retry a bash command on failure
3
-
4
- inputs:
5
- command:
6
- description: The bash command to run
7
- required: true
8
- max_attempts:
9
- description: Maximum number of attempts
10
- required: false
11
- default: '3'
12
- delay:
13
- description: Seconds to wait between attempts
14
- required: false
15
- default: '10'
16
-
17
- runs:
18
- using: composite
19
- steps:
20
- - shell: bash
21
- run: |
22
- attempt=0
23
- max="$RETRY_MAX_ATTEMPTS"
24
- delay="$RETRY_DELAY"
25
- case "$max" in ''|*[!0-9]*)
26
- printf '::error title=Retry Step::max_attempts must be a positive integer\n'
27
- exit 1
28
- ;;
29
- esac
30
- if [ "$max" -lt 1 ]; then
31
- printf '::error title=Retry Step::max_attempts must be a positive integer\n'
32
- exit 1
33
- fi
34
- case "$delay" in ''|*[!0-9]*)
35
- printf '::error title=Retry Step::delay must be a non-negative integer\n'
36
- exit 1
37
- ;;
38
- esac
39
- while true; do
40
- attempt=$(( attempt + 1 ))
41
- printf '::notice title=Retry Step::Attempt %d of %d\n' "$attempt" "$max"
42
- if eval "$RETRY_COMMAND"; then
43
- exit 0
44
- fi
45
- if [ "$attempt" -ge "$max" ]; then
46
- printf '::error title=Retry Step::Command failed after %d attempts\n' "$max"
47
- exit 1
48
- fi
49
- printf '::warning title=Retry Step::Command failed, retrying in %ds...\n' "$delay"
50
- sleep "$delay"
51
- done
52
- env:
53
- RETRY_COMMAND: ${{ inputs.command }}
54
- RETRY_MAX_ATTEMPTS: ${{ inputs.max_attempts }}
55
- RETRY_DELAY: ${{ inputs.delay }}
@@ -1,20 +0,0 @@
1
- name: Setup Environment
2
- description: Install pnpm, set up Node.js with pnpm store cache, and install workspace dependencies
3
-
4
- runs:
5
- using: composite
6
- steps:
7
- - name: Install pnpm
8
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4
9
-
10
- - name: Setup Node.js
11
- uses: actions/setup-node@v4
12
- with:
13
- node-version: '24'
14
- cache: pnpm
15
-
16
- - name: Install Dependencies
17
- uses: ./.github/actions/retry-step
18
- with:
19
- command: pnpm install
20
- max_attempts: '3'