@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.
Files changed (32) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -0
  2. package/dist/cjs/index.js +50 -44
  3. package/dist/cjs/plugins/backendFederationBuild.js +347 -0
  4. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-contract.js +91 -0
  5. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-plan.js +93 -0
  6. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier.js +402 -0
  7. package/dist/cjs/plugins/deploy/platforms/cloudflare.js +272 -29
  8. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +346 -43
  9. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +1 -0
  10. package/dist/esm/index.mjs +2 -0
  11. package/dist/esm/plugins/backendFederationBuild.mjs +296 -0
  12. package/dist/esm/plugins/deploy/platforms/cloudflare-output-contract.mjs +17 -0
  13. package/dist/esm/plugins/deploy/platforms/cloudflare-output-plan.mjs +45 -0
  14. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier.mjs +347 -0
  15. package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +272 -29
  16. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +346 -43
  17. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +1 -0
  18. package/dist/esm-node/index.mjs +2 -0
  19. package/dist/esm-node/plugins/backendFederationBuild.mjs +297 -0
  20. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-contract.mjs +18 -0
  21. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-plan.mjs +46 -0
  22. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier.mjs +348 -0
  23. package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +272 -29
  24. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +346 -43
  25. package/dist/types/plugins/backendFederationBuild.d.ts +11 -0
  26. package/dist/types/plugins/deploy/platforms/cloudflare-output-contract.d.ts +13 -0
  27. package/dist/types/plugins/deploy/platforms/cloudflare-output-plan.d.ts +33 -0
  28. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier.d.ts +32 -0
  29. package/dist/types/types/config/cloudflareDeploy.d.ts +22 -0
  30. package/dist/types/types/config/deploy.d.ts +15 -2
  31. package/lib/types.d.ts +2 -3
  32. package/package.json +17 -11
@@ -302,6 +302,7 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
302
302
  chain.output.module(true).library({
303
303
  type: 'module'
304
304
  }).chunkFormat('module').chunkLoading('import').workerChunkLoading('import');
305
+ chain.optimization.usedExports(false).providedExports(true).innerGraph(false).sideEffects(false);
305
306
  chain.plugins.delete('plugin-module-federation');
