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

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
@@ -0,0 +1,208 @@
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
+ createBackendManifest: ()=>createBackendManifest,
41
+ createBackendRemoteEntrySource: ()=>createBackendRemoteEntrySource
42
+ });
43
+ const external_node_path_namespaceObject = require("node:path");
44
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
45
+ const universal_namespaceObject = require("@modern-js/utils/universal");
46
+ const external_config_js_namespaceObject = require("./config.js");
47
+ const createRelativeImportSpecifier = (fromDirectory, toFile)=>{
48
+ const relativePath = (0, external_config_js_namespaceObject.normalizeRelativePath)(external_node_path_default().relative(fromDirectory, toFile));
49
+ return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
50
+ };
51
+ const createPublicPath = (containerEntry, fallbackPort)=>{
52
+ try {
53
+ return new URL('.', containerEntry).href;
54
+ } catch {
55
+ const slashIndex = containerEntry.lastIndexOf('/');
56
+ if (slashIndex >= 0) return containerEntry.slice(0, slashIndex + 1);
57
+ return `http://localhost:${fallbackPort}/`;
58
+ }
59
+ };
60
+ const createBackendRemoteEntrySource = (workspaceRoot, app, effectApiPath, entryPath)=>{
61
+ const effectApiSpecifier = createRelativeImportSpecifier(external_node_path_default().dirname(entryPath), effectApiPath);
62
+ return `// Generated by Modern.js backend federation build.
63
+ const exposedModules = {
64
+ ${JSON.stringify(universal_namespaceObject.BACKEND_FEDERATION_EFFECT_EXPOSE)}: () =>
65
+ import(new URL(${JSON.stringify(effectApiSpecifier)}, import.meta.url).href),
66
+ };
67
+
68
+ export const __modernjsBackendFederation = ${JSON.stringify({
69
+ buildVersion: app.buildVersion,
70
+ expose: universal_namespaceObject.BACKEND_FEDERATION_EFFECT_EXPOSE,
71
+ name: app.backendName,
72
+ packageName: app.packageName,
73
+ remoteType: app.remoteType,
74
+ source: (0, external_config_js_namespaceObject.normalizeRelativePath)(external_node_path_default().relative(workspaceRoot, effectApiPath)),
75
+ version: app.version,
76
+ ...app.unitId ? {
77
+ unitId: app.unitId
78
+ } : {},
79
+ ...app.sourceRevision ? {
80
+ sourceRevision: app.sourceRevision
81
+ } : {}
82
+ }, null, 2)};
83
+
84
+ export function init() {}
85
+
86
+ export function get(id) {
87
+ const load = exposedModules[id];
88
+ if (!load) {
89
+ throw new Error(\`Unexpected backend federation expose: \${id}\`);
90
+ }
91
+
92
+ return async () => load();
93
+ }
94
+
95
+ export default { get, init };
96
+ `;
97
+ };
98
+ const createBackendManifest = (workspaceRoot, distDirectory, app)=>{
99
+ const sourceModule = `${app.directory}/api/effect-api.ts`;
100
+ const publicPath = createPublicPath(app.containerEntry, app.port);
101
+ const manifest = {
102
+ schemaVersion: 1,
103
+ id: app.backendName,
104
+ name: app.backendName,
105
+ version: app.version,
106
+ buildVersion: app.buildVersion,
107
+ metaData: {
108
+ name: app.backendName,
109
+ type: 'backend',
110
+ buildInfo: {
111
+ buildVersion: app.buildVersion,
112
+ buildName: app.packageName
113
+ },
114
+ remoteEntry: {
115
+ name: universal_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
116
+ path: '',
117
+ type: app.remoteType
118
+ },
119
+ globalName: app.backendName,
120
+ publicPath,
121
+ ssrRemoteEntry: {
122
+ name: universal_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
123
+ path: '',
124
+ type: app.remoteType
125
+ },
126
+ ssrPublicPath: publicPath
127
+ },
128
+ entry: {
129
+ file: universal_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE,
130
+ path: (0, external_config_js_namespaceObject.normalizeRelativePath)(external_node_path_default().relative(workspaceRoot, external_node_path_default().join(distDirectory, universal_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE))),
131
+ type: app.remoteType,
132
+ url: app.containerEntry
133
+ },
134
+ exposes: [
135
+ {
136
+ id: `${app.backendName}:${universal_namespaceObject.BACKEND_FEDERATION_EFFECT_EXPOSE}`,
137
+ name: universal_namespaceObject.BACKEND_FEDERATION_EFFECT_EXPOSE,
138
+ path: '',
139
+ assets: {
140
+ js: {
141
+ async: [],
142
+ sync: [
143
+ universal_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE
144
+ ]
145
+ },
146
+ css: {
147
+ async: [],
148
+ sync: []
149
+ }
150
+ }
151
+ }
152
+ ],
153
+ shared: [],
154
+ backendFederation: {
155
+ role: 'microvertical-server',
156
+ name: app.backendName,
157
+ runtimeFramework: 'effect',
158
+ strictEffectApproach: true,
159
+ contractVersion: universal_namespaceObject.BACKEND_FEDERATION_CONTRACT_VERSION,
160
+ nodeAdapterVersion: universal_namespaceObject.BACKEND_FEDERATION_NODE_ADAPTER_VERSION,
161
+ remoteType: app.remoteType,
162
+ expose: universal_namespaceObject.BACKEND_FEDERATION_EFFECT_EXPOSE,
163
+ manifestUrl: app.manifestUrl,
164
+ containerEntry: app.containerEntry,
165
+ source: {
166
+ module: sourceModule
167
+ },
168
+ readinessPath: `${app.apiPrefix}/${app.apiStem}/readiness`,
169
+ openapiPath: `${app.apiPrefix}/openapi.json`,
170
+ ...app.deliveryUnit ? {
171
+ deliveryUnit: app.deliveryUnit
172
+ } : {},
173
+ versionBoundary: {
174
+ invariant: 'web-and-api-same-build',
175
+ packageName: app.packageName,
176
+ version: app.version,
177
+ buildVersion: app.buildVersion,
178
+ ...app.uiManifestUrl ? {
179
+ uiManifestUrl: app.uiManifestUrl
180
+ } : {},
181
+ ...app.deliveryUnit ? {
182
+ deliveryUnit: {
183
+ unitId: app.deliveryUnit.unitId,
184
+ buildMarker: app.deliveryUnit.buildMarker,
185
+ sourceRevision: app.deliveryUnit.sourceRevision
186
+ }
187
+ } : {}
188
+ }
189
+ }
190
+ };
191
+ const validation = (0, universal_namespaceObject.validateBackendFederationManifest)(manifest, {
192
+ path: 'backendFederationManifest',
193
+ requireEffectExpose: true,
194
+ requireEffectRuntime: true,
195
+ requireVersionFields: true
196
+ });
197
+ if (!validation.ok) throw new Error(`[backend-federation-build] Invalid backend federation manifest: ${(0, universal_namespaceObject.formatBackendFederationValidationErrors)(validation.errors)}.`);
198
+ return manifest;
199
+ };
200
+ exports.createBackendManifest = __webpack_exports__.createBackendManifest;
201
+ exports.createBackendRemoteEntrySource = __webpack_exports__.createBackendRemoteEntrySource;
202
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
203
+ "createBackendManifest",
204
+ "createBackendRemoteEntrySource"
205
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
206
+ Object.defineProperty(exports, '__esModule', {
207
+ value: true
208
+ });
@@ -0,0 +1,217 @@
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
+ COMPACT_CONFIG_PATH: ()=>COMPACT_CONFIG_PATH,
41
+ buildArtifactPathFor: ()=>buildArtifactPathFor,
42
+ buildModulePathFor: ()=>buildModulePathFor,
43
+ createAppFromCompactMetadata: ()=>createAppFromCompactMetadata,
44
+ createStampedDeliveryUnit: ()=>createStampedDeliveryUnit,
45
+ findBackendFederationApp: ()=>findBackendFederationApp,
46
+ findWorkspaceRoot: ()=>findWorkspaceRoot,
47
+ normalizeRelativePath: ()=>normalizeRelativePath,
48
+ readBuildIdentity: ()=>readBuildIdentity,
49
+ resolveWorkspaceSourceRevision: ()=>resolveWorkspaceSourceRevision
50
+ });
51
+ const external_node_child_process_namespaceObject = require("node:child_process");
52
+ const external_node_fs_namespaceObject = require("node:fs");
53
+ const promises_namespaceObject = require("node:fs/promises");
54
+ var promises_default = /*#__PURE__*/ __webpack_require__.n(promises_namespaceObject);
55
+ const external_node_path_namespaceObject = require("node:path");
56
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
57
+ const external_node_util_namespaceObject = require("node:util");
58
+ const universal_namespaceObject = require("@modern-js/utils/universal");
59
+ const COMPACT_CONFIG_PATH = '.modernjs/ultramodern.json';
60
+ const execFileAsync = (0, external_node_util_namespaceObject.promisify)(external_node_child_process_namespaceObject.execFile);
61
+ const normalizeRelativePath = (value)=>value.replace(/\\/gu, '/').replace(/^\.\/+/u, '');
62
+ const isRecord = (value)=>'object' == typeof value && null !== value;
63
+ const readJsonFile = async (filePath)=>JSON.parse(await promises_default().readFile(filePath, 'utf8'));
64
+ const buildArtifactPathFor = (appDirectory)=>external_node_path_default().join(appDirectory, universal_namespaceObject.ULTRAMODERN_BUILD_ARTIFACT_PATH);
65
+ const buildModulePathFor = (appDirectory)=>external_node_path_default().join(appDirectory, universal_namespaceObject.ULTRAMODERN_BUILD_MODULE_PATH);
66
+ const readBuildIdentity = async (appDirectory)=>{
67
+ const buildArtifactPath = buildArtifactPathFor(appDirectory);
68
+ if ((0, external_node_fs_namespaceObject.existsSync)(buildArtifactPath)) {
69
+ const artifact = await readJsonFile(buildArtifactPath);
70
+ const artifactValidation = (0, universal_namespaceObject.validateUltramodernBuildArtifact)(artifact, buildArtifactPath);
71
+ if (!artifactValidation.ok) throw new Error(`[backend-federation-build] Invalid delivery-unit build artifact at ${buildArtifactPath}.`);
72
+ const deliveryUnit = artifact.deliveryUnit;
73
+ return {
74
+ artifact,
75
+ appId: deliveryUnit.appId,
76
+ buildVersion: deliveryUnit.buildMarker,
77
+ packageName: deliveryUnit.packageName,
78
+ version: deliveryUnit.version,
79
+ unitId: deliveryUnit.unitId,
80
+ sourceRevision: deliveryUnit.sourceRevision
81
+ };
82
+ }
83
+ const buildModulePath = buildModulePathFor(appDirectory);
84
+ if (!(0, external_node_fs_namespaceObject.existsSync)(buildModulePath)) return {};
85
+ console.warn(`[backend-federation-build] ${buildArtifactPath} missing; falling back to legacy regex parsing of ${buildModulePath}. Regenerate the workspace to emit ${universal_namespaceObject.ULTRAMODERN_BUILD_ARTIFACT_FILE}.`);
86
+ const source = await promises_default().readFile(buildModulePath, 'utf8');
87
+ return {
88
+ appId: source.match(/\bappId:\s*['"]([^'"]+)['"]/u)?.[1],
89
+ buildVersion: source.match(/\bbuild:\s*['"]([^'"]+)['"]/u)?.[1],
90
+ packageName: source.match(/\bpackageName:\s*['"]([^'"]+)['"]/u)?.[1],
91
+ version: source.match(/\bversion:\s*['"]([^'"]+)['"]/u)?.[1],
92
+ unitId: source.match(/\bunitId:\s*['"]([^'"]+)['"]/u)?.[1],
93
+ sourceRevision: source.match(/\bsourceRevision:\s*['"]([^'"]+)['"]/u)?.[1]
94
+ };
95
+ };
96
+ const toPascalCase = (value)=>value.split(/[^a-zA-Z0-9]+/u).filter(Boolean).map((part)=>part.charAt(0).toUpperCase() + part.slice(1)).join('');
97
+ const stringValue = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
98
+ const createBackendName = (app, id)=>{
99
+ const configuredName = stringValue(app.backendFederation?.name) ?? stringValue(app.backendFederation?.executionSurfaces?.node?.remoteName) ?? stringValue(app.serverExecution?.node?.remoteName);
100
+ if (configuredName) return configuredName;
101
+ const mfName = stringValue(app.moduleFederation?.name);
102
+ return mfName ? `${mfName}Backend` : `vertical${toPascalCase(id)}Backend`;
103
+ };
104
+ const findWorkspaceRoot = (appDirectory)=>{
105
+ let current = appDirectory;
106
+ while(true){
107
+ if ((0, external_node_fs_namespaceObject.existsSync)(external_node_path_default().join(current, COMPACT_CONFIG_PATH))) return current;
108
+ const parent = external_node_path_default().dirname(current);
109
+ if (parent === current) return;
110
+ current = parent;
111
+ }
112
+ };
113
+ const resolveWorkspaceSourceRevision = async (workspaceRoot)=>{
114
+ const envRevision = process.env.ULTRAMODERN_SOURCE_REVISION?.trim();
115
+ if (envRevision) return envRevision;
116
+ try {
117
+ const { stdout } = await execFileAsync('git', [
118
+ '-C',
119
+ workspaceRoot,
120
+ 'rev-parse',
121
+ 'HEAD'
122
+ ]);
123
+ const revision = stdout.trim();
124
+ if (revision.length > 0) return revision;
125
+ } catch {}
126
+ console.warn('[backend-federation-build] Could not resolve git source revision; stamping sourceRevision as "workspace". Set ULTRAMODERN_SOURCE_REVISION to override.');
127
+ return 'workspace';
128
+ };
129
+ const createStampedDeliveryUnit = (input)=>{
130
+ if (!input.unitId || !input.buildMarker || !input.packageName || !input.version) return;
131
+ const record = {
132
+ schemaVersion: universal_namespaceObject.DELIVERY_UNIT_SCHEMA_VERSION,
133
+ kind: universal_namespaceObject.DELIVERY_UNIT_KIND,
134
+ appId: input.appId,
135
+ unitId: input.unitId,
136
+ packageName: input.packageName,
137
+ version: input.version,
138
+ buildMarker: input.buildMarker,
139
+ sourceRevision: input.sourceRevision,
140
+ deployProfile: universal_namespaceObject.DELIVERY_UNIT_DEPLOY_PROFILE
141
+ };
142
+ const validation = (0, universal_namespaceObject.validateDeliveryUnitRecord)(record);
143
+ if (!validation.ok) return;
144
+ return (0, universal_namespaceObject.deliveryUnitContractBlock)(record);
145
+ };
146
+ const createAppFromCompactMetadata = (workspaceRoot, appDirectory, compactApp)=>{
147
+ const id = stringValue(compactApp.id);
148
+ const appPath = stringValue(compactApp.path);
149
+ if (!id || 'vertical' !== compactApp.kind || !isRecord(compactApp.api)) return;
150
+ const directory = appPath ? normalizeRelativePath(appPath) : `verticals/${id}`;
151
+ if (external_node_path_default().resolve(workspaceRoot, directory) !== external_node_path_default().resolve(appDirectory)) return;
152
+ const port = 'number' == typeof compactApp.port ? compactApp.port : void 0;
153
+ if (void 0 === port) return;
154
+ const apiPrefix = stringValue(compactApp.api.prefix) ?? `/${id}-api`;
155
+ const apiStem = stringValue(compactApp.api.stem) ?? id;
156
+ const backendName = createBackendName(compactApp, id);
157
+ const manifestUrl = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.manifestUrl) ?? stringValue(compactApp.serverExecution?.node?.manifestUrl) ?? `http://localhost:${port}/${universal_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE}`;
158
+ const containerEntry = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.containerEntry) ?? stringValue(compactApp.serverExecution?.node?.containerEntry) ?? `http://localhost:${port}/${universal_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE}`;
159
+ const remoteType = stringValue(compactApp.backendFederation?.executionSurfaces?.node?.remoteType) ?? stringValue(compactApp.serverExecution?.node?.remoteType) ?? 'module';
160
+ const packageName = stringValue(compactApp.package);
161
+ const uiManifestUrl = stringValue(compactApp.backendFederation?.versionBoundary?.ui?.manifestUrl) ?? stringValue(compactApp.moduleFederation?.manifestUrl);
162
+ const compactDeliveryUnit = isRecord(compactApp.deliveryUnit) ? {
163
+ unitId: stringValue(compactApp.deliveryUnit.unitId),
164
+ buildMarker: stringValue(compactApp.deliveryUnit.buildMarker),
165
+ sourceRevision: stringValue(compactApp.deliveryUnit.sourceRevision),
166
+ packageName: stringValue(compactApp.deliveryUnit.packageName),
167
+ version: stringValue(compactApp.deliveryUnit.version)
168
+ } : void 0;
169
+ return {
170
+ id,
171
+ directory,
172
+ packageName,
173
+ port,
174
+ apiPrefix,
175
+ apiStem,
176
+ backendName,
177
+ manifestUrl,
178
+ containerEntry,
179
+ remoteType,
180
+ uiManifestUrl,
181
+ compactDeliveryUnit
182
+ };
183
+ };
184
+ const findBackendFederationApp = async (workspaceRoot, appDirectory)=>{
185
+ const compactConfigPath = external_node_path_default().join(workspaceRoot, COMPACT_CONFIG_PATH);
186
+ const compactConfig = await readJsonFile(compactConfigPath);
187
+ const apps = Array.isArray(compactConfig.topology?.apps) ? compactConfig.topology.apps : [];
188
+ for (const app of apps){
189
+ const resolved = createAppFromCompactMetadata(workspaceRoot, appDirectory, app);
190
+ if (resolved) return resolved;
191
+ }
192
+ };
193
+ exports.COMPACT_CONFIG_PATH = __webpack_exports__.COMPACT_CONFIG_PATH;
194
+ exports.buildArtifactPathFor = __webpack_exports__.buildArtifactPathFor;
195
+ exports.buildModulePathFor = __webpack_exports__.buildModulePathFor;
196
+ exports.createAppFromCompactMetadata = __webpack_exports__.createAppFromCompactMetadata;
197
+ exports.createStampedDeliveryUnit = __webpack_exports__.createStampedDeliveryUnit;
198
+ exports.findBackendFederationApp = __webpack_exports__.findBackendFederationApp;
199
+ exports.findWorkspaceRoot = __webpack_exports__.findWorkspaceRoot;
200
+ exports.normalizeRelativePath = __webpack_exports__.normalizeRelativePath;
201
+ exports.readBuildIdentity = __webpack_exports__.readBuildIdentity;
202
+ exports.resolveWorkspaceSourceRevision = __webpack_exports__.resolveWorkspaceSourceRevision;
203
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
204
+ "COMPACT_CONFIG_PATH",
205
+ "buildArtifactPathFor",
206
+ "buildModulePathFor",
207
+ "createAppFromCompactMetadata",
208
+ "createStampedDeliveryUnit",
209
+ "findBackendFederationApp",
210
+ "findWorkspaceRoot",
211
+ "normalizeRelativePath",
212
+ "readBuildIdentity",
213
+ "resolveWorkspaceSourceRevision"
214
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
215
+ Object.defineProperty(exports, '__esModule', {
216
+ value: true
217
+ });
@@ -0,0 +1,139 @@
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: ()=>emit,
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 universal_namespaceObject = require("@modern-js/utils/universal");
49
+ const external_codegen_js_namespaceObject = require("./codegen.js");
50
+ const external_config_js_namespaceObject = require("./config.js");
51
+ const emitBackendFederationArtifacts = async (appDirectory, distDirectory)=>{
52
+ const workspaceRoot = (0, external_config_js_namespaceObject.findWorkspaceRoot)(appDirectory);
53
+ if (!workspaceRoot) return;
54
+ const effectApiPath = external_node_path_default().join(appDirectory, 'api/effect-api.ts');
55
+ const backendFederationConfigPath = external_node_path_default().join(appDirectory, 'backend-federation.config.ts');
56
+ if (!(0, external_node_fs_namespaceObject.existsSync)(effectApiPath) || !(0, external_node_fs_namespaceObject.existsSync)(backendFederationConfigPath)) return;
57
+ const app = await (0, external_config_js_namespaceObject.findBackendFederationApp)(workspaceRoot, appDirectory);
58
+ if (!app) return;
59
+ const buildIdentity = await (0, external_config_js_namespaceObject.readBuildIdentity)(appDirectory);
60
+ const compactDeliveryUnit = app.compactDeliveryUnit;
61
+ const hasCompactDeliveryUnit = void 0 !== compactDeliveryUnit && (void 0 !== compactDeliveryUnit.unitId || void 0 !== compactDeliveryUnit.buildMarker || void 0 !== compactDeliveryUnit.packageName || void 0 !== compactDeliveryUnit.version);
62
+ const hasBuildIdentity = void 0 !== buildIdentity.unitId || void 0 !== buildIdentity.buildVersion || void 0 !== buildIdentity.packageName || void 0 !== buildIdentity.version;
63
+ if (hasBuildIdentity) {
64
+ const compactConfigPath = external_node_path_default().join(workspaceRoot, external_config_js_namespaceObject.COMPACT_CONFIG_PATH);
65
+ const buildIdentityPath = (0, external_node_fs_namespaceObject.existsSync)((0, external_config_js_namespaceObject.buildArtifactPathFor)(appDirectory)) ? (0, external_config_js_namespaceObject.buildArtifactPathFor)(appDirectory) : (0, external_config_js_namespaceObject.buildModulePathFor)(appDirectory);
66
+ const mismatches = [];
67
+ const compare = (label, a, b, leftLabel = 'deliveryUnit')=>{
68
+ if (void 0 !== a && void 0 !== b && a !== b) mismatches.push(`${label}: ${leftLabel}=${a} vs ultramodern-build=${b}`);
69
+ };
70
+ compare('appId', app.id, buildIdentity.appId, 'topology');
71
+ if (hasCompactDeliveryUnit) {
72
+ compare('unitId', compactDeliveryUnit?.unitId, buildIdentity.unitId);
73
+ compare('buildMarker/build', compactDeliveryUnit?.buildMarker, buildIdentity.buildVersion);
74
+ compare('packageName', compactDeliveryUnit?.packageName, buildIdentity.packageName);
75
+ compare('version', compactDeliveryUnit?.version, buildIdentity.version);
76
+ }
77
+ if (mismatches.length > 0) throw new Error(`[backend-federation-build] Delivery-unit identity drift between ${compactConfigPath} (topology) and ${buildIdentityPath}: ${mismatches.join('; ')}`);
78
+ }
79
+ const unitId = compactDeliveryUnit?.unitId ?? buildIdentity.unitId;
80
+ const buildVersion = compactDeliveryUnit?.buildMarker ?? buildIdentity.buildVersion;
81
+ const sourceRevision = await (0, external_config_js_namespaceObject.resolveWorkspaceSourceRevision)(workspaceRoot);
82
+ const packageName = compactDeliveryUnit?.packageName ?? buildIdentity.packageName ?? app.packageName;
83
+ const version = compactDeliveryUnit?.version ?? buildIdentity.version;
84
+ const deliveryUnit = (0, external_config_js_namespaceObject.createStampedDeliveryUnit)({
85
+ appId: app.id,
86
+ unitId,
87
+ buildMarker: buildVersion,
88
+ packageName,
89
+ version,
90
+ sourceRevision
91
+ });
92
+ const stampedBuildArtifact = buildIdentity.artifact ? (0, universal_namespaceObject.stampUltramodernBuildArtifactSourceRevision)(buildIdentity.artifact, sourceRevision) : void 0;
93
+ const resolvedApp = {
94
+ ...app,
95
+ packageName,
96
+ version,
97
+ buildVersion,
98
+ unitId,
99
+ sourceRevision,
100
+ deliveryUnit
101
+ };
102
+ const manifestPath = external_node_path_default().join(distDirectory, universal_namespaceObject.BACKEND_FEDERATION_MANIFEST_FILE);
103
+ const entryPath = external_node_path_default().join(distDirectory, universal_namespaceObject.BACKEND_FEDERATION_REMOTE_ENTRY_FILE);
104
+ const deliveryUnitArtifactPath = stampedBuildArtifact ? external_node_path_default().join(distDirectory, universal_namespaceObject.ULTRAMODERN_BUILD_ARTIFACT_FILE) : void 0;
105
+ await promises_default().mkdir(distDirectory, {
106
+ recursive: true
107
+ });
108
+ await promises_default().writeFile(entryPath, (0, external_codegen_js_namespaceObject.createBackendRemoteEntrySource)(workspaceRoot, resolvedApp, effectApiPath, entryPath));
109
+ await promises_default().writeFile(manifestPath, `${JSON.stringify((0, external_codegen_js_namespaceObject.createBackendManifest)(workspaceRoot, distDirectory, resolvedApp), null, 2)}\n`);
110
+ if (stampedBuildArtifact && deliveryUnitArtifactPath) await promises_default().writeFile(deliveryUnitArtifactPath, `${JSON.stringify(stampedBuildArtifact, null, 2)}\n`);
111
+ return {
112
+ appId: resolvedApp.id,
113
+ manifestPath,
114
+ containerPath: entryPath,
115
+ ...deliveryUnitArtifactPath ? {
116
+ deliveryUnitArtifactPath
117
+ } : {},
118
+ remoteName: resolvedApp.backendName,
119
+ remoteType: resolvedApp.remoteType
120
+ };
121
+ };
122
+ const emit = ()=>({
123
+ name: '@modern-js/backend-federation-build',
124
+ setup (api) {
125
+ api.onAfterBuild(async ()=>{
126
+ const { appDirectory, distDirectory } = api.getAppContext();
127
+ await emitBackendFederationArtifacts(appDirectory, distDirectory);
128
+ });
129
+ }
130
+ });
131
+ exports["default"] = __webpack_exports__["default"];
132
+ exports.emitBackendFederationArtifacts = __webpack_exports__.emitBackendFederationArtifacts;
133
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
134
+ "default",
135
+ "emitBackendFederationArtifacts"
136
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
137
+ Object.defineProperty(exports, '__esModule', {
138
+ value: true
139
+ });