@specdest/devkit 0.4.6 → 0.4.8

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 (125) hide show
  1. package/README.md +34 -4
  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 +10 -0
  5. package/dist/npm/canonical-project.js +109 -0
  6. package/dist/npm/canonical-source.d.ts +14 -0
  7. package/dist/npm/canonical-source.js +216 -0
  8. package/dist/npm/catalog-snapshot.d.ts +47 -0
  9. package/dist/npm/catalog-snapshot.js +28 -0
  10. package/dist/npm/cli.d.ts +2 -0
  11. package/dist/npm/cli.js +15 -0
  12. package/dist/npm/commands.d.ts +9 -0
  13. package/dist/npm/commands.js +157 -0
  14. package/dist/npm/flow.d.ts +48 -0
  15. package/dist/npm/flow.js +396 -0
  16. package/dist/npm/fuzz.d.ts +138 -0
  17. package/dist/npm/fuzz.js +327 -0
  18. package/dist/npm/git-catalog.d.ts +39 -0
  19. package/dist/npm/git-catalog.js +190 -0
  20. package/dist/npm/index.d.ts +5 -0
  21. package/dist/npm/index.js +22 -0
  22. package/dist/npm/installer-primitives.d.ts +3 -0
  23. package/dist/npm/installer-primitives.js +50 -0
  24. package/dist/npm/predefined-packages/abac.d.ts +2 -0
  25. package/dist/npm/predefined-packages/abac.js +22 -0
  26. package/dist/npm/predefined-packages/auth.d.ts +2 -0
  27. package/dist/npm/predefined-packages/auth.js +21 -0
  28. package/dist/npm/predefined-packages/convex.d.ts +2 -0
  29. package/dist/npm/predefined-packages/convex.js +53 -0
  30. package/dist/npm/predefined-packages/expo.d.ts +2 -0
  31. package/dist/npm/predefined-packages/expo.js +84 -0
  32. package/dist/npm/predefined-packages/firebase-hosting.d.ts +2 -0
  33. package/dist/npm/predefined-packages/firebase-hosting.js +24 -0
  34. package/dist/npm/predefined-packages/health.d.ts +10 -0
  35. package/dist/npm/predefined-packages/health.js +52 -0
  36. package/dist/npm/predefined-packages/husky.d.ts +2 -0
  37. package/dist/npm/predefined-packages/husky.js +57 -0
  38. package/dist/npm/predefined-packages/index.d.ts +11 -0
  39. package/dist/npm/predefined-packages/index.js +56 -0
  40. package/dist/npm/predefined-packages/install.d.ts +19 -0
  41. package/dist/npm/predefined-packages/install.js +85 -0
  42. package/dist/npm/predefined-packages/local-logging.d.ts +2 -0
  43. package/dist/npm/predefined-packages/local-logging.js +17 -0
  44. package/dist/npm/predefined-packages/logging.d.ts +2 -0
  45. package/dist/npm/predefined-packages/logging.js +21 -0
  46. package/dist/npm/predefined-packages/multi-tenancy.d.ts +2 -0
  47. package/dist/npm/predefined-packages/multi-tenancy.js +21 -0
  48. package/dist/npm/predefined-packages/nps.d.ts +2 -0
  49. package/dist/npm/predefined-packages/nps.js +32 -0
  50. package/dist/npm/predefined-packages/oxfmt.d.ts +2 -0
  51. package/dist/npm/predefined-packages/oxfmt.js +22 -0
  52. package/dist/npm/predefined-packages/oxlint.d.ts +2 -0
  53. package/dist/npm/predefined-packages/oxlint.js +35 -0
  54. package/dist/npm/predefined-packages/package-json.d.ts +3 -0
  55. package/dist/npm/predefined-packages/package-json.js +61 -0
  56. package/dist/npm/predefined-packages/payments.d.ts +2 -0
  57. package/dist/npm/predefined-packages/payments.js +31 -0
  58. package/dist/npm/predefined-packages/playwright.d.ts +2 -0
  59. package/dist/npm/predefined-packages/playwright.js +35 -0
  60. package/dist/npm/predefined-packages/project-signals.d.ts +4 -0
  61. package/dist/npm/predefined-packages/project-signals.js +39 -0
  62. package/dist/npm/predefined-packages/registry.d.ts +3 -0
  63. package/dist/npm/predefined-packages/registry.js +63 -0
  64. package/dist/npm/predefined-packages/resolver.d.ts +8 -0
  65. package/dist/npm/predefined-packages/resolver.js +35 -0
  66. package/dist/npm/predefined-packages/sentry.d.ts +2 -0
  67. package/dist/npm/predefined-packages/sentry.js +29 -0
  68. package/dist/npm/predefined-packages/shadcn.d.ts +2 -0
  69. package/dist/npm/predefined-packages/shadcn.js +23 -0
  70. package/dist/npm/predefined-packages/storybook.d.ts +2 -0
  71. package/dist/npm/predefined-packages/storybook.js +25 -0
  72. package/dist/npm/predefined-packages/stryker.d.ts +2 -0
  73. package/dist/npm/predefined-packages/stryker.js +48 -0
  74. package/dist/npm/predefined-packages/supabase.d.ts +2 -0
  75. package/dist/npm/predefined-packages/supabase.js +84 -0
  76. package/dist/npm/predefined-packages/tailwind.d.ts +2 -0
  77. package/dist/npm/predefined-packages/tailwind.js +18 -0
  78. package/dist/npm/predefined-packages/tanstack-form.d.ts +2 -0
  79. package/dist/npm/predefined-packages/tanstack-form.js +19 -0
  80. package/dist/npm/predefined-packages/tanstack-query.d.ts +2 -0
  81. package/dist/npm/predefined-packages/tanstack-query.js +15 -0
  82. package/dist/npm/predefined-packages/tanstack-router.d.ts +2 -0
  83. package/dist/npm/predefined-packages/tanstack-router.js +18 -0
  84. package/dist/npm/predefined-packages/types.d.ts +31 -0
  85. package/dist/npm/predefined-packages/types.js +1 -0
  86. package/dist/npm/predefined-packages/vite.d.ts +2 -0
  87. package/dist/npm/predefined-packages/vite.js +123 -0
  88. package/dist/npm/predefined-packages/vitest.d.ts +2 -0
  89. package/dist/npm/predefined-packages/vitest.js +20 -0
  90. package/dist/npm/predefined-packages/zod.d.ts +2 -0
  91. package/dist/npm/predefined-packages/zod.js +18 -0
  92. package/dist/npm/project-check.d.ts +6 -0
  93. package/dist/npm/project-check.js +87 -0
  94. package/dist/npm/project-context.d.ts +42 -0
  95. package/dist/npm/project-context.js +192 -0
  96. package/dist/npm/project-rules.d.ts +22 -0
  97. package/dist/npm/project-rules.js +66 -0
  98. package/dist/npm/project-runtime.d.ts +18 -0
  99. package/dist/npm/project-runtime.js +27 -0
  100. package/dist/npm/project-status.d.ts +32 -0
  101. package/dist/npm/project-status.js +56 -0
  102. package/dist/npm/project-sync.d.ts +7 -0
  103. package/dist/npm/project-sync.js +135 -0
  104. package/dist/npm/remote-installer.d.ts +4 -0
  105. package/dist/npm/remote-installer.js +312 -0
  106. package/dist/npm/state.d.ts +14 -0
  107. package/dist/npm/state.js +182 -0
  108. package/package.json +10 -7
  109. package/src/canonical-project-operations.js +0 -438
  110. package/src/canonical-project.js +0 -136
  111. package/src/canonical-source.js +0 -250
  112. package/src/catalog-snapshot.js +0 -39
  113. package/src/catalog.js +0 -117
  114. package/src/cli.js +0 -14
  115. package/src/fuzz.js +0 -291
  116. package/src/git-catalog.js +0 -177
  117. package/src/index.js +0 -36
  118. package/src/installer-primitives.js +0 -198
  119. package/src/project-operations.js +0 -189
  120. package/src/project-targeting.js +0 -48
  121. package/src/remote-installer.js +0 -479
  122. package/src/rule-profile.js +0 -61
  123. package/src/setup-requirements.js +0 -82
  124. package/src/shared-file.js +0 -131
  125. package/src/sync-core.js +0 -390
