@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.30 → 3.5.0-ultramodern.32

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 (116) hide show
  1. package/dist/cjs/plugins/backend-federation/codegen.js +208 -0
  2. package/dist/cjs/plugins/backend-federation/config.js +217 -0
  3. package/dist/cjs/plugins/backend-federation/emit.js +139 -0
  4. package/dist/cjs/plugins/backendFederationBuild.js +4 -298
  5. package/dist/cjs/plugins/deploy/platforms/cloudflare/artifacts.js +127 -0
  6. package/dist/cjs/plugins/deploy/platforms/cloudflare/constants.js +137 -0
  7. package/dist/cjs/plugins/deploy/platforms/cloudflare/delivery-unit.js +118 -0
  8. package/dist/cjs/plugins/deploy/platforms/cloudflare/i18n-worker.js +135 -0
  9. package/dist/cjs/plugins/deploy/platforms/cloudflare/index.js +126 -0
  10. package/dist/cjs/plugins/deploy/platforms/cloudflare/security-policies.js +223 -0
  11. package/dist/cjs/plugins/deploy/platforms/cloudflare/types.js +18 -0
  12. package/dist/cjs/plugins/deploy/platforms/cloudflare/utils.js +66 -0
  13. package/dist/cjs/plugins/deploy/platforms/cloudflare/worker-manifest.js +178 -0
  14. package/dist/cjs/plugins/deploy/platforms/cloudflare/wrangler-config.js +189 -0
  15. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/identity.js +83 -0
  16. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +184 -0
  17. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/issues.js +54 -0
  18. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/manifest.js +83 -0
  19. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.js +158 -0
  20. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +137 -0
  21. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier.js +23 -363
  22. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +2 -745
  23. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  24. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  25. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  26. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  27. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  28. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  29. package/dist/esm/plugins/backend-federation/codegen.mjs +157 -0
  30. package/dist/esm/plugins/backend-federation/config.mjs +141 -0
  31. package/dist/esm/plugins/backend-federation/emit.mjs +88 -0
  32. package/dist/esm/plugins/backendFederationBuild.mjs +1 -296
  33. package/dist/esm/plugins/deploy/platforms/cloudflare/artifacts.mjs +64 -0
  34. package/dist/esm/plugins/deploy/platforms/cloudflare/constants.mjs +33 -0
  35. package/dist/esm/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +67 -0
  36. package/dist/esm/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +97 -0
  37. package/dist/esm/plugins/deploy/platforms/cloudflare/index.mjs +78 -0
  38. package/dist/esm/plugins/deploy/platforms/cloudflare/security-policies.mjs +167 -0
  39. package/dist/esm/plugins/deploy/platforms/cloudflare/types.mjs +0 -0
  40. package/dist/esm/plugins/deploy/platforms/cloudflare/utils.mjs +12 -0
  41. package/dist/esm/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +118 -0
  42. package/dist/esm/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +135 -0
  43. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +45 -0
  44. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +129 -0
  45. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +10 -0
  46. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +45 -0
  47. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +97 -0
  48. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +68 -0
  49. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier.mjs +1 -347
  50. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +1 -735
  51. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  52. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  53. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  54. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  55. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  56. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  57. package/dist/esm-node/plugins/backend-federation/codegen.mjs +158 -0
  58. package/dist/esm-node/plugins/backend-federation/config.mjs +142 -0
  59. package/dist/esm-node/plugins/backend-federation/emit.mjs +89 -0
  60. package/dist/esm-node/plugins/backendFederationBuild.mjs +1 -296
  61. package/dist/esm-node/plugins/deploy/platforms/cloudflare/artifacts.mjs +65 -0
  62. package/dist/esm-node/plugins/deploy/platforms/cloudflare/constants.mjs +34 -0
  63. package/dist/esm-node/plugins/deploy/platforms/cloudflare/delivery-unit.mjs +68 -0
  64. package/dist/esm-node/plugins/deploy/platforms/cloudflare/i18n-worker.mjs +98 -0
  65. package/dist/esm-node/plugins/deploy/platforms/cloudflare/index.mjs +79 -0
  66. package/dist/esm-node/plugins/deploy/platforms/cloudflare/security-policies.mjs +168 -0
  67. package/dist/esm-node/plugins/deploy/platforms/cloudflare/types.mjs +1 -0
  68. package/dist/esm-node/plugins/deploy/platforms/cloudflare/utils.mjs +13 -0
  69. package/dist/esm-node/plugins/deploy/platforms/cloudflare/worker-manifest.mjs +119 -0
  70. package/dist/esm-node/plugins/deploy/platforms/cloudflare/wrangler-config.mjs +136 -0
  71. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/identity.mjs +46 -0
  72. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +130 -0
  73. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/issues.mjs +11 -0
  74. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/manifest.mjs +46 -0
  75. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.mjs +98 -0
  76. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +69 -0
  77. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier.mjs +1 -347
  78. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +1 -735
  79. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +22 -0
  80. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.mjs +0 -0
  81. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.mjs +0 -0
  82. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.mjs +0 -0
  83. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.mjs +0 -0
  84. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.006-fetch-handler.mjs +32 -0
  85. package/dist/types/plugins/backend-federation/codegen.d.ts +82 -0
  86. package/dist/types/plugins/backend-federation/config.d.ts +103 -0
  87. package/dist/types/plugins/backend-federation/emit.d.ts +13 -0
  88. package/dist/types/plugins/backendFederationBuild.d.ts +2 -11
  89. package/dist/types/plugins/deploy/platforms/cloudflare/artifacts.d.ts +15 -0
  90. package/dist/types/plugins/deploy/platforms/cloudflare/constants.d.ts +23 -0
  91. package/dist/types/plugins/deploy/platforms/cloudflare/delivery-unit.d.ts +23 -0
  92. package/dist/types/plugins/deploy/platforms/cloudflare/i18n-worker.d.ts +21 -0
  93. package/dist/types/plugins/deploy/platforms/cloudflare/index.d.ts +2 -0
  94. package/dist/types/plugins/deploy/platforms/cloudflare/security-policies.d.ts +88 -0
  95. package/dist/types/plugins/deploy/platforms/cloudflare/types.d.ts +5 -0
  96. package/dist/types/plugins/deploy/platforms/cloudflare/utils.d.ts +6 -0
  97. package/dist/types/plugins/deploy/platforms/cloudflare/worker-manifest.d.ts +100 -0
  98. package/dist/types/plugins/deploy/platforms/cloudflare/wrangler-config.d.ts +39 -0
  99. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/identity.d.ts +4 -0
  100. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +18 -0
  101. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/issues.d.ts +14 -0
  102. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/manifest.d.ts +2 -0
  103. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/mutation-policy.d.ts +13 -0
  104. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +16 -0
  105. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier.d.ts +1 -32
  106. package/dist/types/plugins/deploy/platforms/cloudflare.d.ts +1 -2
  107. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -0
  108. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.002-assets-routes.d.mts +1 -0
  109. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.003-i18n-locales.d.mts +1 -0
  110. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.004-rendering-css.d.mts +1 -0
  111. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.005-worker-dispatch.d.mts +1 -0
  112. package/package.json +11 -11
  113. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
  114. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
  115. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +0 -879
  116. /package/dist/types/plugins/deploy/platforms/templates/{cloudflare-entry.d.mts → cloudflare-entry.006-fetch-handler.d.mts} +0 -0
