@rexezuge/tooling 1.13.0 → 1.14.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 (79) hide show
  1. package/README.md +25 -4
  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.d.ts +2 -53
  7. package/dist/eslint.d.ts.map +1 -1
  8. package/dist/eslint.js.map +2 -2
  9. package/dist/pages-proxy.d.ts +2 -0
  10. package/dist/pages-proxy.d.ts.map +1 -0
  11. package/dist/pages-proxy.js +1 -0
  12. package/dist/pages-proxy.js.map +7 -0
  13. package/dist/plugin-option.d.ts +15 -0
  14. package/dist/plugin-option.d.ts.map +1 -0
  15. package/dist/plugin-option.js +1 -0
  16. package/dist/plugin-option.js.map +7 -0
  17. package/dist/scripts/ensure-spa-shell-stub.d.ts +4 -2
  18. package/dist/scripts/ensure-spa-shell-stub.d.ts.map +1 -1
  19. package/dist/scripts/ensure-spa-shell-stub.js +1 -2
  20. package/dist/scripts/ensure-spa-shell-stub.js.map +3 -3
  21. package/dist/scripts/init-secrets.d.ts +1 -2
  22. package/dist/scripts/init-secrets.d.ts.map +1 -1
  23. package/dist/scripts/init-secrets.js +2 -3
  24. package/dist/scripts/init-secrets.js.map +3 -3
  25. package/dist/scripts/migrations-lock.d.ts +6 -2
  26. package/dist/scripts/migrations-lock.d.ts.map +1 -1
  27. package/dist/scripts/migrations-lock.js +1 -2
  28. package/dist/scripts/migrations-lock.js.map +3 -3
  29. package/dist/scripts/prepare-wrangler-config.d.ts +6 -2
  30. package/dist/scripts/prepare-wrangler-config.d.ts.map +1 -1
  31. package/dist/scripts/prepare-wrangler-config.js +1 -2
  32. package/dist/scripts/prepare-wrangler-config.js.map +3 -3
  33. package/dist/scripts/validate-locales.d.ts +20 -2
  34. package/dist/scripts/validate-locales.d.ts.map +1 -1
  35. package/dist/scripts/validate-locales.js +5 -5
  36. package/dist/scripts/validate-locales.js.map +3 -3
  37. package/dist/scripts/verify-spa-shell.d.ts +7 -2
  38. package/dist/scripts/verify-spa-shell.d.ts.map +1 -1
  39. package/dist/scripts/verify-spa-shell.js +1 -2
  40. package/dist/scripts/verify-spa-shell.js.map +3 -3
  41. package/dist/vite.d.ts +2 -1
  42. package/dist/vite.d.ts.map +1 -1
  43. package/dist/vite.js +3 -3
  44. package/dist/vite.js.map +3 -3
  45. package/dist/vitest-integration.d.ts +3 -2
  46. package/dist/vitest-integration.d.ts.map +1 -1
  47. package/dist/vitest-integration.js +1 -1
  48. package/dist/vitest-integration.js.map +3 -3
  49. package/dist/vitest-repo.d.ts +3 -2
  50. package/dist/vitest-repo.d.ts.map +1 -1
  51. package/dist/vitest-repo.js +1 -1
  52. package/dist/vitest-repo.js.map +3 -3
  53. package/dist/vitest-web.d.ts +3 -2
  54. package/dist/vitest-web.d.ts.map +1 -1
  55. package/dist/vitest-web.js +1 -1
  56. package/dist/vitest-web.js.map +3 -3
  57. package/dist/vitest.d.ts +3 -2
  58. package/dist/vitest.d.ts.map +1 -1
  59. package/dist/vitest.js +1 -1
  60. package/dist/vitest.js.map +3 -3
  61. package/package.json +3 -3
  62. package/src/eslint-options.ts +54 -0
  63. package/src/eslint.ts +2 -53
  64. package/src/pages-proxy.test.ts +8 -0
  65. package/src/pages-proxy.ts +13 -0
  66. package/src/plugin-option.test.ts +13 -0
  67. package/src/plugin-option.ts +18 -0
  68. package/src/scripts/ensure-spa-shell-stub.ts +18 -10
  69. package/src/scripts/entrypoints.test.ts +55 -0
  70. package/src/scripts/init-secrets.ts +8 -6
  71. package/src/scripts/migrations-lock.ts +22 -17
  72. package/src/scripts/prepare-wrangler-config.ts +26 -14
  73. package/src/scripts/validate-locales.ts +39 -17
  74. package/src/scripts/verify-spa-shell.ts +21 -20
  75. package/src/vite.ts +5 -3
  76. package/src/vitest-integration.ts +5 -3
  77. package/src/vitest-repo.ts +5 -3
  78. package/src/vitest-web.ts +5 -3
  79. package/src/vitest.ts +5 -3
