@rexezuge/tooling 1.14.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 (80) hide show
  1. package/README.md +42 -30
  2. package/dist/eslint-rules.d.ts.map +1 -1
  3. package/dist/eslint-rules.js +1 -1
  4. package/dist/eslint-rules.js.map +2 -2
  5. package/dist/eslint-strict.d.ts +2 -1
  6. package/dist/eslint-strict.d.ts.map +1 -1
  7. package/dist/eslint-strict.js +2 -1
  8. package/dist/eslint-strict.js.map +3 -3
  9. package/dist/manifest-validate.d.ts.map +1 -1
  10. package/dist/manifest-validate.js +1 -1
  11. package/dist/manifest-validate.js.map +3 -3
  12. package/dist/manifest.d.ts +21 -0
  13. package/dist/manifest.d.ts.map +1 -1
  14. package/dist/manifest.js.map +2 -2
  15. package/dist/scripts/backup/destinations.d.ts +40 -0
  16. package/dist/scripts/backup/destinations.d.ts.map +1 -0
  17. package/dist/scripts/backup/destinations.js +1 -0
  18. package/dist/scripts/backup/destinations.js.map +7 -0
  19. package/dist/scripts/backup/encrypt-backup.d.ts +5 -2
  20. package/dist/scripts/backup/encrypt-backup.d.ts.map +1 -1
  21. package/dist/scripts/backup/encrypt-backup.js +2 -3
  22. package/dist/scripts/backup/encrypt-backup.js.map +3 -3
  23. package/dist/scripts/backup/naming.d.ts +1 -1
  24. package/dist/scripts/backup/naming.d.ts.map +1 -1
  25. package/dist/scripts/backup/naming.js +1 -1
  26. package/dist/scripts/backup/naming.js.map +3 -3
  27. package/dist/scripts/prepare-wrangler-config.d.ts.map +1 -1
  28. package/dist/scripts/prepare-wrangler-config.js +1 -1
  29. package/dist/scripts/prepare-wrangler-config.js.map +3 -3
  30. package/dist/scripts/wrangler-config/resources.d.ts +11 -2
  31. package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
  32. package/dist/scripts/wrangler-config/resources.js +1 -1
  33. package/dist/scripts/wrangler-config/resources.js.map +3 -3
  34. package/dist/vitest-aliases.d.ts +7 -1
  35. package/dist/vitest-aliases.d.ts.map +1 -1
  36. package/dist/vitest-aliases.js +1 -1
  37. package/dist/vitest-aliases.js.map +3 -3
  38. package/dist/vitest-integration.d.ts.map +1 -1
  39. package/dist/vitest-integration.js +1 -1
  40. package/dist/vitest-integration.js.map +3 -3
  41. package/dist/vitest-repo.js +1 -1
  42. package/dist/vitest-repo.js.map +3 -3
  43. package/dist/vitest-web.js +1 -1
  44. package/dist/vitest-web.js.map +3 -3
  45. package/dist/vitest.d.ts +1 -1
  46. package/dist/vitest.d.ts.map +1 -1
  47. package/dist/vitest.js +1 -1
  48. package/dist/vitest.js.map +3 -3
  49. package/package.json +3 -3
  50. package/presets/tsconfig/web.json +2 -2
  51. package/schema/manifest.schema.json +28 -1
  52. package/src/eslint-rules.ts +4 -0
  53. package/src/eslint-strict.test.ts +29 -0
  54. package/src/eslint-strict.ts +36 -4
  55. package/src/github/dependabot.yml +14 -4
  56. package/src/github/workflows/backup-d1.yml +15 -0
  57. package/src/github/workflows/backup-main.yml +9 -126
  58. package/src/github/workflows/continuous-deployment.yml +11 -180
  59. package/src/github/workflows/continuous-integration.yml +9 -249
  60. package/src/github/workflows/scheduled-version-update.yml +8 -31
  61. package/src/github/workflows/upstream-sync.yml +8 -49
  62. package/src/manifest-validate.ts +31 -2
  63. package/src/manifest.test.ts +22 -0
  64. package/src/manifest.ts +22 -0
  65. package/src/presets.test.ts +5 -1
  66. package/src/scripts/backup/backup-rules.test.ts +22 -0
  67. package/src/scripts/backup/destinations.ts +59 -0
  68. package/src/scripts/backup/encrypt-backup.ts +58 -48
  69. package/src/scripts/backup/naming.ts +2 -2
  70. package/src/scripts/prepare-wrangler-config.ts +9 -1
  71. package/src/scripts/wrangler-config/resources.test.ts +10 -0
  72. package/src/scripts/wrangler-config/resources.ts +21 -4
  73. package/src/vitest-aliases.test.ts +33 -0
  74. package/src/vitest-aliases.ts +37 -7
  75. package/src/vitest-integration.ts +2 -5
  76. package/src/vitest-repo.ts +2 -2
  77. package/src/vitest-web.ts +2 -2
  78. package/src/vitest.ts +3 -3
  79. package/src/github/actions/retry-step/action.yml +0 -55
  80. package/src/github/actions/setup-env/action.yml +0 -20
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env tsx
2
1
  /**
3
2
  * Compress and encrypt the exported D1 dump.
4
3
  *
@@ -37,6 +36,7 @@ import { execFileSync } from 'node:child_process';
37
36
  import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
38
37
  import path from 'node:path';
39
38
  import { fail, setOutput } from '../lib/github-actions.ts';
39
+ import { isEntrypoint } from '../lib/entrypoint.ts';
40
40
  import { backupFileName } from './naming.ts';
41
41
 
42
42
  /**
@@ -52,58 +52,68 @@ const SOURCE_FILE = 'backup.sql';
52
52
  */
