stera-ui 0.5.0 → 0.6.1

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.
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ createSpinner,
4
+ getAllComponents
5
+ } from "./chunk-KKUJRJ2N.js";
6
+ import {
7
+ LOGO,
8
+ dim
9
+ } from "./chunk-KGMF6UW4.js";
10
+
11
+ // src/commands/list.ts
12
+ async function list() {
13
+ const spinner = createSpinner("Fetching registry");
14
+ let items;
15
+ try {
16
+ items = await getAllComponents();
17
+ } catch (err) {
18
+ spinner.fail("Failed to fetch registry");
19
+ throw err;
20
+ }
21
+ spinner.succeed("Registry resolved");
22
+ const groups = /* @__PURE__ */ new Map();
23
+ for (const item of items) {
24
+ const type = item.type.replace("registry:", "");
25
+ if (!groups.has(type)) groups.set(type, []);
26
+ groups.get(type).push(item);
27
+ }
28
+ console.log(`
29
+ ${LOGO} Available components
30
+ `);
31
+ for (const [type, groupItems] of groups) {
32
+ console.log(` ${type}`);
33
+ for (const item of groupItems) {
34
+ const deps = item.registryDependencies?.length ? dim(` (depends on: ${item.registryDependencies.join(", ")})`) : "";
35
+ console.log(` ${item.name}${deps}`);
36
+ }
37
+ console.log("");
38
+ }
39
+ console.log(` ${dim(`${items.length} components available`)}
40
+ `);
41
+ }
42
+ export {
43
+ list
44
+ };
@@ -1,16 +1,15 @@
1
- import { RegistryItem } from '../schema/index.js';
1
+ import { RegistryIndexEntry, RegistryItem } from '../schema/index.js';
2
2
  import 'zod';
3
3
 
4
- interface RegistryIndexItem {
5
- name: string;
6
- type: string;
7
- dependencies?: string[];
8
- registryDependencies?: string[];
4
+ /** Thrown when requested components (or their dependencies) are not in the registry. */
5
+ declare class ComponentNotFoundError extends Error {
6
+ readonly components: string[];
7
+ constructor(components: string[]);
9
8
  }
10
9
  /**
11
10
  * Fetch the registry index (component list without file contents).
12
11
  */
13
- declare function fetchRegistryIndex(): Promise<RegistryIndexItem[]>;
12
+ declare function fetchRegistryIndex(): Promise<RegistryIndexEntry[]>;
14
13
  /**
15
14
  * Fetch a single registry item with its file contents.
16
15
  */
@@ -18,15 +17,22 @@ declare function fetchRegistryItem(name: string): Promise<RegistryItem>;
18
17
  /**
19
18
  * Get a component from the registry index (no file contents).
20
19
  */
21
- declare function getComponent(name: string): Promise<RegistryIndexItem | undefined>;
20
+ declare function getComponent(name: string): Promise<RegistryIndexEntry | undefined>;
22
21
  /**
23
22
  * Get all components from the registry index.
24
23
  */
25
- declare function getAllComponents(): Promise<RegistryIndexItem[]>;
24
+ declare function getAllComponents(): Promise<RegistryIndexEntry[]>;
26
25
  /**
27
26
  * Resolve all dependencies for the given component names.
28
27
  * Fetches full registry items (with file contents) for each.
28
+ *
29
+ * The dependency graph is walked using the registry index (a single cached
30
+ * request), then all needed items are fetched in one parallel batch.
31
+ * Order is preserved: requested components first, then dependencies.
32
+ *
33
+ * @throws ComponentNotFoundError when any name (requested or transitive)
34
+ * is missing from the registry index.
29
35
  */
30
36
  declare function resolveDependencies(names: string[]): Promise<RegistryItem[]>;
31
37
 
32
- export { RegistryItem, fetchRegistryIndex, fetchRegistryItem, getAllComponents, getComponent, resolveDependencies };
38
+ export { ComponentNotFoundError, RegistryIndexEntry, RegistryItem, fetchRegistryIndex, fetchRegistryItem, getAllComponents, getComponent, resolveDependencies };
@@ -1,11 +1,14 @@
1
1
  import {
2
+ ComponentNotFoundError,
2
3
  fetchRegistryIndex,
3
4
  fetchRegistryItem,
4
5
  getAllComponents,
5
6
  getComponent,
6
7
  resolveDependencies
7
- } from "../chunk-T3QWOVJR.js";
8
+ } from "../chunk-BJNLGEZJ.js";
9
+ import "../chunk-4E46BULJ.js";
8
10
  export {
11
+ ComponentNotFoundError,
9
12
  fetchRegistryIndex,
10
13
  fetchRegistryItem,
11
14
  getAllComponents,
@@ -8,13 +8,13 @@ declare const registryItemFileSchema: z.ZodObject<{
8
8
  content: z.ZodOptional<z.ZodString>;
9
9
  target: z.ZodOptional<z.ZodString>;
10
10
  }, "strip", z.ZodTypeAny, {
11
- path: string;
12
11
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
12
+ path: string;
13
13
  content?: string | undefined;
14
14
  target?: string | undefined;
15
15
  }, {
16
- path: string;
17
16
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
17
+ path: string;
18
18
  content?: string | undefined;
19
19
  target?: string | undefined;
20
20
  }>;
@@ -88,19 +88,19 @@ declare const registryItemSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
88
88
  content: z.ZodOptional<z.ZodString>;
89
89
  target: z.ZodOptional<z.ZodString>;
90
90
  }, "strip", z.ZodTypeAny, {
91
- path: string;
92
91
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
92
+ path: string;
93
93
  content?: string | undefined;
94
94
  target?: string | undefined;
95
95
  }, {
96
- path: string;
97
96
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
97
+ path: string;
98
98
  content?: string | undefined;
99
99
  target?: string | undefined;
100
100
  }>, "many">>;