@@ -0,0 +1,18 @@
1
+ import type { ViteUserConfig } from 'vitest/config';
2
+
3
+ /**
4
+ * What a `plugins` option accepts: whatever a Vite `plugins` array does (a plugin, a nested array of them as
5
+ * `@vitejs/plugin-react` and `@tailwindcss/vite` return, a promise, a falsy placeholder).
6
+ *
7
+ * Deliberately structural rather than Vite's own `PluginOption`: the app's `vite` and the `vite` that
8
+ * `vitest` brings are separate installs more often than not, and their `Plugin` types are not assignable to
9
+ * each other even at the same version ("Excessive stack depth comparing types"). The kit never inspects a plugin.
10
+ */
11
+ export type PluginOption = object | false | null | undefined;
12
+
13
+ /**
14
+ * Hand the plugins to Vite. One assertion, here, for the reason above.
15
+ */
16
+ export function asVitePlugins(plugins: readonly PluginOption[]): NonNullable<ViteUserConfig['plugins']> {
17
+ return [...plugins] as NonNullable<ViteUserConfig['plugins']>;
18
+ }
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env tsx
2
1
  /**
3
2
  * Write a placeholder `apps/api/src/generated/spa-shell.ts` when it is absent.
4
3
  *
@@ -20,15 +19,24 @@
20
19
  */
21
20
  import path from 'node:path';
22
21
  import { fileURLToPath } from 'node:url';
22
+ import { isEntrypoint } from './lib/entrypoint.ts';
23
23
  import { ensureSpaShellStub } from './spa-shell.ts';
24
24
 
25
- const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
26
- const root = process.argv[2] === undefined ? REPOSITORY_ROOT : path.resolve(process.argv[2]);
27
-
28
- const result = ensureSpaShellStub({ root });
25
+ /**
26
+ * Run the stub writer. `args[0]` is the repo root (default: the repo this file sits in).
27
+ */
28
+ export function main(args: readonly string[] = process.argv.slice(2)): number {
29
+ const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
30
+ const root = args[0] === undefined ? repositoryRoot : path.resolve(args[0]);
31
+ const result = ensureSpaShellStub({ root });
32
+ console.log(
33
+ result.created
34
+ ? `ensure-spa-shell-stub: created stub at ${result.path}`
35
+ : `ensure-spa-shell-stub: ${result.path} already present, left untouched`,
36
+ );
37
+ return 0;
38
+ }
29
39
 