@@ -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,84 @@
1
+ import { ensurePnpmBuildPolicy, mergeMissing, projectPackageName, updatePackageJson, writeProjectFileIfMissing } from "./install.js";
2
+ import { detectDependency } from "./package-json.js";
3
+ const bootstrapDatabaseTypes = `export type Database = {
4
+ public: {
5
+ Tables: {};
6
+ Views: {};
7
+ Functions: {};
8
+ Enums: {};
9
+ CompositeTypes: {};
10
+ };
11
+ };
12
+ `;
13
+ const bootstrapSchema = `// generated schema placeholder; regenerate after defining database tables.
14
+ export {};
15
+ `;
16
+ async function installSupabase(projectRoot, context) {
17
+ const pkg = await updatePackageJson(projectRoot, (pkg) => ({
18
+ ...pkg,
19
+ name: pkg.name ?? projectPackageName(projectRoot),
20
+ private: pkg.private ?? true,
21
+ packageManager: pkg.packageManager ?? 'pnpm@11.6.0',
22
+ engines: {
23
+ ...pkg.engines,
24
+ node: pkg.engines?.node ?? '>=24.0.0',
25
+ pnpm: pkg.engines?.pnpm ?? '>=11.0.0',
26
+ },
27
+ scripts: mergeMissing(pkg.scripts, {
28
+ 'supabase:start': 'supabase start',
29
+ 'supabase:stop': 'supabase stop',
30
+ 'db:types:local': 'supabase gen types typescript --local',
31
+ }),
32
+ dependencies: mergeMissing(pkg.dependencies, {
33
+ '@supabase/supabase-js': '2.103.0',
34
+ }),
35
+ devDependencies: mergeMissing(pkg.devDependencies, {
36
+ supabase: '2.108.0',
37
+ }),
38
+ }));
39
+ await ensurePnpmBuildPolicy(projectRoot);
40
+ await writeProjectFileIfMissing(projectRoot, 'supabase/config.toml', `project_id = "${pkg.name}"
41
+
42
+ [db.migrations]
43
+ enabled = true
44
+ schema_paths = ["./schemas/*.sql"]
45
+
46
+ [experimental.pgdelta]
47
+ enabled = true
48
+ declarative_schema_path = "./schemas"
49
+ `);
50
+ await writeProjectFileIfMissing(projectRoot, 'supabase/schemas/000_base.sql', 'create schema if not exists public;\n');
51
+ await writeProjectFileIfMissing(projectRoot, 'src/__generated__/database.ts', bootstrapDatabaseTypes);
52
+ await writeProjectFileIfMissing(projectRoot, 'src/__generated__/schema.ts', bootstrapSchema);
53
+ await writeProjectFileIfMissing(projectRoot, 'package-scripts.yml', `scripts:
54
+ db:
55
+ schema:
56
+ sync: supabase db schema declarative sync --experimental --no-apply --name declarative_schema
57
+ migrate:
58
+ prod: |-
59
+ nps db.schema.sync &&
60
+ supabase db push --db-url "$SUPABASE_DB_URL" --include-all
61
+ generate:
62
+ remote: |-
63
+ supabase gen types typescript --db-url "$SUPABASE_DB_URL" > src/__generated__/database.ts
64
+ `);
65
+ await context.runCommand('pnpm', ['install', '--no-frozen-lockfile'], { cwd: projectRoot });
66
+ }
67
+ export const supabaseRecipe = {
68
+ id: 'supabase',
69
+ recipeVersion: '1.1.1',
70
+ role: 'backend',
71
+ conflicts: ['convex'],
72
+ async detect(projectRoot) {
73
+ return await detectDependency(projectRoot, '@supabase/supabase-js', '@supabase/supabase-js');
74
+ },
75
+ async apply(projectRoot, detection, _resolution, context) {
76
+ if (detection.present) {
77
+ if (!detection.compatible)
78
+ throw new Error(detection.reason ?? 'Existing Supabase setup is not compatible.');
79
+ return { source: 'adopted' };
80
+ }
81
+ await installSupabase(projectRoot, context);
82
+ return { source: 'installed' };
83
+ },
84
+ };
@@ -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;
@@ -0,0 +1,18 @@
1
+ import { detectDependency } from "./package-json.js";
2
+ export const tanstackRouterRecipe = {
3
+ id: 'tanstack-router',
4
+ recipeVersion: '1.0.0',
5
+ role: 'integration',
6
+ requires: ['vite'],
7
+ async detect(projectRoot) {
8
+ return await detectDependency(projectRoot, '@tanstack/react-router', '@tanstack/react-router');
9
+ },
10
+ async apply(_projectRoot, detection, _resolution) {
11
+ if (!detection.present) {
12
+ throw new Error('TanStack Router is not installed; creating router configuration is not supported by `add tanstack-router` yet.');
13
+ }
14
+ if (!detection.compatible)
15
+ throw new Error(detection.reason ?? 'Existing TanStack Router integration is not compatible.');
16
+ return { source: 'adopted' };
17
+ },
18
+ };
@@ -0,0 +1,31 @@
1
+ export type PackageSource = 'adopted' | 'installed';
2
+ export type PackageDetection = {
3
+ present: boolean;
4
+ compatible: boolean;
5
+ detectedVersion: string | null;
6
+ reason?: string;
7
+ };
8
+ export type PackageVariant = {
9
+ id: string;
10
+ when: string[];
11
+ };
12
+ export type PackageResolution = {
13
+ variant: string | null;
14
+ };
15
+ export type PackageApplyContext = {
16
+ runCommand(command: string, args: string[], options: {
17
+ cwd: string;
18
+ }): Promise<void>;
19
+ };
20
+ export type PackageRecipe = {
21
+ id: string;
22
+ recipeVersion: string;
23
+ role: string;
24
+ requires?: string[];
25
+ conflicts?: string[];
26
+ variants?: PackageVariant[];
27
+ detect(projectRoot: string): Promise<PackageDetection>;
28
+ apply(projectRoot: string, detection: PackageDetection, resolution: PackageResolution, context: PackageApplyContext): Promise<{
29
+ source: PackageSource;
30
+ }>;
31
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const viteRecipe: PackageRecipe;
@@ -0,0 +1,123 @@
1
+ import { basename } from 'node:path';
2
+ import { ensurePnpmBuildPolicy, mergeMissing, updatePackageJson, writeProjectFileIfMissing } from "./install.js";
3
+ import { detectDependency } from "./package-json.js";
4
+ const dependencies = {
5
+ react: '19.2.3',
6
+ 'react-dom': '19.2.3',
7
+ };
8
+ const devDependencies = {
9
+ '@types/react': '19.2.7',
10
+ '@types/react-dom': '19.2.3',
11
+ '@vitejs/plugin-react': '5.1.2',
12
+ typescript: '6.0.3',
13
+ vite: '7.3.0',
14
+ };
15
+ function packageName(projectRoot) {
16
+ const normalized = basename(projectRoot).toLowerCase().replace(/[^a-z0-9._-]+/gu, '-');
17
+ return normalized || 'specdest-app';
18
+ }
19
+ async function installVite(projectRoot, context) {
20
+ await updatePackageJson(projectRoot, (pkg) => ({
21
+ ...pkg,
22
+ name: pkg.name ?? packageName(projectRoot),
23
+ private: pkg.private ?? true,
24
+ type: pkg.type ?? 'module',
25
+ packageManager: pkg.packageManager ?? 'pnpm@11.6.0',
26
+ engines: {
27
+ ...pkg.engines,
28
+ node: pkg.engines?.node ?? '>=24.0.0',
29
+ pnpm: pkg.engines?.pnpm ?? '>=11.0.0',
30
+ },
31
+ scripts: mergeMissing(pkg.scripts, {
32
+ dev: 'vite',
33
+ build: 'tsc -b && vite build',
34
+ typecheck: 'tsc -b',
35
+ preview: 'vite preview',
36
+ }),
37
+ dependencies: mergeMissing(pkg.dependencies, dependencies),
38
+ devDependencies: mergeMissing(pkg.devDependencies, devDependencies),
39
+ }));
40
+ await ensurePnpmBuildPolicy(projectRoot);
41
+ await writeProjectFileIfMissing(projectRoot, 'index.html', `<!doctype html>
42
+ <html lang="en">
43
+ <head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /></head>
44
+ <body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body>
45
+ </html>
46
+ `);
47
+ await writeProjectFileIfMissing(projectRoot, 'src/main.tsx', `import { StrictMode } from 'react';
48
+ import { createRoot } from 'react-dom/client';
49
+ import App from './App';
50
+
51
+ createRoot(document.getElementById('root')!).render(
52
+ <StrictMode>
53
+ <App />
54
+ </StrictMode>,
55
+ );
56
+ `);
57
+ await writeProjectFileIfMissing(projectRoot, 'src/App.tsx', `export default function App() {
58
+ return <main>Specdest app</main>;
59
+ }
60
+ `);
61
+ await writeProjectFileIfMissing(projectRoot, 'vite.config.ts', `import { defineConfig } from 'vite';
62
+ import react from '@vitejs/plugin-react';
63
+
64
+ export default defineConfig({ plugins: [react()] });
65
+ `);
66
+ await writeProjectFileIfMissing(projectRoot, 'tsconfig.json', `{
67
+ "files": [],
68
+ "references": [
69
+ { "path": "./tsconfig.app.json" },
70
+ { "path": "./tsconfig.node.json" }
71
+ ]
72
+ }
73
+ `);
74
+ await writeProjectFileIfMissing(projectRoot, 'tsconfig.app.json', `{
75
+ "compilerOptions": {
76
+ "target": "ES2022",
77
+ "useDefineForClassFields": true,
78
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
79
+ "skipLibCheck": true,
80
+ "module": "ESNext",
81
+ "moduleResolution": "Bundler",
82
+ "allowImportingTsExtensions": true,
83
+ "resolveJsonModule": true,
84
+ "isolatedModules": true,
85
+ "noEmit": true,
86
+ "jsx": "react-jsx",
87
+ "strict": true
88
+ },
89
+ "include": ["src"]
90
+ }
91
+ `);
92
+ await writeProjectFileIfMissing(projectRoot, 'tsconfig.node.json', `{
93
+ "compilerOptions": {
94
+ "composite": true,
95
+ "skipLibCheck": true,
96
+ "module": "ESNext",
97
+ "moduleResolution": "Bundler",
98
+ "allowImportingTsExtensions": true,
99
+ "noEmit": true
100
+ },
101
+ "include": ["vite.config.ts"]
102
+ }
103
+ `);
104
+ await context.runCommand('pnpm', ['install', '--no-frozen-lockfile'], { cwd: projectRoot });
105
+ }
106
+ export const viteRecipe = {
107
+ id: 'vite',
108
+ recipeVersion: '1.1.1',
109
+ role: 'frontend',
110
+ conflicts: ['expo'],
111
+ async detect(projectRoot) {
112
+ return await detectDependency(projectRoot, 'vite', 'Vite');
113
+ },
114
+ async apply(projectRoot, detection, _resolution, context) {
115
+ if (detection.present) {
116
+ if (!detection.compatible)
117
+ throw new Error(detection.reason ?? 'Existing Vite setup is not compatible.');
118
+ return { source: 'adopted' };
119
+ }
120
+ await installVite(projectRoot, context);
121
+ return { source: 'installed' };
122
+ },
123
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const vitestRecipe: PackageRecipe;
@@ -0,0 +1,20 @@
1
+ import { installPackageJsonPatch } from "./install.js";
2
+ import { detectDependency } from "./package-json.js";
3
+ export const vitestRecipe = {
4
+ id: 'vitest',
5
+ recipeVersion: '1.1.0',
6
+ role: 'integration',
7
+ requires: ['vite'],
8
+ async detect(projectRoot) {
9
+ return await detectDependency(projectRoot, 'vitest', 'Vitest');
10
+ },
11
+ async apply(projectRoot, detection, _resolution, context) {
12
+ if (detection.present)
13
+ return { source: 'adopted' };
14
+ await installPackageJsonPatch(projectRoot, context.runCommand, {
15
+ devDependencies: { vitest: '4.1.0' },
16
+ scripts: { test: 'vitest run', 'test:watch': 'vitest' },
17
+ });
18
+ return { source: 'installed' };
19
+ },
20
+ };
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const zodRecipe: PackageRecipe;
@@ -0,0 +1,18 @@
1
+ import { installPackageJsonPatch } from "./install.js";
2
+ import { detectDependency } from "./package-json.js";
3
+ export const zodRecipe = {
4
+ id: 'zod',
5
+ recipeVersion: '1.1.0',
6
+ role: 'integration',
7
+ async detect(projectRoot) {
8
+ return await detectDependency(projectRoot, 'zod', 'Zod');
9
+ },
10
+ async apply(projectRoot, detection, _resolution, context) {
11
+ if (detection.present)
12
+ return { source: 'adopted' };
13
+ await installPackageJsonPatch(projectRoot, context.runCommand, {
14
+ dependencies: { zod: '4.3.6' },
15
+ });
16
+ return { source: 'installed' };
17
+ },
18
+ };
@@ -0,0 +1,6 @@
1
+ export declare function canonicalCheck(projectRoot: string, source: any, options?: any): Promise<{
2
+ exitCode: number;
3
+ results: {
4
+ [k: string]: any;
5
+ };
6
+ }>;
@@ -0,0 +1,87 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { loadCanonicalProjectContext, prepareCanonicalManifest } from "./project-runtime.js";
3
+ import { assertPredefinedPackageState } from "./predefined-packages/health.js";
4
+ import { readInstalledState, writeChecksState } from "./state.js";
5
+ function execute(command, args, cwd) {
6
+ return new Promise((resolve, reject) => {
7
+ const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
8
+ let stdout = '';
9
+ let stderr = '';
10
+ child.stdout.setEncoding('utf8');
11
+ child.stderr.setEncoding('utf8');
12
+ child.stdout.on('data', (chunk) => { stdout += chunk; });
13
+ child.stderr.on('data', (chunk) => { stderr += chunk; });
14
+ child.on('error', reject);
15
+ child.on('close', (code) => resolve({ exitCode: code ?? 1, stdout, stderr }));
16
+ });
17
+ }
18
+ export async function canonicalCheck(projectRoot, source, options = {}) {
19
+ await assertPredefinedPackageState(projectRoot);
20
+ const current = await readInstalledState(projectRoot);
21
+ const { applicable, canonicalCheckRoot, checkerRuntimeRoot } = await loadCanonicalProjectContext(projectRoot, source, { offline: false, withCheckers: true, refresh: options.refresh ?? false });
22
+ const byId = new Map(applicable.map((entry) => [entry.id, entry]));
23
+ const results = {};
24
+ const groups = new Map();
25
+ const executor = options.executor ?? execute;
26
+ const targetMode = options.mode ?? 'full';
27
+ let targetFiles = options.files ?? null;
28
+ if (targetMode === 'staged' && targetFiles === null) {
29
+ const staged = await executor('git', ['diff', '--cached', '--name-only', '-z', '--diff-filter=ACMR'], projectRoot);
30
+ if (staged.exitCode !== 0)
31
+ throw new Error(staged.stderr || 'Unable to read staged files');
32
+ targetFiles = staged.stdout.split('\0').filter(Boolean);
33
+ }
34
+ const normalizedTargetFiles = (targetFiles ?? []).map((file) => String(file).replaceAll('\\', '/'));
35
+ let exitCode = 0;
36
+ for (const [id, installed] of Object.entries(current.installed).sort(([a], [b]) => a.localeCompare(b))) {
37
+ const entry = byId.get(id);
38
+ if (!entry || installed.kind !== 'rule')
39
+ continue;
40
+ const prepared = await prepareCanonicalManifest(source, entry, canonicalCheckRoot, checkerRuntimeRoot);
41
+ if (!prepared?.checkerPath) {
42
+ if ((entry.enforcement ?? 'guidance') === 'guidance')
43
+ continue;
44
+ results[id] = { status: 'fail', exitCode: 1, stderr: 'Canonical checker unavailable for enforced installed rule.' };
45
+ exitCode = 1;
46
+ continue;
47
+ }
48
+ if (prepared.execution === 'manual')
49
+ continue;
50
+ const baseKey = prepared.checkerKey ?? `path:${prepared.checkerPath}:${JSON.stringify(prepared.checkerArgs ?? [])}`;
51
+ const key = `${baseKey}:targeting:${prepared.targeting?.scope ?? 'repository'}:execution:${prepared.execution ?? 'automatic'}`;
52
+ const group = groups.get(key) ?? {
53
+ checkerPath: prepared.checkerPath,
54
+ checkerArgs: prepared.checkerArgs ?? [],
55
+ targeting: prepared.targeting ?? { scope: 'repository' },
56
+ ids: [],
57
+ };
58
+ group.ids.push(id);
59
+ groups.set(key, group);
60
+ }
61
+ const groupExecutions = await Promise.all([...groups.values()].map(async (group) => {
62
+ const args = [group.checkerPath, ...group.checkerArgs];
63
+ if (targetMode !== 'full' && group.targeting.scope !== 'repository') {
64
+ args.push('--target-mode', targetMode);
65
+ for (const file of normalizedTargetFiles)
66
+ args.push('--target-file', file);
67
+ }
68
+ const execution = await executor('node', args, projectRoot);
69
+ return { group, execution };
70
+ }));
71
+ for (const { group, execution } of groupExecutions) {
72
+ const result = { status: execution.exitCode === 0 ? 'pass' : 'fail', ...execution };
73
+ for (const id of group.ids)
74
+ results[id] = result;
75
+ if (execution.exitCode !== 0)
76
+ exitCode = 1;
77
+ }
78
+ const orderedResults = Object.fromEntries(Object.entries(results).sort(([a], [b]) => a.localeCompare(b)));
79
+ if (targetMode === 'full') {
80
+ await writeChecksState(projectRoot, {
81
+ schemaVersion: 2,
82
+ checkedAt: new Date().toISOString(),
83
+ results: Object.fromEntries(Object.entries(orderedResults).map(([id, result]) => [id, { status: result.status }])),
84
+ });
85
+ }
86
+ return { exitCode, results: orderedResults };
87
+ }