101
101
  }, "strip", z.ZodTypeAny, {
102
- type: "registry:font";
103
102
  name: string;
103
+ type: "registry:font";
104
104
  font: {
105
105
  family: string;
106
106
  provider: "google";
@@ -114,14 +114,14 @@ declare const registryItemSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
114
114
  dependencies?: string[] | undefined;
115
115
  registryDependencies?: string[] | undefined;
116
116
  files?: {
117
- path: string;
118
117
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
118
+ path: string;
119
119
  content?: string | undefined;
120
120
  target?: string | undefined;
121
121
  }[] | undefined;
122
122
  }, {
123
- type: "registry:font";
124
123
  name: string;
124
+ type: "registry:font";
125
125
  font: {
126
126
  family: string;
127
127
  provider: "google";
@@ -135,8 +135,8 @@ declare const registryItemSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
135
135
  dependencies?: string[] | undefined;
136
136
  registryDependencies?: string[] | undefined;
137
137
  files?: {
138
- path: string;
139
138
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
139
+ path: string;
140
140
  content?: string | undefined;
141
141
  target?: string | undefined;
142
142
  }[] | undefined;
@@ -152,33 +152,33 @@ declare const registryItemSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
152
152
  content: z.ZodOptional<z.ZodString>;
153
153
  target: z.ZodOptional<z.ZodString>;
154
154
  }, "strip", z.ZodTypeAny, {
155
- path: string;
156
155
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
156
+ path: string;
157
157
  content?: string | undefined;
158
158
  target?: string | undefined;
159
159
  }, {
160
- path: string;
161
160
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
161
+ path: string;
162
162
  content?: string | undefined;
163
163
  target?: string | undefined;
164
164
  }>, "many">;
165
165
  }, "strip", z.ZodTypeAny, {
166
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
167
166
  name: string;
167
+ type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
168
168
  files: {
169
- path: string;
170
169
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
170
+ path: string;
171
171
  content?: string | undefined;
172
172
  target?: string | undefined;
173
173
  }[];
174
174
  dependencies?: string[] | undefined;
175
175
  registryDependencies?: string[] | undefined;
176
176
  }, {
177
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
178
177
  name: string;
178
+ type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
179
179
  files: {
180
- path: string;
181
180
  type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
181
+ path: string;
182
182
  content?: string | undefined;
183
183
  target?: string | undefined;
184
184
  }[];
@@ -189,215 +189,57 @@ type RegistryItem = z.infer<typeof registryItemSchema>;
189
189
  type RegistryFontItem = Extract<RegistryItem, {
190
190
  type: "registry:font";
191
191
  }>;
192
+ declare const registryIndexEntrySchema: z.ZodObject<{
193
+ name: z.ZodString;
194
+ type: z.ZodString;
195
+ dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
196
+ registryDependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
197
+ }, "strip", z.ZodTypeAny, {
198
+ name: string;
199
+ type: string;
200
+ dependencies?: string[] | undefined;
201
+ registryDependencies?: string[] | undefined;
202
+ }, {
203
+ name: string;
204
+ type: string;
205
+ dependencies?: string[] | undefined;
206
+ registryDependencies?: string[] | undefined;
207
+ }>;
208
+ type RegistryIndexEntry = z.infer<typeof registryIndexEntrySchema>;
192
209
  declare const registryIndexSchema: z.ZodObject<{
193
210
  name: z.ZodString;
194
- items: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
195
- name: z.ZodString;
196
- dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
197
- registryDependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
198
- } & {
199
- type: z.ZodLiteral<"registry:font">;
200
- font: z.ZodObject<{
201
- family: z.ZodString;
202
- provider: z.ZodLiteral<"google">;
203
- import: z.ZodString;
204
- variable: z.ZodString;
205
- weight: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
206
- subsets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
207
- selector: z.ZodOptional<z.ZodString>;
208
- dependency: z.ZodOptional<z.ZodString>;
209
- }, "strip", z.ZodTypeAny, {
210
- family: string;
211
- provider: "google";
212
- import: string;
213
- variable: string;
214
- weight?: string[] | undefined;
215
- subsets?: string[] | undefined;
216
- selector?: string | undefined;
217
- dependency?: string | undefined;
218
- }, {
219
- family: string;
220
- provider: "google";
221
- import: string;
222
- variable: string;
223
- weight?: string[] | undefined;
224
- subsets?: string[] | undefined;
225
- selector?: string | undefined;
226
- dependency?: string | undefined;
227
- }>;
228
- files: z.ZodOptional<z.ZodArray<z.ZodObject<{
229
- path: z.ZodString;
230
- type: z.ZodEnum<["registry:ui", "registry:component", "registry:hook", "registry:lib", "registry:style", "registry:font"]>;
231
- content: z.ZodOptional<z.ZodString>;
232
- target: z.ZodOptional<z.ZodString>;
233
- }, "strip", z.ZodTypeAny, {
234
- path: string;
235
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
236
- content?: string | undefined;
237
- target?: string | undefined;
238
- }, {
239
- path: string;
240
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
241
- content?: string | undefined;
242
- target?: string | undefined;
243
- }>, "many">>;
244
- }, "strip", z.ZodTypeAny, {
245
- type: "registry:font";
246
- name: string;
247
- font: {
248
- family: string;
249
- provider: "google";
250
- import: string;
251
- variable: string;
252
- weight?: string[] | undefined;
253
- subsets?: string[] | undefined;
254
- selector?: string | undefined;
255
- dependency?: string | undefined;
256
- };
257
- dependencies?: string[] | undefined;
258
- registryDependencies?: string[] | undefined;
259
- files?: {
260
- path: string;
261
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
262
- content?: string | undefined;
263
- target?: string | undefined;
264
- }[] | undefined;
265
- }, {
266
- type: "registry:font";
267
- name: string;
268
- font: {
269
- family: string;
270
- provider: "google";
271
- import: string;
272
- variable: string;
273
- weight?: string[] | undefined;
274
- subsets?: string[] | undefined;
275
- selector?: string | undefined;
276
- dependency?: string | undefined;
277
- };
278
- dependencies?: string[] | undefined;
279
- registryDependencies?: string[] | undefined;
280
- files?: {
281
- path: string;
282
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
283
- content?: string | undefined;
284
- target?: string | undefined;
285
- }[] | undefined;
286
- }>, z.ZodObject<{
211
+ items: z.ZodArray<z.ZodObject<{
287
212
  name: z.ZodString;
213
+ type: z.ZodString;
288
214
  dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
289
215
  registryDependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
290
- } & {
291
- type: z.ZodEnum<["registry:ui", "registry:component", "registry:hook", "registry:lib", "registry:style"]>;
292
- files: z.ZodArray<z.ZodObject<{
293
- path: z.ZodString;
294
- type: z.ZodEnum<["registry:ui", "registry:component", "registry:hook", "registry:lib", "registry:style", "registry:font"]>;
295
- content: z.ZodOptional<z.ZodString>;
296
- target: z.ZodOptional<z.ZodString>;
297
- }, "strip", z.ZodTypeAny, {
298
- path: string;
299
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
300
- content?: string | undefined;
301
- target?: string | undefined;
302
- }, {
303
- path: string;
304
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
305
- content?: string | undefined;
306
- target?: string | undefined;
307
- }>, "many">;
308
216
  }, "strip", z.ZodTypeAny, {
309
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
310
217
  name: string;
311
- files: {
312
- path: string;
313
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
314
- content?: string | undefined;
315
- target?: string | undefined;
316
- }[];
218
+ type: string;
317
219
  dependencies?: string[] | undefined;
318
220
  registryDependencies?: string[] | undefined;
319
221
  }, {
320
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
321
222
  name: string;
322
- files: {
323
- path: string;
324
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
325
- content?: string | undefined;
326
- target?: string | undefined;
327
- }[];
223
+ type: string;
328
224
  dependencies?: string[] | undefined;
329
225
  registryDependencies?: string[] | undefined;
330
- }>]>, "many">;
226
+ }>, "many">;
331
227
  }, "strip", z.ZodTypeAny, {
332
228
  name: string;
333
- items: ({
334
- type: "registry:font";
229
+ items: {
335
230
  name: string;
336
- font: {
337
- family: string;
338
- provider: "google";
339
- import: string;
340
- variable: string;
341
- weight?: string[] | undefined;
342
- subsets?: string[] | undefined;
343
- selector?: string | undefined;
344
- dependency?: string | undefined;
345
- };
231
+ type: string;
346
232
  dependencies?: string[] | undefined;
347
233
  registryDependencies?: string[] | undefined;
348
- files?: {
349
- path: string;
350
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
351
- content?: string | undefined;
352
- target?: string | undefined;
353
- }[] | undefined;
354
- } | {
355
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
356
- name: string;
357
- files: {
358
- path: string;
359
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
360
- content?: string | undefined;
361
- target?: string | undefined;
362
- }[];
363
- dependencies?: string[] | undefined;
364
- registryDependencies?: string[] | undefined;
365
- })[];
234
+ }[];
366
235
  }, {
367
236
  name: string;
368
- items: ({
369
- type: "registry:font";
237
+ items: {
370
238
  name: string;
371
- font: {
372
- family: string;
373
- provider: "google";
374
- import: string;
375
- variable: string;
376
- weight?: string[] | undefined;
377
- subsets?: string[] | undefined;
378
- selector?: string | undefined;
379
- dependency?: string | undefined;
380
- };
239
+ type: string;
381
240
  dependencies?: string[] | undefined;
382
241
  registryDependencies?: string[] | undefined;
383
- files?: {
384
- path: string;
385
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
386
- content?: string | undefined;
387
- target?: string | undefined;
388
- }[] | undefined;
389
- } | {
390
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style";
391
- name: string;
392
- files: {
393
- path: string;
394
- type: "registry:ui" | "registry:component" | "registry:hook" | "registry:lib" | "registry:style" | "registry:font";
395
- content?: string | undefined;
396
- target?: string | undefined;
397
- }[];
398
- dependencies?: string[] | undefined;
399
- registryDependencies?: string[] | undefined;
400
- })[];
242
+ }[];
401
243
  }>;
