@open-mercato/cli 0.6.7-develop.6686.1.bdda5ed397 → 0.6.7-develop.6687.1.46a258e592

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 (62) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/agentic/guides/module-facts.json +108 -108
  3. package/dist/agentic/guides/modules/ai_assistant.md +1 -1
  4. package/dist/agentic/guides/modules/api_docs.md +1 -1
  5. package/dist/agentic/guides/modules/api_keys.md +1 -1
  6. package/dist/agentic/guides/modules/attachments.md +1 -1
  7. package/dist/agentic/guides/modules/audit_logs.md +1 -1
  8. package/dist/agentic/guides/modules/auth.md +1 -1
  9. package/dist/agentic/guides/modules/business_rules.md +1 -1
  10. package/dist/agentic/guides/modules/catalog.md +1 -1
  11. package/dist/agentic/guides/modules/channel_gmail.md +1 -1
  12. package/dist/agentic/guides/modules/channel_imap.md +1 -1
  13. package/dist/agentic/guides/modules/checkout.md +1 -1
  14. package/dist/agentic/guides/modules/communication_channels.md +1 -1
  15. package/dist/agentic/guides/modules/configs.md +1 -1
  16. package/dist/agentic/guides/modules/content.md +1 -1
  17. package/dist/agentic/guides/modules/currencies.md +1 -1
  18. package/dist/agentic/guides/modules/customer_accounts.md +1 -1
  19. package/dist/agentic/guides/modules/customers.md +1 -1
  20. package/dist/agentic/guides/modules/dashboards.md +1 -1
  21. package/dist/agentic/guides/modules/data_sync.md +1 -1
  22. package/dist/agentic/guides/modules/dictionaries.md +1 -1
  23. package/dist/agentic/guides/modules/directory.md +1 -1
  24. package/dist/agentic/guides/modules/entities.md +1 -1
  25. package/dist/agentic/guides/modules/events.md +1 -1
  26. package/dist/agentic/guides/modules/feature_toggles.md +1 -1
  27. package/dist/agentic/guides/modules/gateway_stripe.md +1 -1
  28. package/dist/agentic/guides/modules/generators.md +1 -1
  29. package/dist/agentic/guides/modules/inbox_ops.md +1 -1
  30. package/dist/agentic/guides/modules/integrations.md +1 -1
  31. package/dist/agentic/guides/modules/messages.md +1 -1
  32. package/dist/agentic/guides/modules/notifications.md +1 -1
  33. package/dist/agentic/guides/modules/onboarding.md +1 -1
  34. package/dist/agentic/guides/modules/payment_gateways.md +1 -1
  35. package/dist/agentic/guides/modules/perspectives.md +1 -1
  36. package/dist/agentic/guides/modules/planner.md +1 -1
  37. package/dist/agentic/guides/modules/portal.md +1 -1
  38. package/dist/agentic/guides/modules/progress.md +1 -1
  39. package/dist/agentic/guides/modules/query_index.md +1 -1
  40. package/dist/agentic/guides/modules/record_locks.md +1 -1
  41. package/dist/agentic/guides/modules/resources.md +1 -1
  42. package/dist/agentic/guides/modules/sales.md +1 -1
  43. package/dist/agentic/guides/modules/scheduler.md +1 -1
  44. package/dist/agentic/guides/modules/search.md +1 -1
  45. package/dist/agentic/guides/modules/security.md +1 -1
  46. package/dist/agentic/guides/modules/shipping_carriers.md +1 -1
  47. package/dist/agentic/guides/modules/sso.md +1 -1
  48. package/dist/agentic/guides/modules/staff.md +1 -1
  49. package/dist/agentic/guides/modules/storage_s3.md +1 -1
  50. package/dist/agentic/guides/modules/sync_akeneo.md +1 -1
  51. package/dist/agentic/guides/modules/sync_excel.md +1 -1
  52. package/dist/agentic/guides/modules/system_status_overlays.md +1 -1
  53. package/dist/agentic/guides/modules/translations.md +1 -1
  54. package/dist/agentic/guides/modules/webhooks.md +1 -1
  55. package/dist/agentic/guides/modules/wms.md +1 -1
  56. package/dist/agentic/guides/modules/workflows.md +1 -1
  57. package/dist/agentic/guides/upstream/manifest.json +1 -1
  58. package/dist/lib/generators/extensions/injection-widgets.js +20 -0
  59. package/dist/lib/generators/extensions/injection-widgets.js.map +2 -2
  60. package/package.json +5 -5
  61. package/src/lib/__tests__/injection-widget-id-validation.test.ts +184 -0
  62. package/src/lib/generators/extensions/injection-widgets.ts +51 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/generators/extensions/injection-widgets.ts"],
