@bleedingdev/modern-js-ultramodern-app-tools 0.0.0 → 3.9.0-ultramodern.6
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/LICENSE +21 -0
- package/dist/cjs/native-composition/index.js +113 -0
- package/dist/cjs/native-composition/preset.js +178 -0
- package/dist/cjs/native-composition/release-envelope-plugin.js +44 -0
- package/dist/cjs/native-composition/router-integration-plugin.js +55 -0
- package/dist/cjs/native-composition/router-runtime.js +66 -0
- package/dist/cjs/native-composition/rsc-disabled-plugin.js +117 -0
- package/dist/cjs/native-composition/server-plugin.js +50 -0
- package/dist/cjs/native-composition/ssr-integration-plugin.js +145 -0
- package/dist/cjs/native-composition/types.js +18 -0
- package/dist/esm/native-composition/index.mjs +56 -0
- package/dist/esm/native-composition/preset.mjs +126 -0
- package/dist/esm/native-composition/release-envelope-plugin.mjs +6 -0
- package/dist/esm/native-composition/router-integration-plugin.mjs +17 -0
- package/dist/esm/native-composition/router-runtime.mjs +26 -0
- package/dist/esm/native-composition/rsc-disabled-plugin.mjs +79 -0
- package/dist/esm/native-composition/server-plugin.mjs +1 -0
- package/dist/esm/native-composition/ssr-integration-plugin.mjs +104 -0
- package/dist/esm/native-composition/types.mjs +0 -0
- package/dist/esm-node/native-composition/index.mjs +57 -0
- package/dist/esm-node/native-composition/preset.mjs +127 -0
- package/dist/esm-node/native-composition/release-envelope-plugin.mjs +7 -0
- package/dist/esm-node/native-composition/router-integration-plugin.mjs +18 -0
- package/dist/esm-node/native-composition/router-runtime.mjs +27 -0
- package/dist/esm-node/native-composition/rsc-disabled-plugin.mjs +81 -0
- package/dist/esm-node/native-composition/server-plugin.mjs +2 -0
- package/dist/esm-node/native-composition/ssr-integration-plugin.mjs +105 -0
- package/dist/esm-node/native-composition/types.mjs +1 -0
- package/dist/types/native-composition/index.d.ts +6 -0
- package/dist/types/native-composition/preset.d.ts +86 -0
- package/dist/types/native-composition/release-envelope-plugin.d.ts +2 -0
- package/dist/types/native-composition/router-integration-plugin.d.ts +3 -0
- package/dist/types/native-composition/router-runtime.d.ts +4 -0
- package/dist/types/native-composition/rsc-disabled-plugin.d.ts +2 -0
- package/dist/types/native-composition/server-plugin.d.ts +1 -0
- package/dist/types/native-composition/ssr-integration-plugin.d.ts +7 -0
- package/dist/types/native-composition/types.d.ts +24 -0
- package/dist/types-esm/native-composition/index.d.mts +6 -0
- package/dist/types-esm/native-composition/preset.d.mts +86 -0
- package/dist/types-esm/native-composition/release-envelope-plugin.d.mts +2 -0
- package/dist/types-esm/native-composition/router-integration-plugin.d.mts +3 -0
- package/dist/types-esm/native-composition/router-runtime.d.mts +4 -0
- package/dist/types-esm/native-composition/rsc-disabled-plugin.d.mts +2 -0
- package/dist/types-esm/native-composition/server-plugin.d.mts +1 -0
- package/dist/types-esm/native-composition/ssr-integration-plugin.d.mts +7 -0
- package/dist/types-esm/native-composition/types.d.mts +24 -0
- package/package.json +100 -5
- package/src/native-composition/index.ts +59 -0
- package/src/native-composition/preset.ts +338 -0
- package/src/native-composition/release-envelope-plugin.ts +6 -0
- package/src/native-composition/router-integration-plugin.ts +20 -0
- package/src/native-composition/router-runtime.ts +28 -0
- package/src/native-composition/rsc-disabled-plugin.ts +117 -0
- package/src/native-composition/server-plugin.ts +1 -0
- package/src/native-composition/ssr-integration-plugin.ts +244 -0
- package/src/native-composition/types.ts +32 -0
- package/README.md +0 -3
|
@@ -0,0 +1,145 @@
|
|
|
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 getRspackPlugins = (rspackConfig)=>{
|
|
31
|
+
if (!rspackConfig) return [];
|
|
32
|
+
const rspackEntries = Array.isArray(rspackConfig) ? rspackConfig : [
|
|
33
|
+
rspackConfig
|
|
34
|
+
];
|
|
35
|
+
const plugins = [];
|
|
36
|
+
for (const entry of rspackEntries){
|
|
37
|
+
if (!entry || 'function' == typeof entry || 'object' != typeof entry) continue;
|
|
38
|
+
const maybePlugins = entry.plugins;
|
|
39
|
+
if (Array.isArray(maybePlugins)) {
|
|
40
|
+
for (const plugin of maybePlugins)if (plugin) plugins.push(plugin);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return plugins;
|
|
44
|
+
};
|
|
45
|
+
const getRspackPluginName = (plugin)=>{
|
|
46
|
+
if ('string' == typeof plugin) return plugin;
|
|
47
|
+
if ('function' == typeof plugin) return plugin.name;
|
|
48
|
+
if (Array.isArray(plugin)) {
|
|
49
|
+
const [first] = plugin;
|
|
50
|
+
if (!first) return;
|
|
51
|
+
if ('string' == typeof first) return first;
|
|
52
|
+
if ('function' == typeof first) return first.name;
|
|
53
|
+
if ('object' == typeof first) return first.name || first.constructor?.name;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
return plugin.name || plugin.constructor?.name;
|
|
57
|
+
};
|
|
58
|
+
const hasServerRenderingConfig = (userConfig)=>{
|
|
59
|
+
const { output, server } = userConfig;
|
|
60
|
+
if (output?.ssg) return true;
|
|
61
|
+
if (output?.ssgByEntries && Object.keys(output.ssgByEntries).length > 0) return true;
|
|
62
|
+
if (server?.ssr) return true;
|
|
63
|
+
if (server?.ssrByEntries && Object.keys(server.ssrByEntries).length > 0) return true;
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
66
|
+
const isModuleFederationAppSSREnabledInConfig = (ssr)=>{
|
|
67
|
+
if (!ssr || 'object' != typeof ssr) return false;
|
|
68
|
+
return true === ssr.moduleFederationAppSSR;
|
|
69
|
+
};
|
|
70
|
+
const isModuleFederationAppSSREnabled = (userConfig)=>{
|
|
71
|
+
if (isModuleFederationAppSSREnabledInConfig(userConfig.server?.ssr)) return true;
|
|
72
|
+
if (userConfig.server?.ssrByEntries && 'object' == typeof userConfig.server.ssrByEntries) return Object.values(userConfig.server.ssrByEntries).some(isModuleFederationAppSSREnabledInConfig);
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
75
|
+
const isModuleFederationRspackPlugin = (plugin)=>{
|
|
76
|
+
const candidate = getRspackPluginName(plugin);
|
|
77
|
+
return 'string' == typeof candidate && /modulefederation/i.test(candidate);
|
|
78
|
+
};
|
|
79
|
+
const hasModuleFederationMarker = (config)=>{
|
|
80
|
+
if ('true' === process.env.MF_SSR_PRJ) return true;
|
|
81
|
+
const define = config.source?.define || {};
|
|
82
|
+
if ('REMOTE_IP_STRATEGY' in define || 'FEDERATION_IPV4' in define) return true;
|
|
83
|
+
const plugins = getRspackPlugins(config.tools?.rspack);
|
|
84
|
+
return plugins.some(isModuleFederationRspackPlugin);
|
|
85
|
+
};
|
|
86
|
+
const isNodeEnvironmentTarget = (target)=>'string' == typeof target && ('node' === target || 'async-node' === target || target.startsWith('node'));
|
|
87
|
+
const shouldUseModuleFederationNodeOutput = (config)=>isNodeEnvironmentTarget(config.output?.target) && hasModuleFederationMarker(config);
|
|
88
|
+
const ssrIntegrationBuilderPlugin = (modernAPI)=>({
|
|
89
|
+
name: '@modern-js/ultramodern-builder-plugin-ssr',
|
|
90
|
+
pre: [
|
|
91
|
+
'@modern-js/builder-plugin-ssr'
|
|
92
|
+
],
|
|
93
|
+
setup (api) {
|
|
94
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>{
|
|
95
|
+
const isServerEnvironment = isNodeEnvironmentTarget(config.output.target) || 'workerSSR' === name;
|
|
96
|
+
const userConfig = modernAPI.getNormalizedConfig();
|
|
97
|
+
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
98
|
+
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
99
|
+
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
100
|
+
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
101
|
+
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
102
|
+
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.';
|
|
103
|
+
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
104
|
+
console.warn(warningMessage);
|
|
105
|
+
}
|
|
106
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
107
|
+
return mergeEnvironmentConfig(config, {
|
|
108
|
+
source: {
|
|
109
|
+
define: {
|
|
110
|
+
'process.env.MODERN_MF_APP_SSR': JSON.stringify(String(isModuleFederationAppSSR))
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
...'workerSSR' === name && userConfig.deploy?.target === 'cloudflare' ? {
|
|
114
|
+
output: {
|
|
115
|
+
module: true
|
|
116
|
+
}
|
|
117
|
+
} : {},
|
|
118
|
+
splitChunks: isServerEnvironment && (hasModuleFederationRuntimeMarker || hasExplicitMfSsrFlag) ? false : void 0
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const ultramodernSSRIntegrationPlugin = ()=>({
|
|
124
|
+
name: '@modern-js/ultramodern-ssr-integration',
|
|
125
|
+
setup (api) {
|
|
126
|
+
api.config(()=>({
|
|
127
|
+
builderPlugins: [
|
|
128
|
+
ssrIntegrationBuilderPlugin(api)
|
|
129
|
+
]
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
134
|
+
shouldUseModuleFederationNodeOutput: shouldUseModuleFederationNodeOutput,
|
|
135
|
+
ultramodernSSRIntegrationPlugin: ultramodernSSRIntegrationPlugin
|
|
136
|
+
});
|
|
137
|
+
exports.shouldUseModuleFederationNodeOutput = __webpack_exports__.shouldUseModuleFederationNodeOutput;
|
|
138
|
+
exports.ultramodernSSRIntegrationPlugin = __webpack_exports__.ultramodernSSRIntegrationPlugin;
|
|
139
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
140
|
+
"shouldUseModuleFederationNodeOutput",
|
|
141
|
+
"ultramodernSSRIntegrationPlugin"
|
|
142
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
143
|
+
Object.defineProperty(exports, '__esModule', {
|
|
144
|
+
value: true
|
|
145
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { appTools } from "@modern-js/app-tools";
|
|
2
|
+
import backend_federation_build from "@modern-js/app-tools-extensions/backend-federation-build";
|
|
3
|
+
import { createCloudflareBuilderPlugin } from "@modern-js/app-tools-extensions/cloudflare-builder";
|
|
4
|
+
import { createDeployOutputAliasesPlugin } from "@modern-js/app-tools-extensions/deploy-output/plugin";
|
|
5
|
+
import { ultramodernI18nIntegrationPlugin } from "@modern-js/i18n-integration";
|
|
6
|
+
import { ultramodernReleaseEnvelopePlugin } from "./release-envelope-plugin.mjs";
|
|
7
|
+
import { ultramodernRouterIntegrationPlugin } from "./router-integration-plugin.mjs";
|
|
8
|
+
import { rscDisabledRuntimePlugin } from "./rsc-disabled-plugin.mjs";
|
|
9
|
+
import { ultramodernSSRIntegrationPlugin } from "./ssr-integration-plugin.mjs";
|
|
10
|
+
const ultramodernAppTools = ()=>({
|
|
11
|
+
name: '@modern-js/ultramodern-app-tools',
|
|
12
|
+
usePlugins: [
|
|
13
|
+
appTools(),
|
|
14
|
+
ultramodernI18nIntegrationPlugin(),
|
|
15
|
+
ultramodernRouterIntegrationPlugin(),
|
|
16
|
+
ultramodernSSRIntegrationPlugin(),
|
|
17
|
+
backend_federation_build(),
|
|
18
|
+
createCloudflareBuilderPlugin(),
|
|
19
|
+
createDeployOutputAliasesPlugin(),
|
|
20
|
+
ultramodernReleaseEnvelopePlugin()
|
|
21
|
+
],
|
|
22
|
+
setup (api) {
|
|
23
|
+
api.modifyResolvedConfig((config)=>{
|
|
24
|
+
if (config.server?.rsc) return config;
|
|
25
|
+
return {
|
|
26
|
+
...config,
|
|
27
|
+
builderPlugins: [
|
|
28
|
+
...config.builderPlugins ?? [],
|
|
29
|
+
rscDisabledRuntimePlugin()
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
api._internalServerPlugins(({ plugins })=>{
|
|
34
|
+
const name = '@modern-js/ultramodern-app-tools/server-plugin';
|
|
35
|
+
if (!plugins.some((plugin)=>plugin.name === name)) plugins.push({
|
|
36
|
+
name
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
plugins
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
43
|
+
plugins.push({
|
|
44
|
+
name: 'rendererHead',
|
|
45
|
+
path: '@modern-js/runtime-renderer-extensions',
|
|
46
|
+
config: {}
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
entrypoint,
|
|
50
|
+
plugins
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
export { createPresetUltramodernConfig, presetUltramodern } from "./preset.mjs";
|
|
56
|
+
export { ultramodernAppTools, ultramodernReleaseEnvelopePlugin };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { builderPluginAdapterPrecompress } from "@modern-js/app-tools-extensions/build-config/precompress/plugin";
|
|
4
|
+
import { resolveEffectTsgoCompiler } from "@modern-js/app-tools-extensions/config";
|
|
5
|
+
import { configureUltramodernTypeChecker } from "@modern-js/app-tools-extensions/native-type-checker";
|
|
6
|
+
import { resolveUltramodernReleaseIdentity } from "@modern-js/app-tools-extensions/release-identity";
|
|
7
|
+
import { mergeConfig } from "@modern-js/plugin/cli";
|
|
8
|
+
import { rspack } from "@rsbuild/core";
|
|
9
|
+
const DEFAULT_OTLP_ENDPOINT = 'http://127.0.0.1:4318/v1/logs';
|
|
10
|
+
const DEFAULT_VICTORIA_METRICS_ENDPOINT = 'http://127.0.0.1:8428/api/v1/import/prometheus';
|
|
11
|
+
const resolveReactRouterPackageDir = (appDirectory)=>{
|
|
12
|
+
const resolveNodeModulePackageJson = (packageName, fromDirectory)=>{
|
|
13
|
+
let currentDirectory = node_path.resolve(fromDirectory);
|
|
14
|
+
while(true){
|
|
15
|
+
const packageJson = node_path.join(currentDirectory, 'node_modules', packageName, 'package.json');
|
|
16
|
+
if (node_fs.existsSync(packageJson)) return node_fs.realpathSync(packageJson);
|
|
17
|
+
const parentDirectory = node_path.dirname(currentDirectory);
|
|
18
|
+
if (parentDirectory === currentDirectory) return;
|
|
19
|
+
currentDirectory = parentDirectory;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const reactRouterPackageJson = resolveNodeModulePackageJson('react-router', appDirectory);
|
|
23
|
+
if (reactRouterPackageJson) return node_path.dirname(reactRouterPackageJson);
|
|
24
|
+
const reactRouterDomPackageJson = resolveNodeModulePackageJson('react-router-dom', appDirectory);
|
|
25
|
+
if (!reactRouterDomPackageJson) return;
|
|
26
|
+
const nestedReactRouterPackageJson = resolveNodeModulePackageJson('react-router', node_path.dirname(reactRouterDomPackageJson));
|
|
27
|
+
if (nestedReactRouterPackageJson) return node_path.dirname(nestedReactRouterPackageJson);
|
|
28
|
+
};
|
|
29
|
+
const setReactRouterBridgeSafeAliases = (chain, { isProd })=>{
|
|
30
|
+
const chainContext = chain.get('context');
|
|
31
|
+
const appDirectory = 'string' == typeof chainContext && chainContext.length > 0 ? chainContext : process.cwd();
|
|
32
|
+
const reactRouterPackageDir = resolveReactRouterPackageDir(appDirectory);
|
|
33
|
+
if (!reactRouterPackageDir) return;
|
|
34
|
+
const productionEntry = node_path.join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
35
|
+
const developmentEntry = node_path.join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
36
|
+
chain.resolve.alias.set('react-router$', isProd ? productionEntry : developmentEntry);
|
|
37
|
+
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
38
|
+
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
39
|
+
};
|
|
40
|
+
const createPresetUltramodernConfig = (options = {})=>{
|
|
41
|
+
const { appId = 'app', deliveryUnit, enableBffRequestId = true, enableTelemetry = true, enableTelemetryExporters, otlpEndpoint = process.env.MODERN_TELEMETRY_OTLP_ENDPOINT, victoriaMetricsEndpoint = process.env.MODERN_TELEMETRY_VICTORIA_ENDPOINT, telemetryFailLoudStartup = false, enableModuleFederationSSR = true } = options;
|
|
42
|
+
const server = {};
|
|
43
|
+
const releaseIdentity = deliveryUnit ? resolveUltramodernReleaseIdentity({
|
|
44
|
+
generationBuildMarker: deliveryUnit.buildMarker,
|
|
45
|
+
unitId: deliveryUnit.unitId
|
|
46
|
+
}) : void 0;
|
|
47
|
+
const bundledReleaseIdentity = releaseIdentity ? {
|
|
48
|
+
...releaseIdentity,
|
|
49
|
+
releaseVersion: deliveryUnit.version
|
|
50
|
+
} : void 0;
|
|
51
|
+
if (enableTelemetry) {
|
|
52
|
+
server.telemetry = {
|
|
53
|
+
enabled: true,
|
|
54
|
+
failLoudStartup: telemetryFailLoudStartup
|
|
55
|
+
};
|
|
56
|
+
if (false !== enableTelemetryExporters) {
|
|
57
|
+
const exporters = {};
|
|
58
|
+
if (true === enableTelemetryExporters || otlpEndpoint) exporters.otlp = {
|
|
59
|
+
enabled: true,
|
|
60
|
+
endpoint: otlpEndpoint || DEFAULT_OTLP_ENDPOINT
|
|
61
|
+
};
|
|
62
|
+
if (true === enableTelemetryExporters || victoriaMetricsEndpoint) exporters.victoriaMetrics = {
|
|
63
|
+
enabled: true,
|
|
64
|
+
endpoint: victoriaMetricsEndpoint || DEFAULT_VICTORIA_METRICS_ENDPOINT
|
|
65
|
+
};
|
|
66
|
+
if (Object.keys(exporters).length > 0) server.telemetry.exporters = exporters;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (enableModuleFederationSSR) server.ssr = {
|
|
70
|
+
mode: 'stream',
|
|
71
|
+
moduleFederationAppSSR: true
|
|
72
|
+
};
|
|
73
|
+
const presetConfig = {
|
|
74
|
+
output: {
|
|
75
|
+
precompress: true
|
|
76
|
+
},
|
|
77
|
+
server,
|
|
78
|
+
source: {
|
|
79
|
+
reactCompiler: true,
|
|
80
|
+
...deliveryUnit ? {
|
|
81
|
+
globalVars: {
|
|
82
|
+
ULTRAMODERN_BUILD_MARKER: releaseIdentity?.buildMarker,
|
|
83
|
+
ULTRAMODERN_RELEASE_VERSION: deliveryUnit.version,
|
|
84
|
+
ULTRAMODERN_SOURCE_REVISION: releaseIdentity?.sourceRevision
|
|
85
|
+
}
|
|
86
|
+
} : {}
|
|
87
|
+
},
|
|
88
|
+
tools: {
|
|
89
|
+
bundlerChain: (chain, utils)=>{
|
|
90
|
+
setReactRouterBridgeSafeAliases(chain, utils);
|
|
91
|
+
configureUltramodernTypeChecker(chain, utils.CHAIN_ID.PLUGIN.TS_CHECKER, (from)=>resolveEffectTsgoCompiler({
|
|
92
|
+
from
|
|
93
|
+
}));
|
|
94
|
+
},
|
|
95
|
+
lightningcssLoader: true,
|
|
96
|
+
...bundledReleaseIdentity ? {
|
|
97
|
+
rspack: (config)=>{
|
|
98
|
+
config.plugins ??= [];
|
|
99
|
+
config.plugins.push(new rspack.BannerPlugin({
|
|
100
|
+
banner: `void ${JSON.stringify(bundledReleaseIdentity.buildMarker)};void ${JSON.stringify(bundledReleaseIdentity.sourceRevision)};void ${JSON.stringify(bundledReleaseIdentity.releaseVersion)};`,
|
|
101
|
+
raw: true,
|
|
102
|
+
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
|
|
103
|
+
test: /\.(?:c|m)?js$/u
|
|
104
|
+
}));
|
|
105
|
+
return config;
|
|
106
|
+
}
|
|
107
|
+
} : {}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
if (enableBffRequestId) presetConfig.bff = {
|
|
111
|
+
requestId: appId
|
|
112
|
+
};
|
|
113
|
+
return presetConfig;
|
|
114
|
+
};
|
|
115
|
+
const presetUltramodern = (config, options = {})=>{
|
|
116
|
+
const merged = mergeConfig([
|
|
117
|
+
createPresetUltramodernConfig(options),
|
|
118
|
+
config
|
|
119
|
+
]);
|
|
120
|
+
merged.builderPlugins = [
|
|
121
|
+
builderPluginAdapterPrecompress(merged.output?.precompress),
|
|
122
|
+
...merged.builderPlugins ?? []
|
|
123
|
+
];
|
|
124
|
+
return merged;
|
|
125
|
+
};
|
|
126
|
+
export { createPresetUltramodernConfig, presetUltramodern };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { resolveDeployTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
|
|
2
|
+
import { createUltramodernReleaseEnvelopePlugin } from "@modern-js/app-tools-extensions/release-envelope/plugin";
|
|
3
|
+
const ultramodernReleaseEnvelopePlugin = ()=>createUltramodernReleaseEnvelopePlugin({
|
|
4
|
+
resolveDeployTarget: resolveDeployTarget
|
|
5
|
+
});
|
|
6
|
+
export { ultramodernReleaseEnvelopePlugin };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const ultramodernRouterIntegrationPlugin = ()=>({
|
|
2
|
+
name: '@modern-js/ultramodern-router-integration',
|
|
3
|
+
pre: [
|
|
4
|
+
'@modern-js/plugin-router',
|
|
5
|
+
'@modern-js/plugin-tanstack'
|
|
6
|
+
],
|
|
7
|
+
setup (api) {
|
|
8
|
+
api._internalRuntimePlugins(({ entrypoint, plugins })=>({
|
|
9
|
+
entrypoint,
|
|
10
|
+
plugins: plugins.map((plugin)=>'@modern-js/runtime/router/internal' === plugin.path ? {
|
|
11
|
+
...plugin,
|
|
12
|
+
path: '@modern-js/ultramodern-app-tools/router-runtime'
|
|
13
|
+
} : plugin)
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
export { ultramodernRouterIntegrationPlugin };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { routerPlugin, routerProviderRegistryHooks } from "@modern-js/runtime/router/internal";
|
|
2
|
+
import { createRouterPlugin } from "@modern-js/runtime-extensions/router-provider";
|
|
3
|
+
import { createRouterStatePlugin } from "@modern-js/runtime-extensions/router-state-plugin";
|
|
4
|
+
const createProvider = createRouterPlugin({
|
|
5
|
+
defaultProvider: {
|
|
6
|
+
name: 'react-router',
|
|
7
|
+
factory: routerPlugin
|
|
8
|
+
},
|
|
9
|
+
registryHooks: routerProviderRegistryHooks
|
|
10
|
+
});
|
|
11
|
+
const router_runtime_routerPlugin = (config)=>{
|
|
12
|
+
const state = createRouterStatePlugin({
|
|
13
|
+
registryHooks: routerProviderRegistryHooks
|
|
14
|
+
});
|
|
15
|
+
const provider = createProvider(config);
|
|
16
|
+
return {
|
|
17
|
+
...provider,
|
|
18
|
+
setup (api) {
|
|
19
|
+
state.setup?.(api);
|
|
20
|
+
return provider.setup?.(api);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const router_runtime = router_runtime_routerPlugin;
|
|
25
|
+
export default router_runtime;
|
|
26
|
+
export { router_runtime_routerPlugin as routerPlugin };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const disabledRuntimeModules = {
|
|
2
|
+
'react-server-dom-rspack/client.browser': './rscDisabledClientBrowserRuntime',
|
|
3
|
+
'react-server-dom-rspack/client.edge': './rscDisabledClientEdgeRuntime',
|
|
4
|
+
'react-server-dom-rspack/client.node': './rscDisabledClientNodeRuntime',
|
|
5
|
+
'react-server-dom-rspack/server.edge': './rscDisabledServerEdgeRuntime',
|
|
6
|
+
'react-server-dom-rspack/server.node': './rscDisabledServerNodeRuntime'
|
|
7
|
+
};
|
|
8
|
+
const disabledRuntimeRequests = Object.keys(disabledRuntimeModules);
|
|
9
|
+
function aliasMatchesRequest(aliasName, request) {
|
|
10
|
+
const exact = aliasName.endsWith('$');
|
|
11
|
+
const normalizedName = exact ? aliasName.slice(0, -1) : aliasName;
|
|
12
|
+
return exact ? normalizedName === request : request === normalizedName || request.startsWith(`${normalizedName}/`);
|
|
13
|
+
}
|
|
14
|
+
function objectAliasMatchesDisabledRuntime(aliasName) {
|
|
15
|
+
return disabledRuntimeRequests.some((request)=>aliasMatchesRequest(aliasName, request));
|
|
16
|
+
}
|
|
17
|
+
function arrayAliasMatchesDisabledRuntime(alias) {
|
|
18
|
+
const aliasName = `${alias.name}${alias.onlyModule ? '$' : ''}`;
|
|
19
|
+
return objectAliasMatchesDisabledRuntime(aliasName);
|
|
20
|
+
}
|
|
21
|
+
function normalizeArrayAliases(aliases) {
|
|
22
|
+
const normalized = {};
|
|
23
|
+
for (const alias of aliases){
|
|
24
|
+
if (arrayAliasMatchesDisabledRuntime(alias)) continue;
|
|
25
|
+
const aliasName = `${alias.name}${alias.onlyModule ? '$' : ''}`;
|
|
26
|
+
const existing = normalized[aliasName];
|
|
27
|
+
if (void 0 === existing) {
|
|
28
|
+
normalized[aliasName] = alias.alias;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
normalized[aliasName] = [
|
|
32
|
+
...Array.isArray(existing) ? existing : [
|
|
33
|
+
existing
|
|
34
|
+
],
|
|
35
|
+
...Array.isArray(alias.alias) ? alias.alias : [
|
|
36
|
+
alias.alias
|
|
37
|
+
]
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
return normalized;
|
|
41
|
+
}
|
|
42
|
+
function resolveDisabledRuntimeModules() {
|
|
43
|
+
return Object.fromEntries(Object.entries(disabledRuntimeModules).map(([request, moduleRequest])=>[
|
|
44
|
+
`${request}$`,
|
|
45
|
+
require.resolve(`@modern-js/runtime-extensions/rsc-disabled/${moduleRequest.slice(2)}`)
|
|
46
|
+
]));
|
|
47
|
+
}
|
|
48
|
+
function applyDisabledRuntimeAliases(config, disabledAliases) {
|
|
49
|
+
config.resolve ??= {};
|
|
50
|
+
if (Array.isArray(config.resolve.alias)) config.resolve.alias = {
|
|
51
|
+
...disabledAliases,
|
|
52
|
+
...normalizeArrayAliases(config.resolve.alias)
|
|
53
|
+
};
|
|
54
|
+
else config.resolve.alias = {
|
|
55
|
+
...disabledAliases,
|
|
56
|
+
...Object.fromEntries(Object.entries(config.resolve.alias ?? {}).filter(([aliasName])=>!objectAliasMatchesDisabledRuntime(aliasName)))
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function rscDisabledRuntimePlugin() {
|
|
60
|
+
return {
|
|
61
|
+
name: 'builder:rsc-disabled-runtime',
|
|
62
|
+
setup (api) {
|
|
63
|
+
const disabledAliases = resolveDisabledRuntimeModules();
|
|
64
|
+
api.modifyRspackConfig({
|
|
65
|
+
order: 'post',
|
|
66
|
+
handler (config) {
|
|
67
|
+
applyDisabledRuntimeAliases(config, disabledAliases);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
api.onBeforeCreateCompiler({
|
|
71
|
+
order: 'post',
|
|
72
|
+
handler ({ bundlerConfigs }) {
|
|
73
|
+
for (const config of bundlerConfigs)applyDisabledRuntimeAliases(config, disabledAliases);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export { rscDisabledRuntimePlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@modern-js/server-runtime-extensions/server-plugin";
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const getRspackPlugins = (rspackConfig)=>{
|
|
2
|
+
if (!rspackConfig) return [];
|
|
3
|
+
const rspackEntries = Array.isArray(rspackConfig) ? rspackConfig : [
|
|
4
|
+
rspackConfig
|
|
5
|
+
];
|
|
6
|
+
const plugins = [];
|
|
7
|
+
for (const entry of rspackEntries){
|
|
8
|
+
if (!entry || 'function' == typeof entry || 'object' != typeof entry) continue;
|
|
9
|
+
const maybePlugins = entry.plugins;
|
|
10
|
+
if (Array.isArray(maybePlugins)) {
|
|
11
|
+
for (const plugin of maybePlugins)if (plugin) plugins.push(plugin);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return plugins;
|
|
15
|
+
};
|
|
16
|
+
const getRspackPluginName = (plugin)=>{
|
|
17
|
+
if ('string' == typeof plugin) return plugin;
|
|
18
|
+
if ('function' == typeof plugin) return plugin.name;
|
|
19
|
+
if (Array.isArray(plugin)) {
|
|
20
|
+
const [first] = plugin;
|
|
21
|
+
if (!first) return;
|
|
22
|
+
if ('string' == typeof first) return first;
|
|
23
|
+
if ('function' == typeof first) return first.name;
|
|
24
|
+
if ('object' == typeof first) return first.name || first.constructor?.name;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
return plugin.name || plugin.constructor?.name;
|
|
28
|
+
};
|
|
29
|
+
const hasServerRenderingConfig = (userConfig)=>{
|
|
30
|
+
const { output, server } = userConfig;
|
|
31
|
+
if (output?.ssg) return true;
|
|
32
|
+
if (output?.ssgByEntries && Object.keys(output.ssgByEntries).length > 0) return true;
|
|
33
|
+
if (server?.ssr) return true;
|
|
34
|
+
if (server?.ssrByEntries && Object.keys(server.ssrByEntries).length > 0) return true;
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
const isModuleFederationAppSSREnabledInConfig = (ssr)=>{
|
|
38
|
+
if (!ssr || 'object' != typeof ssr) return false;
|
|
39
|
+
return true === ssr.moduleFederationAppSSR;
|
|
40
|
+
};
|
|
41
|
+
const isModuleFederationAppSSREnabled = (userConfig)=>{
|
|
42
|
+
if (isModuleFederationAppSSREnabledInConfig(userConfig.server?.ssr)) return true;
|
|
43
|
+
if (userConfig.server?.ssrByEntries && 'object' == typeof userConfig.server.ssrByEntries) return Object.values(userConfig.server.ssrByEntries).some(isModuleFederationAppSSREnabledInConfig);
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
const isModuleFederationRspackPlugin = (plugin)=>{
|
|
47
|
+
const candidate = getRspackPluginName(plugin);
|
|
48
|
+
return 'string' == typeof candidate && /modulefederation/i.test(candidate);
|
|
49
|
+
};
|
|
50
|
+
const hasModuleFederationMarker = (config)=>{
|
|
51
|
+
if ('true' === process.env.MF_SSR_PRJ) return true;
|
|
52
|
+
const define = config.source?.define || {};
|
|
53
|
+
if ('REMOTE_IP_STRATEGY' in define || 'FEDERATION_IPV4' in define) return true;
|
|
54
|
+
const plugins = getRspackPlugins(config.tools?.rspack);
|
|
55
|
+
return plugins.some(isModuleFederationRspackPlugin);
|
|
56
|
+
};
|
|
57
|
+
const isNodeEnvironmentTarget = (target)=>'string' == typeof target && ('node' === target || 'async-node' === target || target.startsWith('node'));
|
|
58
|
+
const shouldUseModuleFederationNodeOutput = (config)=>isNodeEnvironmentTarget(config.output?.target) && hasModuleFederationMarker(config);
|
|
59
|
+
const ssrIntegrationBuilderPlugin = (modernAPI)=>({
|
|
60
|
+
name: '@modern-js/ultramodern-builder-plugin-ssr',
|
|
61
|
+
pre: [
|
|
62
|
+
'@modern-js/builder-plugin-ssr'
|
|
63
|
+
],
|
|
64
|
+
setup (api) {
|
|
65
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>{
|
|
66
|
+
const isServerEnvironment = isNodeEnvironmentTarget(config.output.target) || 'workerSSR' === name;
|
|
67
|
+
const userConfig = modernAPI.getNormalizedConfig();
|
|
68
|
+
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
69
|
+
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
70
|
+
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
71
|
+
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
72
|
+
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
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 (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
75
|
+
console.warn(warningMessage);
|
|
76
|
+
}
|
|
77
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
78
|
+
return mergeEnvironmentConfig(config, {
|
|
79
|
+
source: {
|
|
80
|
+
define: {
|
|
81
|
+
'process.env.MODERN_MF_APP_SSR': JSON.stringify(String(isModuleFederationAppSSR))
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
...'workerSSR' === name && userConfig.deploy?.target === 'cloudflare' ? {
|
|
85
|
+
output: {
|
|
86
|
+
module: true
|
|
87
|
+
}
|
|
88
|
+
} : {},
|
|
89
|
+
splitChunks: isServerEnvironment && (hasModuleFederationRuntimeMarker || hasExplicitMfSsrFlag) ? false : void 0
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const ultramodernSSRIntegrationPlugin = ()=>({
|
|
95
|
+
name: '@modern-js/ultramodern-ssr-integration',
|
|
96
|
+
setup (api) {
|
|
97
|
+
api.config(()=>({
|
|
98
|
+
builderPlugins: [
|
|
99
|
+
ssrIntegrationBuilderPlugin(api)
|
|
100
|
+
]
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
export { shouldUseModuleFederationNodeOutput, ultramodernSSRIntegrationPlugin };
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { appTools } from "@modern-js/app-tools";
|
|
3
|
+
import backend_federation_build from "@modern-js/app-tools-extensions/backend-federation-build";
|
|
4
|
+
import { createCloudflareBuilderPlugin } from "@modern-js/app-tools-extensions/cloudflare-builder";
|
|
5
|
+
import { createDeployOutputAliasesPlugin } from "@modern-js/app-tools-extensions/deploy-output/plugin";
|
|
6
|
+
import { ultramodernI18nIntegrationPlugin } from "@modern-js/i18n-integration";
|
|
7
|
+
import { ultramodernReleaseEnvelopePlugin } from "./release-envelope-plugin.mjs";
|
|
8
|
+
import { ultramodernRouterIntegrationPlugin } from "./router-integration-plugin.mjs";
|
|
9
|
+
import { rscDisabledRuntimePlugin } from "./rsc-disabled-plugin.mjs";
|
|
10
|
+
import { ultramodernSSRIntegrationPlugin } from "./ssr-integration-plugin.mjs";
|
|
11
|
+
const ultramodernAppTools = ()=>({
|
|
12
|
+
name: '@modern-js/ultramodern-app-tools',
|
|
13
|
+
usePlugins: [
|
|
14
|
+
appTools(),
|
|
15
|
+
ultramodernI18nIntegrationPlugin(),
|
|
16
|
+
ultramodernRouterIntegrationPlugin(),
|
|
17
|
+
ultramodernSSRIntegrationPlugin(),
|
|
18
|
+
backend_federation_build(),
|
|
19
|
+
createCloudflareBuilderPlugin(),
|
|
20
|
+
createDeployOutputAliasesPlugin(),
|
|
21
|
+
ultramodernReleaseEnvelopePlugin()
|
|
22
|
+
],
|
|
23
|
+
setup (api) {
|
|
24
|
+
api.modifyResolvedConfig((config)=>{
|
|
25
|
+
if (config.server?.rsc) return config;
|
|
26
|
+
return {
|
|
27
|
+
...config,
|
|
28
|
+
builderPlugins: [
|
|
29
|
+
...config.builderPlugins ?? [],
|
|
30
|
+
rscDisabledRuntimePlugin()
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
api._internalServerPlugins(({ plugins })=>{
|
|
35
|
+
const name = '@modern-js/ultramodern-app-tools/server-plugin';
|
|
36
|
+
if (!plugins.some((plugin)=>plugin.name === name)) plugins.push({
|
|
37
|
+
name
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
plugins
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
44
|
+
plugins.push({
|
|
45
|
+
name: 'rendererHead',
|
|
46
|
+
path: '@modern-js/runtime-renderer-extensions',
|
|
47
|
+
config: {}
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
entrypoint,
|
|
51
|
+
plugins
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
export { createPresetUltramodernConfig, presetUltramodern } from "./preset.mjs";
|
|
57
|
+
export { ultramodernAppTools, ultramodernReleaseEnvelopePlugin };
|