53
53
  const XZ_ARGS = ['-T0', '-6'];
54
54
 
55
- if (!process.env['BACKUP_ENCRYPTION_KEY']) {
56
- fail('BACKUP_ENCRYPTION_KEY is not set. Refusing to export an unencrypted database.');
57
- }
55
+ /**
56
+ * Compress and encrypt `backup.sql` in the working directory, remove the plaintext, and publish the file name as the
57
+ * `file` step output. Calls `fail` (exits 1) on any problem, so no unencrypted dump is left for an upload job.
58
+ */
59
+ export async function main(): Promise<void> {
60
+ if (!process.env['BACKUP_ENCRYPTION_KEY']) {
61
+ fail('BACKUP_ENCRYPTION_KEY is not set. Refusing to export an unencrypted database.');
62
+ }
58
63
 
59
- if (!existsSync(SOURCE_FILE)) {
60
- fail(`Expected ${SOURCE_FILE} from the export step, but it does not exist.`);
61
- }
64
+ if (!existsSync(SOURCE_FILE)) {
65
+ fail(`Expected ${SOURCE_FILE} from the export step, but it does not exist.`);
66
+ }
62
67
 
63
- const key = process.env['BACKUP_ENCRYPTION_KEY'];
64
- const file = backupFileName(new Date());
68
+ const key = process.env['BACKUP_ENCRYPTION_KEY'];
69
+ const file = backupFileName(new Date());
65
70
 
66
- let plaintext: string;
67
- try {
68
- plaintext = readFileSync(SOURCE_FILE, 'utf8');
69
- } catch (error: unknown) {
70
- fail(`Could not read ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);
71
- }
71
+ let plaintext: string;
72
+ try {
73
+ plaintext = readFileSync(SOURCE_FILE, 'utf8');
74
+ } catch (error: unknown) {
75
+ fail(`Could not read ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);
76
+ }
72
77
 
73
- if (plaintext === '') {
74
- fail(`${SOURCE_FILE} is empty. An empty dump is not a backup, and uploading one is a false sense of safety.`);
75
- }
78
+ if (plaintext === '') {
79
+ fail(`${SOURCE_FILE} is empty. An empty dump is not a backup, and uploading one is a false sense of safety.`);
80
+ }
76
81
 
77
- /**
78
- * Compress first, then encrypt.
79
- *
80
- * The order matters: compression over ciphertext buys nothing, and encrypting the
81
- * compressed bytes means the plaintext is never re-materialised on disk at full
82
- * size. Unlike gzip, xz leaves its input in place, so the plaintext SQL has to be
83
- * removed explicitly here or it survives into the artifact store.
84
- */
85
- let compressed: Buffer;
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
91
- compressed = execFileSync('xz', [...XZ_ARGS, '--keep', '--stdout', SOURCE_FILE], { maxBuffer: 512 * 1024 * 1024 });
92
- } catch (error: unknown) {
93
- fail(`xz failed on ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);
94
- }
82
+ /**
83
+ * Compress first, then encrypt.
84
+ *
85
+ * The order matters: compression over ciphertext buys nothing, and encrypting the
86
+ * compressed bytes means the plaintext is never re-materialised on disk at full
87
+ * size. Unlike gzip, xz leaves its input in place, so the plaintext SQL has to be
88
+ * removed explicitly here or it survives into the artifact store.
89
+ */
90
+ let compressed: Buffer;
91
+ try {
92
+ // `xz` is resolved from PATH deliberately: the script runs wherever the
93
+ // operator compresses backups, and pinning an absolute path would break
94
+ // every platform but one.
95
+ // eslint-disable-next-line sonarjs/no-os-command-from-path
96
+ compressed = execFileSync('xz', [...XZ_ARGS, '--keep', '--stdout', SOURCE_FILE], { maxBuffer: 512 * 1024 * 1024 });
97
+ } catch (error: unknown) {
98
+ fail(`xz failed on ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);
99
+ }
95
100
 