4
- "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { VariableDeclarationKind } from 'ts-morph'\nimport ts from 'typescript-js'\nimport type { GeneratorExtension } from '../extension'\nimport { resolveStandaloneSourceMirrorBase, scanModuleDir, SCAN_CONFIGS, type ModuleRoots } from '../scanner'\nimport {\n arrayLiteral,\n arrowFunction,\n identifier,\n methodCall,\n nullishCoalesce,\n objectLiteral,\n propertyAccess,\n writeValue,\n} from '../ast'\nimport { dynamicImportExpression, emptyObject, namespaceFallback, namespaceImportSpec, renderGeneratedTsSource } from './shared'\n\ntype InjectionWidgetEntry = {\n moduleId: string\n key: string\n source: 'app' | 'package'\n importPath: string\n widgetId?: string\n}\n\ntype InjectionTableEntry = {\n moduleId: string\n importName: string\n importPath: string\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression\n while (\n ts.isParenthesizedExpression(current)\n || ts.isAsExpression(current)\n || ts.isTypeAssertionExpression(current)\n || ts.isSatisfiesExpression(current)\n ) {\n current = current.expression\n }\n return current\n}\n\nfunction getPropertyNameText(name: ts.PropertyName): string | null {\n if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNoSubstitutionTemplateLiteral(name)) {\n return name.text\n }\n return null\n}\n\nfunction collectObjectDeclarations(sourceFile: ts.SourceFile): Map<string, ts.ObjectLiteralExpression> {\n const declarations = new Map<string, ts.ObjectLiteralExpression>()\n for (const statement of sourceFile.statements) {\n if (!ts.isVariableStatement(statement)) continue\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || !declaration.initializer) continue\n const initializer = unwrapExpression(declaration.initializer)\n if (ts.isObjectLiteralExpression(initializer)) {\n declarations.set(declaration.name.text, initializer)\n }\n }\n }\n return declarations\n}\n\nfunction resolveObjectExpression(\n expression: ts.Expression,\n declarations: Map<string, ts.ObjectLiteralExpression>,\n): ts.ObjectLiteralExpression | null {\n const unwrapped = unwrapExpression(expression)\n if (ts.isObjectLiteralExpression(unwrapped)) return unwrapped\n if (ts.isIdentifier(unwrapped)) return declarations.get(unwrapped.text) ?? null\n return null\n}\n\nfunction getObjectPropertyExpression(object: ts.ObjectLiteralExpression, propertyName: string): ts.Expression | null {\n for (const property of object.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n if (getPropertyNameText(property.name) === propertyName) return property.initializer\n }\n return null\n}\n\nfunction getStringPropertyValue(object: ts.ObjectLiteralExpression, propertyName: string): string | null {\n const expression = getObjectPropertyExpression(object, propertyName)\n if (!expression) return null\n const unwrapped = unwrapExpression(expression)\n if (ts.isStringLiteral(unwrapped) || ts.isNoSubstitutionTemplateLiteral(unwrapped)) return unwrapped.text\n return null\n}\n\nfunction extractMetadataId(object: ts.ObjectLiteralExpression): string | null {\n const metadata = getObjectPropertyExpression(object, 'metadata')\n if (!metadata) return null\n const unwrapped = unwrapExpression(metadata)\n if (!ts.isObjectLiteralExpression(unwrapped)) return null\n return getStringPropertyValue(unwrapped, 'id')\n}\n\nfunction extractWidgetMetadataId(absolutePath: string): string | null {\n try {\n const source = fs.readFileSync(absolutePath, 'utf8')\n const sourceFile = ts.createSourceFile(absolutePath, source, ts.ScriptTarget.Latest, true)\n const declarations = collectObjectDeclarations(sourceFile)\n\n for (const statement of sourceFile.statements) {\n if (!ts.isExportAssignment(statement) || statement.isExportEquals) continue\n const object = resolveObjectExpression(statement.expression, declarations)\n if (!object) continue\n const id = extractMetadataId(object)\n if (id) return id\n }\n\n for (const object of declarations.values()) {\n const id = extractMetadataId(object)\n if (id) return id\n }\n } catch {\n return null\n }\n return null\n}\n\nfunction collectWidgetIdsFromTableValue(\n value: ts.Expression,\n declarations: Map<string, ts.ObjectLiteralExpression>,\n ids: Set<string>,\n) {\n const expression = unwrapExpression(value)\n if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {\n ids.add(expression.text)\n return\n }\n if (ts.isArrayLiteralExpression(expression)) {\n for (const element of expression.elements) {\n if (ts.isExpression(element)) collectWidgetIdsFromTableValue(element, declarations, ids)\n }\n return\n }\n const object = resolveObjectExpression(expression, declarations)\n if (!object) return\n const widgetId = getStringPropertyValue(object, 'widgetId')\n if (widgetId) ids.add(widgetId)\n}\n\nfunction extractInjectionTableWidgetIds(absolutePath: string): string[] {\n try {\n const source = fs.readFileSync(absolutePath, 'utf8')\n const sourceFile = ts.createSourceFile(absolutePath, source, ts.ScriptTarget.Latest, true)\n const declarations = collectObjectDeclarations(sourceFile)\n let tableObject: ts.ObjectLiteralExpression | null = null\n\n for (const statement of sourceFile.statements) {\n if (ts.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || declaration.name.text !== 'injectionTable' || !declaration.initializer) {\n continue\n }\n tableObject = resolveObjectExpression(declaration.initializer, declarations)\n }\n }\n if (ts.isExportAssignment(statement) && !statement.isExportEquals) {\n tableObject ??= resolveObjectExpression(statement.expression, declarations)\n }\n }\n\n if (!tableObject) return []\n const ids = new Set<string>()\n for (const property of tableObject.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n collectWidgetIdsFromTableValue(property.initializer, declarations, ids)\n }\n return Array.from(ids)\n } catch {\n return []\n }\n}\n\nfunction resolveScannedWidgetPath(roots: ModuleRoots, fromApp: boolean, relPath: string): string {\n const base = fromApp ? roots.appBase : (resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase)\n return path.join(base, 'widgets', 'injection', ...relPath.split('/'))\n}\n\nexport function createInjectionWidgetsExtension(): GeneratorExtension {\n const widgetEntries = new Map<string, InjectionWidgetEntry>()\n const tableEntries: InjectionTableEntry[] = []\n\n return {\n id: 'registry.injection-widgets',\n outputFiles: ['injection-widgets.generated.ts', 'injection-tables.generated.ts'],\n scanModule(ctx) {\n const files = scanModuleDir(ctx.roots, SCAN_CONFIGS.injectionWidgets)\n const moduleWidgetEntries: InjectionWidgetEntry[] = []\n for (const { relPath, fromApp } of files) {\n const segments = relPath.split('/')\n const file = segments.pop() ?? ''\n const base = file.replace(/\\.(t|j)sx?$/, '')\n const importPath = ctx.sanitizeGeneratedModuleSpecifier(\n `${fromApp ? ctx.imps.appBase : ctx.imps.pkgBase}/widgets/injection/${[...segments, base].join('/')}`\n )\n const key = [ctx.moduleId, ...segments, base].filter(Boolean).join(':')\n const entry: InjectionWidgetEntry = {\n moduleId: ctx.moduleId,\n key,\n source: fromApp ? 'app' : 'package',\n importPath,\n widgetId: extractWidgetMetadataId(resolveScannedWidgetPath(ctx.roots, fromApp, relPath)) ?? undefined,\n }\n moduleWidgetEntries.push(entry)\n }\n\n const table = ctx.resolveModuleFile(ctx.roots, ctx.imps, 'widgets/injection-table.ts')\n const tableWidgetIds = table ? extractInjectionTableWidgetIds(table.absolutePath) : []\n if (moduleWidgetEntries.length === 1 && tableWidgetIds.length === 1 && !moduleWidgetEntries[0].widgetId) {\n moduleWidgetEntries[0].widgetId = tableWidgetIds[0]\n }\n\n for (const entry of moduleWidgetEntries) {\n const existing = widgetEntries.get(entry.key)\n if (!existing || (existing.source !== 'app' && entry.source === 'app')) {\n widgetEntries.set(entry.key, entry)\n }\n }\n\n if (table) {\n tableEntries.push({\n moduleId: ctx.moduleId,\n importName: `InjTable_${ctx.moduleId.replace(/[^a-zA-Z0-9_]/g, '_')}_${ctx.importIdRef.value++}`,\n importPath: ctx.sanitizeGeneratedModuleSpecifier(table.importPath),\n })\n }\n },\n generateOutput() {\n const widgetDecls = Array.from(widgetEntries.entries())\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([, entry]) =>\n objectLiteral([\n { name: 'moduleId', value: entry.moduleId },\n { name: 'key', value: entry.key },\n { name: 'source', value: entry.source },\n ...(entry.widgetId ? [{ name: 'widgetId', value: entry.widgetId }] : []),\n {\n name: 'loader',\n value: arrowFunction({\n body: methodCall(dynamicImportExpression(entry.importPath), 'then', [\n arrowFunction({\n parameters: ['mod'],\n body: nullishCoalesce([\n propertyAccess(identifier('mod'), 'default'),\n identifier('mod'),\n ]),\n }),\n ]),\n }),\n },\n ]),\n )\n\n const widgetsOutput = renderGeneratedTsSource({\n fileName: 'injection-widgets.generated.ts',\n imports: [\n { namedImports: [{ name: 'ModuleInjectionWidgetEntry', isTypeOnly: true }], moduleSpecifier: '@open-mercato/shared/modules/registry' },\n ],\n build(sourceFile) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'injectionWidgetEntries',\n type: 'ModuleInjectionWidgetEntry[]',\n initializer: arrayLiteral(widgetDecls, writeValue),\n },\n ],\n })\n },\n })\n\n const tableImports = tableEntries.map((entry) => namespaceImportSpec(entry.importName, entry.importPath))\n const tableDecls = tableEntries.map((entry) =>\n objectLiteral([\n { name: 'moduleId', value: entry.moduleId },\n {\n name: 'table',\n value: namespaceFallback({\n importName: entry.importName,\n members: ['default', 'injectionTable'],\n fallback: emptyObject(),\n castType: 'ModuleInjectionTable',\n }),\n },\n ]),\n )\n const tablesOutput = renderGeneratedTsSource({\n fileName: 'injection-tables.generated.ts',\n imports: [\n { namedImports: [{ name: 'ModuleInjectionTable', isTypeOnly: true }], moduleSpecifier: '@open-mercato/shared/modules/widgets/injection' },\n ...tableImports,\n ],\n build(sourceFile) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'injectionTables',\n type: 'Array<{ moduleId: string; table: ModuleInjectionTable }>',\n initializer: arrayLiteral(tableDecls, writeValue),\n },\n ],\n })\n },\n })\n\n return new Map([\n ['injection-widgets.generated.ts', widgetsOutput],\n ['injection-tables.generated.ts', tablesOutput],\n ])\n },\n }\n}\n"],
5
- "mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,+BAA+B;AACxC,OAAO,QAAQ;AAEf,SAAS,mCAAmC,eAAe,oBAAsC;AACjG;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB,aAAa,m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ACF,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAED,aAAO,oBAAI,IAAI;AAAA,QACb,CAAC,kCAAkC,aAAa;AAAA,QAChD,CAAC,iCAAiC,YAAY;AAAA,MAChD,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { VariableDeclarationKind } from 'ts-morph'\nimport ts from 'typescript-js'\nimport type { GeneratorExtension } from '../extension'\nimport { resolveStandaloneSourceMirrorBase, scanModuleDir, SCAN_CONFIGS, type ModuleRoots } from '../scanner'\nimport {\n arrayLiteral,\n arrowFunction,\n identifier,\n methodCall,\n nullishCoalesce,\n objectLiteral,\n propertyAccess,\n writeValue,\n} from '../ast'\nimport { dynamicImportExpression, emptyObject, namespaceFallback, namespaceImportSpec, renderGeneratedTsSource } from './shared'\n\ntype InjectionWidgetEntry = {\n moduleId: string\n key: string\n source: 'app' | 'package'\n importPath: string\n widgetId?: string\n}\n\ntype InjectionTableEntry = {\n moduleId: string\n importName: string\n importPath: string\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n let current = expression\n while (\n ts.isParenthesizedExpression(current)\n || ts.isAsExpression(current)\n || ts.isTypeAssertionExpression(current)\n || ts.isSatisfiesExpression(current)\n ) {\n current = current.expression\n }\n return current\n}\n\nfunction getPropertyNameText(name: ts.PropertyName): string | null {\n if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNoSubstitutionTemplateLiteral(name)) {\n return name.text\n }\n return null\n}\n\nfunction collectObjectDeclarations(sourceFile: ts.SourceFile): Map<string, ts.ObjectLiteralExpression> {\n const declarations = new Map<string, ts.ObjectLiteralExpression>()\n for (const statement of sourceFile.statements) {\n if (!ts.isVariableStatement(statement)) continue\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || !declaration.initializer) continue\n const initializer = unwrapExpression(declaration.initializer)\n if (ts.isObjectLiteralExpression(initializer)) {\n declarations.set(declaration.name.text, initializer)\n }\n }\n }\n return declarations\n}\n\nfunction resolveObjectExpression(\n expression: ts.Expression,\n declarations: Map<string, ts.ObjectLiteralExpression>,\n): ts.ObjectLiteralExpression | null {\n const unwrapped = unwrapExpression(expression)\n if (ts.isObjectLiteralExpression(unwrapped)) return unwrapped\n if (ts.isIdentifier(unwrapped)) return declarations.get(unwrapped.text) ?? null\n return null\n}\n\nfunction getObjectPropertyExpression(object: ts.ObjectLiteralExpression, propertyName: string): ts.Expression | null {\n for (const property of object.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n if (getPropertyNameText(property.name) === propertyName) return property.initializer\n }\n return null\n}\n\nfunction getStringPropertyValue(object: ts.ObjectLiteralExpression, propertyName: string): string | null {\n const expression = getObjectPropertyExpression(object, propertyName)\n if (!expression) return null\n const unwrapped = unwrapExpression(expression)\n if (ts.isStringLiteral(unwrapped) || ts.isNoSubstitutionTemplateLiteral(unwrapped)) return unwrapped.text\n return null\n}\n\nfunction extractMetadataId(object: ts.ObjectLiteralExpression): string | null {\n const metadata = getObjectPropertyExpression(object, 'metadata')\n if (!metadata) return null\n const unwrapped = unwrapExpression(metadata)\n if (!ts.isObjectLiteralExpression(unwrapped)) return null\n return getStringPropertyValue(unwrapped, 'id')\n}\n\nfunction extractWidgetMetadataId(absolutePath: string): string | null {\n try {\n const source = fs.readFileSync(absolutePath, 'utf8')\n const sourceFile = ts.createSourceFile(absolutePath, source, ts.ScriptTarget.Latest, true)\n const declarations = collectObjectDeclarations(sourceFile)\n\n for (const statement of sourceFile.statements) {\n if (!ts.isExportAssignment(statement) || statement.isExportEquals) continue\n const object = resolveObjectExpression(statement.expression, declarations)\n if (!object) continue\n const id = extractMetadataId(object)\n if (id) return id\n }\n\n for (const object of declarations.values()) {\n const id = extractMetadataId(object)\n if (id) return id\n }\n } catch {\n return null\n }\n return null\n}\n\nfunction collectWidgetIdsFromTableValue(\n value: ts.Expression,\n declarations: Map<string, ts.ObjectLiteralExpression>,\n ids: Set<string>,\n) {\n const expression = unwrapExpression(value)\n if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {\n ids.add(expression.text)\n return\n }\n if (ts.isArrayLiteralExpression(expression)) {\n for (const element of expression.elements) {\n if (ts.isExpression(element)) collectWidgetIdsFromTableValue(element, declarations, ids)\n }\n return\n }\n const object = resolveObjectExpression(expression, declarations)\n if (!object) return\n const widgetId = getStringPropertyValue(object, 'widgetId')\n if (widgetId) ids.add(widgetId)\n}\n\nfunction extractInjectionTableWidgetIds(absolutePath: string): string[] {\n try {\n const source = fs.readFileSync(absolutePath, 'utf8')\n const sourceFile = ts.createSourceFile(absolutePath, source, ts.ScriptTarget.Latest, true)\n const declarations = collectObjectDeclarations(sourceFile)\n let tableObject: ts.ObjectLiteralExpression | null = null\n\n for (const statement of sourceFile.statements) {\n if (ts.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || declaration.name.text !== 'injectionTable' || !declaration.initializer) {\n continue\n }\n tableObject = resolveObjectExpression(declaration.initializer, declarations)\n }\n }\n if (ts.isExportAssignment(statement) && !statement.isExportEquals) {\n tableObject ??= resolveObjectExpression(statement.expression, declarations)\n }\n }\n\n if (!tableObject) return []\n const ids = new Set<string>()\n for (const property of tableObject.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n collectWidgetIdsFromTableValue(property.initializer, declarations, ids)\n }\n return Array.from(ids)\n } catch {\n return []\n }\n}\n\nfunction resolveScannedWidgetPath(roots: ModuleRoots, fromApp: boolean, relPath: string): string {\n const base = fromApp ? roots.appBase : (resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase)\n return path.join(base, 'widgets', 'injection', ...relPath.split('/'))\n}\n\n/**\n * A widget's `metadata.id` and the injection-table entry that mounts it are two hand-typed string\n * literals in two different files, and nothing links them. A typo in either fails silently: the spot\n * resolves to no widget and nothing is logged, so it only surfaces as \"why isn't my widget\n * rendering\" during manual QA.\n *\n * Reports table entries whose `widgetId` no scanned widget declares. Diagnostics only \u2014 generated\n * output is unchanged and the build is not failed, since a table entry may legitimately point at a\n * widget supplied by a module that is not enabled in this app.\n *\n * Deliberately one-directional. The mirror check (\"a widget nothing references is never mounted\")\n * cannot be done reliably yet: `extractInjectionTableWidgetIds` only reads statically-analyzable\n * object literals, so a table assembled by composition or computation contributes **no** visible\n * ids \u2014 `example` exports `cond ? { ...a, ...b } : a` and `translations` exports\n * `buildInjectionTable()`, and both would have every one of their widgets reported as unreferenced.\n * Under-reporting is harmless in the direction implemented here (a reference the extractor never saw\n * cannot produce a warning) but fatal in the other. Teaching the extractor to resolve spreads,\n * conditionals and call expressions is the prerequisite for adding it.\n */\nfunction reportUnresolvableWidgetReferences(\n widgetEntries: Map<string, InjectionWidgetEntry>,\n tableWidgetRefs: Map<string, Set<string>>,\n): void {\n const declaredIds = new Set<string>()\n for (const entry of widgetEntries.values()) {\n if (entry.widgetId) declaredIds.add(entry.widgetId)\n }\n\n for (const [widgetId, modules] of Array.from(tableWidgetRefs.entries()).sort(([a], [b]) => a.localeCompare(b))) {\n if (declaredIds.has(widgetId)) continue\n const owners = Array.from(modules).sort((left, right) => left.localeCompare(right)).join(', ')\n console.warn(\n `[generate] \u26A0 Injection table in \"${owners}\" references widget id \"${widgetId}\", but no scanned ` +\n 'widget declares it \u2014 that spot will render nothing. Check the id against the widget\\'s ' +\n 'metadata.id, and that the widget lives in a file the scanner reads ' +\n '(widgets/injection/**/widget.ts|tsx \u2014 note that widget.client.tsx alone is not scanned).',\n )\n }\n}\n\nexport function createInjectionWidgetsExtension(): GeneratorExtension {\n const widgetEntries = new Map<string, InjectionWidgetEntry>()\n const tableEntries: InjectionTableEntry[] = []\n // widgetId -> module ids whose injection table references it. Collected across every module so a\n // table may legitimately reference a widget another module owns.\n const tableWidgetRefs = new Map<string, Set<string>>()\n\n return {\n id: 'registry.injection-widgets',\n outputFiles: ['injection-widgets.generated.ts', 'injection-tables.generated.ts'],\n scanModule(ctx) {\n const files = scanModuleDir(ctx.roots, SCAN_CONFIGS.injectionWidgets)\n const moduleWidgetEntries: InjectionWidgetEntry[] = []\n for (const { relPath, fromApp } of files) {\n const segments = relPath.split('/')\n const file = segments.pop() ?? ''\n const base = file.replace(/\\.(t|j)sx?$/, '')\n const importPath = ctx.sanitizeGeneratedModuleSpecifier(\n `${fromApp ? ctx.imps.appBase : ctx.imps.pkgBase}/widgets/injection/${[...segments, base].join('/')}`\n )\n const key = [ctx.moduleId, ...segments, base].filter(Boolean).join(':')\n const entry: InjectionWidgetEntry = {\n moduleId: ctx.moduleId,\n key,\n source: fromApp ? 'app' : 'package',\n importPath,\n widgetId: extractWidgetMetadataId(resolveScannedWidgetPath(ctx.roots, fromApp, relPath)) ?? undefined,\n }\n moduleWidgetEntries.push(entry)\n }\n\n const table = ctx.resolveModuleFile(ctx.roots, ctx.imps, 'widgets/injection-table.ts')\n const tableWidgetIds = table ? extractInjectionTableWidgetIds(table.absolutePath) : []\n if (moduleWidgetEntries.length === 1 && tableWidgetIds.length === 1 && !moduleWidgetEntries[0].widgetId) {\n moduleWidgetEntries[0].widgetId = tableWidgetIds[0]\n }\n\n for (const widgetId of tableWidgetIds) {\n const modules = tableWidgetRefs.get(widgetId) ?? new Set<string>()\n modules.add(ctx.moduleId)\n tableWidgetRefs.set(widgetId, modules)\n }\n\n for (const entry of moduleWidgetEntries) {\n const existing = widgetEntries.get(entry.key)\n if (!existing || (existing.source !== 'app' && entry.source === 'app')) {\n widgetEntries.set(entry.key, entry)\n }\n }\n\n if (table) {\n tableEntries.push({\n moduleId: ctx.moduleId,\n importName: `InjTable_${ctx.moduleId.replace(/[^a-zA-Z0-9_]/g, '_')}_${ctx.importIdRef.value++}`,\n importPath: ctx.sanitizeGeneratedModuleSpecifier(table.importPath),\n })\n }\n },\n generateOutput() {\n reportUnresolvableWidgetReferences(widgetEntries, tableWidgetRefs)\n\n const widgetDecls = Array.from(widgetEntries.entries())\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([, entry]) =>\n objectLiteral([\n { name: 'moduleId', value: entry.moduleId },\n { name: 'key', value: entry.key },\n { name: 'source', value: entry.source },\n ...(entry.widgetId ? [{ name: 'widgetId', value: entry.widgetId }] : []),\n {\n name: 'loader',\n value: arrowFunction({\n body: methodCall(dynamicImportExpression(entry.importPath), 'then', [\n arrowFunction({\n parameters: ['mod'],\n body: nullishCoalesce([\n propertyAccess(identifier('mod'), 'default'),\n identifier('mod'),\n ]),\n }),\n ]),\n }),\n },\n ]),\n )\n\n const widgetsOutput = renderGeneratedTsSource({\n fileName: 'injection-widgets.generated.ts',\n imports: [\n { namedImports: [{ name: 'ModuleInjectionWidgetEntry', isTypeOnly: true }], moduleSpecifier: '@open-mercato/shared/modules/registry' },\n ],\n build(sourceFile) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'injectionWidgetEntries',\n type: 'ModuleInjectionWidgetEntry[]',\n initializer: arrayLiteral(widgetDecls, writeValue),\n },\n ],\n })\n },\n })\n\n const tableImports = tableEntries.map((entry) => namespaceImportSpec(entry.importName, entry.importPath))\n const tableDecls = tableEntries.map((entry) =>\n objectLiteral([\n { name: 'moduleId', value: entry.moduleId },\n {\n name: 'table',\n value: namespaceFallback({\n importName: entry.importName,\n members: ['default', 'injectionTable'],\n fallback: emptyObject(),\n castType: 'ModuleInjectionTable',\n }),\n },\n ]),\n )\n const tablesOutput = renderGeneratedTsSource({\n fileName: 'injection-tables.generated.ts',\n imports: [\n { namedImports: [{ name: 'ModuleInjectionTable', isTypeOnly: true }], moduleSpecifier: '@open-mercato/shared/modules/widgets/injection' },\n ...tableImports,\n ],\n build(sourceFile) {\n sourceFile.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: 'injectionTables',\n type: 'Array<{ moduleId: string; table: ModuleInjectionTable }>',\n initializer: arrayLiteral(tableDecls, writeValue),\n },\n ],\n })\n },\n })\n\n return new Map([\n ['injection-widgets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AC;AAAA,IACH;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/cli",
3
- "version": "0.6.7-develop.6686.1.bdda5ed397",
3
+ "version": "0.6.7-develop.6687.1.46a258e592",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -60,8 +60,8 @@
60
60
  "@mikro-orm/decorators": "^7.1.5",