306
307
  if (tanstackRouterSsrServerFile) {
307
308
  chain.resolve.alias.set('@tanstack/router-core/ssr/server$', tanstackRouterSsrServerFile);
package/dist/cjs/index.js CHANGED
@@ -27,6 +27,9 @@ var __webpack_modules__ = {
27
27
  "./plugins/analyze" (module) {
28
28
  module.exports = require("./plugins/analyze/index.js");
29
29
  },
30
+ "./plugins/backendFederationBuild" (module) {
31
+ module.exports = require("./plugins/backendFederationBuild.js");
32
+ },
30
33
  "./plugins/deploy" (module) {
31
34
  module.exports = require("./plugins/deploy/index.js");
32
35
  },
@@ -138,20 +141,22 @@ var __webpack_exports__ = {};
138
141
  var _locale__rspack_import_8 = __webpack_require__("./locale");
139
142
  var _plugins_analyze__rspack_import_9 = __webpack_require__("./plugins/analyze");
140
143
  var _plugins_analyze__rspack_import_9_default = /*#__PURE__*/ __webpack_require__.n(_plugins_analyze__rspack_import_9);
141
- var _plugins_deploy__rspack_import_10 = __webpack_require__("./plugins/deploy");
142
- var _plugins_deploy__rspack_import_10_default = /*#__PURE__*/ __webpack_require__.n(_plugins_deploy__rspack_import_10);
143
- var _plugins_initialize__rspack_import_11 = __webpack_require__("./plugins/initialize");
144
- var _plugins_initialize__rspack_import_11_default = /*#__PURE__*/ __webpack_require__.n(_plugins_initialize__rspack_import_11);
145
- var _plugins_serverBuild__rspack_import_12 = __webpack_require__("./plugins/serverBuild");
146
- var _plugins_serverBuild__rspack_import_12_default = /*#__PURE__*/ __webpack_require__.n(_plugins_serverBuild__rspack_import_12);
147
- var _plugins_serverRuntime__rspack_import_13 = __webpack_require__("./plugins/serverRuntime");
148
- var _plugins_serverRuntime__rspack_import_13_default = /*#__PURE__*/ __webpack_require__.n(_plugins_serverRuntime__rspack_import_13);
149
- var _utils_generateWatchFiles__rspack_import_14 = __webpack_require__("./utils/generateWatchFiles");
150
- var _utils_initAppContext__rspack_import_15 = __webpack_require__("./utils/initAppContext");
151
- var _utils_restart__rspack_import_16 = __webpack_require__("./utils/restart");
152
- var _baseline__rspack_import_17 = __webpack_require__("./baseline");
144
+ var _plugins_backendFederationBuild__rspack_import_10 = __webpack_require__("./plugins/backendFederationBuild");
145
+ var _plugins_backendFederationBuild__rspack_import_10_default = /*#__PURE__*/ __webpack_require__.n(_plugins_backendFederationBuild__rspack_import_10);
146
+ var _plugins_deploy__rspack_import_11 = __webpack_require__("./plugins/deploy");
147
+ var _plugins_deploy__rspack_import_11_default = /*#__PURE__*/ __webpack_require__.n(_plugins_deploy__rspack_import_11);
148
+ var _plugins_initialize__rspack_import_12 = __webpack_require__("./plugins/initialize");
149
+ var _plugins_initialize__rspack_import_12_default = /*#__PURE__*/ __webpack_require__.n(_plugins_initialize__rspack_import_12);
150
+ var _plugins_serverBuild__rspack_import_13 = __webpack_require__("./plugins/serverBuild");
151
+ var _plugins_serverBuild__rspack_import_13_default = /*#__PURE__*/ __webpack_require__.n(_plugins_serverBuild__rspack_import_13);
152
+ var _plugins_serverRuntime__rspack_import_14 = __webpack_require__("./plugins/serverRuntime");
153
+ var _plugins_serverRuntime__rspack_import_14_default = /*#__PURE__*/ __webpack_require__.n(_plugins_serverRuntime__rspack_import_14);
154
+ var _utils_generateWatchFiles__rspack_import_15 = __webpack_require__("./utils/generateWatchFiles");
155
+ var _utils_initAppContext__rspack_import_16 = __webpack_require__("./utils/initAppContext");
156
+ var _utils_restart__rspack_import_17 = __webpack_require__("./utils/restart");
157
+ var _baseline__rspack_import_18 = __webpack_require__("./baseline");
153
158
  var __rspack_reexport = {};
154
- for(const __rspack_import_key in _baseline__rspack_import_17)if ([
159
+ for(const __rspack_import_key in _baseline__rspack_import_18)if ([
155
160
  "dev",
156
161
  "resolveModernRsbuildConfig",
157
162
  "mergeConfig",
@@ -161,11 +166,11 @@ var __webpack_exports__ = {};
161
166
  "generateWatchFiles",
162
167
  "initAppContext",
163
168
  "defineConfig"
164
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_baseline__rspack_import_17[__rspack_import_key];
169
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_baseline__rspack_import_18[__rspack_import_key];
165
170
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
166
- var _defineConfig__rspack_import_18 = __webpack_require__("./defineConfig");
171
+ var _defineConfig__rspack_import_19 = __webpack_require__("./defineConfig");
167
172
  var __rspack_reexport = {};
168
- for(const __rspack_import_key in _defineConfig__rspack_import_18)if ([
173
+ for(const __rspack_import_key in _defineConfig__rspack_import_19)if ([
169
174
  "dev",
170
175
  "resolveModernRsbuildConfig",
171
176
  "mergeConfig",
@@ -175,11 +180,11 @@ var __webpack_exports__ = {};
175
180
  "generateWatchFiles",
176
181
  "initAppContext",
177
182
  "defineConfig"
178
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_defineConfig__rspack_import_18[__rspack_import_key];
183
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_defineConfig__rspack_import_19[__rspack_import_key];
179
184
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
180
- var _presetUltramodern__rspack_import_19 = __webpack_require__("./presetUltramodern");
185
+ var _presetUltramodern__rspack_import_20 = __webpack_require__("./presetUltramodern");
181
186
  var __rspack_reexport = {};
182
- for(const __rspack_import_key in _presetUltramodern__rspack_import_19)if ([
187
+ for(const __rspack_import_key in _presetUltramodern__rspack_import_20)if ([
183
188
  "dev",
184
189
  "resolveModernRsbuildConfig",
185
190
  "mergeConfig",
@@ -189,11 +194,11 @@ var __webpack_exports__ = {};
189
194
  "generateWatchFiles",
190
195
  "initAppContext",
191
196
  "defineConfig"
192
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_presetUltramodern__rspack_import_19[__rspack_import_key];
197
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_presetUltramodern__rspack_import_20[__rspack_import_key];
193
198
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
194
- var _ultramodern_designSystem__rspack_import_20 = __webpack_require__("./ultramodern/designSystem");
199
+ var _ultramodern_designSystem__rspack_import_21 = __webpack_require__("./ultramodern/designSystem");
195
200
  var __rspack_reexport = {};
196
- for(const __rspack_import_key in _ultramodern_designSystem__rspack_import_20)if ([
201
+ for(const __rspack_import_key in _ultramodern_designSystem__rspack_import_21)if ([
197
202
  "dev",
198
203
  "resolveModernRsbuildConfig",
199
204
  "mergeConfig",
@@ -203,14 +208,14 @@ var __webpack_exports__ = {};
203
208
  "generateWatchFiles",
204
209
  "initAppContext",
205
210
  "defineConfig"
206
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_ultramodern_designSystem__rspack_import_20[__rspack_import_key];
211
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_ultramodern_designSystem__rspack_import_21[__rspack_import_key];
207
212
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
208
- var _commands_dev__rspack_import_21 = __webpack_require__("./commands/dev");
209
- var _commands_serve__rspack_import_22 = __webpack_require__("./commands/serve");
210
- var _rsbuild__rspack_import_23 = __webpack_require__("./rsbuild");
211
- var _types__rspack_import_24 = __webpack_require__("./types?6efa");
213
+ var _commands_dev__rspack_import_22 = __webpack_require__("./commands/dev");
214
+ var _commands_serve__rspack_import_23 = __webpack_require__("./commands/serve");
215
+ var _rsbuild__rspack_import_24 = __webpack_require__("./rsbuild");
216
+ var _types__rspack_import_25 = __webpack_require__("./types?6efa");
212
217
  var __rspack_reexport = {};
213
- for(const __rspack_import_key in _types__rspack_import_24)if ([
218
+ for(const __rspack_import_key in _types__rspack_import_25)if ([
214
219
  "dev",
215
220
  "resolveModernRsbuildConfig",
216
221
  "mergeConfig",
@@ -220,18 +225,19 @@ var __webpack_exports__ = {};
220
225
  "generateWatchFiles",
221
226
  "initAppContext",
222
227
  "defineConfig"
223
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_24[__rspack_import_key];
228
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_25[__rspack_import_key];
224
229
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
225
- var _modern_js_plugin_cli__rspack_import_25 = __webpack_require__("@modern-js/plugin/cli");
230
+ var _modern_js_plugin_cli__rspack_import_26 = __webpack_require__("@modern-js/plugin/cli");
226
231
  const appTools = ()=>({
227
232
  name: '@modern-js/app-tools',
228
233
  usePlugins: [
229
- _plugins_serverRuntime__rspack_import_13_default()(),
234
+ _plugins_serverRuntime__rspack_import_14_default()(),
230
235
  (0, _compat__rspack_import_6.compatPlugin)(),
231
- _plugins_initialize__rspack_import_11_default()(),
236
+ _plugins_initialize__rspack_import_12_default()(),
232
237
  _plugins_analyze__rspack_import_9_default()(),
233
- _plugins_serverBuild__rspack_import_12_default()(),
234
- _plugins_deploy__rspack_import_10_default()()
238
+ _plugins_serverBuild__rspack_import_13_default()(),
239
+ _plugins_backendFederationBuild__rspack_import_10_default()(),
240
+ _plugins_deploy__rspack_import_11_default()()
235
241
  ],
236
242
  post: [
237
243
  '@modern-js/plugin-initialize',
@@ -259,7 +265,7 @@ var __webpack_exports__ = {};
259
265
  _locale__rspack_import_8.i18n.changeLanguage({
260
266
  locale
261
267
  });
262
- api.updateAppContext((0, _utils_initAppContext__rspack_import_15.initAppContext)({
268
+ api.updateAppContext((0, _utils_initAppContext__rspack_import_16.initAppContext)({
263
269
  metaName: context.metaName,
264
270
  appDirectory: context.appDirectory,
265
271
  runtimeConfigFile: _constants__rspack_import_7.DEFAULT_RUNTIME_CONFIG_FILE,
@@ -298,7 +304,7 @@ var __webpack_exports__ = {};
298
304
  api.addWatchFiles(async ()=>{
299
305
  const appContext = api.getAppContext();
300
306
  const config = api.getNormalizedConfig();
301
- const files = await (0, _utils_generateWatchFiles__rspack_import_14.generateWatchFiles)(appContext, config.source.configDir);
307
+ const files = await (0, _utils_generateWatchFiles__rspack_import_15.generateWatchFiles)(appContext, config.source.configDir);
302
308
  const watchFiles = (0, _modern_js_builder__rspack_import_0.castArray)(config.dev.watchFiles);
303
309
  watchFiles.forEach(({ type, paths })=>{
304
310
  if ('reload-server' === type) files.push(...Array.isArray(paths) ? paths : [
@@ -315,7 +321,7 @@ var __webpack_exports__ = {};
315
321
  if (!isPrivate && ('change' === eventType || 'unlink' === eventType) && !isApiProject) {
316
322
  const { closeServer } = await import("./utils/createServer.js");
317
323
  await closeServer();
318
- await (0, _utils_restart__rspack_import_16.restart)(api.getHooks(), filename);
324
+ await (0, _utils_restart__rspack_import_17.restart)(api.getHooks(), filename);
319
325
  }
320
326
  });
321
327
  api.onBeforeRestart(()=>{
@@ -327,13 +333,13 @@ var __webpack_exports__ = {};
327
333
  });
328
334
  const __rspack_default_export = appTools;
329
335
  __webpack_require__.d(__webpack_exports__, {
330
- defineConfig: ()=>_defineConfig__rspack_import_18.defineConfig,
331
- dev: ()=>_commands_dev__rspack_import_21.dev,
332
- generateWatchFiles: ()=>_utils_generateWatchFiles__rspack_import_14.generateWatchFiles,
333
- initAppContext: ()=>_utils_initAppContext__rspack_import_15.initAppContext,
334
- mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_25.mergeConfig,
335
- resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_23.resolveModernRsbuildConfig,
336
- serve: ()=>_commands_serve__rspack_import_22.serve
336
+ defineConfig: ()=>_defineConfig__rspack_import_19.defineConfig,
337
+ dev: ()=>_commands_dev__rspack_import_22.dev,
338
+ generateWatchFiles: ()=>_utils_generateWatchFiles__rspack_import_15.generateWatchFiles,
339
+ initAppContext: ()=>_utils_initAppContext__rspack_import_16.initAppContext,
340
+ mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_26.mergeConfig,
341
+ resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_24.resolveModernRsbuildConfig,
342
+ serve: ()=>_commands_serve__rspack_import_23.serve
337
343
  }, {
338
344
  appTools: appTools,
339
345
  default: __rspack_default_export
@@ -0,0 +1,347 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ default: ()=>backendFederationBuild,
41
+ emitBackendFederationArtifacts: ()=>emitBackendFederationArtifacts
42
+ });
43
+ const external_node_fs_namespaceObject = require("node:fs");
44
+ const promises_namespaceObject = require("node:fs/promises");
45
+ var promises_default = /*#__PURE__*/ __webpack_require__.n(promises_namespaceObject);
46
+ const external_node_path_namespaceObject = require("node:path");
47
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
48
+ const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
49
+ const BACKEND_MANIFEST_FILE = 'backend-mf-manifest.json';
50
+ const BACKEND_REMOTE_ENTRY_FILE = 'backendRemoteEntry.mjs';
51
+ const CONTRACT_VERSION = 'microvertical-server-effect-v1';
52
+ const NODE_ADAPTER_VERSION = 'backend-mf-effect-v1';
53
+ const BACKEND_EXPOSE = './effect-api';
54
+ const normalizeRelativePath = (value)=>value.replace(/\\/gu, '/').replace(/^\.\/+/u, '');
55
+ const isRecord = (value)=>'object' == typeof value && null !== value;
56
+ const readJsonFile = async (filePath)=>JSON.parse(await promises_default().readFile(filePath, 'utf8'));
57
+ const buildModulePathFor = (appDirectory)=>external_node_path_default().join(appDirectory, 'shared/ultramodern-build.ts');
58
+ const readBuildIdentity = async (appDirectory)=>{
59
+ const buildModulePath = buildModulePathFor(appDirectory);
60
+ if (!(0, external_node_fs_namespaceObject.existsSync)(buildModulePath)) return {};
61
+ const source = await promises_default().readFile(buildModulePath, 'utf8');
62
+ return {
63
+ buildVersion: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
64
+ packageName: source.match(/\bpackageName:\s*['"]([^'"]+)['"]/u)?.[1],
65
+ version: source.match(/\bversion:\s*['"]([^'"]+)['"]/u)?.[1],
66
+ unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
67
+ sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
68
+ };
69
+ };
70
+ const toPascalCase = (value)=>value.split(/[^a-zA-Z0-9]+/u).filter(Boolean).map((part)=>part.charAt(0).toUpperCase() + part.slice(1)).join('');
71
+ const stringValue = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
72
+ const createBackendName = (app, id)=>{
73
+ const configuredName = stringValue(app.backendFederation?.name) ?? stringValue(app.backendFederation?.executionSurfaces?.node?.remoteName) ?? stringValue(app.serverExecution?.node?.remoteName);
74
+ if (configuredName) return configuredName;
75
+ const mfName = stringValue(app.moduleFederation?.name);
76
+ return mfName ? `${mfName}Backend` : `vertical${toPascalCase(id)}Backend`;
77
+ };
78
+ const findWorkspaceRoot = (appDirectory)=>{
79
+ let current = appDirectory;
80
+ while(true){
81
+ if ((0, external_node_fs_namespaceObject.existsSync)(external_node_path_default().join(current, COMPACT_CONFIG_PATH))) return current;
82
+ const parent = external_node_path_default().dirname(current);
83
+ if (parent === current) return;
84
+ current = parent;
85
+ }
86
+ };
87
+ const createAppFromCompactMetadata = (workspaceRoot, appDirectory, compactApp)=>{
88
+ const id = stringValue(compactApp.id);
89
+ const appPath = stringValue(compactApp.path);
90
+ if (!id || 'vertical' !== compactApp.kind || !isRecord(compactApp.api)) return;
91
+ const directory = appPath ? normalizeRelativePath(appPath) : `verticals/${id}`;
92
+ if (external_node_path_default().resolve(workspaceRoot, directory) !== external_node_path_default().resolve(appDirectory)) return;
93
+ const port = 'number' == typeof compactApp.port ? compactApp.port : void 0;
94
+ if (void 0 === port) return;
95
+ const apiPrefix = stringValue(compactApp.api.prefix) ?? `/${id}-api`;
96
+ const apiStem = stringValue(compactApp.api.stem) ?? id;
97
+ const backendName = createBackendName(compactApp, id);
98
+ const manifestUrl = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.manifestUrl) ?? stringValue(compactApp.serverExecution?.node?.manifestUrl) ?? `http://localhost:${port}/${BACKEND_MANIFEST_FILE}`;
99
+ const containerEntry = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.containerEntry) ?? stringValue(compactApp.serverExecution?.node?.containerEntry) ?? `http://localhost:${port}/${BACKEND_REMOTE_ENTRY_FILE}`;
100
+ const remoteType = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.remoteType) ?? stringValue(compactApp.serverExecution?.node?.remoteType) ?? 'module';
101
+ const packageName = stringValue(compactApp.package);
102
+ const uiManifestUrl = stringValue(compactApp.backendFederation?.versionBoundary?.ui?.manifestUrl) ?? stringValue(compactApp.moduleFederation?.manifestUrl);
103
+ const compactDeliveryUnit = isRecord(compactApp.deliveryUnit) ? {
104
+ unitId: stringValue(compactApp.deliveryUnit.unitId),
105
+ buildMarker: stringValue(compactApp.deliveryUnit.buildMarker),
106
+ sourceRevision: stringValue(compactApp.deliveryUnit.sourceRevision),
107
+ packageName: stringValue(compactApp.deliveryUnit.packageName),
108
+ version: stringValue(compactApp.deliveryUnit.version)
109
+ } : void 0;
110
+ return {
111
+ id,
112
+ directory,
113
+ packageName,
114
+ port,
115
+ apiPrefix,
116
+ apiStem,
117
+ backendName,
118
+ manifestUrl,
119
+ containerEntry,
120
+ remoteType,
121
+ uiManifestUrl,
122
+ compactDeliveryUnit
123
+ };
124
+ };
125
+ const findBackendFederationApp = async (workspaceRoot, appDirectory)=>{
126
+ const compactConfigPath = external_node_path_default().join(workspaceRoot, COMPACT_CONFIG_PATH);
127
+ const compactConfig = await readJsonFile(compactConfigPath);
128
+ const apps = Array.isArray(compactConfig.topology?.apps) ? compactConfig.topology.apps : [];
129
+ for (const app of apps){
130
+ const resolved = createAppFromCompactMetadata(workspaceRoot, appDirectory, app);
131
+ if (resolved) return resolved;
132
+ }
133
+ };
134
+ const createRelativeImportSpecifier = (fromDirectory, toFile)=>{
135
+ const relativePath = normalizeRelativePath(external_node_path_default().relative(fromDirectory, toFile));
136
+ return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
137
+ };
138
+ const createBackendRemoteEntrySource = (workspaceRoot, app, effectApiPath, entryPath)=>{
139
+ const effectApiSpecifier = createRelativeImportSpecifier(external_node_path_default().dirname(entryPath), effectApiPath);
140
+ return `// Generated by Modern.js backend federation build.
141
+ const exposedModules = {
142
+ ${JSON.stringify(BACKEND_EXPOSE)}: () =>
143
+ import(new URL(${JSON.stringify(effectApiSpecifier)}, import.meta.url).href),
144
+ };
145
+
146
+ export const __modernjsBackendFederation = ${JSON.stringify({
147
+ buildVersion: app.buildVersion,
148
+ expose: BACKEND_EXPOSE,
149
+ name: app.backendName,
150
+ packageName: app.packageName,
151
+ remoteType: app.remoteType,
152
+ source: normalizeRelativePath(external_node_path_default().relative(workspaceRoot, effectApiPath)),
153
+ version: app.version,
154
+ ...app.unitId ? {
155
+ unitId: app.unitId
156
+ } : {},
157
+ ...app.sourceRevision ? {
158
+ sourceRevision: app.sourceRevision
159
+ } : {}
160
+ }, null, 2)};
161
+
162
+ export function init() {}
163
+
164
+ export function get(id) {
165
+ const load = exposedModules[id];
166
+ if (!load) {
167
+ throw new Error(\`Unexpected backend federation expose: \${id}\`);
168
+ }
169
+
170
+ return async () => load();
171
+ }
172
+
173
+ export default { get, init };
174
+ `;
175
+ };
176
+ const createBackendManifest = (workspaceRoot, distDirectory, app)=>{
177
+ const sourceModule = `${app.directory}/api/effect-api.ts`;
178
+ const publicPath = `http://localhost:${app.port}/`;
179
+ return {
180
+ schemaVersion: 1,
181
+ id: app.backendName,
182
+ name: app.backendName,
183
+ version: app.version,
184
+ buildVersion: app.buildVersion,
185
+ metaData: {
186
+ name: app.backendName,
187
+ type: 'backend',
188
+ buildInfo: {
189
+ buildVersion: app.buildVersion,
190
+ buildName: app.packageName
191
+ },
192
+ remoteEntry: {
193
+ name: BACKEND_REMOTE_ENTRY_FILE,
194
+ path: '',
195
+ type: app.remoteType
196
+ },
197
+ globalName: app.backendName,
198
+ publicPath,
199
+ ssrRemoteEntry: {
200
+ name: BACKEND_REMOTE_ENTRY_FILE,
201
+ path: '',
202
+ type: app.remoteType
203
+ },
204
+ ssrPublicPath: publicPath
205
+ },
206
+ entry: {
207
+ file: BACKEND_REMOTE_ENTRY_FILE,
208
+ path: normalizeRelativePath(external_node_path_default().relative(workspaceRoot, external_node_path_default().join(distDirectory, BACKEND_REMOTE_ENTRY_FILE))),
209
+ type: app.remoteType,
210
+ url: app.containerEntry
211
+ },
212
+ exposes: [
213
+ {
214
+ id: `${app.backendName}:${BACKEND_EXPOSE}`,
215
+ name: BACKEND_EXPOSE,
216
+ path: '',
217
+ assets: {
218
+ js: {
219
+ async: [],
220
+ sync: [
221
+ BACKEND_REMOTE_ENTRY_FILE
222
+ ]
223
+ },
224
+ css: {
225
+ async: [],
226
+ sync: []
227
+ }
228
+ }
229
+ }
230
+ ],
231
+ shared: [],
232
+ backendFederation: {
233
+ role: 'microvertical-server',
234
+ name: app.backendName,
235
+ runtimeFramework: 'effect',
236
+ strictEffectApproach: true,
237
+ contractVersion: CONTRACT_VERSION,
238
+ nodeAdapterVersion: NODE_ADAPTER_VERSION,
239
+ remoteType: app.remoteType,
240
+ expose: BACKEND_EXPOSE,
241
+ manifestUrl: app.manifestUrl,
242
+ containerEntry: app.containerEntry,
243
+ source: {
244
+ module: sourceModule
245
+ },
246
+ readinessPath: `${app.apiPrefix}/${app.apiStem}/readiness`,
247
+ openapiPath: `${app.apiPrefix}/openapi.json`,
248
+ ...app.unitId && app.buildVersion ? {
249
+ deliveryUnit: {
250
+ schemaVersion: 1,
251
+ kind: 'microvertical-delivery-unit',
252
+ unitId: app.unitId,
253
+ packageName: app.packageName,
254
+ version: app.version,
255
+ buildMarker: app.buildVersion,
256
+ sourceRevision: app.sourceRevision
257
+ }
258
+ } : {},
259
+ versionBoundary: {
260
+ invariant: 'web-and-api-same-build',
261
+ packageName: app.packageName,
262
+ version: app.version,
263
+ buildVersion: app.buildVersion,
264
+ ...app.uiManifestUrl ? {
265
+ uiManifestUrl: app.uiManifestUrl
266
+ } : {},
267
+ ...app.unitId && app.buildVersion ? {
268
+ deliveryUnit: {
269
+ unitId: app.unitId,
270
+ buildMarker: app.buildVersion
271
+ }
272
+ } : {}
273
+ }
274
+ }
275
+ };
276
+ };
277
+ const emitBackendFederationArtifacts = async (appDirectory, distDirectory)=>{
278
+ const workspaceRoot = findWorkspaceRoot(appDirectory);
279
+ if (!workspaceRoot) return;
280
+ const effectApiPath = external_node_path_default().join(appDirectory, 'api/effect-api.ts');
281
+ const backendFederationConfigPath = external_node_path_default().join(appDirectory, 'backend-federation.config.ts');
282
+ if (!(0, external_node_fs_namespaceObject.existsSync)(effectApiPath) || !(0, external_node_fs_namespaceObject.existsSync)(backendFederationConfigPath)) return;
283
+ const app = await findBackendFederationApp(workspaceRoot, appDirectory);
284
+ if (!app) return;
285
+ const buildIdentity = await readBuildIdentity(appDirectory);
286
+ const compactDeliveryUnit = app.compactDeliveryUnit;
287
+ const hasCompactDeliveryUnit = void 0 !== compactDeliveryUnit && (void 0 !== compactDeliveryUnit.unitId || void 0 !== compactDeliveryUnit.buildMarker || void 0 !== compactDeliveryUnit.packageName || void 0 !== compactDeliveryUnit.version);
288
+ const hasBuildIdentity = void 0 !== buildIdentity.unitId || void 0 !== buildIdentity.buildVersion || void 0 !== buildIdentity.packageName || void 0 !== buildIdentity.version;
289
+ if (hasCompactDeliveryUnit && hasBuildIdentity) {
290
+ const compactConfigPath = external_node_path_default().join(workspaceRoot, COMPACT_CONFIG_PATH);
291
+ const buildModulePath = buildModulePathFor(appDirectory);
292
+ const mismatches = [];
293
+ const compare = (label, a, b)=>{
294
+ if (void 0 !== a && void 0 !== b && a !== b) mismatches.push(`${label}: deliveryUnit=${a} vs ultramodern-build=${b}`);
295
+ };
296
+ compare('unitId', compactDeliveryUnit?.unitId, buildIdentity.unitId);
297
+ compare('buildMarker/build', compactDeliveryUnit?.buildMarker, buildIdentity.buildVersion);
298
+ compare('packageName', compactDeliveryUnit?.packageName, buildIdentity.packageName);
299
+ compare('version', compactDeliveryUnit?.version, buildIdentity.version);
300
+ if (mismatches.length > 0) throw new Error(`[backend-federation-build] Delivery-unit identity drift between ${compactConfigPath} (deliveryUnit) and ${buildModulePath}: ${mismatches.join('; ')}`);
301
+ }
302
+ const unitId = compactDeliveryUnit?.unitId ?? buildIdentity.unitId;
303
+ const buildVersion = compactDeliveryUnit?.buildMarker ?? buildIdentity.buildVersion;
304
+ const sourceRevision = compactDeliveryUnit?.sourceRevision ?? buildIdentity.sourceRevision;
305
+ const packageName = compactDeliveryUnit?.packageName ?? buildIdentity.packageName ?? app.packageName;
306
+ const version = compactDeliveryUnit?.version ?? buildIdentity.version;
307
+ const resolvedApp = {
308
+ ...app,
309
+ packageName,
310
+ version,
311
+ buildVersion,
312
+ unitId,
313
+ sourceRevision
314
+ };
315
+ const manifestPath = external_node_path_default().join(distDirectory, BACKEND_MANIFEST_FILE);
316
+ const entryPath = external_node_path_default().join(distDirectory, BACKEND_REMOTE_ENTRY_FILE);
317
+ await promises_default().mkdir(distDirectory, {
318
+ recursive: true
319
+ });
320
+ await promises_default().writeFile(entryPath, createBackendRemoteEntrySource(workspaceRoot, resolvedApp, effectApiPath, entryPath));
321
+ await promises_default().writeFile(manifestPath, `${JSON.stringify(createBackendManifest(workspaceRoot, distDirectory, resolvedApp), null, 2)}\n`);
322
+ return {
323
+ appId: resolvedApp.id,
324
+ manifestPath,
325
+ containerPath: entryPath,
326
+ remoteName: resolvedApp.backendName,
327
+ remoteType: resolvedApp.remoteType
328
+ };
329
+ };
330
+ const backendFederationBuild = ()=>({
331
+ name: '@modern-js/backend-federation-build',
332
+ setup (api) {
333
+ api.onAfterBuild(async ()=>{
334
+ const { appDirectory, distDirectory } = api.getAppContext();
335
+ await emitBackendFederationArtifacts(appDirectory, distDirectory);
336
+ });
337
+ }
338
+ });
339
+ exports["default"] = __webpack_exports__["default"];
340
+ exports.emitBackendFederationArtifacts = __webpack_exports__.emitBackendFederationArtifacts;
341
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
342
+ "default",
343
+ "emitBackendFederationArtifacts"
344
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
345
+ Object.defineProperty(exports, '__esModule', {
346
+ value: true
347
+ });
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const CLOUDFLARE_WORKER_ENTRY = 'server/index.mjs';
31
+ const CLOUDFLARE_WORKER_MANIFEST = 'server/modern-worker-manifest.json';
32
+ const CLOUDFLARE_WRANGLER_CONFIG_FILE = 'wrangler.json';
33
+ const CLOUDFLARE_OUTPUT_PACKAGE_FILE = 'package.json';
34
+ const CLOUDFLARE_WORKER_PACKAGE_FILE = 'worker/package.json';
35
+ const CLOUDFLARE_ASSETS_BINDING = 'ASSETS';
36
+ const CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY = 'public';
37
+ const CLOUDFLARE_WORKER_BUNDLE_DIRECTORY = 'worker';
38
+ const CLOUDFLARE_RUNTIME_TYPE = 'cloudflare-module-worker';
39
+ const CLOUDFLARE_OUTPUT_PACKAGE_TYPE = 'module';
40
+ const CLOUDFLARE_WORKER_PACKAGE_TYPE = 'commonjs';
41
+ const CLOUDFLARE_WORKER_BUNDLE_FORMAT = 'commonjs';
42
+ const CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS = [
43
+ 'nodejs_compat',
44
+ 'global_fetch_strictly_public'
45
+ ];
46
+ __webpack_require__.d(__webpack_exports__, {}, {
47
+ CLOUDFLARE_ASSETS_BINDING: CLOUDFLARE_ASSETS_BINDING,
48
+ CLOUDFLARE_OUTPUT_PACKAGE_FILE: CLOUDFLARE_OUTPUT_PACKAGE_FILE,
49
+ CLOUDFLARE_OUTPUT_PACKAGE_TYPE: CLOUDFLARE_OUTPUT_PACKAGE_TYPE,
50
+ CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY: CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY,
51
+ CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS: CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS,
52
+ CLOUDFLARE_RUNTIME_TYPE: CLOUDFLARE_RUNTIME_TYPE,
53
+ CLOUDFLARE_WORKER_BUNDLE_DIRECTORY: CLOUDFLARE_WORKER_BUNDLE_DIRECTORY,
54
+ CLOUDFLARE_WORKER_BUNDLE_FORMAT: CLOUDFLARE_WORKER_BUNDLE_FORMAT,
55
+ CLOUDFLARE_WORKER_ENTRY: CLOUDFLARE_WORKER_ENTRY,
56
+ CLOUDFLARE_WORKER_MANIFEST: CLOUDFLARE_WORKER_MANIFEST,
57
+ CLOUDFLARE_WORKER_PACKAGE_FILE: CLOUDFLARE_WORKER_PACKAGE_FILE,
58
+ CLOUDFLARE_WORKER_PACKAGE_TYPE: CLOUDFLARE_WORKER_PACKAGE_TYPE,
59
+ CLOUDFLARE_WRANGLER_CONFIG_FILE: CLOUDFLARE_WRANGLER_CONFIG_FILE
60
+ });
61
+ exports.CLOUDFLARE_ASSETS_BINDING = __webpack_exports__.CLOUDFLARE_ASSETS_BINDING;
62
+ exports.CLOUDFLARE_OUTPUT_PACKAGE_FILE = __webpack_exports__.CLOUDFLARE_OUTPUT_PACKAGE_FILE;
63
+ exports.CLOUDFLARE_OUTPUT_PACKAGE_TYPE = __webpack_exports__.CLOUDFLARE_OUTPUT_PACKAGE_TYPE;
64
+ exports.CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY = __webpack_exports__.CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY;
65
+ exports.CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS = __webpack_exports__.CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS;
66
+ exports.CLOUDFLARE_RUNTIME_TYPE = __webpack_exports__.CLOUDFLARE_RUNTIME_TYPE;
67
+ exports.CLOUDFLARE_WORKER_BUNDLE_DIRECTORY = __webpack_exports__.CLOUDFLARE_WORKER_BUNDLE_DIRECTORY;
68
+ exports.CLOUDFLARE_WORKER_BUNDLE_FORMAT = __webpack_exports__.CLOUDFLARE_WORKER_BUNDLE_FORMAT;
69
+ exports.CLOUDFLARE_WORKER_ENTRY = __webpack_exports__.CLOUDFLARE_WORKER_ENTRY;
70
+ exports.CLOUDFLARE_WORKER_MANIFEST = __webpack_exports__.CLOUDFLARE_WORKER_MANIFEST;
71
+ exports.CLOUDFLARE_WORKER_PACKAGE_FILE = __webpack_exports__.CLOUDFLARE_WORKER_PACKAGE_FILE;
72
+ exports.CLOUDFLARE_WORKER_PACKAGE_TYPE = __webpack_exports__.CLOUDFLARE_WORKER_PACKAGE_TYPE;
73
+ exports.CLOUDFLARE_WRANGLER_CONFIG_FILE = __webpack_exports__.CLOUDFLARE_WRANGLER_CONFIG_FILE;
74
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
75
+ "CLOUDFLARE_ASSETS_BINDING",
76
+ "CLOUDFLARE_OUTPUT_PACKAGE_FILE",
77
+ "CLOUDFLARE_OUTPUT_PACKAGE_TYPE",
78
+ "CLOUDFLARE_PUBLIC_ASSETS_DIRECTORY",
79
+ "CLOUDFLARE_REQUIRED_COMPATIBILITY_FLAGS",
80
+ "CLOUDFLARE_RUNTIME_TYPE",
81
+ "CLOUDFLARE_WORKER_BUNDLE_DIRECTORY",
82
+ "CLOUDFLARE_WORKER_BUNDLE_FORMAT",
83
+ "CLOUDFLARE_WORKER_ENTRY",
84
+ "CLOUDFLARE_WORKER_MANIFEST",
85
+ "CLOUDFLARE_WORKER_PACKAGE_FILE",
86
+ "CLOUDFLARE_WORKER_PACKAGE_TYPE",
87
+ "CLOUDFLARE_WRANGLER_CONFIG_FILE"
88
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
89
+ Object.defineProperty(exports, '__esModule', {
90
+ value: true
91
+ });