@bleedingdev/modern-js-ultramodern-create 3.9.0-ultramodern.12 → 3.9.0-ultramodern.13

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 (201) hide show
  1. package/README.md +32 -36
  2. package/dist/cjs/ultramodern-release-cohort.cjs +6 -21
  3. package/dist/cjs/ultramodern-tooling/commands/context.cjs +2 -1
  4. package/dist/cjs/ultramodern-tooling/commands/validate.cjs +2 -57
  5. package/dist/cjs/ultramodern-tooling/commands.cjs +11 -1
  6. package/dist/cjs/ultramodern-tooling/config/index.cjs +11 -4
  7. package/dist/cjs/ultramodern-tooling/config/load.cjs +4 -17
  8. package/dist/cjs/ultramodern-tooling/config/metadata.cjs +41 -2
  9. package/dist/cjs/ultramodern-tooling/config/normalize.cjs +121 -208
  10. package/dist/cjs/ultramodern-workspace/add-shell.cjs +51 -18
  11. package/dist/cjs/ultramodern-workspace/add-vertical/execute.cjs +40 -39
  12. package/dist/cjs/ultramodern-workspace/add-vertical/plan.cjs +1 -1
  13. package/dist/cjs/ultramodern-workspace/add-vertical/preflight.cjs +2 -8
  14. package/dist/cjs/ultramodern-workspace/add-vertical/topology.cjs +0 -32
  15. package/dist/cjs/ultramodern-workspace/add-vertical/workspace-state.cjs +3 -10
  16. package/dist/cjs/ultramodern-workspace/api/contracts.cjs +2 -2
  17. package/dist/cjs/ultramodern-workspace/api/rpc.cjs +16 -14
  18. package/dist/cjs/ultramodern-workspace/api/service.cjs +4 -8
  19. package/dist/cjs/ultramodern-workspace/api/shared.cjs +1 -1
  20. package/dist/cjs/ultramodern-workspace/backend-federation.cjs +3 -3
  21. package/dist/cjs/ultramodern-workspace/contracts.cjs +14 -183
  22. package/dist/cjs/ultramodern-workspace/delivery-unit-stamp.cjs +10 -5
  23. package/dist/cjs/ultramodern-workspace/delivery-unit-sync.cjs +27 -17
  24. package/dist/cjs/ultramodern-workspace/delivery-unit.cjs +11 -6
  25. package/dist/cjs/ultramodern-workspace/descriptors.cjs +0 -4
  26. package/dist/cjs/ultramodern-workspace/generation-result.cjs +1 -1
  27. package/dist/cjs/ultramodern-workspace/index.cjs +2 -5
  28. package/dist/cjs/ultramodern-workspace/mf-validation/constants.cjs +0 -6
  29. package/dist/cjs/ultramodern-workspace/mf-validation/discovery.cjs +6 -6
  30. package/dist/cjs/ultramodern-workspace/mf-validation/path-utils.cjs +37 -38
  31. package/dist/cjs/ultramodern-workspace/module-federation/config.cjs +8 -15
  32. package/dist/cjs/ultramodern-workspace/package-json.cjs +47 -54
  33. package/dist/cjs/ultramodern-workspace/patch-inventory.cjs +27 -36
  34. package/dist/cjs/ultramodern-workspace/policy.cjs +6 -354
  35. package/dist/cjs/ultramodern-workspace/public-surface.cjs +2 -2
  36. package/dist/cjs/ultramodern-workspace/routes.cjs +11 -7
  37. package/dist/cjs/ultramodern-workspace/shells.cjs +0 -70
  38. package/dist/cjs/ultramodern-workspace/tooling-command-catalog.cjs +6 -43
  39. package/dist/cjs/ultramodern-workspace/tsconfigs.cjs +3 -1
  40. package/dist/cjs/ultramodern-workspace/validation/architecture.cjs +5 -5
  41. package/dist/cjs/ultramodern-workspace/validation/workspace.cjs +275 -1249
  42. package/dist/cjs/ultramodern-workspace/versions.cjs +25 -41
  43. package/dist/cjs/ultramodern-workspace/workspace-artifact-ownership.cjs +1 -6
  44. package/dist/cjs/ultramodern-workspace/workspace-script-plan.cjs +7 -7
  45. package/dist/cjs/ultramodern-workspace/workspace-scripts.cjs +17 -112
  46. package/dist/cjs/ultramodern-workspace/workspace-validation-contract.cjs +62 -371
  47. package/dist/cjs/ultramodern-workspace/write-app.cjs +5 -4
  48. package/dist/cjs/ultramodern-workspace/write-workspace.cjs +10 -50
  49. package/dist/esm/ultramodern-release-cohort.js +5 -14
  50. package/dist/esm/ultramodern-tooling/commands/context.js +2 -1
  51. package/dist/esm/ultramodern-tooling/commands/validate.js +3 -48
  52. package/dist/esm/ultramodern-tooling/commands.js +10 -1
  53. package/dist/esm/ultramodern-tooling/config/index.js +1 -0
  54. package/dist/esm/ultramodern-tooling/config/load.js +5 -17
  55. package/dist/esm/ultramodern-tooling/config/metadata.js +36 -1
  56. package/dist/esm/ultramodern-tooling/config/normalize.js +125 -201
  57. package/dist/esm/ultramodern-workspace/add-shell.js +55 -22
  58. package/dist/esm/ultramodern-workspace/add-vertical/execute.js +41 -41
  59. package/dist/esm/ultramodern-workspace/add-vertical/plan.js +2 -2
  60. package/dist/esm/ultramodern-workspace/add-vertical/preflight.js +3 -6
  61. package/dist/esm/ultramodern-workspace/add-vertical/topology.js +1 -30
  62. package/dist/esm/ultramodern-workspace/add-vertical/workspace-state.js +3 -10
  63. package/dist/esm/ultramodern-workspace/api/contracts.js +2 -2
  64. package/dist/esm/ultramodern-workspace/api/rpc.js +16 -14
  65. package/dist/esm/ultramodern-workspace/api/service.js +4 -8
  66. package/dist/esm/ultramodern-workspace/api/shared.js +1 -1
  67. package/dist/esm/ultramodern-workspace/backend-federation.js +3 -3
  68. package/dist/esm/ultramodern-workspace/contracts.js +14 -180
  69. package/dist/esm/ultramodern-workspace/delivery-unit-stamp.js +10 -5
  70. package/dist/esm/ultramodern-workspace/delivery-unit-sync.js +28 -18
  71. package/dist/esm/ultramodern-workspace/delivery-unit.js +11 -6
  72. package/dist/esm/ultramodern-workspace/descriptors.js +1 -2
  73. package/dist/esm/ultramodern-workspace/generation-result.js +2 -2
  74. package/dist/esm/ultramodern-workspace/index.js +1 -1
  75. package/dist/esm/ultramodern-workspace/mf-validation/constants.js +1 -4
  76. package/dist/esm/ultramodern-workspace/mf-validation/discovery.js +7 -7
  77. package/dist/esm/ultramodern-workspace/mf-validation/path-utils.js +36 -34
  78. package/dist/esm/ultramodern-workspace/module-federation/config.js +9 -16
  79. package/dist/esm/ultramodern-workspace/package-json.js +48 -55
  80. package/dist/esm/ultramodern-workspace/patch-inventory.js +27 -36
  81. package/dist/esm/ultramodern-workspace/policy.js +6 -335
  82. package/dist/esm/ultramodern-workspace/public-surface.js +2 -2
  83. package/dist/esm/ultramodern-workspace/routes.js +11 -7
  84. package/dist/esm/ultramodern-workspace/shells.js +3 -67
  85. package/dist/esm/ultramodern-workspace/tooling-command-catalog.js +7 -41
  86. package/dist/esm/ultramodern-workspace/tsconfigs.js +4 -2
  87. package/dist/esm/ultramodern-workspace/validation/architecture.js +5 -5
  88. package/dist/esm/ultramodern-workspace/validation/workspace.js +267 -1250
  89. package/dist/esm/ultramodern-workspace/versions.js +24 -28
  90. package/dist/esm/ultramodern-workspace/workspace-artifact-ownership.js +3 -8
  91. package/dist/esm/ultramodern-workspace/workspace-script-plan.js +7 -7
  92. package/dist/esm/ultramodern-workspace/workspace-scripts.js +18 -107
  93. package/dist/esm/ultramodern-workspace/workspace-validation-contract.js +64 -373
  94. package/dist/esm/ultramodern-workspace/write-app.js +4 -3
  95. package/dist/esm/ultramodern-workspace/write-workspace.js +16 -53
  96. package/dist/esm-node/ultramodern-release-cohort.js +5 -14
  97. package/dist/esm-node/ultramodern-tooling/commands/context.js +2 -1
  98. package/dist/esm-node/ultramodern-tooling/commands/validate.js +3 -48
  99. package/dist/esm-node/ultramodern-tooling/commands.js +10 -1
  100. package/dist/esm-node/ultramodern-tooling/config/index.js +1 -0
  101. package/dist/esm-node/ultramodern-tooling/config/load.js +5 -17
  102. package/dist/esm-node/ultramodern-tooling/config/metadata.js +36 -1
  103. package/dist/esm-node/ultramodern-tooling/config/normalize.js +125 -201
  104. package/dist/esm-node/ultramodern-workspace/add-shell.js +55 -22
  105. package/dist/esm-node/ultramodern-workspace/add-vertical/execute.js +41 -41
  106. package/dist/esm-node/ultramodern-workspace/add-vertical/plan.js +2 -2
  107. package/dist/esm-node/ultramodern-workspace/add-vertical/preflight.js +3 -6
  108. package/dist/esm-node/ultramodern-workspace/add-vertical/topology.js +1 -30
  109. package/dist/esm-node/ultramodern-workspace/add-vertical/workspace-state.js +3 -10
  110. package/dist/esm-node/ultramodern-workspace/api/contracts.js +2 -2
  111. package/dist/esm-node/ultramodern-workspace/api/rpc.js +16 -14
  112. package/dist/esm-node/ultramodern-workspace/api/service.js +4 -8
  113. package/dist/esm-node/ultramodern-workspace/api/shared.js +1 -1
  114. package/dist/esm-node/ultramodern-workspace/backend-federation.js +3 -3
  115. package/dist/esm-node/ultramodern-workspace/contracts.js +14 -180
  116. package/dist/esm-node/ultramodern-workspace/delivery-unit-stamp.js +10 -5
  117. package/dist/esm-node/ultramodern-workspace/delivery-unit-sync.js +28 -18
  118. package/dist/esm-node/ultramodern-workspace/delivery-unit.js +11 -6
  119. package/dist/esm-node/ultramodern-workspace/descriptors.js +1 -2
  120. package/dist/esm-node/ultramodern-workspace/generation-result.js +2 -2
  121. package/dist/esm-node/ultramodern-workspace/index.js +1 -1
  122. package/dist/esm-node/ultramodern-workspace/mf-validation/constants.js +1 -4
  123. package/dist/esm-node/ultramodern-workspace/mf-validation/discovery.js +7 -7
  124. package/dist/esm-node/ultramodern-workspace/mf-validation/path-utils.js +36 -34
  125. package/dist/esm-node/ultramodern-workspace/module-federation/config.js +9 -16
  126. package/dist/esm-node/ultramodern-workspace/package-json.js +48 -55
  127. package/dist/esm-node/ultramodern-workspace/patch-inventory.js +27 -36
  128. package/dist/esm-node/ultramodern-workspace/policy.js +6 -335
  129. package/dist/esm-node/ultramodern-workspace/public-surface.js +2 -2
  130. package/dist/esm-node/ultramodern-workspace/routes.js +11 -7
  131. package/dist/esm-node/ultramodern-workspace/shells.js +3 -67
  132. package/dist/esm-node/ultramodern-workspace/tooling-command-catalog.js +7 -41
  133. package/dist/esm-node/ultramodern-workspace/tsconfigs.js +4 -2
  134. package/dist/esm-node/ultramodern-workspace/validation/architecture.js +5 -5
  135. package/dist/esm-node/ultramodern-workspace/validation/workspace.js +267 -1250
  136. package/dist/esm-node/ultramodern-workspace/versions.js +24 -28
  137. package/dist/esm-node/ultramodern-workspace/workspace-artifact-ownership.js +3 -8
  138. package/dist/esm-node/ultramodern-workspace/workspace-script-plan.js +7 -7
  139. package/dist/esm-node/ultramodern-workspace/workspace-scripts.js +18 -107
  140. package/dist/esm-node/ultramodern-workspace/workspace-validation-contract.js +64 -373
  141. package/dist/esm-node/ultramodern-workspace/write-app.js +4 -3
  142. package/dist/esm-node/ultramodern-workspace/write-workspace.js +16 -53
  143. package/dist/types/ultramodern-release-cohort.d.ts +1 -3
  144. package/dist/types/ultramodern-tooling/commands/validate.d.ts +2 -2
  145. package/dist/types/ultramodern-tooling/config/index.d.ts +1 -0
  146. package/dist/types/ultramodern-tooling/config/load.d.ts +6 -58
  147. package/dist/types/ultramodern-tooling/config/metadata.d.ts +3 -0
  148. package/dist/types/ultramodern-tooling/config/normalize.d.ts +9 -90
  149. package/dist/types/ultramodern-tooling/config/types.d.ts +1 -9
  150. package/dist/types/ultramodern-workspace/add-vertical/preflight.d.ts +3 -3
  151. package/dist/types/ultramodern-workspace/add-vertical/topology.d.ts +0 -1
  152. package/dist/types/ultramodern-workspace/add-vertical/workspace-state.d.ts +1 -1
  153. package/dist/types/ultramodern-workspace/api/rpc.d.ts +1 -1
  154. package/dist/types/ultramodern-workspace/contracts.d.ts +1 -3
  155. package/dist/types/ultramodern-workspace/delivery-unit-stamp.d.ts +2 -2
  156. package/dist/types/ultramodern-workspace/delivery-unit.d.ts +2 -2
  157. package/dist/types/ultramodern-workspace/descriptors.d.ts +0 -1
  158. package/dist/types/ultramodern-workspace/index.d.ts +1 -1
  159. package/dist/types/ultramodern-workspace/mf-validation/constants.d.ts +0 -1
  160. package/dist/types/ultramodern-workspace/mf-validation/path-utils.d.ts +2 -3
  161. package/dist/types/ultramodern-workspace/module-federation/config.d.ts +1 -1
  162. package/dist/types/ultramodern-workspace/patch-inventory.d.ts +2 -10
  163. package/dist/types/ultramodern-workspace/policy.d.ts +60 -182
  164. package/dist/types/ultramodern-workspace/shells.d.ts +1 -14
  165. package/dist/types/ultramodern-workspace/tooling-command-catalog.d.ts +1 -6
  166. package/dist/types/ultramodern-workspace/validation/types.d.ts +1 -12
  167. package/dist/types/ultramodern-workspace/validation/workspace.d.ts +5 -2
  168. package/dist/types/ultramodern-workspace/versions.d.ts +23 -27
  169. package/dist/types/ultramodern-workspace/workspace-script-plan.d.ts +1 -1
  170. package/dist/types/ultramodern-workspace/workspace-scripts.d.ts +7 -14
  171. package/dist/types/ultramodern-workspace/workspace-validation-contract.d.ts +22 -188
  172. package/dist/types/ultramodern-workspace/write-workspace.d.ts +1 -3
  173. package/package.json +17 -16
  174. package/{template-workspace/.modernjs/release-cohort.json → release-cohort.json} +48 -48
  175. package/template-workspace/README.md.handlebars +9 -16
  176. package/template-workspace/pnpm-workspace.yaml.handlebars +0 -24
  177. package/templates/workspace/apps/modern.config.ts.handlebars +5 -5
  178. package/templates/workspace/apps/shared/src/routes/ultramodern-route-metadata.ts.handlebars +8 -21
  179. package/templates/workspace-scripts/generate-node-backend-federation.mjs +39 -49
  180. package/templates/workspace-scripts/generate-public-surface-assets.mjs +142 -206
  181. package/templates/workspace-scripts/materialize-zerops-runtime.mjs +3 -11
  182. package/templates/workspace-scripts/proof-cloudflare-version.mjs +53 -444
  183. package/templates/workspace-scripts/proof-node-backend-federation.mjs +193 -39
  184. package/templates/workspace-scripts/proof-workerd-ssr.mjs +126 -66
  185. package/templates/workspace-scripts/ultramodern-performance-readiness.mjs +45 -147
  186. package/dist/cjs/ultramodern-workspace/cohort-parity.cjs +0 -129
  187. package/dist/cjs/ultramodern-workspace/patch-parity.cjs +0 -163
  188. package/dist/esm/ultramodern-workspace/cohort-parity.js +0 -74
  189. package/dist/esm/ultramodern-workspace/patch-parity.js +0 -99
  190. package/dist/esm-node/ultramodern-workspace/cohort-parity.js +0 -75
  191. package/dist/esm-node/ultramodern-workspace/patch-parity.js +0 -100
  192. package/dist/types/ultramodern-workspace/cohort-parity.d.ts +0 -31
  193. package/dist/types/ultramodern-workspace/patch-parity.d.ts +0 -39
  194. package/template-workspace/patches/@module-federation__bridge-react@2.9.0.patch +0 -47
  195. package/template-workspace/patches/@module-federation__dts-plugin@2.9.0.patch +0 -132
  196. package/template-workspace/patches/@module-federation__modern-js-v3@2.9.0.patch +0 -287
  197. package/template-workspace/patches/@module-federation__runtime-core@2.9.0.patch +0 -13
  198. package/template-workspace/patches/drizzle-orm-ts7-strict-declarations.patch +0 -471
  199. package/template-workspace/patches/msgpackr@2.1.0.patch +0 -30
  200. package/template-workspace/patches/zod@4.5.4.patch +0 -56
  201. package/templates/packages/effect-bff-runtime.ts +0 -2