61
61
  "@mikro-orm/migrations": "^7.1.5",
62
62
  "@mikro-orm/postgresql": "^7.1.5",
63
- "@open-mercato/queue": "0.6.7-develop.6686.1.bdda5ed397",
64
- "@open-mercato/shared": "0.6.7-develop.6686.1.bdda5ed397",
63
+ "@open-mercato/queue": "0.6.7-develop.6687.1.46a258e592",
64
+ "@open-mercato/shared": "0.6.7-develop.6687.1.46a258e592",
65
65
  "cross-spawn": "^7.0.6",
66
66
  "pg": "8.22.0",
67
67
  "semver": "^7.8.5",
@@ -72,10 +72,10 @@
72
72
  "typescript-js": "npm:typescript@6.0.3"
73
73
  },
74
74
  "peerDependencies": {
75
- "@open-mercato/shared": "0.6.7-develop.6686.1.bdda5ed397"
75
+ "@open-mercato/shared": "0.6.7-develop.6687.1.46a258e592"
76
76
  },
77
77
  "devDependencies": {
78
- "@open-mercato/shared": "0.6.7-develop.6686.1.bdda5ed397",
78
+ "@open-mercato/shared": "0.6.7-develop.6687.1.46a258e592",
79
79
  "@types/jest": "^30.0.0",
80
80
  "jest": "^30.4.2",
81
81
  "ts-jest": "^29.4.11"
@@ -0,0 +1,184 @@
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import { createInjectionWidgetsExtension } from '../generators/extensions/injection-widgets'
5
+ import type { ModuleScanContext } from '../generators/extension'
6
+
7
+ // A widget's `metadata.id` and the `widgetId` that mounts it are two hand-typed literals in two
8
+ // different files. Nothing linked them, so a typo in either failed silently — the widget was never
9
+ // mounted, or the table entry resolved to nothing. These cases drive the real scan → generate seam
10
+ // (real filesystem fixtures, real AST extraction) and assert the reconciliation warnings.
11
+
12
+ let tmpRoot: string
13
+
14
+ beforeEach(() => {
15
+ tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'om-injection-widgets-'))
16
+ })
17
+
18
+ afterEach(() => {
19
+ fs.rmSync(tmpRoot, { recursive: true, force: true })
20
+ jest.restoreAllMocks()
21
+ })
22
+
23
+ function widgetSource(id: string): string {
24
+ return [
25
+ "import type { InjectionWidgetModule } from '@open-mercato/shared/modules/widgets/injection'",
26
+ "import Impl from './widget.client'",
27
+ '',
28
+ 'const widget: InjectionWidgetModule = {',
29
+ ' metadata: {',
30
+ ` id: '${id}',`,
31
+ " title: 'Fixture widget',",
32
+ ' },',
33
+ ' Widget: Impl,',
34
+ '}',
35
+ '',
36
+ 'export default widget',
37
+ ].join('\n')
38
+ }
39
+
40
+ function tableSource(widgetIds: string[]): string {
41
+ const entries = widgetIds
42
+ .map((id, index) => ` 'detail:fixture:tab${index}': [{ widgetId: '${id}', kind: 'tab' }],`)
43
+ .join('\n')
44
+ return [
45
+ "import type { ModuleInjectionTable } from '@open-mercato/shared/modules/widgets/injection'",
46
+ '',
47
+ 'export const injectionTable: ModuleInjectionTable = {',
48
+ entries,
49
+ '}',
50
+ '',
51
+ 'export default injectionTable',
52
+ ].join('\n')
53
+ }
54
+
55
+ /**
56
+ * Lays out one module on disk in the shape the scanner expects and returns a scan context for it.
57
+ * `declaredIds` each get `widgets/injection/<name>/widget.ts`; `referencedIds` go into the module's
58
+ * `widgets/injection-table.ts` (omitted entirely when the list is empty).
59
+ */
60
+ function makeModule(moduleId: string, declaredIds: string[], referencedIds: string[]): ModuleScanContext {
61
+ const base = path.join(tmpRoot, moduleId)
62
+ const injectionDir = path.join(base, 'widgets', 'injection')
63
+ fs.mkdirSync(injectionDir, { recursive: true })
64
+
65
+ declaredIds.forEach((id, index) => {
66
+ const dir = path.join(injectionDir, `w${index}`)
67
+ fs.mkdirSync(dir, { recursive: true })
68
+ fs.writeFileSync(path.join(dir, 'widget.ts'), widgetSource(id))
69
+ })
70
+
71
+ const tablePath = path.join(base, 'widgets', 'injection-table.ts')
72
+ if (referencedIds.length > 0) fs.writeFileSync(tablePath, tableSource(referencedIds))
73
+
74
+ const roots = { appBase: base, pkgBase: base }
75
+ return {
76
+ moduleId,
77
+ roots,
78
+ imps: { appBase: `@fixture/${moduleId}`, pkgBase: `@fixture/${moduleId}` },
79
+ importIdRef: { value: 0 },
80
+ sharedImports: [],
81
+ resolveModuleFile: (() =>
82
+ referencedIds.length > 0
83
+ ? { absolutePath: tablePath, importPath: `@fixture/${moduleId}/widgets/injection-table` }
84
+ : null) as unknown as ModuleScanContext['resolveModuleFile'],
85
+ resolveFirstModuleFile: (() => null) as unknown as ModuleScanContext['resolveFirstModuleFile'],
86
+ processStandaloneConfig: () => null,
87
+ sanitizeGeneratedModuleSpecifier: (importPath: string) => importPath,
88
+ }
89
+ }
90
+
91
+ function runGenerate(contexts: ModuleScanContext[]): string[] {
92
+ const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
93
+ const extension = createInjectionWidgetsExtension()
94
+ for (const ctx of contexts) extension.scanModule(ctx)
95
+ extension.generateOutput()
96
+ return warn.mock.calls.map((call) => String(call[0]))
97
+ }
98
+
99
+ describe('injection widget id reconciliation at generate time', () => {
100
+ it('stays silent when every declared widget is referenced and vice versa', () => {
101
+ const warnings = runGenerate([makeModule('alpha', ['alpha.one', 'alpha.two'], ['alpha.one', 'alpha.two'])])
102
+
103
+ expect(warnings).toEqual([])
104
+ })
105
+
106
+ it('warns when an injection table references a widget id nothing declares', () => {
107
+ const warnings = runGenerate([makeModule('alpha', ['alpha.one'], ['alpha.one', 'alpha.typo'])])
108
+
109
+ expect(warnings).toHaveLength(1)
110
+ expect(warnings[0]).toContain('alpha.typo')
111
+ expect(warnings[0]).toContain('references widget id')
112
+ expect(warnings[0]).toContain('alpha')
113
+ })
114
+
115
+ it('stays silent about a declared widget that no table references', () => {
116
+ // The mirror check is deliberately not implemented: `extractInjectionTableWidgetIds` reads only
117
+ // statically-analyzable literals, so a table built by composition or computation exposes no ids
118
+ // and every widget in such a module would be reported as unreferenced. Pinned so the omission is
119
+ // a decision rather than an oversight.
120
+ const warnings = runGenerate([makeModule('alpha', ['alpha.one', 'alpha.orphan'], ['alpha.one'])])
121
+
122
+ expect(warnings).toEqual([])
123
+ })
124
+
125
+ it('reports only the unresolvable reference when the two sides disagree entirely', () => {
126
+ const warnings = runGenerate([makeModule('alpha', ['alpha.declared'], ['alpha.referenced'])])
127
+
128
+ expect(warnings).toHaveLength(1)
129
+ expect(warnings[0]).toContain('alpha.referenced')
130
+ })
131
+
132
+ it('does not warn about a table assembled by composition, whose ids are invisible statically', () => {
133
+ // Mirrors the real `example` module: `cond ? { ...a, ...b } : a`. The extractor sees no ids, so
134
+ // there is nothing to reconcile — and critically, no false warning.
135
+ const base = path.join(tmpRoot, 'composed')
136
+ fs.mkdirSync(path.join(base, 'widgets', 'injection', 'w0'), { recursive: true })
137
+ fs.writeFileSync(path.join(base, 'widgets', 'injection', 'w0', 'widget.ts'), widgetSource('composed.one'))
138
+ const tablePath = path.join(base, 'widgets', 'injection-table.ts')
139
+ fs.writeFileSync(
140
+ tablePath,
141
+ [
142
+ "import type { ModuleInjectionTable } from '@open-mercato/shared/modules/widgets/injection'",
143
+ "const a: ModuleInjectionTable = { 'detail:x:tab': [{ widgetId: 'composed.one' }] }",
144
+ "const b: ModuleInjectionTable = { 'detail:y:tab': [{ widgetId: 'composed.two' }] }",
145
+ 'export const injectionTable: ModuleInjectionTable = process.env.FLAG ? { ...a, ...b } : a',
146
+ 'export default injectionTable',
147
+ ].join('\n'),
148
+ )
149
+
150
+ const ctx: ModuleScanContext = {
151
+ ...makeModule('composed', [], []),
152
+ resolveModuleFile: (() => ({
153
+ absolutePath: tablePath,
154
+ importPath: '@fixture/composed/widgets/injection-table',
155
+ })) as unknown as ModuleScanContext['resolveModuleFile'],
156
+ }
157
+
158
+ expect(runGenerate([ctx])).toEqual([])
159
+ })
160
+
161
+ it('accepts a table in one module referencing a widget declared in another', () => {
162
+ const warnings = runGenerate([
163
+ makeModule('alpha', ['alpha.shared'], []),
164
+ makeModule('beta', [], ['alpha.shared']),
165
+ ])
166
+
167
+ expect(warnings).toEqual([])
168
+ })
169
+
170
+ it('does not warn for the single-widget id inference', () => {
171
+ // A lone widget whose metadata.id cannot be extracted adopts the table's single id; that
172
+ // convenience path must not then report itself as a mismatch.
173
+ const ctx = makeModule('gamma', [], ['gamma.inferred'])
174
+ const dir = path.join(tmpRoot, 'gamma', 'widgets', 'injection', 'solo')
175
+ fs.mkdirSync(dir, { recursive: true })
176
+ fs.writeFileSync(path.join(dir, 'widget.ts'), 'export default { Widget: () => null }\n')
177
+
178
+ expect(runGenerate([ctx])).toEqual([])
179
+ })
180
+
181
+ it('stays silent for a module with no injection widgets and no table', () => {
182
+ expect(runGenerate([makeModule('delta', [], [])])).toEqual([])
183
+ })
184
+ })
@@ -183,9 +183,52 @@ function resolveScannedWidgetPath(roots: ModuleRoots, fromApp: boolean, relPath:
183
183
  return path.join(base, 'widgets', 'injection', ...relPath.split('/'))
184
184
  }
