create-next-hydra 0.2.0 → 0.2.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.
|
@@ -17,7 +17,10 @@ export declare function fetchRegistryItemGraph(options: {
|
|
|
17
17
|
repository?: string;
|
|
18
18
|
}): Promise<RegistryItemGraph>;
|
|
19
19
|
export declare function loadSourceRegistryCatalog(cwd: string, registryFile?: string): Promise<SourceRegistryCatalog>;
|
|
20
|
-
export declare function loadGitHubSourceRegistryCatalog(repository: string, ref?: string
|
|
20
|
+
export declare function loadGitHubSourceRegistryCatalog(repository: string, ref?: string, dependencies?: {
|
|
21
|
+
fetchItems?: (addresses: string[]) => RegistryItem[] | Promise<RegistryItem[]>;
|
|
22
|
+
loadRegistryConfig?: (cwd: string) => RegistriesConfig | Promise<RegistriesConfig>;
|
|
23
|
+
}): Promise<SourceRegistryCatalog>;
|
|
21
24
|
export declare function addCatalogReferences(catalog: SourceRegistryCatalog, references: Iterable<string>, cwd?: string): Promise<SourceRegistryCatalog>;
|
|
22
25
|
export declare function resolveCatalogSelection(catalog: SourceRegistryCatalog, reference: string): CatalogSelection;
|
|
23
26
|
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/composition/catalog.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAclD,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/composition/catalog.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAA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,CAAC;CAC9C,GACL,OAAO,CAAC,qBAAqB,CAAC,CA4BhC;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,qBAAqB,EAC9B,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC5B,GAAG,SAA+B,GACjC,OAAO,CAAC,qBAAqB,CAAC,CA8ChC;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,SAAS,EAAE,MAAM,GAChB,gBAAgB,CASlB"}
|
|
@@ -7,6 +7,7 @@ import { CompositionValidationError } from "./errors.js";
|
|
|
7
7
|
import { isManagedApplicationSource, resolveRegistryTarget, resolveWorkspacePath, } from "./paths.js";
|
|
8
8
|
import { formatZodError, NEXT_HYDRA_SELECTION_SCHEMA_URL, selectionDefinitionSchema, } from "./schema.js";
|
|
9
9
|
const GITHUB_HOMEPAGE_PATTERN = /^https:\/\/github\.com\/([^/]+\/[^/]+?)(?:\.git)?\/?$/;
|
|
10
|
+
const SHADCN_REGISTRY_ITEM_SCHEMA_URL = "https://ui.shadcn.com/schema/registry-item.json";
|
|
10
11
|
const OFFICIAL_REFERENCES = {
|
|
11
12
|
commercetools: "next-hydra/commerce/commercetools",
|
|
12
13
|
contentstack: "next-hydra/cms/contentstack",
|
|
@@ -22,6 +23,15 @@ const OFFICIAL_ITEM_NAMES = [
|
|
|
22
23
|
"drupal",
|
|
23
24
|
"next-hydra-standard",
|
|
24
25
|
];
|
|
26
|
+
function restoreFetchedSelectionSchema(item) {
|
|
27
|
+
// ShadCN assigns its registry-item schema to every resolved artifact,
|
|
28
|
+
// including artifacts authored with the Next Hydra Selection schema.
|
|
29
|
+
if (item.meta?.nextHydra !== undefined &&
|
|
30
|
+
item.$schema === SHADCN_REGISTRY_ITEM_SCHEMA_URL) {
|
|
31
|
+
return { ...item, $schema: NEXT_HYDRA_SELECTION_SCHEMA_URL };
|
|
32
|
+
}
|
|
33
|
+
return item;
|
|
34
|
+
}
|
|
25
35
|
function createCatalog(options) {
|
|
26
36
|
const items = new Map(options.registryItems.map((item) => [item.name, item]));
|
|
27
37
|
const itemByReference = new Map(options.itemByReference);
|
|
@@ -162,12 +172,13 @@ export async function fetchRegistryItemGraph(options) {
|
|
|
162
172
|
if (!itemName) {
|
|
163
173
|
// oxlint-disable-next-line no-await-in-loop -- Breadth-first discovery reveals each next reference in order.
|
|
164
174
|
const resolvedReference = await resolveRegistryReference(reference, options.cwd);
|
|
165
|
-
const [
|
|
175
|
+
const [fetchedArtifact] = await fetchItems([resolvedReference], {
|
|
166
176
|
config: options.config,
|
|
167
177
|
});
|
|
168
|
-
if (!
|
|
178
|
+
if (!fetchedArtifact) {
|
|
169
179
|
throw new CompositionValidationError("The registry dependency graph is incomplete.", [`${reference} returned no registry item`]);
|
|
170
180
|
}
|
|
181
|
+
const artifact = restoreFetchedSelectionSchema(fetchedArtifact);
|
|
171
182
|
const fetched = fetchedItems.get(artifact.name);
|
|
172
183
|
const unpinnedReference = reference.split("#", 1)[0] ?? reference;
|
|
173
184
|
const replacesPinnedRepositoryItem = reference.includes("#") &&
|
|
@@ -233,11 +244,12 @@ export async function loadSourceRegistryCatalog(cwd, registryFile = "registry.js
|
|
|
233
244
|
repository,
|
|
234
245
|
});
|
|
235
246
|
}
|
|
236
|
-
export async function loadGitHubSourceRegistryCatalog(repository, ref) {
|
|
247
|
+
export async function loadGitHubSourceRegistryCatalog(repository, ref, dependencies = {}) {
|
|
237
248
|
const suffix = ref ? `#${ref}` : "";
|
|
238
249
|
const addresses = OFFICIAL_ITEM_NAMES.map((item) => `${repository}/${item}${suffix}`);
|
|
239
|
-
const
|
|
240
|
-
const
|
|
250
|
+
const fetchedItems = await (dependencies.fetchItems ?? getRegistryItems)(addresses);
|
|
251
|
+
const registryItems = fetchedItems.map(restoreFetchedSelectionSchema);
|
|
252
|
+
const registryConfig = await (dependencies.loadRegistryConfig ?? getRegistriesConfig)(process.cwd());
|
|
241
253
|
const itemByReference = new Map(registryItems.flatMap((item, index) => {
|
|
242
254
|
const address = addresses[index];
|
|
243
255
|
return address ? [[address, item.name]] : [];
|