96
- let envelope: { ciphertext: string; iv: string };
97
- try {
98
- envelope = await encryptSecret(compressed.toString('base64'), key);
99
- } catch (error: unknown) {
100
- // A key that is not 32 base64 bytes, or not valid base64 at all, fails here
101
- // rather than producing a file nothing can open.
102
- fail(`Could not encrypt the dump: ${error instanceof Error ? error.message : String(error)}`);
103
- }
101
+ let envelope: { ciphertext: string; iv: string };
102
+ try {
103
+ envelope = await encryptSecret(compressed.toString('base64'), key);
104
+ } catch (error: unknown) {
105
+ // A key that is not 32 base64 bytes, or not valid base64 at all, fails here
106
+ // rather than producing a file nothing can open.
107
+ fail(`Could not encrypt the dump: ${error instanceof Error ? error.message : String(error)}`);
108
+ }
104
109
 
105
- writeFileSync(file, `${JSON.stringify({ ...envelope, source: path.basename(SOURCE_FILE) }, null, 2)}\n`, 'utf8');
106
- rmSync(SOURCE_FILE, { force: true });
110
+ writeFileSync(file, `${JSON.stringify({ ...envelope, source: path.basename(SOURCE_FILE) }, null, 2)}\n`, 'utf8');
111
+ rmSync(SOURCE_FILE, { force: true });
107
112
 