@@ -1,296 +1 @@
1
- import { existsSync } from "node:fs";
2
- import promises from "node:fs/promises";
3
- import node_path from "node:path";
4
- const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
5
- const BACKEND_MANIFEST_FILE = 'backend-mf-manifest.json';
6
- const BACKEND_REMOTE_ENTRY_FILE = 'backendRemoteEntry.mjs';
7
- const CONTRACT_VERSION = 'microvertical-server-effect-v1';
8
- const NODE_ADAPTER_VERSION = 'backend-mf-effect-v1';
9
- const BACKEND_EXPOSE = './effect-api';
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 buildModulePathFor = (appDirectory)=>node_path.join(appDirectory, 'shared/ultramodern-build.ts');
14
- const readBuildIdentity = async (appDirectory)=>{
15
- const buildModulePath = buildModulePathFor(appDirectory);
16
- if (!existsSync(buildModulePath)) return {};
17
- const source = await promises.readFile(buildModulePath, 'utf8');
18
- return {
19
- buildVersion: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
20
- packageName: source.match(/\bpackageName:\s*['"]([^'"]+)['"]/u)?.[1],
21
- version: source.match(/\bversion:\s*['"]([^'"]+)['"]/u)?.[1],
22
- unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
23
- sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
24
- };
25
- };
26
- const toPascalCase = (value)=>value.split(/[^a-zA-Z0-9]+/u).filter(Boolean).map((part)=>part.charAt(0).toUpperCase() + part.slice(1)).join('');
27
- const stringValue = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
28
- const createBackendName = (app, id)=>{
29
- const configuredName = stringValue(app.backendFederation?.name) ?? stringValue(app.backendFederation?.executionSurfaces?.node?.remoteName) ?? stringValue(app.serverExecution?.node?.remoteName);
30
- if (configuredName) return configuredName;
31
- const mfName = stringValue(app.moduleFederation?.name);
32
- return mfName ? `${mfName}Backend` : `vertical${toPascalCase(id)}Backend`;
33
- };
34
- const findWorkspaceRoot = (appDirectory)=>{
35
- let current = appDirectory;
36
- while(true){
37
- if (existsSync(node_path.join(current, COMPACT_CONFIG_PATH))) return current;
38
- const parent = node_path.dirname(current);
39
- if (parent === current) return;
40
- current = parent;
41
- }
42
- };
43
- const createAppFromCompactMetadata = (workspaceRoot, appDirectory, compactApp)=>{
44
- const id = stringValue(compactApp.id);
45
- const appPath = stringValue(compactApp.path);
46
- if (!id || 'vertical' !== compactApp.kind || !isRecord(compactApp.api)) return;
47
- const directory = appPath ? normalizeRelativePath(appPath) : `verticals/${id}`;
48
- if (node_path.resolve(workspaceRoot, directory) !== node_path.resolve(appDirectory)) return;
49
- const port = 'number' == typeof compactApp.port ? compactApp.port : void 0;
50
- if (void 0 === port) return;
51
- const apiPrefix = stringValue(compactApp.api.prefix) ?? `/${id}-api`;
52
- const apiStem = stringValue(compactApp.api.stem) ?? id;
53
- const backendName = createBackendName(compactApp, id);
54
- const manifestUrl = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.manifestUrl) ?? stringValue(compactApp.serverExecution?.node?.manifestUrl) ?? `http://localhost:${port}/${BACKEND_MANIFEST_FILE}`;
55
- const containerEntry = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.containerEntry) ?? stringValue(compactApp.serverExecution?.node?.containerEntry) ?? `http://localhost:${port}/${BACKEND_REMOTE_ENTRY_FILE}`;
56
- const remoteType = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.remoteType) ?? stringValue(compactApp.serverExecution?.node?.remoteType) ?? 'module';
57
- const packageName = stringValue(compactApp.package);
58
- const uiManifestUrl = stringValue(compactApp.backendFederation?.versionBoundary?.ui?.manifestUrl) ?? stringValue(compactApp.moduleFederation?.manifestUrl);
59
- const compactDeliveryUnit = isRecord(compactApp.deliveryUnit) ? {
60
- unitId: stringValue(compactApp.deliveryUnit.unitId),
61
- buildMarker: stringValue(compactApp.deliveryUnit.buildMarker),
62
- sourceRevision: stringValue(compactApp.deliveryUnit.sourceRevision),
63
- packageName: stringValue(compactApp.deliveryUnit.packageName),
64
- version: stringValue(compactApp.deliveryUnit.version)
65
- } : void 0;
66
- return {
67
- id,
68
- directory,
69
- packageName,
70
- port,
71
- apiPrefix,
72
- apiStem,
73
- backendName,
74
- manifestUrl,
75
- containerEntry,
76
- remoteType,
77
- uiManifestUrl,
78
- compactDeliveryUnit
79
- };
80
- };
81
- const findBackendFederationApp = async (workspaceRoot, appDirectory)=>{
82
- const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
83
- const compactConfig = await readJsonFile(compactConfigPath);
84
- const apps = Array.isArray(compactConfig.topology?.apps) ? compactConfig.topology.apps : [];
85
- for (const app of apps){
86
- const resolved = createAppFromCompactMetadata(workspaceRoot, appDirectory, app);
87
- if (resolved) return resolved;
88
- }
89
- };
90
- const createRelativeImportSpecifier = (fromDirectory, toFile)=>{
91
- const relativePath = normalizeRelativePath(node_path.relative(fromDirectory, toFile));
92
- return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
93
- };
94
- const createBackendRemoteEntrySource = (workspaceRoot, app, effectApiPath, entryPath)=>{
95
- const effectApiSpecifier = createRelativeImportSpecifier(node_path.dirname(entryPath), effectApiPath);
96
- return `// Generated by Modern.js backend federation build.
97
- const exposedModules = {
98
- ${JSON.stringify(BACKEND_EXPOSE)}: () =>
99
- import(new URL(${JSON.stringify(effectApiSpecifier)}, import.meta.url).href),
100
- };
101
-
102
- export const __modernjsBackendFederation = ${JSON.stringify({
103
- buildVersion: app.buildVersion,
104
- expose: BACKEND_EXPOSE,
105
- name: app.backendName,
106
- packageName: app.packageName,
107
- remoteType: app.remoteType,
108
- source: normalizeRelativePath(node_path.relative(workspaceRoot, effectApiPath)),
109
- version: app.version,
110
- ...app.unitId ? {
111
- unitId: app.unitId
112
- } : {},
113
- ...app.sourceRevision ? {
114
- sourceRevision: app.sourceRevision
115
- } : {}
116
- }, null, 2)};
117
-
118
- export function init() {}
119
-
120
- export function get(id) {
121
- const load = exposedModules[id];
122
- if (!load) {
123
- throw new Error(\`Unexpected backend federation expose: \${id}\`);
124
- }
125
-
126
- return async () => load();
127
- }
128
-
129
- export default { get, init };
130
- `;
131
- };
132
- const createBackendManifest = (workspaceRoot, distDirectory, app)=>{
133
- const sourceModule = `${app.directory}/api/effect-api.ts`;
134
- const publicPath = `http://localhost:${app.port}/`;
135
- return {
136
- schemaVersion: 1,
137
- id: app.backendName,
138
- name: app.backendName,
139
- version: app.version,
140
- buildVersion: app.buildVersion,
141
- metaData: {
142
- name: app.backendName,
143
- type: 'backend',
144
- buildInfo: {
145
- buildVersion: app.buildVersion,
146
- buildName: app.packageName
147
- },
148
- remoteEntry: {
149
- name: BACKEND_REMOTE_ENTRY_FILE,
150
- path: '',
151
- type: app.remoteType
152
- },
153
- globalName: app.backendName,
154
- publicPath,
155
- ssrRemoteEntry: {
156
- name: BACKEND_REMOTE_ENTRY_FILE,
157
- path: '',
158
- type: app.remoteType
159
- },
160
- ssrPublicPath: publicPath
161
- },
162
- entry: {
163
- file: BACKEND_REMOTE_ENTRY_FILE,
164
- path: normalizeRelativePath(node_path.relative(workspaceRoot, node_path.join(distDirectory, BACKEND_REMOTE_ENTRY_FILE))),
165
- type: app.remoteType,
166
- url: app.containerEntry
167
- },
168
- exposes: [
169
- {
170
- id: `${app.backendName}:${BACKEND_EXPOSE}`,
171
- name: BACKEND_EXPOSE,
172
- path: '',
173
- assets: {
174
- js: {
175
- async: [],
176
- sync: [
177
- BACKEND_REMOTE_ENTRY_FILE
178
- ]
179
- },
180
- css: {
181
- async: [],
182
- sync: []
183
- }
184
- }
185
- }
186
- ],
187
- shared: [],
188
- backendFederation: {
189
- role: 'microvertical-server',
190
- name: app.backendName,
191
- runtimeFramework: 'effect',
192
- strictEffectApproach: true,
193
- contractVersion: CONTRACT_VERSION,
194
- nodeAdapterVersion: NODE_ADAPTER_VERSION,
195
- remoteType: app.remoteType,
196
- expose: BACKEND_EXPOSE,
197
- manifestUrl: app.manifestUrl,
198
- containerEntry: app.containerEntry,
199
- source: {
200
- module: sourceModule
201
- },
202
- readinessPath: `${app.apiPrefix}/${app.apiStem}/readiness`,
203
- openapiPath: `${app.apiPrefix}/openapi.json`,
204
- ...app.unitId && app.buildVersion ? {
205
- deliveryUnit: {
206
- schemaVersion: 1,
207
- kind: 'microvertical-delivery-unit',
208
- unitId: app.unitId,
209
- packageName: app.packageName,
210
- version: app.version,
211
- buildMarker: app.buildVersion,
212
- sourceRevision: app.sourceRevision
213
- }
214
- } : {},
215
- versionBoundary: {
216
- invariant: 'web-and-api-same-build',
217
- packageName: app.packageName,
218
- version: app.version,
219
- buildVersion: app.buildVersion,
220
- ...app.uiManifestUrl ? {
221
- uiManifestUrl: app.uiManifestUrl
222
- } : {},
223
- ...app.unitId && app.buildVersion ? {
224
- deliveryUnit: {
225
- unitId: app.unitId,
226
- buildMarker: app.buildVersion
227
- }
228
- } : {}
229
- }
230
- }
231
- };
232
- };
233
- const emitBackendFederationArtifacts = async (appDirectory, distDirectory)=>{
234
- const workspaceRoot = findWorkspaceRoot(appDirectory);
235
- if (!workspaceRoot) return;
236
- const effectApiPath = node_path.join(appDirectory, 'api/effect-api.ts');
237
- const backendFederationConfigPath = node_path.join(appDirectory, 'backend-federation.config.ts');
238
- if (!existsSync(effectApiPath) || !existsSync(backendFederationConfigPath)) return;
239
- const app = await findBackendFederationApp(workspaceRoot, appDirectory);
240
- if (!app) return;
241
- const buildIdentity = await readBuildIdentity(appDirectory);
242
- const compactDeliveryUnit = app.compactDeliveryUnit;
243
- const hasCompactDeliveryUnit = void 0 !== compactDeliveryUnit && (void 0 !== compactDeliveryUnit.unitId || void 0 !== compactDeliveryUnit.buildMarker || void 0 !== compactDeliveryUnit.packageName || void 0 !== compactDeliveryUnit.version);
244
- const hasBuildIdentity = void 0 !== buildIdentity.unitId || void 0 !== buildIdentity.buildVersion || void 0 !== buildIdentity.packageName || void 0 !== buildIdentity.version;
245
- if (hasCompactDeliveryUnit && hasBuildIdentity) {
246
- const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
247
- const buildModulePath = buildModulePathFor(appDirectory);
248
- const mismatches = [];
249
- const compare = (label, a, b)=>{
250
- if (void 0 !== a && void 0 !== b && a !== b) mismatches.push(`${label}: deliveryUnit=${a} vs ultramodern-build=${b}`);
251
- };
252
- compare('unitId', compactDeliveryUnit?.unitId, buildIdentity.unitId);
253
- compare('buildMarker/build', compactDeliveryUnit?.buildMarker, buildIdentity.buildVersion);
254
- compare('packageName', compactDeliveryUnit?.packageName, buildIdentity.packageName);
255
- compare('version', compactDeliveryUnit?.version, buildIdentity.version);
256
- if (mismatches.length > 0) throw new Error(`[backend-federation-build] Delivery-unit identity drift between ${compactConfigPath} (deliveryUnit) and ${buildModulePath}: ${mismatches.join('; ')}`);
257
- }
258
- const unitId = compactDeliveryUnit?.unitId ?? buildIdentity.unitId;
259
- const buildVersion = compactDeliveryUnit?.buildMarker ?? buildIdentity.buildVersion;
260
- const sourceRevision = compactDeliveryUnit?.sourceRevision ?? buildIdentity.sourceRevision;
261
- const packageName = compactDeliveryUnit?.packageName ?? buildIdentity.packageName ?? app.packageName;
262
- const version = compactDeliveryUnit?.version ?? buildIdentity.version;
263
- const resolvedApp = {
264
- ...app,
265
- packageName,
266
- version,
267
- buildVersion,
268
- unitId,
269
- sourceRevision
270
- };
271
- const manifestPath = node_path.join(distDirectory, BACKEND_MANIFEST_FILE);
272
- const entryPath = node_path.join(distDirectory, BACKEND_REMOTE_ENTRY_FILE);
273
- await promises.mkdir(distDirectory, {
274
- recursive: true
275
- });
276
- await promises.writeFile(entryPath, createBackendRemoteEntrySource(workspaceRoot, resolvedApp, effectApiPath, entryPath));
277
- await promises.writeFile(manifestPath, `${JSON.stringify(createBackendManifest(workspaceRoot, distDirectory, resolvedApp), null, 2)}\n`);
278
- return {
279
- appId: resolvedApp.id,
280
- manifestPath,
281
- containerPath: entryPath,
282
- remoteName: resolvedApp.backendName,
283
- remoteType: resolvedApp.remoteType
284
- };
285
- };
286
- const backendFederationBuild = ()=>({
287
- name: '@modern-js/backend-federation-build',
288
- setup (api) {
289
- api.onAfterBuild(async ()=>{
290
- const { appDirectory, distDirectory } = api.getAppContext();
291
- await emitBackendFederationArtifacts(appDirectory, distDirectory);
292
- });
293
- }
294
- });
295
- export default backendFederationBuild;
296
- export { emitBackendFederationArtifacts };
1
+ export { default, emitBackendFederationArtifacts } from "./backend-federation/emit.mjs";
@@ -0,0 +1,64 @@
1
+ import node_path from "node:path";
2
+ import { fs } from "@modern-js/utils";
3
+ import { RESERVED_ARTIFACT_DESTINATION_DIRECTORIES, RESERVED_ARTIFACT_DESTINATION_FILES, ROUTE_SPEC_OUTPUT } from "./constants.mjs";
4
+ import { normalizeRelativePath } from "./utils.mjs";
5
+ const normalizeCloudflareArtifact = (artifact, index)=>{
6
+ const from = normalizeRelativePath(artifact.from, `deploy.worker.artifacts[${index}].from`, 'app root');
7
+ const to = normalizeRelativePath(artifact.to, `deploy.worker.artifacts[${index}].to`, 'Cloudflare output');
8
+ const [topLevelDestination] = to.split('/');
9
+ const reservedDestination = RESERVED_ARTIFACT_DESTINATION_FILES.has(to) ? to : topLevelDestination;
10
+ 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)}.`);
11
+ return {
12
+ from,
13
+ to,
14
+ index
15
+ };
16
+ };
17
+ const getCloudflareArtifacts = (modernConfig)=>(modernConfig.deploy?.worker?.artifacts ?? []).map(normalizeCloudflareArtifact);
18
+ const normalizeCloudflarePublicAsset = (asset, index)=>{
19
+ const from = normalizeRelativePath(asset.from, `deploy.worker.publicAssets[${index}].from`, 'app root');
20
+ const to = normalizeRelativePath(asset.to, `deploy.worker.publicAssets[${index}].to`, 'Cloudflare public output', {
21
+ allowRoot: true
22
+ });
23
+ return {
24
+ from,
25
+ to,
26
+ index
27
+ };
28
+ };
29
+ const getCloudflarePublicAssets = (modernConfig)=>(modernConfig.deploy?.worker?.publicAssets ?? []).map(normalizeCloudflarePublicAsset);
30
+ const copyCloudflareArtifacts = async (appDirectory, outputDirectory, artifacts)=>{
31
+ for (const artifact of artifacts){
32
+ const sourcePath = node_path.join(appDirectory, artifact.from);
33
+ if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.artifacts[${artifact.index}].from does not exist: ${artifact.from}`);
34
+ await fs.copy(sourcePath, node_path.join(outputDirectory, artifact.to));
35
+ }
36
+ };
37
+ const copyCloudflarePublicAssets = async (appDirectory, publicDirectory, publicAssets)=>{
38
+ for (const asset of publicAssets){
39
+ const sourcePath = node_path.join(appDirectory, asset.from);
40
+ if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.publicAssets[${asset.index}].from does not exist: ${asset.from}`);
41
+ await fs.copy(sourcePath, node_path.join(publicDirectory, asset.to));
42
+ }
43
+ };
44
+ const copyCloudflareD1Migrations = async (appDirectory, outputDirectory, modernConfig)=>{
45
+ for (const [index, database] of (modernConfig.deploy?.worker?.d1Databases ?? []).entries()){
46
+ if (!database.migrationsDir) continue;
47
+ const migrationsDir = normalizeRelativePath(database.migrationsDir, `deploy.worker.d1Databases[${index}].migrationsDir`, 'app root');
48
+ const sourcePath = node_path.join(appDirectory, migrationsDir);
49
+ if (!await fs.pathExists(sourcePath)) throw new Error(`deploy.worker.d1Databases[${index}].migrationsDir does not exist: ${migrationsDir}`);
50
+ await fs.copy(sourcePath, node_path.join(outputDirectory, migrationsDir));
51
+ }
52
+ };
53
+ const readRouteSpec = async (outputDirectory)=>{
54
+ const routeSpecPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
55
+ if (!await fs.pathExists(routeSpecPath)) return {
56
+ routes: []
57
+ };
58
+ const routeSpec = await fs.readJSON(routeSpecPath);
59
+ return {
60
+ ...routeSpec,
61
+ routes: Array.isArray(routeSpec.routes) ? routeSpec.routes : []
62
+ };
63
+ };
64
+ export { copyCloudflareArtifacts, copyCloudflareD1Migrations, copyCloudflarePublicAssets, getCloudflareArtifacts, getCloudflarePublicAssets, readRouteSpec };
@@ -0,0 +1,33 @@
1
+ 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";
2
+ const WORKER_ENTRY = CLOUDFLARE_WORKER_ENTRY;
3
+ const WORKER_MANIFEST = CLOUDFLARE_WORKER_MANIFEST;
4
+ const WRANGLER_CONFIG_FILE = CLOUDFLARE_WRANGLER_CONFIG_FILE;
5
+ const OUTPUT_PACKAGE_FILE = CLOUDFLARE_OUTPUT_PACKAGE_FILE;
6
+ const ASSETS_BINDING = CLOUDFLARE_ASSETS_BINDING;
7
+ const ROUTE_SPEC_FILE = 'route.json';
8
+ const ROUTE_SPEC_OUTPUT = `server/${ROUTE_SPEC_FILE}`;
9
+ const LOADABLE_STATS_FILE = 'loadable-stats.json';
10
+ const ROUTE_MANIFEST_FILE = 'routes-manifest.json';
11
+ const PUBLIC_ASSETS_DIRECTORY = CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY;
12
+ const WORKER_BUNDLE_DIRECTORY = CLOUDFLARE_WORKER_BUNDLE_DIRECTORY;
13
+ const SERVER_BUNDLE_DIRECTORY = 'bundles';
14
+ const SERVER_OUTPUT_DIRECTORY = 'server';
15
+ const DEFAULT_SERVER_ONLY_PUBLIC_ASSET_EXCLUDES = [
16
+ 'api',
17
+ 'shared'
18
+ ];
19
+ const BFF_EFFECT_WORKER_ENTRY = `${WORKER_BUNDLE_DIRECTORY}/__modern_bff_effect.js`;
20
+ 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.';
21
+ const DEFAULT_COMPATIBILITY_DATE = '2026-06-02';
22
+ const COMPATIBILITY_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
23
+ const REQUIRED_COMPATIBILITY_FLAGS = CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS;
24
+ const RESERVED_ARTIFACT_DESTINATION_FILES = new Set([
25
+ WRANGLER_CONFIG_FILE,
26
+ OUTPUT_PACKAGE_FILE
27
+ ]);
28
+ const RESERVED_ARTIFACT_DESTINATION_DIRECTORIES = new Set([
29
+ PUBLIC_ASSETS_DIRECTORY,
30
+ SERVER_OUTPUT_DIRECTORY,
31
+ WORKER_BUNDLE_DIRECTORY
32
+ ]);
33
+ 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,67 @@
1
+ import node_path from "node:path";
2
+ import { fs } from "@modern-js/utils";
3
+ import { ULTRAMODERN_BUILD_ARTIFACT_PATH, ULTRAMODERN_BUILD_MODULE_PATH, isUltramodernBuildArtifact, nonEmptyString, toDeliveryUnitIdentity } from "@modern-js/utils/universal";
4
+ import { isRecord } from "./utils.mjs";
5
+ const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
6
+ const findWorkspaceRoot = async (appDirectory)=>{
7
+ let current = node_path.resolve(appDirectory);
8
+ for(;;){
9
+ if (await fs.pathExists(node_path.join(current, COMPACT_CONFIG_PATH))) return current;
10
+ const parent = node_path.dirname(current);
11
+ if (parent === current) return;
12
+ current = parent;
13
+ }
14
+ };
15
+ const resolveTopologyDeliveryUnit = async (appDirectory)=>{
16
+ const workspaceRoot = await findWorkspaceRoot(appDirectory);
17
+ if (!workspaceRoot) return;
18
+ let compactConfig;
19
+ try {
20
+ compactConfig = await fs.readJSON(node_path.join(workspaceRoot, COMPACT_CONFIG_PATH));
21
+ } catch {
22
+ return;
23
+ }
24
+ if (!isRecord(compactConfig)) return;
25
+ const topology = isRecord(compactConfig.topology) ? compactConfig.topology : void 0;
26
+ const apps = Array.isArray(topology?.apps) ? topology.apps : [];
27
+ const resolvedAppDirectory = node_path.resolve(appDirectory);
28
+ for (const app of apps){
29
+ if (!isRecord(app)) continue;
30
+ const appPath = nonEmptyString(app.path);
31
+ if (appPath && node_path.resolve(workspaceRoot, appPath.replace(/^\.\/+/u, '')) === resolvedAppDirectory) return toDeliveryUnitIdentity(app.deliveryUnit);
32
+ }
33
+ return toDeliveryUnitIdentity(compactConfig.deliveryUnit);
34
+ };
35
+ const resolveWorkerDeliveryUnitStamp = async (appDirectory)=>{
36
+ const buildArtifactPath = node_path.join(appDirectory, ULTRAMODERN_BUILD_ARTIFACT_PATH);
37
+ const buildModulePath = node_path.join(appDirectory, ULTRAMODERN_BUILD_MODULE_PATH);
38
+ let identity;
39
+ if (await fs.pathExists(buildArtifactPath)) {
40
+ const artifact = await fs.readJSON(buildArtifactPath);
41
+ if (!isUltramodernBuildArtifact(artifact)) return;
42
+ identity = toDeliveryUnitIdentity(artifact.deliveryUnit);
43
+ } else if (await fs.pathExists(buildModulePath)) {
44
+ console.warn(`[cloudflare] ${buildArtifactPath} missing; falling back to legacy regex parsing of ${buildModulePath}. Regenerate the workspace to emit ultramodern-build.json.`);
45
+ const source = await fs.readFile(buildModulePath, 'utf8');
46
+ identity = toDeliveryUnitIdentity({
47
+ buildMarker: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
48
+ unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
49
+ sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
50
+ });
51
+ }
52
+ if (!identity) return;
53
+ return {
54
+ ...identity,
55
+ surfaces: {
56
+ ui: {
57
+ ...identity,
58
+ surface: 'ui'
59
+ },
60
+ api: {
61
+ ...identity,
62
+ surface: 'api'
63
+ }
64
+ }
65
+ };
66
+ };
67
+ export { resolveTopologyDeliveryUnit, resolveWorkerDeliveryUnitStamp };
@@ -0,0 +1,97 @@
1
+ import { isRecord } from "./utils.mjs";
2
+ const I18N_SERVER_PLUGIN_NAME = 'plugin-i18n/server';
3
+ const DEFAULT_I18NEXT_DETECTION_OPTIONS = {
4
+ order: [
5
+ 'querystring',
6
+ 'cookie',
7
+ 'localStorage',
8
+ 'header',
9
+ 'navigator',
10
+ 'htmlTag',
11
+ 'path',
12
+ 'subdomain'
13
+ ],
14
+ lookupQuerystring: 'lng',
15
+ lookupCookie: 'i18next',
16
+ lookupHeader: 'accept-language'
17
+ };
18
+ const SERVER_SIDE_I18N_DETECTORS = new Set([
19
+ 'querystring',
20
+ 'cookie',
21
+ 'header'
22
+ ]);
23
+ const toStringArray = (value)=>Array.isArray(value) ? value.filter((entry)=>'string' == typeof entry) : [];
24
+ const getI18nServerPlugin = (appContext)=>appContext.serverPlugins?.find((plugin)=>plugin.name.includes(I18N_SERVER_PLUGIN_NAME));
25
+ const removeLocaleDetectionByEntry = (config)=>{
26
+ const { localeDetectionByEntry: _localeDetectionByEntry, ...rest } = config;
27
+ return rest;
28
+ };
29
+ const getEntryLocaleDetection = (entryName, localeDetection)=>{
30
+ const byEntry = isRecord(localeDetection.localeDetectionByEntry) ? localeDetection.localeDetectionByEntry : void 0;
31
+ const entryConfig = byEntry?.[entryName];
32
+ const globalConfig = removeLocaleDetectionByEntry(localeDetection);
33
+ return isRecord(entryConfig) ? {
34
+ ...globalConfig,
35
+ ...entryConfig
36
+ } : globalConfig;
37
+ };
38
+ const normalizeI18nDetection = (detection)=>{
39
+ const configured = isRecord(detection) ? detection : {};
40
+ const rawOrder = Array.isArray(configured.order) ? configured.order : DEFAULT_I18NEXT_DETECTION_OPTIONS.order;
41
+ const order = rawOrder.filter((entry)=>'string' == typeof entry && SERVER_SIDE_I18N_DETECTORS.has(entry));
42
+ return {
43
+ order: order.length > 0 ? order : [
44
+ 'querystring',
45
+ 'cookie',
46
+ 'header'
47
+ ],
48
+ lookupQuerystring: 'string' == typeof configured.lookupQuerystring && configured.lookupQuerystring ? configured.lookupQuerystring : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupQuerystring,
49
+ lookupCookie: 'string' == typeof configured.lookupCookie && configured.lookupCookie ? configured.lookupCookie : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupCookie,
50
+ lookupHeader: 'string' == typeof configured.lookupHeader && configured.lookupHeader ? configured.lookupHeader : DEFAULT_I18NEXT_DETECTION_OPTIONS.lookupHeader
51
+ };
52
+ };
53
+ const normalizeLocalisedUrls = (localisedUrls)=>{
54
+ if (!isRecord(localisedUrls) || 0 === Object.keys(localisedUrls).length) return;
55
+ const normalized = {};
56
+ for (const [canonicalPath, languageMap] of Object.entries(localisedUrls)){
57
+ if (!isRecord(languageMap)) continue;
58
+ const normalizedLanguageMap = Object.fromEntries(Object.entries(languageMap).filter((entry)=>'string' == typeof entry[1] && entry[1].length > 0));
59
+ if (Object.keys(normalizedLanguageMap).length > 0) normalized[canonicalPath] = normalizedLanguageMap;
60
+ }
61
+ return Object.keys(normalized).length > 0 ? normalized : void 0;
62
+ };
63
+ const normalizeWorkerI18nEntry = (entryName, localeDetection, staticRoutePrefixes)=>{
64
+ const entryConfig = getEntryLocaleDetection(entryName, localeDetection);
65
+ const languages = toStringArray(entryConfig.languages);
66
+ if (true !== entryConfig.localePathRedirect || 0 === languages.length) return;
67
+ const fallbackLanguage = 'string' == typeof entryConfig.fallbackLanguage && entryConfig.fallbackLanguage ? entryConfig.fallbackLanguage : 'en';
68
+ const ignoreRedirectRoutes = Array.isArray(entryConfig.ignoreRedirectRoutes) ? toStringArray(entryConfig.ignoreRedirectRoutes) : [];
69
+ const localisedUrls = normalizeLocalisedUrls(entryConfig.localisedUrls);
70
+ return {
71
+ i18nextDetector: false !== entryConfig.i18nextDetector,
72
+ languages,
73
+ fallbackLanguage,
74
+ detection: normalizeI18nDetection(entryConfig.detection),
75
+ ignoreRedirectRoutes,
76
+ staticRoutePrefixes,
77
+ ...localisedUrls ? {
78
+ localisedUrls
79
+ } : {}
80
+ };
81
+ };
82
+ const createI18nWorkerManifest = (routeSpec, appContext)=>{
83
+ const i18nServerPlugin = getI18nServerPlugin(appContext);
84
+ const localeDetection = i18nServerPlugin?.options?.localeDetection;
85
+ if (!isRecord(localeDetection)) return;
86
+ const staticRoutePrefixes = toStringArray(i18nServerPlugin?.options?.staticRoutePrefixes);
87
+ const entries = {};
88
+ for (const route of routeSpec.routes){
89
+ if ('string' != typeof route.entryName || entries[route.entryName]) continue;
90
+ const entry = normalizeWorkerI18nEntry(route.entryName, localeDetection, staticRoutePrefixes);
91
+ if (entry) entries[route.entryName] = entry;
92
+ }
93
+ return Object.keys(entries).length > 0 ? {
94
+ entries
95
+ } : void 0;
96
+ };
97
+ export { createI18nWorkerManifest };
@@ -0,0 +1,78 @@
1
+ import node_path from "node:path";
2
+ import { fs } from "@modern-js/utils";
3
+ import { readTemplate } from "../../utils/index.mjs";
4
+ import { createCloudflareOutputPlan } from "../cloudflare-output-plan.mjs";
5
+ import { assertCloudflareOutput } from "../cloudflare-output-verifier.mjs";
6
+ import { copyCloudflareArtifacts, copyCloudflareD1Migrations, copyCloudflarePublicAssets, getCloudflareArtifacts, getCloudflarePublicAssets } from "./artifacts.mjs";
7
+ import { ROUTE_SPEC_FILE, ROUTE_SPEC_OUTPUT, WORKER_BUNDLE_DIRECTORY } from "./constants.mjs";
8
+ import { resolveTopologyDeliveryUnit, resolveWorkerDeliveryUnitStamp } from "./delivery-unit.mjs";
9
+ import { createWorkerManifest, createWorkerModuleLoaders, getPublicAssetExcludes, shouldCopyToPublicAssets, shouldCopyToWorkerBundle } from "./worker-manifest.mjs";
10
+ import { createWranglerConfig } from "./wrangler-config.mjs";
11
+ const CLOUDFLARE_ENTRY_TEMPLATE_FRAGMENTS = [
12
+ 'cloudflare-entry.001-bootstrap-security.mjs',
13
+ 'cloudflare-entry.002-assets-routes.mjs',
14
+ 'cloudflare-entry.003-i18n-locales.mjs',
15
+ 'cloudflare-entry.004-rendering-css.mjs',
16
+ 'cloudflare-entry.005-worker-dispatch.mjs',
17
+ 'cloudflare-entry.006-fetch-handler.mjs'
18
+ ];
19
+ const readCloudflareEntryTemplate = async ()=>(await Promise.all(CLOUDFLARE_ENTRY_TEMPLATE_FRAGMENTS.map((fragment)=>readTemplate(fragment)))).join('');
20
+ const createCloudflarePreset = ({ appContext, modernConfig })=>{
21
+ const { appDirectory, distDirectory } = appContext;
22
+ const outputDirectory = node_path.join(appDirectory, '.output');
23
+ const outputPlan = createCloudflareOutputPlan(outputDirectory);
24
+ const publicDirectory = outputPlan.paths.publicAssets;
25
+ const workerEntryPath = outputPlan.paths.workerEntry;
26
+ const workerManifestPath = outputPlan.paths.workerManifest;
27
+ const routeSpecOutputPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
28
+ const wranglerConfigPath = outputPlan.paths.wranglerConfig;
29
+ const cloudflareArtifacts = getCloudflareArtifacts(modernConfig);
30
+ const publicAssetExcludes = getPublicAssetExcludes(appDirectory, modernConfig);
31
+ return {
32
+ async prepare () {
33
+ await fs.remove(outputDirectory);
34
+ },
35
+ async writeOutput () {
36
+ await fs.copy(distDirectory, publicDirectory, {
37
+ filter: (src)=>shouldCopyToPublicAssets(src, distDirectory, publicAssetExcludes)
38
+ });
39
+ await fs.ensureDir(node_path.dirname(workerEntryPath));
40
+ await fs.ensureDir(node_path.dirname(workerManifestPath));
41
+ const routeSpecSourcePath = node_path.join(distDirectory, ROUTE_SPEC_FILE);
42
+ if (await fs.pathExists(routeSpecSourcePath)) await fs.copy(routeSpecSourcePath, routeSpecOutputPath);
43
+ const workerBundleSourceDirectory = node_path.join(distDirectory, WORKER_BUNDLE_DIRECTORY);
44
+ const workerBundleOutputDirectory = outputPlan.paths.workerBundle;
45
+ if (await fs.pathExists(workerBundleSourceDirectory)) {
46
+ await fs.copy(workerBundleSourceDirectory, workerBundleOutputDirectory, {
47
+ filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
48
+ });
49
+ await fs.writeJSON(outputPlan.paths.workerPackage, outputPlan.packages.worker);
50
+ }
51
+ await copyCloudflareArtifacts(appDirectory, outputDirectory, cloudflareArtifacts);
52
+ await copyCloudflarePublicAssets(appDirectory, publicDirectory, getCloudflarePublicAssets(modernConfig));
53
+ await copyCloudflareD1Migrations(appDirectory, outputDirectory, modernConfig);
54
+ await fs.writeJSON(wranglerConfigPath, createWranglerConfig(appDirectory, modernConfig), {
55
+ spaces: 2
56
+ });
57
+ const deliveryUnitStamp = await resolveWorkerDeliveryUnitStamp(appDirectory);
58
+ await fs.writeJSON(workerManifestPath, await createWorkerManifest(outputDirectory, modernConfig, appContext, deliveryUnitStamp), {
59
+ spaces: 2
60
+ });
61
+ await fs.writeJSON(outputPlan.paths.outputPackage, outputPlan.packages.output);
62
+ },
63
+ async genEntry () {
64
+ const template = await readCloudflareEntryTemplate();
65
+ const manifest = await fs.readJSON(workerManifestPath);
66
+ await fs.writeFile(workerEntryPath, template.replace('p_workerManifest', JSON.stringify(manifest, null, 2)).replace('p_workerModuleLoaders', createWorkerModuleLoaders(manifest)));
67
+ const topologyDeliveryUnit = await resolveTopologyDeliveryUnit(appDirectory);
68
+ await assertCloudflareOutput({
69
+ outputDirectory,
70
+ importWorker: false,
71
+ ...topologyDeliveryUnit ? {
72
+ deliveryUnit: topologyDeliveryUnit
73
+ } : {}
74
+ });
75
+ }
76
+ };
77
+ };
78
+ export { createCloudflarePreset };