@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.27 → 3.5.0-ultramodern.29

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 (28) hide show
  1. package/dist/cjs/index.js +50 -44
  2. package/dist/cjs/plugins/backendFederationBuild.js +347 -0
  3. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +91 -0
  4. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +93 -0
  5. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier.js +402 -0
  6. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +158 -30
  7. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +30 -19
  8. package/dist/esm/index.mjs +2 -0
  9. package/dist/esm/plugins/backendFederationBuild.mjs +296 -0
  10. package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +17 -0
  11. package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +45 -0
  12. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier.mjs +347 -0
  13. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +158 -30
  14. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +30 -19
  15. package/dist/esm-node/index.mjs +2 -0
  16. package/dist/esm-node/plugins/backendFederationBuild.mjs +297 -0
  17. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +18 -0
  18. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +46 -0
  19. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier.mjs +348 -0
  20. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +158 -30
  21. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +30 -19
  22. package/dist/types/plugins/backendFederationBuild.d.ts +11 -0
  23. package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +13 -0
  24. package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +33 -0
  25. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier.d.ts +32 -0
  26. package/dist/types/types/config/cloudflareDeploy.d.ts +11 -0
  27. package/dist/types/types/config/deploy.d.ts +11 -3
  28. package/package.json +17 -11
@@ -2,7 +2,7 @@ const ASSETS_BINDING = 'ASSETS';
2
2
  const MODERN_WORKER_MANIFEST = p_workerManifest;
3
3
  const WORKER_MODULE_LOADERS = p_workerModuleLoaders;
4
4
  const workerModulePromises = new Map();
5
- const effectBffHandlerPromises = new Map();
5
+ const effectBffDispatcherPromises = new Map();
6
6
  let effectEdgeRuntimePromise;
7
7
  const remoteJsonPromises = new Map();
8
8
  const CORS_POLICY = MODERN_WORKER_MANIFEST.security?.cors || {};
@@ -152,17 +152,7 @@ async function createCorsPreflightResponse(request, env) {
152
152
  status: 204
153
153
  });
154
154
  }
155
- if (!ASSET_CORS_ENABLED) return null;
156
- const assets = env?.[ASSETS_BINDING];
157
- if (!assets || 'function' != typeof assets.fetch) return null;
158
- const assetResponse = await assets.fetch(new Request(request.url, {
159
- method: 'HEAD'
160
- }));
161
- if (!assetResponse || 404 === assetResponse.status) return null;
162
- return new Response(null, {
163
- headers: ASSET_CORS_HEADERS,
164
- status: 204
165
- });
155
+ return null;
166
156
  }
