@open-mercato/cli 0.11.1-develop.8784.1.e9d95a72f5 → 0.11.1-develop.8843.1.b02f9b125d

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 (210) hide show
  1. package/.turbo/turbo-build.log +8 -2
  2. package/AGENTS.md +2 -0
  3. package/dist/agentic/guides/architecture.md +1 -0
  4. package/dist/agentic/guides/module-facts.json +2453 -1146
  5. package/dist/agentic/guides/module-facts.v2.json +2453 -1146
  6. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  7. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  8. package/dist/agentic/guides/modules/ai_assistant/owned-contract-module-metadata.md +1 -1
  9. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  10. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  11. package/dist/agentic/guides/modules/assisted_selling/index.md +1 -1
  12. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  13. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  14. package/dist/agentic/guides/modules/auth/index.md +1 -1
  15. package/dist/agentic/guides/modules/auth/owned-contract-module-metadata.md +1 -1
  16. package/dist/agentic/guides/modules/availability/index.md +1 -1
  17. package/dist/agentic/guides/modules/backups/index.md +1 -1
  18. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  19. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  20. package/dist/agentic/guides/modules/cart/index.md +1 -1
  21. package/dist/agentic/guides/modules/cart/owned-contract-module-metadata.md +1 -1
  22. package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +11 -8
  23. package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -5
  24. package/dist/agentic/guides/modules/catalog/exact-override-targets.md +11 -8
  25. package/dist/agentic/guides/modules/catalog/index.md +2 -2
  26. package/dist/agentic/guides/modules/catalog/owned-contract-module-metadata.md +1 -1
  27. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  28. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  29. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  30. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  31. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  32. package/dist/agentic/guides/modules/channel_gmail/owned-contract-module-metadata.md +1 -1
  33. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  34. package/dist/agentic/guides/modules/channel_imap/owned-contract-module-metadata.md +1 -1
  35. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  36. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  37. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  38. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  39. package/dist/agentic/guides/modules/communication_channels/exact-override-targets.md +2 -2
  40. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  41. package/dist/agentic/guides/modules/communication_channels/owned-contract-module-metadata.md +1 -1
  42. package/dist/agentic/guides/modules/communication_channels/workers.md +2 -2
  43. package/dist/agentic/guides/modules/configs/acl-features.md +2 -1
  44. package/dist/agentic/guides/modules/configs/backend-pages.md +1 -0
  45. package/dist/agentic/guides/modules/configs/entities.md +0 -1
  46. package/dist/agentic/guides/modules/configs/exact-override-targets.md +2 -0
  47. package/dist/agentic/guides/modules/configs/host-extension-points.md +10 -0
  48. package/dist/agentic/guides/modules/configs/index.md +5 -3
  49. package/dist/agentic/guides/modules/configs/owned-contract-module-metadata.md +1 -1
  50. package/dist/agentic/guides/modules/configs/setup.md +1 -1
  51. package/dist/agentic/guides/modules/configs/umes-diagnostics.md +9 -0
  52. package/dist/agentic/guides/modules/configs/umes-hosts.md +9 -1
  53. package/dist/agentic/guides/modules/content/index.md +1 -1
  54. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  55. package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
  56. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  57. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  58. package/dist/agentic/guides/modules/customers/acl-features.md +2 -1
  59. package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -0
  60. package/dist/agentic/guides/modules/customers/contribution-resolutions.md +2 -0
  61. package/dist/agentic/guides/modules/customers/di-registrations-rich.md +8 -5
  62. package/dist/agentic/guides/modules/customers/domain-commands.md +1 -1
  63. package/dist/agentic/guides/modules/customers/exact-override-targets.md +11 -5
  64. package/dist/agentic/guides/modules/customers/index.md +5 -5
  65. package/dist/agentic/guides/modules/customers/owned-contract-module-metadata.md +1 -1
  66. package/dist/agentic/guides/modules/customers/umes-contributions.md +2 -0
  67. package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -10
  68. package/dist/agentic/guides/modules/dashboards/contribution-resolutions.md +0 -10
  69. package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +0 -10
  70. package/dist/agentic/guides/modules/dashboards/index.md +5 -5
  71. package/dist/agentic/guides/modules/dashboards/umes-contributions.md +0 -10
  72. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  73. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  74. package/dist/agentic/guides/modules/devices/index.md +1 -1
  75. package/dist/agentic/guides/modules/devices/owned-contract-module-metadata.md +1 -1
  76. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  77. package/dist/agentic/guides/modules/directory/index.md +1 -1
  78. package/dist/agentic/guides/modules/documents/index.md +1 -1
  79. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  80. package/dist/agentic/guides/modules/ecommerce/owned-contract-module-metadata.md +1 -1
  81. package/dist/agentic/guides/modules/entities/index.md +1 -1
  82. package/dist/agentic/guides/modules/entities/owned-contract-module-metadata.md +1 -1
  83. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  84. package/dist/agentic/guides/modules/events/index.md +1 -1
  85. package/dist/agentic/guides/modules/events/owned-contract-module-metadata.md +1 -1
  86. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  87. package/dist/agentic/guides/modules/forms/index.md +1 -1
  88. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  89. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  90. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  91. package/dist/agentic/guides/modules/generators/index.md +1 -1
  92. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  93. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  94. package/dist/agentic/guides/modules/integrations/owned-contract-module-metadata.md +1 -1
  95. package/dist/agentic/guides/modules/ledger/index.md +1 -1
  96. package/dist/agentic/guides/modules/maintenance/contribution-resolutions.md +11 -0
  97. package/dist/agentic/guides/modules/maintenance/events.md +14 -0
  98. package/dist/agentic/guides/modules/maintenance/exact-override-targets.md +11 -0
  99. package/dist/agentic/guides/modules/maintenance/index.md +17 -0
  100. package/dist/agentic/guides/modules/maintenance/owned-contract-module-metadata.md +11 -0
  101. package/dist/agentic/guides/modules/maintenance/umes-contributions.md +11 -0
  102. package/dist/agentic/guides/modules/maintenance/umes-hosts.md +14 -0
  103. package/dist/agentic/guides/modules/messages/index.md +1 -1
  104. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  105. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  106. package/dist/agentic/guides/modules/payment_gateways/exact-override-targets.md +3 -3
  107. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  108. package/dist/agentic/guides/modules/payment_gateways/setup.md +1 -1
  109. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  110. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  111. package/dist/agentic/guides/modules/phone_calls/owned-contract-module-metadata.md +1 -1
  112. package/dist/agentic/guides/modules/planner/index.md +1 -1
  113. package/dist/agentic/guides/modules/portal/index.md +1 -1
  114. package/dist/agentic/guides/modules/progress/index.md +1 -1
  115. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  116. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  117. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  118. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  119. package/dist/agentic/guides/modules/resources/index.md +1 -1
  120. package/dist/agentic/guides/modules/sales/active-extension-bindings.md +8 -0
  121. package/dist/agentic/guides/modules/sales/contribution-resolutions.md +8 -0
  122. package/dist/agentic/guides/modules/sales/di-registrations-rich.md +31 -30
  123. package/dist/agentic/guides/modules/sales/di-service-tokens.md +5 -5
  124. package/dist/agentic/guides/modules/sales/exact-override-targets.md +39 -30
  125. package/dist/agentic/guides/modules/sales/index.md +5 -5
  126. package/dist/agentic/guides/modules/sales/owned-contract-module-metadata.md +1 -1
  127. package/dist/agentic/guides/modules/sales/umes-contributions.md +8 -0
  128. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  129. package/dist/agentic/guides/modules/search/index.md +1 -1
  130. package/dist/agentic/guides/modules/search/owned-contract-module-metadata.md +1 -1
  131. package/dist/agentic/guides/modules/security/index.md +1 -1
  132. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  133. package/dist/agentic/guides/modules/shipping_carriers/active-extension-bindings.md +1 -1
  134. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  135. package/dist/agentic/guides/modules/sso/index.md +1 -1
  136. package/dist/agentic/guides/modules/staff/active-extension-bindings.md +2 -1
  137. package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -0
  138. package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -0
  139. package/dist/agentic/guides/modules/staff/index.md +8 -8
  140. package/dist/agentic/guides/modules/staff/umes-contributions.md +1 -0
  141. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  142. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  143. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  144. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  145. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  146. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  147. package/dist/agentic/guides/modules/translations/index.md +1 -1
  148. package/dist/agentic/guides/modules/upgrade_actions/cli-commands.md +11 -0
  149. package/dist/agentic/guides/modules/upgrade_actions/contribution-resolutions.md +12 -0
  150. package/dist/agentic/guides/modules/upgrade_actions/entities.md +11 -0
  151. package/dist/agentic/guides/modules/upgrade_actions/exact-override-targets.md +12 -0
  152. package/dist/agentic/guides/modules/upgrade_actions/index.md +18 -0
  153. package/dist/agentic/guides/modules/upgrade_actions/owned-contract-module-metadata.md +11 -0
  154. package/dist/agentic/guides/modules/upgrade_actions/umes-contributions.md +12 -0
  155. package/dist/agentic/guides/modules/upgrade_actions/umes-hosts.md +11 -0
  156. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  157. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  158. package/dist/agentic/guides/modules/wms/index.md +1 -1
  159. package/dist/agentic/guides/modules/workflows/domain-commands.md +3 -0
  160. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  161. package/dist/agentic/guides/production-deployment.md +6 -0
  162. package/dist/agentic/guides/reference-module-facts.json +1 -1
  163. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +17 -9
  164. package/dist/agentic/guides/upstream/manifest.json +2 -2
  165. package/dist/agentic/shared/AGENTS.md.template +1 -1
  166. package/dist/agentic/shared/ai/harness/cases.json +7 -7
  167. package/dist/lib/generators/extensions/dashboard-widgets.js +46 -4
  168. package/dist/lib/generators/extensions/dashboard-widgets.js.map +2 -2
  169. package/dist/lib/generators/extensions/workflows.js +25 -2
  170. package/dist/lib/generators/extensions/workflows.js.map +2 -2
  171. package/dist/lib/generators/module-facts.js +2 -0
  172. package/dist/lib/generators/module-facts.js.map +2 -2
  173. package/dist/lib/generators/module-registry.js +35 -6
  174. package/dist/lib/generators/module-registry.js.map +2 -2
  175. package/dist/lib/module-coupling/analyze.js +391 -0
  176. package/dist/lib/module-coupling/analyze.js.map +7 -0
  177. package/dist/lib/module-diagnostics.js +160 -0
  178. package/dist/lib/module-diagnostics.js.map +7 -0
  179. package/dist/lib/module-index.js +103 -0
  180. package/dist/lib/module-index.js.map +7 -0
  181. package/dist/lib/testing/ephemeral-database-guard.js +89 -0
  182. package/dist/lib/testing/ephemeral-database-guard.js.map +7 -0
  183. package/dist/lib/testing/integration-discovery.js +20 -15
  184. package/dist/lib/testing/integration-discovery.js.map +3 -3
  185. package/dist/mercato.js +45 -5
  186. package/dist/mercato.js.map +2 -2
  187. package/package.json +7 -7
  188. package/src/__tests__/init-ephemeral-database.test.ts +112 -0
  189. package/src/__tests__/mercato.test.ts +15 -0
  190. package/src/__tests__/rotation-json-output.test.ts +13 -0
  191. package/src/lib/__tests__/module-diagnostics.test.ts +207 -0
  192. package/src/lib/__tests__/modules-config.test.ts +1 -0
  193. package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +2 -1
  194. package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +2 -2
  195. package/src/lib/generators/__tests__/module-registry-requires-enforcement.test.ts +18 -0
  196. package/src/lib/generators/__tests__/output-snapshots.test.ts +19 -0
  197. package/src/lib/generators/__tests__/registry-variant-parity.test.ts +95 -19
  198. package/src/lib/generators/__tests__/structural-contracts.test.ts +18 -0
  199. package/src/lib/generators/extensions/dashboard-widgets.ts +49 -3
  200. package/src/lib/generators/extensions/workflows.ts +26 -2
  201. package/src/lib/generators/module-facts.ts +2 -0
  202. package/src/lib/generators/module-registry.ts +55 -7
  203. package/src/lib/module-coupling/analyze.ts +464 -0
  204. package/src/lib/module-diagnostics.ts +182 -0
  205. package/src/lib/module-index.ts +133 -0
  206. package/src/lib/testing/__tests__/ephemeral-database-guard.test.ts +88 -0
  207. package/src/lib/testing/__tests__/integration-discovery.test.ts +26 -2
  208. package/src/lib/testing/ephemeral-database-guard.ts +105 -0
  209. package/src/lib/testing/integration-discovery.ts +19 -11
  210. package/src/mercato.ts +47 -5
