@bleedingdev/modern-js-ultramodern-app-tools 3.9.0-ultramodern.19 → 3.9.0-ultramodern.20
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/native-composition/index.js +1 -2
- package/dist/cjs/native-composition/module-federation-shared-plugin.js +61 -13
- package/dist/cjs/native-composition/release-envelope-plugin.js +1 -4
- package/dist/cjs/native-composition/ssr-integration-plugin.js +7 -42
- package/dist/esm/native-composition/index.mjs +1 -2
- package/dist/esm/native-composition/module-federation-shared-plugin.mjs +54 -12
- package/dist/esm/native-composition/release-envelope-plugin.mjs +1 -4
- package/dist/esm/native-composition/ssr-integration-plugin.mjs +8 -40
- package/dist/esm-node/native-composition/index.mjs +1 -2
- package/dist/esm-node/native-composition/module-federation-shared-plugin.mjs +54 -12
- package/dist/esm-node/native-composition/release-envelope-plugin.mjs +1 -4
- package/dist/esm-node/native-composition/ssr-integration-plugin.mjs +8 -40
- package/dist/types/native-composition/module-federation-shared-plugin.d.ts +19 -4
- package/dist/types/native-composition/ssr-integration-plugin.d.ts +0 -4
- package/dist/types-esm/native-composition/module-federation-shared-plugin.d.mts +19 -4
- package/dist/types-esm/native-composition/ssr-integration-plugin.d.mts +0 -4
- package/package.json +18 -18
- package/src/native-composition/index.ts +2 -3
- package/src/native-composition/module-federation-shared-plugin.ts +115 -17
- package/src/native-composition/release-envelope-plugin.ts +2 -2
- package/src/native-composition/ssr-integration-plugin.ts +26 -100
|
@@ -51,7 +51,6 @@ const backend_federation_build_namespaceObject = require("@modern-js/app-tools-e
|
|
|
51
51
|
var backend_federation_build_default = /*#__PURE__*/ __webpack_require__.n(backend_federation_build_namespaceObject);
|
|
52
52
|
const cloudflare_builder_namespaceObject = require("@modern-js/app-tools-extensions/cloudflare-builder");
|
|
53
53
|
const plugin_namespaceObject = require("@modern-js/app-tools-extensions/deploy-output/plugin");
|
|
54
|
-
const target_namespaceObject = require("@modern-js/app-tools-extensions/deploy-output/target");
|
|
55
54
|
const policy_defaults_namespaceObject = require("@modern-js/app-tools-extensions/policy-defaults");
|
|
56
55
|
const runtime_package_resolution_namespaceObject = require("@modern-js/app-tools-extensions/runtime-package-resolution");
|
|
57
56
|
const i18n_integration_namespaceObject = require("@modern-js/i18n-integration");
|
|
@@ -68,8 +67,8 @@ const headlessCloudflareWorkerPlugin = ()=>({
|
|
|
68
67
|
setup (api) {
|
|
69
68
|
api.onAfterBuild(async ()=>{
|
|
70
69
|
const appContext = api.getAppContext();
|
|
70
|
+
if (!appContext.apiOnly || 'cloudflare' !== appContext.deployTarget.target) return;
|
|
71
71
|
const normalizedConfig = api.getNormalizedConfig();
|
|
72
|
-
if (!appContext.apiOnly || 'cloudflare' !== (0, target_namespaceObject.resolveDeployTarget)(normalizedConfig)) return;
|
|
73
72
|
const createBuilderForModern = await (0, builder_namespaceObject.createBuilderGenerator)();
|
|
74
73
|
const builder = await createBuilderForModern({
|
|
75
74
|
appContext,
|
|
@@ -39,21 +39,26 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
40
|
FederationPrivateContextsPlugin: ()=>FederationPrivateContextsPlugin,
|
|
41
41
|
resolveFrameworkSharedPackages: ()=>resolveFrameworkSharedPackages,
|
|
42
|
+
resolveManifestRecoveryRuntimePlugin: ()=>resolveManifestRecoveryRuntimePlugin,
|
|
42
43
|
ultramodernModuleFederationSharedPlugin: ()=>ultramodernModuleFederationSharedPlugin,
|
|
43
44
|
withFrameworkShared: ()=>withFrameworkShared,
|
|
44
|
-
withReactJsxRuntimeShared: ()=>withReactJsxRuntimeShared
|
|
45
|
+
withReactJsxRuntimeShared: ()=>withReactJsxRuntimeShared,
|
|
46
|
+
withRuntimePlugin: ()=>withRuntimePlugin
|
|
45
47
|
});
|
|
46
48
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
49
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
47
50
|
const external_node_path_namespaceObject = require("node:path");
|
|
48
51
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
49
52
|
const REACT_JSX_RUNTIMES = [
|
|
50
53
|
'react/jsx-runtime',
|
|
51
54
|
'react/jsx-dev-runtime'
|
|
52
55
|
];
|
|
56
|
+
const MODULE_FEDERATION_SERVER_CHAIN_ID = 'plugin-module-federation-server';
|
|
53
57
|
const MODULE_FEDERATION_CHAIN_IDS = [
|
|
54
58
|
'plugin-module-federation',
|
|
55
|
-
|
|
59
|
+
MODULE_FEDERATION_SERVER_CHAIN_ID
|
|
56
60
|
];
|
|
61
|
+
const MANIFEST_RECOVERY_RUNTIME_PLUGIN = '@modern-js/federation-runtime/manifest-recovery-runtime-plugin';
|
|
57
62
|
const FRAMEWORK_SHARES = [
|
|
58
63
|
{
|
|
59
64
|
packageName: '@modern-js/runtime',
|
|
@@ -71,7 +76,10 @@ const FRAMEWORK_SHARES = [
|
|
|
71
76
|
packageName: '@modern-js/bff-effect',
|
|
72
77
|
prefix: '@modern-js/bff-effect/',
|
|
73
78
|
contextsRequest: '@modern-js/bff-effect/context',
|
|
74
|
-
contexts: /[\\/]effect[\\/]context\.[cm]?[jt]sx
|
|
79
|
+
contexts: /[\\/]effect[\\/]context\.[cm]?[jt]sx?$/,
|
|
80
|
+
peers: [
|
|
81
|
+
'effect'
|
|
82
|
+
]
|
|
75
83
|
}
|
|
76
84
|
];
|
|
77
85
|
const loadsCode = (target)=>'string' == typeof target ? !target.endsWith('.d.ts') : Boolean(target) && 'object' == typeof target && Object.entries(target).some(([condition, value])=>'types' !== condition && loadsCode(value));
|
|
@@ -85,17 +93,36 @@ const findInstalledManifest = (appDirectory, packageName)=>{
|
|
|
85
93
|
directory = parent;
|
|
86
94
|
}
|
|
87
95
|
};
|
|
96
|
+
const readManifest = (manifest)=>JSON.parse((0, external_node_fs_namespaceObject.readFileSync)(manifest, 'utf8'));
|
|
97
|
+
const peerShare = (directory, packageName)=>{
|
|
98
|
+
const manifest = findInstalledManifest(directory, packageName);
|
|
99
|
+
if (!manifest) return [];
|
|
100
|
+
return [
|
|
101
|
+
{
|
|
102
|
+
prefix: `${packageName}/`,
|
|
103
|
+
version: readManifest(manifest).version,
|
|
104
|
+
requests: [
|
|
105
|
+
packageName,
|
|
106
|
+
`${packageName}/`
|
|
107
|
+
],
|
|
108
|
+
directory: (0, external_node_fs_namespaceObject.realpathSync)(external_node_path_default().dirname(manifest))
|
|
109
|
+
}
|
|
110
|
+
];
|
|
111
|
+
};
|
|
88
112
|
const resolveFrameworkSharedPackages = (appDirectory)=>FRAMEWORK_SHARES.flatMap((share)=>{
|
|
89
113
|
const manifest = findInstalledManifest(appDirectory, share.packageName);
|
|
90
114
|
if (!manifest) return [];
|
|
91
|
-
const { version, exports: exports1 } =
|
|
115
|
+
const { version, exports: exports1 } = readManifest(manifest);
|
|
116
|
+
const directory = (0, external_node_fs_namespaceObject.realpathSync)(external_node_path_default().dirname(manifest));
|
|
117
|
+
const { peers = [], ...shareConfig } = share;
|
|
92
118
|
return [
|
|
93
119
|
{
|
|
94
|
-
...
|
|
120
|
+
...shareConfig,
|
|
95
121
|
version,
|
|
96
122
|
requests: exportedRequests(share.packageName, share.prefix, exports1),
|
|
97
|
-
directory
|
|
98
|
-
}
|
|
123
|
+
directory
|
|
124
|
+
},
|
|
125
|
+
...peers.flatMap((peer)=>peerShare(directory, peer))
|
|
99
126
|
];
|
|
100
127
|
});
|
|
101
128
|
const findShared = (entries, request)=>{
|
|
@@ -148,13 +175,28 @@ const withFrameworkShared = (shared, packages)=>withShared(shared, Object.fromEn
|
|
|
148
175
|
treeShaking: false
|
|
149
176
|
}
|
|
150
177
|
]))));
|
|
178
|
+
const resolveManifestRecoveryRuntimePlugin = (appDirectory)=>{
|
|
179
|
+
if (!findInstalledManifest(appDirectory, '@modern-js/federation-runtime')) return;
|
|
180
|
+
return (0, external_node_module_namespaceObject.createRequire)(external_node_path_default().join(appDirectory, 'package.json')).resolve(MANIFEST_RECOVERY_RUNTIME_PLUGIN);
|
|
181
|
+
};
|
|
182
|
+
const withRuntimePlugin = (runtimePlugins, runtimePlugin)=>{
|
|
183
|
+
const plugins = runtimePlugins ?? [];
|
|
184
|
+
const registered = plugins.some((plugin)=>(Array.isArray(plugin) ? plugin[0] : plugin) === runtimePlugin);
|
|
185
|
+
return registered ? plugins : [
|
|
186
|
+
...plugins,
|
|
187
|
+
runtimePlugin
|
|
188
|
+
];
|
|
189
|
+
};
|
|
151
190
|
const federationConfig = (options)=>options.mfConfig && 'object' == typeof options.mfConfig ? federationConfig(options.mfConfig) : options;
|
|
152
|
-
const withDefaults = (options, packages)=>options.mfConfig && 'object' == typeof options.mfConfig ? {
|
|
191
|
+
const withDefaults = (options, packages, runtimePlugin)=>options.mfConfig && 'object' == typeof options.mfConfig ? {
|
|
153
192
|
...options,
|
|
154
|
-
mfConfig: withDefaults(options.mfConfig, packages)
|
|
193
|
+
mfConfig: withDefaults(options.mfConfig, packages, runtimePlugin)
|
|
155
194
|
} : {
|
|
156
195
|
...options,
|
|
157
|
-
shared: withFrameworkShared(withReactJsxRuntimeShared(options.shared), packages)
|
|
196
|
+
shared: withFrameworkShared(withReactJsxRuntimeShared(options.shared), packages),
|
|
197
|
+
...runtimePlugin ? {
|
|
198
|
+
runtimePlugins: withRuntimePlugin(options.runtimePlugins, runtimePlugin)
|
|
199
|
+
} : {}
|
|
158
200
|
};
|
|
159
201
|
const hasExposes = (options)=>{
|
|
160
202
|
const { exposes } = federationConfig(options);
|
|
@@ -203,13 +245,15 @@ const ultramodernModuleFederationSharedPlugin = ()=>({
|
|
|
203
245
|
api.modifyBundlerChain((chain)=>{
|
|
204
246
|
const ids = MODULE_FEDERATION_CHAIN_IDS.filter((id)=>chain.plugins.has(id));
|
|
205
247
|
if (0 === ids.length) return;
|
|
206
|
-
const
|
|
248
|
+
const { appDirectory } = api.getAppContext();
|
|
249
|
+
const packages = resolveFrameworkSharedPackages(appDirectory);
|
|
250
|
+
const manifestRecovery = resolveManifestRecoveryRuntimePlugin(appDirectory);
|
|
207
251
|
let exposes = false;
|
|
208
252
|
for (const id of ids){
|
|
209
253
|
const [options] = chain.plugin(id).get('args');
|
|
210
254
|
exposes ||= hasExposes(options);
|
|
211
255
|
chain.plugin(id).tap(([options, ...rest])=>[
|
|
212
|
-
withDefaults(options, packages),
|
|
256
|
+
withDefaults(options, packages, id === MODULE_FEDERATION_SERVER_CHAIN_ID ? manifestRecovery : void 0),
|
|
213
257
|
...rest
|
|
214
258
|
]);
|
|
215
259
|
}
|
|
@@ -221,15 +265,19 @@ const ultramodernModuleFederationSharedPlugin = ()=>({
|
|
|
221
265
|
});
|
|
222
266
|
exports.FederationPrivateContextsPlugin = __webpack_exports__.FederationPrivateContextsPlugin;
|
|
223
267
|
exports.resolveFrameworkSharedPackages = __webpack_exports__.resolveFrameworkSharedPackages;
|
|
268
|
+
exports.resolveManifestRecoveryRuntimePlugin = __webpack_exports__.resolveManifestRecoveryRuntimePlugin;
|
|
224
269
|
exports.ultramodernModuleFederationSharedPlugin = __webpack_exports__.ultramodernModuleFederationSharedPlugin;
|
|
225
270
|
exports.withFrameworkShared = __webpack_exports__.withFrameworkShared;
|
|
226
271
|
exports.withReactJsxRuntimeShared = __webpack_exports__.withReactJsxRuntimeShared;
|
|
272
|
+
exports.withRuntimePlugin = __webpack_exports__.withRuntimePlugin;
|
|
227
273
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
228
274
|
"FederationPrivateContextsPlugin",
|
|
229
275
|
"resolveFrameworkSharedPackages",
|
|
276
|
+
"resolveManifestRecoveryRuntimePlugin",
|
|
230
277
|
"ultramodernModuleFederationSharedPlugin",
|
|
231
278
|
"withFrameworkShared",
|
|
232
|
-
"withReactJsxRuntimeShared"
|
|
279
|
+
"withReactJsxRuntimeShared",
|
|
280
|
+
"withRuntimePlugin"
|
|
233
281
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
234
282
|
Object.defineProperty(exports, '__esModule', {
|
|
235
283
|
value: true
|
|
@@ -30,11 +30,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
ultramodernReleaseEnvelopePlugin: ()=>ultramodernReleaseEnvelopePlugin
|
|
32
32
|
});
|
|
33
|
-
const target_namespaceObject = require("@modern-js/app-tools-extensions/deploy-output/target");
|
|
34
33
|
const plugin_namespaceObject = require("@modern-js/app-tools-extensions/release-envelope/plugin");
|
|
35
|
-
const ultramodernReleaseEnvelopePlugin = ()=>(0, plugin_namespaceObject.createUltramodernReleaseEnvelopePlugin)(
|
|
36
|
-
resolveDeployTarget: target_namespaceObject.resolveDeployTarget
|
|
37
|
-
});
|
|
34
|
+
const ultramodernReleaseEnvelopePlugin = ()=>(0, plugin_namespaceObject.createUltramodernReleaseEnvelopePlugin)();
|
|
38
35
|
exports.ultramodernReleaseEnvelopePlugin = __webpack_exports__.ultramodernReleaseEnvelopePlugin;
|
|
39
36
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
40
37
|
"ultramodernReleaseEnvelopePlugin"
|
|
@@ -27,38 +27,17 @@ var __webpack_require__ = {};
|
|
|
27
27
|
})();
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
const hasModuleFederationMarker = (config, projectMarker)=>{
|
|
31
|
-
if (projectMarker) return true;
|
|
32
|
-
const define = config.source?.define ?? {};
|
|
33
|
-
if ('REMOTE_IP_STRATEGY' in define || 'FEDERATION_IPV4' in define) return true;
|
|
34
|
-
const rspack = config.tools?.rspack;
|
|
35
|
-
return (Array.isArray(rspack) ? rspack : [
|
|
36
|
-
rspack
|
|
37
|
-
]).some((entry)=>{
|
|
38
|
-
if (!entry || 'object' != typeof entry || !('plugins' in entry) || !Array.isArray(entry.plugins)) return false;
|
|
39
|
-
return entry.plugins.some((input)=>{
|
|
40
|
-
const plugin = Array.isArray(input) ? input[0] : input;
|
|
41
|
-
if (!plugin) return false;
|
|
42
|
-
const name = 'string' == typeof plugin ? plugin : 'function' == typeof plugin ? plugin.name : 'object' == typeof plugin ? plugin.name || plugin.constructor?.name : void 0;
|
|
43
|
-
return 'string' == typeof name && /modulefederation/i.test(name);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
30
|
const normalizeSsrCapabilities = (config)=>{
|
|
48
31
|
const ssr = [
|
|
49
32
|
config.server?.ssr,
|
|
50
33
|
...Object.values(config.server?.ssrByEntries ?? {})
|
|
51
34
|
];
|
|
35
|
+
const rendering = Boolean(config.output?.ssg || Object.keys(config.output?.ssgByEntries ?? {}).length || config.server?.ssr || Object.keys(config.server?.ssrByEntries ?? {}).length);
|
|
52
36
|
return {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
worker: config.deploy?.target === 'cloudflare',
|
|
56
|
-
projectMarker: 'true' === process.env.MF_SSR_PRJ,
|
|
57
|
-
requireExplicit: 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT
|
|
37
|
+
federation: rendering && ssr.some((value)=>value && 'object' == typeof value && true === value.moduleFederationAppSSR),
|
|
38
|
+
worker: config.deploy?.target === 'cloudflare'
|
|
58
39
|
};
|
|
59
40
|
};
|
|
60
|
-
const isNodeEnvironmentTarget = (target)=>'string' == typeof target && ('node' === target || 'async-node' === target || target.startsWith('node'));
|
|
61
|
-
const shouldUseModuleFederationNodeOutput = (config)=>isNodeEnvironmentTarget(config.output?.target) && hasModuleFederationMarker(config, 'true' === process.env.MF_SSR_PRJ);
|
|
62
41
|
const ssrIntegrationBuilderPlugin = (modernAPI)=>({
|
|
63
42
|
name: '@modern-js/ultramodern-builder-plugin-ssr',
|
|
64
43
|
pre: [
|
|
@@ -66,29 +45,18 @@ const ssrIntegrationBuilderPlugin = (modernAPI)=>({
|
|
|
66
45
|
],
|
|
67
46
|
setup (api) {
|
|
68
47
|
const capabilities = normalizeSsrCapabilities(modernAPI.getNormalizedConfig());
|
|
69
|
-
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>{
|
|
70
|
-
const isServerEnvironment = isNodeEnvironmentTarget(config.output.target) || 'workerSSR' === name;
|
|
71
|
-
const hasModuleFederationRuntimeMarker = capabilities.rendering && isNodeEnvironmentTarget(config.output.target) && hasModuleFederationMarker(config, capabilities.projectMarker);
|
|
72
|
-
if (capabilities.rendering && hasModuleFederationRuntimeMarker && !capabilities.federation) {
|
|
73
|
-
const warningMessage = '[modernjs][mf-ssr] Module Federation SSR was auto-detected from runtime markers. Set server.ssr.moduleFederationAppSSR=true explicitly in host and remotes to avoid heuristic drift.';
|
|
74
|
-
if (capabilities.requireExplicit) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
75
|
-
console.warn(warningMessage);
|
|
76
|
-
}
|
|
77
|
-
const isModuleFederationAppSSR = capabilities.rendering && capabilities.federation;
|
|
78
|
-
return mergeEnvironmentConfig(config, {
|
|
48
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>mergeEnvironmentConfig(config, {
|
|
79
49
|
source: {
|
|
80
50
|
define: {
|
|
81
|
-
'process.env.MODERN_MF_APP_SSR': JSON.stringify(String(
|
|
51
|
+
'process.env.MODERN_MF_APP_SSR': JSON.stringify(String(capabilities.federation))
|
|
82
52
|
}
|
|
83
53
|
},
|
|
84
54
|
...'workerSSR' === name && capabilities.worker ? {
|
|
85
55
|
output: {
|
|
86
56
|
module: true
|
|
87
57
|
}
|
|
88
|
-
} : {}
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
});
|
|
58
|
+
} : {}
|
|
59
|
+
}));
|
|
92
60
|
}
|
|
93
61
|
});
|
|
94
62
|
const ultramodernSSRIntegrationPlugin = ()=>({
|
|
@@ -102,13 +70,10 @@ const ultramodernSSRIntegrationPlugin = ()=>({
|
|
|
102
70
|
}
|
|
103
71
|
});
|
|
104
72
|
__webpack_require__.d(__webpack_exports__, {}, {
|
|
105
|
-
shouldUseModuleFederationNodeOutput: shouldUseModuleFederationNodeOutput,
|
|
106
73
|
ultramodernSSRIntegrationPlugin: ultramodernSSRIntegrationPlugin
|
|
107
74
|
});
|
|
108
|
-
exports.shouldUseModuleFederationNodeOutput = __webpack_exports__.shouldUseModuleFederationNodeOutput;
|
|
109
75
|
exports.ultramodernSSRIntegrationPlugin = __webpack_exports__.ultramodernSSRIntegrationPlugin;
|
|
110
76
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
111
|
-
"shouldUseModuleFederationNodeOutput",
|
|
112
77
|
"ultramodernSSRIntegrationPlugin"
|
|
113
78
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
114
79
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -3,7 +3,6 @@ import { createBuilderGenerator } from "@modern-js/app-tools/builder";
|
|
|
3
3
|
import backend_federation_build from "@modern-js/app-tools-extensions/backend-federation-build";
|
|
4
4
|
import { createCloudflareBuilderPlugin } from "@modern-js/app-tools-extensions/cloudflare-builder";
|
|
5
5
|
import { createDeployOutputAliasesPlugin, createDeployOutputPublicAssetsPlugin } from "@modern-js/app-tools-extensions/deploy-output/plugin";
|
|
6
|
-
import { resolveDeployTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
|
|
7
6
|
import { RENDERER_EXTENSIONS_PACKAGE, SERVER_EXTENSIONS_PLUGIN_NAME } from "@modern-js/app-tools-extensions/policy-defaults";
|
|
8
7
|
import { collectRuntimePackageModuleDirectories, createRuntimePackageResolutionPlugin } from "@modern-js/app-tools-extensions/runtime-package-resolution";
|
|
9
8
|
import { ultramodernI18nIntegrationPlugin } from "@modern-js/i18n-integration";
|
|
@@ -19,8 +18,8 @@ const headlessCloudflareWorkerPlugin = ()=>({
|
|
|
19
18
|
setup (api) {
|
|
20
19
|
api.onAfterBuild(async ()=>{
|
|
21
20
|
const appContext = api.getAppContext();
|
|
21
|
+
if (!appContext.apiOnly || 'cloudflare' !== appContext.deployTarget.target) return;
|
|
22
22
|
const normalizedConfig = api.getNormalizedConfig();
|
|
23
|
-
if (!appContext.apiOnly || 'cloudflare' !== resolveDeployTarget(normalizedConfig)) return;
|
|
24
23
|
const createBuilderForModern = await createBuilderGenerator();
|
|
25
24
|
const builder = await createBuilderForModern({
|
|
26
25
|
appContext,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import node_path from "node:path";
|
|
3
4
|
const REACT_JSX_RUNTIMES = [
|
|
4
5
|
'react/jsx-runtime',
|
|
5
6
|
'react/jsx-dev-runtime'
|
|
6
7
|
];
|
|
8
|
+
const MODULE_FEDERATION_SERVER_CHAIN_ID = 'plugin-module-federation-server';
|
|
7
9
|
const MODULE_FEDERATION_CHAIN_IDS = [
|
|
8
10
|
'plugin-module-federation',
|
|
9
|
-
|
|
11
|
+
MODULE_FEDERATION_SERVER_CHAIN_ID
|
|
10
12
|
];
|
|
13
|
+
const MANIFEST_RECOVERY_RUNTIME_PLUGIN = '@modern-js/federation-runtime/manifest-recovery-runtime-plugin';
|
|
11
14
|
const FRAMEWORK_SHARES = [
|
|
12
15
|
{
|
|
13
16
|
packageName: '@modern-js/runtime',
|
|
@@ -25,7 +28,10 @@ const FRAMEWORK_SHARES = [
|
|
|
25
28
|
packageName: '@modern-js/bff-effect',
|
|
26
29
|
prefix: '@modern-js/bff-effect/',
|
|
27
30
|
contextsRequest: '@modern-js/bff-effect/context',
|
|
28
|
-
contexts: /[\\/]effect[\\/]context\.[cm]?[jt]sx
|
|
31
|
+
contexts: /[\\/]effect[\\/]context\.[cm]?[jt]sx?$/,
|
|
32
|
+
peers: [
|
|
33
|
+
'effect'
|
|
34
|
+
]
|
|
29
35
|
}
|
|
30
36
|
];
|
|
31
37
|
const loadsCode = (target)=>'string' == typeof target ? !target.endsWith('.d.ts') : Boolean(target) && 'object' == typeof target && Object.entries(target).some(([condition, value])=>'types' !== condition && loadsCode(value));
|
|
@@ -39,17 +45,36 @@ const findInstalledManifest = (appDirectory, packageName)=>{
|
|
|
39
45
|
directory = parent;
|
|
40
46
|
}
|
|
41
47
|
};
|
|
48
|
+
const readManifest = (manifest)=>JSON.parse(readFileSync(manifest, 'utf8'));
|
|
49
|
+
const peerShare = (directory, packageName)=>{
|
|
50
|
+
const manifest = findInstalledManifest(directory, packageName);
|
|
51
|
+
if (!manifest) return [];
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
prefix: `${packageName}/`,
|
|
55
|
+
version: readManifest(manifest).version,
|
|
56
|
+
requests: [
|
|
57
|
+
packageName,
|
|
58
|
+
`${packageName}/`
|
|
59
|
+
],
|
|
60
|
+
directory: realpathSync(node_path.dirname(manifest))
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
};
|
|
42
64
|
const resolveFrameworkSharedPackages = (appDirectory)=>FRAMEWORK_SHARES.flatMap((share)=>{
|
|
43
65
|
const manifest = findInstalledManifest(appDirectory, share.packageName);
|
|
44
66
|
if (!manifest) return [];
|
|
45
|
-
const { version, exports } =
|
|
67
|
+
const { version, exports } = readManifest(manifest);
|
|
68
|
+
const directory = realpathSync(node_path.dirname(manifest));
|
|
69
|
+
const { peers = [], ...shareConfig } = share;
|
|
46
70
|
return [
|
|
47
71
|
{
|
|
48
|
-
...
|
|
72
|
+
...shareConfig,
|
|
49
73
|
version,
|
|
50
74
|
requests: exportedRequests(share.packageName, share.prefix, exports),
|
|
51
|
-
directory
|
|
52
|
-
}
|
|
75
|
+
directory
|
|
76
|
+
},
|
|
77
|
+
...peers.flatMap((peer)=>peerShare(directory, peer))
|
|
53
78
|
];
|
|
54
79
|
});
|
|
55
80
|
const findShared = (entries, request)=>{
|
|
@@ -102,13 +127,28 @@ const withFrameworkShared = (shared, packages)=>withShared(shared, Object.fromEn
|
|
|
102
127
|
treeShaking: false
|
|
103
128
|
}
|
|
104
129
|
]))));
|
|
130
|
+
const resolveManifestRecoveryRuntimePlugin = (appDirectory)=>{
|
|
131
|
+
if (!findInstalledManifest(appDirectory, '@modern-js/federation-runtime')) return;
|
|
132
|
+
return createRequire(node_path.join(appDirectory, 'package.json')).resolve(MANIFEST_RECOVERY_RUNTIME_PLUGIN);
|
|
133
|
+
};
|
|
134
|
+
const withRuntimePlugin = (runtimePlugins, runtimePlugin)=>{
|
|
135
|
+
const plugins = runtimePlugins ?? [];
|
|
136
|
+
const registered = plugins.some((plugin)=>(Array.isArray(plugin) ? plugin[0] : plugin) === runtimePlugin);
|
|
137
|
+
return registered ? plugins : [
|
|
138
|
+
...plugins,
|
|
139
|
+
runtimePlugin
|
|
140
|
+
];
|
|
141
|
+
};
|
|
105
142
|
const federationConfig = (options)=>options.mfConfig && 'object' == typeof options.mfConfig ? federationConfig(options.mfConfig) : options;
|
|
106
|
-
const withDefaults = (options, packages)=>options.mfConfig && 'object' == typeof options.mfConfig ? {
|
|
143
|
+
const withDefaults = (options, packages, runtimePlugin)=>options.mfConfig && 'object' == typeof options.mfConfig ? {
|
|
107
144
|
...options,
|
|
108
|
-
mfConfig: withDefaults(options.mfConfig, packages)
|
|
145
|
+
mfConfig: withDefaults(options.mfConfig, packages, runtimePlugin)
|
|
109
146
|
} : {
|
|
110
147
|
...options,
|
|
111
|
-
shared: withFrameworkShared(withReactJsxRuntimeShared(options.shared), packages)
|
|
148
|
+
shared: withFrameworkShared(withReactJsxRuntimeShared(options.shared), packages),
|
|
149
|
+
...runtimePlugin ? {
|
|
150
|
+
runtimePlugins: withRuntimePlugin(options.runtimePlugins, runtimePlugin)
|
|
151
|
+
} : {}
|
|
112
152
|
};
|
|
113
153
|
const hasExposes = (options)=>{
|
|
114
154
|
const { exposes } = federationConfig(options);
|
|
@@ -157,13 +197,15 @@ const ultramodernModuleFederationSharedPlugin = ()=>({
|
|
|
157
197
|
api.modifyBundlerChain((chain)=>{
|
|
158
198
|
const ids = MODULE_FEDERATION_CHAIN_IDS.filter((id)=>chain.plugins.has(id));
|
|
159
199
|
if (0 === ids.length) return;
|
|
160
|
-
const
|
|
200
|
+
const { appDirectory } = api.getAppContext();
|
|
201
|
+
const packages = resolveFrameworkSharedPackages(appDirectory);
|
|
202
|
+
const manifestRecovery = resolveManifestRecoveryRuntimePlugin(appDirectory);
|
|
161
203
|
let exposes = false;
|
|
162
204
|
for (const id of ids){
|
|
163
205
|
const [options] = chain.plugin(id).get('args');
|
|
164
206
|
exposes ||= hasExposes(options);
|
|
165
207
|
chain.plugin(id).tap(([options, ...rest])=>[
|
|
166
|
-
withDefaults(options, packages),
|
|
208
|
+
withDefaults(options, packages, id === MODULE_FEDERATION_SERVER_CHAIN_ID ? manifestRecovery : void 0),
|
|
167
209
|
...rest
|
|
168
210
|
]);
|
|
169
211
|
}
|
|
@@ -173,4 +215,4 @@ const ultramodernModuleFederationSharedPlugin = ()=>({
|
|
|
173
215
|
});
|
|
174
216
|
}
|
|
175
217
|
});
|
|
176
|
-
export { FederationPrivateContextsPlugin, resolveFrameworkSharedPackages, ultramodernModuleFederationSharedPlugin, withFrameworkShared, withReactJsxRuntimeShared };
|
|
218
|
+
export { FederationPrivateContextsPlugin, resolveFrameworkSharedPackages, resolveManifestRecoveryRuntimePlugin, ultramodernModuleFederationSharedPlugin, withFrameworkShared, withReactJsxRuntimeShared, withRuntimePlugin };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { resolveDeployTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
|
|
2
1
|
import { createUltramodernReleaseEnvelopePlugin } from "@modern-js/app-tools-extensions/release-envelope/plugin";
|
|
3
|
-
const ultramodernReleaseEnvelopePlugin = ()=>createUltramodernReleaseEnvelopePlugin(
|
|
4
|
-
resolveDeployTarget: resolveDeployTarget
|
|
5
|
-
});
|
|
2
|
+
const ultramodernReleaseEnvelopePlugin = ()=>createUltramodernReleaseEnvelopePlugin();
|
|
6
3
|
export { ultramodernReleaseEnvelopePlugin };
|
|
@@ -1,35 +1,14 @@
|
|
|
1
|
-
const hasModuleFederationMarker = (config, projectMarker)=>{
|
|
2
|
-
if (projectMarker) return true;
|
|
3
|
-
const define = config.source?.define ?? {};
|
|
4
|
-
if ('REMOTE_IP_STRATEGY' in define || 'FEDERATION_IPV4' in define) return true;
|
|
5
|
-
const rspack = config.tools?.rspack;
|
|
6
|
-
return (Array.isArray(rspack) ? rspack : [
|
|
7
|
-
rspack
|
|
8
|
-
]).some((entry)=>{
|
|
9
|
-
if (!entry || 'object' != typeof entry || !('plugins' in entry) || !Array.isArray(entry.plugins)) return false;
|
|
10
|
-
return entry.plugins.some((input)=>{
|
|
11
|
-
const plugin = Array.isArray(input) ? input[0] : input;
|
|
12
|
-
if (!plugin) return false;
|
|
13
|
-
const name = 'string' == typeof plugin ? plugin : 'function' == typeof plugin ? plugin.name : 'object' == typeof plugin ? plugin.name || plugin.constructor?.name : void 0;
|
|
14
|
-
return 'string' == typeof name && /modulefederation/i.test(name);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
1
|
const normalizeSsrCapabilities = (config)=>{
|
|
19
2
|
const ssr = [
|
|
20
3
|
config.server?.ssr,
|
|
21
4
|
...Object.values(config.server?.ssrByEntries ?? {})
|
|
22
5
|
];
|
|
6
|
+
const rendering = Boolean(config.output?.ssg || Object.keys(config.output?.ssgByEntries ?? {}).length || config.server?.ssr || Object.keys(config.server?.ssrByEntries ?? {}).length);
|
|
23
7
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
worker: config.deploy?.target === 'cloudflare',
|
|
27
|
-
projectMarker: 'true' === process.env.MF_SSR_PRJ,
|
|
28
|
-
requireExplicit: 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT
|
|
8
|
+
federation: rendering && ssr.some((value)=>value && 'object' == typeof value && true === value.moduleFederationAppSSR),
|
|
9
|
+
worker: config.deploy?.target === 'cloudflare'
|
|
29
10
|
};
|
|
30
11
|
};
|
|
31
|
-
const isNodeEnvironmentTarget = (target)=>'string' == typeof target && ('node' === target || 'async-node' === target || target.startsWith('node'));
|
|
32
|
-
const shouldUseModuleFederationNodeOutput = (config)=>isNodeEnvironmentTarget(config.output?.target) && hasModuleFederationMarker(config, 'true' === process.env.MF_SSR_PRJ);
|
|
33
12
|
const ssrIntegrationBuilderPlugin = (modernAPI)=>({
|
|
34
13
|
name: '@modern-js/ultramodern-builder-plugin-ssr',
|
|
35
14
|
pre: [
|
|
@@ -37,29 +16,18 @@ const ssrIntegrationBuilderPlugin = (modernAPI)=>({
|
|
|
37
16
|
],
|
|
38
17
|
setup (api) {
|
|
39
18
|
const capabilities = normalizeSsrCapabilities(modernAPI.getNormalizedConfig());
|
|
40
|
-
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>{
|
|
41
|
-
const isServerEnvironment = isNodeEnvironmentTarget(config.output.target) || 'workerSSR' === name;
|
|
42
|
-
const hasModuleFederationRuntimeMarker = capabilities.rendering && isNodeEnvironmentTarget(config.output.target) && hasModuleFederationMarker(config, capabilities.projectMarker);
|
|
43
|
-
if (capabilities.rendering && hasModuleFederationRuntimeMarker && !capabilities.federation) {
|
|
44
|
-
const warningMessage = '[modernjs][mf-ssr] Module Federation SSR was auto-detected from runtime markers. Set server.ssr.moduleFederationAppSSR=true explicitly in host and remotes to avoid heuristic drift.';
|
|
45
|
-
if (capabilities.requireExplicit) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
46
|
-
console.warn(warningMessage);
|
|
47
|
-
}
|
|
48
|
-
const isModuleFederationAppSSR = capabilities.rendering && capabilities.federation;
|
|
49
|
-
return mergeEnvironmentConfig(config, {
|
|
19
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>mergeEnvironmentConfig(config, {
|
|
50
20
|
source: {
|
|
51
21
|
define: {
|
|
52
|
-
'process.env.MODERN_MF_APP_SSR': JSON.stringify(String(
|
|
22
|
+
'process.env.MODERN_MF_APP_SSR': JSON.stringify(String(capabilities.federation))
|
|
53
23
|
}
|
|
54
24
|
},
|
|
55
25
|
...'workerSSR' === name && capabilities.worker ? {
|
|
56
26
|
output: {
|
|
57
27
|
module: true
|
|
58
28
|
}
|
|
59
|
-
} : {}
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
});
|
|
29
|
+
} : {}
|
|
30
|
+
}));
|
|
63
31
|
}
|
|
64
32
|
});
|
|
65
33
|
const ultramodernSSRIntegrationPlugin = ()=>({
|
|
@@ -72,4 +40,4 @@ const ultramodernSSRIntegrationPlugin = ()=>({
|
|
|
72
40
|
}));
|
|
73
41
|
}
|
|
74
42
|
});
|
|
75
|
-
export {
|
|
43
|
+
export { ultramodernSSRIntegrationPlugin };
|
|
@@ -4,7 +4,6 @@ import { createBuilderGenerator } from "@modern-js/app-tools/builder";
|
|
|
4
4
|
import backend_federation_build from "@modern-js/app-tools-extensions/backend-federation-build";
|
|
5
5
|
import { createCloudflareBuilderPlugin } from "@modern-js/app-tools-extensions/cloudflare-builder";
|
|
6
6
|
import { createDeployOutputAliasesPlugin, createDeployOutputPublicAssetsPlugin } from "@modern-js/app-tools-extensions/deploy-output/plugin";
|
|
7
|
-
import { resolveDeployTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
|
|
8
7
|
import { RENDERER_EXTENSIONS_PACKAGE, SERVER_EXTENSIONS_PLUGIN_NAME } from "@modern-js/app-tools-extensions/policy-defaults";
|
|
9
8
|
import { collectRuntimePackageModuleDirectories, createRuntimePackageResolutionPlugin } from "@modern-js/app-tools-extensions/runtime-package-resolution";
|
|
10
9
|
import { ultramodernI18nIntegrationPlugin } from "@modern-js/i18n-integration";
|
|
@@ -20,8 +19,8 @@ const headlessCloudflareWorkerPlugin = ()=>({
|
|
|
20
19
|
setup (api) {
|
|
21
20
|
api.onAfterBuild(async ()=>{
|
|
22
21
|
const appContext = api.getAppContext();
|
|
22
|
+
if (!appContext.apiOnly || 'cloudflare' !== appContext.deployTarget.target) return;
|
|
23
23
|
const normalizedConfig = api.getNormalizedConfig();
|
|
24
|
-
if (!appContext.apiOnly || 'cloudflare' !== resolveDeployTarget(normalizedConfig)) return;
|
|
25
24
|
const createBuilderForModern = await createBuilderGenerator();
|
|
26
25
|
const builder = await createBuilderForModern({
|
|
27
26
|
appContext,
|