@specdest/devkit 0.4.18 → 0.4.20

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 (146) hide show
  1. package/README.md +107 -28
  2. package/dist/npm/cli.js +16 -24
  3. package/dist/npm/index.js +5 -1
  4. package/dist/npm/native/specdest-darwin-arm64 +0 -0
  5. package/dist/npm/native/specdest-darwin-x64 +0 -0
  6. package/dist/npm/native/specdest-linux-arm64 +0 -0
  7. package/dist/npm/native/specdest-linux-x64 +0 -0
  8. package/package.json +8 -5
  9. package/dist/npm/automation-policy.d.ts +0 -2
  10. package/dist/npm/automation-policy.js +0 -30
  11. package/dist/npm/canonical-project-operations.d.ts +0 -5
  12. package/dist/npm/canonical-project-operations.js +0 -5
  13. package/dist/npm/canonical-project.d.ts +0 -21
  14. package/dist/npm/canonical-project.js +0 -115
  15. package/dist/npm/catalog-snapshot.d.ts +0 -53
  16. package/dist/npm/catalog-snapshot.js +0 -35
  17. package/dist/npm/client-only-boundary.d.ts +0 -1
  18. package/dist/npm/client-only-boundary.js +0 -29
  19. package/dist/npm/commands.d.ts +0 -15
  20. package/dist/npm/commands.js +0 -188
  21. package/dist/npm/git-catalog.d.ts +0 -40
  22. package/dist/npm/git-catalog.js +0 -222
  23. package/dist/npm/host-automation.d.ts +0 -9
  24. package/dist/npm/host-automation.js +0 -66
  25. package/dist/npm/installer-primitives.d.ts +0 -3
  26. package/dist/npm/installer-primitives.js +0 -50
  27. package/dist/npm/predefined-packages/abac.d.ts +0 -2
  28. package/dist/npm/predefined-packages/abac.js +0 -22
  29. package/dist/npm/predefined-packages/admin-ui-templates/AdminConfirmDialog.tsx.template +0 -46
  30. package/dist/npm/predefined-packages/admin-ui-templates/AdminDataTable.tsx.template +0 -49
  31. package/dist/npm/predefined-packages/admin-ui-templates/AdminDetailLayout.tsx.template +0 -15
  32. package/dist/npm/predefined-packages/admin-ui-templates/AdminEmptyState.tsx.template +0 -17
  33. package/dist/npm/predefined-packages/admin-ui-templates/AdminFilterBar.tsx.template +0 -16
  34. package/dist/npm/predefined-packages/admin-ui-templates/AdminFormLayout.tsx.template +0 -19
  35. package/dist/npm/predefined-packages/admin-ui-templates/AdminPage.tsx.template +0 -19
  36. package/dist/npm/predefined-packages/admin-ui-templates/AdminPageHeader.tsx.template +0 -19
  37. package/dist/npm/predefined-packages/admin-ui-templates/AdminPagination.tsx.template +0 -20
  38. package/dist/npm/predefined-packages/admin-ui-templates/AdminShell.tsx.template +0 -20
  39. package/dist/npm/predefined-packages/admin-ui-templates/AdminSidebar.tsx.template +0 -18
  40. package/dist/npm/predefined-packages/admin-ui-templates/AdminStatCard.tsx.template +0 -22
  41. package/dist/npm/predefined-packages/admin-ui.d.ts +0 -2
  42. package/dist/npm/predefined-packages/admin-ui.js +0 -79
  43. package/dist/npm/predefined-packages/auth.d.ts +0 -2
  44. package/dist/npm/predefined-packages/auth.js +0 -21
  45. package/dist/npm/predefined-packages/convex.d.ts +0 -2
  46. package/dist/npm/predefined-packages/convex.js +0 -53
  47. package/dist/npm/predefined-packages/expo.d.ts +0 -2
  48. package/dist/npm/predefined-packages/expo.js +0 -88
  49. package/dist/npm/predefined-packages/firebase-hosting.d.ts +0 -2
  50. package/dist/npm/predefined-packages/firebase-hosting.js +0 -24
  51. package/dist/npm/predefined-packages/health.d.ts +0 -10
  52. package/dist/npm/predefined-packages/health.js +0 -52
  53. package/dist/npm/predefined-packages/husky.d.ts +0 -2
  54. package/dist/npm/predefined-packages/husky.js +0 -57
  55. package/dist/npm/predefined-packages/index.d.ts +0 -12
  56. package/dist/npm/predefined-packages/index.js +0 -97
  57. package/dist/npm/predefined-packages/install.d.ts +0 -19
  58. package/dist/npm/predefined-packages/install.js +0 -86
  59. package/dist/npm/predefined-packages/local-logging.d.ts +0 -2
  60. package/dist/npm/predefined-packages/local-logging.js +0 -17
  61. package/dist/npm/predefined-packages/logging.d.ts +0 -2
  62. package/dist/npm/predefined-packages/logging.js +0 -21
  63. package/dist/npm/predefined-packages/multi-tenancy.d.ts +0 -2
  64. package/dist/npm/predefined-packages/multi-tenancy.js +0 -21
  65. package/dist/npm/predefined-packages/nps.d.ts +0 -2
  66. package/dist/npm/predefined-packages/nps.js +0 -32
  67. package/dist/npm/predefined-packages/oxfmt.d.ts +0 -2
  68. package/dist/npm/predefined-packages/oxfmt.js +0 -22
  69. package/dist/npm/predefined-packages/oxlint.d.ts +0 -2
  70. package/dist/npm/predefined-packages/oxlint.js +0 -35
  71. package/dist/npm/predefined-packages/package-json.d.ts +0 -3
  72. package/dist/npm/predefined-packages/package-json.js +0 -61
  73. package/dist/npm/predefined-packages/payments.d.ts +0 -2
  74. package/dist/npm/predefined-packages/payments.js +0 -31
  75. package/dist/npm/predefined-packages/playwright.d.ts +0 -2
  76. package/dist/npm/predefined-packages/playwright.js +0 -35
  77. package/dist/npm/predefined-packages/project-signals.d.ts +0 -4
  78. package/dist/npm/predefined-packages/project-signals.js +0 -39
  79. package/dist/npm/predefined-packages/registry.d.ts +0 -3
  80. package/dist/npm/predefined-packages/registry.js +0 -65
  81. package/dist/npm/predefined-packages/resolver.d.ts +0 -8
  82. package/dist/npm/predefined-packages/resolver.js +0 -35
  83. package/dist/npm/predefined-packages/sentry.d.ts +0 -2
  84. package/dist/npm/predefined-packages/sentry.js +0 -29
  85. package/dist/npm/predefined-packages/shadcn.d.ts +0 -2
  86. package/dist/npm/predefined-packages/shadcn.js +0 -23
  87. package/dist/npm/predefined-packages/storybook.d.ts +0 -2
  88. package/dist/npm/predefined-packages/storybook.js +0 -25
  89. package/dist/npm/predefined-packages/stryker.d.ts +0 -2
  90. package/dist/npm/predefined-packages/stryker.js +0 -48
  91. package/dist/npm/predefined-packages/supabase.d.ts +0 -2
  92. package/dist/npm/predefined-packages/supabase.js +0 -355
  93. package/dist/npm/predefined-packages/tailwind.d.ts +0 -2
  94. package/dist/npm/predefined-packages/tailwind.js +0 -18
  95. package/dist/npm/predefined-packages/tanstack-form.d.ts +0 -2
  96. package/dist/npm/predefined-packages/tanstack-form.js +0 -19
  97. package/dist/npm/predefined-packages/tanstack-query.d.ts +0 -2
  98. package/dist/npm/predefined-packages/tanstack-query.js +0 -15
  99. package/dist/npm/predefined-packages/tanstack-router.d.ts +0 -2
  100. package/dist/npm/predefined-packages/tanstack-router.js +0 -18
  101. package/dist/npm/predefined-packages/types.d.ts +0 -38
  102. package/dist/npm/predefined-packages/types.js +0 -1
  103. package/dist/npm/predefined-packages/vite.d.ts +0 -2
  104. package/dist/npm/predefined-packages/vite.js +0 -127
  105. package/dist/npm/predefined-packages/vitest.d.ts +0 -2
  106. package/dist/npm/predefined-packages/vitest.js +0 -20
  107. package/dist/npm/predefined-packages/zod.d.ts +0 -2
  108. package/dist/npm/predefined-packages/zod.js +0 -18
  109. package/dist/npm/project-check.d.ts +0 -25
  110. package/dist/npm/project-check.js +0 -178
  111. package/dist/npm/project-context.d.ts +0 -52
  112. package/dist/npm/project-context.js +0 -211
  113. package/dist/npm/project-install-guard.d.ts +0 -2
  114. package/dist/npm/project-install-guard.js +0 -51
  115. package/dist/npm/project-rules.d.ts +0 -25
  116. package/dist/npm/project-rules.js +0 -106
  117. package/dist/npm/project-runtime.d.ts +0 -21
  118. package/dist/npm/project-runtime.js +0 -41
  119. package/dist/npm/project-status.d.ts +0 -32
  120. package/dist/npm/project-status.js +0 -70
  121. package/dist/npm/project-sync.d.ts +0 -7
  122. package/dist/npm/project-sync.js +0 -143
  123. package/dist/npm/remote-installer.d.ts +0 -35
  124. package/dist/npm/remote-installer.js +0 -351
  125. package/dist/npm/rule-id-migrations.d.ts +0 -6
  126. package/dist/npm/rule-id-migrations.js +0 -19
  127. package/dist/npm/slack.d.ts +0 -16
  128. package/dist/npm/slack.js +0 -135
  129. package/dist/npm/snapshot/config.d.ts +0 -10
  130. package/dist/npm/snapshot/config.js +0 -24
  131. package/dist/npm/snapshot/policy.d.ts +0 -1
  132. package/dist/npm/snapshot/policy.js +0 -64
  133. package/dist/npm/snapshot/restore.d.ts +0 -10
  134. package/dist/npm/snapshot/restore.js +0 -19
  135. package/dist/npm/snapshot/sql.d.ts +0 -2
  136. package/dist/npm/snapshot/sql.js +0 -113
  137. package/dist/npm/snapshot/storage.d.ts +0 -8
  138. package/dist/npm/snapshot/storage.js +0 -70
  139. package/dist/npm/snapshot/verify.d.ts +0 -11
  140. package/dist/npm/snapshot/verify.js +0 -13
  141. package/dist/npm/snapshot-cli.d.ts +0 -6
  142. package/dist/npm/snapshot-cli.js +0 -45
  143. package/dist/npm/state.d.ts +0 -14
  144. package/dist/npm/state.js +0 -269
  145. package/dist/npm/supabase-local.d.ts +0 -2
  146. package/dist/npm/supabase-local.js +0 -62
