@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.4 → 3.5.0-ultramodern.41

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 (159) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -0
  2. package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +13 -4
  3. package/dist/cjs/builder/shared/lazyCompilation.js +2 -10
  4. package/dist/cjs/commands/index.js +0 -4
  5. package/dist/cjs/index.js +37 -66
  6. package/dist/cjs/plugins/backend-federation/codegen.js +209 -0
  7. package/dist/cjs/plugins/backend-federation/config.js +217 -0
  8. package/dist/cjs/plugins/backend-federation/emit.js +139 -0
  9. package/dist/cjs/plugins/backendFederationBuild.js +53 -0
  10. package/dist/cjs/plugins/deploy/index.js +4 -4
  11. package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +127 -0
  12. package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +137 -0
  13. package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +121 -0
  14. package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +135 -0
  15. package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +126 -0
  16. package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +205 -0
  17. package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +18 -0
  18. package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +66 -0
  19. package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +178 -0
  20. package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +189 -0
  21. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +91 -0
  22. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +93 -0
  23. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +83 -0
  24. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +184 -0
  25. package/dist/cjs/{baseline.js → plugins/deploy/platforms/cloudflare-output-verifier/issues.js} +19 -10
  26. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +83 -0
  27. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +149 -0
  28. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +131 -0
  29. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  30. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  31. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  32. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  33. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  34. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  35. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +1 -0
  36. package/dist/esm/builder/shared/builderPlugins/adapterPrecompress.mjs +13 -4
  37. package/dist/esm/builder/shared/lazyCompilation.mjs +1 -3
  38. package/dist/esm/commands/index.mjs +0 -1
  39. package/dist/esm/index.mjs +3 -4
  40. package/dist/esm/plugins/analyze/getHtmlTemplate.mjs +2 -2
  41. package/dist/esm/plugins/analyze/isDefaultExportFunction.mjs +2 -2
  42. package/dist/esm/plugins/backend-federation/codegen.mjs +158 -0
  43. package/dist/esm/plugins/backend-federation/config.mjs +141 -0
  44. package/dist/esm/plugins/backend-federation/emit.mjs +88 -0
  45. package/dist/esm/plugins/backendFederationBuild.mjs +1 -0
  46. package/dist/esm/plugins/deploy/index.mjs +1 -1
  47. package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +64 -0
  48. package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +33 -0
  49. package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +70 -0
  50. package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +97 -0
  51. package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +78 -0
  52. package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +167 -0
  53. package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
  54. package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +12 -0
  55. package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +118 -0
  56. package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +135 -0
  57. package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +17 -0
  58. package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +45 -0
  59. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +45 -0
  60. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +129 -0
  61. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +10 -0
  62. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +45 -0
  63. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +97 -0
  64. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +68 -0
  65. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  66. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  67. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  68. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  69. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  70. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  71. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +1 -0
  72. package/dist/esm-node/builder/shared/builderPlugins/adapterPrecompress.mjs +13 -4
  73. package/dist/esm-node/builder/shared/lazyCompilation.mjs +1 -3
  74. package/dist/esm-node/commands/index.mjs +0 -1
  75. package/dist/esm-node/index.mjs +3 -4
  76. package/dist/esm-node/plugins/analyze/getHtmlTemplate.mjs +2 -2
  77. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +2 -2
  78. package/dist/esm-node/plugins/backend-federation/codegen.mjs +159 -0
  79. package/dist/esm-node/plugins/backend-federation/config.mjs +142 -0
  80. package/dist/esm-node/plugins/backend-federation/emit.mjs +89 -0
  81. package/dist/esm-node/plugins/backendFederationBuild.mjs +2 -0
  82. package/dist/esm-node/plugins/deploy/index.mjs +1 -1
  83. package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +65 -0
  84. package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +34 -0
  85. package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +71 -0
  86. package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +98 -0
  87. package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +79 -0
  88. package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +168 -0
  89. package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +1 -0
  90. package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +13 -0
  91. package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +119 -0
  92. package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +136 -0
  93. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +18 -0
  94. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +46 -0
  95. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +46 -0
  96. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +130 -0
  97. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +11 -0
  98. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +46 -0
  99. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +98 -0
  100. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +69 -0
  101. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  102. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  103. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  104. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  105. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  106. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  107. package/dist/types/builder/generator/createCopyPattern.d.ts +7 -5
  108. package/dist/types/builder/shared/lazyCompilation.d.ts +2 -4
  109. package/dist/types/commands/index.d.ts +0 -1
  110. package/dist/types/index.d.ts +0 -2
  111. package/dist/types/plugins/backend-federation/codegen.d.ts +83 -0
  112. package/dist/types/plugins/backend-federation/config.d.ts +103 -0
  113. package/dist/types/plugins/backend-federation/emit.d.ts +13 -0
  114. package/dist/types/plugins/backendFederationBuild.d.ts +2 -0
  115. package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +15 -0
  116. package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +23 -0
  117. package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +23 -0
  118. package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +22 -0
  119. package/dist/types/plugins/deploy/platforms/{cloudflare.d.ts → cloudflare/index.d.ts} +1 -1
  120. package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +51 -0
  121. package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +5 -0
  122. package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +6 -0
  123. package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +113 -0
  124. package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +39 -0
  125. package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +13 -0
  126. package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +34 -0
  127. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +4 -0
  128. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +18 -0
  129. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +14 -0
  130. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +2 -0
  131. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +6 -0
  132. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +15 -0
  133. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
  134. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
  135. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
  136. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
  137. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
  138. package/dist/types/types/config/cloudflareDeploy.d.ts +22 -0
  139. package/dist/types/types/config/deploy.d.ts +15 -2
  140. package/lib/types.d.ts +2 -3
  141. package/package.json +24 -18
  142. package/dist/cjs/commands/runtime.js +0 -196
  143. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +0 -540
  144. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  145. package/dist/cjs/ultramodern/designSystem.js +0 -123
  146. package/dist/esm/baseline.mjs +0 -4
  147. package/dist/esm/commands/runtime.mjs +0 -146
  148. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +0 -492
  149. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  150. package/dist/esm/ultramodern/designSystem.mjs +0 -73
  151. package/dist/esm-node/baseline.mjs +0 -5
  152. package/dist/esm-node/commands/runtime.mjs +0 -147
  153. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +0 -493
  154. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -576
  155. package/dist/esm-node/ultramodern/designSystem.mjs +0 -74
  156. package/dist/types/baseline.d.ts +0 -16
  157. package/dist/types/commands/runtime.d.ts +0 -12
  158. package/dist/types/ultramodern/designSystem.d.ts +0 -54
  159. /package/dist/types/plugins/deploy/platforms/templates/{cloudflare-entry.d.mts → cloudflare-entry.006-fetch-handler.d.mts} +0 -0