@@ -2,155 +2,59 @@
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { fileURLToPath, pathToFileURL } from 'node:url';
5
+ import { format } from 'oxfmt';
6
+ import { tsImport } from 'tsx/esm/api';
7
+ import ultracite from 'ultracite/oxfmt';
5
8
 
6
9
  const workspaceRoot = path.resolve(
7
10
  process.env.ULTRAMODERN_WORKSPACE_ROOT ??
8
11
  path.join(path.dirname(fileURLToPath(import.meta.url)), '..'),
9
12
  );
10
- const compactConfigPath = path.join(workspaceRoot, '.modernjs/ultramodern.json');
13
+ const topologyPath = path.join(workspaceRoot, 'topology/reference-topology.json');
11
14
 
12
15
  function readJson(filePath) {
13
16
  return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
14
17
  }
15
18
 
16
- function toKebabCase(value) {
17
- return String(value)
18
- .trim()
19
- .replace(/([a-z0-9])([A-Z])/gu, '$1-$2')
20
- .replace(/[^a-zA-Z0-9._-]+/gu, '-')
21
- .replace(/[._]+/gu, '-')
22
- .toLowerCase()
23
- .replace(/-+/gu, '-')
24
- .replace(/^-+|-+$/gu, '');
25
- }
26
-
27
- function toEnvSegment(value) {
28
- return toKebabCase(value).replace(/-/gu, '_').toUpperCase();
29
- }
30
-
31
- function normalizeRelativePath(value) {
32
- return String(value ?? '').replace(/\\/gu, '/').replace(/^\.\/+/u, '');
33
- }
34
-
35
- function appNamespace(app) {
36
- return app.kind === 'shell' ? 'shell' : (app.domain ?? app.id);
37
- }
38
-
39
- function defaultPortEnv(app) {
40
- return app.kind === 'shell'
41
- ? 'SHELL_SUPER_APP_PORT'
42
- : `VERTICAL_${toEnvSegment(app.domain ?? app.id)}_PORT`;
43
- }
44
-
45
- function defaultPort(app) {
46
- return app.kind === 'shell' ? 3020 : 3030;
47
- }
48
-
49
- function normalizeCompactApp(rawApp) {
50
- const id = String(rawApp.id);
51
- const kind = rawApp.kind === 'vertical' ? 'vertical' : 'shell';
52
- const appPath =
53
- typeof rawApp.path === 'string'
54
- ? normalizeRelativePath(rawApp.path)
55
- : kind === 'shell'
56
- ? 'apps/shell-super-app'
57
- : `verticals/${toKebabCase(id)}`;
58
- const packageSuffix =
59
- typeof rawApp.packageSuffix === 'string'
60
- ? rawApp.packageSuffix
61
- : appPath.split('/').at(-1) ?? id;
62
- const domain =
63
- typeof rawApp.domain === 'string'
64
- ? rawApp.domain
65
- : kind === 'vertical'
66
- ? packageSuffix
67
- : undefined;
68
- const moduleFederation =
69
- rawApp.moduleFederation && typeof rawApp.moduleFederation === 'object'
70
- ? rawApp.moduleFederation
71
- : {};
72
-
73
- return {
74
- id,
75
- kind,
76
- path: appPath,
77
- packageSuffix,
78
- domain,
79
- port:
80
- typeof rawApp.port === 'number'
81
- ? rawApp.port
82
- : defaultPort({ id, kind, domain }),
83
- portEnv:
84
- typeof rawApp.portEnv === 'string'
85
- ? rawApp.portEnv
86
- : defaultPortEnv({ id, kind, domain }),
87
- mfName:
88
- typeof moduleFederation.name === 'string'
89
- ? moduleFederation.name
90
- : kind === 'shell'
91
- ? 'shellSuperApp'
92
- : `vertical${toKebabCase(domain ?? id)
93
- .split('-')
94
- .filter(Boolean)
95
- .map(part => part.charAt(0).toUpperCase() + part.slice(1))
96
- .join('')}`,
97
- exposes: Array.isArray(moduleFederation.exposes)
98
- ? moduleFederation.exposes.filter(expose => typeof expose === 'string')
99
- : [],
100
- verticalRefs: Array.isArray(moduleFederation.verticalRefs)
101
- ? moduleFederation.verticalRefs.filter(ref => typeof ref === 'string')
102
- : [],
103
- marker: {
104
- appId: id,
105
- },
106
- routes:
107
- rawApp.routes && typeof rawApp.routes === 'object'
108
- ? rawApp.routes
109
- : undefined,
110
- api:
111
- rawApp.api && typeof rawApp.api === 'object'
112
- ? {
113
- stem:
114
- typeof rawApp.api.stem === 'string'
115
- ? rawApp.api.stem
116
- : domain ?? id,
117
- prefix:
118
- typeof rawApp.api.prefix === 'string'
119
- ? rawApp.api.prefix
120
- : `/${domain ?? id}-api`,
121
- }
122
- : undefined,
123
- };
124
- }
125
-
126
- function createRouteOwnedEntries(app) {
127
- const namespace = appNamespace(app);
128
- const base = {
129
- descriptionKey: `${namespace}.seo.description`,
130
- mfBoundaryId: app.mfName,
131
- namespace,
132
- ownerAppId: app.id,
133
- public: false,
134
- indexable: false,
135
- publicSurface: 'private-app-screen',
136
- };
137
-
138
- return [
139
- {
140
- ...base,
141
- canonicalPath: '/',
142
- id: app.kind === 'shell' ? 'shell-home' : `${app.id}-home`,
143
- localisedPaths: {
144
- cs: '/',
145
- en: '/',
146
- },
147
- titleKey: app.kind === 'shell' ? 'shell.title' : `${namespace}.title`,
148
- },
149
- ];
19
+ async function readRouteOwnedEntries(app) {
20
+ const appRoot = fs.realpathSync(path.join(workspaceRoot, app.path));
21
+ const workspaceReal = fs.realpathSync(workspaceRoot);
22
+ const relativeAppPath = path.relative(workspaceReal, appRoot);
23
+ if (!relativeAppPath || relativeAppPath === '..' ||
24
+ relativeAppPath.startsWith(`..${path.sep}`) || path.isAbsolute(relativeAppPath))
25
+ throw new Error(`${app.id} topology path escapes the workspace`);
26
+ const routesRoot = path.join(appRoot, 'src/routes');
27
+ if (!fs.existsSync(routesRoot)) {
28
+ if (app.surfaceProfile === 'api-only') return [];
29
+ throw new Error(`${app.id} is missing its route-owned metadata directory`);
30
+ }
31
+ const files = [];
32
+ function visit(directory) {
33
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
34
+ const file = path.join(directory, entry.name);
35
+ if (entry.isSymbolicLink()) throw new Error(`${app.id} route metadata may not be a symbolic link`);
36
+ if (entry.isDirectory()) visit(file);
37
+ else if (entry.name === 'route.meta.ts') files.push(file);
38
+ }
39
+ }
40
+ visit(routesRoot);
41
+ const routes = [];
42
+ for (const file of files.sort()) {
43
+ const module = await tsImport(pathToFileURL(file).href, { parentURL: import.meta.url, tsconfig: false });
44
+ const namedRoute = module.routeMeta ?? module.default?.routeMeta;
45
+ const route = namedRoute ?? module.default?.default ?? module.default;
46
+ if (!route || typeof route !== 'object' || route.ownerAppId !== app.id ||
47
+ typeof route.id !== 'string' || typeof route.canonicalPath !== 'string' ||
48
+ !route.localisedPaths || typeof route.localisedPaths.en !== 'string' ||
49
+ typeof route.localisedPaths.cs !== 'string')
50
+ throw new Error(`${app.id} has invalid route-owned metadata in ${file}`);
51
+ routes.push({ file, route, exportName: namedRoute ? 'routeMeta' : 'default' });
52
+ }
53
+ return routes;
150
54
  }
