@specdest/devkit 0.4.5 → 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.
- package/README.md +34 -4
- package/dist/npm/canonical-project-operations.d.ts +5 -0
- package/dist/npm/canonical-project-operations.js +5 -0
- package/dist/npm/canonical-project.d.ts +10 -0
- package/dist/npm/canonical-project.js +109 -0
- package/dist/npm/canonical-source.d.ts +14 -0
- package/dist/npm/canonical-source.js +216 -0
- package/dist/npm/catalog-snapshot.d.ts +47 -0
- package/dist/npm/catalog-snapshot.js +28 -0
- package/dist/npm/cli.d.ts +2 -0
- package/dist/npm/cli.js +15 -0
- package/dist/npm/commands.d.ts +9 -0
- package/dist/npm/commands.js +157 -0
- package/dist/npm/flow.d.ts +48 -0
- package/dist/npm/flow.js +396 -0
- package/dist/npm/fuzz.d.ts +138 -0
- package/dist/npm/fuzz.js +327 -0
- package/dist/npm/git-catalog.d.ts +39 -0
- package/dist/npm/git-catalog.js +190 -0
- package/dist/npm/index.d.ts +5 -0
- package/dist/npm/index.js +22 -0
- package/dist/npm/installer-primitives.d.ts +3 -0
- package/dist/npm/installer-primitives.js +50 -0
- package/dist/npm/predefined-packages/abac.d.ts +2 -0
- package/dist/npm/predefined-packages/abac.js +22 -0
- package/dist/npm/predefined-packages/auth.d.ts +2 -0
- package/dist/npm/predefined-packages/auth.js +21 -0
- package/dist/npm/predefined-packages/convex.d.ts +2 -0
- package/dist/npm/predefined-packages/convex.js +53 -0
- package/dist/npm/predefined-packages/expo.d.ts +2 -0
- package/dist/npm/predefined-packages/expo.js +84 -0
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +2 -0
- package/dist/npm/predefined-packages/firebase-hosting.js +24 -0
- package/dist/npm/predefined-packages/health.d.ts +10 -0
- package/dist/npm/predefined-packages/health.js +52 -0
- package/dist/npm/predefined-packages/husky.d.ts +2 -0
- package/dist/npm/predefined-packages/husky.js +57 -0
- package/dist/npm/predefined-packages/index.d.ts +11 -0
- package/dist/npm/predefined-packages/index.js +56 -0
- package/dist/npm/predefined-packages/install.d.ts +19 -0
- package/dist/npm/predefined-packages/install.js +85 -0
- package/dist/npm/predefined-packages/local-logging.d.ts +2 -0
- package/dist/npm/predefined-packages/local-logging.js +17 -0
- package/dist/npm/predefined-packages/logging.d.ts +2 -0
- package/dist/npm/predefined-packages/logging.js +21 -0
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +2 -0
- package/dist/npm/predefined-packages/multi-tenancy.js +21 -0
- package/dist/npm/predefined-packages/nps.d.ts +2 -0
- package/dist/npm/predefined-packages/nps.js +32 -0
- package/dist/npm/predefined-packages/oxfmt.d.ts +2 -0
- package/dist/npm/predefined-packages/oxfmt.js +22 -0
- package/dist/npm/predefined-packages/oxlint.d.ts +2 -0
- package/dist/npm/predefined-packages/oxlint.js +35 -0
- package/dist/npm/predefined-packages/package-json.d.ts +3 -0
- package/dist/npm/predefined-packages/package-json.js +61 -0
- package/dist/npm/predefined-packages/payments.d.ts +2 -0
- package/dist/npm/predefined-packages/payments.js +31 -0
- package/dist/npm/predefined-packages/playwright.d.ts +2 -0
- package/dist/npm/predefined-packages/playwright.js +35 -0
- package/dist/npm/predefined-packages/project-signals.d.ts +4 -0
- package/dist/npm/predefined-packages/project-signals.js +39 -0
- package/dist/npm/predefined-packages/registry.d.ts +3 -0
- package/dist/npm/predefined-packages/registry.js +63 -0
- package/dist/npm/predefined-packages/resolver.d.ts +8 -0
- package/dist/npm/predefined-packages/resolver.js +35 -0
- package/dist/npm/predefined-packages/sentry.d.ts +2 -0
- package/dist/npm/predefined-packages/sentry.js +29 -0
- package/dist/npm/predefined-packages/shadcn.d.ts +2 -0
- package/dist/npm/predefined-packages/shadcn.js +23 -0
- package/dist/npm/predefined-packages/storybook.d.ts +2 -0
- package/dist/npm/predefined-packages/storybook.js +25 -0
- package/dist/npm/predefined-packages/stryker.d.ts +2 -0
- package/dist/npm/predefined-packages/stryker.js +48 -0
- package/dist/npm/predefined-packages/supabase.d.ts +2 -0
- package/dist/npm/predefined-packages/supabase.js +84 -0
- package/dist/npm/predefined-packages/tailwind.d.ts +2 -0
- package/dist/npm/predefined-packages/tailwind.js +18 -0
- package/dist/npm/predefined-packages/tanstack-form.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-form.js +19 -0
- package/dist/npm/predefined-packages/tanstack-query.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-query.js +15 -0
- package/dist/npm/predefined-packages/tanstack-router.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-router.js +18 -0
- package/dist/npm/predefined-packages/types.d.ts +31 -0
- package/dist/npm/predefined-packages/types.js +1 -0
- package/dist/npm/predefined-packages/vite.d.ts +2 -0
- package/dist/npm/predefined-packages/vite.js +123 -0
- package/dist/npm/predefined-packages/vitest.d.ts +2 -0
- package/dist/npm/predefined-packages/vitest.js +20 -0
- package/dist/npm/predefined-packages/zod.d.ts +2 -0
- package/dist/npm/predefined-packages/zod.js +18 -0
- package/dist/npm/project-check.d.ts +6 -0
- package/dist/npm/project-check.js +87 -0
- package/dist/npm/project-context.d.ts +42 -0
- package/dist/npm/project-context.js +192 -0
- package/dist/npm/project-rules.d.ts +22 -0
- package/dist/npm/project-rules.js +66 -0
- package/dist/npm/project-runtime.d.ts +18 -0
- package/dist/npm/project-runtime.js +27 -0
- package/dist/npm/project-status.d.ts +32 -0
- package/dist/npm/project-status.js +56 -0
- package/dist/npm/project-sync.d.ts +7 -0
- package/dist/npm/project-sync.js +135 -0
- package/dist/npm/remote-installer.d.ts +4 -0
- package/dist/npm/remote-installer.js +312 -0
- package/dist/npm/state.d.ts +14 -0
- package/dist/npm/state.js +182 -0
- package/package.json +10 -7
- package/src/canonical-project-operations.js +0 -433
- package/src/canonical-project.js +0 -136
- package/src/canonical-source.js +0 -250
- package/src/catalog-snapshot.js +0 -39
- package/src/catalog.js +0 -117
- package/src/cli.js +0 -14
- package/src/fuzz.js +0 -291
- package/src/git-catalog.js +0 -177
- package/src/index.js +0 -36
- package/src/installer-primitives.js +0 -198
- package/src/project-operations.js +0 -189
- package/src/project-targeting.js +0 -48
- package/src/remote-installer.js +0 -479
- package/src/rule-profile.js +0 -61
- package/src/setup-requirements.js +0 -82
- package/src/shared-file.js +0 -131
- package/src/sync-core.js +0 -390
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
export async function addPredefinedPackage(projectRoot, id, options = {}) {
|
|
6
|
+
const recipe = getPackageRecipe(id);
|
|
7
|
+
const state = await readInstalledState(projectRoot);
|
|
8
|
+
const recipes = listPackageRecipes();
|
|
9
|
+
const detections = await Promise.all(recipes.map(async (item) => [item.id, await item.detect(projectRoot)]));
|
|
10
|
+
const detectionById = new Map(detections);
|
|
11
|
+
const detected = detections.filter(([, result]) => result.present).map(([packageId]) => packageId);
|
|
12
|
+
const registeredPackages = new Set(installedPackageIds(state));
|
|
13
|
+
registeredPackages.delete(id);
|
|
14
|
+
const presentPackages = new Set(detected);
|
|
15
|
+
presentPackages.delete(id);
|
|
16
|
+
const resolution = resolvePackageAddition(recipe, {
|
|
17
|
+
registeredPackageIds: registeredPackages,
|
|
18
|
+
presentPackageIds: presentPackages,
|
|
19
|
+
knownRecipes: recipes,
|
|
20
|
+
});
|
|
21
|
+
const detection = detectionById.get(id);
|
|
22
|
+
if (!detection)
|
|
23
|
+
throw new Error(`Package detection missing for ${id}`);
|
|
24
|
+
const applied = await recipe.apply(projectRoot, detection, resolution, {
|
|
25
|
+
runCommand: options.runCommand ?? runPackageCommand,
|
|
26
|
+
});
|
|
27
|
+
const currentDetection = await recipe.detect(projectRoot);
|
|
28
|
+
if (!currentDetection.present || !currentDetection.compatible) {
|
|
29
|
+
throw new Error(currentDetection.reason ?? `${id} install did not produce a compatible package state`);
|
|
30
|
+
}
|
|
31
|
+
const entry = {
|
|
32
|
+
kind: 'package',
|
|
33
|
+
recipeVersion: recipe.recipeVersion,
|
|
34
|
+
detectedVersion: currentDetection.detectedVersion,
|
|
35
|
+
role: recipe.role,
|
|
36
|
+
source: applied.source,
|
|
37
|
+
...(resolution.variant ? { resolvedVariant: resolution.variant } : {}),
|
|
38
|
+
};
|
|
39
|
+
const existingEntry = state.installed[id];
|
|
40
|
+
const unchanged = existingEntry && JSON.stringify(existingEntry) === JSON.stringify(entry);
|
|
41
|
+
if (!unchanged) {
|
|
42
|
+
state.installed[id] = entry;
|
|
43
|
+
if (!state.requested.includes(id))
|
|
44
|
+
state.requested.push(id);
|
|
45
|
+
state.requested.sort();
|
|
46
|
+
await writeInstalledState(projectRoot, state);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
id,
|
|
50
|
+
recipeVersion: recipe.recipeVersion,
|
|
51
|
+
detectedVersion: currentDetection.detectedVersion,
|
|
52
|
+
source: applied.source,
|
|
53
|
+
resolvedVariant: resolution.variant,
|
|
54
|
+
changed: !unchanged,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -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,85 @@
|
|
|
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
|
+
const execFileAsync = promisify(execFile);
|
|
6
|
+
export async function runPackageCommand(command, args, options) {
|
|
7
|
+
try {
|
|
8
|
+
await execFileAsync(command, args, { cwd: options.cwd });
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
const detail = [error?.stderr, error?.stdout, error?.message]
|
|
12
|
+
.map((value) => String(value ?? '').trim())
|
|
13
|
+
.find(Boolean);
|
|
14
|
+
throw new Error(`${command} ${args.join(' ')} failed${detail ? `: ${detail}` : ''}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export async function updatePackageJson(projectRoot, update) {
|
|
18
|
+
const path = join(projectRoot, 'package.json');
|
|
19
|
+
let pkg = {};
|
|
20
|
+
try {
|
|
21
|
+
pkg = JSON.parse(await readFile(path, 'utf8'));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error?.code !== 'ENOENT')
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
const updated = update(pkg);
|
|
28
|
+
await writeFile(path, `${JSON.stringify(updated, null, 2)}\n`);
|
|
29
|
+
return updated;
|
|
30
|
+
}
|
|
31
|
+
export async function writeProjectFileIfMissing(projectRoot, relativePath, content) {
|
|
32
|
+
const path = join(projectRoot, relativePath);
|
|
33
|
+
try {
|
|
34
|
+
await readFile(path);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error?.code !== 'ENOENT')
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
await mkdir(dirname(path), { recursive: true });
|
|
42
|
+
await writeFile(path, content);
|
|
43
|
+
}
|
|
44
|
+
export function mergeMissing(target, values) {
|
|
45
|
+
return { ...values, ...(target ?? {}) };
|
|
46
|
+
}
|
|
47
|
+
export function projectPackageName(projectRoot) {
|
|
48
|
+
const normalized = basename(projectRoot).toLowerCase().replace(/[^a-z0-9._-]+/gu, '-');
|
|
49
|
+
return normalized || 'specdest-app';
|
|
50
|
+
}
|
|
51
|
+
export async function ensurePnpmBuildPolicy(projectRoot) {
|
|
52
|
+
const path = join(projectRoot, 'pnpm-workspace.yaml');
|
|
53
|
+
let existing = '';
|
|
54
|
+
try {
|
|
55
|
+
existing = await readFile(path, 'utf8');
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error?.code !== 'ENOENT')
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
let updated = existing;
|
|
62
|
+
if (!/^verifyDepsBeforeRun:\s*error\s*$/mu.test(updated)) {
|
|
63
|
+
updated = `verifyDepsBeforeRun: error\n\n${updated.trimStart()}`;
|
|
64
|
+
}
|
|
65
|
+
if (!/^allowBuilds:\s*$/mu.test(updated)) {
|
|
66
|
+
updated = `${updated.trimEnd()}\n\nallowBuilds:\n`;
|
|
67
|
+
}
|
|
68
|
+
if (!/^\s{2}esbuild:\s*true\s*$/mu.test(updated)) {
|
|
69
|
+
updated = updated.replace(/^allowBuilds:\s*$/mu, 'allowBuilds:\n esbuild: true');
|
|
70
|
+
}
|
|
71
|
+
if (updated !== existing)
|
|
72
|
+
await writeFile(path, `${updated.trimEnd()}\n`);
|
|
73
|
+
}
|
|
74
|
+
export async function installPackageJsonPatch(projectRoot, runCommand, patch) {
|
|
75
|
+
await updatePackageJson(projectRoot, (pkg) => ({
|
|
76
|
+
...pkg,
|
|
77
|
+
...(patch.dependencies ? { dependencies: mergeMissing(pkg.dependencies, patch.dependencies) } : {}),
|
|
78
|
+
...(patch.devDependencies ? { devDependencies: mergeMissing(pkg.devDependencies, patch.devDependencies) } : {}),
|
|
79
|
+
...(patch.scripts ? { scripts: mergeMissing(pkg.scripts, patch.scripts) } : {}),
|
|
80
|
+
}));
|
|
81
|
+
await runCommand('pnpm', ['install', '--no-frozen-lockfile'], { cwd: projectRoot });
|
|
82
|
+
}
|
|
83
|
+
export async function makeProjectFileExecutable(projectRoot, relativePath) {
|
|
84
|
+
await chmod(join(projectRoot, relativePath), 0o755);
|
|
85
|
+
}
|
|
@@ -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,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,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,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,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,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,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,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,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
|
+
}
|