@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.
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 -433
  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
@@ -1,250 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import { homedir } from 'node:os';
3
- import { dirname, join } from 'node:path';
4
- import { mkdir, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises';
5
-
6
- const DEFAULT_REPOSITORY = 'specdest-org/devkit';
7
- const DEFAULT_REF = 'main';
8
-
9
- async function exists(path) {
10
- try { await stat(path); return true; } catch (error) { if (error?.code === 'ENOENT') return false; throw error; }
11
- }
12
-
13
- function defaultCacheRoot(env = process.env) {
14
- return join(env.XDG_CACHE_HOME?.trim() || join(homedir(), '.cache'), 'specdest', 'devkit');
15
- }
16
-
17
- function repositoryUrl(options = {}) {
18
- if (options.repositoryUrl) return String(options.repositoryUrl);
19
- const repository = String(options.repository ?? DEFAULT_REPOSITORY);
20
- if (repository.startsWith('/') || repository.startsWith('.') || repository.includes('://') || repository.startsWith('git@')) {
21
- return repository;
22
- }
23
- return `git@github.com:${repository}.git`;
24
- }
25
-
26
- function run(command, args, options = {}) {
27
- return new Promise((resolve, reject) => {
28
- const child = spawn(command, args, { cwd: options.cwd, stdio: ['ignore', 'pipe', 'pipe'] });
29
- let stdout = '';
30
- let stderr = '';
31
- child.stdout.setEncoding('utf8');
32
- child.stderr.setEncoding('utf8');
33
- child.stdout.on('data', (chunk) => { stdout += chunk; });
34
- child.stderr.on('data', (chunk) => { stderr += chunk; });
35
- child.on('error', reject);
36
- child.on('close', (code) => code === 0 ? resolve(stdout) : reject(new Error(`${command} exited ${code}: ${stderr.trim()}`)));
37
- });
38
- }
39
-
40
- async function ensureGitRepository(cacheRoot, options = {}) {
41
- const gitDir = join(cacheRoot, 'source.git');
42
- const url = repositoryUrl(options);
43
- const ref = String(options.ref ?? DEFAULT_REF);
44
- if (!(await exists(join(gitDir, 'HEAD')))) {
45
- await mkdir(cacheRoot, { recursive: true });
46
- await run('git', ['clone', '--bare', '--single-branch', '--branch', ref, url, gitDir]);
47
- } else {
48
- const configured = (await run('git', ['--git-dir', gitDir, 'remote', 'get-url', 'origin'])).trim();
49
- if (configured !== url) throw new Error(`Canonical Devkit cache remote mismatch: ${configured}`);
50
- }
51
- return gitDir;
52
- }
53
-
54
- async function fetchGitRevision(cacheRoot, options = {}) {
55
- const gitDir = await ensureGitRepository(cacheRoot, options);
56
- const ref = String(options.ref ?? DEFAULT_REF);
57
- await run('git', ['--git-dir', gitDir, 'fetch', '--prune', 'origin', ref]);
58
- const revision = (await run('git', ['--git-dir', gitDir, 'rev-parse', 'FETCH_HEAD'])).trim();
59
- return { gitDir, revision };
60
- }
61
-
62
- async function readGitFile(gitDir, revision, path) {
63
- return await run('git', ['--git-dir', gitDir, 'show', `${revision}:${path}`]);
64
- }
65
-
66
- async function readGitModule(gitDir, revision, id) {
67
- const prefix = `modules/${id}/`;
68
- const listed = await run('git', ['--git-dir', gitDir, 'ls-tree', '-r', '--name-only', revision, '--', `modules/${id}`]);
69
- const paths = listed.split('\n').map((value) => value.trim()).filter((value) => value.startsWith(prefix));
70
- if (!paths.length) throw new Error(`Canonical module directory not found: ${id}`);
71
- const files = [];
72
- for (const path of paths.sort()) {
73
- files.push({ path: path.slice(prefix.length), content: await readGitFile(gitDir, revision, path) });
74
- }
75
- return { files };
76
- }
77
-
78
- async function writePayload(root, files) {
79
- for (const file of files) {
80
- const target = join(root, file.path);
81
- await mkdir(dirname(target), { recursive: true });
82
- await writeFile(target, file.content, 'utf8');
83
- }
84
- }
85
-
86
- async function readMarker(path) {
87
- try { return JSON.parse(await readFile(path, 'utf8')); } catch (error) {
88
- if (error?.code === 'ENOENT' || error instanceof SyntaxError) return null;
89
- throw error;
90
- }
91
- }
92
-
93
- function markerMatches(marker, id, version, contentHash) {
94
- return Boolean(marker && marker.id === id && marker.version === version && (!contentHash || marker.contentHash === contentHash));
95
- }
96
-
97
- export function createCanonicalSource(options = {}) {
98
- const cacheRoot = options.cacheRoot ?? defaultCacheRoot(options.env);
99
- const catalogPath = join(cacheRoot, 'catalog.json');
100
- const catalogMetaPath = join(cacheRoot, 'catalog-meta.json');
101
- const customFetch = Boolean(options.fetchCatalog || options.fetchModule);
102
- let activeRevision = null;
103
- let activeGitDir = null;
104
-
105
- async function cachedCatalog() {
106
- if (!(await exists(catalogPath)) || !(await exists(catalogMetaPath))) return null;
107
- const meta = JSON.parse(await readFile(catalogMetaPath, 'utf8'));
108
- if (!customFetch && (meta.repositoryUrl !== repositoryUrl(options) || meta.ref !== String(options.ref ?? DEFAULT_REF))) return null;
109
- activeRevision = meta.revision ?? null;
110
- if (!customFetch) activeGitDir = await ensureGitRepository(cacheRoot, options);
111
- return JSON.parse(await readFile(catalogPath, 'utf8'));
112
- }
113
-
114
- async function refreshCatalog() {
115
- let catalog;
116
- let revision;
117
- if (options.fetchCatalog) {
118
- catalog = await options.fetchCatalog();
119
- revision = String(catalog.repositoryRevision ?? catalog.package?.version ?? 'custom');
120
- } else {
121
- const fetched = await fetchGitRevision(cacheRoot, options);
122
- activeGitDir = fetched.gitDir;
123
- revision = fetched.revision;
124
- const rawCatalog = JSON.parse(await readGitFile(activeGitDir, revision, 'catalog.json'));
125
- catalog = {
126
- ...rawCatalog,
127
- repositoryRevision: revision,
128
- entries: (rawCatalog.entries ?? []).map((entry) => ({ ...entry, revision })),
129
- };
130
- }
131
- activeRevision = revision;
132
- await mkdir(cacheRoot, { recursive: true });
133
- await writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`, 'utf8');
134
- await writeFile(catalogMetaPath, `${JSON.stringify({
135
- revision,
136
- ref: String(options.ref ?? DEFAULT_REF),
137
- repositoryUrl: customFetch ? 'custom' : repositoryUrl(options),
138
- }, null, 2)}\n`, 'utf8');
139
- return catalog;
140
- }
141
-
142
- async function revisionForModule() {
143
- if (activeRevision) return activeRevision;
144
- const catalog = await cachedCatalog();
145
- if (catalog && activeRevision) return activeRevision;
146
- await refreshCatalog();
147
- return activeRevision;
148
- }
149
-
150
- return {
151
- cacheRoot,
152
- cachedModulePath(id, version) { return join(cacheRoot, 'rules', id, version); },
153
- async hasModule(id, version, contentHash = null) {
154
- const marker = await readMarker(join(cacheRoot, 'rules', id, version, '.complete'));
155
- return markerMatches(marker, id, version, contentHash);
156
- },
157
- async catalog({ refresh = false } = {}) {
158
- if (!refresh) {
159
- const cached = await cachedCatalog();
160
- if (cached) return cached;
161
- }
162
- return await refreshCatalog();
163
- },
164
- async module(id, version, { refresh = false, contentHash = null } = {}) {
165
- const root = join(cacheRoot, 'rules', id, version);
166
- const markerPath = join(root, '.complete');
167
- const marker = await readMarker(markerPath);
168
- if (!refresh && markerMatches(marker, id, version, contentHash)) return root;
169
-
170
- const revision = await revisionForModule();
171
- let payload;
172
- if (options.fetchModule) payload = await options.fetchModule(id, { revision });
173
- else {
174
- activeGitDir ??= await ensureGitRepository(cacheRoot, options);
175
- payload = await readGitModule(activeGitDir, revision, id);
176
- }
177
- await rm(root, { recursive: true, force: true });
178
- await mkdir(root, { recursive: true });
179
- await writePayload(root, payload.files ?? []);
180
- await writeFile(markerPath, `${JSON.stringify({ id, version, contentHash, revision })}\n`, 'utf8');
181
- return root;
182
- },
183
- };
184
- }
185
-
186
- async function directoryFiles(root, prefix = '') {
187
- const files = [];
188
- for (const entry of (await readdir(root, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
189
- if (entry.name === '.complete') continue;
190
- const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
191
- if (entry.isDirectory()) files.push(...await directoryFiles(join(root, entry.name), relative));
192
- else if (entry.isFile()) files.push({ path: relative, content: await readFile(join(root, entry.name), 'utf8') });
193
- }
194
- return files;
195
- }
196
-
197
- export async function fetchGitHubCatalog(options = {}) {
198
- return await createCanonicalSource(options).catalog({ refresh: true });
199
- }
200
-
201
- export async function fetchGitHubModule(id, options = {}) {
202
- const source = createCanonicalSource(options);
203
- const catalog = await source.catalog({ refresh: true });
204
- const entry = (catalog.entries ?? []).find((candidate) => candidate.id === id);
205
- if (!entry) throw new Error(`Canonical module not found in catalog: ${id}`);
206
- const root = await source.module(id, entry.version, { contentHash: entry.contentHash });
207
- return { files: await directoryFiles(root) };
208
- }
209
-
210
- function stackFromDependencies(deps) {
211
- const expo = Boolean(deps.expo);
212
- const vite = Boolean(deps.vite || deps['@vitejs/plugin-react']);
213
- const convex = Boolean(deps.convex);
214
- const supabase = Boolean(deps['@supabase/supabase-js']);
215
- if (expo && convex) return 'stack-expo-convex';
216
- if (expo && supabase) return 'stack-expo-supabase';
217
- if (vite && convex) return 'stack-vite-convex';
218
- if (vite && supabase) return 'stack-vite-supabase';
219
- return null;
220
- }
221
-
222
- async function readPackageDependencies(path) {
223
- try {
224
- const pkg = JSON.parse(await readFile(path, 'utf8'));
225
- return { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
226
- } catch (error) {
227
- if (error?.code === 'ENOENT') return null;
228
- throw error;
229
- }
230
- }
231
-
232
- export async function detectProjectStack(projectRoot) {
233
- const dependencySets = [];
234
- const rootDeps = await readPackageDependencies(join(projectRoot, 'package.json'));
235
- if (rootDeps) dependencySets.push(rootDeps);
236
- for (const group of ['apps', 'packages']) {
237
- let children = [];
238
- try { children = await readdir(join(projectRoot, group), { withFileTypes: true }); }
239
- catch (error) { if (error?.code !== 'ENOENT') throw error; }
240
- for (const child of children.filter((entry) => entry.isDirectory())) {
241
- const deps = await readPackageDependencies(join(projectRoot, group, child.name, 'package.json'));
242
- if (deps) dependencySets.push(deps);
243
- }
244
- }
245
- const detected = new Set(dependencySets.map(stackFromDependencies).filter(Boolean));
246
- if (detected.size === 1) return [...detected][0];
247
- if (detected.size > 1) throw new Error(`Multiple canonical stacks detected: ${[...detected].sort().join(', ')}`);
248
- const combined = Object.assign({}, ...dependencySets);
249
- return stackFromDependencies(combined);
250
- }
@@ -1,39 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { listCatalogEntries, loadCatalogEntry } from './catalog.js';
3
-
4
- function firstHeading(content) {
5
- const line = content.split(/\r?\n/u).find((item) => /^#\s+\S/u.test(item.trim()));
6
- return line ? line.trim().replace(/^#\s+/u, '').trim() : null;
7
- }
8
-
9
- function displayContent(entry) {
10
- const skill = entry.artifacts.find((artifact) => artifact.path.endsWith('/SKILL.md'));
11
- return skill?.content?.trim() || `${entry.kind} ${entry.id}`;
12
- }
13
-
14
- export async function buildCatalogSnapshot() {
15
- const packageJson = JSON.parse(
16
- await readFile(new URL('../package.json', import.meta.url), 'utf8'),
17
- );
18
- const listed = await listCatalogEntries();
19
- const entries = [];
20
- for (const item of listed) {
21
- const entry = await loadCatalogEntry(item.id);
22
- const content = displayContent(entry);
23
- entries.push({
24
- id: entry.id,
25
- kind: entry.kind,
26
- version: entry.version,
27
- name: firstHeading(content) ?? entry.id,
28
- content,
29
- group: entry.kind === 'module' ? 'Modules' : 'Rules',
30
- order: entries.length + 1,
31
- source: '@specdest/devkit',
32
- });
33
- }
34
- return {
35
- schemaVersion: 1,
36
- package: { name: packageJson.name, version: packageJson.version },
37
- entries,
38
- };
39
- }
package/src/catalog.js DELETED
@@ -1,117 +0,0 @@
1
- import { readdir, readFile } from 'node:fs/promises';
2
- import { dirname, join } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- import { validateSetupRequirements } from './setup-requirements.js';
6
- import { validateManifest } from './sync-core.js';
7
-
8
- export { validateSetupRequirements } from './setup-requirements.js';
9
-
10
- const DEFAULT_CATALOG_ROOT = fileURLToPath(new URL('../catalog/', import.meta.url));
11
-
12
- async function readManifest(path) {
13
- const parsed = JSON.parse(await readFile(path, 'utf8'));
14
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
15
- throw new Error(`Catalog manifest must be an object: ${path}`);
16
- }
17
- return parsed;
18
- }
19
-
20
- async function manifestLocations(catalogRoot = DEFAULT_CATALOG_ROOT) {
21
- const locations = [];
22
- for (const group of ['modules', 'rules']) {
23
- const groupRoot = join(catalogRoot, group);
24
- let entries;
25
- try {
26
- entries = await readdir(groupRoot, { withFileTypes: true });
27
- } catch (error) {
28
- if (error?.code === 'ENOENT') continue;
29
- throw error;
30
- }
31
- for (const entry of entries) {
32
- if (!entry.isDirectory()) continue;
33
- locations.push(join(groupRoot, entry.name, 'manifest.json'));
34
- }
35
- }
36
- return locations.sort();
37
- }
38
-
39
- async function hydrateManifest(manifestPath) {
40
- const raw = await readManifest(manifestPath);
41
- const base = dirname(manifestPath);
42
- const artifacts = [];
43
- for (const artifact of raw.artifacts ?? []) {
44
- if (!artifact?.source) {
45
- artifacts.push({ ...artifact });
46
- continue;
47
- }
48
- const { source, ...rest } = artifact;
49
- artifacts.push({
50
- ...rest,
51
- content: await readFile(join(base, source), 'utf8'),
52
- });
53
- }
54
- const hydrated = { ...raw, artifacts };
55
- validateManifest(hydrated);
56
- const requires = hydrated.requires ?? [];
57
- if (!Array.isArray(requires) || requires.some((id) => !String(id).trim())) {
58
- throw new Error(`Invalid catalog dependencies: ${hydrated.id}`);
59
- }
60
- validateSetupRequirements(hydrated.setupRequirements ?? []);
61
- if (hydrated.check) {
62
- if (!Array.isArray(hydrated.check.command) || hydrated.check.command.length === 0) {
63
- throw new Error(`Invalid checker command: ${hydrated.id}`);
64
- }
65
- }
66
- return hydrated;
67
- }
68
-
69
- export async function listCatalogEntries(options = {}) {
70
- const root = options.catalogRoot ?? DEFAULT_CATALOG_ROOT;
71
- const entries = [];
72
- for (const path of await manifestLocations(root)) {
73
- const manifest = await readManifest(path);
74
- entries.push({ id: manifest.id, kind: manifest.kind, version: manifest.version });
75
- }
76
- return entries.sort((a, b) => a.id.localeCompare(b.id));
77
- }
78
-
79
- async function catalogIndex(catalogRoot = DEFAULT_CATALOG_ROOT) {
80
- const index = new Map();
81
- for (const path of await manifestLocations(catalogRoot)) {
82
- const manifest = await readManifest(path);
83
- if (index.has(manifest.id)) throw new Error(`Duplicate catalog id: ${manifest.id}`);
84
- index.set(manifest.id, path);
85
- }
86
- return index;
87
- }
88
-
89
- export async function loadCatalogEntry(id, options = {}) {
90
- const root = options.catalogRoot ?? DEFAULT_CATALOG_ROOT;
91
- const index = await catalogIndex(root);
92
- const path = index.get(id);
93
- if (!path) throw new Error(`Catalog entry not found: ${id}`);
94
- return await hydrateManifest(path);
95
- }
96
-
97
- export async function resolveCatalogSelection(ids, options = {}) {
98
- const root = options.catalogRoot ?? DEFAULT_CATALOG_ROOT;
99
- const index = await catalogIndex(root);
100
- const visiting = new Set();
101
- const resolved = new Map();
102
-
103
- const visit = async (id) => {
104
- if (resolved.has(id)) return;
105
- if (visiting.has(id)) throw new Error(`Catalog dependency cycle: ${id}`);
106
- const path = index.get(id);
107
- if (!path) throw new Error(`Catalog entry not found: ${id}`);
108
- visiting.add(id);
109
- const entry = await hydrateManifest(path);
110
- for (const required of entry.requires ?? []) await visit(required);
111
- visiting.delete(id);
112
- resolved.set(id, entry);
113
- };
114
-
115
- for (const id of ids) await visit(id);
116
- return [...resolved.values()];
117
- }
package/src/cli.js DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createFuzzCommandHandler, runCli } from './index.js';
3
- import { createCanonicalCommandHandlers } from './canonical-project-operations.js';
4
-
5
- try {
6
- const exitCode = await runCli(process.argv.slice(2), process, {
7
- ...createCanonicalCommandHandlers(),
8
- fuzz: createFuzzCommandHandler(),
9
- });
10
- process.exitCode = exitCode;
11
- } catch (error) {
12
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
13
- process.exitCode = 1;
14
- }