@decocms/blocks-cli 7.79.2 → 7.79.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks-cli",
3
- "version": "7.79.2",
3
+ "version": "7.79.3",
4
4
  "type": "module",
5
5
  "description": "Deco codegen (generate-blocks, generate-schema, generate-invoke) and Fresh-to-TanStack migration tooling",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "lint:unused": "knip"
34
34
  },
35
35
  "dependencies": {
36
- "@decocms/blocks": "7.79.2",
36
+ "@decocms/blocks": "7.79.3",
37
37
  "ts-morph": "^27.0.0",
38
38
  "tsx": "^4.22.5"
39
39
  },
@@ -186,7 +186,10 @@ describe("generate-schema site multivariate flags", () => {
186
186
 
187
187
  it("offers the flag on a nested prop of a loader's props (a list of items with flagged content)", () => {
188
188
  const loader = def(btoa("site/loaders/kits.ts"));
189
- const kit = loader.properties!.kits.items!;
189
+ // A list prop of a type a loader returns also offers that loader (here,
190
+ // the loader itself); its inline branch is the list.
191
+ const kits = loader.properties!.kits;
192
+ const kit = (kits.anyOf?.[0] ?? kits).items!;
190
193
  expect(kit.properties!.name.type).toBe("string");
191
194
  expectFlagged(kit.properties!.content, FLAG, "Content Variants");
192
195
  });
@@ -0,0 +1,190 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
6
+
7
+ interface Schema {
8
+ type?: string;
9
+ title?: string;
10
+ $ref?: string;
11
+ allOf?: Schema[];
12
+ anyOf?: Schema[];
13
+ enum?: string[];
14
+ properties?: Record<string, Schema>;
15
+ items?: Schema;
16
+ }
17
+
18
+ // Regressions, compared with deco-cx/deco's admin:
19
+ // - A section's `page: ProductListingPage` never offered the commerce
20
+ // `listingPage.ts` extension wrapper (every PLP's stored value), because the
21
+ // wrapper was emitted but not registered as returning what it wraps.
22
+ // - The wrapper's `extensions` list offered nothing: the site's extension
23
+ // loaders (`ExtensionOf<ProductListingPage>`) were never collected.
24
+ // - A loader's own props never got loader pickers: loader input schemas were
25
+ // built before the loader output map existed, so an extension's
26
+ // `products: Product[]` was a bare array with no way to pick a product loader.
27
+ describe("generate-schema loader props and commerce extension wrappers", () => {
28
+ let fixture: string;
29
+ let meta: any;
30
+
31
+ const WRAPPER = "commerce/loaders/product/extensions/listingPage.ts";
32
+ const EXTENSION = "site/loaders/extensions/injectProducts.ts";
33
+
34
+ beforeAll(() => {
35
+ fixture = mkdtempSync(path.join(tmpdir(), "schema-loader-props-"));
36
+ const write = (relative: string, contents: string) => {
37
+ const file = path.join(fixture, relative);
38
+ mkdirSync(path.dirname(file), { recursive: true });
39
+ writeFileSync(file, contents);
40
+ };
41
+ write(
42
+ "tsconfig.json",
43
+ JSON.stringify({
44
+ compilerOptions: {
45
+ target: "ES2022",
46
+ module: "ESNext",
47
+ moduleResolution: "Bundler",
48
+ strict: true,
49
+ },
50
+ }),
51
+ );
52
+ write(
53
+ "src/types.ts",
54
+ `export interface Product { productID: string; name: string; }
55
+ export interface ProductListingPage { products: Product[]; }
56
+ export type ExtensionOf<T> = (data: T) => T | Promise<T>;
57
+ export interface Settings { ids: string[]; }`,
58
+ );
59
+ write(
60
+ "src/loaders/plp.ts",
61
+ `import type { ProductListingPage } from "../types";
62
+ export interface Props { query: string; }
63
+ export default async function plp(_p: Props): Promise<ProductListingPage | null> { return null; }`,
64
+ );
65
+ write(
66
+ "src/loaders/productList.ts",
67
+ `import type { Product } from "../types";
68
+ /** @title Product list */
69
+ export default function productList(): Product[] { return []; }`,
70
+ );
71
+ write(
72
+ "src/loaders/settings.ts",
73
+ `import type { Settings } from "../types";
74
+ export interface Props { fallback?: Settings; }
75
+ /** @title Global settings */
76
+ export default function settings(_p: Props): Settings { return { ids: [] }; }`,
77
+ );
78
+ write(
79
+ "src/loaders/kits.ts",
80
+ `import type { Product } from "../types";
81
+ export interface Props { kits: Product[]; }
82
+ /** @title Kits */
83
+ export default function kits({ kits }: Props): Product[] { return kits; }`,
84
+ );
85
+ write(
86
+ "src/loaders/extensions/injectProducts.ts",
87
+ `import type { ExtensionOf, Product, ProductListingPage, Settings } from "../../types";
88
+ export interface Props {
89
+ products: Product[] | null;
90
+ settings?: Settings | null;
91
+ /** @title Add to the end */
92
+ append?: boolean;
93
+ }
94
+ /** @title Inject products */
95
+ export default async function injectProducts(
96
+ _p: Props,
97
+ ): Promise<ExtensionOf<ProductListingPage | null>> { return (page) => page; }`,
98
+ );
99
+ write(
100
+ "src/sections/Search.tsx",
101
+ `import type { ProductListingPage } from "../types";
102
+ export interface Props { page: ProductListingPage | null; }
103
+ export default function Search(_props: Props) { return null; }`,
104
+ );
105
+
106
+ const run = spawnSync(
107
+ process.execPath,
108
+ [
109
+ "--import",
110
+ import.meta.resolve("tsx"),
111
+ path.resolve(__dirname, "generate-schema.ts"),
112
+ "--skip-apps",
113
+ ],
114
+ { cwd: fixture, encoding: "utf8", timeout: 30_000 },
115
+ );
116
+ expect(run.status, run.error?.message ?? run.stderr).toBe(0);
117
+ meta = JSON.parse(readFileSync(path.join(fixture, ".deco/meta.gen.json"), "utf8"));
118
+ }, 30_000);
119
+
120
+ afterAll(() => {
121
+ if (fixture) rmSync(fixture, { recursive: true, force: true });
122
+ });
123
+
124
+ const def = (key: string): Schema => meta.schema.definitions[key];
125
+ const ref = (key: string) => ({ $ref: `#/definitions/${btoa(key)}` });
126
+ const loaderBranch = (key: string, title: string) => ({
127
+ title,
128
+ type: "object",
129
+ allOf: [ref(key)],
130
+ required: ["__resolveType"],
131
+ properties: { __resolveType: { type: "string", enum: [key], default: key } },
132
+ });
133
+
134
+ it("offers the listingPage wrapper on a section's ProductListingPage prop", () => {
135
+ const section = def(btoa("site/sections/Search.tsx"));
136
+ const propsRef = section.allOf!.find((part) => part.$ref)!.$ref!;
137
+ const page = def(propsRef.replace("#/definitions/", "")).properties!.page;
138
+ expect(page.anyOf).toEqual([
139
+ { $ref: "#/definitions/Resolvable" },
140
+ ref("site/loaders/plp.ts"),
141
+ ref(WRAPPER),
142
+ ]);
143
+ });
144
+
145
+ it("lists the site's extension loaders in the wrapper's extensions", () => {
146
+ const wrapper = def(btoa(WRAPPER));
147
+ expect(wrapper.properties!.extensions.items!.anyOf).toEqual([
148
+ { $ref: "#/definitions/Resolvable" },
149
+ ref(EXTENSION),
150
+ ]);
151
+ // `data` still offers only the base loaders, never the wrapper itself.
152
+ expect(wrapper.properties!.data.anyOf).toEqual([
153
+ { $ref: "#/definitions/Resolvable" },
154
+ ref("site/loaders/plp.ts"),
155
+ ]);
156
+ });
157
+
158
+ it("titles a site loader by its @title", () => {
159
+ expect(def(btoa(EXTENSION)).title).toBe("Inject products");
160
+ expect(def(btoa("site/loaders/plp.ts")).title).toBe("site/loaders/plp.ts");
161
+ });
162
+
163
+ it("keeps a loader's list prop inline and offers the loaders of its type beside it", () => {
164
+ const props = def(btoa(EXTENSION)).properties!;
165
+ const [inline, ...loaders] = props.products.anyOf!;
166
+ expect(inline.type).toBe("array");
167
+ expect(inline.items?.properties?.productID.type).toBe("string");
168
+ expect(loaders).toEqual([
169
+ loaderBranch("site/loaders/kits.ts", "Kits"),
170
+ loaderBranch("site/loaders/productList.ts", "Product list"),
171
+ ]);
172
+ expect(props.append).toMatchObject({ type: "boolean", title: "Add to the end" });
173
+ });
174
+
175
+ it("offers a list loader in its own list prop (content nests it, as deco-cx/deco allowed)", () => {
176
+ const kits = def(btoa("site/loaders/kits.ts")).properties!.kits;
177
+ expect(kits.anyOf?.[0].type).toBe("array");
178
+ expect(kits.anyOf).toContainEqual(loaderBranch("site/loaders/kits.ts", "Kits"));
179
+ });
180
+
181
+ it("keeps a loader's object prop inline only", () => {
182
+ // The admin can't keep an object editable in place beside block options:
183
+ // it would edit a stored plain value through the picked loader's form.
184
+ const { settings } = def(btoa(EXTENSION)).properties!;
185
+ expect(settings.anyOf).toBeUndefined();
186
+ expect(settings.properties?.ids.type).toBe("array");
187
+ const { fallback } = def(btoa("site/loaders/settings.ts")).properties!;
188
+ expect(fallback.anyOf).toBeUndefined();
189
+ });
190
+ });
@@ -382,6 +382,17 @@ interface GenerationContext {
382
382
  * makes the admin offer — and recognize — variants on that field.
383
383
  */
384
384
  outputTypeToFlags?: Map<string, FlagBlock[]>;
385
+ /**
386
+ * Loader input schemas: a list prop (`T[]`) of a type loaders return keeps its
387
+ * inline form and offers those loaders beside it — `anyOf [inline T[],
388
+ * ...loaders]`, deco-cx/deco's shape, which the admin renders as an editable
389
+ * list that can also hold a loader (`array` + `loaderRef`). Object props stay
390
+ * inline only: for an object the admin draws a block picker and edits a
391
+ * stored plain value through the picked loader's form, not in place.
392
+ */
393
+ loaderPicksInline?: boolean;
394
+ /** Loader key → picker label (its @title), for inline loader branches. */
395
+ loaderTitles?: Map<string, string>;
385
396
  /**
386
397
  * Shared definitions sink. When present, a recursive named type (e.g.
387
398
  * `interface Link { submenu?: Link[] }`) is emitted once as a definition and
@@ -486,6 +497,27 @@ function extractLoaderOutputTypeName(sourceFile: SourceFile): string | null {
486
497
  return loaderTypeName(ret);
487
498
  }
488
499
 
500
+ /**
501
+ * For an extension loader — default export returning `ExtensionOf<T>` (or a
502
+ * Promise of it), e.g. `ExtensionOf<ProductListingPage | null>` — the name of
503
+ * `T`, so the commerce extension wrapper over `T` can offer it in its
504
+ * `extensions` list. Null for any other loader.
505
+ */
506
+ export function extractExtensionTargetTypeName(sourceFile: SourceFile): string | null {
507
+ const sym = sourceFile.getDefaultExportSymbol();
508
+ if (!sym) return null;
509
+ const callSigs = sym.getTypeAtLocation(sourceFile).getCallSignatures();
510
+ if (!callSigs.length) return null;
511
+ let ret = callSigs[0].getReturnType();
512
+ if (ret.getSymbol()?.getName() === "Promise") {
513
+ const args = ret.getTypeArguments();
514
+ if (args.length) ret = args[0];
515
+ }
516
+ if (ret.getAliasSymbol()?.getName() !== "ExtensionOf") return null;
517
+ const [target] = ret.getAliasTypeArguments();
518
+ return target ? loaderTypeName(target) : null;
519
+ }
520
+
489
521
  /** A site flag block (`src/flags/**`): its key, picker title and definition id. */
490
522
  export interface FlagBlock {
491
523
  key: string;
@@ -522,13 +554,22 @@ export function extractFlagValueType(sourceFile: SourceFile): Type | null {
522
554
  * would make it a plain block picker instead.
523
555
  */
524
556
  export function flagBranch(flag: FlagBlock): any {
557
+ return blockBranch(flag.key, flag.title, `${flag.defKey}@Props`);
558
+ }
559
+
560
+ /** A loader as an inline `anyOf` branch (same shape as flagBranch). */
561
+ export function loaderBranch(key: string, title: string): any {
562
+ return blockBranch(key, title, toBase64(key));
563
+ }
564
+
565
+ function blockBranch(key: string, title: string, inputDefKey: string): any {
525
566
  return {
526
- title: flag.title,
567
+ title,
527
568
  type: "object",
528
- allOf: [{ $ref: `#/definitions/${flag.defKey}@Props` }],
569
+ allOf: [{ $ref: `#/definitions/${inputDefKey}` }],
529
570
  required: ["__resolveType"],
530
571
  properties: {
531
- __resolveType: { type: "string", enum: [flag.key], default: flag.key },
572
+ __resolveType: { type: "string", enum: [key], default: key },
532
573
  },
533
574
  };
534
575
  }
@@ -809,11 +850,15 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
809
850
 
810
851
  // Loader output type → block-ref: emit anyOf [Resolvable, ...matchingLoaders]
811
852
  // baseHint strips "| null | undefined" so "ProductListingPage | null" → "ProductListingPage"
853
+ let inlineLoaders: string[] = [];
812
854
  if (ctx?.outputTypeToLoaderKeys) {
813
855
  const matchingLoaders =
814
856
  (outputTypeName ? ctx.outputTypeToLoaderKeys.get(outputTypeName) : undefined) ??
815
- (outputTypeName !== baseHint ? ctx.outputTypeToLoaderKeys.get(baseHint) : undefined);
816
- if (matchingLoaders?.length) {
857
+ (outputTypeName !== baseHint ? ctx.outputTypeToLoaderKeys.get(baseHint) : undefined) ??
858
+ [];
859
+ if (ctx.loaderPicksInline) {
860
+ if (outputTypeName?.endsWith("[]")) inlineLoaders = matchingLoaders;
861
+ } else if (matchingLoaders.length) {
817
862
  const blockRefSchema: any = {
818
863
  anyOf: [
819
864
  { $ref: `#/definitions/${RESOLVABLE_KEY}` },
@@ -846,10 +891,15 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
846
891
  // A site flag over this prop's type → the value may also be that flag
847
892
  // (`{ __resolveType: "site/flags/…", variants }`). Without the branch the
848
893
  // admin can't read a stored flag and shows the bare, empty object form.
849
- if (matchingFlags.length > 0 && schema.hide !== "true") {
894
+ // Same for loaders of this type in a loader's props (loaderPicksInline).
895
+ const blockBranches = [
896
+ ...inlineLoaders.map((k) => loaderBranch(k, ctx?.loaderTitles?.get(k) ?? k)),
897
+ ...matchingFlags.map(flagBranch),
898
+ ];
899
+ if (blockBranches.length > 0 && schema.hide !== "true") {
850
900
  const { title, description, nullable, ...inline } = schema;
851
901
  const flagged: any = {
852
- anyOf: [{ ...inline, title }, ...matchingFlags.map(flagBranch)],
902
+ anyOf: [{ ...inline, title }, ...blockBranches],
853
903
  title,
854
904
  };
855
905
  if (description) flagged.description = description;
@@ -1246,8 +1296,24 @@ function generateMeta(): MetaResponse {
1246
1296
  }
1247
1297
 
1248
1298
  // ---------------------------------------------------------------------------
1249
- // First pass: scan loaders — build input schemas + outputTypeToLoaderKeys map
1299
+ // First pass: scan loaders — register each loader and its output type. The
1300
+ // input schemas are built later (pendingLoaderDefs), once every loader's
1301
+ // output type is known (site, app and extension wrappers): a loader prop of a
1302
+ // type other loaders return gets the same block-ref picker a section prop
1303
+ // gets, e.g. an extension loader's `products: Product[]` → product loaders.
1250
1304
  // ---------------------------------------------------------------------------
1305
+ const pendingLoaderDefs: Array<() => void> = [];
1306
+ const loaderTitles = new Map<string, string>();
1307
+ const loaderCtx = (): GenerationContext => ({ ...ctx, loaderPicksInline: true, loaderTitles });
1308
+ /** Extended type name → extension loader keys (see extractExtensionTargetTypeName). */
1309
+ const extensionTargetToLoaderKeys = new Map<string, string[]>();
1310
+ const registerExtension = (sourceFile: SourceFile, loaderKey: string) => {
1311
+ const target = extractExtensionTargetTypeName(sourceFile);
1312
+ if (!target) return;
1313
+ const existing = extensionTargetToLoaderKeys.get(target) ?? [];
1314
+ existing.push(loaderKey);
1315
+ extensionTargetToLoaderKeys.set(target, existing);
1316
+ };
1251
1317
  const loaderFiles = fs.existsSync(loadersDir) ? findTsxFiles(loadersDir) : [];
1252
1318
  console.log(`Found ${loaderFiles.length} loader files`);
1253
1319
  for (const filePath of loaderFiles) {
@@ -1260,35 +1326,7 @@ function generateMeta(): MetaResponse {
1260
1326
 
1261
1327
  try {
1262
1328
  const sourceFile = getSourceFile(project, filePath, sourceFileCache);
1263
-
1264
- // Extract Props (input schema)
1265
- let propsSchema: any = null;
1266
- const propsInterface = sourceFile.getInterface("Props");
1267
- if (propsInterface)
1268
- propsSchema = typeToJsonSchema(propsInterface.getType(), undefined, schemaRefs);
1269
-
1270
- const propsTypeAlias = sourceFile.getTypeAlias("Props");
1271
- if (!propsSchema && propsTypeAlias)
1272
- propsSchema = typeToJsonSchema(propsTypeAlias.getType(), undefined, schemaRefs);
1273
-
1274
- if (!propsSchema) {
1275
- const localPropsType = extractDefaultExportPropsType(sourceFile);
1276
- if (localPropsType) propsSchema = typeToJsonSchema(localPropsType, undefined, schemaRefs);
1277
- }
1278
-
1279
- if (!propsSchema) propsSchema = { type: "object", properties: {} };
1280
-
1281
- // Register flat loader definition (Bug #2: spread props, not nested under "props:")
1282
1329
  const loaderDefKey = toBase64(loaderKey);
1283
- definitions[loaderDefKey] = {
1284
- title: loaderKey,
1285
- type: "object",
1286
- required: ["__resolveType", ...(propsSchema?.required || [])],
1287
- properties: {
1288
- __resolveType: { type: "string", enum: [loaderKey], default: loaderKey },
1289
- ...(propsSchema?.properties || {}),
1290
- },
1291
- };
1292
1330
 
1293
1331
  loaderBlocks[loaderKey] = {
1294
1332
  $ref: `#/definitions/${loaderDefKey}`,
@@ -1296,18 +1334,61 @@ function generateMeta(): MetaResponse {
1296
1334
  };
1297
1335
  loaderRootAnyOf.push({ $ref: `#/definitions/${loaderDefKey}` });
1298
1336
 
1299
- // Extract return type name for block-ref detection in sections (Bug #3)
1337
+ // Extract return type name for block-ref detection (Bug #3)
1300
1338
  const outputTypeName = extractLoaderOutputTypeName(sourceFile);
1301
1339
  if (outputTypeName) {
1302
1340
  const existing = outputTypeToLoaderKeys.get(outputTypeName) ?? [];
1303
1341
  existing.push(loaderKey);
1304
1342
  outputTypeToLoaderKeys.set(outputTypeName, existing);
1305
1343
  }
1344
+ registerExtension(sourceFile, loaderKey);
1306
1345
 
1307
- const propCount = Object.keys(propsSchema.properties || {}).length;
1308
- console.log(
1309
- ` ✓ loader ${loaderKey} (${propCount} props${outputTypeName ? ` → ${outputTypeName}` : ""})`,
1310
- );
1346
+ // The picker label, as for app loaders: a slash-free JSDoc @title on the
1347
+ // default export, else the key.
1348
+ const defaultSym = sourceFile.getDefaultExportSymbol();
1349
+ const titleTag = defaultSym ? getJsDocTags(defaultSym).title : undefined;
1350
+ const title = titleTag && !titleTag.includes("/") ? titleTag : loaderKey;
1351
+ loaderTitles.set(loaderKey, title);
1352
+
1353
+ pendingLoaderDefs.push(() => {
1354
+ try {
1355
+ // Extract Props (input schema)
1356
+ const lctx = loaderCtx();
1357
+ let propsSchema: any = null;
1358
+ const propsInterface = sourceFile.getInterface("Props");
1359
+ if (propsInterface)
1360
+ propsSchema = typeToJsonSchema(propsInterface.getType(), undefined, lctx);
1361
+
1362
+ const propsTypeAlias = sourceFile.getTypeAlias("Props");
1363
+ if (!propsSchema && propsTypeAlias)
1364
+ propsSchema = typeToJsonSchema(propsTypeAlias.getType(), undefined, lctx);
1365
+
1366
+ if (!propsSchema) {
1367
+ const localPropsType = extractDefaultExportPropsType(sourceFile);
1368
+ if (localPropsType) propsSchema = typeToJsonSchema(localPropsType, undefined, lctx);
1369
+ }
1370
+
1371
+ if (!propsSchema) propsSchema = { type: "object", properties: {} };
1372
+
1373
+ // Register flat loader definition (Bug #2: spread props, not nested under "props:")
1374
+ definitions[loaderDefKey] = {
1375
+ title,
1376
+ type: "object",
1377
+ required: ["__resolveType", ...(propsSchema?.required || [])],
1378
+ properties: {
1379
+ __resolveType: { type: "string", enum: [loaderKey], default: loaderKey },
1380
+ ...(propsSchema?.properties || {}),
1381
+ },
1382
+ };
1383
+
1384
+ const propCount = Object.keys(propsSchema.properties || {}).length;
1385
+ console.log(
1386
+ ` ✓ loader ${loaderKey} (${propCount} props${outputTypeName ? ` → ${outputTypeName}` : ""})`,
1387
+ );
1388
+ } catch (e) {
1389
+ console.warn(` ✗ loader ${loaderKey}: ${(e as Error).message}`);
1390
+ }
1391
+ });
1311
1392
  } catch (e) {
1312
1393
  console.warn(` ✗ loader ${loaderKey}: ${(e as Error).message}`);
1313
1394
  }
@@ -1386,7 +1467,9 @@ function generateMeta(): MetaResponse {
1386
1467
 
1387
1468
  // De-duplicate: when re-export files point to the same source, parse once
1388
1469
  const appLoaderCache = new Map<string, {
1389
- propsSchema: any;
1470
+ sourceFile: SourceFile;
1471
+ /** Built on first use, in the deferred pass (see pendingLoaderDefs). */
1472
+ propsSchema?: any;
1390
1473
  outputTypeName: string | null;
1391
1474
  title: string | null;
1392
1475
  hidden: boolean;
@@ -1423,40 +1506,60 @@ function generateMeta(): MetaResponse {
1423
1506
  const title = titleTag && !titleTag.includes("/") ? titleTag : null;
1424
1507
  const hidden = !!loaderTags.ignore;
1425
1508
 
1426
- // Extract Props (input schema)
1427
- let propsSchema: any = null;
1428
- const propsInterface = sourceFile.getInterface("Props");
1429
- if (propsInterface)
1430
- propsSchema = typeToJsonSchema(propsInterface.getType(), undefined, schemaRefs);
1431
-
1432
- const propsTypeAlias = sourceFile.getTypeAlias("Props");
1433
- if (!propsSchema && propsTypeAlias)
1434
- propsSchema = typeToJsonSchema(propsTypeAlias.getType(), undefined, schemaRefs);
1435
-
1436
- if (!propsSchema) {
1437
- const localPropsType = extractDefaultExportPropsType(sourceFile);
1438
- if (localPropsType) propsSchema = typeToJsonSchema(localPropsType, undefined, schemaRefs);
1439
- }
1440
-
1441
- if (!propsSchema) propsSchema = { type: "object", properties: {} };
1442
-
1443
1509
  const outputTypeName = extractLoaderOutputTypeName(sourceFile);
1444
- cached = { propsSchema, outputTypeName, title, hidden };
1510
+ cached = { sourceFile, outputTypeName, title, hidden };
1445
1511
  appLoaderCache.set(realPath, cached);
1446
1512
  }
1447
1513
 
1448
- const { propsSchema, outputTypeName, title, hidden } = cached;
1514
+ const entry = cached;
1515
+ if (!entry.hidden) registerExtension(entry.sourceFile, appLoader.cmsKey);
1516
+ loaderTitles.set(appLoader.cmsKey, entry.title ?? appLoader.cmsKey);
1517
+ const { outputTypeName, title, hidden } = entry;
1449
1518
  const loaderDefKey = toBase64(appLoader.cmsKey);
1519
+ const cmsKey = appLoader.cmsKey;
1450
1520
 
1451
- definitions[loaderDefKey] = {
1452
- title: title ?? appLoader.cmsKey,
1453
- type: "object",
1454
- required: ["__resolveType", ...(propsSchema?.required || [])],
1455
- properties: {
1456
- __resolveType: { type: "string", enum: [appLoader.cmsKey], default: appLoader.cmsKey },
1457
- ...(propsSchema?.properties || {}),
1458
- },
1459
- };
1521
+ pendingLoaderDefs.push(() => {
1522
+ try {
1523
+ if (!entry.propsSchema) {
1524
+ const { sourceFile } = entry;
1525
+ const lctx = loaderCtx();
1526
+ // Extract Props (input schema)
1527
+ let propsSchema: any = null;
1528
+ const propsInterface = sourceFile.getInterface("Props");
1529
+ if (propsInterface)
1530
+ propsSchema = typeToJsonSchema(propsInterface.getType(), undefined, lctx);
1531
+
1532
+ const propsTypeAlias = sourceFile.getTypeAlias("Props");
1533
+ if (!propsSchema && propsTypeAlias)
1534
+ propsSchema = typeToJsonSchema(propsTypeAlias.getType(), undefined, lctx);
1535
+
1536
+ if (!propsSchema) {
1537
+ const localPropsType = extractDefaultExportPropsType(sourceFile);
1538
+ if (localPropsType) propsSchema = typeToJsonSchema(localPropsType, undefined, lctx);
1539
+ }
1540
+
1541
+ entry.propsSchema = propsSchema ?? { type: "object", properties: {} };
1542
+ }
1543
+ const { propsSchema } = entry;
1544
+
1545
+ definitions[loaderDefKey] = {
1546
+ title: title ?? cmsKey,
1547
+ type: "object",
1548
+ required: ["__resolveType", ...(propsSchema?.required || [])],
1549
+ properties: {
1550
+ __resolveType: { type: "string", enum: [cmsKey], default: cmsKey },
1551
+ ...(propsSchema?.properties || {}),
1552
+ },
1553
+ };
1554
+
1555
+ const propCount = Object.keys(propsSchema.properties || {}).length;
1556
+ console.log(
1557
+ ` ${hidden ? "·" : "✓"} app loader ${cmsKey} (${propCount} props${outputTypeName ? ` → ${outputTypeName}` : ""}${hidden ? ", hidden" : ""})`,
1558
+ );
1559
+ } catch (e) {
1560
+ console.warn(` ✗ app loader ${cmsKey}: ${(e as Error).message}`);
1561
+ }
1562
+ });
1460
1563
 
1461
1564
  loaderBlocks[appLoader.cmsKey] = {
1462
1565
  $ref: `#/definitions/${loaderDefKey}`,
@@ -1476,11 +1579,6 @@ function generateMeta(): MetaResponse {
1476
1579
  outputTypeToLoaderKeys.set(outputTypeName, existing);
1477
1580
  }
1478
1581
  }
1479
-
1480
- const propCount = Object.keys(propsSchema.properties || {}).length;
1481
- console.log(
1482
- ` ${hidden ? "·" : "✓"} app loader ${appLoader.cmsKey} (${propCount} props${outputTypeName ? ` → ${outputTypeName}` : ""}${hidden ? ", hidden" : ""})`,
1483
- );
1484
1582
  } catch (e) {
1485
1583
  console.warn(` ✗ app loader ${appLoader.cmsKey}: ${(e as Error).message}`);
1486
1584
  }
@@ -1537,7 +1635,8 @@ function generateMeta(): MetaResponse {
1537
1635
  },
1538
1636
  ];
1539
1637
  for (const wrapper of COMMERCE_EXTENSION_WRAPPERS) {
1540
- const matchingLoaders = outputTypeToLoaderKeys.get(wrapper.outputType) ?? [];
1638
+ const matchingLoaders = [...(outputTypeToLoaderKeys.get(wrapper.outputType) ?? [])];
1639
+ const extensionLoaders = extensionTargetToLoaderKeys.get(wrapper.outputType) ?? [];
1541
1640
  // A wrapper whose base loader type has no matching loaders in the site is
1542
1641
  // useless (its `data` picker would only offer Resolvable). Non-commerce
1543
1642
  // sites (e.g. Eitri) have none, so skip it instead of injecting a phantom
@@ -1561,7 +1660,12 @@ function generateMeta(): MetaResponse {
1561
1660
  extensions: {
1562
1661
  type: "array",
1563
1662
  title: "The data Extensions",
1564
- items: { anyOf: [{ $ref: `#/definitions/${RESOLVABLE_KEY}` }] },
1663
+ items: {
1664
+ anyOf: [
1665
+ { $ref: `#/definitions/${RESOLVABLE_KEY}` },
1666
+ ...extensionLoaders.map((k) => ({ $ref: `#/definitions/${toBase64(k)}` })),
1667
+ ],
1668
+ },
1565
1669
  },
1566
1670
  },
1567
1671
  };
@@ -1570,11 +1674,17 @@ function generateMeta(): MetaResponse {
1570
1674
  namespace: "commerce",
1571
1675
  };
1572
1676
  loaderRootAnyOf.push({ $ref: `#/definitions/${wrapperDefKey}` });
1677
+ // The wrapper returns what it wraps, so a prop of that type offers it too
1678
+ // (a PLP section's `page` → "listingPage.ts" with its extensions).
1679
+ outputTypeToLoaderKeys.set(wrapper.outputType, [...matchingLoaders, wrapper.key]);
1573
1680
  console.log(
1574
- ` ✓ commerce extension wrapper ${wrapper.key} (data → ${matchingLoaders.length} loader(s))`,
1681
+ ` ✓ commerce extension wrapper ${wrapper.key} (data → ${matchingLoaders.length} loader(s), ${extensionLoaders.length} extension(s))`,
1575
1682
  );
1576
1683
  }
1577
1684
 
1685
+ // Loader input schemas, now that every loader output type is registered.
1686
+ for (const buildLoaderDef of pendingLoaderDefs) buildLoaderDef();
1687
+
1578
1688
  // ---------------------------------------------------------------------------
1579
1689
  // Second pass: scan sections
1580
1690
  // ---------------------------------------------------------------------------