@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.3 → 3.5.0-ultramodern.30
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.
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -0
- package/dist/cjs/index.js +50 -44
- package/dist/cjs/plugins/backendFederationBuild.js +347 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +91 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +93 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier.js +402 -0
- package/dist/cjs/plugins/deploy/platforms/cloudflare.js +272 -29
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +346 -43
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/plugins/backendFederationBuild.mjs +296 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +17 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +45 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier.mjs +347 -0
- package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +272 -29
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +346 -43
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +1 -0
- package/dist/esm-node/index.mjs +2 -0
- package/dist/esm-node/plugins/backendFederationBuild.mjs +297 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +18 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier.mjs +348 -0
- package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +272 -29
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +346 -43
- package/dist/types/plugins/backendFederationBuild.d.ts +11 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +13 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +33 -0
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier.d.ts +32 -0
- package/dist/types/types/config/cloudflareDeploy.d.ts +22 -0
- package/dist/types/types/config/deploy.d.ts +15 -2
- package/lib/types.d.ts +2 -3
- package/package.json +17 -11
|
@@ -0,0 +1,296 @@
|
|
|
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 };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const CLOUDFLARE_WORKER_ENTRY = 'server/index.mjs';
|
|
2
|
+
const CLOUDFLARE_WORKER_MANIFEST = 'server/modern-worker-manifest.json';
|
|
3
|
+
const CLOUDFLARE_WRANGLER_CONFIG_FILE = 'wrangler.json';
|
|
4
|
+
const CLOUDFLARE_OUTPUT_PACKAGE_FILE = 'package.json';
|
|
5
|
+
const CLOUDFLARE_WORKER_PACKAGE_FILE = 'worker/package.json';
|
|
6
|
+
const CLOUDFLARE_ASSETS_BINDING = 'ASSETS';
|
|
7
|
+
const CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY = 'public';
|
|
8
|
+
const CLOUDFLARE_WORKER_BUNDLE_DIRECTORY = 'worker';
|
|
9
|
+
const CLOUDFLARE_RUNTIME_TYPE = 'cloudflare-module-worker';
|
|
10
|
+
const CLOUDFLARE_OUTPUT_PACKAGE_TYPE = 'module';
|
|
11
|
+
const CLOUDFLARE_WORKER_PACKAGE_TYPE = 'commonjs';
|
|
12
|
+
const CLOUDFLARE_WORKER_BUNDLE_FORMAT = 'commonjs';
|
|
13
|
+
const CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS = [
|
|
14
|
+
'nodejs_compat',
|
|
15
|
+
'global_fetch_strictly_public'
|
|
16
|
+
];
|
|
17
|
+
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,45 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
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";
|
|
3
|
+
const resolveOutput = (outputDirectory, relativePath)=>node_path.join(outputDirectory, relativePath);
|
|
4
|
+
function createCloudflareOutputPlan(outputDirectory) {
|
|
5
|
+
return {
|
|
6
|
+
outputDirectory,
|
|
7
|
+
requiredFiles: [
|
|
8
|
+
CLOUDFLARE_WORKER_ENTRY,
|
|
9
|
+
CLOUDFLARE_WORKER_MANIFEST,
|
|
10
|
+
CLOUDFLARE_WRANGLER_CONFIG_FILE,
|
|
11
|
+
CLOUDFLARE_OUTPUT_PACKAGE_FILE
|
|
12
|
+
],
|
|
13
|
+
publicLeakDirectories: [
|
|
14
|
+
'server',
|
|
15
|
+
CLOUDFLARE_WORKER_BUNDLE_DIRECTORY
|
|
16
|
+
],
|
|
17
|
+
paths: {
|
|
18
|
+
workerEntry: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_ENTRY),
|
|
19
|
+
workerManifest: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_MANIFEST),
|
|
20
|
+
wranglerConfig: resolveOutput(outputDirectory, CLOUDFLARE_WRANGLER_CONFIG_FILE),
|
|
21
|
+
outputPackage: resolveOutput(outputDirectory, CLOUDFLARE_OUTPUT_PACKAGE_FILE),
|
|
22
|
+
workerPackage: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_PACKAGE_FILE),
|
|
23
|
+
publicAssets: resolveOutput(outputDirectory, CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY),
|
|
24
|
+
workerBundle: resolveOutput(outputDirectory, CLOUDFLARE_WORKER_BUNDLE_DIRECTORY)
|
|
25
|
+
},
|
|
26
|
+
packages: {
|
|
27
|
+
output: {
|
|
28
|
+
type: CLOUDFLARE_OUTPUT_PACKAGE_TYPE
|
|
29
|
+
},
|
|
30
|
+
worker: {
|
|
31
|
+
type: CLOUDFLARE_WORKER_PACKAGE_TYPE
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
wrangler: {
|
|
35
|
+
main: CLOUDFLARE_WORKER_ENTRY,
|
|
36
|
+
assets: {
|
|
37
|
+
binding: CLOUDFLARE_ASSETS_BINDING,
|
|
38
|
+
directory: `./${CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY}`,
|
|
39
|
+
run_worker_first: true
|
|
40
|
+
},
|
|
41
|
+
requiredCompatibilityFlags: CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export { createCloudflareOutputPlan };
|