@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,57 @@
1
+ import { installPackageJsonPatch, makeProjectFileExecutable, writeProjectFileIfMissing, } from "./install.js";
2
+ import { detectDependency } from "./package-json.js";
3
+ import { pathExists } from "./project-signals.js";
4
+ const preCommit = `#!/bin/sh
5
+ set -eu
6
+
7
+ npx --yes @specdest/devkit check --staged
8
+ pnpm run typecheck
9
+ `;
10
+ const prePush = `#!/bin/sh
11
+ set -eu
12
+
13
+ npx --yes @specdest/devkit check
14
+ `;
15
+ export const huskyRecipe = {
16
+ id: 'husky',
17
+ recipeVersion: '1.1.0',
18
+ role: 'tooling',
19
+ async detect(projectRoot) {
20
+ const dependency = await detectDependency(projectRoot, 'husky', 'Husky');
21
+ if (!dependency.present)
22
+ return dependency;
23
+ const [preCommitExists, prePushExists] = await Promise.all([
24
+ pathExists(projectRoot, '.husky/pre-commit'),
25
+ pathExists(projectRoot, '.husky/pre-push'),
26
+ ]);
27
+ if (!preCommitExists || !prePushExists) {
28
+ return {
29
+ ...dependency,
30
+ compatible: false,
31
+ reason: 'Husky requires both .husky/pre-commit and .husky/pre-push for the Devkit verification contract',
32
+ };
33
+ }
34
+ return dependency;
35
+ },
36
+ async apply(projectRoot, detection, _resolution, context) {
37
+ if (detection.present) {
38
+ if (!detection.compatible)
39
+ throw new Error(detection.reason ?? 'Existing Husky integration is not compatible.');
40
+ return { source: 'adopted' };
41
+ }
42
+ if (!(await pathExists(projectRoot, '.git'))) {
43
+ throw new Error('Husky installation requires a Git repository');
44
+ }
45
+ await writeProjectFileIfMissing(projectRoot, '.husky/pre-commit', preCommit);
46
+ await writeProjectFileIfMissing(projectRoot, '.husky/pre-push', prePush);
47
+ await Promise.all([
48
+ makeProjectFileExecutable(projectRoot, '.husky/pre-commit'),
49
+ makeProjectFileExecutable(projectRoot, '.husky/pre-push'),
50
+ ]);
51
+ await installPackageJsonPatch(projectRoot, context.runCommand, {
52
+ devDependencies: { husky: '9.1.7' },
53
+ scripts: { prepare: 'husky' },
54
+ });
55
+ return { source: 'installed' };
56
+ },
57
+ };
@@ -0,0 +1,12 @@
1
+ import { type PackageCommandRunner } from './install.ts';
2
+ export declare function addPredefinedPackage(projectRoot: string, id: string, options?: {
3
+ runCommand?: PackageCommandRunner;
4
+ }): Promise<{
5
+ setupPackages?: string[] | undefined;
6
+ id: string;
7
+ recipeVersion: string;
8
+ detectedVersion: string | null;
9
+ source: import("./types.ts").PackageSource;
10
+ resolvedVariant: string | null;
11
+ changed: boolean;
12
+ }>;
@@ -0,0 +1,97 @@
1
+ import { getPackageRecipe, listPackageRecipes } from "./registry.js";
2
+ import { runPackageCommand } from "./install.js";
3
+ import { installedPackageIds, resolvePackageAddition } from "./resolver.js";
4
+ import { readInstalledState, writeInstalledState } from "../state.js";
5
+ import { resolveProjectStack, STACK_PACKAGES } from "../project-context.js";
6
+ import { pathExists } from "./project-signals.js";
7
+ async function requiredSetupPackageIds(projectRoot, stack) {
8
+ const result = new Set();
9
+ const hasGit = await pathExists(projectRoot, '.git');
10
+ for (const foundationId of STACK_PACKAGES[stack] ?? []) {
11
+ const foundation = getPackageRecipe(foundationId);
12
+ for (const requirement of foundation.setupRequirements ?? []) {
13
+ if (requirement.kind !== 'package' || !requirement.required)
14
+ continue;
15
+ if (requirement.when === 'git' && !hasGit)
16
+ continue;
17
+ result.add(requirement.packageId);
18
+ }
19
+ }
20
+ return [...result].sort();
21
+ }
22
+ async function ensureResolvedStackSetup(projectRoot, options) {
23
+ const stack = await resolveProjectStack(projectRoot);
24
+ if (!stack)
25
+ return [];
26
+ const state = await readInstalledState(projectRoot);
27
+ const foundations = STACK_PACKAGES[stack] ?? [];
28
+ const createdByDevkit = foundations.every((foundationId) => state.installed[foundationId]?.kind === 'package' &&
29
+ state.installed[foundationId]?.source === 'installed');
30
+ if (!createdByDevkit)
31
+ return [];
32
+ const setupPackages = await requiredSetupPackageIds(projectRoot, stack);
33
+ for (const packageId of setupPackages) {
34
+ await addPredefinedPackageInternal(projectRoot, packageId, {
35
+ ...options,
36
+ ensureStackSetup: false,
37
+ });
38
+ }
39
+ return setupPackages;
40
+ }
41
+ async function addPredefinedPackageInternal(projectRoot, id, options = {}) {
42
+ const recipe = getPackageRecipe(id);
43
+ const state = await readInstalledState(projectRoot);
44
+ const recipes = listPackageRecipes();
45
+ const detections = await Promise.all(recipes.map(async (item) => [item.id, await item.detect(projectRoot)]));
46
+ const detectionById = new Map(detections);
47
+ const detected = detections.filter(([, result]) => result.present).map(([packageId]) => packageId);
48
+ const registeredPackages = new Set(installedPackageIds(state));
49
+ registeredPackages.delete(id);
50
+ const presentPackages = new Set(detected);
51
+ presentPackages.delete(id);
52
+ const resolution = resolvePackageAddition(recipe, {
53
+ registeredPackageIds: registeredPackages,
54
+ presentPackageIds: presentPackages,
55
+ knownRecipes: recipes,
56
+ });
57
+ const detection = detectionById.get(id);
58
+ if (!detection)
59
+ throw new Error(`Package detection missing for ${id}`);
60
+ const applied = await recipe.apply(projectRoot, detection, resolution, {
61
+ runCommand: options.runCommand ?? runPackageCommand,
62
+ });
63
+ const currentDetection = await recipe.detect(projectRoot);
64
+ if (!currentDetection.present || !currentDetection.compatible) {
65
+ throw new Error(currentDetection.reason ?? `${id} install did not produce a compatible package state`);
66
+ }
67
+ const existingEntry = state.installed[id];
68
+ const entry = {
69
+ kind: 'package',
70
+ recipeVersion: recipe.recipeVersion,
71
+ detectedVersion: currentDetection.detectedVersion,
72
+ role: recipe.role,
73
+ source: existingEntry?.source ?? applied.source,
74
+ ...(resolution.variant ? { resolvedVariant: resolution.variant } : {}),
75
+ };
76
+ const unchanged = existingEntry && JSON.stringify(existingEntry) === JSON.stringify(entry);
77
+ if (!unchanged) {
78
+ state.installed[id] = entry;
79
+ if (!state.requested.includes(id))
80
+ state.requested.push(id);
81
+ state.requested.sort();
82
+ await writeInstalledState(projectRoot, state);
83
+ }
84
+ const setupPackages = options.ensureStackSetup === false ? [] : await ensureResolvedStackSetup(projectRoot, options);
85
+ return {
86
+ id,
87
+ recipeVersion: recipe.recipeVersion,
88
+ detectedVersion: currentDetection.detectedVersion,
89
+ source: applied.source,
90
+ resolvedVariant: resolution.variant,
91
+ changed: !unchanged,
92
+ ...(setupPackages.length ? { setupPackages } : {}),
93
+ };
94
+ }
95
+ export async function addPredefinedPackage(projectRoot, id, options = {}) {
96
+ return await addPredefinedPackageInternal(projectRoot, id, options);
97
+ }
@@ -0,0 +1,19 @@
1
+ export type PackageCommandRunner = (command: string, args: string[], options: {
2
+ cwd: string;
3
+ }) => Promise<void>;
4
+ export declare function runPackageCommand(command: string, args: string[], options: {
5
+ cwd: string;
6
+ }): Promise<void>;
7
+ export declare function updatePackageJson(projectRoot: string, update: (pkg: any) => any): Promise<any>;
8
+ export declare function writeProjectFileIfMissing(projectRoot: string, relativePath: string, content: string): Promise<void>;
9
+ export declare function mergeMissing(target: Record<string, string> | undefined, values: Record<string, string>): {
10
+ [x: string]: string;
11
+ };
12
+ export declare function projectPackageName(projectRoot: string): string;
13
+ export declare function ensurePnpmBuildPolicy(projectRoot: string): Promise<void>;
14
+ export declare function installPackageJsonPatch(projectRoot: string, runCommand: PackageCommandRunner, patch: {
15
+ dependencies?: Record<string, string>;
16
+ devDependencies?: Record<string, string>;
17
+ scripts?: Record<string, string>;
18
+ }): Promise<void>;
19
+ export declare function makeProjectFileExecutable(projectRoot: string, relativePath: string): Promise<void>;
@@ -0,0 +1,86 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises';
3
+ import { basename, dirname, join } from 'node:path';
4
+ import { promisify } from 'node:util';
5
+ import { PackageJsonSchema, parseWithSchema } from "../schemas.js";
6
+ const execFileAsync = promisify(execFile);
7
+ export async function runPackageCommand(command, args, options) {
8
+ try {
9
+ await execFileAsync(command, args, { cwd: options.cwd });
10
+ }
11
+ catch (error) {
12
+ const detail = [error?.stderr, error?.stdout, error?.message]
13
+ .map((value) => String(value ?? '').trim())
14
+ .find(Boolean);
15
+ throw new Error(`${command} ${args.join(' ')} failed${detail ? `: ${detail}` : ''}`, { cause: error });
16
+ }
17
+ }
18
+ export async function updatePackageJson(projectRoot, update) {
19
+ const path = join(projectRoot, 'package.json');
20
+ let pkg = {};
21
+ try {
22
+ pkg = parseWithSchema(PackageJsonSchema, JSON.parse(await readFile(path, 'utf8')), `package.json at ${path}`);
23
+ }
24
+ catch (error) {
25
+ if (error?.code !== 'ENOENT')
26
+ throw error;
27
+ }
28
+ const updated = update(pkg);
29
+ await writeFile(path, `${JSON.stringify(updated, null, 2)}\n`);
30
+ return updated;
31
+ }
32
+ export async function writeProjectFileIfMissing(projectRoot, relativePath, content) {
33
+ const path = join(projectRoot, relativePath);
34
+ try {
35
+ await readFile(path);
36
+ return;
37
+ }
38
+ catch (error) {
39
+ if (error?.code !== 'ENOENT')
40
+ throw error;
41
+ }
42
+ await mkdir(dirname(path), { recursive: true });
43
+ await writeFile(path, content);
44
+ }
45
+ export function mergeMissing(target, values) {
46
+ return { ...values, ...(target ?? {}) };
47
+ }
48
+ export function projectPackageName(projectRoot) {
49
+ const normalized = basename(projectRoot).toLowerCase().replace(/[^a-z0-9._-]+/gu, '-');
50
+ return normalized || 'specdest-app';
51
+ }
52
+ export async function ensurePnpmBuildPolicy(projectRoot) {
53
+ const path = join(projectRoot, 'pnpm-workspace.yaml');
54
+ let existing = '';
55
+ try {
56
+ existing = await readFile(path, 'utf8');
57
+ }
58
+ catch (error) {
59
+ if (error?.code !== 'ENOENT')
60
+ throw error;
61
+ }
62
+ let updated = existing;
63
+ if (!/^verifyDepsBeforeRun:\s*error\s*$/mu.test(updated)) {
64
+ updated = `verifyDepsBeforeRun: error\n\n${updated.trimStart()}`;
65
+ }
66
+ if (!/^allowBuilds:\s*$/mu.test(updated)) {
67
+ updated = `${updated.trimEnd()}\n\nallowBuilds:\n`;
68
+ }
69
+ if (!/^\s{2}esbuild:\s*true\s*$/mu.test(updated)) {
70
+ updated = updated.replace(/^allowBuilds:\s*$/mu, 'allowBuilds:\n esbuild: true');
71
+ }
72
+ if (updated !== existing)
73
+ await writeFile(path, `${updated.trimEnd()}\n`);
74
+ }
75
+ export async function installPackageJsonPatch(projectRoot, runCommand, patch) {
76
+ await updatePackageJson(projectRoot, (pkg) => ({
77
+ ...pkg,
78
+ ...(patch.dependencies ? { dependencies: mergeMissing(pkg.dependencies, patch.dependencies) } : {}),
79
+ ...(patch.devDependencies ? { devDependencies: mergeMissing(pkg.devDependencies, patch.devDependencies) } : {}),
80
+ ...(patch.scripts ? { scripts: mergeMissing(pkg.scripts, patch.scripts) } : {}),
81
+ }));
82
+ await runCommand('pnpm', ['install', '--no-frozen-lockfile'], { cwd: projectRoot });
83
+ }
84
+ export async function makeProjectFileExecutable(projectRoot, relativePath) {
85
+ await chmod(join(projectRoot, relativePath), 0o755);
86
+ }
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const localLoggingRecipe: PackageRecipe;
@@ -0,0 +1,17 @@
1
+ import { pathExists } from "./project-signals.js";
2
+ export const localLoggingRecipe = {
3
+ id: 'local-logging',
4
+ recipeVersion: '1.0.0',
5
+ role: 'integration',
6
+ async detect(projectRoot) {
7
+ const present = await pathExists(projectRoot, 'tools/local-log/local-log.mjs');
8
+ return present
9
+ ? { present: true, compatible: true, detectedVersion: null }
10
+ : { present: false, compatible: false, detectedVersion: null, reason: 'tools/local-log/local-log.mjs was not found' };
11
+ },
12
+ async apply(_projectRoot, detection, _resolution) {
13
+ if (!detection.present)
14
+ throw new Error('Local logging tooling was not detected; creating local logging tooling is not supported by `add local-logging` yet.');
15
+ return { source: 'adopted' };
16
+ },
17
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const loggingRecipe: PackageRecipe;
@@ -0,0 +1,21 @@
1
+ import { detectAnyDependency } from "./package-json.js";
2
+ import { pathExists } from "./project-signals.js";
3
+ export const loggingRecipe = {
4
+ id: 'logging',
5
+ recipeVersion: '1.0.0',
6
+ role: 'integration',
7
+ async detect(projectRoot) {
8
+ if (await pathExists(projectRoot, 'tools/local-log/local-log.mjs')) {
9
+ return { present: true, compatible: true, detectedVersion: null };
10
+ }
11
+ return await detectAnyDependency(projectRoot, ['pino', 'winston', 'bunyan'], 'supported structured logging dependency');
12
+ },
13
+ async apply(_projectRoot, detection, _resolution) {
14
+ if (!detection.present) {
15
+ throw new Error('Structured/local logging integration was not detected; creating logging infrastructure is not supported by `add logging` yet.');
16
+ }
17
+ if (!detection.compatible)
18
+ throw new Error(detection.reason ?? 'Existing logging integration is not compatible.');
19
+ return { source: 'adopted' };
20
+ },
21
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const multiTenancyRecipe: PackageRecipe;
@@ -0,0 +1,21 @@
1
+ import { detectCapability } from "./project-signals.js";
2
+ export const multiTenancyRecipe = {
3
+ id: 'multi-tenancy',
4
+ recipeVersion: '1.0.0',
5
+ role: 'feature',
6
+ variants: [
7
+ { id: 'supabase', when: ['supabase'] },
8
+ { id: 'convex', when: ['convex'] },
9
+ ],
10
+ async detect(projectRoot) {
11
+ return await detectCapability(projectRoot, 'multi-tenant');
12
+ },
13
+ async apply(_projectRoot, detection, _resolution) {
14
+ if (!detection.present) {
15
+ throw new Error('Multi-tenancy is not declared in this project; creating multi-tenancy is not supported by `add multi-tenancy` yet.');
16
+ }
17
+ if (!detection.compatible)
18
+ throw new Error(detection.reason ?? 'Existing multi-tenancy integration is not compatible.');
19
+ return { source: 'adopted' };
20
+ },
21
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const npsRecipe: PackageRecipe;
@@ -0,0 +1,32 @@
1
+ import { installPackageJsonPatch, writeProjectFileIfMissing } from "./install.js";
2
+ import { detectDependency } from "./package-json.js";
3
+ import { pathExists } from "./project-signals.js";
4
+ export const npsRecipe = {
5
+ id: 'nps',
6
+ recipeVersion: '1.1.0',
7
+ role: 'tooling',
8
+ async detect(projectRoot) {
9
+ const dependency = await detectDependency(projectRoot, 'nps', 'NPS');
10
+ if (!dependency.present)
11
+ return dependency;
12
+ if (!(await pathExists(projectRoot, 'package-scripts.yml'))) {
13
+ return { ...dependency, compatible: false, reason: 'package-scripts.yml was not found' };
14
+ }
15
+ return dependency;
16
+ },
17
+ async apply(projectRoot, detection, _resolution, context) {
18
+ if (detection.present) {
19
+ if (!detection.compatible)
20
+ throw new Error(detection.reason ?? 'Existing NPS integration is not compatible.');
21
+ return { source: 'adopted' };
22
+ }
23
+ await writeProjectFileIfMissing(projectRoot, 'package-scripts.yml', `scripts:
24
+ check: pnpm run typecheck
25
+ `);
26
+ await installPackageJsonPatch(projectRoot, context.runCommand, {
27
+ devDependencies: { nps: '5.10.0' },
28
+ scripts: { nps: 'nps' },
29
+ });
30
+ return { source: 'installed' };
31
+ },
32
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const oxfmtRecipe: PackageRecipe;
@@ -0,0 +1,22 @@
1
+ import { installPackageJsonPatch } from "./install.js";
2
+ import { detectDependency } from "./package-json.js";
3
+ export const oxfmtRecipe = {
4
+ id: 'oxfmt',
5
+ recipeVersion: '1.1.0',
6
+ role: 'tooling',
7
+ async detect(projectRoot) {
8
+ return await detectDependency(projectRoot, 'oxfmt', 'Oxfmt');
9
+ },
10
+ async apply(projectRoot, detection, _resolution, context) {
11
+ if (detection.present) {
12
+ if (!detection.compatible)
13
+ throw new Error(detection.reason ?? 'Existing Oxfmt integration is not compatible.');
14
+ return { source: 'adopted' };
15
+ }
16
+ await installPackageJsonPatch(projectRoot, context.runCommand, {
17
+ devDependencies: { oxfmt: '0.54.0' },
18
+ scripts: { fmt: 'oxfmt --check .', 'fmt:fix': 'oxfmt --write .' },
19
+ });
20
+ return { source: 'installed' };
21
+ },
22
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const oxlintRecipe: PackageRecipe;
@@ -0,0 +1,35 @@
1
+ import { installPackageJsonPatch, writeProjectFileIfMissing } from "./install.js";
2
+ import { detectDependency } from "./package-json.js";
3
+ const config = `{
4
+ "categories": {
5
+ "correctness": "error",
6
+ "suspicious": "error",
7
+ "perf": "warn"
8
+ },
9
+ "rules": {
10
+ "typescript/no-explicit-any": "error",
11
+ "typescript/no-non-null-assertion": "error",
12
+ "eslint/no-console": "warn",
13
+ "react/set-state-in-effect": "error"
14
+ },
15
+ "ignorePatterns": ["dist/**", "coverage/**", "node_modules/**"]
16
+ }
17
+ `;
18
+ export const oxlintRecipe = {
19
+ id: 'oxlint',
20
+ recipeVersion: '1.1.1',
21
+ role: 'tooling',
22
+ async detect(projectRoot) {
23
+ return await detectDependency(projectRoot, 'oxlint', 'Oxlint');
24
+ },
25
+ async apply(projectRoot, detection, _resolution, context) {
26
+ if (detection.present)
27
+ return { source: 'adopted' };
28
+ await writeProjectFileIfMissing(projectRoot, '.oxlintrc.json', config);
29
+ await installPackageJsonPatch(projectRoot, context.runCommand, {
30
+ devDependencies: { oxlint: '1.82.0' },
31
+ scripts: { lint: 'oxlint .', 'lint:fix': 'oxlint . --fix' },
32
+ });
33
+ return { source: 'installed' };
34
+ },
35
+ };
@@ -0,0 +1,3 @@
1
+ import type { PackageDetection } from './types.ts';
2
+ export declare function detectDependency(projectRoot: string, dependencyName: string, displayName: string): Promise<PackageDetection>;
3
+ export declare function detectAnyDependency(projectRoot: string, dependencyNames: string[], displayName: string): Promise<PackageDetection>;
@@ -0,0 +1,61 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ async function readPackageJson(projectRoot) {
4
+ try {
5
+ return JSON.parse(await readFile(join(projectRoot, 'package.json'), 'utf8'));
6
+ }
7
+ catch (error) {
8
+ if (error?.code === 'ENOENT')
9
+ return null;
10
+ throw error;
11
+ }
12
+ }
13
+ function dependencySpecifier(pkg, dependencyName) {
14
+ return pkg.dependencies?.[dependencyName] ?? pkg.devDependencies?.[dependencyName] ?? null;
15
+ }
16
+ function normalizeVersion(specifier) {
17
+ const match = String(specifier).match(/(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/u);
18
+ return match?.[1] ?? String(specifier);
19
+ }
20
+ export async function detectDependency(projectRoot, dependencyName, displayName) {
21
+ const pkg = await readPackageJson(projectRoot);
22
+ if (!pkg) {
23
+ return { present: false, compatible: false, detectedVersion: null, reason: 'package.json not found' };
24
+ }
25
+ const specifier = dependencySpecifier(pkg, dependencyName);
26
+ if (!specifier) {
27
+ return {
28
+ present: false,
29
+ compatible: false,
30
+ detectedVersion: null,
31
+ reason: `${displayName} is not declared in package.json`,
32
+ };
33
+ }
34
+ return {
35
+ present: true,
36
+ compatible: true,
37
+ detectedVersion: normalizeVersion(specifier),
38
+ };
39
+ }
40
+ export async function detectAnyDependency(projectRoot, dependencyNames, displayName) {
41
+ const pkg = await readPackageJson(projectRoot);
42
+ if (!pkg) {
43
+ return { present: false, compatible: false, detectedVersion: null, reason: 'package.json not found' };
44
+ }
45
+ for (const dependencyName of dependencyNames) {
46
+ const specifier = dependencySpecifier(pkg, dependencyName);
47
+ if (specifier) {
48
+ return {
49
+ present: true,
50
+ compatible: true,
51
+ detectedVersion: normalizeVersion(specifier),
52
+ };
53
+ }
54
+ }
55
+ return {
56
+ present: false,
57
+ compatible: false,
58
+ detectedVersion: null,
59
+ reason: `${displayName} is not declared in package.json`,
60
+ };
61
+ }
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const paymentsRecipe: PackageRecipe;
@@ -0,0 +1,31 @@
1
+ import { detectAnyDependency } from "./package-json.js";
2
+ import { detectAnyPath } from "./project-signals.js";
3
+ const PROVIDER_DEPENDENCIES = [
4
+ 'stripe',
5
+ '@stripe/stripe-js',
6
+ '@stripe/react-stripe-js',
7
+ '@paddle/paddle-js',
8
+ '@paypal/react-paypal-js',
9
+ 'braintree',
10
+ '@adyen/adyen-web',
11
+ 'square',
12
+ ];
13
+ export const paymentsRecipe = {
14
+ id: 'payments',
15
+ recipeVersion: '1.0.0',
16
+ role: 'integration',
17
+ async detect(projectRoot) {
18
+ const dependency = await detectAnyDependency(projectRoot, PROVIDER_DEPENDENCIES, 'supported payment provider dependency');
19
+ if (dependency.present)
20
+ return dependency;
21
+ return await detectAnyPath(projectRoot, ['src/payments', 'src/integrations/stripe', 'src/integrations/payments', 'app/payments'], 'payment provider integration was not detected');
22
+ },
23
+ async apply(_projectRoot, detection, _resolution) {
24
+ if (!detection.present) {
25
+ throw new Error('Payments integration was not detected; creating payment-provider infrastructure is not supported by `add payments` yet.');
26
+ }
27
+ if (!detection.compatible)
28
+ throw new Error(detection.reason ?? 'Existing payments integration is not compatible.');
29
+ return { source: 'adopted' };
30
+ },
31
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const playwrightRecipe: PackageRecipe;
@@ -0,0 +1,35 @@
1
+ import { installPackageJsonPatch, writeProjectFileIfMissing } from "./install.js";
2
+ import { detectAnyDependency } from "./package-json.js";
3
+ const config = `import { defineConfig } from '@playwright/test';
4
+
5
+ export default defineConfig({
6
+ testDir: './tests/e2e',
7
+ outputDir: 'test-results/playwright-artifacts',
8
+ reporter: [['list']],
9
+ use: {
10
+ baseURL: process.env.E2E_BASE_URL ?? 'http://127.0.0.1:5173',
11
+ trace: 'retain-on-failure',
12
+ screenshot: 'only-on-failure',
13
+ video: 'retain-on-failure',
14
+ },
15
+ });
16
+ `;
17
+ export const playwrightRecipe = {
18
+ id: 'playwright',
19
+ recipeVersion: '1.1.0',
20
+ role: 'integration',
21
+ requires: ['vite'],
22
+ async detect(projectRoot) {
23
+ return await detectAnyDependency(projectRoot, ['@playwright/test', 'playwright'], 'Playwright');
24
+ },
25
+ async apply(projectRoot, detection, _resolution, context) {
26
+ if (detection.present)
27
+ return { source: 'adopted' };
28
+ await writeProjectFileIfMissing(projectRoot, 'playwright.e2e.config.ts', config);
29
+ await installPackageJsonPatch(projectRoot, context.runCommand, {
30
+ devDependencies: { '@playwright/test': '1.57.0' },
31
+ scripts: { 'test:e2e': 'playwright test --config playwright.e2e.config.ts' },
32
+ });
33
+ return { source: 'installed' };
34
+ },
35
+ };
@@ -0,0 +1,4 @@
1
+ import type { PackageDetection } from './types.ts';
2
+ export declare function pathExists(projectRoot: string, relativePath: string): Promise<boolean>;
3
+ export declare function detectAnyPath(projectRoot: string, relativePaths: string[], reason: string): Promise<PackageDetection>;
4
+ export declare function detectCapability(projectRoot: string, capability: string): Promise<PackageDetection>;
@@ -0,0 +1,39 @@
1
+ import { access, readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ export async function pathExists(projectRoot, relativePath) {
4
+ try {
5
+ await access(join(projectRoot, relativePath));
6
+ return true;
7
+ }
8
+ catch (error) {
9
+ if (error?.code === 'ENOENT')
10
+ return false;
11
+ throw error;
12
+ }
13
+ }
14
+ export async function detectAnyPath(projectRoot, relativePaths, reason) {
15
+ for (const relativePath of relativePaths) {
16
+ if (await pathExists(projectRoot, relativePath)) {
17
+ return { present: true, compatible: true, detectedVersion: null };
18
+ }
19
+ }
20
+ return { present: false, compatible: false, detectedVersion: null, reason };
21
+ }
22
+ export async function detectCapability(projectRoot, capability) {
23
+ try {
24
+ const profile = JSON.parse(await readFile(join(projectRoot, '.spd/rules.json'), 'utf8'));
25
+ if (Array.isArray(profile.capabilities) && profile.capabilities.includes(capability)) {
26
+ return { present: true, compatible: true, detectedVersion: null };
27
+ }
28
+ }
29
+ catch (error) {
30
+ if (error?.code !== 'ENOENT')
31
+ throw error;
32
+ }
33
+ return {
34
+ present: false,
35
+ compatible: false,
36
+ detectedVersion: null,
37
+ reason: `project does not declare the ${capability} capability`,
38
+ };
39
+ }
@@ -0,0 +1,3 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare function getPackageRecipe(id: string): PackageRecipe;
3
+ export declare function listPackageRecipes(): PackageRecipe[];