167
157
  async function fetchAsset(request, env) {
168
158
  if ('GET' !== request.method && 'HEAD' !== request.method) return null;
@@ -798,17 +788,17 @@ async function dispatchBffRequest(request, env) {
798
788
  const defaultExport = workerModule.default;
799
789
  const runtime = getRuntimeModule(workerModule);
800
790
  if ('effect' === bff.runtimeFramework) {
801
- let effectHandlerPromise = effectBffHandlerPromises.get(bff.worker);
802
- if (!effectHandlerPromise) {
803
- const { createEffectBffEdgeHandler } = await loadEffectEdgeRuntime();
804
- effectHandlerPromise = createEffectBffEdgeHandler({
791
+ let effectDispatcherPromise = effectBffDispatcherPromises.get(bff.worker);
792
+ if (!effectDispatcherPromise) {
793
+ const { createEffectBffEdgeDispatcher } = await loadEffectEdgeRuntime();
794
+ effectDispatcherPromise = createEffectBffEdgeDispatcher({
805
795
  module: runtime,
806
796
  prefix: bff.prefix
807
797
  });
808
- effectBffHandlerPromises.set(bff.worker, effectHandlerPromise);
798
+ effectBffDispatcherPromises.set(bff.worker, effectDispatcherPromise);
809
799
  }
810
- const effectHandler = await effectHandlerPromise;
811
- return effectHandler.handler(request, {
800
+ const effectDispatcher = await effectDispatcherPromise;
801
+ return effectDispatcher.dispatch(request, {
812
802
  env
813
803
  });
814
804
  }
@@ -836,12 +826,33 @@ async function dispatchBffRequest(request, env) {
836
826
  };
837
827
  return handler(mountedRequest, effectContext);
838
828
  }
829
+ async function dispatchServiceBindingRequest(request, env) {
830
+ const serviceBindings = MODERN_WORKER_MANIFEST.serviceBindings;
831
+ if (!Array.isArray(serviceBindings) || 0 === serviceBindings.length) return null;
832
+ const pathname = new URL(request.url).pathname;
833
+ for (const binding of serviceBindings){
834
+ if (!binding?.binding || !binding?.prefix) continue;
835
+ if (!matchesPrefix(pathname, binding.prefix)) continue;
836
+ const service = env?.[binding.binding];
837
+ if (!service || 'function' != typeof service.fetch) return new Response(`Cloudflare service binding not available: ${binding.binding}`, {
838
+ status: 502,
839
+ headers: {
840
+ 'content-type': 'text/plain; charset=utf-8',
841
+ 'x-modern-js-service-binding': binding.binding
842
+ }
843
+ });
844
+ return service.fetch(request);
845
+ }
846
+ return null;
847
+ }
839
848
  export default {
840
849
  async fetch (request, env, ctx) {
841
850
  const corsPreflightResponse = await createCorsPreflightResponse(request, env);
842
851
  if (corsPreflightResponse) return finalizeResponseForRequest(corsPreflightResponse, request);
843
852
  const bffResponse = await dispatchBffRequest(request, env);
844
853
  if (bffResponse) return finalizeResponseForRequest(withAppCorsHeaders(bffResponse, request), request);
854
+ const serviceBindingResponse = await dispatchServiceBindingRequest(request, env);
855
+ if (serviceBindingResponse) return finalizeResponseForRequest(withAppCorsHeaders(serviceBindingResponse, request), request);
845
856
  const route = findRoute(request);
846
857
  const { pathname } = new URL(request.url);
847
858
  if (isAssetLikePathname(pathname) && !routeMatchesExactly(route, pathname)) {
@@ -10,6 +10,7 @@ import { compatPlugin } from "./compat/index.mjs";
10
10
  import { DEFAULT_RUNTIME_CONFIG_FILE } from "./constants.mjs";
11
11
  import { i18n } from "./locale/index.mjs";
12
12
  import analyze from "./plugins/analyze/index.mjs";
13
+ import backendFederationBuild from "./plugins/backendFederationBuild.mjs";
13
14
  import deploy from "./plugins/deploy/index.mjs";
14
15
  import initialize from "./plugins/initialize/index.mjs";
15
16
  import serverBuild from "./plugins/serverBuild.mjs";
@@ -30,6 +31,7 @@ const appTools = ()=>({
30
31
  initialize(),
31
32
  analyze(),
32
33
  serverBuild(),
34
+ backendFederationBuild(),
33
35
  deploy()
34
36
  ],
35
37
  post: [
@@ -0,0 +1,297 @@
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
+ const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
6
+ const BACKEND_MANIFEST_FILE = 'backend-mf-manifest.json';
7
+ const BACKEND_REMOTE_ENTRY_FILE = 'backendRemoteEntry.mjs';
8
+ const CONTRACT_VERSION = 'microvertical-server-effect-v1';
9
+ const NODE_ADAPTER_VERSION = 'backend-mf-effect-v1';
10
+ const BACKEND_EXPOSE = './effect-api';
11
+ const normalizeRelativePath = (value)=>value.replace(/\\/gu, '/').replace(/^\.\/+/u, '');
12
+ const isRecord = (value)=>'object' == typeof value && null !== value;
13
+ const readJsonFile = async (filePath)=>JSON.parse(await promises.readFile(filePath, 'utf8'));
14
+ const buildModulePathFor = (appDirectory)=>node_path.join(appDirectory, 'shared/ultramodern-build.ts');
15
+ const readBuildIdentity = async (appDirectory)=>{
16
+ const buildModulePath = buildModulePathFor(appDirectory);
17
+ if (!existsSync(buildModulePath)) return {};
18
+ const source = await promises.readFile(buildModulePath, 'utf8');
19
+ return {
20
+ buildVersion: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
21
+ packageName: source.match(/\bpackageName:\s*['"]([^'"]+)['"]/u)?.[1],
22
+ version: source.match(/\bversion:\s*['"]([^'"]+)['"]/u)?.[1],
23
+ unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
24
+ sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
25
+ };
26
+ };
27
+ const toPascalCase = (value)=>value.split(/[^a-zA-Z0-9]+/u).filter(Boolean).map((part)=>part.charAt(0).toUpperCase() + part.slice(1)).join('');
28
+ const stringValue = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
29
+ const createBackendName = (app, id)=>{
30
+ const configuredName = stringValue(app.backendFederation?.name) ?? stringValue(app.backendFederation?.executionSurfaces?.node?.remoteName) ?? stringValue(app.serverExecution?.node?.remoteName);
31
+ if (configuredName) return configuredName;
32
+ const mfName = stringValue(app.moduleFederation?.name);
33
+ return mfName ? `${mfName}Backend` : `vertical${toPascalCase(id)}Backend`;
34
+ };
35
+ const findWorkspaceRoot = (appDirectory)=>{
36
+ let current = appDirectory;
37
+ while(true){
38
+ if (existsSync(node_path.join(current, COMPACT_CONFIG_PATH))) return current;
39
+ const parent = node_path.dirname(current);
40
+ if (parent === current) return;
41
+ current = parent;
42
+ }
43
+ };
44
+ const createAppFromCompactMetadata = (workspaceRoot, appDirectory, compactApp)=>{
45
+ const id = stringValue(compactApp.id);
46
+ const appPath = stringValue(compactApp.path);
47
+ if (!id || 'vertical' !== compactApp.kind || !isRecord(compactApp.api)) return;
48
+ const directory = appPath ? normalizeRelativePath(appPath) : `verticals/${id}`;
49
+ if (node_path.resolve(workspaceRoot, directory) !== node_path.resolve(appDirectory)) return;
50
+ const port = 'number' == typeof compactApp.port ? compactApp.port : void 0;
51
+ if (void 0 === port) return;
52
+ const apiPrefix = stringValue(compactApp.api.prefix) ?? `/${id}-api`;
53
+ const apiStem = stringValue(compactApp.api.stem) ?? id;
54
+ const backendName = createBackendName(compactApp, id);
55
+ const manifestUrl = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.manifestUrl) ?? stringValue(compactApp.serverExecution?.node?.manifestUrl) ?? `http://localhost:${port}/${BACKEND_MANIFEST_FILE}`;
56
+ const containerEntry = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.containerEntry) ?? stringValue(compactApp.serverExecution?.node?.containerEntry) ?? `http://localhost:${port}/${BACKEND_REMOTE_ENTRY_FILE}`;
57
+ const remoteType = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.remoteType) ?? stringValue(compactApp.serverExecution?.node?.remoteType) ?? 'module';
58
+ const packageName = stringValue(compactApp.package);
59
+ const uiManifestUrl = stringValue(compactApp.backendFederation?.versionBoundary?.ui?.manifestUrl) ?? stringValue(compactApp.moduleFederation?.manifestUrl);
60
+ const compactDeliveryUnit = isRecord(compactApp.deliveryUnit) ? {
61
+ unitId: stringValue(compactApp.deliveryUnit.unitId),
62
+ buildMarker: stringValue(compactApp.deliveryUnit.buildMarker),
63
+ sourceRevision: stringValue(compactApp.deliveryUnit.sourceRevision),
64
+ packageName: stringValue(compactApp.deliveryUnit.packageName),
65
+ version: stringValue(compactApp.deliveryUnit.version)
66
+ } : void 0;
67
+ return {
68
+ id,
69
+ directory,
70
+ packageName,
71
+ port,
72
+ apiPrefix,
73
+ apiStem,
74
+ backendName,
75
+ manifestUrl,
76
+ containerEntry,
77
+ remoteType,
78
+ uiManifestUrl,
79
+ compactDeliveryUnit
80
+ };
81
+ };
82
+ const findBackendFederationApp = async (workspaceRoot, appDirectory)=>{
83
+ const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
84
+ const compactConfig = await readJsonFile(compactConfigPath);
85
+ const apps = Array.isArray(compactConfig.topology?.apps) ? compactConfig.topology.apps : [];
86
+ for (const app of apps){
87
+ const resolved = createAppFromCompactMetadata(workspaceRoot, appDirectory, app);
88
+ if (resolved) return resolved;
89
+ }
90
+ };
91
+ const createRelativeImportSpecifier = (fromDirectory, toFile)=>{
92
+ const relativePath = normalizeRelativePath(node_path.relative(fromDirectory, toFile));
93
+ return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
94
+ };
95
+ const createBackendRemoteEntrySource = (workspaceRoot, app, effectApiPath, entryPath)=>{
96
+ const effectApiSpecifier = createRelativeImportSpecifier(node_path.dirname(entryPath), effectApiPath);
97
+ return `// Generated by Modern.js backend federation build.
98
+ const exposedModules = {
99
+ ${JSON.stringify(BACKEND_EXPOSE)}: () =>
100
+ import(new URL(${JSON.stringify(effectApiSpecifier)}, import.meta.url).href),
101
+ };
102
+
103
+ export const __modernjsBackendFederation = ${JSON.stringify({
104
+ buildVersion: app.buildVersion,
105
+ expose: BACKEND_EXPOSE,
106
+ name: app.backendName,
107
+ packageName: app.packageName,
108
+ remoteType: app.remoteType,
109
+ source: normalizeRelativePath(node_path.relative(workspaceRoot, effectApiPath)),
110
+ version: app.version,
111
+ ...app.unitId ? {
112
+ unitId: app.unitId
113
+ } : {},
114
+ ...app.sourceRevision ? {
115
+ sourceRevision: app.sourceRevision
116
+ } : {}
117
+ }, null, 2)};
118
+
119
+ export function init() {}
120
+
121
+ export function get(id) {
122
+ const load = exposedModules[id];
123
+ if (!load) {
124
+ throw new Error(\`Unexpected backend federation expose: \${id}\`);
125
+ }
126
+
127
+ return async () => load();
128
+ }
129
+
130
+ export default { get, init };
131
+ `;
132
+ };
133
+ const createBackendManifest = (workspaceRoot, distDirectory, app)=>{
134
+ const sourceModule = `${app.directory}/api/effect-api.ts`;
135
+ const publicPath = `http://localhost:${app.port}/`;
136
+ return {
137
+ schemaVersion: 1,
138
+ id: app.backendName,
139
+ name: app.backendName,
140
+ version: app.version,
141
+ buildVersion: app.buildVersion,
142
+ metaData: {
143
+ name: app.backendName,
144
+ type: 'backend',
145
+ buildInfo: {
146
+ buildVersion: app.buildVersion,
147
+ buildName: app.packageName
148
+ },
149
+ remoteEntry: {
150
+ name: BACKEND_REMOTE_ENTRY_FILE,
151
+ path: '',
152
+ type: app.remoteType
153
+ },
154
+ globalName: app.backendName,
155
+ publicPath,
156
+ ssrRemoteEntry: {
157
+ name: BACKEND_REMOTE_ENTRY_FILE,
158
+ path: '',
159
+ type: app.remoteType
160
+ },
161
+ ssrPublicPath: publicPath
162
+ },
163
+ entry: {
164
+ file: BACKEND_REMOTE_ENTRY_FILE,
165
+ path: normalizeRelativePath(node_path.relative(workspaceRoot, node_path.join(distDirectory, BACKEND_REMOTE_ENTRY_FILE))),
166
+ type: app.remoteType,
167
+ url: app.containerEntry
168
+ },
169
+ exposes: [
170
+ {
171
+ id: `${app.backendName}:${BACKEND_EXPOSE}`,
172
+ name: BACKEND_EXPOSE,
173
+ path: '',
174
+ assets: {
175
+ js: {
176
+ async: [],
177
+ sync: [
178
+ BACKEND_REMOTE_ENTRY_FILE
179
+ ]
180
+ },
181
+ css: {
182
+ async: [],
183
+ sync: []
184
+ }
185
+ }
186
+ }
187
+ ],
188
+ shared: [],
189
+ backendFederation: {
190
+ role: 'microvertical-server',
191
+ name: app.backendName,
192
+ runtimeFramework: 'effect',
193
+ strictEffectApproach: true,
194
+ contractVersion: CONTRACT_VERSION,
195
+ nodeAdapterVersion: NODE_ADAPTER_VERSION,
196
+ remoteType: app.remoteType,
197
+ expose: BACKEND_EXPOSE,
198
+ manifestUrl: app.manifestUrl,
199
+ containerEntry: app.containerEntry,
200
+ source: {
201
+ module: sourceModule
202
+ },
203
+ readinessPath: `${app.apiPrefix}/${app.apiStem}/readiness`,
204
+ openapiPath: `${app.apiPrefix}/openapi.json`,
205
+ ...app.unitId && app.buildVersion ? {
206
+ deliveryUnit: {
207
+ schemaVersion: 1,
208
+ kind: 'microvertical-delivery-unit',
209
+ unitId: app.unitId,
210
+ packageName: app.packageName,
211
+ version: app.version,
212
+ buildMarker: app.buildVersion,
213
+ sourceRevision: app.sourceRevision
214
+ }
215
+ } : {},
216
+ versionBoundary: {
217
+ invariant: 'web-and-api-same-build',
218
+ packageName: app.packageName,
219
+ version: app.version,
220
+ buildVersion: app.buildVersion,
221
+ ...app.uiManifestUrl ? {
222
+ uiManifestUrl: app.uiManifestUrl
223
+ } : {},
224
+ ...app.unitId && app.buildVersion ? {
225
+ deliveryUnit: {
226
+ unitId: app.unitId,
227
+ buildMarker: app.buildVersion
228
+ }
229
+ } : {}
230
+ }
231
+ }
232
+ };
233
+ };
234
+ const emitBackendFederationArtifacts = async (appDirectory, distDirectory)=>{
235
+ const workspaceRoot = findWorkspaceRoot(appDirectory);
236
+ if (!workspaceRoot) return;
237
+ const effectApiPath = node_path.join(appDirectory, 'api/effect-api.ts');
238
+ const backendFederationConfigPath = node_path.join(appDirectory, 'backend-federation.config.ts');
239
+ if (!existsSync(effectApiPath) || !existsSync(backendFederationConfigPath)) return;
240
+ const app = await findBackendFederationApp(workspaceRoot, appDirectory);
241
+ if (!app) return;
242
+ const buildIdentity = await readBuildIdentity(appDirectory);
243
+ const compactDeliveryUnit = app.compactDeliveryUnit;
244
+ const hasCompactDeliveryUnit = void 0 !== compactDeliveryUnit && (void 0 !== compactDeliveryUnit.unitId || void 0 !== compactDeliveryUnit.buildMarker || void 0 !== compactDeliveryUnit.packageName || void 0 !== compactDeliveryUnit.version);
245
+ const hasBuildIdentity = void 0 !== buildIdentity.unitId || void 0 !== buildIdentity.buildVersion || void 0 !== buildIdentity.packageName || void 0 !== buildIdentity.version;
246
+ if (hasCompactDeliveryUnit && hasBuildIdentity) {
247
+ const compactConfigPath = node_path.join(workspaceRoot, COMPACT_CONFIG_PATH);
248
+ const buildModulePath = buildModulePathFor(appDirectory);
249
+ const mismatches = [];
250
+ const compare = (label, a, b)=>{
251
+ if (void 0 !== a && void 0 !== b && a !== b) mismatches.push(`${label}: deliveryUnit=${a} vs ultramodern-build=${b}`);
252
+ };
253
+ compare('unitId', compactDeliveryUnit?.unitId, buildIdentity.unitId);
254
+ compare('buildMarker/build', compactDeliveryUnit?.buildMarker, buildIdentity.buildVersion);
255
+ compare('packageName', compactDeliveryUnit?.packageName, buildIdentity.packageName);
256
+ compare('version', compactDeliveryUnit?.version, buildIdentity.version);
257
+ if (mismatches.length > 0) throw new Error(`[backend-federation-build] Delivery-unit identity drift between ${compactConfigPath} (deliveryUnit) and ${buildModulePath}: ${mismatches.join('; ')}`);
258
+ }
259
+ const unitId = compactDeliveryUnit?.unitId ?? buildIdentity.unitId;
260
+ const buildVersion = compactDeliveryUnit?.buildMarker ?? buildIdentity.buildVersion;
261
+ const sourceRevision = compactDeliveryUnit?.sourceRevision ?? buildIdentity.sourceRevision;
262
+ const packageName = compactDeliveryUnit?.packageName ?? buildIdentity.packageName ?? app.packageName;
263
+ const version = compactDeliveryUnit?.version ?? buildIdentity.version;
264
+ const resolvedApp = {
265
+ ...app,
266
+ packageName,
267
+ version,
268
+ buildVersion,
269
+ unitId,
270
+ sourceRevision
271
+ };
272
+ const manifestPath = node_path.join(distDirectory, BACKEND_MANIFEST_FILE);
273
+ const entryPath = node_path.join(distDirectory, BACKEND_REMOTE_ENTRY_FILE);
274
+ await promises.mkdir(distDirectory, {
275
+ recursive: true
276
+ });
277
+ await promises.writeFile(entryPath, createBackendRemoteEntrySource(workspaceRoot, resolvedApp, effectApiPath, entryPath));
278
+ await promises.writeFile(manifestPath, `${JSON.stringify(createBackendManifest(workspaceRoot, distDirectory, resolvedApp), null, 2)}\n`);
279
+ return {
280
+ appId: resolvedApp.id,
281
+ manifestPath,
282
+ containerPath: entryPath,
283
+ remoteName: resolvedApp.backendName,
284
+ remoteType: resolvedApp.remoteType
285
+ };
286
+ };
287
+ const backendFederationBuild = ()=>({
288
+ name: '@modern-js/backend-federation-build',
289
+ setup (api) {
290
+ api.onAfterBuild(async ()=>{
291
+ const { appDirectory, distDirectory } = api.getAppContext();
292
+ await emitBackendFederationArtifacts(appDirectory, distDirectory);
293
+ });
294
+ }
295
+ });
296
+ export default backendFederationBuild;
297
+ export { emitBackendFederationArtifacts };
@@ -0,0 +1,18 @@
1
+ import "node:module";
2
+ const CLOUDFLARE_WORKER_ENTRY = 'server/index.mjs';
3
+ const CLOUDFLARE_WORKER_MANIFEST = 'server/modern-worker-manifest.json';
4
+ const CLOUDFLARE_WRANGLER_CONFIG_FILE = 'wrangler.json';
5
+ const CLOUDFLARE_OUTPUT_PACKAGE_FILE = 'package.json';
6
+ const CLOUDFLARE_WORKER_PACKAGE_FILE = 'worker/package.json';
7
+ const CLOUDFLARE_ASSETS_BINDING = 'ASSETS';
8
+ const CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY = 'public';
9
+ const CLOUDFLARE_WORKER_BUNDLE_DIRECTORY = 'worker';
10
+ const CLOUDFLARE_RUNTIME_TYPE = 'cloudflare-module-worker';
11
+ const CLOUDFLARE_OUTPUT_PACKAGE_TYPE = 'module';
12
+ const CLOUDFLARE_WORKER_PACKAGE_TYPE = 'commonjs';
13
+ const CLOUDFLARE_WORKER_BUNDLE_FORMAT = 'commonjs';
14
+ const CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS = [
15
+ 'nodejs_compat',
16
+ 'global_fetch_strictly_public'
17
+ ];
18
+ export { CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_OUTPUT_PACKAGE_FILE, CLOUDFLARE_OUTPUT_PACKAGE_TYPE, 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_WORKER_PACKAGE_FILE, CLOUDFLARE_WORKER_PACKAGE_TYPE, CLOUDFLARE_WRANGLER_CONFIG_FILE };
@@ -0,0 +1,46 @@
1
+ import "node:module";
2
+ import node_path from "node:path";
3
+ import { CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_OUTPUT_PACKAGE_FILE, CLOUDFLARE_OUTPUT_PACKAGE_TYPE, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY, CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY, CLOUDFLARE_WORKER_ENTRY, CLOUDFLARE_WORKER_MANIFEST, CLOUDFLARE_WORKER_PACKAGE_FILE, CLOUDFLARE_WORKER_PACKAGE_TYPE, CLOUDFLARE_WRANGLER_CONFIG_FILE } from "./cloudflare-output-contract.mjs";
4
+ const resolveOutput = (outputDirectory, relativePath)=>node_path.join(outputDirectory, relativePath);
5
+ function createCloudflareOutputPlan(outputDirectory) {
6
+ return {
7
+ outputDirectory,
8
+ requiredFiles: [
9
+ CLOUDFLARE_WORKER_ENTRY,
10
+ CLOUDFLARE_WORKER_MANIFEST,
11
+ CLOUDFLARE_WRANGLER_CONFIG_FILE,
12
+ CLOUDFLARE_OUTPUT_PACKAGE_FILE
13
+ ],
14
+ publicLeakDirectories: [
15
+ 'server',
16
+ CLOUDFLARE_WORKER_BUNDLE_DIRECTORY
17
+ ],
18
+ paths: {
19
+ workerEntry: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_ENTRY),
20
+ workerManifest: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_MANIFEST),
21
+ wranglerConfig: resolveOutput(outputDirectory, CLOUDFLARE_WRANGLER_CONFIG_FILE),
22
+ outputPackage: resolveOutput(outputDirectory, CLOUDFLARE_OUTPUT_PACKAGE_FILE),
23
+ workerPackage: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_PACKAGE_FILE),
24
+ publicAssets: resolveOutput(outputDirectory, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY),
25
+ workerBundle: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY)
26
+ },
27
+ packages: {
28
+ output: {
29
+ type: CLOUDFLARE_OUTPUT_PACKAGE_TYPE
30
+ },
31
+ worker: {
32
+ type: CLOUDFLARE_WORKER_PACKAGE_TYPE
33
+ }
34
+ },
35
+ wrangler: {
36
+ main: CLOUDFLARE_WORKER_ENTRY,
37
+ assets: {
38
+ binding: CLOUDFLARE_ASSETS_BINDING,
39
+ directory: `./${CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY}`,
40
+ run_worker_first: true
41
+ },
42
+ requiredCompatibilityFlags: CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS
43
+ }
44
+ };
45
+ }
46
+ export { createCloudflareOutputPlan };