@@ -0,0 +1,159 @@
1
+ import "node:module";
2
+ import node_path from "node:path";
3
+ import { BACKEND_FEDERATION_CONTRACT_VERSION, BACKEND_FEDERATION_EFFECT_EXPOSE, BACKEND_FEDERATION_NODE_ADAPTER_VERSION, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, formatBackendFederationValidationErrors, validateBackendFederationManifest } from "@modern-js/utils/universal";
4
+ import { normalizeRelativePath } from "./config.mjs";
5
+ const createRelativeImportSpecifier = (fromDirectory, toFile)=>{
6
+ const relativePath = normalizeRelativePath(node_path.relative(fromDirectory, toFile));
7
+ return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
8
+ };
9
+ const createPublicPath = (containerEntry, fallbackPort)=>{
10
+ try {
11
+ return new URL('.', containerEntry).href;
12
+ } catch {
13
+ const slashIndex = containerEntry.lastIndexOf('/');
14
+ if (slashIndex >= 0) return containerEntry.slice(0, slashIndex + 1);
15
+ return `http://localhost:${fallbackPort}/`;
16
+ }
17
+ };
18
+ const createBackendRemoteEntrySource = (workspaceRoot, app, effectApiPath, entryPath)=>{
19
+ const effectApiSpecifier = createRelativeImportSpecifier(node_path.dirname(entryPath), effectApiPath);
20
+ return `// Generated by Modern.js backend federation build.
21
+ const exposedModules = {
22
+ ${JSON.stringify(BACKEND_FEDERATION_EFFECT_EXPOSE)}: () =>
23
+ import(new URL(${JSON.stringify(effectApiSpecifier)}, import.meta.url).href),
24
+ };
25
+
26
+ export const __modernjsBackendFederation = ${JSON.stringify({
27
+ buildVersion: app.buildVersion,
28
+ expose: BACKEND_FEDERATION_EFFECT_EXPOSE,
29
+ name: app.backendName,
30
+ packageName: app.packageName,
31
+ remoteType: app.remoteType,
32
+ source: normalizeRelativePath(node_path.relative(workspaceRoot, effectApiPath)),
33
+ version: app.version,
34
+ ...app.unitId ? {
35
+ unitId: app.unitId
36
+ } : {},
37
+ ...app.sourceRevision ? {
38
+ sourceRevision: app.sourceRevision
39
+ } : {}
40
+ }, null, 2)};
41
+
42
+ export function init() {}
43
+
44
+ export function get(id) {
45
+ const load = exposedModules[id];
46
+ if (!load) {
47
+ throw new Error(\`Unexpected backend federation expose: \${id}\`);
48
+ }
49
+
50
+ return async () => load();
51
+ }
52
+
53
+ export default { get, init };
54
+ `;
55
+ };
56
+ const createBackendManifest = (workspaceRoot, distDirectory, app)=>{
57
+ const sourceModule = `${app.directory}/api/effect-api.ts`;
58
+ const publicPath = createPublicPath(app.containerEntry, app.port);
59
+ const manifest = {
60
+ schemaVersion: 1,
61
+ id: app.backendName,
62
+ name: app.backendName,
63
+ version: app.version,
64
+ buildVersion: app.buildVersion,
65
+ metaData: {
66
+ name: app.backendName,
67
+ type: 'backend',
68
+ buildInfo: {
69
+ buildVersion: app.buildVersion,
70
+ buildName: app.packageName
71
+ },
72
+ remoteEntry: {
73
+ name: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
74
+ path: '',
75
+ type: app.remoteType
76
+ },
77
+ globalName: app.backendName,
78
+ publicPath,
79
+ ssrRemoteEntry: {
80
+ name: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
81
+ path: '',
82
+ type: app.remoteType
83
+ },
84
+ ssrPublicPath: publicPath
85
+ },
86
+ entry: {
87
+ file: BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
88
+ path: normalizeRelativePath(node_path.relative(workspaceRoot, node_path.join(distDirectory, BACKEND_FEDERATION_REMOTE_ENTRY_FILE))),
89
+ type: app.remoteType,
90
+ url: app.containerEntry
91
+ },
92
+ exposes: [
93
+ {
94
+ id: `${app.backendName}:${BACKEND_FEDERATION_EFFECT_EXPOSE}`,
95
+ name: BACKEND_FEDERATION_EFFECT_EXPOSE,
96
+ path: '',
97
+ assets: {
98
+ js: {
99
+ async: [],
100
+ sync: [
101
+ BACKEND_FEDERATION_REMOTE_ENTRY_FILE
102
+ ]
103
+ },
104
+ css: {
105
+ async: [],
106
+ sync: []
107
+ }
108
+ }
109
+ }
110
+ ],
111
+ shared: [],
112
+ backendFederation: {
113
+ role: 'microvertical-server',
114
+ appId: app.id,
115
+ name: app.backendName,
116
+ runtimeFramework: 'effect',
117
+ strictEffectApproach: true,
118
+ contractVersion: BACKEND_FEDERATION_CONTRACT_VERSION,
119
+ nodeAdapterVersion: BACKEND_FEDERATION_NODE_ADAPTER_VERSION,
120
+ remoteType: app.remoteType,
121
+ expose: BACKEND_FEDERATION_EFFECT_EXPOSE,
122
+ manifestUrl: app.manifestUrl,
123
+ containerEntry: app.containerEntry,
124
+ source: {
125
+ module: sourceModule
126
+ },
127
+ readinessPath: `${app.apiPrefix}/${app.apiStem}/readiness`,
128
+ openapiPath: `${app.apiPrefix}/openapi.json`,
129
+ ...app.deliveryUnit ? {
130
+ deliveryUnit: app.deliveryUnit
131
+ } : {},
132
+ versionBoundary: {
133
+ invariant: 'web-and-api-same-build',
134
+ packageName: app.packageName,
135
+ version: app.version,
136
+ buildVersion: app.buildVersion,
137
+ ...app.uiManifestUrl ? {
138
+ uiManifestUrl: app.uiManifestUrl
139
+ } : {},
140
+ ...app.deliveryUnit ? {
141
+ deliveryUnit: {
142
+ unitId: app.deliveryUnit.unitId,
143
+ buildMarker: app.deliveryUnit.buildMarker,
144
+ sourceRevision: app.deliveryUnit.sourceRevision
145
+ }
146
+ } : {}
147
+ }
148
+ }
149
+ };
150
+ const validation = validateBackendFederationManifest(manifest, {
151
+ path: 'backendFederationManifest',
152
+ requireEffectExpose: true,
153
+ requireEffectRuntime: true,
154
+ requireVersionFields: true
155
+ });
156
+ if (!validation.ok) throw new Error(`[backend-federation-build] Invalid backend federation manifest: ${formatBackendFederationValidationErrors(validation.errors)}.`);
157
+ return manifest;
158
+ };
159
+ export { createBackendManifest, createBackendRemoteEntrySource };
@@ -0,0 +1,142 @@
1
+ import "node:module";
2
+ import { execFile } from "node:child_process";
3
+ import { existsSync } from "node:fs";
4
+ import promises from "node:fs/promises";
5
+ import node_path from "node:path";
6
+ import { promisify } from "node:util";
7
+ import { BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, DELIVERY_UNIT_DEPLOY_PROFILE, DELIVERY_UNIT_KIND, DELIVERY_UNIT_SCHEMA_VERSION, ULTRAMODERN_BUILD_ARTIFACT_FILE, ULTRAMODERN_BUILD_ARTIFACT_PATH, ULTRAMODERN_BUILD_MODULE_PATH, deliveryUnitContractBlock, validateDeliveryUnitRecord, validateUltramodernBuildArtifact } from "@modern-js/utils/universal";
8
+ const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
9
+ const execFileAsync = promisify(execFile);
10
+ const normalizeRelativePath = (value)=>value.replace(/\\/gu, '/').replace(/^\.\/+/u, '');
11
+ const isRecord = (value)=>'object' == typeof value && null !== value;
12
+ const readJsonFile = async (filePath)=>JSON.parse(await promises.readFile(filePath, 'utf8'));
13
+ const buildArtifactPathFor = (appDirectory)=>node_path.join(appDirectory, ULTRAMODERN_BUILD_ARTIFACT_PATH);
14
+ const buildModulePathFor = (appDirectory)=>node_path.join(appDirectory, ULTRAMODERN_BUILD_MODULE_PATH);
15
+ const readBuildIdentity = async (appDirectory)=>{
16
+ const buildArtifactPath = buildArtifactPathFor(appDirectory);
17
+ if (existsSync(buildArtifactPath)) {
18
+ const artifact = await readJsonFile(buildArtifactPath);
19
+ const artifactValidation = validateUltramodernBuildArtifact(artifact, buildArtifactPath);
20
+ if (!artifactValidation.ok) throw new Error(`[backend-federation-build] Invalid delivery-unit build artifact at ${buildArtifactPath}.`);
21
+ const deliveryUnit = artifact.deliveryUnit;
22
+ return {
23
+ artifact,
24
+ appId: deliveryUnit.appId,
25
+ buildVersion: deliveryUnit.buildMarker,
26
+ packageName: deliveryUnit.packageName,
27
+ version: deliveryUnit.version,
28
+ unitId: deliveryUnit.unitId,
29
+ sourceRevision: deliveryUnit.sourceRevision
30
+ };
31
+ }
32
+ const buildModulePath = buildModulePathFor(appDirectory);
33
+ if (!existsSync(buildModulePath)) return {};
34
+ console.warn(`[backend-federation-build] ${buildArtifactPath} missing; falling back to legacy regex parsing of ${buildModulePath}. Regenerate the workspace to emit ${ULTRAMODERN_BUILD_ARTIFACT_FILE}.`);
35
+ const source = await promises.readFile(buildModulePath, 'utf8');
36
+ return {
37
+ appId: source.match(/\bappId:\s*['"]([^'"]+)['"]/u)?.[1],
38
+ buildVersion: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
39
+ packageName: source.match(/\bpackageName:\s*['"]([^'"]+)['"]/u)?.[1],
40
+ version: source.match(/\bversion:\s*['"]([^'"]+)['"]/u)?.[1],
41
+ unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
42
+ sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
43
+ };
44
+ };
45
+ const toPascalCase = (value)=>value.split(/[^a-zA-Z0-9]+/u).filter(Boolean).map((part)=>part.charAt(0).toUpperCase() + part.slice(1)).join('');
46
+ const stringValue = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
47
+ const createBackendName = (app, id)=>{
48
+ const configuredName = stringValue(app.backendFederation?.name) ?? stringValue(app.backendFederation?.executionSurfaces?.node?.remoteName) ?? stringValue(app.serverExecution?.node?.remoteName);
49
+ if (configuredName) return configuredName;
50
+ const mfName = stringValue(app.moduleFederation?.name);
51
+ return mfName ? `${mfName}Backend` : `vertical${toPascalCase(id)}Backend`;
52
+ };
53
+ const findWorkspaceRoot = (appDirectory)=>{
54
+ let current = appDirectory;
55
+ while(true){
56
+ if (existsSync(node_path.join(current, COMPACT_CONFIG_PATH))) return current;
57
+ const parent = node_path.dirname(current);
58
+ if (parent === current) return;
59
+ current = parent;
60
+ }
61
+ };
62
+ const resolveWorkspaceSourceRevision = async (workspaceRoot)=>{
63
+ const envRevision = process.env.ULTRAMODERN_SOURCE_REVISION?.trim();
64
+ if (envRevision) return envRevision;
65
+ try {
66
+ const { stdout } = await execFileAsync('git', [
67
+ '-C',
68
+ workspaceRoot,
69
+ 'rev-parse',
70
+ 'HEAD'
71
+ ]);
72
+ const revision = stdout.trim();
73
+ if (revision.length > 0) return revision;
74
+ } catch {}
75
+ console.warn('[backend-federation-build] Could not resolve git source revision; stamping sourceRevision as "workspace". Set ULTRAMODERN_SOURCE_REVISION to override.');
76
+ return 'workspace';
77
+ };
78
+ const createStampedDeliveryUnit = (input)=>{
79
+ if (!input.unitId || !input.buildMarker || !input.packageName || !input.version) return;
80
+ const record = {
81
+ schemaVersion: DELIVERY_UNIT_SCHEMA_VERSION,
82
+ kind: DELIVERY_UNIT_KIND,
83
+ appId: input.appId,
84
+ unitId: input.unitId,
85
+ packageName: input.packageName,
86
+ version: input.version,
87
+ buildMarker: input.buildMarker,
88
+ sourceRevision: input.sourceRevision,
89
+ deployProfile: DELIVERY_UNIT_DEPLOY_PROFILE
90
+ };
91
+ const validation = validateDeliveryUnitRecord(record);
92
+ if (!validation.ok) return;
93
+ return deliveryUnitContractBlock(record);
94
+ };
95
+ const createAppFromCompactMetadata = (workspaceRoot, appDirectory, compactApp)=>{
96
+ const id = stringValue(compactApp.id);
97
+ const appPath = stringValue(compactApp.path);
98
+ if (!id || 'vertical' !== compactApp.kind || !isRecord(compactApp.api)) return;
99
+ const directory = appPath ? normalizeRelativePath(appPath) : `verticals/${id}`;
100
+ if (node_path.resolve(workspaceRoot, directory) !== node_path.resolve(appDirectory)) return;
101
+ const port = 'number' == typeof compactApp.port ? compactApp.port : void 0;
102
+ if (void 0 === port) return;
103
+ const apiPrefix = stringValue(compactApp.api.prefix) ?? `/${id}-api`;
104
+ const apiStem = stringValue(compactApp.api.stem) ?? id;
105
+ const backendName = createBackendName(compactApp, id);
106
+ const manifestUrl = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.manifestUrl) ?? stringValue(compactApp.serverExecution?.node?.manifestUrl) ?? `http://localhost:${port}/${BACKEND_FEDERATION_MANIFEST_FILE}`;
107
+ const containerEntry = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.containerEntry) ?? stringValue(compactApp.serverExecution?.node?.containerEntry) ?? `http://localhost:${port}/${BACKEND_FEDERATION_REMOTE_ENTRY_FILE}`;
108
+ const remoteType = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.remoteType) ?? stringValue(compactApp.serverExecution?.node?.remoteType) ?? 'module';
109
+ const packageName = stringValue(compactApp.package);
110
+ const uiManifestUrl = stringValue(compactApp.backendFederation?.versionBoundary?.ui?.manifestUrl) ?? stringValue(compactApp.moduleFederation?.manifestUrl);
111
+ const compactDeliveryUnit = isRecord(compactApp.deliveryUnit) ? {
112
+ unitId: stringValue(compactApp.deliveryUnit.unitId),
113
+ buildMarker: stringValue(compactApp.deliveryUnit.buildMarker),
114
+ sourceRevision: stringValue(compactApp.deliveryUnit.sourceRevision),
115
+ packageName: stringValue(compactApp.deliveryUnit.packageName),
116
+ version: stringValue(compactApp.deliveryUnit.version)
117
+ } : void 0;
118
+ return {
119
+ id,
120
+ directory,
121
+ packageName,
122
+ port,
123
+ apiPrefix,
124
+ apiStem,
125
+ backendName,
126
+ manifestUrl,
127
+ containerEntry,
128
+ remoteType,
129
+ uiManifestUrl,
130
+ compactDeliveryUnit
131
+ };
132
+ };
133
+ const findBackendFederationApp = async (workspaceRoot, appDirectory)=>{
134
+ const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
135
+ const compactConfig = await readJsonFile(compactConfigPath);
136
+ const apps = Array.isArray(compactConfig.topology?.apps) ? compactConfig.topology.apps : [];
137
+ for (const app of apps){
138
+ const resolved = createAppFromCompactMetadata(workspaceRoot, appDirectory, app);
139
+ if (resolved) return resolved;
140
+ }
141
+ };
142
+ export { COMPACT_CONFIG_PATH, buildArtifactPathFor, buildModulePathFor, createAppFromCompactMetadata, createStampedDeliveryUnit, findBackendFederationApp, findWorkspaceRoot, normalizeRelativePath, readBuildIdentity, resolveWorkspaceSourceRevision };
@@ -0,0 +1,89 @@
1
+ import "node:module";
2
+ import { existsSync } from "node:fs";
3
+ import promises from "node:fs/promises";
4
+ import node_path from "node:path";
5
+ import { BACKEND_FEDERATION_MANIFEST_FILE, BACKEND_FEDERATION_REMOTE_ENTRY_FILE, ULTRAMODERN_BUILD_ARTIFACT_FILE, stampUltramodernBuildArtifactSourceRevision } from "@modern-js/utils/universal";
6
+ import { createBackendManifest, createBackendRemoteEntrySource } from "./codegen.mjs";
7
+ import { COMPACT_CONFIG_PATH, buildArtifactPathFor, buildModulePathFor, createStampedDeliveryUnit, findBackendFederationApp, findWorkspaceRoot, readBuildIdentity, resolveWorkspaceSourceRevision } from "./config.mjs";
8
+ const emitBackendFederationArtifacts = async (appDirectory, distDirectory)=>{
9
+ const workspaceRoot = findWorkspaceRoot(appDirectory);
10
+ if (!workspaceRoot) return;
11
+ const effectApiPath = node_path.join(appDirectory, 'api/effect-api.ts');
12
+ const backendFederationConfigPath = node_path.join(appDirectory, 'backend-federation.config.ts');
13
+ if (!existsSync(effectApiPath) || !existsSync(backendFederationConfigPath)) return;
14
+ const app = await findBackendFederationApp(workspaceRoot, appDirectory);
15
+ if (!app) return;
16
+ const buildIdentity = await readBuildIdentity(appDirectory);
17
+ const compactDeliveryUnit = app.compactDeliveryUnit;
18
+ const hasCompactDeliveryUnit = void 0 !== compactDeliveryUnit && (void 0 !== compactDeliveryUnit.unitId || void 0 !== compactDeliveryUnit.buildMarker || void 0 !== compactDeliveryUnit.packageName || void 0 !== compactDeliveryUnit.version);
19
+ const hasBuildIdentity = void 0 !== buildIdentity.unitId || void 0 !== buildIdentity.buildVersion || void 0 !== buildIdentity.packageName || void 0 !== buildIdentity.version;
20
+ if (hasBuildIdentity) {
21
+ const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
22
+ const buildIdentityPath = existsSync(buildArtifactPathFor(appDirectory)) ? buildArtifactPathFor(appDirectory) : buildModulePathFor(appDirectory);
23
+ const mismatches = [];
24
+ const compare = (label, a, b, leftLabel = 'deliveryUnit')=>{
25
+ if (void 0 !== a && void 0 !== b && a !== b) mismatches.push(`${label}: ${leftLabel}=${a} vs ultramodern-build=${b}`);
26
+ };
27
+ compare('appId', app.id, buildIdentity.appId, 'topology');
28
+ if (hasCompactDeliveryUnit) {
29
+ compare('unitId', compactDeliveryUnit?.unitId, buildIdentity.unitId);
30
+ compare('buildMarker/build', compactDeliveryUnit?.buildMarker, buildIdentity.buildVersion);
31
+ compare('packageName', compactDeliveryUnit?.packageName, buildIdentity.packageName);
32
+ compare('version', compactDeliveryUnit?.version, buildIdentity.version);
33
+ }
34
+ if (mismatches.length > 0) throw new Error(`[backend-federation-build] Delivery-unit identity drift between ${compactConfigPath} (topology) and ${buildIdentityPath}: ${mismatches.join('; ')}`);
35
+ }
36
+ const unitId = compactDeliveryUnit?.unitId ?? buildIdentity.unitId;
37
+ const buildVersion = compactDeliveryUnit?.buildMarker ?? buildIdentity.buildVersion;
38
+ const sourceRevision = await resolveWorkspaceSourceRevision(workspaceRoot);
39
+ const packageName = compactDeliveryUnit?.packageName ?? buildIdentity.packageName ?? app.packageName;
40
+ const version = compactDeliveryUnit?.version ?? buildIdentity.version;
41
+ const deliveryUnit = createStampedDeliveryUnit({
42
+ appId: app.id,
43
+ unitId,
44
+ buildMarker: buildVersion,
45
+ packageName,
46
+ version,
47
+ sourceRevision
48
+ });
49
+ const stampedBuildArtifact = buildIdentity.artifact ? stampUltramodernBuildArtifactSourceRevision(buildIdentity.artifact, sourceRevision) : void 0;
50
+ const resolvedApp = {
51
+ ...app,
52
+ packageName,
53
+ version,
54
+ buildVersion,
55
+ unitId,
56
+ sourceRevision,
57
+ deliveryUnit
58
+ };
59
+ const manifestPath = node_path.join(distDirectory, BACKEND_FEDERATION_MANIFEST_FILE);
60
+ const entryPath = node_path.join(distDirectory, BACKEND_FEDERATION_REMOTE_ENTRY_FILE);
61
+ const deliveryUnitArtifactPath = stampedBuildArtifact ? node_path.join(distDirectory, ULTRAMODERN_BUILD_ARTIFACT_FILE) : void 0;
62
+ await promises.mkdir(distDirectory, {
63
+ recursive: true
64
+ });
65
+ await promises.writeFile(entryPath, createBackendRemoteEntrySource(workspaceRoot, resolvedApp, effectApiPath, entryPath));
66
+ await promises.writeFile(manifestPath, `${JSON.stringify(createBackendManifest(workspaceRoot, distDirectory, resolvedApp), null, 2)}\n`);
67
+ if (stampedBuildArtifact && deliveryUnitArtifactPath) await promises.writeFile(deliveryUnitArtifactPath, `${JSON.stringify(stampedBuildArtifact, null, 2)}\n`);
68
+ return {
69
+ appId: resolvedApp.id,
70
+ manifestPath,
71
+ containerPath: entryPath,
72
+ ...deliveryUnitArtifactPath ? {
73
+ deliveryUnitArtifactPath
74
+ } : {},
75
+ remoteName: resolvedApp.backendName,
76
+ remoteType: resolvedApp.remoteType
77
+ };
78
+ };
79
+ const emit = ()=>({
80
+ name: '@modern-js/backend-federation-build',
81
+ setup (api) {
82
+ api.onAfterBuild(async ()=>{
83
+ const { appDirectory, distDirectory } = api.getAppContext();
84
+ await emitBackendFederationArtifacts(appDirectory, distDirectory);
85
+ });
86
+ }
87
+ });
88
+ export default emit;
89
+ export { emitBackendFederationArtifacts };
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ export { default, emitBackendFederationArtifacts } from "./backend-federation/emit.mjs";
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
2
  import { provider } from "std-env";