@@ -17,7 +17,7 @@ import path from 'node:path'
17
17
  import os from 'node:os'
18
18
  import ts from 'typescript-js'
19
19
  import type { PackageResolver, ModuleEntry } from '../../resolver'
20
- import { generateModuleRegistry, generateModuleRegistryApp, generateModuleRegistryCli } from '../module-registry'
20
+ import { generateModuleRegistries, generateModuleRegistry, generateModuleRegistryApp, generateModuleRegistryCli } from '../module-registry'
21
21
 
22
22
  /** Properties both registry variants must agree on, per module. */
23
23
  const SHARED_PROPERTIES = [
@@ -35,10 +35,19 @@ const SHARED_PROPERTIES = [
35
35
  'setup',
36
36
  'runtime',
37
37
  'defaultEncryptionMaps',
38
+ 'upgradeActions',
38
39
  'integrations',
39
40
  'bundles',
40
41
  ] as const
41
42
 
43
+ const SERVER_REGISTRY_FILES = [
44
+ 'modules.generated.ts',
45
+ 'modules.runtime.generated.ts',
46
+ 'modules.app.generated.ts',
47
+ 'modules.bootstrap.generated.ts',
48
+ 'modules.cli.generated.ts',
49
+ ]
50
+
42
51
  let tmpDir: string
43
52
  let outputDir: string
44
53
  let fileMtimeNonce = 0
@@ -55,22 +64,28 @@ function pkgModulePath(modId: string, ...segments: string[]): string {
55
64
  return path.join(tmpDir, 'packages', 'core', 'src', 'modules', modId, ...segments)
56
65
  }
57
66
 
58
- function createMockResolver(enabled: ModuleEntry[]): PackageResolver {
67
+ function appModulePath(modId: string, ...segments: string[]): string {
68
+ return path.join(tmpDir, 'app', 'src', 'modules', modId, ...segments)
69
+ }
70
+
71
+ function createMockResolver(enabled: ModuleEntry[], generatedDir = outputDir): PackageResolver {
72
+ const getPackageName = (entry: ModuleEntry): string =>
73
+ entry.from?.startsWith('@open-mercato/') ? entry.from : '@open-mercato/core'
59
74
  return {
60
75
  isMonorepo: () => true,
61
76
  getRootDir: () => tmpDir,
62
77
  getAppDir: () => path.join(tmpDir, 'app'),
63
- getOutputDir: () => outputDir,
78
+ getOutputDir: () => generatedDir,
64
79
  getModulesConfigPath: () => path.join(tmpDir, 'app', 'src', 'modules.ts'),
65
80
  discoverPackages: () => [],
66
81
  loadEnabledModules: () => enabled,
67
82
  getModulePaths: (entry: ModuleEntry) => ({
68
83
  appBase: path.join(tmpDir, 'app', 'src', 'modules', entry.id),
69
- pkgBase: path.join(tmpDir, 'packages', 'core', 'src', 'modules', entry.id),
84
+ pkgBase: path.join(tmpDir, 'packages', getPackageName(entry).slice('@open-mercato/'.length), 'src', 'modules', entry.id),
70
85
  }),
71
86
  getModuleImportBase: (entry: ModuleEntry) => ({
72
87
  appBase: `@/modules/${entry.id}`,
73
- pkgBase: `@open-mercato/core/modules/${entry.id}`,
88
+ pkgBase: `${getPackageName(entry)}/modules/${entry.id}`,
74
89
  }),
75
90
  getPackageOutputDir: () => outputDir,
76
91
  getPackageRoot: () => path.join(tmpDir, 'packages', 'core'),
@@ -118,17 +133,36 @@ function scaffoldFixture(): ModuleEntry[] {
118
133
  touchFile(pkgModulePath('orders', 'ce.ts'), "export const entities = [{ id: 'orders:custom', fields: [{ id: 'note', kind: 'text' }] }]\n")
119
134
  touchFile(pkgModulePath('orders', 'i18n', 'en.json'), JSON.stringify({ orders: { title: 'Orders' } }))
120
135
  touchFile(pkgModulePath('orders', 'cli.ts'), 'export default { command: "orders", run: async () => {} }\n')
136
+ touchFile(
137
+ pkgModulePath('orders', 'upgrades.ts'),
138
+ "import action from './upgrades/0.1.0-backfill'\nexport const upgradeActions = [action]\nexport default upgradeActions\n",
139
+ )
140
+ touchFile(
141
+ pkgModulePath('orders', 'upgrades', '0.1.0-backfill.ts'),
142
+ "export default { id: 'orders.backfill', version: '0.1.0', messageKey: 'm', ctaKey: 'c', successKey: 's', run: async () => {} }\n",
143
+ )
144
+ touchFile(appModulePath('shop', 'index.ts'), "export const metadata = { id: 'shop', label: 'Shop' }\n")
145
+ touchFile(
146
+ appModulePath('shop', 'upgrades.ts'),
147
+ "export const upgradeActions = [{ id: 'shop.seed', version: '0.1.0', messageKey: 'm', ctaKey: 'c', successKey: 's', run: async () => {} }]\n",
148
+ )
121
149
 
122
150
  touchFile(pkgModulePath('bare', 'index.ts'), "export const metadata = { id: 'bare', label: 'Bare' }\n")
151
+ touchFile(
152
+ path.join(tmpDir, 'packages', 'upgrade-actions', 'src', 'modules', 'upgrade_actions', 'index.ts'),
153
+ "export const metadata = { id: 'upgrade_actions', label: 'Upgrade actions' }\n",
154
+ )
123
155
 
124
156
  return [
125
157
  { id: 'orders', from: '@open-mercato/core' },
126
158
  { id: 'bare', from: '@open-mercato/core' },
159
+ { id: 'shop', from: '@app' },
160
+ { id: 'upgrade_actions', from: '@open-mercato/upgrade-actions' },
127
161
  ]
128
162
  }
129
163
 
130
- function readGenerated(fileName: string): string {
131
- const filePath = path.join(outputDir, fileName)
164
+ function readGenerated(fileName: string, generatedDir = outputDir): string {
165
+ const filePath = path.join(generatedDir, fileName)
132
166
  if (!fs.existsSync(filePath)) throw new Error(`Expected generated file not found: ${fileName}`)
133
167
  return fs.readFileSync(filePath, 'utf8')
134
168
  }
@@ -183,6 +217,7 @@ function restrictTo(names: Set<string>, allowed: readonly string[]): string[] {
183
217
  }
184
218
 
185
219
  describe('module registry variant parity', () => {
220
+ let enabledModules: ModuleEntry[]
186
221
  let mainVariant: Map<string, Set<string>>
187
222
  let runtimeVariant: Map<string, Set<string>>
188
223
  let appVariant: Map<string, Set<string>>
@@ -192,7 +227,8 @@ describe('module registry variant parity', () => {
192
227
  outputDir = path.join(tmpDir, 'app', '.mercato', 'generated')
193
228
  fs.mkdirSync(outputDir, { recursive: true })
194
229
 
195
- const resolver = createMockResolver(scaffoldFixture())
230
+ enabledModules = scaffoldFixture()
231
+ const resolver = createMockResolver(enabledModules)
196
232
  const mainResult = await generateModuleRegistry({ resolver, quiet: true })
197
233
  const appResult = await generateModuleRegistryApp({ resolver, quiet: true })
198
234
  const cliResult = await generateModuleRegistryCli({ resolver, quiet: true })
@@ -214,7 +250,7 @@ describe('module registry variant parity', () => {
214
250
 
215
251
  it('discovers the same module ids in every variant', () => {
216
252
  const ids = [...mainVariant.keys()].sort()
217
- expect(ids).toEqual(['bare', 'orders'])
253
+ expect(ids).toEqual(['bare', 'orders', 'shop', 'upgrade_actions'])
218
254
  expect([...runtimeVariant.keys()].sort()).toEqual(ids)
219
255
  expect([...appVariant.keys()].sort()).toEqual(ids)
220
256
  })
@@ -247,20 +283,12 @@ describe('module registry variant parity', () => {
247
283
  // reads the app and bootstrap registries. A convention file that reaches only some of them is a
248
284
  // runtime that starts in some processes and not others, with nothing to say so.
249
285
  it('emits the module runtime in every registry a process can read', () => {
250
- const registryFiles = [
251
- 'modules.generated.ts',
252
- 'modules.runtime.generated.ts',
253
- 'modules.app.generated.ts',
254
- 'modules.bootstrap.generated.ts',
255
- 'modules.cli.generated.ts',
256
- ]
257
-
258
- const carriesRuntime = registryFiles.map((fileName) => {
286
+ const carriesRuntime = SERVER_REGISTRY_FILES.map((fileName) => {
259
287
  const byId = parseModulePropertiesById(readGenerated(fileName), fileName)
260
288
  return [fileName, byId.get('orders')?.has('runtime'), byId.get('bare')?.has('runtime')]
261
289
  })
262
290
 
263
- expect(carriesRuntime).toEqual(registryFiles.map((fileName) => [fileName, true, false]))
291
+ expect(carriesRuntime).toEqual(SERVER_REGISTRY_FILES.map((fileName) => [fileName, true, false]))
264
292
  })
265
293
 
266
294
  // The IIFE `namespaceFallback` emits narrows `unknown` to `{}`. That satisfies `setup`, whose
@@ -279,6 +307,54 @@ describe('module registry variant parity', () => {
279
307
  }
280
308
  })
281
309
 
310
+ it('emits module-owned upgrade actions in every server registry when the consumer is registered', () => {
311
+ const carriesUpgradeActions = SERVER_REGISTRY_FILES.map((fileName) => {
312
+ const byId = parseModulePropertiesById(readGenerated(fileName), fileName)
313
+ return [
314
+ fileName,
315
+ byId.get('orders')?.has('upgradeActions'),
316
+ byId.get('shop')?.has('upgradeActions'),
317
+ byId.get('bare')?.has('upgradeActions'),
318
+ ]
319
+ })
320
+
321
+ expect(carriesUpgradeActions).toEqual(SERVER_REGISTRY_FILES.map((fileName) => [fileName, true, true, false]))
322
+ expect(readGenerated('modules.cli.generated.ts')).toMatch(/import \* as UPGRADES_orders from ["']@open-mercato\/core\/modules\/orders\/upgrades["']/)
323
+ expect(readGenerated('modules.cli.generated.ts')).toMatch(/import \* as UPGRADES_shop from ["'][./]*\/?.*modules\/shop\/upgrades["']/)
324
+ })
325
+
326
+ it('omits upgrade action registrations and imports when the installed consumer is disabled', async () => {
327
+ const disabledOutputDir = path.join(path.dirname(outputDir), 'disabled-generated')
328
+ fs.cpSync(outputDir, disabledOutputDir, { recursive: true })
329
+ const resolver = createMockResolver(enabledModules.filter((entry) => entry.id !== 'upgrade_actions'), disabledOutputDir)
330
+ const results = await generateModuleRegistries({ resolver, quiet: true })
331
+ expect(results.map((result) => result.errors)).toEqual([[], [], []])
332
+
333
+ for (const fileName of SERVER_REGISTRY_FILES) {
334
+ const content = readGenerated(fileName, disabledOutputDir)
335
+ const byId = parseModulePropertiesById(content, fileName)
336
+ expect(byId.get('orders')?.has('upgradeActions')).toBe(false)
337
+ expect(byId.get('shop')?.has('upgradeActions')).toBe(false)
338
+ expect(byId.has('upgrade_actions')).toBe(false)
339
+ expect(content).not.toMatch(/UPGRADES_|@open-mercato\/upgrade-actions/)
340
+ }
341
+ })
342
+
343
+ it('keeps upgrade action handlers out of client, route-manifest and i18n artifacts', () => {
344
+ const serverRegistries = new Set(SERVER_REGISTRY_FILES)
345
+ const leaking = fs
346
+ .readdirSync(outputDir)
347
+ .filter((fileName) => fileName.endsWith('.ts') && !serverRegistries.has(fileName))
348
+ .filter((fileName) => /modules\/(orders|shop)\/upgrades/.test(fs.readFileSync(path.join(outputDir, fileName), 'utf8')))
349
+ expect(leaking).toEqual([])
350
+ })
351
+
352
+ it('does not renumber existing convention imports when a module adds upgrades.ts', () => {
353
+ const content = readGenerated('modules.app.generated.ts')
354
+ expect(content).toContain('UPGRADES_orders')
355
+ expect(content).not.toMatch(/UPGRADES_orders_\d/)
356
+ })
357
+
282
358
  describe('known, intentional divergences', () => {
283
359
  it('only the main variant carries eager api handlers and the cli entry point', () => {
284
360
  expect(mainVariant.get('orders')!.has('apis')).toBe(true)
@@ -1084,6 +1084,24 @@ describe('dashboard-widgets.generated.ts', () => {
1084
1084
  expect(content).toContain('source: "app"')
1085
1085
  expect(content).toContain('loader: () =>')
1086
1086
  })
1087
+
1088
+ it.each([
1089
+ "export const dashboardWidgetKey = 'dashboards:revenue:widget'; export default {}",
1090
+ "const key = 'dashboards:revenue:widget'; export { key as dashboardWidgetKey }; export default {}",
1091
+ ])('keeps a relocated dashboard key in both registries with an app override (%s)', async (source) => {
1092
+ const enabled = scaffoldFixture()
1093
+ const resolver = createMockResolver(enabled)
1094
+ touchFile(pkgModulePath('orders', 'widgets', 'dashboard', 'revenue', 'widget.ts'), source)
1095
+ touchFile(appModulePath('orders', 'widgets', 'dashboard', 'revenue', 'widget.ts'), 'export default {}')
1096
+ await generateModuleRegistry({ resolver, quiet: true })
1097
+
1098
+ for (const name of ['dashboard-widgets.generated.ts', 'modules.generated.ts']) {
1099
+ const registry = readGenerated(name)
1100
+ expect(registry).toContain('key: "dashboards:revenue:widget"')
1101
+ expect(registry).not.toContain('key: "orders:revenue:widget"')
1102
+ expect(registry).toContain('@/modules/orders/widgets/dashboard/revenue/widget')
1103
+ }
1104
+ })
1087
1105
  })
1088
1106
 
1089
1107
  describe('injection-widgets.generated.ts', () => {
@@ -1,6 +1,17 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import ts from 'typescript-js'
1
4
  import { VariableDeclarationKind } from 'ts-morph'
2
5
  import type { GeneratorExtension } from '../extension'
3
- import { scanModuleDir, SCAN_CONFIGS } from '../scanner'
6
+ import {
7
+ MODULE_CODE_EXTENSIONS,
8
+ resolveStandaloneSourceMirrorBase,
9
+ scanModuleDir,
10
+ SCAN_CONFIGS,
11
+ stripModuleCodeExtension,
12
+ type ModuleRoots,
13
+ type ScannedFile,
14
+ } from '../scanner'
4
15
  import { arrayLiteral, arrowFunction, identifier, methodCall, nullishCoalesce, objectLiteral, propertyAccess, writeValue } from '../ast'
5
16
  import { dynamicImportExpression, renderGeneratedTsSource } from './shared'
6
17
 
@@ -11,6 +22,41 @@ type DashboardWidgetEntry = {
11
22
  importPath: string
12
23
  }
13
24
 
25
+ function readRegisteredWidgetKey(absolutePath: string): string | undefined {
26
+ if (!fs.existsSync(absolutePath)) return undefined
27
+ const source = ts.createSourceFile(absolutePath, fs.readFileSync(absolutePath, 'utf8'), ts.ScriptTarget.Latest, true)
28
+ const values = new Map<string, string>()
29
+ let exportName: string | undefined
30
+ for (const statement of source.statements) {
31
+ if (ts.isVariableStatement(statement)) {
32
+ const exported = statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)
33
+ for (const declaration of statement.declarationList.declarations) {
34
+ if (!ts.isIdentifier(declaration.name) || !declaration.initializer) continue
35
+ if (!ts.isStringLiteralLike(declaration.initializer) || !declaration.initializer.text) continue
36
+ values.set(declaration.name.text, declaration.initializer.text)
37
+ if (exported && declaration.name.text === 'dashboardWidgetKey') exportName = declaration.name.text
38
+ }
39
+ } else if (ts.isExportDeclaration(statement) && !statement.moduleSpecifier && statement.exportClause
40
+ && ts.isNamedExports(statement.exportClause)) {
41
+ const key = statement.exportClause.elements.find((item) => item.name.text === 'dashboardWidgetKey')
42
+ if (key) exportName = (key.propertyName ?? key.name).text
43
+ }
44
+ }
45
+ return exportName ? values.get(exportName) : undefined
46
+ }
47
+
48
+ export function resolveDashboardWidgetKey(moduleId: string, roots: ModuleRoots, file: ScannedFile): string {
49
+ const relative = path.join('widgets', 'dashboard', file.relPath)
50
+ const fallback = [moduleId, ...stripModuleCodeExtension(file.relPath).split('/')].join(':')
51
+ const packageBase = resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase
52
+ if (!file.fromApp) return readRegisteredWidgetKey(path.join(packageBase, relative)) ?? fallback
53
+ const appKey = readRegisteredWidgetKey(path.join(roots.appBase, relative))
54
+ if (appKey) return appKey
55
+ const packagePath = stripModuleCodeExtension(path.join(packageBase, relative))
56
+ const packageExtension = MODULE_CODE_EXTENSIONS.find((extension) => fs.existsSync(packagePath + extension))
57
+ return (packageExtension && readRegisteredWidgetKey(packagePath + packageExtension)) ?? fallback
58
+ }
59
+
14
60
  export function createDashboardWidgetsExtension(): GeneratorExtension {
15
61
  const widgetEntries = new Map<string, DashboardWidgetEntry>()
16
62
 
@@ -22,11 +68,11 @@ export function createDashboardWidgetsExtension(): GeneratorExtension {
22
68
  for (const { relPath, fromApp } of files) {
23
69
  const segments = relPath.split('/')
24
70
  const file = segments.pop() ?? ''
25
- const base = file.replace(/\.(t|j)sx?$/, '')
71
+ const base = stripModuleCodeExtension(file)
26
72
  const importPath = ctx.sanitizeGeneratedModuleSpecifier(
27
73
  `${fromApp ? ctx.imps.appBase : ctx.imps.pkgBase}/widgets/dashboard/${[...segments, base].join('/')}`
28
74
  )
29
- const key = [ctx.moduleId, ...segments, base].filter(Boolean).join(':')
75
+ const key = resolveDashboardWidgetKey(ctx.moduleId, ctx.roots, { relPath, fromApp })
30
76
  const entry: DashboardWidgetEntry = {
31
77
  moduleId: ctx.moduleId,
32
78
  key,
@@ -20,11 +20,16 @@ import {
20
20
  export function createWorkflowsExtension(): GeneratorExtension {
21
21
  const imports: Array<ReturnType<typeof namespaceImportSpec>> = []
22
22
  const entries: WriterFunction[] = []
23
+ let registrarImport: string | undefined
23
24
 
24
25
  return {
25
26
  id: 'registry.workflows',
26
- outputFiles: ['workflows.generated.ts'],
27
+ outputFiles: ['workflows.generated.ts', 'workflow-registrations.generated.ts'],
27
28
  scanModule(ctx) {
29
+ if (ctx.moduleId === 'workflows') {
30
+ const registrar = ctx.resolveModuleFile(ctx.roots, ctx.imps, 'lib/code-registry.ts')
31
+ if (registrar) registrarImport = ctx.sanitizeGeneratedModuleSpecifier(registrar.importPath)
32
+ }
28
33
  ctx.processStandaloneConfig({
29
34
  roots: ctx.roots,
30
35
  imps: ctx.imps,
@@ -135,7 +140,26 @@ export function createWorkflowsExtension(): GeneratorExtension {
135
140
  },
136
141
  })
137
142
 
138
- return new Map([['workflows.generated.ts', output]])
143
+ const registrationOutput = renderGeneratedTsSource({
144
+ fileName: 'workflow-registrations.generated.ts',
145
+ imports: registrarImport ? [
146
+ { namedImports: [{ name: 'allCodeWorkflows' }], moduleSpecifier: './workflows.generated' },
147
+ { namedImports: [{ name: 'registerCodeWorkflows' }], moduleSpecifier: registrarImport },
148
+ ] : [],
149
+ build(sourceFile) {
150
+ sourceFile.addFunction({
151
+ name: 'registerGeneratedCodeWorkflows',
152
+ isExported: true,
153
+ returnType: 'void',
154
+ statements: registrarImport ? ['registerCodeWorkflows(allCodeWorkflows)'] : [],
155
+ })
156
+ },
157
+ })
158
+
159
+ return new Map([
160
+ ['workflows.generated.ts', output],
161
+ ['workflow-registrations.generated.ts', registrationOutput],
162
+ ])
139
163
  },
140
164
  }
141
165
  }
@@ -1542,6 +1542,8 @@ function extractModuleMetadataContract(
1542
1542
  if (version) facts.version = version
1543
1543
  const requires = readStringArrayPropertyInitializer(metadata, 'requires')
1544
1544
  if (requires && requires.length > 0) facts.requires = requires
1545
+ const optionalRequires = readStringArrayPropertyInitializer(metadata, 'optionalRequires')
1546
+ if (optionalRequires && optionalRequires.length > 0) facts.optionalRequires = optionalRequires
1545
1547
  const ejectable = readBooleanPropertyInitializer(metadata, 'ejectable')
1546
1548
  if (ejectable !== undefined) facts.ejectable = ejectable
1547
1549
  return {
@@ -80,6 +80,7 @@ import {
80
80
  resolveStandaloneSourceMirrorBase,
81
81
  } from './scanner'
82
82
  import { loadGeneratorExtensions } from './extensions'
83
+ import { resolveDashboardWidgetKey } from './extensions/dashboard-widgets'
83
84
  import { prepareCrudFormSectionRegistries, writeCrudFormSectionRegistries, writeDerivedCrudFormSectionRoutes } from './form-sections'
84
85
  import type { ModuleScanContext, StandaloneConfigOptions } from './extension'
85
86
  import {
@@ -101,6 +102,7 @@ export interface ModuleRegistryOptions {
101
102
  interface ModuleRegistryDiscovery {
102
103
  enabled: ModuleEntry[]
103
104
  modules: ModuleRegistryDiscoveryEntry[]
105
+ hasUpgradeActionsModule: boolean
104
106
  identities: ReturnType<typeof getEnabledModuleIdentities>
105
107
  getStructureChecksum: () => string
106
108
  getCrudFormSections: () => ReturnType<typeof prepareCrudFormSectionRegistries>
@@ -321,7 +323,7 @@ function scanDashboardWidgetEntries(options: {
321
323
  const importPath = sanitizeGeneratedModuleSpecifier(
322
324
  `${fromApp ? appImportBase : pkgImportBase}/widgets/dashboard/${[...segs, base].join('/')}`
323
325
  )
324
- const key = [modId, ...segs, base].filter(Boolean).join(':')
326
+ const key = resolveDashboardWidgetKey(modId, roots, { relPath, fromApp })
325
327
  const source = fromApp ? 'app' : 'package'
326
328
  return { moduleId: modId, key, source, importPath }
327
329
  })
@@ -601,12 +603,15 @@ function findExportedMetadataSource(parsed: ts.SourceFile): ExportedMetadataSour
601
603
  }
602
604
 
603
605
  /**
604
- * Reads `metadata.requires` from a module `index` source purely syntactically — the file is parsed,
606
+ * Reads a module dependency declaration from its `index` source; the file is parsed,
605
607
  * never executed, so packaged TypeScript sources and module side effects are both safe. Only the
606
608
  * exported `metadata` object is consulted, and only string-literal entries are accepted: anything
607
609
  * computed is reported as unresolvable instead of being guessed.
608
610
  */
609
- export function extractModuleRequiresFromSource(sourceFile: string): ModuleRequiresExtraction {
611
+ export function extractModuleRequiresFromSource(
612
+ sourceFile: string,
613
+ propertyName: 'requires' | 'optionalRequires' = 'requires',
614
+ ): ModuleRequiresExtraction {
610
615
  let source = ''
611
616
  try {
612
617
  source = fs.readFileSync(sourceFile, 'utf8')
@@ -647,9 +652,9 @@ export function extractModuleRequiresFromSource(sourceFile: string): ModuleRequi
647
652
  return { status: 'unresolvable', reason: 'exported metadata uses a computed key' }
648
653
  }
649
654
  const key = ts.isIdentifier(name) || ts.isStringLiteral(name) ? name.text : null
650
- if (key !== 'requires') continue
655
+ if (key !== propertyName) continue
651
656
  if (!ts.isPropertyAssignment(property)) {
652
- return { status: 'unresolvable', reason: 'metadata.requires is not a property assignment' }
657
+ return { status: 'unresolvable', reason: `metadata.${propertyName} is not a property assignment` }
653
658
  }
654
659
  requiresInitializer = property.initializer
655
660
  }
@@ -657,14 +662,14 @@ export function extractModuleRequiresFromSource(sourceFile: string): ModuleRequi
657
662
 
658
663
  const requiresArray = unwrapExpression(requiresInitializer)
659
664
  if (!ts.isArrayLiteralExpression(requiresArray)) {
660
- return { status: 'unresolvable', reason: 'metadata.requires is not an array literal' }
665
+ return { status: 'unresolvable', reason: `metadata.${propertyName} is not an array literal` }
661
666
  }
662
667
 
663
668
  const requires: string[] = []
664
669
  for (const element of requiresArray.elements) {
665
670
  const value = unwrapExpression(element)
666
671
  if (!ts.isStringLiteral(value) && !ts.isNoSubstitutionTemplateLiteral(value)) {
667
- return { status: 'unresolvable', reason: 'metadata.requires contains a non-literal entry' }
672
+ return { status: 'unresolvable', reason: `metadata.${propertyName} contains a non-literal entry` }
668
673
  }
669
674
  requires.push(value.text)
670
675
  }
@@ -2226,6 +2231,7 @@ async function createModuleRegistryDiscovery(
2226
2231
  return {
2227
2232
  enabled,
2228
2233
  modules,
2234
+ hasUpgradeActionsModule: enabled.some((entry) => entry.id === 'upgrade_actions'),
2229
2235
  identities,
2230
2236
  getStructureChecksum: () => structureChecksum ??= calculateStructureChecksum(Array.from(trackedRoots)),
2231
2237
  getCrudFormSections,
@@ -3713,6 +3719,27 @@ function resolveConventionFile(
3713
3719
  return { importName, importPath, fromApp: resolved.fromApp }
3714
3720
  }
3715
3721
 
3722
+ function resolveUpgradeActionsFile(
3723
+ resolved: ResolvedFile | null,
3724
+ modId: string,
3725
+ importTargets: string[][],
3726
+ ): string | null {
3727
+ if (!resolved) return null
3728
+ const importName = `UPGRADES_${toVar(modId)}`
3729
+ const statement = buildImportStatement(`* as ${importName}`, sanitizeGeneratedModuleSpecifier(resolved.importPath))
3730
+ for (const target of importTargets) target.push(statement)
3731
+ return importName
3732
+ }
3733
+
3734
+ function buildUpgradeActionsValue(importName: string): WriterFunction {
3735
+ return namespaceFallback({
3736
+ importName,
3737
+ members: ['default', 'upgradeActions'],
3738
+ fallback: emptyArray(),
3739
+ castType: "import('@open-mercato/shared/modules/upgrade-actions').UpgradeActionDefinition[]",
3740
+ })
3741
+ }
3742
+
3716
3743
  type ModuleRegistryRenderOptions = ModuleRegistryOptions & {
3717
3744
  discovery: ModuleRegistryDiscovery
3718
3745
  skipCommands?: boolean
@@ -3970,6 +3997,10 @@ async function generateModuleRegistryFromDiscovery(options: ModuleRegistryRender
3970
3997
  if (encryption) encryptionImportName = encryption.importName
3971
3998
  }
3972
3999
 
4000
+ const upgradeActionsImportName = discovery.hasUpgradeActionsModule
4001
+ ? resolveUpgradeActionsFile(discovered.resolve('upgrades.ts'), modId, [imports, runtimeImports])
4002
+ : null
4003
+
3973
4004
  // 11b. Integration manifest: integration.ts
3974
4005
  {
3975
4006
  const resolved = discovered.resolve('integration.ts')
@@ -4187,6 +4218,9 @@ async function generateModuleRegistryFromDiscovery(options: ModuleRegistryRender
4187
4218
  }),
4188
4219
  })
4189
4220
  }
4221
+ if (upgradeActionsImportName) {
4222
+ setupAndBeyondEntries.push({ name: 'upgradeActions', value: buildUpgradeActionsValue(upgradeActionsImportName) })
4223
+ }
4190
4224
  if (integrationExports) {
4191
4225
  setupAndBeyondEntries.push({
4192
4226
  name: 'integrations',
@@ -4581,6 +4615,10 @@ async function generateModuleRegistryAppFromDiscovery(options: ModuleRegistryRen
4581
4615
  if (encryption) encryptionImportName = encryption.importName
4582
4616
  }
4583
4617
 
4618
+ const upgradeActionsImportName = discovery.hasUpgradeActionsModule
4619
+ ? resolveUpgradeActionsFile(discovered.resolve('upgrades.ts'), modId, [imports, bootstrapImports])
4620
+ : null
4621
+
4584
4622
  {
4585
4623
  const resolved = discovered.resolve('integration.ts')
4586
4624
  if (resolved) {
@@ -4788,6 +4826,9 @@ async function generateModuleRegistryAppFromDiscovery(options: ModuleRegistryRen
4788
4826
  }),
4789
4827
  })
4790
4828
  }
4829
+ if (upgradeActionsImportName) {
4830
+ moduleEntries.push({ name: 'upgradeActions', value: buildUpgradeActionsValue(upgradeActionsImportName) })
4831
+ }
4791
4832
  if (integrationImportName) {
4792
4833
  moduleEntries.push({
4793
4834
  name: 'integrations',
@@ -4978,6 +5019,10 @@ async function generateModuleRegistryCliFromDiscovery(options: ModuleRegistryRen
4978
5019
  if (encryption) encryptionImportName = encryption.importName
4979
5020
  }
4980
5021
 
5022
+ const upgradeActionsImportName = discovery.hasUpgradeActionsModule
5023
+ ? resolveUpgradeActionsFile(discovered.resolve('upgrades.ts'), modId, [imports])
5024
+ : null
5025
+
4981
5026
  // Integration manifest: integration.ts
4982
5027
  {
4983
5028
  const resolved = discovered.resolve('integration.ts')
@@ -5163,6 +5208,9 @@ async function generateModuleRegistryCliFromDiscovery(options: ModuleRegistryRen
5163
5208
  }),
5164
5209
  })
5165
5210
  }
5211
+ if (upgradeActionsImportName) {
5212
+ moduleEntries.push({ name: 'upgradeActions', value: buildUpgradeActionsValue(upgradeActionsImportName) })
5213
+ }
5166
5214
  if (integrationImportName) {
5167
5215
  moduleEntries.push({
5168
5216
  name: 'integrations',