30
- console.log(
31
- result.created
32
- ? `ensure-spa-shell-stub: created stub at ${result.path}`
33
- : `ensure-spa-shell-stub: ${result.path} already present, left untouched`,
34
- );
40
+ if (isEntrypoint(import.meta.url)) {
41
+ process.exit(main());
42
+ }
@@ -0,0 +1,55 @@
1
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import path from 'node:path';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
+ import { main as ensureStub } from './ensure-spa-shell-stub.ts';
6
+ import { main as lockMigrations } from './migrations-lock.ts';
7
+ import { collectLocaleProblems } from './validate-locales.ts';
8
+ import { main as verifyShell } from './verify-spa-shell.ts';
9
+
10
+ const tmp = (): string => mkdtempSync(path.join(tmpdir(), 'tooling-scripts-'));
11
+
12
+ afterEach(() => vi.restoreAllMocks());
13
+
14
+ describe('script entrypoints export main(args)', () => {
15
+ it('ensure-spa-shell-stub writes the stub once and exits 0', () => {
16
+ const log = vi.spyOn(console, 'log').mockImplementation(vi.fn());
17
+ const root = tmp();
18
+ expect(ensureStub([root])).toBe(0);
19
+ expect(existsSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
20
+ expect(ensureStub([root])).toBe(0);
21
+ expect(log.mock.calls.map(String)).toEqual([expect.stringContaining('created stub'), expect.stringContaining('already present')]);
22
+ });
23
+
24
+ it('verify-spa-shell rejects the stub with exit 1', () => {
25
+ vi.spyOn(console, 'log').mockImplementation(vi.fn());
26
+ const error = vi.spyOn(console, 'error').mockImplementation(vi.fn());
27
+ const root = tmp();
28
+ ensureStub([root]);
29
+ expect(verifyShell([root])).toBe(1);
30
+ expect(error).toHaveBeenCalledWith('SPA shell check failed:');
31
+ });
32
+
33
+ it('migrations-lock records the files and exits 0', () => {
34
+ const log = vi.spyOn(console, 'log').mockImplementation(vi.fn());
35
+ const root = tmp();
36
+ mkdirSync(path.join(root, 'migrations'));
37
+ writeFileSync(path.join(root, 'migrations/0001_init.sql'), 'CREATE TABLE t (id TEXT);\n');
38
+ expect(lockMigrations([path.join(root, 'migrations')])).toBe(0);
39
+ expect(readFileSync(path.join(root, 'migrations/migrations.lock.json'), 'utf8')).toContain('0001_init.sql');
40
+ expect(log).toHaveBeenCalledWith(expect.stringContaining('1 migration(s) recorded'));
41
+ });
42
+ });
43
+
44
+ describe('collectLocaleProblems', () => {
45
+ it('returns the findings as data without printing', () => {
46
+ const root = tmp();
47
+ mkdirSync(path.join(root, 'en'));
48
+ mkdirSync(path.join(root, 'de'));
49
+ writeFileSync(path.join(root, 'en/translation.json'), JSON.stringify({ a: 'A', b: 'B' }));
50
+ writeFileSync(path.join(root, 'de/translation.json'), JSON.stringify({ a: 'A' }));
51
+ const { report, problems } = collectLocaleProblems({ dir: root });
52
+ expect(report.locales).toContain('de');
53
+ expect(problems.some((problem) => problem.locale === 'de')).toBe(true);
54
+ });
55
+ });
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env tsx
2
1
  /**
3
2
  * Create the Secrets Store entries declared in `wrangler.jsonc`, generating a fresh
4
3
  * value for each one that does not exist yet.
@@ -47,6 +46,7 @@
47
46
  import { execFileSync } from 'node:child_process';
48
47
  import { existsSync, readFileSync } from 'node:fs';
49
48
  import { parse } from 'jsonc-parser';
49
+ import { isEntrypoint } from './lib/entrypoint.ts';
50
50
  import { fail } from './lib/github-actions.ts';
51
51
  import { isEmptySecretsStoreListing, parseWranglerNames } from './lib/wrangler-table.ts';
52
52
  import { CONFIG_PATH, type WranglerConfig } from './wrangler-config/types.ts';
@@ -230,7 +230,7 @@ function createSecret(storeId: string, secretName: string, secretValue: string):
230
230
  wrangler(['secrets-store', 'secret', 'create', storeId, '--name', secretName, '--scopes', 'workers', '--remote'], secretValue);
231
231
  }
232
232
 
233
- async function main(): Promise<void> {
233
+ export async function main(): Promise<void> {
234
234
  console.log('Initializing Cloudflare secrets...');
235
235
  const config = parseWranglerConfig();
236
236
  const plan = planSecrets(config);
@@ -266,8 +266,10 @@ async function main(): Promise<void> {
266
266
  // as a stack trace with its cause intact and the process exits non-zero. Either way
267
267
  // the exit status has to be right: this runs in the deploy pipeline, and swallowing
268
268
  // the rejection reported a failed key bootstrap as a green step.
269
- try {
270
- await main();
271
- } catch (error: unknown) {
272
- fail(error instanceof Error ? `Secret initialization failed: ${error.message}` : String(error));
269
+ if (isEntrypoint(import.meta.url)) {
270
+ try {
271
+ await main();
272
+ } catch (error: unknown) {
273
+ fail(error instanceof Error ? `Secret initialization failed: ${error.message}` : String(error));
274
+ }
273
275
  }
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env tsx
2
1
  /**
3
2
  * Record newly-added migration files in `migrations/migrations.lock.json`.
4
3
  *
@@ -29,23 +28,29 @@
29
28
  */
30
29
  import path from 'node:path';
31
30
  import { fileURLToPath } from 'node:url';
31
+ import { isEntrypoint } from './lib/entrypoint.ts';
32
32
  import { LOCK_NAME, verifyMigrations } from './verify-migrations.ts';
33
33
 
34
- const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
35
- const migrationsDir = process.argv[2] === undefined ? path.join(REPOSITORY_ROOT, 'migrations') : path.resolve(process.argv[2]);
36
-
37
- const report = verifyMigrations(migrationsDir, { write: true });
38
-
39
- for (const problem of report.problems) {
40
- console.error(`FAIL: ${problem.problem}`);
34
+ /**
35
+ * Write the lock. `args[0]` is the migrations directory (default `./migrations`
36
+ * beside the repo this file sits in). Returns the exit code; it is non-zero when a
37
+ * problem the write cannot resolve (an `edited` entry) remains.
38
+ */
39
+ export function main(args: readonly string[] = process.argv.slice(2)): number {
40
+ const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
41
+ const migrationsDir = args[0] === undefined ? path.join(repositoryRoot, 'migrations') : path.resolve(args[0]);
42
+ const report = verifyMigrations(migrationsDir, { write: true });
43
+ for (const problem of report.problems) {
44
+ console.error(`FAIL: ${problem.problem}`);
45
+ }
46
+ console.log(
47
+ `${report.lock === null ? 'left' : 'wrote'} ${path.join(migrationsDir, LOCK_NAME)} (${report.files.length} migration(s) recorded)`,
48
+ );
49
+ // The lock is re-checked by the caller: `verify-migrations.ts` re-reads from disk,
50
+ // so running it after this command reports the same verdict CI will.
51
+ return report.problems.length === 0 ? 0 : 1;
41
52
  }
42
53
 
43
- console.log(
44
- `${report.lock === null ? 'left' : 'wrote'} ${path.join(migrationsDir, LOCK_NAME)} (${report.files.length} migration(s) recorded)`,
45
- );
46
-
47
- // The lock is re-checked by the caller: `verify-migrations.ts` re-reads from disk,
48
- // so running it after this command reports the same verdict CI will. A `--write`
49
- // that could not resolve everything still exits non-zero here, which is why an
50
- // incremental `edited` finding does not vanish just because someone wrote.
51
- process.exit(report.problems.length === 0 ? 0 : 1);
54
+ if (isEntrypoint(import.meta.url)) {
55
+ process.exit(main());
56
+ }
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env tsx
2
1
  /**
3
2
  * Materialize `wrangler.jsonc` and provision what it refers to.
4
3
  *
@@ -34,18 +33,31 @@
34
33
  import { setOutput } from './lib/github-actions.ts';
35
34
  import { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches.ts';
36
35
  import { provisionWranglerResources } from './wrangler-config/resources.ts';
36
+ import { isEntrypoint } from './lib/entrypoint.ts';
37
37
 
38
- prepareConfigFile();
39
- ensureMinimumConfigVersion();
40
- applyTopLevelPatch();
41
- applyVarsPatch();
42
- const created = provisionWranglerResources();
38
+ /**
39
+ * Materialize and provision. Reads `process.env` and `process.cwd()` (the config paths
40
+ * resolve when `wrangler-config/types.ts` is first imported, so a caller changing
41
+ * directory must do so before importing this module). Returns the created resources.
42
+ */
43
+ export function main(): string[] {
44
+ prepareConfigFile();
45
+ ensureMinimumConfigVersion();
46
+ applyTopLevelPatch();
47
+ applyVarsPatch();
48
+ const created = provisionWranglerResources();
49
+
50
+ // Published as a step output rather than only printed. The backup workflow needs
51
+ // to know whether the D1 database *existed* or was created moments ago: a fresh one
52
+ // holds no user data, and uploading that empty dump every night is a false sense
53
+ // of safety. The alternative — re-reading the placeholder id out of
54
+ // `wrangler.jsonc` — is unreachable, because `provisionWranglerResources` patches
55
+ // the placeholder away before the reader ever runs.
56
+ setOutput('created', created.join(','));
57
+ console.log('Wrangler configuration is ready.');
58
+ return created;
59
+ }
43
60
 
44
- // Published as a step output rather than only printed. The backup workflow needs
45
- // to know whether the D1 database *existed* or was created moments ago: a fresh one
46
- // holds no user data, and uploading that empty dump every night is a false sense
47
- // of safety. The alternative — re-reading the placeholder id out of
48
- // `wrangler.jsonc` — is unreachable, because `provisionWranglerResources` patches
49
- // the placeholder away before the reader ever runs.
50
- setOutput('created', created.join(','));
51
- console.log('Wrangler configuration is ready.');
61
+ if (isEntrypoint(import.meta.url)) {
62
+ main();
63
+ }
@@ -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
+ }
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',
@@ -17,7 +17,9 @@
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
24
  import { DEFAULT_WORKSPACE_PACKAGES, workspaceAliases } from './vitest-aliases.ts';
23
25
  import type { VitestAlias } from './vitest-aliases.ts';
@@ -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.
@@ -105,7 +107,7 @@ export function defineIntegrationVitestConfig(options: IntegrationVitestConfigOp
105
107
 
106
108
  return defineConfig({
107
109
  ...(options.define !== undefined && { define: { ...options.define } }),
108
- ...(options.plugins !== undefined && { plugins: [...options.plugins] }),
110
+ ...(options.plugins !== undefined && { plugins: asVitePlugins(options.plugins) }),
109
111
  resolve: { alias: aliases },
110
112
  test: {
111
113
  globals: true,
@@ -23,7 +23,9 @@
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
31
  import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
@@ -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
  */
@@ -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,7 +39,9 @@
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
46
  import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
45
47
  import type { VitestAlias } from './vitest-aliases.ts';
@@ -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
  */
@@ -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,7 +33,9 @@
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
40
  import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_DEDUPE, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
39
41
  import type { VitestAlias } from './vitest-aliases.ts';
@@ -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).
@@ -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 ?? [])],