151
55
 
152
- function createPublicRoutes(app) {
153
- return createRouteOwnedEntries(app)
56
+ function createPublicRoutes(routes) {
57
+ return routes
154
58
  .filter(route => route.public && route.indexable)
155
59
  .map(route => ({
156
60
  canonicalPath: route.canonicalPath,
@@ -163,15 +67,24 @@ function createPublicRoutes(app) {
163
67
  }));
164
68
  }
165
69
 
166
- function createPublicSurface(app) {
167
- const publicRoutes = createPublicRoutes(app);
70
+ function createPublicSurface(app, routes) {
71
+ const publicRoutes = createPublicRoutes(routes);
72
+ const routeEntries = publicRoutes.filter(route =>
73
+ Object.values(route.localisedPaths).every(routePath =>
74
+ !/(?:^|\/):[^/]+|\[[^\]]+\]|\*/u.test(routePath),
75
+ ),
76
+ ).map(route => ({ ...route,
77
+ canonicalUrlPath: createLocalisedPublicPath(route.localisedPaths.en, 'en'),
78
+ localeUrlPaths: Object.fromEntries(['en', 'cs'].map(language =>
79
+ [language, createLocalisedPublicPath(route.localisedPaths[language], language)])),
80
+ }));
168
81
  const basePublicSurface = {
169
82
  authoring: 'colocated-route-meta',
170
83
  artifactLifecycle: 'build-and-deploy-output',
171
84
  generatedManifest: './src/routes/ultramodern-route-metadata',
172
85
  source: 'route-owned-public-routes',
173
86
  metadataExport: './src/routes/ultramodern-route-metadata',
174
- generator: 'scripts/generate-public-surface-assets.mts',
87
+ generator: 'ultramodern-create ultramodern public-surface',
175
88
  outputRoot: 'dist/public',
176
89
  cloudflareBuildOutputRoot: 'dist-cloudflare/public',
177
90
  privateRoutePolicy: 'omit-from-generated-public-surface',
@@ -192,8 +105,8 @@ function createPublicSurface(app) {
192
105
  },
193
106
  contentSources: [],
194
107
  publicRoutes,
195
- routeEntries: [],
196
- concreteUrlPaths: [],
108
+ routeEntries,
109
+ concreteUrlPaths: uniqueSorted(routeEntries.flatMap(route => Object.values(route.localeUrlPaths))),
197
110
  };
198
111
 
199
112
  return app.routes?.publicSurface &&
@@ -205,59 +118,41 @@ function createPublicSurface(app) {
205
118
  : basePublicSurface;
206
119
  }
207
120
 
208
- function createCloudflareDeploy(config, app) {
209
- const packageScope =
210
- typeof config.workspace?.packageScope === 'string'
211
- ? config.workspace.packageScope
212
- : path.basename(workspaceRoot);
213
- const compatibilityDate =
214
- typeof config.deploy?.worker?.compatibilityDate === 'string'
215
- ? config.deploy.worker.compatibilityDate
216
- : '2026-06-02';
217
- return {
218
- workerName: `${toKebabCase(packageScope)}-${app.packageSuffix}`.slice(0, 63),
219
- publicUrlEnv: `ULTRAMODERN_PUBLIC_URL_${toEnvSegment(app.id)}`,
220
- compatibilityDate,
221
- compatibilityFlags: ['nodejs_compat', 'global_fetch_strictly_public'],
222
- };
223
- }
224
-
225
- function synthesizeContractFromCompactConfig(config) {
226
- const apps = Array.isArray(config.topology?.apps)
227
- ? config.topology.apps.map(normalizeCompactApp)
228
- : [];
229
-
121
+ export async function readGeneratedContractView() {
122
+ const topology = readJson(topologyPath);
123
+ if (topology.schemaVersion !== 1 || !topology.shell || !Array.isArray(topology.verticals)) {
124
+ throw new Error('Invalid topology/reference-topology.json');
125
+ }
126
+ const apps = [topology.shell, ...topology.verticals, ...(topology.shells ?? [])];
230
127
  return {
231
- sourcePath: compactConfigPath,
232
- apps: apps.map(app => ({
233
- ...app,
234
- deploy: {
235
- cloudflare: createCloudflareDeploy(config, app),
236
- },
237
- routes: {
238
- publicSurface: createPublicSurface(app),
239
- },
128
+ sourcePath: topologyPath,
129
+ apps: await Promise.all(apps.map(async app => {
130
+ if (typeof app.path !== 'string' || !app.path) {
131
+ throw new Error(`${app.id} topology path is missing`);
132
+ }
133
+ const routeModules = await readRouteOwnedEntries(app);
134
+ return {
135
+ id: app.id,
136
+ kind: app.kind,
137
+ surfaceProfile: app.surfaceProfile,
138
+ path: app.path,
139
+ domain: app.domain,
140
+ mfName: app.moduleFederation?.name,
141
+ marker: { appId: app.id },
142
+ deploy: { cloudflare: app.cloudflare },
143
+ routes: { publicSurface: createPublicSurface(app, routeModules.map(entry => entry.route)) },
144
+ routeModules,
145
+ };
240
146
  })),
241
147
  };
242
148
  }
243
149
 
244
- function readGeneratedContractView() {
245
- if (fs.existsSync(compactConfigPath)) {
246
- return synthesizeContractFromCompactConfig(readJson(compactConfigPath));
247
- }
248
- throw new Error(
249
- `Missing UltraModern config. Expected ${path.relative(
250
- workspaceRoot,
251
- compactConfigPath,
252
- )}.`,
253
- );
254
- }
255
-
256
150
  function parseArgs(argv) {
257
151
  const parsed = {
258
152
  appId: undefined,
259
153
  target: 'dist',
260
154
  requirePublicOrigin: false,
155
+ syncRouteMetadata: false,
261
156
  };
262
157
 
263
158
  for (let index = 0; index < argv.length; index += 1) {
@@ -270,6 +165,8 @@ function parseArgs(argv) {
270
165
  index += 1;
271
166
  } else if (arg === '--require-public-origin') {
272
167
  parsed.requirePublicOrigin = true;
168
+ } else if (arg === '--sync-route-metadata') {
169
+ parsed.syncRouteMetadata = true;
273
170
  } else if (arg === '--help' || arg === '-h') {
274
171
  parsed.help = true;
275
172
  } else {
@@ -289,7 +186,7 @@ function parseArgs(argv) {
289
186
 
290
187
  function printHelp() {
291
188
  process.stdout.write(`Usage:
292
- node scripts/generate-public-surface-assets.mts --app shell-super-app [--target dist|cloudflare-dist] [--require-public-origin]
189
+ ultramodern-create ultramodern public-surface --app shell-super-app [--target dist|cloudflare-dist] [--require-public-origin|--sync-route-metadata]
293
190
 
294
191
  Set each app's production URL using the contract env key, for example:
295
192
  ULTRAMODERN_PUBLIC_URL_SHELL_SUPER_APP=https://example.com
@@ -714,19 +611,55 @@ function writeText(outputDir, fileName, content) {
714
611
  fs.writeFileSync(path.join(outputDir, fileName), content);
715
612
  }
716
613
 
717
- async function generatePublicSurfaceAssets(app, target, requirePublicOrigin) {
614
+ async function syncRouteMetadata(app) {
615
+ if (app.surfaceProfile === 'api-only') return;
616
+ const file = path.join(fs.realpathSync(path.join(workspaceRoot, app.path)),
617
+ 'src/routes/ultramodern-route-metadata.ts');
618
+ const imports = app.routeModules.map(({ file: routeFile, exportName }, index) => {
619
+ const relative = path.relative(path.dirname(file), routeFile).replaceAll(path.sep, '/').replace(/\.ts$/u, '');
620
+ const specifier = JSON.stringify(relative.startsWith('.') ? relative : `./${relative}`);
621
+ return exportName === 'routeMeta'
622
+ ? `import { routeMeta as route${index} } from ${specifier};`
623
+ : `import route${index} from ${specifier};`;
624
+ });
625
+ const namespace = app.kind === 'shell' ? 'shell' : (app.domain ?? app.id);
626
+ const content = `// @generated by @modern-js/ultramodern-create from route-owned metadata.\n${imports.join('\n')}\n\nexport const ultramodernRouteNamespace = ${JSON.stringify(namespace)} as const;\nexport const ultramodernRouteMetadata = [${app.routeModules.map((_, index) => `route${index}`).join(', ')}] as const;\nexport const ultramodernLocalisedUrls = Object.fromEntries(ultramodernRouteMetadata.filter(route => route.canonicalPath !== '/').map(route => [route.canonicalPath, route.localisedPaths]));\nexport const ultramodernPublicRoutes = ultramodernRouteMetadata.filter(route => route.public && route.indexable).map(route => ({ canonicalPath: route.canonicalPath, descriptionKey: route.descriptionKey, id: route.id, localisedPaths: route.localisedPaths, namespace: route.namespace, ownerAppId: route.ownerAppId, titleKey: route.titleKey, ...('jsonLd' in route ? { jsonLd: route.jsonLd } : {}) }));\nexport const ultramodernRouteConfig = { authoring: 'colocated-route-meta', generatedManifest: true, localisedUrls: ultramodernLocalisedUrls, namespace: ultramodernRouteNamespace, publicRoutes: ultramodernPublicRoutes, routes: ultramodernRouteMetadata, source: 'route-owned' } as const;\n`;
627
+ const formatted = await format(file, content, {
628
+ ...ultracite,
629
+ printWidth: 120,
630
+ singleQuote: true,
631
+ trailingComma: 'all',
632
+ });
633
+ if (formatted.errors.length > 0)
634
+ throw new Error(`${app.id} route metadata aggregate could not be formatted`);
635
+ if (!fs.existsSync(file) || fs.readFileSync(file, 'utf8') !== formatted.code)
636
+ fs.writeFileSync(file, formatted.code);
637
+ }
638
+
639
+ export async function resolvePublicSurface(app) {
718
640
  const publicSurface = app.routes?.publicSurface ?? {};
719
641
  const languages = publicSurface.languages ?? ['en', 'cs'];
720
- const outputDir = ensureOutputDir(app, target);
721
- const shouldRequirePublicOrigin =
722
- requirePublicOrigin ||
723
- process.env.ULTRAMODERN_CLOUDFLARE_REQUIRE_PUBLIC_URLS === 'true';
724
642
  const routeEntries = mergeRouteEntries(
725
643
  publicSurface.routeEntries ?? [],
726
644
  await expandContentSources(app, publicSurface, languages),
727
645
  languages,
728
646
  );
729
- const urlPaths = createConcreteUrlPaths(routeEntries, languages);
647
+ return {
648
+ ...publicSurface,
649
+ routeEntries,
650
+ concreteUrlPaths: createConcreteUrlPaths(routeEntries, languages),
651
+ };
652
+ }
653
+
654
+ async function generatePublicSurfaceAssets(app, target, requirePublicOrigin) {
655
+ const publicSurface = await resolvePublicSurface(app);
656
+ const languages = publicSurface.languages ?? ['en', 'cs'];
657
+ const outputDir = ensureOutputDir(app, target);
658
+ const shouldRequirePublicOrigin =
659
+ requirePublicOrigin ||
660
+ process.env.ULTRAMODERN_CLOUDFLARE_REQUIRE_PUBLIC_URLS === 'true';
661
+ const routeEntries = publicSurface.routeEntries;
662
+ const urlPaths = publicSurface.concreteUrlPaths;
730
663
 
731
664
  if (routeEntries.length === 0) {
732
665
  writeText(outputDir, 'robots.txt', renderRobotsTxt([], undefined));
@@ -748,19 +681,22 @@ async function generatePublicSurfaceAssets(app, target, requirePublicOrigin) {
748
681
  writeText(outputDir, 'robots.txt', renderRobotsTxt(urlPaths, `${origin}/sitemap.xml`));
749
682
  }
750
683
 
751
- try {
752
- const args = parseArgs(process.argv.slice(2));
753
- if (args.help) {
754
- printHelp();
755
- process.exit(0);
756
- }
757
- const contract = readGeneratedContractView();
758
- const app = contract.apps?.find(candidate => candidate.id === args.appId);
759
- if (!app) {
760
- throw new Error(`Unknown app in UltraModern config: ${args.appId}`);
684
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
685
+ try {
686
+ const args = parseArgs(process.argv.slice(2));
687
+ if (args.help) {
688
+ printHelp();
689
+ process.exit(0);
690
+ }
691
+ const contract = await readGeneratedContractView();
692
+ const app = contract.apps?.find(candidate => candidate.id === args.appId);
693
+ if (!app) {
694
+ throw new Error(`Unknown app in UltraModern config: ${args.appId}`);
695
+ }
696
+ if (args.syncRouteMetadata) await syncRouteMetadata(app);
697
+ else await generatePublicSurfaceAssets(app, args.target, args.requirePublicOrigin);
698
+ } catch (error) {
699
+ process.stderr.write(`[public-surface] ${error.message}\n`);
700
+ process.exitCode = 1;
761
701
  }
762
- await generatePublicSurfaceAssets(app, args.target, args.requirePublicOrigin);
763
- } catch (error) {
764
- process.stderr.write(`[public-surface] ${error.message}\n`);
765
- process.exitCode = 1;
766
702
  }
@@ -3,6 +3,7 @@ import fs from 'node:fs';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import execa from '@modern-js/utils/execa';
6
+ import { readWorkspacePackageSource } from '../../dist/esm-node/ultramodern-tooling/config/metadata.js';
6
7
 
7
8
  const workspaceRoot = path.resolve(
8
9
  process.env.ULTRAMODERN_WORKSPACE_ROOT ?? process.cwd(),
@@ -45,10 +46,6 @@ function readJson(filePath) {
45
46
  return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
46
47
  }
47
48
 
48
- function readOptionalJson(filePath) {
49
- return fs.existsSync(filePath) ? readJson(filePath) : undefined;
50
- }
51
-
52
49
  function writeJson(filePath, value) {
53
50
  fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, 'utf-8');
54
51
  }
@@ -221,13 +218,8 @@ console.log(
221
218
  );
222
219
 
223
220
  function normalizeRuntimePackageDependencies(packageJson) {
224
- const compactConfig = readOptionalJson(
225
- path.join(workspaceRoot, '.modernjs/ultramodern.json'),
226
- );
227
- const packageSource = compactConfig?.packageSource;
228
- const modernPackageVersion = packageSource?.modernPackageVersion;
229
- const aliasScope = packageSource?.aliasScope;
230
- const aliasPackageNamePrefix = packageSource?.aliasPackageNamePrefix;
221
+ const { modernPackageVersion, aliasScope, aliasPackageNamePrefix } =
222
+ readWorkspacePackageSource(workspaceRoot);
231
223
 
232
224
  if (!modernPackageVersion || !aliasScope || !aliasPackageNamePrefix) {
233
225
  return;