185
185
 
186
+ /**
187
+ * A widget's `metadata.id` and the injection-table entry that mounts it are two hand-typed string
188
+ * literals in two different files, and nothing links them. A typo in either fails silently: the spot
189
+ * resolves to no widget and nothing is logged, so it only surfaces as "why isn't my widget
190
+ * rendering" during manual QA.
191
+ *
192
+ * Reports table entries whose `widgetId` no scanned widget declares. Diagnostics only — generated
193
+ * output is unchanged and the build is not failed, since a table entry may legitimately point at a
194
+ * widget supplied by a module that is not enabled in this app.
195
+ *
196
+ * Deliberately one-directional. The mirror check ("a widget nothing references is never mounted")
197
+ * cannot be done reliably yet: `extractInjectionTableWidgetIds` only reads statically-analyzable
198
+ * object literals, so a table assembled by composition or computation contributes **no** visible
199
+ * ids — `example` exports `cond ? { ...a, ...b } : a` and `translations` exports
200
+ * `buildInjectionTable()`, and both would have every one of their widgets reported as unreferenced.
201
+ * Under-reporting is harmless in the direction implemented here (a reference the extractor never saw
202
+ * cannot produce a warning) but fatal in the other. Teaching the extractor to resolve spreads,
203
+ * conditionals and call expressions is the prerequisite for adding it.
204
+ */
205
+ function reportUnresolvableWidgetReferences(
206
+ widgetEntries: Map<string, InjectionWidgetEntry>,
207
+ tableWidgetRefs: Map<string, Set<string>>,
208
+ ): void {
209
+ const declaredIds = new Set<string>()
210
+ for (const entry of widgetEntries.values()) {
211
+ if (entry.widgetId) declaredIds.add(entry.widgetId)
212
+ }
213
+
214
+ for (const [widgetId, modules] of Array.from(tableWidgetRefs.entries()).sort(([a], [b]) => a.localeCompare(b))) {
215
+ if (declaredIds.has(widgetId)) continue
216
+ const owners = Array.from(modules).sort((left, right) => left.localeCompare(right)).join(', ')
217
+ console.warn(
218
+ `[generate] ⚠ Injection table in "${owners}" references widget id "${widgetId}", but no scanned ` +
219
+ 'widget declares it — that spot will render nothing. Check the id against the widget\'s ' +
220
+ 'metadata.id, and that the widget lives in a file the scanner reads ' +
221
+ '(widgets/injection/**/widget.ts|tsx — note that widget.client.tsx alone is not scanned).',
222
+ )
223
+ }
224
+ }
225
+
186
226
  export function createInjectionWidgetsExtension(): GeneratorExtension {
187
227
  const widgetEntries = new Map<string, InjectionWidgetEntry>()
188
228
  const tableEntries: InjectionTableEntry[] = []
229
+ // widgetId -> module ids whose injection table references it. Collected across every module so a
230
+ // table may legitimately reference a widget another module owns.
231
+ const tableWidgetRefs = new Map<string, Set<string>>()
189
232
 
190
233
  return {
191
234
  id: 'registry.injection-widgets',
@@ -217,6 +260,12 @@ export function createInjectionWidgetsExtension(): GeneratorExtension {
217
260
  moduleWidgetEntries[0].widgetId = tableWidgetIds[0]
218
261
  }
219
262
 
263
+ for (const widgetId of tableWidgetIds) {
264
+ const modules = tableWidgetRefs.get(widgetId) ?? new Set<string>()
265
+ modules.add(ctx.moduleId)
266
+ tableWidgetRefs.set(widgetId, modules)
267
+ }
268
+
220
269
  for (const entry of moduleWidgetEntries) {
221
270
  const existing = widgetEntries.get(entry.key)
222
271
  if (!existing || (existing.source !== 'app' && entry.source === 'app')) {
@@ -233,6 +282,8 @@ export function createInjectionWidgetsExtension(): GeneratorExtension {
233
282
  }
234
283
  },
235
284
  generateOutput() {
285
+ reportUnresolvableWidgetReferences(widgetEntries, tableWidgetRefs)
286
+
236
287
  const widgetDecls = Array.from(widgetEntries.entries())
237
288
  .sort(([left], [right]) => left.localeCompare(right))
238
289
  .map(([, entry]) =>