@bleedingdev/modern-js-ultramodern-app-tools 0.0.0 → 3.9.0-ultramodern.10
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 +131 -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 +71 -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 +72 -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 +92 -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,72 @@
|
|
|
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 { RENDERER_EXTENSIONS_PACKAGE, SERVER_EXTENSIONS_PLUGIN_NAME } from "@modern-js/app-tools-extensions/policy-defaults";
|
|
7
|
+
import { collectRuntimePackageModuleDirectories, createRuntimePackageResolutionPlugin } from "@modern-js/app-tools-extensions/runtime-package-resolution";
|
|
8
|
+
import { ultramodernI18nIntegrationPlugin } from "@modern-js/i18n-integration";
|
|
9
|
+
import { ultramodernReleaseEnvelopePlugin } from "./release-envelope-plugin.mjs";
|
|
10
|
+
import { ultramodernRouterIntegrationPlugin } from "./router-integration-plugin.mjs";
|
|
11
|
+
import { rscDisabledRuntimePlugin } from "./rsc-disabled-plugin.mjs";
|
|
12
|
+
import { ultramodernSSRIntegrationPlugin } from "./ssr-integration-plugin.mjs";
|
|
13
|
+
const ultramodernAppTools = ()=>({
|
|
14
|
+
name: '@modern-js/ultramodern-app-tools',
|
|
15
|
+
usePlugins: [
|
|
16
|
+
appTools(),
|
|
17
|
+
ultramodernI18nIntegrationPlugin(),
|
|
18
|
+
ultramodernRouterIntegrationPlugin(),
|
|
19
|
+
ultramodernSSRIntegrationPlugin(),
|
|
20
|
+
backend_federation_build(),
|
|
21
|
+
createCloudflareBuilderPlugin(),
|
|
22
|
+
createDeployOutputAliasesPlugin(),
|
|
23
|
+
ultramodernReleaseEnvelopePlugin()
|
|
24
|
+
],
|
|
25
|
+
setup (api) {
|
|
26
|
+
const runtimeModuleDirectories = collectRuntimePackageModuleDirectories([
|
|
27
|
+
RENDERER_EXTENSIONS_PACKAGE,
|
|
28
|
+
'@modern-js/i18n-integration'
|
|
29
|
+
], import.meta.url);
|
|
30
|
+
api.modifyResolvedConfig((config)=>{
|
|
31
|
+
const builderPlugins = [
|
|
32
|
+
...config.builderPlugins ?? [],
|
|
33
|
+
...runtimeModuleDirectories.length > 0 ? [
|
|
34
|
+
createRuntimePackageResolutionPlugin(runtimeModuleDirectories)
|
|
35
|
+
] : [],
|
|
36
|
+
...config.server?.rsc ? [] : [
|
|
37
|
+
rscDisabledRuntimePlugin()
|
|
38
|
+
]
|
|
39
|
+
];
|
|
40
|
+
return {
|
|
41
|
+
...config,
|
|
42
|
+
builderPlugins
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
api._internalServerPlugins(({ plugins })=>{
|
|
46
|
+
const name = '@modern-js/ultramodern-app-tools/server-plugin';
|
|
47
|
+
const renamed = plugins.map((plugin)=>plugin.name === SERVER_EXTENSIONS_PLUGIN_NAME ? {
|
|
48
|
+
...plugin,
|
|
49
|
+
name
|
|
50
|
+
} : plugin);
|
|
51
|
+
if (!renamed.some((plugin)=>plugin.name === name)) renamed.push({
|
|
52
|
+
name
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
plugins: renamed
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
59
|
+
if (!plugins.some((plugin)=>plugin.path === RENDERER_EXTENSIONS_PACKAGE)) plugins.push({
|
|
60
|
+
name: 'rendererHead',
|
|
61
|
+
path: RENDERER_EXTENSIONS_PACKAGE,
|
|
62
|
+
config: {}
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
entrypoint,
|
|
66
|
+
plugins
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
export { createPresetUltramodernConfig, presetUltramodern } from "./preset.mjs";
|
|
72
|
+
export { ultramodernAppTools, ultramodernReleaseEnvelopePlugin };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_fs from "node:fs";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { builderPluginAdapterPrecompress } from "@modern-js/app-tools-extensions/build-config/precompress/plugin";
|
|
5
|
+
import { resolveEffectTsgoCompiler } from "@modern-js/app-tools-extensions/config";
|
|
6
|
+
import { configureUltramodernTypeChecker } from "@modern-js/app-tools-extensions/native-type-checker";
|
|
7
|
+
import { resolveUltramodernReleaseIdentity } from "@modern-js/app-tools-extensions/release-identity";
|
|
8
|
+
import { mergeConfig } from "@modern-js/plugin/cli";
|
|
9
|
+
import { rspack } from "@rsbuild/core";
|
|
10
|
+
const DEFAULT_OTLP_ENDPOINT = 'http://127.0.0.1:4318/v1/logs';
|
|
11
|
+
const DEFAULT_VICTORIA_METRICS_ENDPOINT = 'http://127.0.0.1:8428/api/v1/import/prometheus';
|
|
12
|
+
const resolveReactRouterPackageDir = (appDirectory)=>{
|
|
13
|
+
const resolveNodeModulePackageJson = (packageName, fromDirectory)=>{
|
|
14
|
+
let currentDirectory = node_path.resolve(fromDirectory);
|
|
15
|
+
while(true){
|
|
16
|
+
const packageJson = node_path.join(currentDirectory, 'node_modules', packageName, 'package.json');
|
|
17
|
+
if (node_fs.existsSync(packageJson)) return node_fs.realpathSync(packageJson);
|
|
18
|
+
const parentDirectory = node_path.dirname(currentDirectory);
|
|
19
|
+
if (parentDirectory === currentDirectory) return;
|
|
20
|
+
currentDirectory = parentDirectory;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const reactRouterPackageJson = resolveNodeModulePackageJson('react-router', appDirectory);
|
|
24
|
+
if (reactRouterPackageJson) return node_path.dirname(reactRouterPackageJson);
|
|
25
|
+
const reactRouterDomPackageJson = resolveNodeModulePackageJson('react-router-dom', appDirectory);
|
|
26
|
+
if (!reactRouterDomPackageJson) return;
|
|
27
|
+
const nestedReactRouterPackageJson = resolveNodeModulePackageJson('react-router', node_path.dirname(reactRouterDomPackageJson));
|
|
28
|
+
if (nestedReactRouterPackageJson) return node_path.dirname(nestedReactRouterPackageJson);
|
|
29
|
+
};
|
|
30
|
+
const setReactRouterBridgeSafeAliases = (chain, { isProd })=>{
|
|
31
|
+
const chainContext = chain.get('context');
|
|
32
|
+
const appDirectory = 'string' == typeof chainContext && chainContext.length > 0 ? chainContext : process.cwd();
|
|
33
|
+
const reactRouterPackageDir = resolveReactRouterPackageDir(appDirectory);
|
|
34
|
+
if (!reactRouterPackageDir) return;
|
|
35
|
+
const productionEntry = node_path.join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
36
|
+
const developmentEntry = node_path.join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
37
|
+
chain.resolve.alias.set('react-router$', isProd ? productionEntry : developmentEntry);
|
|
38
|
+
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
39
|
+
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
40
|
+
};
|
|
41
|
+
const createPresetUltramodernConfig = (options = {})=>{
|
|
42
|
+
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;
|
|
43
|
+
const server = {};
|
|
44
|
+
const releaseIdentity = deliveryUnit ? resolveUltramodernReleaseIdentity({
|
|
45
|
+
generationBuildMarker: deliveryUnit.buildMarker,
|
|
46
|
+
unitId: deliveryUnit.unitId
|
|
47
|
+
}) : void 0;
|
|
48
|
+
const bundledReleaseIdentity = releaseIdentity ? {
|
|
49
|
+
...releaseIdentity,
|
|
50
|
+
releaseVersion: deliveryUnit.version
|
|
51
|
+
} : void 0;
|
|
52
|
+
if (enableTelemetry) {
|
|
53
|
+
server.telemetry = {
|
|
54
|
+
enabled: true,
|
|
55
|
+
failLoudStartup: telemetryFailLoudStartup
|
|
56
|
+
};
|
|
57
|
+
if (false !== enableTelemetryExporters) {
|
|
58
|
+
const exporters = {};
|
|
59
|
+
if (true === enableTelemetryExporters || otlpEndpoint) exporters.otlp = {
|
|
60
|
+
enabled: true,
|
|
61
|
+
endpoint: otlpEndpoint || DEFAULT_OTLP_ENDPOINT
|
|
62
|
+
};
|
|
63
|
+
if (true === enableTelemetryExporters || victoriaMetricsEndpoint) exporters.victoriaMetrics = {
|
|
64
|
+
enabled: true,
|
|
65
|
+
endpoint: victoriaMetricsEndpoint || DEFAULT_VICTORIA_METRICS_ENDPOINT
|
|
66
|
+
};
|
|
67
|
+
if (Object.keys(exporters).length > 0) server.telemetry.exporters = exporters;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (enableModuleFederationSSR) server.ssr = {
|
|
71
|
+
mode: 'stream',
|
|
72
|
+
moduleFederationAppSSR: true
|
|
73
|
+
};
|
|
74
|
+
const presetConfig = {
|
|
75
|
+
output: {
|
|
76
|
+
precompress: true
|
|
77
|
+
},
|
|
78
|
+
server,
|
|
79
|
+
source: {
|
|
80
|
+
reactCompiler: true,
|
|
81
|
+
...deliveryUnit ? {
|
|
82
|
+
globalVars: {
|
|
83
|
+
ULTRAMODERN_BUILD_MARKER: releaseIdentity?.buildMarker,
|
|
84
|
+
ULTRAMODERN_RELEASE_VERSION: deliveryUnit.version,
|
|
85
|
+
ULTRAMODERN_SOURCE_REVISION: releaseIdentity?.sourceRevision
|
|
86
|
+
}
|
|
87
|
+
} : {}
|
|
88
|
+
},
|
|
89
|
+
tools: {
|
|
90
|
+
bundlerChain: (chain, utils)=>{
|
|
91
|
+
setReactRouterBridgeSafeAliases(chain, utils);
|
|
92
|
+
configureUltramodernTypeChecker(chain, utils.CHAIN_ID.PLUGIN.TS_CHECKER, (from)=>resolveEffectTsgoCompiler({
|
|
93
|
+
from
|
|
94
|
+
}));
|
|
95
|
+
},
|
|
96
|
+
lightningcssLoader: true,
|
|
97
|
+
...bundledReleaseIdentity ? {
|
|
98
|
+
rspack: (config)=>{
|
|
99
|
+
config.plugins ??= [];
|
|
100
|
+
config.plugins.push(new rspack.BannerPlugin({
|
|
101
|
+
banner: `void ${JSON.stringify(bundledReleaseIdentity.buildMarker)};void ${JSON.stringify(bundledReleaseIdentity.sourceRevision)};void ${JSON.stringify(bundledReleaseIdentity.releaseVersion)};`,
|
|
102
|
+
raw: true,
|
|
103
|
+
stage: rspack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
|
|
104
|
+
test: /\.(?:c|m)?js$/u
|
|
105
|
+
}));
|
|
106
|
+
return config;
|
|
107
|
+
}
|
|
108
|
+
} : {}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
if (enableBffRequestId) presetConfig.bff = {
|
|
112
|
+
requestId: appId
|
|
113
|
+
};
|
|
114
|
+
return presetConfig;
|
|
115
|
+
};
|
|
116
|
+
const presetUltramodern = (config, options = {})=>{
|
|
117
|
+
const merged = mergeConfig([
|
|
118
|
+
createPresetUltramodernConfig(options),
|
|
119
|
+
config
|
|
120
|
+
]);
|
|
121
|
+
merged.builderPlugins = [
|
|
122
|
+
builderPluginAdapterPrecompress(merged.output?.precompress),
|
|
123
|
+
...merged.builderPlugins ?? []
|
|
124
|
+
];
|
|
125
|
+
return merged;
|
|
126
|
+
};
|
|
127
|
+
export { createPresetUltramodernConfig, presetUltramodern };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { resolveDeployTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
|
|
3
|
+
import { createUltramodernReleaseEnvelopePlugin } from "@modern-js/app-tools-extensions/release-envelope/plugin";
|
|
4
|
+
const ultramodernReleaseEnvelopePlugin = ()=>createUltramodernReleaseEnvelopePlugin({
|
|
5
|
+
resolveDeployTarget: resolveDeployTarget
|
|
6
|
+
});
|
|
7
|
+
export { ultramodernReleaseEnvelopePlugin };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
const ultramodernRouterIntegrationPlugin = ()=>({
|
|
3
|
+
name: '@modern-js/ultramodern-router-integration',
|
|
4
|
+
pre: [
|
|
5
|
+
'@modern-js/plugin-router',
|
|
6
|
+
'@modern-js/plugin-tanstack'
|
|
7
|
+
],
|
|
8
|
+
setup (api) {
|
|
9
|
+
api._internalRuntimePlugins(({ entrypoint, plugins })=>({
|
|
10
|
+
entrypoint,
|
|
11
|
+
plugins: plugins.map((plugin)=>'@modern-js/runtime/router/internal' === plugin.path ? {
|
|
12
|
+
...plugin,
|
|
13
|
+
path: '@modern-js/ultramodern-app-tools/router-runtime'
|
|
14
|
+
} : plugin)
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
export { ultramodernRouterIntegrationPlugin };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { routerPlugin, routerProviderRegistryHooks } from "@modern-js/runtime/router/internal";
|
|
3
|
+
import { createRouterPlugin } from "@modern-js/runtime-extensions/router-provider";
|
|
4
|
+
import { createRouterStatePlugin } from "@modern-js/runtime-extensions/router-state-plugin";
|
|
5
|
+
const createProvider = createRouterPlugin({
|
|
6
|
+
defaultProvider: {
|
|
7
|
+
name: 'react-router',
|
|
8
|
+
factory: routerPlugin
|
|
9
|
+
},
|
|
10
|
+
registryHooks: routerProviderRegistryHooks
|
|
11
|
+
});
|
|
12
|
+
const router_runtime_routerPlugin = (config)=>{
|
|
13
|
+
const state = createRouterStatePlugin({
|
|
14
|
+
registryHooks: routerProviderRegistryHooks
|
|
15
|
+
});
|
|
16
|
+
const provider = createProvider(config);
|
|
17
|
+
return {
|
|
18
|
+
...provider,
|
|
19
|
+
setup (api) {
|
|
20
|
+
state.setup?.(api);
|
|
21
|
+
return provider.setup?.(api);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const router_runtime = router_runtime_routerPlugin;
|
|
26
|
+
export default router_runtime;
|
|
27
|
+
export { router_runtime_routerPlugin as routerPlugin };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import __rslib_shim_module__ from "node:module";
|
|
2
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
+
const disabledRuntimeModules = {
|
|
4
|
+
'react-server-dom-rspack/client.browser': './rscDisabledClientBrowserRuntime',
|
|
5
|
+
'react-server-dom-rspack/client.edge': './rscDisabledClientEdgeRuntime',
|
|
6
|
+
'react-server-dom-rspack/client.node': './rscDisabledClientNodeRuntime',
|
|
7
|
+
'react-server-dom-rspack/server.edge': './rscDisabledServerEdgeRuntime',
|
|
8
|
+
'react-server-dom-rspack/server.node': './rscDisabledServerNodeRuntime'
|
|
9
|
+
};
|
|
10
|
+
const disabledRuntimeRequests = Object.keys(disabledRuntimeModules);
|
|
11
|
+
function aliasMatchesRequest(aliasName, request) {
|
|
12
|
+
const exact = aliasName.endsWith('$');
|
|
13
|
+
const normalizedName = exact ? aliasName.slice(0, -1) : aliasName;
|
|
14
|
+
return exact ? normalizedName === request : request === normalizedName || request.startsWith(`${normalizedName}/`);
|
|
15
|
+
}
|
|
16
|
+
function objectAliasMatchesDisabledRuntime(aliasName) {
|
|
17
|
+
return disabledRuntimeRequests.some((request)=>aliasMatchesRequest(aliasName, request));
|
|
18
|
+
}
|
|
19
|
+
function arrayAliasMatchesDisabledRuntime(alias) {
|
|
20
|
+
const aliasName = `${alias.name}${alias.onlyModule ? '$' : ''}`;
|
|
21
|
+
return objectAliasMatchesDisabledRuntime(aliasName);
|
|
22
|
+
}
|
|
23
|
+
function normalizeArrayAliases(aliases) {
|
|
24
|
+
const normalized = {};
|
|
25
|
+
for (const alias of aliases){
|
|
26
|
+
if (arrayAliasMatchesDisabledRuntime(alias)) continue;
|
|
27
|
+
const aliasName = `${alias.name}${alias.onlyModule ? '$' : ''}`;
|
|
28
|
+
const existing = normalized[aliasName];
|
|
29
|
+
if (void 0 === existing) {
|
|
30
|
+
normalized[aliasName] = alias.alias;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
normalized[aliasName] = [
|
|
34
|
+
...Array.isArray(existing) ? existing : [
|
|
35
|
+
existing
|
|
36
|
+
],
|
|
37
|
+
...Array.isArray(alias.alias) ? alias.alias : [
|
|
38
|
+
alias.alias
|
|
39
|
+
]
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
return normalized;
|
|
43
|
+
}
|
|
44
|
+
function resolveDisabledRuntimeModules() {
|
|
45
|
+
return Object.fromEntries(Object.entries(disabledRuntimeModules).map(([request, moduleRequest])=>[
|
|
46
|
+
`${request}$`,
|
|
47
|
+
require.resolve(`@modern-js/runtime-extensions/rsc-disabled/${moduleRequest.slice(2)}`)
|
|
48
|
+
]));
|
|
49
|
+
}
|
|
50
|
+
function applyDisabledRuntimeAliases(config, disabledAliases) {
|
|
51
|
+
config.resolve ??= {};
|
|
52
|
+
if (Array.isArray(config.resolve.alias)) config.resolve.alias = {
|
|
53
|
+
...disabledAliases,
|
|
54
|
+
...normalizeArrayAliases(config.resolve.alias)
|
|
55
|
+
};
|
|
56
|
+
else config.resolve.alias = {
|
|
57
|
+
...disabledAliases,
|
|
58
|
+
...Object.fromEntries(Object.entries(config.resolve.alias ?? {}).filter(([aliasName])=>!objectAliasMatchesDisabledRuntime(aliasName)))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function rscDisabledRuntimePlugin() {
|
|
62
|
+
return {
|
|
63
|
+
name: 'builder:rsc-disabled-runtime',
|
|
64
|
+
setup (api) {
|
|
65
|
+
const disabledAliases = resolveDisabledRuntimeModules();
|
|
66
|
+
api.modifyRspackConfig({
|
|
67
|
+
order: 'post',
|
|
68
|
+
handler (config) {
|
|
69
|
+
applyDisabledRuntimeAliases(config, disabledAliases);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
api.onBeforeCreateCompiler({
|
|
73
|
+
order: 'post',
|
|
74
|
+
handler ({ bundlerConfigs }) {
|
|
75
|
+
for (const config of bundlerConfigs)applyDisabledRuntimeAliases(config, disabledAliases);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export { rscDisabledRuntimePlugin };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
const getRspackPlugins = (rspackConfig)=>{
|
|
3
|
+
if (!rspackConfig) return [];
|
|
4
|
+
const rspackEntries = Array.isArray(rspackConfig) ? rspackConfig : [
|
|
5
|
+
rspackConfig
|
|
6
|
+
];
|
|
7
|
+
const plugins = [];
|
|
8
|
+
for (const entry of rspackEntries){
|
|
9
|
+
if (!entry || 'function' == typeof entry || 'object' != typeof entry) continue;
|
|
10
|
+
const maybePlugins = entry.plugins;
|
|
11
|
+
if (Array.isArray(maybePlugins)) {
|
|
12
|
+
for (const plugin of maybePlugins)if (plugin) plugins.push(plugin);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return plugins;
|
|
16
|
+
};
|
|
17
|
+
const getRspackPluginName = (plugin)=>{
|
|
18
|
+
if ('string' == typeof plugin) return plugin;
|
|
19
|
+
if ('function' == typeof plugin) return plugin.name;
|
|
20
|
+
if (Array.isArray(plugin)) {
|
|
21
|
+
const [first] = plugin;
|
|
22
|
+
if (!first) return;
|
|
23
|
+
if ('string' == typeof first) return first;
|
|
24
|
+
if ('function' == typeof first) return first.name;
|
|
25
|
+
if ('object' == typeof first) return first.name || first.constructor?.name;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return plugin.name || plugin.constructor?.name;
|
|
29
|
+
};
|
|
30
|
+
const hasServerRenderingConfig = (userConfig)=>{
|
|
31
|
+
const { output, server } = userConfig;
|
|
32
|
+
if (output?.ssg) return true;
|
|
33
|
+
if (output?.ssgByEntries && Object.keys(output.ssgByEntries).length > 0) return true;
|
|
34
|
+
if (server?.ssr) return true;
|
|
35
|
+
if (server?.ssrByEntries && Object.keys(server.ssrByEntries).length > 0) return true;
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
const isModuleFederationAppSSREnabledInConfig = (ssr)=>{
|
|
39
|
+
if (!ssr || 'object' != typeof ssr) return false;
|
|
40
|
+
return true === ssr.moduleFederationAppSSR;
|
|
41
|
+
};
|
|
42
|
+
const isModuleFederationAppSSREnabled = (userConfig)=>{
|
|
43
|
+
if (isModuleFederationAppSSREnabledInConfig(userConfig.server?.ssr)) return true;
|
|
44
|
+
if (userConfig.server?.ssrByEntries && 'object' == typeof userConfig.server.ssrByEntries) return Object.values(userConfig.server.ssrByEntries).some(isModuleFederationAppSSREnabledInConfig);
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
47
|
+
const isModuleFederationRspackPlugin = (plugin)=>{
|
|
48
|
+
const candidate = getRspackPluginName(plugin);
|
|
49
|
+
return 'string' == typeof candidate && /modulefederation/i.test(candidate);
|
|
50
|
+
};
|
|
51
|
+
const hasModuleFederationMarker = (config)=>{
|
|
52
|
+
if ('true' === process.env.MF_SSR_PRJ) return true;
|
|
53
|
+
const define = config.source?.define || {};
|
|
54
|
+
if ('REMOTE_IP_STRATEGY' in define || 'FEDERATION_IPV4' in define) return true;
|
|
55
|
+
const plugins = getRspackPlugins(config.tools?.rspack);
|
|
56
|
+
return plugins.some(isModuleFederationRspackPlugin);
|
|
57
|
+
};
|
|
58
|
+
const isNodeEnvironmentTarget = (target)=>'string' == typeof target && ('node' === target || 'async-node' === target || target.startsWith('node'));
|
|
59
|
+
const shouldUseModuleFederationNodeOutput = (config)=>isNodeEnvironmentTarget(config.output?.target) && hasModuleFederationMarker(config);
|
|
60
|
+
const ssrIntegrationBuilderPlugin = (modernAPI)=>({
|
|
61
|
+
name: '@modern-js/ultramodern-builder-plugin-ssr',
|
|
62
|
+
pre: [
|
|
63
|
+
'@modern-js/builder-plugin-ssr'
|
|
64
|
+
],
|
|
65
|
+
setup (api) {
|
|
66
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>{
|
|
67
|
+
const isServerEnvironment = isNodeEnvironmentTarget(config.output.target) || 'workerSSR' === name;
|
|
68
|
+
const userConfig = modernAPI.getNormalizedConfig();
|
|
69
|
+
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
70
|
+
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
71
|
+
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
72
|
+
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
73
|
+
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
74
|
+
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.';
|
|
75
|
+
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
76
|
+
console.warn(warningMessage);
|
|
77
|
+
}
|
|
78
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
79
|
+
return mergeEnvironmentConfig(config, {
|
|
80
|
+
source: {
|
|
81
|
+
define: {
|
|
82
|
+
'process.env.MODERN_MF_APP_SSR': JSON.stringify(String(isModuleFederationAppSSR))
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
...'workerSSR' === name && userConfig.deploy?.target === 'cloudflare' ? {
|
|
86
|
+
output: {
|
|
87
|
+
module: true
|
|
88
|
+
}
|
|
89
|
+
} : {},
|
|
90
|
+
splitChunks: isServerEnvironment && (hasModuleFederationRuntimeMarker || hasExplicitMfSsrFlag) ? false : void 0
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const ultramodernSSRIntegrationPlugin = ()=>({
|
|
96
|
+
name: '@modern-js/ultramodern-ssr-integration',
|
|
97
|
+
setup (api) {
|
|
98
|
+
api.config(()=>({
|
|
99
|
+
builderPlugins: [
|
|
100
|
+
ssrIntegrationBuilderPlugin(api)
|
|
101
|
+
]
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
export { shouldUseModuleFederationNodeOutput, ultramodernSSRIntegrationPlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AppTools, type CliPlugin } from '@modern-js/app-tools';
|
|
2
|
+
export { createPresetUltramodernConfig, type PresetUltramodernOptions, presetUltramodern, } from './preset.js';
|
|
3
|
+
export { ultramodernReleaseEnvelopePlugin } from './release-envelope-plugin.js';
|
|
4
|
+
export type { AppUserConfig, UltramodernAppUserConfig } from './types.js';
|
|
5
|
+
/** Compose the fork's build and release features through native CLI plugins. */
|
|
6
|
+
export declare const ultramodernAppTools: () => CliPlugin<AppTools>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { AppUserConfig } from './types.js';
|
|
2
|
+
export interface PresetUltramodernOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Stable producer identity used by BFF cross-project clients.
|
|
5
|
+
* @default "app"
|
|
6
|
+
*/
|
|
7
|
+
appId?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Generation-time identity root for a generated delivery unit. When set, the
|
|
10
|
+
* preset derives one build identity from the immutable source revision and
|
|
11
|
+
* injects it into every browser, SSR, API, and backend bundle.
|
|
12
|
+
*/
|
|
13
|
+
deliveryUnit?: {
|
|
14
|
+
buildMarker: string;
|
|
15
|
+
unitId: string;
|
|
16
|
+
version: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Enable BFF requestId contract by default.
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
enableBffRequestId?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Enable telemetry contract by default.
|
|
25
|
+
* Exporters are still configured separately by applications.
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
enableTelemetry?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Enable telemetry exporters.
|
|
31
|
+
*
|
|
32
|
+
* By default each exporter is enabled only when its endpoint is explicitly
|
|
33
|
+
* configured (via the matching option or environment variable), so a bare
|
|
34
|
+
* preset app boots in production without local collectors.
|
|
35
|
+
* Set `true` to force both exporters on with their default localhost
|
|
36
|
+
* endpoints, or `false` to disable exporters entirely.
|
|
37
|
+
* @default undefined (endpoint-driven)
|
|
38
|
+
*/
|
|
39
|
+
enableTelemetryExporters?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* OTLP exporter endpoint. Setting it (or the environment variable)
|
|
42
|
+
* enables the OTLP exporter unless `enableTelemetryExporters` is `false`.
|
|
43
|
+
* The localhost endpoint is used only when exporters are forced on with
|
|
44
|
+
* `enableTelemetryExporters: true` and no endpoint was provided.
|
|
45
|
+
* @default process.env.MODERN_TELEMETRY_OTLP_ENDPOINT
|
|
46
|
+
*/
|
|
47
|
+
otlpEndpoint?: string;
|
|
48
|
+
/**
|
|
49
|
+
* VictoriaMetrics exporter endpoint. Setting it (or the environment
|
|
50
|
+
* variable) enables the VictoriaMetrics exporter unless
|
|
51
|
+
* `enableTelemetryExporters` is `false`.
|
|
52
|
+
* The localhost endpoint is used only when exporters are forced on with
|
|
53
|
+
* `enableTelemetryExporters: true` and no endpoint was provided.
|
|
54
|
+
* @default process.env.MODERN_TELEMETRY_VICTORIA_ENDPOINT
|
|
55
|
+
*/
|
|
56
|
+
victoriaMetricsEndpoint?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Enable fail-loud startup probing for telemetry exporters.
|
|
59
|
+
* Probes only run for exporters that are actually enabled.
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
telemetryFailLoudStartup?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Enable app-level Module Federation SSR handshake by default.
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
enableModuleFederationSSR?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Materialize a fresh UltraModern preset config.
|
|
71
|
+
*
|
|
72
|
+
* This is the advanced inspection API. Use `presetUltramodern` when composing
|
|
73
|
+
* an application config so nested records, arrays, and hooks keep the normal
|
|
74
|
+
* Modern.js merge behavior.
|
|
75
|
+
*/
|
|
76
|
+
export declare const createPresetUltramodernConfig: (options?: PresetUltramodernOptions) => AppUserConfig;
|
|
77
|
+
/**
|
|
78
|
+
* Compose an application config over the UltraModern preset.
|
|
79
|
+
*
|
|
80
|
+
* The application config is merged after the preset. Nested records are
|
|
81
|
+
* preserved, scalar values and `false` override preset values, and omitted or
|
|
82
|
+
* `undefined` values keep the preset value. Arrays and hooks compose in
|
|
83
|
+
* preset-first order. An empty record does not reset nested preset defaults;
|
|
84
|
+
* use the typed `PresetUltramodernOptions` opt-outs instead.
|
|
85
|
+
*/
|
|
86
|
+
export declare const presetUltramodern: (config: AppUserConfig, options?: PresetUltramodernOptions) => AppUserConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@modern-js/server-runtime-extensions/server-plugin';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
2
|
+
import type { MergedEnvironmentConfig } from '@rsbuild/core';
|
|
3
|
+
type EnvironmentConfigLike = Partial<Pick<MergedEnvironmentConfig, 'output' | 'source' | 'tools'>>;
|
|
4
|
+
export declare const shouldUseModuleFederationNodeOutput: (config: EnvironmentConfigLike) => boolean;
|
|
5
|
+
/** Apply fork SSR policy after native SSR defaults through Rsbuild hooks. */
|
|
6
|
+
export declare const ultramodernSSRIntegrationPlugin: () => CliPlugin<AppTools>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AppUserConfig as NativeAppUserConfig } from '@modern-js/app-tools';
|
|
2
|
+
import type { PrecompressConfig } from '@modern-js/app-tools-extensions/build-config/precompress/plugin';
|
|
3
|
+
import type { CloudflareDeployConfig } from '@modern-js/app-tools-extensions/config';
|
|
4
|
+
import type { BffRuntimeUserConfig, ServerTelemetryUserConfig } from '@modern-js/runtime-extensions/server-config';
|
|
5
|
+
type NativeServerConfig = NonNullable<NativeAppUserConfig['server']>;
|
|
6
|
+
type NativeSSRConfig = Exclude<NativeServerConfig['ssr'], boolean | undefined>;
|
|
7
|
+
/** Native Modern.js configuration with the fork's explicitly owned options. */
|
|
8
|
+
export type UltramodernAppUserConfig = Omit<NativeAppUserConfig, 'output' | 'server' | 'bff' | 'deploy'> & {
|
|
9
|
+
output?: Omit<NonNullable<NativeAppUserConfig['output']>, 'precompress'> & {
|
|
10
|
+
precompress?: boolean | PrecompressConfig;
|
|
11
|
+
};
|
|
12
|
+
server?: Omit<NativeServerConfig, 'ssr' | 'telemetry'> & {
|
|
13
|
+
ssr?: boolean | (NativeSSRConfig & {
|
|
14
|
+
moduleFederationAppSSR?: boolean;
|
|
15
|
+
});
|
|
16
|
+
telemetry?: ServerTelemetryUserConfig;
|
|
17
|
+
};
|
|
18
|
+
bff?: Omit<NonNullable<NativeAppUserConfig['bff']>, keyof BffRuntimeUserConfig> & BffRuntimeUserConfig & {
|
|
19
|
+
requestId?: string;
|
|
20
|
+
};
|
|
21
|
+
deploy?: NonNullable<NativeAppUserConfig['deploy']> & CloudflareDeployConfig;
|
|
22
|
+
};
|
|
23
|
+
export type AppUserConfig = UltramodernAppUserConfig;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AppTools, type CliPlugin } from '@modern-js/app-tools';
|
|
2
|
+
export { createPresetUltramodernConfig, type PresetUltramodernOptions, presetUltramodern, } from './preset.mjs';
|
|
3
|
+
export { ultramodernReleaseEnvelopePlugin } from './release-envelope-plugin.mjs';
|
|
4
|
+
export type { AppUserConfig, UltramodernAppUserConfig } from './types.mjs';
|
|
5
|
+
/** Compose the fork's build and release features through native CLI plugins. */
|
|
6
|
+
export declare const ultramodernAppTools: () => CliPlugin<AppTools>;
|