108
- console.log(`Backup encrypted: ${file} (${compressed.byteLength} compressed bytes)`);
109
- setOutput('file', file);
113
+ console.log(`Backup encrypted: ${file} (${compressed.byteLength} compressed bytes)`);
114
+ setOutput('file', file);
115
+ }
116
+
117
+ if (isEntrypoint(import.meta.url)) {
118
+ await main();
119
+ }
@@ -54,8 +54,8 @@ export function retentionCutoff(now: Date, days: number): string {
54
54
  * `Number()` rather than `parseInt()`: `parseInt('30d')` yields 30, which would
55
55
  * silently accept a mistyped value and prune against the wrong window.
56
56
  */
57
- export function requireRetentionDays(): number {
58
- const raw = process.env['BACKUP_RETENTION_DAYS'];
57
+ export function requireRetentionDays(env: NodeJS.ProcessEnv = process.env): number {
58
+ const raw = env['BACKUP_RETENTION_DAYS'];
59
59
  const days = Number(raw);
60
60
  if (!Number.isFinite(days) || days <= 0) {
61
61
  throw new Error(`BACKUP_RETENTION_DAYS must be a positive number, got ${JSON.stringify(raw)}.`);
@@ -29,7 +29,10 @@
29
29
  * written verbatim instead of copying the template.
30
30
  * - `WRANGLER_PATCH_JSON` — top-level keys merged into the config.
31
31
  * - `WRANGLER_VARS_PATCH_JSON` — `vars` entries merged into the config.
32
+ *
33
+ * KV bindings come from the manifest's `features.kv` (none declared: none added).
32
34
  */
35
+ import { loadManifest } from '../manifest.ts';
33
36
  import { setOutput } from './lib/github-actions.ts';
34
37
  import { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches.ts';
35
38
  import { provisionWranglerResources } from './wrangler-config/resources.ts';
@@ -45,7 +48,12 @@ export function main(): string[] {
45
48
  ensureMinimumConfigVersion();
46
49
  applyTopLevelPatch();
47
50
  applyVarsPatch();
48
- const created = provisionWranglerResources();
51
+ // KV is manifest-driven: a repo that declares no `features.kv` gets no KV binding and no namespace (no phantom CACHE).
52
+ const kv = loadManifest(process.cwd())?.features?.kv;
53
+ const created = provisionWranglerResources({
54
+ namespaceNames: { ...kv?.namespaceNames },
55
+ requiredKvBindings: kv?.bindings ?? [],
56
+ });
49
57
 
50
58
  // Published as a step output rather than only printed. The backup workflow needs
51
59
  // to know whether the D1 database *existed* or was created moments ago: a fresh one
@@ -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);
@@ -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
@@ -21,7 +21,7 @@ import { defineConfig } from 'vitest/config';
21
21
  import { asVitePlugins } from './plugin-option.ts';
22
22
  import type { PluginOption } from './plugin-option.ts';
23
23
  import type { Pool } from 'vitest/node';
24
- import { DEFAULT_WORKSPACE_PACKAGES, workspaceAliases } from './vitest-aliases.ts';
24
+ import { workspaceAliases } from './vitest-aliases.ts';
25
25
  import type { VitestAlias } from './vitest-aliases.ts';
26
26
 
27
27
  /**
@@ -100,10 +100,7 @@ export interface IntegrationVitestConfigOptions {
100
100
  */
101
101
  export function defineIntegrationVitestConfig(options: IntegrationVitestConfigOptions): ReturnType<typeof defineConfig> {
102
102
  const root = options.root ?? new URL('.', import.meta.url).href;
103
- const aliases = [
104
- ...workspaceAliases({ scope: options.scope, root, packages: options.packages ?? DEFAULT_WORKSPACE_PACKAGES, mocks: [] }),
105
- ...(options.aliases ?? []),
106
- ];
103
+ const aliases = [...workspaceAliases({ scope: options.scope, root, packages: options.packages, mocks: [] }), ...(options.aliases ?? [])];
107
104
 
108
105
  return defineConfig({
109
106
  ...(options.define !== undefined && { define: { ...options.define } }),
@@ -28,7 +28,7 @@ import { asVitePlugins } from './plugin-option.ts';
28
28
  import type { PluginOption } from './plugin-option.ts';
29
29
  import { fileURLToPath } from 'node:url';
30
30
  import { manifestCoverageThresholds } from './manifest.ts';
31
- 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';
32
32
  import type { VitestAlias } from './vitest-aliases.ts';
33
33
  import type { CoverageThresholds } from './vitest.ts';
34
34
 
@@ -211,7 +211,7 @@ const INDEX_BARREL_EXCLUDE = '**/index.ts';
211
211
  export function defineRepoVitestConfig(options: RepoVitestConfigOptions): ReturnType<typeof defineConfig> {
212
212
  const root = options.root ?? new URL('.', import.meta.url).href;
213
213
  const thresholds = options.thresholds ?? manifestCoverageThresholds(root);
214
- const packages = options.packages ?? DEFAULT_WORKSPACE_PACKAGES;
214
+ const packages = options.packages;
215
215
  const mocks = options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS;
216
216
  const noExternal = [...KIT_NO_EXTERNAL, ...(options.noExternal ?? [])];
217
217
  const backend = options.backend ?? {};
package/src/vitest-web.ts CHANGED
@@ -43,7 +43,7 @@ import { defineConfig } from 'vitest/config';
43
43
  import { asVitePlugins } from './plugin-option.ts';
44
44
  import type { PluginOption } from './plugin-option.ts';
45
45
  import { fileURLToPath } from 'node:url';
46
- 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';
47
47
  import type { VitestAlias } from './vitest-aliases.ts';
48
48
  import type { CoverageThresholds } from './vitest.ts';
49
49
 
@@ -154,7 +154,7 @@ export function defineWebVitestConfig(options: WebVitestConfigOptions = {}): Ret
154
154
  const scopePart = workspaceAliases({
155
155
  scope: options.scope ?? '@unused',
156
156
  root,
157
- packages: options.packages ?? DEFAULT_WORKSPACE_PACKAGES,
157
+ packages: options.packages,
158
158
  mocks: options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS,
159
159
  }).filter((alias) => typeof alias.find === 'string' && !alias.find.startsWith('@unused'));
160
160
  const aliases: VitestAlias[] = [
package/src/vitest.ts CHANGED
@@ -37,7 +37,7 @@ import { defineConfig } from 'vitest/config';
37
37
  import { asVitePlugins } from './plugin-option.ts';
38
38
  import type { PluginOption } from './plugin-option.ts';
39
39
  import { manifestCoverageThresholds } from './manifest.ts';
40
- 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';
41
41
  import type { VitestAlias } from './vitest-aliases.ts';
42
42
 
43
43
  export type { VitestAlias } from './vitest-aliases.ts';
@@ -47,7 +47,7 @@ export type { VitestAlias } from './vitest-aliases.ts';
47
47
  // kit's components. Exporting it only from the root meant that import failed with
48
48
  // `does not provide an export named 'KIT_DEDUPE'` at config-load time, which is a
49
49
  // build failure before any test runs and no error that names the install.
50
- export { KIT_DEDUPE, KIT_NO_EXTERNAL } from './vitest-aliases.ts';
50
+ export { DEFAULT_WORKSPACE_PACKAGES, KIT_DEDUPE, KIT_NO_EXTERNAL } from './vitest-aliases.ts';
51
51
 
52
52
  /**
53
53
  * Coverage thresholds, in the four figures Vitest gates on.
@@ -230,7 +230,7 @@ export function defineUnitVitestConfig(options: UnitVitestConfigOptions = {}): R
230
230
  const baseAliases = workspaceAliases({
231
231
  scope: options.scope ?? '@unused',
232
232
  root,
233
- packages: options.scope === undefined ? [] : (options.packages ?? DEFAULT_WORKSPACE_PACKAGES),
233
+ packages: options.scope === undefined ? [] : options.packages,
234
234
  mocks: options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS,
235
235
  });
236
236
  // A placeholder scope contributes no `@unused/*` entries; the mocks plus
@@ -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'