402
244
  type RegistryIndex = z.infer<typeof registryIndexSchema>;
403
245
  declare const configSchema: z.ZodObject<{
@@ -466,4 +308,4 @@ declare const configSchema: z.ZodObject<{
466
308
  }>;
467
309
  type SteraConfig = z.infer<typeof configSchema>;
468
310
 
469
- export { type RegistryFontItem, type RegistryIndex, type RegistryItem, type RegistryItemFile, type RegistryItemFont, type RegistryItemType, type SteraConfig, configSchema, registryIndexSchema, registryItemFileSchema, registryItemFontSchema, registryItemSchema, registryItemTypeSchema };
311
+ export { type RegistryFontItem, type RegistryIndex, type RegistryIndexEntry, type RegistryItem, type RegistryItemFile, type RegistryItemFont, type RegistryItemType, type SteraConfig, configSchema, registryIndexEntrySchema, registryIndexSchema, registryItemFileSchema, registryItemFontSchema, registryItemSchema, registryItemTypeSchema };
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  configSchema,
3
+ registryIndexEntrySchema,
3
4
  registryIndexSchema,
4
5
  registryItemFileSchema,
5
6
  registryItemFontSchema,
6
7
  registryItemSchema,
7
8
  registryItemTypeSchema
8
- } from "../chunk-3KADOWKC.js";
9
+ } from "../chunk-4E46BULJ.js";
9
10
  export {
10
11
  configSchema,
12
+ registryIndexEntrySchema,
11
13
  registryIndexSchema,
12
14
  registryItemFileSchema,
13
15
  registryItemFontSchema,
@@ -119,9 +119,14 @@ declare function installDependencies(deps: string[], cwd: string): Promise<void>
119
119
  interface WriteOptions {
120
120
  overwrite?: boolean;
121
121
  }
122
+ interface SkippedFile {
123
+ path: string;
124
+ /** "unchanged" — identical content on disk; "declined" — user kept their version. */
125
+ reason: "unchanged" | "declined";
126
+ }
122
127
  interface WriteResult {
123
128
  written: string[];
124
- skipped: string[];
129
+ skipped: SkippedFile[];
125
130
  }
126
131
  /**
127
132
  * Write component files to the consumer's project.
@@ -167,4 +172,4 @@ declare function updateFonts(fonts: RegistryFontItem[], project: ProjectInfo, cw
167
172
  silent?: boolean;
168
173
  }): Promise<void>;
169
174
 
170
- export { CHECK, CONFIG_FILE, CROSS, LEGACY_CONFIG_FILE, LOGO, type ProjectInfo, type TransformContext, type TransformFn, WARN, type WriteOptions, type WriteResult, type WriteSteraCssResult, applyTransforms, brand, createSpinner, detectAliasPrefix, detectPackageManager, detectProject, dim, findConfigPath, insertImportLine, installDependencies, loadConfig, massageTreeForFonts, resolveOutputPath, transformImports, updateFonts, writeComponentFiles, writeSteraUiCss };
175
+ export { CHECK, CONFIG_FILE, CROSS, LEGACY_CONFIG_FILE, LOGO, type ProjectInfo, type SkippedFile, type TransformContext, type TransformFn, WARN, type WriteOptions, type WriteResult, type WriteSteraCssResult, applyTransforms, brand, createSpinner, detectAliasPrefix, detectPackageManager, detectProject, dim, findConfigPath, insertImportLine, installDependencies, loadConfig, massageTreeForFonts, resolveOutputPath, transformImports, updateFonts, writeComponentFiles, writeSteraUiCss };
@@ -22,8 +22,9 @@ import {
22
22
  updateFonts,
23
23
  writeComponentFiles,
24
24
  writeSteraUiCss
25
- } from "../chunk-F4NT3JC6.js";
26
- import "../chunk-T3QWOVJR.js";
25
+ } from "../chunk-SIXUH4HI.js";
26
+ import "../chunk-BJNLGEZJ.js";
27
+ import "../chunk-4E46BULJ.js";
27
28
  export {
28
29
  CHECK,
29
30
  CONFIG_FILE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stera-ui",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "description": "Add Stera UI components to your project.",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "homepage": "https://ui.stera.sh",
20
20
  "engines": {
21
- "node": ">=18"
21
+ "node": ">=20"
22
22
  },
23
23
  "bin": {
24
24
  "stera-ui": "./dist/cli.js"
@@ -1,60 +0,0 @@
1
- // src/registry/index.ts
2
- var REGISTRY_URL = process.env.REGISTRY_URL ?? "https://ui.stera.sh/r";
3
- var _indexCache = null;
4
- async function fetchJSON(url) {
5
- const res = await fetch(url);
6
- if (!res.ok) {
7
- throw new Error(`Failed to fetch ${url}: ${res.status} ${res.statusText}`);
8
- }
9
- return res.json();
10
- }
11
- async function fetchRegistryIndex() {
12
- if (_indexCache) return _indexCache;
13
- const data = await fetchJSON(
14
- `${REGISTRY_URL}/index.json`
15
- );
16
- _indexCache = data.items;
17
- return _indexCache;
18
- }
19
- async function fetchRegistryItem(name) {
20
- return fetchJSON(`${REGISTRY_URL}/${name}.json`);
21
- }
22
- async function getComponent(name) {
23
- const index = await fetchRegistryIndex();
24
- return index.find((item) => item.name === name);
25
- }
26
- async function getAllComponents() {
27
- return fetchRegistryIndex();
28
- }
29
- async function resolveDependencies(names) {
30
- const resolved = /* @__PURE__ */ new Map();
31
- const queue = [...names];
32
- while (queue.length > 0) {
33
- const name = queue.shift();
34
- if (resolved.has(name)) continue;
35
- let item;
36
- try {
37
- item = await fetchRegistryItem(name);
38
- } catch {
39
- console.error(`Component "${name}" not found in registry.`);
40
- process.exit(1);
41
- }
42
- resolved.set(name, item);
43
- if (item.registryDependencies) {
44
- for (const dep of item.registryDependencies) {
45
- if (!resolved.has(dep)) {
46
- queue.push(dep);
47
- }
48
- }
49
- }
50
- }
51
- return Array.from(resolved.values());
52
- }
53
-
54
- export {
55
- fetchRegistryIndex,
56
- fetchRegistryItem,
57
- getComponent,
58
- getAllComponents,
59
- resolveDependencies
60
- };