3
- import { createCloudflarePreset } from "./platforms/cloudflare.mjs";
3
+ import { createCloudflarePreset } from "./platforms/cloudflare/index.mjs";
4
4
  import { createGhPagesPreset } from "./platforms/gh-pages.mjs";
5
5
  import { createNetlifyPreset } from "./platforms/netlify.mjs";
6
6
  import { createNodePreset } from "./platforms/node.mjs";
@@ -0,0 +1,65 @@
1
+ import "node:module";
2
+ import node_path from "node:path";
3
+ import { fs } from "@modern-js/utils";
4
+ import { RESERVED_ARTIFACT_DESTINATION_DIRECTORIES, RESERVED_ARTIFACT_DESTINATION_FILES, ROUTE_SPEC_OUTPUT } from "./constants.mjs";
5
+ import { normalizeRelativePath } from "./utils.mjs";
6
+ const normalizeCloudflareArtifact = (artifact, index)=>{
7
+ const from = normalizeRelativePath(artifact.from, `deploy.worker.artifacts[${index}].from`, 'app root');
8
+ const to = normalizeRelativePath(artifact.to, `deploy.worker.artifacts[${index}].to`, 'Cloudflare output');
9
+ const [topLevelDestination] = to.split('/');
10
+ const reservedDestination = RESERVED_ARTIFACT_DESTINATION_FILES.has(to) ? to : topLevelDestination;
11
+ if (RESERVED_ARTIFACT_DESTINATION_FILES.has(to) || RESERVED_ARTIFACT_DESTINATION_DIRECTORIES.has(topLevelDestination)) throw new Error(`deploy.worker.artifacts[${index}].to must not target generated Cloudflare output path ${JSON.stringify(reservedDestination)}.`);
12
+ return {
13
+ from,
14
+ to,
15
+ index
16
+ };
17
+ };
18
+ const getCloudflareArtifacts = (modernConfig)=>(modernConfig.deploy?.worker?.artifacts ?? []).map(normalizeCloudflareArtifact);
19
+ const normalizeCloudflarePublicAsset = (asset, index)=>{
20
+ const from = normalizeRelativePath(asset.from, `deploy.worker.publicAssets[${index}].from`, 'app root');
21
+ const to = normalizeRelativePath(asset.to, `deploy.worker.publicAssets[${index}].to`, 'Cloudflare public output', {
22
+ allowRoot: true
23
+ });
24
+ return {
25
+ from,
26
+ to,
27
+ index
28
+ };
29
+ };
30
+ const getCloudflarePublicAssets = (modernConfig)=>(modernConfig.deploy?.worker?.publicAssets ?? []).map(normalizeCloudflarePublicAsset);
31
+ const copyCloudflareArtifacts = async (appDirectory, outputDirectory, artifacts)=>{
32
+ for (const artifact of artifacts){
33
+ const sourcePath = node_path.join(appDirectory, artifact.from);
34
+ if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.artifacts[${artifact.index}].from does not exist: ${artifact.from}`);
35
+ await fs.copy(sourcePath, node_path.join(outputDirectory, artifact.to));
36
+ }
37
+ };
38
+ const copyCloudflarePublicAssets = async (appDirectory, publicDirectory, publicAssets)=>{
39
+ for (const asset of publicAssets){
40
+ const sourcePath = node_path.join(appDirectory, asset.from);
41
+ if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.publicAssets[${asset.index}].from does not exist: ${asset.from}`);
42
+ await fs.copy(sourcePath, node_path.join(publicDirectory, asset.to));
43
+ }
44
+ };
45
+ const copyCloudflareD1Migrations = async (appDirectory, outputDirectory, modernConfig)=>{
46
+ for (const [index, database] of (modernConfig.deploy?.worker?.d1Databases ?? []).entries()){
47
+ if (!database.migrationsDir) continue;
48
+ const migrationsDir = normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
49
+ const sourcePath = node_path.join(appDirectory, migrationsDir);
50
+ if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.d1Databases[${index}].migrationsDir does not exist: ${migrationsDir}`);
51
+ await fs.copy(sourcePath, node_path.join(outputDirectory, migrationsDir));
52
+ }
53
+ };
54
+ const readRouteSpec = async (outputDirectory)=>{
55
+ const routeSpecPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
56
+ if (!await fs.pathExists(routeSpecPath)) return {
57
+ routes: []
58
+ };
59
+ const routeSpec = await fs.readJSON(routeSpecPath);
60
+ return {
61
+ ...routeSpec,
62
+ routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
63
+ };
64
+ };
65
+ export { copyCloudflareArtifacts, copyCloudflareD1Migrations, copyCloudflarePublicAssets, getCloudflareArtifacts, getCloudflarePublicAssets, readRouteSpec };
@@ -0,0 +1,34 @@
1
+ import "node:module";
2
+ import { CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_OUTPUT_PACKAGE_FILE, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY, CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS, CLOUDFLARE_RUNTIME_TYPE, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY, CLOUDFLARE_WORKER_BUNDLE_FORMAT, CLOUDFLARE_WORKER_ENTRY, CLOUDFLARE_WORKER_MANIFEST, CLOUDFLARE_WRANGLER_CONFIG_FILE } from "../cloudflare-output-contract.mjs";
3
+ const WORKER_ENTRY = CLOUDFLARE_WORKER_ENTRY;
4
+ const WORKER_MANIFEST = CLOUDFLARE_WORKER_MANIFEST;
5
+ const WRANGLER_CONFIG_FILE = CLOUDFLARE_WRANGLER_CONFIG_FILE;
6
+ const OUTPUT_PACKAGE_FILE = CLOUDFLARE_OUTPUT_PACKAGE_FILE;
7
+ const ASSETS_BINDING = CLOUDFLARE_ASSETS_BINDING;
8
+ const ROUTE_SPEC_FILE = 'route.json';
9
+ const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
10
+ const LOADABLE_STATS_FILE = 'loadable-stats.json';
11
+ const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
12
+ const PUBLIC_ASSETS_DIRECTORY = CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY;
13
+ const WORKER_BUNDLE_DIRECTORY = CLOUDFLARE_WORKER_BUNDLE_DIRECTORY;
14
+ const SERVER_BUNDLE_DIRECTORY = 'bundles';
15
+ const SERVER_OUTPUT_DIRECTORY = 'server';
16
+ const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES = [
17
+ 'api',
18
+ 'shared'
19
+ ];
20
+ const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
21
+ const EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE = 'Ensure the Effect API entry exists at api/index.ts or bff.effect.entry, and import Cloudflare edge handlers from @modern-js/plugin-bff/effect-edge instead of lambda/Hono server helpers.';
22
+ const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
23
+ const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
24
+ const REQUIRED_COMPATIBILITY_FLAGS = CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS;
25
+ const RESERVED_ARTIFACT_DESTINATION_FILES = new Set([
26
+ WRANGLER_CONFIG_FILE,
27
+ OUTPUT_PACKAGE_FILE
28
+ ]);
29
+ const RESERVED_ARTIFACT_DESTINATION_DIRECTORIES = new Set([
30
+ PUBLIC_ASSETS_DIRECTORY,
31
+ SERVER_OUTPUT_DIRECTORY,
32
+ WORKER_BUNDLE_DIRECTORY
33
+ ]);
34
+ export { ASSETS_BINDING, BFF_EFFECT_WORKER_ENTRY, CLOUDFLARE_RUNTIME_TYPE, CLOUDFLARE_WORKER_BUNDLE_FORMAT, COMPATIBILITY_DATE_PATTERN, DEFAULT_COMPATIBILITY_DATE, DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES, EFFECT_BFF_CLOUDFLARE_IMPORT_GUIDANCE, LOADABLE_STATS_FILE, OUTPUT_PACKAGE_FILE, PUBLIC_ASSETS_DIRECTORY, REQUIRED_COMPATIBILITY_FLAGS, RESERVED_ARTIFACT_DESTINATION_DIRECTORIES, RESERVED_ARTIFACT_DESTINATION_FILES, ROUTE_MANIFEST_FILE, ROUTE_SPEC_FILE, ROUTE_SPEC_OUTPUT, SERVER_BUNDLE_DIRECTORY, SERVER_OUTPUT_DIRECTORY, WORKER_BUNDLE_DIRECTORY, WORKER_ENTRY, WORKER_MANIFEST, WRANGLER_CONFIG_FILE };
@@ -0,0 +1,71 @@
1
+ import "node:module";
2
+ import node_path from "node:path";
3
+ import { fs } from "@modern-js/utils";
4
+ import { ULTRAMODERN_BUILD_ARTIFACT_PATH, ULTRAMODERN_BUILD_MODULE_PATH, isUltramodernBuildArtifact, nonEmptyString, toDeliveryUnitIdentity } from "@modern-js/utils/universal";
5
+ import { isRecord } from "./utils.mjs";
6
+ const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
7
+ const findWorkspaceRoot = async (appDirectory)=>{
8
+ let current = node_path.resolve(appDirectory);
9
+ for(;;){
10
+ if (await fs.pathExists(node_path.join(current, COMPACT_CONFIG_PATH))) return current;
11
+ const parent = node_path.dirname(current);
12
+ if (parent === current) return;
13
+ current = parent;
14
+ }
15
+ };
16
+ const resolveTopologyDeliveryUnit = async (appDirectory)=>{
17
+ const workspaceRoot = await findWorkspaceRoot(appDirectory);
18
+ if (!workspaceRoot) return;
19
+ let compactConfig;
20
+ try {
21
+ compactConfig = await fs.readJSON(node_path.join(workspaceRoot, COMPACT_CONFIG_PATH));
22
+ } catch {
23
+ return;
24
+ }
25
+ if (!isRecord(compactConfig)) return;
26
+ const topology = isRecord(compactConfig.topology) ? compactConfig.topology : void 0;
27
+ const apps = Array.isArray(topology?.apps) ? topology.apps : void 0;
28
+ const resolvedAppDirectory = node_path.resolve(appDirectory);
29
+ if (apps) {
30
+ for (const app of apps){
31
+ if (!isRecord(app)) continue;
32
+ const appPath = nonEmptyString(app.path);
33
+ if (appPath && node_path.resolve(workspaceRoot, appPath.replace(/^\.\/+/u, '')) === resolvedAppDirectory) return toDeliveryUnitIdentity(app.deliveryUnit);
34
+ }
35
+ return;
36
+ }
37
+ return toDeliveryUnitIdentity(compactConfig.deliveryUnit);
38
+ };
39
+ const resolveWorkerDeliveryUnitStamp = async (appDirectory)=>{
40
+ const buildArtifactPath = node_path.join(appDirectory, ULTRAMODERN_BUILD_ARTIFACT_PATH);
41
+ const buildModulePath = node_path.join(appDirectory, ULTRAMODERN_BUILD_MODULE_PATH);
42
+ let identity;
43
+ if (await fs.pathExists(buildArtifactPath)) {
44
+ const artifact = await fs.readJSON(buildArtifactPath);
45
+ if (!isUltramodernBuildArtifact(artifact)) return;
46
+ identity = toDeliveryUnitIdentity(artifact.deliveryUnit);
47
+ } else if (await fs.pathExists(buildModulePath)) {
48
+ console.warn(`[cloudflare] ${buildArtifactPath} missing; falling back to legacy regex parsing of ${buildModulePath}. Regenerate the workspace to emit ultramodern-build.json.`);
49
+ const source = await fs.readFile(buildModulePath, 'utf8');
50
+ identity = toDeliveryUnitIdentity({
51
+ buildMarker: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
52
+ unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
53
+ sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
54
+ });
55
+ }
56
+ if (!identity) return;
57
+ return {
58
+ ...identity,
59
+ surfaces: {
60
+ ui: {
61
+ ...identity,
62
+ surface: 'ui'
63
+ },
64
+ api: {
65
+ ...identity,
66
+ surface: 'api'
67
+ }
68
+ }
69
+ };
70
+ };
71
+ export { resolveTopologyDeliveryUnit, resolveWorkerDeliveryUnitStamp };