@@ -1,65 +0,0 @@
1
- import { abacRecipe } from "./abac.js";
2
- import { adminUiRecipe } from "./admin-ui.js";
3
- import { authRecipe } from "./auth.js";
4
- import { convexRecipe } from "./convex.js";
5
- import { expoRecipe } from "./expo.js";
6
- import { loggingRecipe } from "./logging.js";
7
- import { multiTenancyRecipe } from "./multi-tenancy.js";
8
- import { paymentsRecipe } from "./payments.js";
9
- import { sentryRecipe } from "./sentry.js";
10
- import { shadcnRecipe } from "./shadcn.js";
11
- import { supabaseRecipe } from "./supabase.js";
12
- import { tanstackRouterRecipe } from "./tanstack-router.js";
13
- import { viteRecipe } from "./vite.js";
14
- import { firebaseHostingRecipe } from "./firebase-hosting.js";
15
- import { localLoggingRecipe } from "./local-logging.js";
16
- import { playwrightRecipe } from "./playwright.js";
17
- import { storybookRecipe } from "./storybook.js";
18
- import { tanstackFormRecipe } from "./tanstack-form.js";
19
- import { tanstackQueryRecipe } from "./tanstack-query.js";
20
- import { vitestRecipe } from "./vitest.js";
21
- import { zodRecipe } from "./zod.js";
22
- import { huskyRecipe } from "./husky.js";
23
- import { npsRecipe } from "./nps.js";
24
- import { oxfmtRecipe } from "./oxfmt.js";
25
- import { oxlintRecipe } from "./oxlint.js";
26
- import { strykerRecipe } from "./stryker.js";
27
- import { tailwindRecipe } from "./tailwind.js";
28
- const RECIPES = new Map([
29
- [viteRecipe.id, viteRecipe],
30
- [expoRecipe.id, expoRecipe],
31
- [supabaseRecipe.id, supabaseRecipe],
32
- [convexRecipe.id, convexRecipe],
33
- [authRecipe.id, authRecipe],
34
- [multiTenancyRecipe.id, multiTenancyRecipe],
35
- [abacRecipe.id, abacRecipe],
36
- [adminUiRecipe.id, adminUiRecipe],
37
- [sentryRecipe.id, sentryRecipe],
38
- [loggingRecipe.id, loggingRecipe],
39
- [paymentsRecipe.id, paymentsRecipe],
40
- [shadcnRecipe.id, shadcnRecipe],
41
- [tanstackRouterRecipe.id, tanstackRouterRecipe],
42
- [tanstackQueryRecipe.id, tanstackQueryRecipe],
43
- [tanstackFormRecipe.id, tanstackFormRecipe],
44
- [storybookRecipe.id, storybookRecipe],
45
- [playwrightRecipe.id, playwrightRecipe],
46
- [vitestRecipe.id, vitestRecipe],
47
- [localLoggingRecipe.id, localLoggingRecipe],
48
- [firebaseHostingRecipe.id, firebaseHostingRecipe],
49
- [zodRecipe.id, zodRecipe],
50
- [tailwindRecipe.id, tailwindRecipe],
51
- [huskyRecipe.id, huskyRecipe],
52
- [npsRecipe.id, npsRecipe],
53
- [oxlintRecipe.id, oxlintRecipe],
54
- [oxfmtRecipe.id, oxfmtRecipe],
55
- [strykerRecipe.id, strykerRecipe],
56
- ]);
57
- export function getPackageRecipe(id) {
58
- const recipe = RECIPES.get(id);
59
- if (!recipe)
60
- throw new Error(`Unknown predefined package: ${id}`);
61
- return recipe;
62
- }
63
- export function listPackageRecipes() {
64
- return [...RECIPES.values()];
65
- }
@@ -1,8 +0,0 @@
1
- import type { PackageRecipe, PackageResolution } from './types.ts';
2
- export type PackageResolutionContext = {
3
- registeredPackageIds: Iterable<string>;
4
- presentPackageIds?: Iterable<string>;
5
- knownRecipes?: Iterable<PackageRecipe>;
6
- };
7
- export declare function resolvePackageAddition(recipe: PackageRecipe, context: PackageResolutionContext): PackageResolution;
8
- export declare function installedPackageIds(state: any): string[];
@@ -1,35 +0,0 @@
1
- export function resolvePackageAddition(recipe, context) {
2
- const registered = new Set(context.registeredPackageIds);
3
- const present = new Set(context.presentPackageIds ?? context.registeredPackageIds);
4
- const knownRecipes = [...(context.knownRecipes ?? [])];
5
- const missing = (recipe.requires ?? []).filter((id) => !registered.has(id));
6
- if (missing.length) {
7
- throw new Error(recipe.id + ' requires package' + (missing.length === 1 ? '' : 's') + ': ' + missing.join(', '));
8
- }
9
- const available = new Set([...registered, ...present]);
10
- const directConflicts = (recipe.conflicts ?? []).filter((id) => available.has(id));
11
- const reverseConflicts = knownRecipes
12
- .filter((candidate) => available.has(candidate.id) && (candidate.conflicts ?? []).includes(recipe.id))
13
- .map((candidate) => candidate.id);
14
- const conflicts = [...new Set([...directConflicts, ...reverseConflicts])].sort();
15
- if (conflicts.length) {
16
- throw new Error(recipe.id + ' conflicts with present package' + (conflicts.length === 1 ? '' : 's') + ': ' + conflicts.join(', '));
17
- }
18
- const variantEnvironment = new Set([...available, recipe.id]);
19
- const variants = recipe.variants ?? [];
20
- if (!variants.length)
21
- return { variant: null };
22
- const matches = variants.filter((variant) => variant.when.every((id) => variantEnvironment.has(id)));
23
- if (matches.length === 0)
24
- throw new Error(recipe.id + ' has no compatible variant for the present packages');
25
- if (matches.length > 1) {
26
- throw new Error(recipe.id + ' has multiple compatible variants: ' + matches.map((item) => item.id).join(', '));
27
- }
28
- return { variant: matches[0].id };
29
- }
30
- export function installedPackageIds(state) {
31
- return Object.entries(state?.installed ?? {})
32
- .filter(([, value]) => value?.kind === 'package')
33
- .map(([id]) => id)
34
- .sort();
35
- }
@@ -1,2 +0,0 @@
1
- import type { PackageRecipe } from './types.ts';
2
- export declare const sentryRecipe: PackageRecipe;
@@ -1,29 +0,0 @@
1
- import { detectDependency } from "./package-json.js";
2
- export const sentryRecipe = {
3
- id: 'sentry',
4
- recipeVersion: '1.0.0',
5
- role: 'integration',
6
- variants: [
7
- { id: 'vite', when: ['vite'] },
8
- { id: 'expo', when: ['expo'] },
9
- ],
10
- async detect(projectRoot) {
11
- const expo = await detectDependency(projectRoot, 'expo', 'Expo');
12
- return expo.present
13
- ? await detectDependency(projectRoot, '@sentry/react-native', '@sentry/react-native')
14
- : await detectDependency(projectRoot, '@sentry/react', '@sentry/react');
15
- },
16
- async apply(projectRoot, detection, resolution) {
17
- if (!detection.present) {
18
- throw new Error('Sentry is not installed; creating a Sentry integration is not supported by `add sentry` yet.');
19
- }
20
- const expected = resolution.variant === 'expo' ? '@sentry/react-native' : '@sentry/react';
21
- const expectedDetection = await detectDependency(projectRoot, expected, expected);
22
- if (!expectedDetection.present) {
23
- throw new Error(`Sentry ${resolution.variant ?? 'project'} variant requires ${expected}`);
24
- }
25
- if (!detection.compatible)
26
- throw new Error(detection.reason ?? 'Existing Sentry integration is not compatible.');
27
- return { source: 'adopted' };
28
- },
29
- };
@@ -1,2 +0,0 @@
1
- import type { PackageRecipe } from './types.ts';
2
- export declare const shadcnRecipe: PackageRecipe;
@@ -1,23 +0,0 @@
1
- import { detectAnyDependency } from "./package-json.js";
2
- import { pathExists } from "./project-signals.js";
3
- export const shadcnRecipe = {
4
- id: 'shadcn',
5
- recipeVersion: '1.0.2',
6
- role: 'integration',
7
- requires: ['tailwind'],
8
- async detect(projectRoot) {
9
- if (!(await pathExists(projectRoot, 'components.json'))) {
10
- return { present: false, compatible: false, detectedVersion: null, reason: 'components.json was not found' };
11
- }
12
- const dependency = await detectAnyDependency(projectRoot, ['shadcn', '@shadcn/react'], 'shadcn');
13
- return { present: true, compatible: true, detectedVersion: dependency.present ? dependency.detectedVersion : null };
14
- },
15
- async apply(_projectRoot, detection, _resolution) {
16
- if (!detection.present) {
17
- throw new Error('Shadcn is not configured; creating Shadcn configuration is not supported by `add shadcn` yet.');
18
- }
19
- if (!detection.compatible)
20
- throw new Error(detection.reason ?? 'Existing Shadcn integration is not compatible.');
21
- return { source: 'adopted' };
22
- },
23
- };
@@ -1,2 +0,0 @@
1
- import type { PackageRecipe } from './types.ts';
2
- export declare const storybookRecipe: PackageRecipe;
@@ -1,25 +0,0 @@
1
- import { detectAnyDependency, detectDependency } from "./package-json.js";
2
- export const storybookRecipe = {
3
- id: 'storybook',
4
- recipeVersion: '1.0.0',
5
- role: 'integration',
6
- variants: [
7
- { id: 'vite', when: ['vite'] },
8
- { id: 'expo', when: ['expo'] },
9
- ],
10
- async detect(projectRoot) {
11
- const expo = await detectDependency(projectRoot, 'expo', 'Expo');
12
- return expo.present
13
- ? await detectDependency(projectRoot, '@storybook/react-native', '@storybook/react-native')
14
- : await detectAnyDependency(projectRoot, ['@storybook/react-vite', 'storybook'], 'Storybook');
15
- },
16
- async apply(projectRoot, detection, resolution) {
17
- if (!detection.present)
18
- throw new Error('Storybook is not installed; creating Storybook configuration is not supported by `add storybook` yet.');
19
- const expected = resolution.variant === 'expo' ? ['@storybook/react-native'] : ['@storybook/react-vite', 'storybook'];
20
- const compatible = await detectAnyDependency(projectRoot, expected, 'compatible Storybook renderer');
21
- if (!compatible.present)
22
- throw new Error(`Storybook ${resolution.variant ?? 'project'} variant is not configured with a compatible renderer`);
23
- return { source: 'adopted' };
24
- },
25
- };
@@ -1,2 +0,0 @@
1
- import type { PackageRecipe } from './types.ts';
2
- export declare const strykerRecipe: PackageRecipe;
@@ -1,48 +0,0 @@
1
- import { installPackageJsonPatch, writeProjectFileIfMissing } from "./install.js";
2
- import { detectDependency } from "./package-json.js";
3
- import { detectAnyPath } from "./project-signals.js";
4
- const config = `export default {
5
- testRunner: 'vitest',
6
- reporters: ['progress', 'clear-text'],
7
- mutate: [
8
- 'src/**/*.{ts,tsx}',
9
- '!src/**/*.test.{ts,tsx}',
10
- '!src/**/*.stories.{ts,tsx}',
11
- ],
12
- };
13
- `;
14
- export const strykerRecipe = {
15
- id: 'stryker',
16
- recipeVersion: '1.1.0',
17
- role: 'tooling',
18
- requires: ['vitest'],
19
- async detect(projectRoot) {
20
- const core = await detectDependency(projectRoot, '@stryker-mutator/core', '@stryker-mutator/core');
21
- if (!core.present)
22
- return core;
23
- const runner = await detectDependency(projectRoot, '@stryker-mutator/vitest-runner', '@stryker-mutator/vitest-runner');
24
- if (!runner.present) {
25
- return { ...core, compatible: false, reason: '@stryker-mutator/vitest-runner was not found' };
26
- }
27
- const configDetection = await detectAnyPath(projectRoot, ['stryker.config.mjs', 'stryker.config.js', 'stryker.config.cjs', 'stryker.config.ts', 'stryker.conf.json'], 'Stryker configuration was not found');
28
- if (!configDetection.present)
29
- return { ...core, compatible: false, reason: configDetection.reason };
30
- return core;
31
- },
32
- async apply(projectRoot, detection, _resolution, context) {
33
- if (detection.present) {
34
- if (!detection.compatible)
35
- throw new Error(detection.reason ?? 'Existing Stryker integration is not compatible.');
36
- return { source: 'adopted' };
37
- }
38
- await writeProjectFileIfMissing(projectRoot, 'stryker.config.mjs', config);
39
- await installPackageJsonPatch(projectRoot, context.runCommand, {
40
- devDependencies: {
41
- '@stryker-mutator/core': '10.0.0',
42
- '@stryker-mutator/vitest-runner': '10.0.0',
43
- },
44
- scripts: { 'test:mutation': 'stryker run' },
45
- });
46
- return { source: 'installed' };
47
- },
48
- };
@@ -1,2 +0,0 @@
1
- import type { PackageRecipe } from './types.ts';
2
- export declare const supabaseRecipe: PackageRecipe;
@@ -1,355 +0,0 @@
1
- import { readFile, writeFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { ensurePnpmBuildPolicy, mergeMissing, projectPackageName, updatePackageJson, writeProjectFileIfMissing, } from "./install.js";
4
- import { detectDependency } from "./package-json.js";
5
- const bootstrapDatabaseTypes = `export type Database = {
6
- public: {
7
- Tables: {};
8
- Views: {};
9
- Functions: {};
10
- Enums: {};
11
- CompositeTypes: {};
12
- };
13
- };
14
- `;
15
- const bootstrapSchema = `// generated schema placeholder; regenerate after defining database tables.
16
- export {};
17
- `;
18
- const humanRemoteGuard = `const HUMAN_ACK = 'I_AM_A_HUMAN_RUNNING_REMOTE_INFRASTRUCTURE';
19
-
20
- const operationIndex = process.argv.indexOf('--operation');
21
- const operation = operationIndex >= 0 ? process.argv[operationIndex + 1] : undefined;
22
-
23
- if (!operation) {
24
- console.error('Remote-operation guard requires --operation <name>.');
25
- process.exit(1);
26
- }
27
-
28
- if (process.env.SPECDEST_HUMAN_REMOTE_ACK !== HUMAN_ACK) {
29
- console.error(
30
- \`Blocked \${operation}: set SPECDEST_HUMAN_REMOTE_ACK=\${HUMAN_ACK} only from an interactive human shell.\`,
31
- );
32
- process.exit(1);
33
- }
34
-
35
- if (!process.stdin.isTTY || !process.stdout.isTTY) {
36
- console.error(\`Blocked \${operation}: remote infrastructure commands require an interactive TTY.\`);
37
- process.exit(1);
38
- }
39
-
40
- console.log(\`Human-only remote operation approved: \${operation}\`);
41
- `;
42
- const productionReconcile = `const { spawnSync } = require('node:child_process');
43
- const fs = require('node:fs');
44
- const path = require('node:path');
45
-
46
- const MIGRATION_PREFIX = /^(\\d{14})_/;
47
-
48
- function formatMigrationTimestamp(date) {
49
- const pad = (value) => String(value).padStart(2, '0');
50
- return [
51
- date.getUTCFullYear(),
52
- pad(date.getUTCMonth() + 1),
53
- pad(date.getUTCDate()),
54
- pad(date.getUTCHours()),
55
- pad(date.getUTCMinutes()),
56
- pad(date.getUTCSeconds()),
57
- ].join('');
58
- }
59
-
60
- function parseMigrationTimestamp(value) {
61
- const year = Number(value.slice(0, 4));
62
- const month = Number(value.slice(4, 6)) - 1;
63
- const day = Number(value.slice(6, 8));
64
- const hour = Number(value.slice(8, 10));
65
- const minute = Number(value.slice(10, 12));
66
- const second = Number(value.slice(12, 14));
67
- return new Date(Date.UTC(year, month, day, hour, minute, second));
68
- }
69
-
70
- function nextMigrationTimestamp({ migrationsDir, now }) {
71
- const current = formatMigrationTimestamp(now);
72
- const latest = fs
73
- .readdirSync(migrationsDir)
74
- .map((name) => name.match(MIGRATION_PREFIX)?.[1])
75
- .filter(Boolean)
76
- .sort()
77
- .at(-1);
78
-
79
- if (!latest) {
80
- const previousSecond = new Date(now);
81
- previousSecond.setUTCSeconds(previousSecond.getUTCSeconds() - 1);
82
- return formatMigrationTimestamp(previousSecond);
83
- }
84
-
85
- const next = parseMigrationTimestamp(latest);
86
- next.setUTCSeconds(next.getUTCSeconds() + 1);
87
- const candidate = formatMigrationTimestamp(next);
88
- if (candidate >= current) {
89
- throw new Error(
90
- 'Cannot place production reconciliation before the next generated migration; retry after the clock advances.',
91
- );
92
- }
93
- return candidate;
94
- }
95
-
96
- function isIdentifier(value) {
97
- return /^[A-Za-z_][A-Za-z0-9_]*$/.test(value) || (value.startsWith('"') && value.endsWith('"'));
98
- }
99
-
100
- function matchesQualifiedStatement(trimmed, prefix, suffix) {
101
- if (!trimmed.startsWith(prefix) || !trimmed.endsWith(suffix)) return false;
102
- return isIdentifier(trimmed.slice(prefix.length, -suffix.length));
103
- }
104
-
105
- function isReplaySafeStatement(line) {
106
- const trimmed = line.trim();
107
- if (!trimmed) return false;
108
- if (
109
- ['ALTER TABLE public.', 'ALTER TABLE "public".'].some((prefix) =>
110
- matchesQualifiedStatement(trimmed, prefix, ' ENABLE ROW LEVEL SECURITY;'),
111
- )
112
- ) {
113
- return true;
114
- }
115
- return ['ALTER VIEW public.', 'ALTER VIEW "public".'].some((prefix) =>
116
- [
117
- ' SET (security_invoker=true);',
118
- ' SET (security_invoker = true);',
119
- ].some((suffix) => matchesQualifiedStatement(trimmed, prefix, suffix)),
120
- );
121
- }
122
-
123
- function isIgnorableDiffPreamble(line) {
124
- return line.trim() === 'SET check_function_bodies = false;';
125
- }
126
-
127
- function extractReplaySafeSql(sql) {
128
- const safe = [];
129
- const unsafe = [];
130
- for (const line of sql.split(/\\r?\\n/)) {
131
- if (!line.trim() || isIgnorableDiffPreamble(line)) continue;
132
- if (isReplaySafeStatement(line)) safe.push(line.trim());
133
- else unsafe.push(line);
134
- }
135
- return {
136
- safeSql: safe.length > 0 ? \`\${safe.join('\\n')}\\n\` : '',
137
- unsafeSql: unsafe.length > 0 ? \`\${unsafe.join('\\n')}\\n\` : '',
138
- };
139
- }
140
-
141
- function persistMigration({ migrationsDir, sql, now = new Date() }) {
142
- if (!sql.trim()) return null;
143
- fs.mkdirSync(migrationsDir, { recursive: true });
144
- const timestamp = nextMigrationTimestamp({ migrationsDir, now });
145
- const outputPath = path.join(migrationsDir, \`\${timestamp}_production_reconcile.sql\`);
146
- fs.writeFileSync(outputPath, \`\${sql.trimEnd()}\\n\`, { flag: 'wx' });
147
- return outputPath;
148
- }
149
-
150
- function persistReview({ reviewPath, sql }) {
151
- if (!sql.trim()) return null;
152
- fs.mkdirSync(path.dirname(reviewPath), { recursive: true });
153
- fs.writeFileSync(reviewPath, \`\${sql.trimEnd()}\\n\`);
154
- return reviewPath;
155
- }
156
-
157
- function run() {
158
- const dbUrl = process.env.SUPABASE_DB_URL;
159
- if (!dbUrl) throw new Error('SUPABASE_DB_URL is required');
160
-
161
- const result = spawnSync(
162
- 'pnpm',
163
- ['exec', 'supabase', 'db', 'diff', '--from', dbUrl, '--to', 'migrations'],
164
- {
165
- cwd: process.cwd(),
166
- encoding: 'utf8',
167
- env: process.env,
168
- maxBuffer: 50 * 1024 * 1024,
169
- stdio: ['inherit', 'pipe', 'inherit'],
170
- },
171
- );
172
-
173
- if (result.error) throw result.error;
174
- if (result.status !== 0) process.exit(result.status ?? 1);
175
-
176
- const rawSql = result.stdout ?? '';
177
- if (rawSql) process.stdout.write(rawSql);
178
- const { safeSql, unsafeSql } = extractReplaySafeSql(rawSql);
179
-
180
- if (unsafeSql) {
181
- const reviewPath = persistReview({
182
- reviewPath: path.resolve('supabase/.temp/production-reconcile-review.sql'),
183
- sql: rawSql,
184
- });
185
- console.error(
186
- \`Blocked production reconciliation: non-replay-safe drift detected. Review \${reviewPath}.\`,
187
- );
188
- process.exit(1);
189
- }
190
-
191
- const migrationPath = persistMigration({
192
- migrationsDir: path.resolve('supabase/migrations'),
193
- sql: safeSql,
194
- });
195
- if (migrationPath) console.error(\`Created replay-safe reconciliation migration at \${migrationPath}\`);
196
- else console.error('No production schema drift detected.');
197
- }
198
-
199
- if (require.main === module) run();
200
-
201
- module.exports = {
202
- extractReplaySafeSql,
203
- formatMigrationTimestamp,
204
- isReplaySafeStatement,
205
- nextMigrationTimestamp,
206
- persistMigration,
207
- persistReview,
208
- run,
209
- };
210
- `;
211
- const productionOperations = `#!/usr/bin/env bash
212
- set -euo pipefail
213
- cd "$(dirname "\${BASH_SOURCE[0]}")/../.."
214
-
215
- operation="\${1:-}"
216
- case "$operation" in
217
- reconcile|migrationGen|migrate|push|squash|generate|release) ;;
218
- *) echo 'Unsupported production database operation' >&2; exit 2 ;;
219
- esac
220
-
221
- # No production configuration is accessed before the human-only check.
222
- node scripts/safety/require-human-remote-operation.cjs --operation "prod.db.$operation"
223
- source ./supabase/.env.production
224
- : "\${SUPABASE_DB_URL:?SUPABASE_DB_URL must be configured}"
225
- export SUPABASE_DB_URL
226
-
227
- case "$operation" in
228
- reconcile)
229
- node scripts/db/generate-production-reconcile.cjs
230
- ;;
231
- migrationGen)
232
- pnpm exec supabase db schema declarative sync --experimental --no-apply --name schema_change
233
- ;;
234
- migrate)
235
- bash "$0" reconcile
236
- bash "$0" migrationGen
237
- pnpm exec supabase db push --db-url "$SUPABASE_DB_URL" --include-all
238
- ;;
239
- push)
240
- pnpm exec supabase db push --db-url "$SUPABASE_DB_URL" --yes
241
- ;;
242
- squash)
243
- pnpm exec supabase migration squash --db-url "$SUPABASE_DB_URL" --yes
244
- ;;
245
- generate)
246
- types_tmp="$(mktemp ./src/__generated__/.db-types-XXXXXX)"
247
- trap 'rm -f "$types_tmp"' EXIT
248
- pnpm exec supabase gen types typescript --db-url "$SUPABASE_DB_URL" > "$types_tmp"
249
- mv "$types_tmp" src/__generated__/database.ts
250
- trap - EXIT
251
- ;;
252
- release)
253
- bash "$0" reconcile
254
- bash "$0" migrationGen
255
- bash "$0" push
256
- bash "$0" squash
257
- bash "$0" generate
258
- ;;
259
- esac
260
- `;
261
- async function installSupabase(projectRoot, context) {
262
- const pkg = await updatePackageJson(projectRoot, (currentPackage) => ({
263
- ...currentPackage,
264
- name: currentPackage.name ?? projectPackageName(projectRoot),
265
- private: currentPackage.private ?? true,
266
- packageManager: currentPackage.packageManager ?? 'pnpm@11.6.0',
267
- engines: {
268
- ...currentPackage.engines,
269
- node: currentPackage.engines?.node ?? '>=24.0.0',
270
- pnpm: currentPackage.engines?.pnpm ?? '>=11.0.0',
271
- },
272
- scripts: mergeMissing(currentPackage.scripts, {
273
- 'supabase:start': 'supabase start',
274
- 'supabase:stop': 'supabase stop',
275
- 'db:types:local': 'supabase gen types typescript --local',
276
- }),
277
- dependencies: mergeMissing(currentPackage.dependencies, {
278
- '@supabase/supabase-js': '2.103.0',
279
- }),
280
- devDependencies: mergeMissing(currentPackage.devDependencies, {
281
- supabase: '2.118.0',
282
- }),
283
- }));
284
- await ensurePnpmBuildPolicy(projectRoot);
285
- await writeProjectFileIfMissing(projectRoot, 'supabase/config.toml', `project_id = "${pkg.name}"
286
-
287
- [db.migrations]
288
- enabled = true
289
- schema_paths = ["./schemas/*.sql"]
290
-
291
- [experimental.pgdelta]
292
- enabled = true
293
- declarative_schema_path = "./schemas"
294
- `);
295
- await writeProjectFileIfMissing(projectRoot, 'supabase/schemas/000_base.sql', 'create schema if not exists public;\n');
296
- await writeProjectFileIfMissing(projectRoot, 'src/__generated__/database.ts', bootstrapDatabaseTypes);
297
- await writeProjectFileIfMissing(projectRoot, 'src/__generated__/schema.ts', bootstrapSchema);
298
- await writeProjectFileIfMissing(projectRoot, 'scripts/safety/require-human-remote-operation.cjs', humanRemoteGuard);
299
- await writeProjectFileIfMissing(projectRoot, 'scripts/db/generate-production-reconcile.cjs', productionReconcile);
300
- await writeProjectFileIfMissing(projectRoot, 'scripts/db/run-production-operation.sh', productionOperations);
301
- const supabaseScripts = `scripts:
302
- local:
303
- db:
304
- start: pnpm exec supabase start
305
- stop: pnpm exec supabase stop
306
- status: pnpm exec supabase status
307
- migrationGen: pnpm exec supabase db schema declarative sync --experimental --no-apply --name schema_change
308
- generate: pnpm exec supabase gen types typescript --local > src/__generated__/database.ts
309
- prod:
310
- db:
311
- reconcile: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.reconcile && bash scripts/db/run-production-operation.sh reconcile
312
- migrationGen: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.migrationGen && bash scripts/db/run-production-operation.sh migrationGen
313
- migrate: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.migrate && bash scripts/db/run-production-operation.sh migrate
314
- push: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.push && bash scripts/db/run-production-operation.sh push
315
- squash: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.squash && bash scripts/db/run-production-operation.sh squash
316
- generate: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.generate && bash scripts/db/run-production-operation.sh generate
317
- release: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.release && bash scripts/db/run-production-operation.sh release
318
- `;
319
- const scriptPath = join(projectRoot, 'package-scripts.yml');
320
- let existingScripts;
321
- try {
322
- existingScripts = await readFile(scriptPath, 'utf8');
323
- }
324
- catch (error) {
325
- if (error.code !== 'ENOENT')
326
- throw error;
327
- }
328
- if (existingScripts === undefined) {
329
- await writeFile(scriptPath, supabaseScripts);
330
- }
331
- else if (existingScripts === 'scripts:\n check: pnpm run typecheck\n') {
332
- // Only extend Devkit's untouched NPS bootstrap; never rewrite project-owned scripts.
333
- await writeFile(scriptPath, supabaseScripts.replace('scripts:\n', existingScripts));
334
- }
335
- await context.runCommand('pnpm', ['install', '--no-frozen-lockfile'], { cwd: projectRoot });
336
- }
337
- export const supabaseRecipe = {
338
- id: 'supabase',
339
- recipeVersion: '1.3.0',
340
- role: 'backend',
341
- setupRequirements: [{ kind: 'package', packageId: 'nps', required: true }],
342
- conflicts: ['convex'],
343
- async detect(projectRoot) {
344
- return await detectDependency(projectRoot, '@supabase/supabase-js', '@supabase/supabase-js');
345
- },
346
- async apply(projectRoot, detection, _resolution, context) {
347
- if (detection.present) {
348
- if (!detection.compatible)
349
- throw new Error(detection.reason ?? 'Existing Supabase setup is not compatible.');
350
- return { source: 'adopted' };
351
- }
352
- await installSupabase(projectRoot, context);
353
- return { source: 'installed' };
354
- },
355
- };
@@ -1,2 +0,0 @@
1
- import type { PackageRecipe } from './types.ts';
2
- export declare const tailwindRecipe: PackageRecipe;
@@ -1,18 +0,0 @@
1
- import { detectDependency } from "./package-json.js";
2
- export const tailwindRecipe = {
3
- id: 'tailwind',
4
- recipeVersion: '1.0.0',
5
- role: 'integration',
6
- requires: ['vite'],
7
- async detect(projectRoot) {
8
- return await detectDependency(projectRoot, 'tailwindcss', 'Tailwind CSS');
9
- },
10
- async apply(_projectRoot, detection, _resolution) {
11
- if (!detection.present) {
12
- throw new Error('Tailwind CSS is not installed; creating Tailwind configuration is not supported by `add tailwind` yet.');
13
- }
14
- if (!detection.compatible)
15
- throw new Error(detection.reason ?? 'Existing Tailwind integration is not compatible.');
16
- return { source: 'adopted' };
17
- },
18
- };
@@ -1,2 +0,0 @@
1
- import type { PackageRecipe } from './types.ts';
2
- export declare const tanstackFormRecipe: PackageRecipe;
@@ -1,19 +0,0 @@
1
- import { installPackageJsonPatch } from "./install.js";
2
- import { detectDependency } from "./package-json.js";
3
- export const tanstackFormRecipe = {
4
- id: 'tanstack-form',
5
- recipeVersion: '1.1.0',
6
- role: 'integration',
7
- requires: ['zod'],
8
- async detect(projectRoot) {
9
- return await detectDependency(projectRoot, '@tanstack/react-form', '@tanstack/react-form');
10
- },
11
- async apply(projectRoot, detection, _resolution, context) {
12
- if (detection.present)
13
- return { source: 'adopted' };
14
- await installPackageJsonPatch(projectRoot, context.runCommand, {
15
- dependencies: { '@tanstack/react-form': '1.0.0' },
16
- });
17
- return { source: 'installed' };
18
- },
19
- };
@@ -1,2 +0,0 @@
1
- import type { PackageRecipe } from './types.ts';
2
- export declare const tanstackQueryRecipe: PackageRecipe;