@specdest/devkit 0.4.6 → 0.4.9

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 (131) hide show
  1. package/README.md +52 -20
  2. package/dist/npm/canonical-project-operations.d.ts +5 -0
  3. package/dist/npm/canonical-project-operations.js +5 -0
  4. package/dist/npm/canonical-project.d.ts +21 -0
  5. package/dist/npm/canonical-project.js +115 -0
  6. package/dist/npm/canonical-source.d.ts +26 -0
  7. package/dist/npm/canonical-source.js +248 -0
  8. package/dist/npm/catalog-snapshot.d.ts +53 -0
  9. package/dist/npm/catalog-snapshot.js +35 -0
  10. package/dist/npm/cli.d.ts +2 -0
  11. package/dist/npm/cli.js +18 -0
  12. package/dist/npm/commands.d.ts +15 -0
  13. package/dist/npm/commands.js +182 -0
  14. package/dist/npm/flow.d.ts +48 -0
  15. package/dist/npm/flow.js +430 -0
  16. package/dist/npm/git-catalog.d.ts +40 -0
  17. package/dist/npm/git-catalog.js +222 -0
  18. package/dist/npm/index.d.ts +4 -0
  19. package/dist/npm/index.js +32 -0
  20. package/dist/npm/installer-primitives.d.ts +3 -0
  21. package/dist/npm/installer-primitives.js +50 -0
  22. package/dist/npm/predefined-packages/abac.d.ts +2 -0
  23. package/dist/npm/predefined-packages/abac.js +22 -0
  24. package/dist/npm/predefined-packages/auth.d.ts +2 -0
  25. package/dist/npm/predefined-packages/auth.js +21 -0
  26. package/dist/npm/predefined-packages/convex.d.ts +2 -0
  27. package/dist/npm/predefined-packages/convex.js +53 -0
  28. package/dist/npm/predefined-packages/expo.d.ts +2 -0
  29. package/dist/npm/predefined-packages/expo.js +88 -0
  30. package/dist/npm/predefined-packages/firebase-hosting.d.ts +2 -0
  31. package/dist/npm/predefined-packages/firebase-hosting.js +24 -0
  32. package/dist/npm/predefined-packages/health.d.ts +10 -0
  33. package/dist/npm/predefined-packages/health.js +52 -0
  34. package/dist/npm/predefined-packages/husky.d.ts +2 -0
  35. package/dist/npm/predefined-packages/husky.js +57 -0
  36. package/dist/npm/predefined-packages/index.d.ts +12 -0
  37. package/dist/npm/predefined-packages/index.js +97 -0
  38. package/dist/npm/predefined-packages/install.d.ts +19 -0
  39. package/dist/npm/predefined-packages/install.js +86 -0
  40. package/dist/npm/predefined-packages/local-logging.d.ts +2 -0
  41. package/dist/npm/predefined-packages/local-logging.js +17 -0
  42. package/dist/npm/predefined-packages/logging.d.ts +2 -0
  43. package/dist/npm/predefined-packages/logging.js +21 -0
  44. package/dist/npm/predefined-packages/multi-tenancy.d.ts +2 -0
  45. package/dist/npm/predefined-packages/multi-tenancy.js +21 -0
  46. package/dist/npm/predefined-packages/nps.d.ts +2 -0
  47. package/dist/npm/predefined-packages/nps.js +32 -0
  48. package/dist/npm/predefined-packages/oxfmt.d.ts +2 -0
  49. package/dist/npm/predefined-packages/oxfmt.js +22 -0
  50. package/dist/npm/predefined-packages/oxlint.d.ts +2 -0
  51. package/dist/npm/predefined-packages/oxlint.js +35 -0
  52. package/dist/npm/predefined-packages/package-json.d.ts +3 -0
  53. package/dist/npm/predefined-packages/package-json.js +61 -0
  54. package/dist/npm/predefined-packages/payments.d.ts +2 -0
  55. package/dist/npm/predefined-packages/payments.js +31 -0
  56. package/dist/npm/predefined-packages/playwright.d.ts +2 -0
  57. package/dist/npm/predefined-packages/playwright.js +35 -0
  58. package/dist/npm/predefined-packages/project-signals.d.ts +4 -0
  59. package/dist/npm/predefined-packages/project-signals.js +39 -0
  60. package/dist/npm/predefined-packages/registry.d.ts +3 -0
  61. package/dist/npm/predefined-packages/registry.js +63 -0
  62. package/dist/npm/predefined-packages/resolver.d.ts +8 -0
  63. package/dist/npm/predefined-packages/resolver.js +35 -0
  64. package/dist/npm/predefined-packages/sentry.d.ts +2 -0
  65. package/dist/npm/predefined-packages/sentry.js +29 -0
  66. package/dist/npm/predefined-packages/shadcn.d.ts +2 -0
  67. package/dist/npm/predefined-packages/shadcn.js +23 -0
  68. package/dist/npm/predefined-packages/storybook.d.ts +2 -0
  69. package/dist/npm/predefined-packages/storybook.js +25 -0
  70. package/dist/npm/predefined-packages/stryker.d.ts +2 -0
  71. package/dist/npm/predefined-packages/stryker.js +48 -0
  72. package/dist/npm/predefined-packages/supabase.d.ts +2 -0
  73. package/dist/npm/predefined-packages/supabase.js +335 -0
  74. package/dist/npm/predefined-packages/tailwind.d.ts +2 -0
  75. package/dist/npm/predefined-packages/tailwind.js +18 -0
  76. package/dist/npm/predefined-packages/tanstack-form.d.ts +2 -0
  77. package/dist/npm/predefined-packages/tanstack-form.js +19 -0
  78. package/dist/npm/predefined-packages/tanstack-query.d.ts +2 -0
  79. package/dist/npm/predefined-packages/tanstack-query.js +15 -0
  80. package/dist/npm/predefined-packages/tanstack-router.d.ts +2 -0
  81. package/dist/npm/predefined-packages/tanstack-router.js +18 -0
  82. package/dist/npm/predefined-packages/types.d.ts +38 -0
  83. package/dist/npm/predefined-packages/types.js +1 -0
  84. package/dist/npm/predefined-packages/vite.d.ts +2 -0
  85. package/dist/npm/predefined-packages/vite.js +127 -0
  86. package/dist/npm/predefined-packages/vitest.d.ts +2 -0
  87. package/dist/npm/predefined-packages/vitest.js +20 -0
  88. package/dist/npm/predefined-packages/zod.d.ts +2 -0
  89. package/dist/npm/predefined-packages/zod.js +18 -0
  90. package/dist/npm/project-check.d.ts +14 -0
  91. package/dist/npm/project-check.js +118 -0
  92. package/dist/npm/project-context.d.ts +52 -0
  93. package/dist/npm/project-context.js +206 -0
  94. package/dist/npm/project-rules.d.ts +25 -0
  95. package/dist/npm/project-rules.js +75 -0
  96. package/dist/npm/project-runtime.d.ts +21 -0
  97. package/dist/npm/project-runtime.js +41 -0
  98. package/dist/npm/project-status.d.ts +32 -0
  99. package/dist/npm/project-status.js +70 -0
  100. package/dist/npm/project-sync.d.ts +7 -0
  101. package/dist/npm/project-sync.js +143 -0
  102. package/dist/npm/remote-installer.d.ts +35 -0
  103. package/dist/npm/remote-installer.js +351 -0
  104. package/dist/npm/rule-id-migrations.d.ts +6 -0
  105. package/dist/npm/rule-id-migrations.js +19 -0
  106. package/dist/npm/schemas.d.ts +64 -0
  107. package/dist/npm/schemas.js +194 -0
  108. package/dist/npm/slack.d.ts +16 -0
  109. package/dist/npm/slack.js +131 -0
  110. package/dist/npm/state.d.ts +14 -0
  111. package/dist/npm/state.js +231 -0
  112. package/dist/npm/supabase-local.d.ts +2 -0
  113. package/dist/npm/supabase-local.js +62 -0
  114. package/package.json +18 -12
  115. package/src/canonical-project-operations.js +0 -438
  116. package/src/canonical-project.js +0 -136
  117. package/src/canonical-source.js +0 -250
  118. package/src/catalog-snapshot.js +0 -39
  119. package/src/catalog.js +0 -117
  120. package/src/cli.js +0 -14
  121. package/src/fuzz.js +0 -291
  122. package/src/git-catalog.js +0 -177
  123. package/src/index.js +0 -36
  124. package/src/installer-primitives.js +0 -198
  125. package/src/project-operations.js +0 -189
  126. package/src/project-targeting.js +0 -48
  127. package/src/remote-installer.js +0 -479
  128. package/src/rule-profile.js +0 -61
  129. package/src/setup-requirements.js +0 -82
  130. package/src/shared-file.js +0 -131
  131. package/src/sync-core.js +0 -390
