@bleedingdev/modern-js-ultramodern-app-tools 3.9.3-ultramodern.8 → 3.11.3-ultramodern.1
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/README.md +41 -0
- package/dist/cjs/native-composition/config-metadata.js +75 -3
- package/dist/cjs/native-composition/config.js +3 -0
- package/dist/cjs/native-composition/module-federation-renderer-plugin.js +5 -4
- package/dist/cjs/native-composition/native-development.js +187 -27
- package/dist/cjs/native-composition/native-entry.js +84 -19
- package/dist/cjs/native-composition/native-federation-dev-assets.js +143 -10
- package/dist/cjs/native-composition/native-federation-dev-public-path.js +46 -0
- package/dist/cjs/native-composition/native-infrastructure.js +81 -1
- package/dist/cjs/native-composition/native-module-federation.js +109 -25
- package/dist/cjs/native-composition/native-routes.js +120 -5
- package/dist/cjs/native-composition/native-worker-context-profiles.js +112 -0
- package/dist/cjs/native-composition/native-worker-federation-config.js +215 -0
- package/dist/cjs/native-composition/native-worker-federation-policy.js +102 -0
- package/dist/cjs/native-composition/native-worker-federation.js +226 -0
- package/dist/cjs/native-composition/native-worker-publication.js +107 -0
- package/dist/cjs/native-composition/native-worker.js +37 -3
- package/dist/cjs/native-composition/redact-config.js +51 -0
- package/dist/cjs/native-composition/renderer-installed-profile.js +61 -2
- package/dist/cjs/native-composition/renderer-registration.js +3 -1
- package/dist/cjs/native-composition/renderer-selection.js +3 -1
- package/dist/cjs/native-composition/server-minify.js +1 -4
- package/dist/cjs/native-composition/type-checker.js +14 -4
- package/dist/cjs/native-composition/workspace-preset.js +19 -7
- package/dist/cjs/renderers/react/composition.js +2 -0
- package/dist/cjs/renderers/react/module-federation.js +56 -12
- package/dist/cjs/renderers/react/redact-integration-plugin.js +302 -0
- package/dist/esm/native-composition/config-metadata.mjs +75 -3
- package/dist/esm/native-composition/config.mjs +3 -0
- package/dist/esm/native-composition/module-federation-renderer-plugin.mjs +7 -6
- package/dist/esm/native-composition/native-development.mjs +189 -29
- package/dist/esm/native-composition/native-entry.mjs +85 -20
- package/dist/esm/native-composition/native-federation-dev-assets.mjs +124 -9
- package/dist/esm/native-composition/native-federation-dev-public-path.mjs +38 -1
- package/dist/esm/native-composition/native-infrastructure.mjs +81 -1
- package/dist/esm/native-composition/native-module-federation.mjs +108 -27
- package/dist/esm/native-composition/native-routes.mjs +110 -4
- package/dist/esm/native-composition/native-worker-context-profiles.mjs +63 -0
- package/dist/esm/native-composition/native-worker-federation-config.mjs +164 -0
- package/dist/esm/native-composition/native-worker-federation-policy.mjs +53 -0
- package/dist/esm/native-composition/native-worker-federation.mjs +166 -0
- package/dist/esm/native-composition/native-worker-publication.mjs +66 -0
- package/dist/esm/native-composition/native-worker.mjs +37 -3
- package/dist/esm/native-composition/redact-config.mjs +10 -0
- package/dist/esm/native-composition/renderer-installed-profile.mjs +54 -1
- package/dist/esm/native-composition/renderer-registration.mjs +3 -1
- package/dist/esm/native-composition/renderer-selection.mjs +3 -1
- package/dist/esm/native-composition/server-minify.mjs +1 -4
- package/dist/esm/native-composition/type-checker.mjs +4 -4
- package/dist/esm/native-composition/workspace-preset.mjs +19 -7
- package/dist/esm/renderers/react/composition.mjs +2 -0
- package/dist/esm/renderers/react/module-federation.mjs +52 -11
- package/dist/esm/renderers/react/redact-integration-plugin.mjs +221 -0
- package/dist/esm-node/native-composition/config-metadata.mjs +75 -3
- package/dist/esm-node/native-composition/config.mjs +3 -0
- package/dist/esm-node/native-composition/module-federation-renderer-plugin.mjs +7 -6
- package/dist/esm-node/native-composition/native-development.mjs +189 -29
- package/dist/esm-node/native-composition/native-entry.mjs +85 -20
- package/dist/esm-node/native-composition/native-federation-dev-assets.mjs +124 -9
- package/dist/esm-node/native-composition/native-federation-dev-public-path.mjs +38 -1
- package/dist/esm-node/native-composition/native-infrastructure.mjs +81 -1
- package/dist/esm-node/native-composition/native-module-federation.mjs +108 -27
- package/dist/esm-node/native-composition/native-routes.mjs +110 -4
- package/dist/esm-node/native-composition/native-worker-context-profiles.mjs +64 -0
- package/dist/esm-node/native-composition/native-worker-federation-config.mjs +165 -0
- package/dist/esm-node/native-composition/native-worker-federation-policy.mjs +54 -0
- package/dist/esm-node/native-composition/native-worker-federation.mjs +167 -0
- package/dist/esm-node/native-composition/native-worker-publication.mjs +67 -0
- package/dist/esm-node/native-composition/native-worker.mjs +37 -3
- package/dist/esm-node/native-composition/redact-config.mjs +11 -0
- package/dist/esm-node/native-composition/renderer-installed-profile.mjs +54 -1
- package/dist/esm-node/native-composition/renderer-registration.mjs +3 -1
- package/dist/esm-node/native-composition/renderer-selection.mjs +3 -1
- package/dist/esm-node/native-composition/server-minify.mjs +1 -4
- package/dist/esm-node/native-composition/type-checker.mjs +4 -4
- package/dist/esm-node/native-composition/workspace-preset.mjs +19 -7
- package/dist/esm-node/renderers/react/composition.mjs +2 -0
- package/dist/esm-node/renderers/react/module-federation.mjs +52 -11
- package/dist/esm-node/renderers/react/redact-integration-plugin.mjs +222 -0
- package/dist/types/native-composition/config-metadata.d.ts +6 -0
- package/dist/types/native-composition/module-federation-renderer-plugin.d.ts +2 -1
- package/dist/types/native-composition/native-development.d.ts +16 -0
- package/dist/types/native-composition/native-entry.d.ts +1 -1
- package/dist/types/native-composition/native-federation-dev-assets.d.ts +26 -2
- package/dist/types/native-composition/native-federation-dev-public-path.d.ts +9 -0
- package/dist/types/native-composition/native-infrastructure.d.ts +10 -0
- package/dist/types/native-composition/native-module-federation.d.ts +8 -4
- package/dist/types/native-composition/native-routes.d.ts +11 -0
- package/dist/types/native-composition/native-worker-context-profiles.d.ts +2 -0
- package/dist/types/native-composition/native-worker-federation-config.d.ts +46 -0
- package/dist/types/native-composition/native-worker-federation-policy.d.ts +8 -0
- package/dist/types/native-composition/native-worker-federation.d.ts +57 -0
- package/dist/types/native-composition/native-worker-publication.d.ts +12 -0
- package/dist/types/native-composition/native-worker.d.ts +14 -1
- package/dist/types/native-composition/redact-config.d.ts +11 -0
- package/dist/types/native-composition/renderer-installed-profile.d.ts +6 -0
- package/dist/types/native-composition/renderer-selection.d.ts +1 -1
- package/dist/types/native-composition/server-minify.d.ts +2 -5
- package/dist/types/native-composition/types.d.ts +7 -0
- package/dist/types/renderers/react/module-federation.d.ts +10 -1
- package/dist/types/renderers/react/redact-integration-plugin.d.ts +50 -0
- package/dist/types-esm/native-composition/config-metadata.d.mts +6 -0
- package/dist/types-esm/native-composition/module-federation-renderer-plugin.d.mts +2 -1
- package/dist/types-esm/native-composition/native-development.d.mts +16 -0
- package/dist/types-esm/native-composition/native-entry.d.mts +1 -1
- package/dist/types-esm/native-composition/native-federation-dev-assets.d.mts +26 -2
- package/dist/types-esm/native-composition/native-federation-dev-public-path.d.mts +9 -0
- package/dist/types-esm/native-composition/native-infrastructure.d.mts +10 -0
- package/dist/types-esm/native-composition/native-module-federation.d.mts +8 -4
- package/dist/types-esm/native-composition/native-routes.d.mts +11 -0
- package/dist/types-esm/native-composition/native-worker-context-profiles.d.mts +2 -0
- package/dist/types-esm/native-composition/native-worker-federation-config.d.mts +46 -0
- package/dist/types-esm/native-composition/native-worker-federation-policy.d.mts +8 -0
- package/dist/types-esm/native-composition/native-worker-federation.d.mts +57 -0
- package/dist/types-esm/native-composition/native-worker-publication.d.mts +12 -0
- package/dist/types-esm/native-composition/native-worker.d.mts +14 -1
- package/dist/types-esm/native-composition/redact-config.d.mts +11 -0
- package/dist/types-esm/native-composition/renderer-installed-profile.d.mts +6 -0
- package/dist/types-esm/native-composition/renderer-selection.d.mts +1 -1
- package/dist/types-esm/native-composition/server-minify.d.mts +2 -5
- package/dist/types-esm/native-composition/types.d.mts +7 -0
- package/dist/types-esm/renderers/react/module-federation.d.mts +10 -1
- package/dist/types-esm/renderers/react/redact-integration-plugin.d.mts +50 -0
- package/package.json +39 -35
- package/src/native-composition/config-metadata.ts +110 -11
- package/src/native-composition/config.ts +3 -0
- package/src/native-composition/module-federation-renderer-plugin.ts +23 -5
- package/src/native-composition/native-development.ts +336 -47
- package/src/native-composition/native-entry.ts +116 -21
- package/src/native-composition/native-federation-dev-assets.ts +240 -13
- package/src/native-composition/native-federation-dev-public-path.ts +96 -0
- package/src/native-composition/native-infrastructure.ts +164 -1
- package/src/native-composition/native-module-federation.ts +178 -55
- package/src/native-composition/native-routes.ts +167 -3
- package/src/native-composition/native-worker-context-profiles.ts +119 -0
- package/src/native-composition/native-worker-federation-config.ts +343 -0
- package/src/native-composition/native-worker-federation-policy.ts +119 -0
- package/src/native-composition/native-worker-federation.ts +401 -0
- package/src/native-composition/native-worker-publication.ts +151 -0
- package/src/native-composition/native-worker.ts +71 -3
- package/src/native-composition/redact-config.ts +33 -0
- package/src/native-composition/renderer-installed-profile.ts +67 -0
- package/src/native-composition/renderer-registration.ts +2 -0
- package/src/native-composition/renderer-selection.ts +4 -1
- package/src/native-composition/server-minify.ts +3 -2
- package/src/native-composition/type-checker.ts +8 -8
- package/src/native-composition/types.ts +5 -0
- package/src/native-composition/workspace-preset.ts +34 -5
- package/src/renderers/react/composition.ts +2 -0
- package/src/renderers/react/module-federation.ts +107 -9
- package/src/renderers/react/redact-integration-plugin.ts +347 -0
package/README.md
CHANGED
|
@@ -25,6 +25,47 @@ The selector belongs to this config import. Do not add another `appTools()` or
|
|
|
25
25
|
native application source and dependencies, then a dev-server restart and a
|
|
26
26
|
document reload. The generated entries own mounting and hydration.
|
|
27
27
|
|
|
28
|
+
## Default React runtime
|
|
29
|
+
|
|
30
|
+
React applications use the framework's exact `@tanstack/redact@0.2.1` runtime
|
|
31
|
+
by default, on the client, Node SSR and Cloudflare workerd SSR. Keep authoring
|
|
32
|
+
normal React 19 imports; no application dependency or template edits enable it.
|
|
33
|
+
The framework owns Redact, `rsbuild-redact-plugin@0.1.0`, and a React 19 copy for
|
|
34
|
+
the public plugin's version check under pnpm's strict dependency isolation.
|
|
35
|
+
CSR uses that public plugin; SSR uses a fork-owned integration with the same
|
|
36
|
+
exact aliases, including canonical Redact imports, in every environment.
|
|
37
|
+
Custom Document compilers inherit these aliases instead of forcing real React
|
|
38
|
+
externals; the native compiler respects explicit runtime aliases.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
export default defineConfig({
|
|
42
|
+
// Omit for Redact with view transitions disabled.
|
|
43
|
+
redact: { viewTransitions: true },
|
|
44
|
+
server: { ssr: true },
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Set `redact: false` to use real React throughout the application. Invalid values
|
|
49
|
+
fail configuration validation. **RSC applications always use real React**, on
|
|
50
|
+
both server and client: Flight requires React internals Redact does not provide.
|
|
51
|
+
The CLI logs this limitation once rather than mixing runtimes.
|
|
52
|
+
|
|
53
|
+
Enabled builds require the reviewed pnpm patch whose first line in Redact's
|
|
54
|
+
`dist/server/stream.js` is `// ultramodern-redact-patch: v1`. Missing patches
|
|
55
|
+
fail the build with installation guidance and the `redact: false` escape hatch;
|
|
56
|
+
there is no configuration bypass. The patch fixes streamed Suspense IDs,
|
|
57
|
+
post-hydration IDs, namespace-sensitive segments and deferred reveal ordering.
|
|
58
|
+
|
|
59
|
+
Federated hosts and remotes must choose the same runtime. Their existing
|
|
60
|
+
renderer manifest contract publishes the effective runtime and hydration
|
|
61
|
+
identity (Redact `0.2.1`, or actual React for opt-out/RSC), and rejects mismatches
|
|
62
|
+
before remote initialization. Redact publishes under React's own share keys
|
|
63
|
+
(`react`, `react-dom`, JSX runtimes), once each, so hosts that govern those
|
|
64
|
+
singletons keep working. Each key carries Redact's real version with strict
|
|
65
|
+
matching, not a React 19 version, and direct Redact imports consume the same
|
|
66
|
+
singletons. The React authoring
|
|
67
|
+
profile continues to describe React's API/compiler, not the runtime override.
|
|
68
|
+
|
|
28
69
|
## Native application imports
|
|
29
70
|
|
|
30
71
|
| Renderer | Component authoring | Application router |
|
|
@@ -47,8 +47,12 @@ const external_node_module_namespaceObject = require("node:module");
|
|
|
47
47
|
const external_node_path_namespaceObject = require("node:path");
|
|
48
48
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
49
49
|
const external_node_url_namespaceObject = require("node:url");
|
|
50
|
+
const cli_namespaceObject = require("@modern-js/plugin/cli");
|
|
50
51
|
const core_namespaceObject = require("@rsbuild/core");
|
|
51
52
|
const external_config_js_namespaceObject = require("./config.js");
|
|
53
|
+
const external_config_read_context_js_namespaceObject = require("./config-read-context.js");
|
|
54
|
+
const external_native_i18n_js_namespaceObject = require("./native-i18n.js");
|
|
55
|
+
const external_renderer_router_resolution_js_namespaceObject = require("./renderer-router-resolution.js");
|
|
52
56
|
function inside(directory, file) {
|
|
53
57
|
const relative = external_node_path_default().relative(directory, file);
|
|
54
58
|
return '' !== relative && !relative.startsWith(`..${external_node_path_default().sep}`) && '..' !== relative && !external_node_path_default().isAbsolute(relative);
|
|
@@ -115,11 +119,76 @@ async function readUltramodernConfigMetadata(options) {
|
|
|
115
119
|
appDirectory,
|
|
116
120
|
configFile: options.configFile,
|
|
117
121
|
env: options.env,
|
|
118
|
-
command: options.command
|
|
122
|
+
command: options.analyzeServerRoutes ? 'metadata' : options.command
|
|
119
123
|
});
|
|
124
|
+
const installedAppDirectory = options.stagedWorkspace && (appDirectory === external_node_path_default().resolve(options.stagedWorkspace.root) || inside(external_node_path_default().resolve(options.stagedWorkspace.root), appDirectory)) ? external_node_path_default().resolve(options.stagedWorkspace.originalRoot, external_node_path_default().relative(options.stagedWorkspace.root, appDirectory)) : appDirectory;
|
|
125
|
+
if (options.analyzeServerRoutes) {
|
|
126
|
+
const previousArgv = process.env.MODERN_ARGV;
|
|
127
|
+
process.env.MODERN_ARGV = 'node modern metadata';
|
|
128
|
+
const cli = (0, cli_namespaceObject.createCli)();
|
|
129
|
+
let cleanup;
|
|
130
|
+
try {
|
|
131
|
+
return await (0, external_config_read_context_js_namespaceObject.withEntryMetadataRead)(async ()=>{
|
|
132
|
+
const { appContext } = await cli.init({
|
|
133
|
+
cwd: appDirectory,
|
|
134
|
+
configFile: false,
|
|
135
|
+
config: loaded.config,
|
|
136
|
+
command: 'metadata',
|
|
137
|
+
internalPlugins: [
|
|
138
|
+
{
|
|
139
|
+
name: '@modern-js/ultramodern-route-metadata-context',
|
|
140
|
+
setup (api) {
|
|
141
|
+
api.updateAppContext({
|
|
142
|
+
configFile: loaded.configFile
|
|
143
|
+
});
|
|
144
|
+
cleanup = ()=>api.getHooks().onBeforeExit.call();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
const context = appContext.pluginAPI.getAppContext();
|
|
150
|
+
const entrypoints = context.entrypoints ?? [];
|
|
151
|
+
if (!entrypoints.length) throw new Error('UltraModern analyzed configuration has no application entries');
|
|
152
|
+
const entryBasePaths = {};
|
|
153
|
+
for (const entry of entrypoints){
|
|
154
|
+
const prefixes = [
|
|
155
|
+
...new Set((context.serverRoutes ?? []).filter((route)=>route.entryName === entry.entryName && !route.isApi).map((route)=>route.urlPath))
|
|
156
|
+
];
|
|
157
|
+
if (1 !== prefixes.length || 'string' != typeof prefixes[0]) throw new Error(`Native Worker federation entry ${entry.entryName} requires exactly one analyzed public route prefix.`);
|
|
158
|
+
entryBasePaths[entry.entryName] = prefixes[0];
|
|
159
|
+
}
|
|
160
|
+
const entries = entrypoints.map(({ entryName, isMainEntry })=>({
|
|
161
|
+
entryName,
|
|
162
|
+
isMainEntry
|
|
163
|
+
}));
|
|
164
|
+
const primary = entries.find((entry)=>entry.isMainEntry) ?? entries[0];
|
|
165
|
+
const renderer = loaded.config.renderer;
|
|
166
|
+
const routerBindings = await (0, external_renderer_router_resolution_js_namespaceObject.resolveEntrypointRouterBindings)(renderer, entrypoints, context.plugins.map((plugin)=>plugin.name), void 0, installedAppDirectory);
|
|
167
|
+
const i18n = (0, external_native_i18n_js_namespaceObject.findNativeI18nConfig)(loaded.config.plugins ?? []);
|
|
168
|
+
return {
|
|
169
|
+
renderer,
|
|
170
|
+
entries,
|
|
171
|
+
primaryEntryName: primary.entryName,
|
|
172
|
+
routerBindings,
|
|
173
|
+
entryBasePaths,
|
|
174
|
+
...i18n ? {
|
|
175
|
+
i18n
|
|
176
|
+
} : {}
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
} finally{
|
|
180
|
+
try {
|
|
181
|
+
await cleanup?.();
|
|
182
|
+
} finally{
|
|
183
|
+
cli.dispose();
|
|
184
|
+
if (void 0 === previousArgv) delete process.env.MODERN_ARGV;
|
|
185
|
+
else process.env.MODERN_ARGV = previousArgv;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
120
189
|
const resolution = await (0, external_config_js_namespaceObject.resolveUltramodernEntryIdentities)({
|
|
121
190
|
appDirectory,
|
|
122
|
-
installedAppDirectory
|
|
191
|
+
installedAppDirectory,
|
|
123
192
|
config: loaded.config,
|
|
124
193
|
command: options.command,
|
|
125
194
|
configFile: loaded.configFile
|
|
@@ -150,7 +219,10 @@ function loadUltramodernConfigMetadata(options) {
|
|
|
150
219
|
execArgv: [],
|
|
151
220
|
env: {
|
|
152
221
|
...process.env,
|
|
153
|
-
NODE_ENV: options.env
|
|
222
|
+
NODE_ENV: options.env,
|
|
223
|
+
...options.analyzeServerRoutes ? {
|
|
224
|
+
MODERN_ARGV: 'node modern metadata'
|
|
225
|
+
} : {}
|
|
154
226
|
},
|
|
155
227
|
stdio: [
|
|
156
228
|
'ignore',
|
|
@@ -50,6 +50,7 @@ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_no
|
|
|
50
50
|
const cli_namespaceObject = require("@modern-js/plugin/cli");
|
|
51
51
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
52
52
|
const external_config_read_context_js_namespaceObject = require("./config-read-context.js");
|
|
53
|
+
const external_redact_config_js_namespaceObject = require("./redact-config.js");
|
|
53
54
|
const external_renderer_registration_js_namespaceObject = require("./renderer-registration.js");
|
|
54
55
|
const external_renderer_router_resolution_js_namespaceObject = require("./renderer-router-resolution.js");
|
|
55
56
|
const external_renderer_selection_js_namespaceObject = require("./renderer-selection.js");
|
|
@@ -59,6 +60,7 @@ function isConfigPromise(value) {
|
|
|
59
60
|
}
|
|
60
61
|
function selectConfig(config, factory) {
|
|
61
62
|
if (!config || 'object' != typeof config || Array.isArray(config)) throw new Error('UltraModern configuration must be an object');
|
|
63
|
+
(0, external_redact_config_js_namespaceObject.validateRedactConfig)(config.redact);
|
|
62
64
|
const renderer = (0, external_renderer_registration_js_namespaceObject.resolveRendererAdapter)(config.renderer).name;
|
|
63
65
|
const plugins = config.plugins ?? [];
|
|
64
66
|
(0, external_renderer_selection_js_namespaceObject.assertNoAdditionalBasePlugins)(plugins);
|
|
@@ -88,6 +90,7 @@ function createDefineConfig(factory) {
|
|
|
88
90
|
}
|
|
89
91
|
async function resolveUltramodernConfig(config, context) {
|
|
90
92
|
const resolved = 'function' == typeof config ? await config(context) : config;
|
|
93
|
+
(0, external_redact_config_js_namespaceObject.validateRedactConfig)(resolved.redact);
|
|
91
94
|
const renderer = (0, external_renderer_registration_js_namespaceObject.resolveRendererAdapter)(resolved.renderer).name;
|
|
92
95
|
return void 0 === resolved.renderer ? {
|
|
93
96
|
...resolved,
|
|
@@ -72,9 +72,9 @@ function nativeManifestAssetNames(manifest) {
|
|
|
72
72
|
function resolveRendererFederationRuntimePlugin(registrarUrl = __rslib_import_meta_url__) {
|
|
73
73
|
return (0, external_node_module_namespaceObject.createRequire)(registrarUrl).resolve('@modern-js/federation-runtime/renderer-runtime-plugin');
|
|
74
74
|
}
|
|
75
|
-
function resolveRendererFederationCompatibility(renderer) {
|
|
75
|
+
function resolveRendererFederationCompatibility(renderer, config = {}) {
|
|
76
76
|
const adapter = (0, external_renderer_registration_js_namespaceObject.resolveRendererAdapter)(renderer);
|
|
77
|
-
if ('native' !== adapter.kind) return (0, module_federation_js_namespaceObject.resolveReactFederationCompatibility)();
|
|
77
|
+
if ('native' !== adapter.kind) return (0, module_federation_js_namespaceObject.resolveReactFederationCompatibility)(config);
|
|
78
78
|
const owners = adapter.runtime;
|
|
79
79
|
const metadata = (0, external_renderer_profile_js_namespaceObject.resolveRendererProfileMetadata)(renderer);
|
|
80
80
|
const bootstrap = metadata.frameworkPackages.find((owner)=>owner.specifier === owners.bootstrap);
|
|
@@ -83,7 +83,7 @@ function resolveRendererFederationCompatibility(renderer) {
|
|
|
83
83
|
specifier: owners.package,
|
|
84
84
|
filename: (0, external_node_module_namespaceObject.createRequire)(`${bootstrap.directory}/package.json`).resolve(owners.package)
|
|
85
85
|
});
|
|
86
|
-
const { protocolVersion, compiler, hydration, router } = metadata.profile;
|
|
86
|
+
const { protocolVersion, compiler, hydration, router } = (0, external_renderer_installed_profile_js_namespaceObject.projectInstalledFederationProfile)(metadata.profile, bootstrap);
|
|
87
87
|
return (0, renderer_contract_namespaceObject.readRendererFederationCompatibility)({
|
|
88
88
|
profile: {
|
|
89
89
|
renderer,
|
|
@@ -121,7 +121,7 @@ function createRendererModuleFederationIntegration(renderer, options = {}) {
|
|
|
121
121
|
api.modifyBundlerChain((chain)=>{
|
|
122
122
|
const nativeKeys = NATIVE_PLUGINS.filter((key)=>chain.plugins.has(key));
|
|
123
123
|
if (!nativeKeys.length) return;
|
|
124
|
-
const compatibility = (0, renderer_contract_namespaceObject.readRendererFederationCompatibility)(options.resolveCompatibility?.() ?? resolveRendererFederationCompatibility(renderer));
|
|
124
|
+
const compatibility = (0, renderer_contract_namespaceObject.readRendererFederationCompatibility)(options.resolveCompatibility?.() ?? resolveRendererFederationCompatibility(renderer, api.getNormalizedConfig()));
|
|
125
125
|
const runtimePlugin = (options.resolveRuntimePlugin ?? resolveRendererFederationRuntimePlugin)();
|
|
126
126
|
const stamped = new WeakSet();
|
|
127
127
|
const publications = new Set();
|
|
@@ -132,6 +132,7 @@ function createRendererModuleFederationIntegration(renderer, options = {}) {
|
|
|
132
132
|
const config = {
|
|
133
133
|
...original
|
|
134
134
|
};
|
|
135
|
+
if ('react' === renderer) config.shared = (0, module_federation_js_namespaceObject.withReactRuntimeShared)(config.shared, compatibility);
|
|
135
136
|
if (false === config.manifest) throw (0, renderer_contract_namespaceObject.rendererFederationError)('renderer components require native manifest publication.');
|
|
136
137
|
if (void 0 !== config.manifest && true !== config.manifest && !record(config.manifest)) throw (0, renderer_contract_namespaceObject.rendererFederationError)('native manifest options must be a boolean or record.');
|
|
137
138
|
const manifest = record(config.manifest) ? config.manifest : {};
|
|
@@ -56,6 +56,7 @@ const server_namespaceObject = require("@modern-js/renderer-core/server");
|
|
|
56
56
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
57
57
|
const external_native_build_manifest_js_namespaceObject = require("./native-build-manifest.js");
|
|
58
58
|
const external_native_federation_dev_assets_js_namespaceObject = require("./native-federation-dev-assets.js");
|
|
59
|
+
const external_native_federation_dev_public_path_js_namespaceObject = require("./native-federation-dev-public-path.js");
|
|
59
60
|
const external_renderer_registration_js_namespaceObject = require("./renderer-registration.js");
|
|
60
61
|
const allowsOrigin = (allowed, origin)=>Array.isArray(allowed) ? allowed.some((entry)=>allowsOrigin(entry, origin)) : allowed instanceof RegExp ? allowed.test(origin) : 'string' == typeof allowed ? allowed === origin : Boolean(allowed);
|
|
61
62
|
async function applyDevServerHeaders(request, response, server) {
|
|
@@ -95,6 +96,47 @@ function emittedBytes(result, name) {
|
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
class NativeDevelopment {
|
|
99
|
+
async captureFederationGraph(result) {
|
|
100
|
+
try {
|
|
101
|
+
const entryNames = Object.keys(this.options.getSessionIdentities().identities);
|
|
102
|
+
const assets = await (0, external_native_federation_dev_assets_js_namespaceObject.collectNativeFederationDevAssets)(result, entryNames, (name)=>emittedBytes(result, name));
|
|
103
|
+
if (0 === assets.size) return;
|
|
104
|
+
return {
|
|
105
|
+
assets,
|
|
106
|
+
graph: (0, external_native_federation_dev_assets_js_namespaceObject.nativeFederationDevGraph)(result)
|
|
107
|
+
};
|
|
108
|
+
} catch {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
retainFinishedGraphs() {
|
|
113
|
+
const pending = this.finishedFederationGraphs;
|
|
114
|
+
this.finishedFederationGraphs = [];
|
|
115
|
+
for (const finished of pending){
|
|
116
|
+
if (this.closed) return;
|
|
117
|
+
const revision = (0, external_native_federation_dev_assets_js_namespaceObject.nativeFederationDevRevision)(finished.assets);
|
|
118
|
+
const graphManifest = finished.graph?.immutableManifest;
|
|
119
|
+
try {
|
|
120
|
+
this.retainedFederationAssets = (0, external_native_federation_dev_assets_js_namespaceObject.retainNativeFederationDevAssets)(this.retainedFederationAssets, new Map([
|
|
121
|
+
...finished.assets
|
|
122
|
+
].map(([url, asset])=>[
|
|
123
|
+
url,
|
|
124
|
+
{
|
|
125
|
+
...asset,
|
|
126
|
+
revision,
|
|
127
|
+
graphManifest
|
|
128
|
+
}
|
|
129
|
+
])));
|
|
130
|
+
} catch (error) {
|
|
131
|
+
utils_namespaceObject.logger.warn('Native development could not retain a finished federation graph.', error);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
this.federationAssets = new Map([
|
|
135
|
+
...this.federationAssets,
|
|
136
|
+
...this.retainedFederationAssets
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
98
140
|
notify() {
|
|
99
141
|
for (const waiter of this.waiters)waiter();
|
|
100
142
|
this.waiters.clear();
|
|
@@ -124,6 +166,15 @@ class NativeDevelopment {
|
|
|
124
166
|
(0, identity_namespaceObject.assertRendererIdentity)(snapshot.manifest.rendererIdentity, identity);
|
|
125
167
|
return snapshot;
|
|
126
168
|
}
|
|
169
|
+
await this.waitForPublication(signal);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async waitForPublication(signal) {
|
|
173
|
+
for(;;){
|
|
174
|
+
signal.throwIfAborted();
|
|
175
|
+
if (this.closed) throw new Error('Native development compiler is closed');
|
|
176
|
+
if (this.failure) throw this.failure.error;
|
|
177
|
+
if (this.ready) return;
|
|
127
178
|
await new Promise((resolve, reject)=>{
|
|
128
179
|
const resumed = ()=>{
|
|
129
180
|
signal.removeEventListener('abort', aborted);
|
|
@@ -150,11 +201,26 @@ class NativeDevelopment {
|
|
|
150
201
|
if (!client?.compilation.hash || !server?.compilation.hash || !serverRoot) throw new Error('Native development requires completed client and server compilations');
|
|
151
202
|
const session = this.options.getSessionIdentities();
|
|
152
203
|
const entryNames = Object.keys(session.identities);
|
|
153
|
-
const federationAssets =
|
|
204
|
+
const federationAssets = new Map([
|
|
205
|
+
...await (0, external_native_federation_dev_assets_js_namespaceObject.collectNativeFederationDevAssets)(server, entryNames, (name)=>emittedBytes(server, name)),
|
|
206
|
+
...await (0, external_native_federation_dev_assets_js_namespaceObject.collectNativeFederationDevAssets)(client, entryNames, (name)=>emittedBytes(client, name))
|
|
207
|
+
]);
|
|
208
|
+
const federationGraph = (0, external_native_federation_dev_assets_js_namespaceObject.nativeFederationDevGraph)(client);
|
|
209
|
+
const federationRevision = federationAssets.size ? (0, external_native_federation_dev_assets_js_namespaceObject.nativeFederationDevRevision)(federationAssets) : void 0;
|
|
210
|
+
const retainedFederationAssets = (0, external_native_federation_dev_assets_js_namespaceObject.retainNativeFederationDevAssets)(this.retainedFederationAssets, new Map([
|
|
211
|
+
...federationAssets
|
|
212
|
+
].map(([url, asset])=>[
|
|
213
|
+
url,
|
|
214
|
+
{
|
|
215
|
+
...asset,
|
|
216
|
+
revision: federationRevision,
|
|
217
|
+
graphManifest: federationGraph?.immutableManifest
|
|
218
|
+
}
|
|
219
|
+
])));
|
|
154
220
|
const publicPath = client.compilation.outputOptions.publicPath;
|
|
155
221
|
const prefix = 'string' == typeof publicPath && 'auto' !== publicPath ? publicPath.endsWith('/') ? publicPath : `${publicPath}/` : '/';
|
|
156
222
|
for (const asset of client.compilation.getAssets()){
|
|
157
|
-
if (asset.info.hotModuleReplacement || this.mutableClientAssets.has(asset.name) || this.compilerArtifacts.isMutableDevelopmentAsset(asset.name, entryNames)) continue;
|
|
223
|
+
if (true !== asset.info.immutable || asset.info.hotModuleReplacement || this.mutableClientAssets.has(asset.name) || this.compilerArtifacts.isMutableDevelopmentAsset(asset.name, entryNames)) continue;
|
|
158
224
|
const pathname = new URL(`${prefix}${asset.name}`, 'http://native-dev.invalid').pathname;
|
|
159
225
|
if (!this.retained.has(pathname)) this.retained.set(pathname, {
|
|
160
226
|
bytes: await emittedBytes(client, asset.name),
|
|
@@ -218,7 +284,10 @@ class NativeDevelopment {
|
|
|
218
284
|
await promises_default().rename(temporary, manifestFile);
|
|
219
285
|
return {
|
|
220
286
|
entries,
|
|
221
|
-
federationAssets
|
|
287
|
+
federationAssets,
|
|
288
|
+
federationGraph,
|
|
289
|
+
federationRevision,
|
|
290
|
+
retainedFederationAssets
|
|
222
291
|
};
|
|
223
292
|
}
|
|
224
293
|
async close() {
|
|
@@ -226,8 +295,13 @@ class NativeDevelopment {
|
|
|
226
295
|
this.closed = true;
|
|
227
296
|
this.ready = void 0;
|
|
228
297
|
this.notify();
|
|
298
|
+
await this.publication.catch(()=>{});
|
|
229
299
|
this.retained.clear();
|
|
230
300
|
this.federationAssets = new Map();
|
|
301
|
+
this.federationRevision = void 0;
|
|
302
|
+
this.federationGraph = void 0;
|
|
303
|
+
this.federationCompilers.clear();
|
|
304
|
+
this.retainedFederationAssets = new Map();
|
|
231
305
|
if (this.manifestFile) await promises_default().rm(this.manifestFile, {
|
|
232
306
|
force: true
|
|
233
307
|
});
|
|
@@ -238,9 +312,13 @@ class NativeDevelopment {
|
|
|
238
312
|
this.compilerVersions = new WeakMap();
|
|
239
313
|
this.compilationVersions = new WeakMap();
|
|
240
314
|
this.generation = 0;
|
|
315
|
+
this.publication = Promise.resolve();
|
|
241
316
|
this.closed = false;
|
|
242
317
|
this.retained = new Map();
|
|
243
318
|
this.federationAssets = new Map();
|
|
319
|
+
this.federationCompilers = new Set();
|
|
320
|
+
this.retainedFederationAssets = new Map();
|
|
321
|
+
this.finishedFederationGraphs = [];
|
|
244
322
|
this.mutableClientAssets = new Set([
|
|
245
323
|
'renderer-assets.json'
|
|
246
324
|
]);
|
|
@@ -279,16 +357,73 @@ class NativeDevelopment {
|
|
|
279
357
|
config.mode = 'development';
|
|
280
358
|
const previous = config.dev?.setupMiddlewares;
|
|
281
359
|
const retain = (middlewares)=>{
|
|
282
|
-
|
|
360
|
+
const owner = this;
|
|
361
|
+
middlewares.unshift(function serve(request, response, next) {
|
|
362
|
+
if (owner.closed) return next();
|
|
283
363
|
if ('GET' !== request.method && 'HEAD' !== request.method) return next();
|
|
284
364
|
const pathname = URL.parse(request.url ?? '/', 'http://native-dev.invalid')?.pathname;
|
|
285
365
|
const protocol = request.socket instanceof external_node_tls_namespaceObject.TLSSocket ? 'https:' : 'http:';
|
|
286
|
-
const
|
|
287
|
-
|
|
366
|
+
const origin = `${protocol}//${request.headers.host}`;
|
|
367
|
+
const afterPublication = (resume)=>{
|
|
368
|
+
const pending = new AbortController();
|
|
369
|
+
const aborted = ()=>pending.abort(new Error('Native graph request closed'));
|
|
370
|
+
request.once('aborted', aborted);
|
|
371
|
+
response.once('close', aborted);
|
|
372
|
+
if (request.aborted || response.destroyed) aborted();
|
|
373
|
+
const cleanup = ()=>{
|
|
374
|
+
request.removeListener('aborted', aborted);
|
|
375
|
+
response.removeListener('close', aborted);
|
|
376
|
+
};
|
|
377
|
+
owner.waitForPublication(pending.signal).then(()=>{
|
|
378
|
+
cleanup();
|
|
379
|
+
if (!pending.signal.aborted) resume();
|
|
380
|
+
}, (error)=>{
|
|
381
|
+
cleanup();
|
|
382
|
+
if (!pending.signal.aborted) next(error);
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
if (!owner.federationGraph && [
|
|
386
|
+
...owner.federationCompilers
|
|
387
|
+
].some((compiler)=>{
|
|
388
|
+
const manifest = (0, external_native_federation_dev_assets_js_namespaceObject.nativeFederationDevManifest)(compiler);
|
|
389
|
+
return manifest && URL.parse(manifest)?.pathname === pathname;
|
|
390
|
+
})) return void afterPublication(()=>{
|
|
391
|
+
if (!owner.federationGraph) return next(new Error('Native browser manifest was not published'));
|
|
392
|
+
serve(request, response, next);
|
|
393
|
+
});
|
|
394
|
+
const hotUpdate = owner.federationGraph && (0, external_native_federation_dev_public_path_js_namespaceObject.nativeFederationDevHotUpdateTarget)(owner.federationGraph.publicPath, request.url ?? '/', origin);
|
|
395
|
+
if (hotUpdate) {
|
|
396
|
+
request.url = hotUpdate;
|
|
397
|
+
return next();
|
|
398
|
+
}
|
|
399
|
+
const federationAsset = (0, external_native_federation_dev_assets_js_namespaceObject.resolveNativeFederationDevAsset)(owner.federationAssets, request.url ?? '/', origin) ?? (owner.federationGraph && (0, external_native_federation_dev_assets_js_namespaceObject.resolveNativeFederationDevManifest)(owner.federationAssets, request.url ?? '/', owner.federationGraph.manifest));
|
|
400
|
+
const revision = owner.federationRevision;
|
|
401
|
+
const asset = federationAsset || pathname && owner.retained.get(pathname);
|
|
402
|
+
if (!asset) {
|
|
403
|
+
if (owner.federationGraph && !owner.ready && !owner.failure && (0, external_native_federation_dev_public_path_js_namespaceObject.isNativeFederationDevGraphAsset)(owner.federationGraph.publicPath, request.url ?? '/', origin)) return void afterPublication(()=>serve(request, response, next));
|
|
404
|
+
return next();
|
|
405
|
+
}
|
|
288
406
|
applyDevServerHeaders(request, response, api.getNormalizedConfig().server).then(()=>{
|
|
289
407
|
response.setHeader('Content-Type', asset.contentType);
|
|
290
408
|
response.setHeader('Content-Length', asset.bytes.length);
|
|
291
|
-
response.setHeader('Cache-Control', 'no-store');
|
|
409
|
+
response.setHeader('Cache-Control', asset.immutable ? 'public, max-age=31536000, immutable' : 'no-store');
|
|
410
|
+
if (federationAsset) {
|
|
411
|
+
const graphManifest = asset.graphManifest ?? owner.federationGraph?.immutableManifest;
|
|
412
|
+
if (graphManifest) response.setHeader('Link', `<${graphManifest}>; rel="ultramodern-completed-graph"`);
|
|
413
|
+
const graphRevision = asset.revision ?? revision;
|
|
414
|
+
if (graphRevision) response.setHeader(external_native_federation_dev_assets_js_namespaceObject.NATIVE_FEDERATION_DEV_REVISION_HEADER, graphRevision);
|
|
415
|
+
if (api.getNormalizedConfig().server.cors) {
|
|
416
|
+
const previous = response.getHeader('Access-Control-Expose-Headers');
|
|
417
|
+
const exposed = new Set([
|
|
418
|
+
...Array.isArray(previous) ? previous : String(previous ?? '').split(','),
|
|
419
|
+
'Link',
|
|
420
|
+
external_native_federation_dev_assets_js_namespaceObject.NATIVE_FEDERATION_DEV_REVISION_HEADER
|
|
421
|
+
].map((value)=>value.trim()).filter(Boolean));
|
|
422
|
+
response.setHeader('Access-Control-Expose-Headers', [
|
|
423
|
+
...exposed
|
|
424
|
+
].join(','));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
292
427
|
response.end('HEAD' === request.method ? void 0 : asset.bytes);
|
|
293
428
|
}, next);
|
|
294
429
|
});
|
|
@@ -309,6 +444,7 @@ class NativeDevelopment {
|
|
|
309
444
|
compiler
|
|
310
445
|
];
|
|
311
446
|
for (const candidate of compilers){
|
|
447
|
+
this.federationCompilers.add(candidate);
|
|
312
448
|
this.compilerVersions.set(candidate, 0);
|
|
313
449
|
let runVersion = 0;
|
|
314
450
|
const captureRun = ()=>{
|
|
@@ -328,30 +464,54 @@ class NativeDevelopment {
|
|
|
328
464
|
this.invalidate();
|
|
329
465
|
});
|
|
330
466
|
candidate.hooks.failed.tap('UltraModernNativeDevelopment', (error)=>this.fail(error));
|
|
467
|
+
candidate.hooks.done.tapPromise(runHook, async (result)=>{
|
|
468
|
+
if (result.hasErrors()) return;
|
|
469
|
+
const finished = await this.captureFederationGraph(result);
|
|
470
|
+
if (finished) this.finishedFederationGraphs.push(finished);
|
|
471
|
+
});
|
|
331
472
|
}
|
|
332
473
|
});
|
|
333
|
-
api.onDevCompileDone(
|
|
474
|
+
api.onDevCompileDone(({ stats })=>{
|
|
334
475
|
const epoch = this.epoch;
|
|
335
|
-
const
|
|
336
|
-
stats
|
|
337
|
-
];
|
|
338
|
-
if (this.closed || results.some((result)=>{
|
|
339
|
-
const version = this.compilationVersions.get(result.compilation);
|
|
340
|
-
return void 0 === version || version !== this.compilerVersions.get(result.compilation.compiler);
|
|
341
|
-
})) return;
|
|
342
|
-
if (stats.hasErrors()) return this.fail(new Error('Native development compilation failed'));
|
|
343
|
-
try {
|
|
344
|
-
const publication = await this.publish(stats);
|
|
345
|
-
if (this.closed || epoch !== this.epoch) return;
|
|
346
|
-
this.federationAssets = publication.federationAssets;
|
|
347
|
-
this.ready = publication.entries;
|
|
348
|
-
this.failure = void 0;
|
|
349
|
-
this.notify();
|
|
350
|
-
} catch (error) {
|
|
476
|
+
const publishCurrent = async ()=>{
|
|
351
477
|
if (this.closed || epoch !== this.epoch) return;
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
478
|
+
const results = 'stats' in stats ? stats.stats : [
|
|
479
|
+
stats
|
|
480
|
+
];
|
|
481
|
+
if (results.some((result)=>{
|
|
482
|
+
const version = this.compilationVersions.get(result.compilation);
|
|
483
|
+
return void 0 === version || version !== this.compilerVersions.get(result.compilation.compiler);
|
|
484
|
+
})) return;
|
|
485
|
+
if (stats.hasErrors()) return this.fail(new Error('Native development compilation failed'));
|
|
486
|
+
try {
|
|
487
|
+
const publication = await this.publish(stats);
|
|
488
|
+
if (this.closed || epoch !== this.epoch) return;
|
|
489
|
+
this.retainedFederationAssets = publication.retainedFederationAssets;
|
|
490
|
+
this.retainFinishedGraphs();
|
|
491
|
+
this.federationAssets = new Map([
|
|
492
|
+
...publication.federationAssets,
|
|
493
|
+
...this.retainedFederationAssets
|
|
494
|
+
]);
|
|
495
|
+
this.federationRevision = publication.federationRevision;
|
|
496
|
+
this.federationGraph = publication.federationGraph;
|
|
497
|
+
this.ready = publication.entries;
|
|
498
|
+
this.failure = void 0;
|
|
499
|
+
this.notify();
|
|
500
|
+
} catch (error) {
|
|
501
|
+
if (this.closed || epoch !== this.epoch) return;
|
|
502
|
+
this.fail(error);
|
|
503
|
+
api.logger.error('Native development could not load the compiled application.', error);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
const publishNext = async ()=>{
|
|
507
|
+
try {
|
|
508
|
+
await publishCurrent();
|
|
509
|
+
} finally{
|
|
510
|
+
this.retainFinishedGraphs();
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
this.publication = this.publication.then(publishNext, publishNext);
|
|
514
|
+
return this.publication;
|
|
355
515
|
});
|
|
356
516
|
api.onCloseDevServer(()=>this.close());
|
|
357
517
|
}
|