@bleedingdev/modern-js-runtime 3.2.0-ultramodern.9 → 3.2.0-ultramodern.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/boundary-debugger/index.js +299 -0
- package/dist/cjs/cli/ssr/index.js +5 -15
- package/dist/cjs/cli/template.server.js +1 -0
- package/dist/cjs/core/react/wrapper.js +9 -3
- package/dist/cjs/core/server/federatedCss.js +47 -0
- package/dist/cjs/core/server/helmet.js +8 -2
- package/dist/cjs/core/server/stream/afterTemplate.js +9 -6
- package/dist/cjs/core/server/stream/beforeTemplate.js +13 -20
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +98 -0
- package/dist/cjs/core/server/stream/createReadableStream.js +7 -2
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +4 -2
- package/dist/cjs/core/server/stream/shared.js +3 -1
- package/dist/cjs/core/server/string/index.js +6 -6
- package/dist/cjs/core/server/string/loadable.js +33 -7
- package/dist/cjs/exports/head.js +196 -5
- package/dist/cjs/router/cli/code/tanstackTypes.js +116 -51
- package/dist/cjs/router/cli/code/templates.js +1 -8
- package/dist/cjs/router/runtime/tanstack/plugin.js +4 -5
- package/dist/cjs/router/runtime/tanstack/plugin.node.js +2 -13
- package/dist/cjs/router/runtime/tanstack/routeTree.js +47 -4
- package/dist/cjs/rsc/server.worker.js +58 -0
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +9 -8
- package/dist/esm/boundary-debugger/index.mjs +263 -0
- package/dist/esm/cli/ssr/index.mjs +5 -15
- package/dist/esm/cli/template.server.mjs +1 -0
- package/dist/esm/core/react/wrapper.mjs +9 -3
- package/dist/esm/core/server/federatedCss.mjs +13 -0
- package/dist/esm/core/server/helmet.mjs +5 -2
- package/dist/esm/core/server/stream/afterTemplate.mjs +10 -7
- package/dist/esm/core/server/stream/beforeTemplate.mjs +14 -11
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +64 -0
- package/dist/esm/core/server/stream/createReadableStream.mjs +7 -2
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +4 -2
- package/dist/esm/core/server/stream/shared.mjs +3 -1
- package/dist/esm/core/server/string/index.mjs +7 -6
- package/dist/esm/core/server/string/loadable.mjs +33 -7
- package/dist/esm/exports/head.mjs +189 -4
- package/dist/esm/router/cli/code/tanstackTypes.mjs +116 -51
- package/dist/esm/router/cli/code/templates.mjs +1 -8
- package/dist/esm/router/runtime/tanstack/plugin.mjs +8 -9
- package/dist/esm/router/runtime/tanstack/plugin.node.mjs +3 -14
- package/dist/esm/router/runtime/tanstack/routeTree.mjs +47 -4
- package/dist/esm/rsc/server.worker.mjs +1 -0
- package/dist/esm/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/esm-node/boundary-debugger/index.mjs +264 -0
- package/dist/esm-node/cli/ssr/index.mjs +5 -15
- package/dist/esm-node/cli/template.server.mjs +1 -0
- package/dist/esm-node/core/react/wrapper.mjs +9 -3
- package/dist/esm-node/core/server/federatedCss.mjs +14 -0
- package/dist/esm-node/core/server/helmet.mjs +5 -2
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +10 -7
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +14 -11
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +65 -0
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +7 -2
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +4 -2
- package/dist/esm-node/core/server/stream/shared.mjs +3 -1
- package/dist/esm-node/core/server/string/index.mjs +7 -6
- package/dist/esm-node/core/server/string/loadable.mjs +33 -7
- package/dist/esm-node/exports/head.mjs +189 -4
- package/dist/esm-node/router/cli/code/tanstackTypes.mjs +116 -51
- package/dist/esm-node/router/cli/code/templates.mjs +1 -8
- package/dist/esm-node/router/runtime/tanstack/plugin.mjs +8 -9
- package/dist/esm-node/router/runtime/tanstack/plugin.node.mjs +3 -14
- package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +47 -4
- package/dist/esm-node/rsc/server.worker.mjs +2 -0
- package/dist/esm-node/ssr/serverRender/renderToString/entry.mjs +9 -6
- package/dist/types/boundary-debugger/index.d.ts +28 -0
- package/dist/types/core/context/runtime.d.ts +4 -0
- package/dist/types/core/server/federatedCss.d.ts +5 -0
- package/dist/types/core/server/helmet.d.ts +5 -3
- package/dist/types/core/server/stream/beforeTemplate.d.ts +1 -0
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +10 -0
- package/dist/types/core/server/stream/shared.d.ts +8 -0
- package/dist/types/core/server/string/loadable.d.ts +4 -0
- package/dist/types/exports/head.d.ts +10 -3
- package/dist/types/rsc/server.worker.d.ts +1 -0
- package/package.json +25 -19
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
buildShellBeforeTemplate: ()=>buildShellBeforeTemplate
|
|
28
|
+
});
|
|
29
|
+
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
30
|
+
const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
|
|
31
|
+
const external_constants_js_namespaceObject = require("../constants.js");
|
|
32
|
+
const external_federatedCss_js_namespaceObject = require("../federatedCss.js");
|
|
33
|
+
const external_helmet_js_namespaceObject = require("../helmet.js");
|
|
34
|
+
const external_shared_js_namespaceObject = require("../shared.js");
|
|
35
|
+
const external_utils_js_namespaceObject = require("../utils.js");
|
|
36
|
+
const checkIsInline = (chunk, enableInline)=>{
|
|
37
|
+
if ('production' !== process.env.NODE_ENV) return false;
|
|
38
|
+
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
39
|
+
return Boolean(enableInline);
|
|
40
|
+
};
|
|
41
|
+
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
42
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
43
|
+
const helmetData = (0, external_helmet_js_namespaceObject.getHelmetData)(runtimeContext);
|
|
44
|
+
const callbacks = [
|
|
45
|
+
(0, external_helmet_js_namespaceObject.createReplaceHelemt)(helmetData),
|
|
46
|
+
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
47
|
+
];
|
|
48
|
+
return (0, external_shared_js_namespaceObject.buildHtml)(beforeAppTemplate, callbacks);
|
|
49
|
+
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
50
|
+
let css = await getCssChunks();
|
|
51
|
+
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
52
|
+
css += (0, external_federatedCss_js_namespaceObject.createFederatedCssLinks)(moduleFederationCssAssets, {
|
|
53
|
+
template,
|
|
54
|
+
existingAssets: css.match(/href="([^"]+)"/g)?.map((item)=>item.replace(/^href="/, '').replace(/"$/, ''))
|
|
55
|
+
});
|
|
56
|
+
return (0, external_utils_js_namespaceObject.safeReplace)(template, external_constants_js_namespaceObject.CHUNK_CSS_PLACEHOLDER, css);
|
|
57
|
+
async function getCssChunks() {
|
|
58
|
+
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
59
|
+
if (!routeManifest) return '';
|
|
60
|
+
const { routeAssets } = routeManifest;
|
|
61
|
+
let matchedRouteManifests = [];
|
|
62
|
+
const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext);
|
|
63
|
+
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
64
|
+
else if (routerContext && routes) {
|
|
65
|
+
const matches = (0, router_namespaceObject.matchRoutes)(routes, routerContext.location, routerContext.basename);
|
|
66
|
+
matchedRouteManifests = matches?.map((match, index)=>{
|
|
67
|
+
if (!index) return;
|
|
68
|
+
const routeId = match.route.id;
|
|
69
|
+
if (routeId) return routeAssets[routeId];
|
|
70
|
+
}).filter(Boolean) ?? [];
|
|
71
|
+
}
|
|
72
|
+
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
73
|
+
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
74
|
+
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
75
|
+
const { referenceCssAssets = [] } = routeManifest;
|
|
76
|
+
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
77
|
+
return [
|
|
78
|
+
...chunks,
|
|
79
|
+
..._cssChunks
|
|
80
|
+
];
|
|
81
|
+
}, []);
|
|
82
|
+
const { inlineStyles } = config;
|
|
83
|
+
const styles = cssChunks.map((chunk)=>{
|
|
84
|
+
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
85
|
+
checkIsInline(chunk, inlineStyles);
|
|
86
|
+
return link;
|
|
87
|
+
});
|
|
88
|
+
return `${styles.join('')}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.buildShellBeforeTemplate = __webpack_exports__.buildShellBeforeTemplate;
|
|
93
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
94
|
+
"buildShellBeforeTemplate"
|
|
95
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
96
|
+
Object.defineProperty(exports, '__esModule', {
|
|
97
|
+
value: true
|
|
98
|
+
});
|
|
@@ -43,7 +43,7 @@ const defaultExtender = {
|
|
|
43
43
|
};
|
|
44
44
|
const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
45
45
|
const { renderToPipeableStream } = await import("react-dom/server");
|
|
46
|
-
const { runtimeContext, htmlTemplate, config, ssrConfig, entryName } = options;
|
|
46
|
+
const { runtimeContext, htmlTemplate, config, ssrConfig, entryName, moduleFederationCssAssets } = options;
|
|
47
47
|
let shellChunkStatus = external_shared_js_namespaceObject.ShellChunkStatus.START;
|
|
48
48
|
let renderLevel = external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER;
|
|
49
49
|
const forceStream2String = Boolean(process.env.MODERN_JS_STREAM_TO_STRING);
|
|
@@ -63,11 +63,14 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
63
63
|
if (extender.modifyRootElement) processedRootElement = extender.modifyRootElement(processedRootElement);
|
|
64
64
|
});
|
|
65
65
|
const chunkVec = [];
|
|
66
|
+
let hasStartedPipe = false;
|
|
66
67
|
return new Promise((resolve)=>{
|
|
67
68
|
const { pipe: reactStreamingPipe } = renderToPipeableStream(processedRootElement, {
|
|
68
69
|
nonce: config.nonce,
|
|
69
70
|
identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX,
|
|
70
71
|
[onReady] () {
|
|
72
|
+
if (hasStartedPipe) return;
|
|
73
|
+
hasStartedPipe = true;
|
|
71
74
|
let styledComponentsStyleTags = '';
|
|
72
75
|
extenders.forEach((extender)=>{
|
|
73
76
|
if (extender.getStyleTags) styledComponentsStyleTags += extender.getStyleTags();
|
|
@@ -80,6 +83,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
80
83
|
runtimeContext,
|
|
81
84
|
config,
|
|
82
85
|
entryName,
|
|
86
|
+
moduleFederationCssAssets,
|
|
83
87
|
styledComponentsStyleTags
|
|
84
88
|
}).then(({ shellAfter, shellBefore })=>{
|
|
85
89
|
const pendingScripts = [];
|
|
@@ -137,7 +141,8 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
137
141
|
renderLevel,
|
|
138
142
|
runtimeContext,
|
|
139
143
|
entryName,
|
|
140
|
-
config
|
|
144
|
+
config,
|
|
145
|
+
moduleFederationCssAssets
|
|
141
146
|
}).then(({ shellAfter, shellBefore })=>{
|
|
142
147
|
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
143
148
|
const readableStream = (0, external_shared_js_namespaceObject.getReadableStreamFromString)(fallbackHtml);
|
|
@@ -36,19 +36,21 @@ const external_template_js_namespaceObject = require("./template.js");
|
|
|
36
36
|
const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
37
37
|
let shellChunkStatus = external_shared_js_namespaceObject.ShellChunkStatus.START;
|
|
38
38
|
const chunkVec = [];
|
|
39
|
-
const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, rscRoot } = options;
|
|
39
|
+
const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, moduleFederationCssAssets, rscManifest, rscRoot } = options;
|
|
40
40
|
const { shellBefore, shellAfter } = await (0, external_template_js_namespaceObject.getTemplates)(htmlTemplate, {
|
|
41
41
|
renderLevel: external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER,
|
|
42
42
|
runtimeContext,
|
|
43
43
|
ssrConfig,
|
|
44
44
|
request,
|
|
45
45
|
config,
|
|
46
|
-
entryName
|
|
46
|
+
entryName,
|
|
47
|
+
moduleFederationCssAssets
|
|
47
48
|
});
|
|
48
49
|
try {
|
|
49
50
|
const readableOriginal = await (0, ssr_namespaceObject.renderSSRStream)(rootElement, {
|
|
50
51
|
request,
|
|
51
52
|
nonce: config.nonce,
|
|
53
|
+
rscManifest,
|
|
52
54
|
rscRoot: rscRoot,
|
|
53
55
|
routes: runtimeContext.routes,
|
|
54
56
|
onError (error) {
|
|
@@ -95,7 +95,7 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
95
95
|
const end = (0, time_namespaceObject.time)();
|
|
96
96
|
const { runtimeContext, config, resource } = options;
|
|
97
97
|
const { onError, onTiming } = options;
|
|
98
|
-
const { htmlTemplate, entryName } = resource;
|
|
98
|
+
const { htmlTemplate, entryName, moduleFederationCssAssets } = resource;
|
|
99
99
|
const ssrConfig = (0, external_utils_js_namespaceObject.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
100
100
|
const StreamServerRootWrapper = ({ children })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
101
101
|
children: [
|
|
@@ -115,9 +115,11 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
115
115
|
runtimeContext,
|
|
116
116
|
ssrConfig,
|
|
117
117
|
entryName,
|
|
118
|
+
moduleFederationCssAssets,
|
|
118
119
|
rscClientManifest: options.rscClientManifest,
|
|
119
120
|
rscSSRManifest: options.rscSSRManifest,
|
|
120
121
|
rscServerManifest: options.rscServerManifest,
|
|
122
|
+
rscManifest: options.rscManifest,
|
|
121
123
|
rscRoot: options.rscRoot,
|
|
122
124
|
onShellReady () {
|
|
123
125
|
const cost = end();
|
|
@@ -39,8 +39,6 @@ const time_namespaceObject = require("@modern-js/runtime-utils/time");
|
|
|
39
39
|
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
40
40
|
const server_namespaceObject = require("react-dom/server");
|
|
41
41
|
var server_default = /*#__PURE__*/ __webpack_require__.n(server_namespaceObject);
|
|
42
|
-
const external_react_helmet_namespaceObject = require("react-helmet");
|
|
43
|
-
var external_react_helmet_default = /*#__PURE__*/ __webpack_require__.n(external_react_helmet_namespaceObject);
|
|
44
42
|
const external_constants_js_namespaceObject = require("../../constants.js");
|
|
45
43
|
const index_js_namespaceObject = require("../../context/index.js");
|
|
46
44
|
const wrapper_js_namespaceObject = require("../../react/wrapper.js");
|
|
@@ -58,7 +56,7 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
58
56
|
onTiming
|
|
59
57
|
};
|
|
60
58
|
const routerContext = runtimeContext.routerContext;
|
|
61
|
-
const { htmlTemplate, entryName, loadableStats, routeManifest } = resource;
|
|
59
|
+
const { htmlTemplate, entryName, loadableStats, routeManifest, moduleFederationCssAssets } = resource;
|
|
62
60
|
const ssrConfig = (0, external_utils_js_namespaceObject.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
63
61
|
const chunkSet = {
|
|
64
62
|
renderLevel: external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER,
|
|
@@ -71,8 +69,10 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
71
69
|
stats: loadableStats,
|
|
72
70
|
nonce: config.nonce,
|
|
73
71
|
routeManifest,
|
|
72
|
+
runtimeContext,
|
|
74
73
|
template: htmlTemplate,
|
|
75
74
|
entryName,
|
|
75
|
+
moduleFederationCssAssets,
|
|
76
76
|
chunkSet,
|
|
77
77
|
config
|
|
78
78
|
}),
|
|
@@ -96,10 +96,10 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
96
96
|
const rootElement = (0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(serverRoot, Object.assign(runtimeContext, {
|
|
97
97
|
ssr: true
|
|
98
98
|
}));
|
|
99
|
-
const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors, runtimeContext.ssrContext?.htmlModifiers || [], tracer);
|
|
99
|
+
const html = await generateHtml(rootElement, htmlTemplate, chunkSet, collectors, runtimeContext.ssrContext?.htmlModifiers || [], runtimeContext, tracer);
|
|
100
100
|
return html;
|
|
101
101
|
};
|
|
102
|
-
async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, { onError, onTiming }) {
|
|
102
|
+
async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, runtimeContext, { onError, onTiming }) {
|
|
103
103
|
let html = '';
|
|
104
104
|
let helmetData;
|
|
105
105
|
const finalApp = collectors.reduce((pre, creator)=>creator.collect?.(pre) || pre, App);
|
|
@@ -109,7 +109,7 @@ async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifie
|
|
|
109
109
|
identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX
|
|
110
110
|
});
|
|
111
111
|
chunkSet.renderLevel = external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER;
|
|
112
|
-
helmetData =
|
|
112
|
+
helmetData = (0, external_helmet_js_namespaceObject.getHelmetData)(runtimeContext);
|
|
113
113
|
const cost = end();
|
|
114
114
|
onTiming(external_tracer_js_namespaceObject.SSRTimings.RENDER_HTML, cost);
|
|
115
115
|
} catch (e) {
|
|
@@ -27,6 +27,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
LoadableCollector: ()=>LoadableCollector
|
|
28
28
|
});
|
|
29
29
|
const server_namespaceObject = require("@loadable/server");
|
|
30
|
+
const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
|
|
31
|
+
const external_federatedCss_js_namespaceObject = require("../federatedCss.js");
|
|
30
32
|
const external_utils_js_namespaceObject = require("../utils.js");
|
|
31
33
|
const extname = (uri)=>{
|
|
32
34
|
if ('string' != typeof uri || !uri.includes('.')) return '';
|
|
@@ -49,6 +51,20 @@ class LoadableCollector {
|
|
|
49
51
|
const { routeManifest, entryName } = this.options;
|
|
50
52
|
return routeManifest?.routeAssets?.[entryName]?.assets;
|
|
51
53
|
}
|
|
54
|
+
getMatchedRouteChunks() {
|
|
55
|
+
const { routeManifest, runtimeContext } = this.options;
|
|
56
|
+
const routeAssets = routeManifest?.routeAssets;
|
|
57
|
+
if (!routeAssets) return [];
|
|
58
|
+
const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext) ?? [];
|
|
59
|
+
return matchedRouteIds.flatMap((routeId)=>{
|
|
60
|
+
const routeAsset = routeAssets[routeId];
|
|
61
|
+
return (routeAsset?.assets ?? []).map((asset)=>({
|
|
62
|
+
filename: asset.replace(/^\//, ''),
|
|
63
|
+
path: asset,
|
|
64
|
+
url: asset
|
|
65
|
+
}));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
52
68
|
collect(comopnent) {
|
|
53
69
|
const { stats, entryName } = this.options;
|
|
54
70
|
if (!stats) return comopnent;
|
|
@@ -61,20 +77,21 @@ class LoadableCollector {
|
|
|
61
77
|
return this.extractor.collectChunks(comopnent);
|
|
62
78
|
}
|
|
63
79
|
async effect() {
|
|
64
|
-
if (!this.extractor) return;
|
|
65
80
|
const { extractor, options } = this;
|
|
66
81
|
const { entryName, config } = options;
|
|
67
82
|
const asyncChunks = [];
|
|
68
|
-
if (config.enableAsyncEntry) try {
|
|
83
|
+
if (extractor && config.enableAsyncEntry) try {
|
|
69
84
|
asyncChunks.push(...extractor.getChunkAssets([
|
|
70
85
|
`async-${entryName}`
|
|
71
86
|
]));
|
|
72
87
|
} catch (e) {}
|
|
73
|
-
const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
|
|
88
|
+
const chunks = [].concat(asyncChunks).concat(extractor ? extractor.getChunkAssets(extractor.chunks) : []).concat(this.getMatchedRouteChunks());
|
|
74
89
|
const scriptChunks = generateChunks(chunks, 'js');
|
|
75
90
|
const styleChunks = generateChunks(chunks, 'css');
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
if (extractor) {
|
|
92
|
+
this.emitLoadableScripts(extractor);
|
|
93
|
+
await this.emitScriptAssets(scriptChunks);
|
|
94
|
+
}
|
|
78
95
|
await this.emitStyleAssets(styleChunks);
|
|
79
96
|
}
|
|
80
97
|
emitLoadableScripts(extractor) {
|
|
@@ -109,19 +126,28 @@ class LoadableCollector {
|
|
|
109
126
|
chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
|
|
110
127
|
}
|
|
111
128
|
async emitStyleAssets(chunks) {
|
|
112
|
-
const { template, chunkSet, config,
|
|
129
|
+
const { template, chunkSet, config, moduleFederationCssAssets } = this.options;
|
|
113
130
|
const { inlineStyles } = config;
|
|
114
131
|
const atrributes = (0, external_utils_js_namespaceObject.attributesToString)(this.generateAttributes());
|
|
115
132
|
const linkRegExp = /<link .*?href="([^"]+)".*?>/g;
|
|
116
133
|
const matchs = template.matchAll(linkRegExp);
|
|
117
134
|
const existedLinks = [];
|
|
118
135
|
for (const match of matchs)existedLinks.push(match[1]);
|
|
119
|
-
const
|
|
136
|
+
const emittedChunks = chunks.filter((chunk)=>!existedLinks.includes(chunk.url) && !this.existsAssets?.includes(chunk.path));
|
|
137
|
+
const css = await Promise.all(emittedChunks.map(async (chunk)=>{
|
|
120
138
|
const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
|
|
121
139
|
if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
122
140
|
return link;
|
|
123
141
|
}));
|
|
124
142
|
chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
|
|
143
|
+
chunkSet.cssChunk += (0, external_federatedCss_js_namespaceObject.createFederatedCssLinks)(moduleFederationCssAssets, {
|
|
144
|
+
template,
|
|
145
|
+
attributes: this.generateAttributes(),
|
|
146
|
+
existingAssets: [
|
|
147
|
+
...existedLinks,
|
|
148
|
+
...emittedChunks.map((chunk)=>chunk.url)
|
|
149
|
+
]
|
|
150
|
+
});
|
|
125
151
|
}
|
|
126
152
|
generateAttributes(extraAtr = {}) {
|
|
127
153
|
const { config } = this.options;
|
package/dist/cjs/exports/head.js
CHANGED
|
@@ -34,16 +34,207 @@ var __webpack_require__ = {};
|
|
|
34
34
|
var __webpack_exports__ = {};
|
|
35
35
|
__webpack_require__.r(__webpack_exports__);
|
|
36
36
|
__webpack_require__.d(__webpack_exports__, {
|
|
37
|
-
Helmet: ()=>
|
|
38
|
-
|
|
37
|
+
Helmet: ()=>Helmet,
|
|
38
|
+
HelmetData: ()=>external_react_helmet_async_namespaceObject.HelmetData,
|
|
39
|
+
HelmetProvider: ()=>external_react_helmet_async_namespaceObject.HelmetProvider,
|
|
40
|
+
default: ()=>exports_head
|
|
39
41
|
});
|
|
40
|
-
const
|
|
41
|
-
var
|
|
42
|
-
const
|
|
42
|
+
const external_react_namespaceObject = require("react");
|
|
43
|
+
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
44
|
+
const external_react_helmet_async_namespaceObject = require("react-helmet-async");
|
|
45
|
+
const index_js_namespaceObject = require("../core/context/index.js");
|
|
46
|
+
const ATTRIBUTE_NAME_MAP = {
|
|
47
|
+
charSet: 'charset',
|
|
48
|
+
className: 'class',
|
|
49
|
+
contentEditable: 'contenteditable',
|
|
50
|
+
httpEquiv: 'http-equiv',
|
|
51
|
+
itemProp: 'itemprop',
|
|
52
|
+
tabIndex: 'tabindex'
|
|
53
|
+
};
|
|
54
|
+
const escapeHtml = (value)=>String(value).replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>');
|
|
55
|
+
const toHtmlAttributeName = (name)=>ATTRIBUTE_NAME_MAP[name] ?? name;
|
|
56
|
+
const attributesToString = (attributes, includeHelmetAttribute = false)=>{
|
|
57
|
+
const pairs = [];
|
|
58
|
+
if (includeHelmetAttribute) pairs.push('data-rh="true"');
|
|
59
|
+
for (const [name, value] of Object.entries(attributes ?? {})){
|
|
60
|
+
if (false === value || null == value) continue;
|
|
61
|
+
const htmlName = toHtmlAttributeName(name);
|
|
62
|
+
if (true === value) pairs.push(htmlName);
|
|
63
|
+
else pairs.push(`${htmlName}="${escapeHtml(value)}"`);
|
|
64
|
+
}
|
|
65
|
+
return pairs.join(' ');
|
|
66
|
+
};
|
|
67
|
+
const createDatum = (tagName, tags)=>({
|
|
68
|
+
toComponent: ()=>[],
|
|
69
|
+
toString: ()=>tags.map((tag)=>{
|
|
70
|
+
const attrs = attributesToString(tag, true);
|
|
71
|
+
if ("script" === tagName && 'string' == typeof tag.innerHTML) return `<script ${attrs}>${tag.innerHTML}</script>`;
|
|
72
|
+
if ('style' === tagName && 'string' == typeof tag.cssText) return `<style ${attrs}>${tag.cssText}</style>`;
|
|
73
|
+
if ("noscript" === tagName && 'string' == typeof tag.innerHTML) return `<noscript ${attrs}>${tag.innerHTML}</noscript>`;
|
|
74
|
+
return `<${tagName} ${attrs}>`;
|
|
75
|
+
}).join('')
|
|
76
|
+
});
|
|
77
|
+
const createAttributeDatum = (attributes)=>({
|
|
78
|
+
toComponent: ()=>attributes,
|
|
79
|
+
toString: ()=>attributesToString(attributes)
|
|
80
|
+
});
|
|
81
|
+
const createTitleDatum = (title, attributes)=>({
|
|
82
|
+
toComponent: ()=>[],
|
|
83
|
+
toString: ()=>{
|
|
84
|
+
if (!title) return '';
|
|
85
|
+
const attrs = attributesToString(attributes, true);
|
|
86
|
+
return `<title ${attrs}>${escapeHtml(title)}</title>`;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const createEmptyHelmetState = ()=>({
|
|
90
|
+
base: createDatum('base', []),
|
|
91
|
+
bodyAttributes: createAttributeDatum({}),
|
|
92
|
+
htmlAttributes: createAttributeDatum({}),
|
|
93
|
+
link: createDatum('link', []),
|
|
94
|
+
meta: createDatum('meta', []),
|
|
95
|
+
noscript: createDatum("noscript", []),
|
|
96
|
+
priority: createDatum('meta', []),
|
|
97
|
+
script: createDatum("script", []),
|
|
98
|
+
style: createDatum('style', []),
|
|
99
|
+
title: createTitleDatum(void 0, {})
|
|
100
|
+
});
|
|
101
|
+
const mergeAttributes = (current, next)=>({
|
|
102
|
+
...current,
|
|
103
|
+
...next ?? {}
|
|
104
|
+
});
|
|
105
|
+
const collectChildren = (children, draft)=>{
|
|
106
|
+
external_react_default().Children.forEach(children, (child)=>{
|
|
107
|
+
if (!external_react_default().isValidElement(child)) return;
|
|
108
|
+
if (child.type === external_react_default().Fragment) return void collectChildren(child.props.children, draft);
|
|
109
|
+
if ('string' != typeof child.type) return;
|
|
110
|
+
const { children: nestedChildren, ...props } = child.props;
|
|
111
|
+
if ('title' === child.type) {
|
|
112
|
+
draft.title = external_react_default().Children.toArray(nestedChildren).join('');
|
|
113
|
+
draft.titleAttributes = mergeAttributes(draft.titleAttributes, props);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if ('html' === child.type || 'body' === child.type) return;
|
|
117
|
+
if ('base' === child.type || 'link' === child.type || 'meta' === child.type || "noscript" === child.type || "script" === child.type || 'style' === child.type) {
|
|
118
|
+
const tag = {
|
|
119
|
+
...props
|
|
120
|
+
};
|
|
121
|
+
if (("script" === child.type || 'style' === child.type || "noscript" === child.type) && 'string' == typeof nestedChildren) tag['style' === child.type ? 'cssText' : 'innerHTML'] = nestedChildren;
|
|
122
|
+
draft[child.type].push(tag);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
const collectHelmetProps = (current, props)=>{
|
|
127
|
+
const baseState = current ?? createEmptyHelmetState();
|
|
128
|
+
const draft = {
|
|
129
|
+
base: [
|
|
130
|
+
...props.base ? [
|
|
131
|
+
props.base
|
|
132
|
+
] : []
|
|
133
|
+
],
|
|
134
|
+
bodyAttributes: props.bodyAttributes,
|
|
135
|
+
htmlAttributes: props.htmlAttributes,
|
|
136
|
+
link: [
|
|
137
|
+
...props.link ?? []
|
|
138
|
+
],
|
|
139
|
+
meta: [
|
|
140
|
+
...props.meta ?? []
|
|
141
|
+
],
|
|
142
|
+
noscript: [
|
|
143
|
+
...props.noscript ?? []
|
|
144
|
+
],
|
|
145
|
+
script: [
|
|
146
|
+
...props.script ?? []
|
|
147
|
+
],
|
|
148
|
+
style: [
|
|
149
|
+
...props.style ?? []
|
|
150
|
+
],
|
|
151
|
+
title: 'string' == typeof props.title ? props.title : Array.isArray(props.title) ? props.title.join('') : void 0,
|
|
152
|
+
titleAttributes: props.titleAttributes ?? {}
|
|
153
|
+
};
|
|
154
|
+
collectChildren(props.children, draft);
|
|
155
|
+
const title = draft.title && props.titleTemplate ? props.titleTemplate.replaceAll('%s', draft.title) : draft.title ?? props.defaultTitle;
|
|
156
|
+
return {
|
|
157
|
+
base: createDatum('base', [
|
|
158
|
+
...baseState.__baseTags ?? [],
|
|
159
|
+
...draft.base
|
|
160
|
+
]),
|
|
161
|
+
bodyAttributes: createAttributeDatum(mergeAttributes(baseState.__bodyAttributes ?? {}, draft.bodyAttributes)),
|
|
162
|
+
htmlAttributes: createAttributeDatum(mergeAttributes(baseState.__htmlAttributes ?? {}, draft.htmlAttributes)),
|
|
163
|
+
link: createDatum('link', [
|
|
164
|
+
...baseState.__linkTags ?? [],
|
|
165
|
+
...draft.link
|
|
166
|
+
]),
|
|
167
|
+
meta: createDatum('meta', [
|
|
168
|
+
...baseState.__metaTags ?? [],
|
|
169
|
+
...draft.meta
|
|
170
|
+
]),
|
|
171
|
+
noscript: createDatum("noscript", [
|
|
172
|
+
...baseState.__noscriptTags ?? [],
|
|
173
|
+
...draft.noscript
|
|
174
|
+
]),
|
|
175
|
+
priority: createDatum('meta', []),
|
|
176
|
+
script: createDatum("script", [
|
|
177
|
+
...baseState.__scriptTags ?? [],
|
|
178
|
+
...draft.script
|
|
179
|
+
]),
|
|
180
|
+
style: createDatum('style', [
|
|
181
|
+
...baseState.__styleTags ?? [],
|
|
182
|
+
...draft.style
|
|
183
|
+
]),
|
|
184
|
+
title: createTitleDatum(title ?? baseState.__title, mergeAttributes(baseState.__titleAttributes ?? {}, draft.titleAttributes)),
|
|
185
|
+
__baseTags: [
|
|
186
|
+
...baseState.__baseTags ?? [],
|
|
187
|
+
...draft.base
|
|
188
|
+
],
|
|
189
|
+
__bodyAttributes: mergeAttributes(baseState.__bodyAttributes ?? {}, draft.bodyAttributes),
|
|
190
|
+
__htmlAttributes: mergeAttributes(baseState.__htmlAttributes ?? {}, draft.htmlAttributes),
|
|
191
|
+
__linkTags: [
|
|
192
|
+
...baseState.__linkTags ?? [],
|
|
193
|
+
...draft.link
|
|
194
|
+
],
|
|
195
|
+
__metaTags: [
|
|
196
|
+
...baseState.__metaTags ?? [],
|
|
197
|
+
...draft.meta
|
|
198
|
+
],
|
|
199
|
+
__noscriptTags: [
|
|
200
|
+
...baseState.__noscriptTags ?? [],
|
|
201
|
+
...draft.noscript
|
|
202
|
+
],
|
|
203
|
+
__scriptTags: [
|
|
204
|
+
...baseState.__scriptTags ?? [],
|
|
205
|
+
...draft.script
|
|
206
|
+
],
|
|
207
|
+
__styleTags: [
|
|
208
|
+
...baseState.__styleTags ?? [],
|
|
209
|
+
...draft.style
|
|
210
|
+
],
|
|
211
|
+
__title: title ?? baseState.__title,
|
|
212
|
+
__titleAttributes: mergeAttributes(baseState.__titleAttributes ?? {}, draft.titleAttributes)
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
const Helmet = (props)=>{
|
|
216
|
+
const runtimeContext = external_react_default().useContext(index_js_namespaceObject.InternalRuntimeContext);
|
|
217
|
+
if (runtimeContext && !runtimeContext.isBrowser) {
|
|
218
|
+
runtimeContext._helmetContext ??= {};
|
|
219
|
+
runtimeContext._helmetContext.helmet = collectHelmetProps(runtimeContext._helmetContext.helmet ?? void 0, props);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return external_react_default().createElement(external_react_helmet_async_namespaceObject.Helmet, props);
|
|
223
|
+
};
|
|
224
|
+
const head = {
|
|
225
|
+
Helmet,
|
|
226
|
+
HelmetData: external_react_helmet_async_namespaceObject.HelmetData,
|
|
227
|
+
HelmetProvider: external_react_helmet_async_namespaceObject.HelmetProvider
|
|
228
|
+
};
|
|
229
|
+
const exports_head = head;
|
|
43
230
|
exports.Helmet = __webpack_exports__.Helmet;
|
|
231
|
+
exports.HelmetData = __webpack_exports__.HelmetData;
|
|
232
|
+
exports.HelmetProvider = __webpack_exports__.HelmetProvider;
|
|
44
233
|
exports["default"] = __webpack_exports__["default"];
|
|
45
234
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
46
235
|
"Helmet",
|
|
236
|
+
"HelmetData",
|
|
237
|
+
"HelmetProvider",
|
|
47
238
|
"default"
|
|
48
239
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
49
240
|
Object.defineProperty(exports, '__esModule', {
|