@@ -0,0 +1,63 @@
1
+ import { abacRecipe } from "./abac.js";
2
+ import { authRecipe } from "./auth.js";
3
+ import { convexRecipe } from "./convex.js";
4
+ import { expoRecipe } from "./expo.js";
5
+ import { loggingRecipe } from "./logging.js";
6
+ import { multiTenancyRecipe } from "./multi-tenancy.js";
7
+ import { paymentsRecipe } from "./payments.js";
8
+ import { sentryRecipe } from "./sentry.js";
9
+ import { shadcnRecipe } from "./shadcn.js";
10
+ import { supabaseRecipe } from "./supabase.js";
11
+ import { tanstackRouterRecipe } from "./tanstack-router.js";
12
+ import { viteRecipe } from "./vite.js";
13
+ import { firebaseHostingRecipe } from "./firebase-hosting.js";
14
+ import { localLoggingRecipe } from "./local-logging.js";
15
+ import { playwrightRecipe } from "./playwright.js";
16
+ import { storybookRecipe } from "./storybook.js";
17
+ import { tanstackFormRecipe } from "./tanstack-form.js";
18
+ import { tanstackQueryRecipe } from "./tanstack-query.js";
19
+ import { vitestRecipe } from "./vitest.js";
20
+ import { zodRecipe } from "./zod.js";
21
+ import { huskyRecipe } from "./husky.js";
22
+ import { npsRecipe } from "./nps.js";
23
+ import { oxfmtRecipe } from "./oxfmt.js";
24
+ import { oxlintRecipe } from "./oxlint.js";
25
+ import { strykerRecipe } from "./stryker.js";
26
+ import { tailwindRecipe } from "./tailwind.js";
27
+ const RECIPES = new Map([
28
+ [viteRecipe.id, viteRecipe],
29
+ [expoRecipe.id, expoRecipe],
30
+ [supabaseRecipe.id, supabaseRecipe],
31
+ [convexRecipe.id, convexRecipe],
32
+ [authRecipe.id, authRecipe],
33
+ [multiTenancyRecipe.id, multiTenancyRecipe],
34
+ [abacRecipe.id, abacRecipe],
35
+ [sentryRecipe.id, sentryRecipe],
36
+ [loggingRecipe.id, loggingRecipe],
37
+ [paymentsRecipe.id, paymentsRecipe],
38
+ [shadcnRecipe.id, shadcnRecipe],
39
+ [tanstackRouterRecipe.id, tanstackRouterRecipe],
40
+ [tanstackQueryRecipe.id, tanstackQueryRecipe],
41
+ [tanstackFormRecipe.id, tanstackFormRecipe],
42
+ [storybookRecipe.id, storybookRecipe],
43
+ [playwrightRecipe.id, playwrightRecipe],
44
+ [vitestRecipe.id, vitestRecipe],
45
+ [localLoggingRecipe.id, localLoggingRecipe],
46
+ [firebaseHostingRecipe.id, firebaseHostingRecipe],
47
+ [zodRecipe.id, zodRecipe],
48
+ [tailwindRecipe.id, tailwindRecipe],
49
+ [huskyRecipe.id, huskyRecipe],
50
+ [npsRecipe.id, npsRecipe],
51
+ [oxlintRecipe.id, oxlintRecipe],
52
+ [oxfmtRecipe.id, oxfmtRecipe],
53
+ [strykerRecipe.id, strykerRecipe],
54
+ ]);
55
+ export function getPackageRecipe(id) {
56
+ const recipe = RECIPES.get(id);
57
+ if (!recipe)
58
+ throw new Error(`Unknown predefined package: ${id}`);
59
+ return recipe;
60
+ }
61
+ export function listPackageRecipes() {
62
+ return [...RECIPES.values()];
63
+ }
@@ -0,0 +1,8 @@
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[];
@@ -0,0 +1,35 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const sentryRecipe: PackageRecipe;
@@ -0,0 +1,29 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const shadcnRecipe: PackageRecipe;
@@ -0,0 +1,23 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const storybookRecipe: PackageRecipe;
@@ -0,0 +1,25 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const strykerRecipe: PackageRecipe;
@@ -0,0 +1,48 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const supabaseRecipe: PackageRecipe;
@@ -0,0 +1,335 @@
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
+ async function installSupabase(projectRoot, context) {
212
+ const pkg = await updatePackageJson(projectRoot, (currentPackage) => ({
213
+ ...currentPackage,
214
+ name: currentPackage.name ?? projectPackageName(projectRoot),
215
+ private: currentPackage.private ?? true,
216
+ packageManager: currentPackage.packageManager ?? 'pnpm@11.6.0',
217
+ engines: {
218
+ ...currentPackage.engines,
219
+ node: currentPackage.engines?.node ?? '>=24.0.0',
220
+ pnpm: currentPackage.engines?.pnpm ?? '>=11.0.0',
221
+ },
222
+ scripts: mergeMissing(currentPackage.scripts, {
223
+ 'supabase:start': 'supabase start',
224
+ 'supabase:stop': 'supabase stop',
225
+ 'db:types:local': 'supabase gen types typescript --local',
226
+ }),
227
+ dependencies: mergeMissing(currentPackage.dependencies, {
228
+ '@supabase/supabase-js': '2.103.0',
229
+ }),
230
+ devDependencies: mergeMissing(currentPackage.devDependencies, {
231
+ supabase: '2.118.0',
232
+ }),
233
+ }));
234
+ await ensurePnpmBuildPolicy(projectRoot);
235
+ await writeProjectFileIfMissing(projectRoot, 'supabase/config.toml', `project_id = "${pkg.name}"
236
+
237
+ [db.migrations]
238
+ enabled = true
239
+ schema_paths = ["./schemas/*.sql"]
240
+
241
+ [experimental.pgdelta]
242
+ enabled = true
243
+ declarative_schema_path = "./schemas"
244
+ `);
245
+ await writeProjectFileIfMissing(projectRoot, 'supabase/schemas/000_base.sql', 'create schema if not exists public;\n');
246
+ await writeProjectFileIfMissing(projectRoot, 'src/__generated__/database.ts', bootstrapDatabaseTypes);
247
+ await writeProjectFileIfMissing(projectRoot, 'src/__generated__/schema.ts', bootstrapSchema);
248
+ await writeProjectFileIfMissing(projectRoot, 'scripts/safety/require-human-remote-operation.cjs', humanRemoteGuard);
249
+ await writeProjectFileIfMissing(projectRoot, 'scripts/db/generate-production-reconcile.cjs', productionReconcile);
250
+ const supabaseScripts = `scripts:
251
+ local:
252
+ db:
253
+ start: nps db.local.start
254
+ stop: nps db.local.stop
255
+ status: nps db.local.status
256
+ migrate: nps db.local.migrate
257
+ generate: nps db.local.generate
258
+ reset: nps db.local.reset
259
+ prod:
260
+ db:
261
+ migrate: nps db.prod.migrate
262
+ db:
263
+ local:
264
+ start: pnpm exec supabase start
265
+ stop: pnpm exec supabase stop
266
+ status: pnpm exec supabase status
267
+ migrate: nps db.schema.sync && pnpm exec supabase db reset
268
+ generate: pnpm exec supabase gen types typescript --local > src/__generated__/database.ts
269
+ reset: pnpm exec supabase db reset
270
+ prod:
271
+ migrate: node scripts/safety/require-human-remote-operation.cjs --operation db.prod.migrate && nps db.migrate.prod
272
+ schema:
273
+ sync: pnpm exec supabase db schema declarative sync --experimental --no-apply --name declarative_schema
274
+ migrationGen: pnpm exec supabase db schema declarative sync --experimental --no-apply --name schema_change
275
+ migrate:
276
+ reconcileRemote: |-
277
+ node scripts/safety/require-human-remote-operation.cjs --operation db.migrate.reconcileRemote
278
+ SUPABASE_DB_URL="$SUPABASE_DB_URL" node scripts/db/generate-production-reconcile.cjs
279
+ prod: |-
280
+ node scripts/safety/require-human-remote-operation.cjs --operation db.migrate.prod
281
+ nps db.migrate.reconcileRemote
282
+ nps db.schema.sync
283
+ pnpm exec supabase db push --db-url "$SUPABASE_DB_URL" --include-all
284
+ squashYes: |-
285
+ node scripts/safety/require-human-remote-operation.cjs --operation db.migrate.squashYes
286
+ set -e
287
+ pnpm exec supabase migration squash --db-url "$SUPABASE_DB_URL" --yes
288
+ push:
289
+ remoteYes: |-
290
+ node scripts/safety/require-human-remote-operation.cjs --operation db.push.remoteYes
291
+ pnpm exec supabase db push --db-url "$SUPABASE_DB_URL" --yes
292
+ release:
293
+ remote: >-
294
+ node scripts/safety/require-human-remote-operation.cjs --operation db.release.remote && nps db.migrate.reconcileRemote && nps db.migrationGen && nps db.push.remoteYes && nps db.migrate.squashYes && nps db.generate.remote
295
+ generate:
296
+ remote: |-
297
+ pnpm exec supabase gen types typescript --db-url "$SUPABASE_DB_URL" > src/__generated__/database.ts
298
+ `;
299
+ const scriptPath = join(projectRoot, 'package-scripts.yml');
300
+ let existingScripts;
301
+ try {
302
+ existingScripts = await readFile(scriptPath, 'utf8');
303
+ }
304
+ catch (error) {
305
+ if (error.code !== 'ENOENT')
306
+ throw error;
307
+ }
308
+ if (existingScripts === undefined) {
309
+ await writeFile(scriptPath, supabaseScripts);
310
+ }
311
+ else if (existingScripts === 'scripts:\n check: pnpm run typecheck\n') {
312
+ // Only extend Devkit's untouched NPS bootstrap; never rewrite project-owned scripts.
313
+ await writeFile(scriptPath, supabaseScripts.replace('scripts:\n', existingScripts));
314
+ }
315
+ await context.runCommand('pnpm', ['install', '--no-frozen-lockfile'], { cwd: projectRoot });
316
+ }
317
+ export const supabaseRecipe = {
318
+ id: 'supabase',
319
+ recipeVersion: '1.3.0',
320
+ role: 'backend',
321
+ setupRequirements: [{ kind: 'package', packageId: 'nps', required: true }],
322
+ conflicts: ['convex'],
323
+ async detect(projectRoot) {
324
+ return await detectDependency(projectRoot, '@supabase/supabase-js', '@supabase/supabase-js');
325
+ },
326
+ async apply(projectRoot, detection, _resolution, context) {
327
+ if (detection.present) {
328
+ if (!detection.compatible)
329
+ throw new Error(detection.reason ?? 'Existing Supabase setup is not compatible.');
330
+ return { source: 'adopted' };
331
+ }
332
+ await installSupabase(projectRoot, context);
333
+ return { source: 'installed' };
334
+ },
335
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const tailwindRecipe: PackageRecipe;
@@ -0,0 +1,18 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const tanstackFormRecipe: PackageRecipe;
@@ -0,0 +1,19 @@
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
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const tanstackQueryRecipe: PackageRecipe;
@@ -0,0 +1,15 @@
1
+ import { detectDependency } from "./package-json.js";
2
+ export const tanstackQueryRecipe = {
3
+ id: 'tanstack-query',
4
+ recipeVersion: '1.0.1',
5
+ role: 'integration',
6
+ requires: ['supabase'],
7
+ async detect(projectRoot) {
8
+ return await detectDependency(projectRoot, '@tanstack/react-query', '@tanstack/react-query');
9
+ },
10
+ async apply(_projectRoot, detection, _resolution) {
11
+ if (!detection.present)
12
+ throw new Error('TanStack Query is not installed; creating Query configuration is not supported by `add tanstack-query` yet.');
13
+ return { source: 'adopted' };
14
+ },
15
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const tanstackRouterRecipe: PackageRecipe;