@bleedingdev/modern-js-runtime 3.2.0-ultramodern.8 → 3.2.0-ultramodern.80
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 +298 -0
- package/dist/cjs/cli/ssr/index.js +3 -2
- package/dist/cjs/cli/template.server.js +1 -0
- package/dist/cjs/core/server/federatedCss.js +47 -0
- package/dist/cjs/core/server/helmet.js +2 -2
- package/dist/cjs/core/server/stream/afterTemplate.js +9 -6
- package/dist/cjs/core/server/stream/beforeTemplate.js +12 -8
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +109 -0
- package/dist/cjs/core/server/stream/createReadableStream.js +4 -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 +3 -1
- package/dist/cjs/core/server/string/loadable.js +33 -7
- 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 +40 -4
- package/dist/cjs/rsc/server.worker.js +58 -0
- package/dist/esm/boundary-debugger/index.mjs +262 -0
- package/dist/esm/cli/ssr/index.mjs +3 -2
- package/dist/esm/cli/template.server.mjs +1 -0
- package/dist/esm/core/server/federatedCss.mjs +13 -0
- package/dist/esm/core/server/helmet.mjs +1 -1
- package/dist/esm/core/server/stream/afterTemplate.mjs +10 -7
- package/dist/esm/core/server/stream/beforeTemplate.mjs +12 -8
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +65 -0
- package/dist/esm/core/server/stream/createReadableStream.mjs +4 -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 +3 -1
- package/dist/esm/core/server/string/loadable.mjs +33 -7
- 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 +40 -4
- package/dist/esm/rsc/server.worker.mjs +1 -0
- package/dist/esm-node/boundary-debugger/index.mjs +263 -0
- package/dist/esm-node/cli/ssr/index.mjs +3 -2
- package/dist/esm-node/cli/template.server.mjs +1 -0
- package/dist/esm-node/core/server/federatedCss.mjs +14 -0
- package/dist/esm-node/core/server/helmet.mjs +1 -1
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +10 -7
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +12 -8
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +66 -0
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +4 -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 +3 -1
- package/dist/esm-node/core/server/string/loadable.mjs +33 -7
- 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 +40 -4
- package/dist/esm-node/rsc/server.worker.mjs +2 -0
- package/dist/types/boundary-debugger/index.d.ts +28 -0
- package/dist/types/core/server/federatedCss.d.ts +5 -0
- 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/rsc/server.worker.d.ts +1 -0
- package/package.json +22 -15
|
@@ -0,0 +1,298 @@
|
|
|
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
|
+
default: ()=>boundary_debugger,
|
|
28
|
+
ultramodernBoundaryDebuggerPlugin: ()=>ultramodernBoundaryDebuggerPlugin
|
|
29
|
+
});
|
|
30
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
31
|
+
const external_react_namespaceObject = require("react");
|
|
32
|
+
const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
|
|
33
|
+
const queryParamName = 'modern-boundaries';
|
|
34
|
+
const boundarySelector = '[data-modern-boundary-id]';
|
|
35
|
+
const defaultLabels = {
|
|
36
|
+
cs: {
|
|
37
|
+
toggle: 'zobrazit hranice týmů'
|
|
38
|
+
},
|
|
39
|
+
en: {
|
|
40
|
+
toggle: 'show team boundaries'
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const palette = [
|
|
44
|
+
'#ff5a5f',
|
|
45
|
+
'#30e27a',
|
|
46
|
+
'#f6cf45',
|
|
47
|
+
'#7c8cff',
|
|
48
|
+
'#29b6f6'
|
|
49
|
+
];
|
|
50
|
+
const readStoredEnabled = (storageKey, fallback)=>{
|
|
51
|
+
if ("u" < typeof window) return fallback;
|
|
52
|
+
try {
|
|
53
|
+
const stored = window.localStorage.getItem(storageKey);
|
|
54
|
+
return null === stored ? fallback : 'true' === stored;
|
|
55
|
+
} catch {
|
|
56
|
+
return fallback;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const writeStoredEnabled = (storageKey, enabled)=>{
|
|
60
|
+
if ("u" < typeof window) return;
|
|
61
|
+
try {
|
|
62
|
+
window.localStorage.setItem(storageKey, String(enabled));
|
|
63
|
+
} catch {}
|
|
64
|
+
};
|
|
65
|
+
const parseEnabledOverride = (value)=>{
|
|
66
|
+
if (null === value) return;
|
|
67
|
+
const normalized = value.toLowerCase();
|
|
68
|
+
if ('1' === normalized || 'true' === normalized) return true;
|
|
69
|
+
if ('0' === normalized || 'false' === normalized) return false;
|
|
70
|
+
};
|
|
71
|
+
const readQueryEnabledOverride = ()=>{
|
|
72
|
+
if ("u" < typeof window) return;
|
|
73
|
+
try {
|
|
74
|
+
return parseEnabledOverride(new URLSearchParams(window.location.search).get(queryParamName));
|
|
75
|
+
} catch {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const detectLanguage = ()=>{
|
|
80
|
+
if ("u" < typeof document) return 'en';
|
|
81
|
+
const htmlLanguage = document.documentElement.lang;
|
|
82
|
+
if (htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
|
|
83
|
+
if ("u" < typeof window) return 'en';
|
|
84
|
+
return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
|
|
85
|
+
};
|
|
86
|
+
const hashBoundaryId = (id)=>{
|
|
87
|
+
let hash = 0;
|
|
88
|
+
for(let index = 0; index < id.length; index++)hash = 31 * hash + id.charCodeAt(index) >>> 0;
|
|
89
|
+
return hash;
|
|
90
|
+
};
|
|
91
|
+
const formatRectKey = (rect)=>[
|
|
92
|
+
Math.round(100 * rect.left) / 100,
|
|
93
|
+
Math.round(100 * rect.top) / 100,
|
|
94
|
+
Math.round(100 * rect.width) / 100,
|
|
95
|
+
Math.round(100 * rect.height) / 100
|
|
96
|
+
].join(':');
|
|
97
|
+
const getBoundaryId = (element)=>element.dataset.modernBoundaryId ?? element.dataset.mfRemote ?? element.getAttribute('data-mf-remote') ?? void 0;
|
|
98
|
+
const collectBoundaryElements = (legacySelector)=>{
|
|
99
|
+
const elements = new Set();
|
|
100
|
+
for (const element of document.querySelectorAll(boundarySelector))elements.add(element);
|
|
101
|
+
if (!legacySelector) return Array.from(elements);
|
|
102
|
+
try {
|
|
103
|
+
for (const element of document.querySelectorAll(legacySelector))elements.add(element);
|
|
104
|
+
} catch {}
|
|
105
|
+
return Array.from(elements);
|
|
106
|
+
};
|
|
107
|
+
function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, labels = defaultLabels, legacySelector, metadata, storageKey = defaultStorageKey }) {
|
|
108
|
+
const [mounted, setMounted] = (0, external_react_namespaceObject.useState)(false);
|
|
109
|
+
const [enabled, setEnabled] = (0, external_react_namespaceObject.useState)(false);
|
|
110
|
+
const [boxes, setBoxes] = (0, external_react_namespaceObject.useState)([]);
|
|
111
|
+
const boundaries = (0, external_react_namespaceObject.useMemo)(()=>new Map(metadata.boundaries.map((entry, index)=>[
|
|
112
|
+
entry.mfName,
|
|
113
|
+
{
|
|
114
|
+
...entry,
|
|
115
|
+
color: entry.color ?? palette[index % palette.length],
|
|
116
|
+
label: entry.label ?? entry.appId
|
|
117
|
+
}
|
|
118
|
+
])), [
|
|
119
|
+
metadata
|
|
120
|
+
]);
|
|
121
|
+
const language = mounted ? detectLanguage() : 'en';
|
|
122
|
+
const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show team boundaries';
|
|
123
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
124
|
+
setMounted(true);
|
|
125
|
+
const queryOverride = readQueryEnabledOverride();
|
|
126
|
+
setEnabled(queryOverride ?? readStoredEnabled(storageKey, enabledByDefault));
|
|
127
|
+
}, [
|
|
128
|
+
enabledByDefault,
|
|
129
|
+
storageKey
|
|
130
|
+
]);
|
|
131
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
132
|
+
if (!mounted) return;
|
|
133
|
+
writeStoredEnabled(storageKey, enabled);
|
|
134
|
+
}, [
|
|
135
|
+
enabled,
|
|
136
|
+
mounted,
|
|
137
|
+
storageKey
|
|
138
|
+
]);
|
|
139
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
140
|
+
if (!enabled) return void setBoxes([]);
|
|
141
|
+
const readBoxes = ()=>{
|
|
142
|
+
const seenBoxes = new Set();
|
|
143
|
+
const nextBoxes = collectBoundaryElements(legacySelector).map((element)=>{
|
|
144
|
+
const boundaryId = getBoundaryId(element);
|
|
145
|
+
if (!boundaryId) return;
|
|
146
|
+
const rect = element.getBoundingClientRect();
|
|
147
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
148
|
+
const rectKey = formatRectKey(rect);
|
|
149
|
+
const boxKey = `${boundaryId}:${rectKey}`;
|
|
150
|
+
if (seenBoxes.has(boxKey)) return;
|
|
151
|
+
seenBoxes.add(boxKey);
|
|
152
|
+
const boundary = boundaries.get(boundaryId);
|
|
153
|
+
const color = boundary?.color ?? palette[hashBoundaryId(boundaryId) % palette.length];
|
|
154
|
+
const label = boundary?.label ?? boundary?.appId ?? boundaryId;
|
|
155
|
+
const expose = element.dataset.modernMfExpose;
|
|
156
|
+
const detail = expose && expose !== label && expose !== boundaryId ? expose : void 0;
|
|
157
|
+
const box = {
|
|
158
|
+
color,
|
|
159
|
+
height: rect.height,
|
|
160
|
+
id: boxKey,
|
|
161
|
+
label,
|
|
162
|
+
left: rect.left,
|
|
163
|
+
top: rect.top,
|
|
164
|
+
width: rect.width
|
|
165
|
+
};
|
|
166
|
+
if (detail) box.detail = detail;
|
|
167
|
+
return box;
|
|
168
|
+
}).filter((box)=>void 0 !== box);
|
|
169
|
+
setBoxes(nextBoxes);
|
|
170
|
+
};
|
|
171
|
+
readBoxes();
|
|
172
|
+
const resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
173
|
+
for (const element of collectBoundaryElements(legacySelector))resizeObserver?.observe(element);
|
|
174
|
+
const mutationObserver = new MutationObserver(readBoxes);
|
|
175
|
+
mutationObserver.observe(document.body, {
|
|
176
|
+
childList: true,
|
|
177
|
+
subtree: true
|
|
178
|
+
});
|
|
179
|
+
window.addEventListener('resize', readBoxes);
|
|
180
|
+
window.addEventListener('scroll', readBoxes, true);
|
|
181
|
+
return ()=>{
|
|
182
|
+
mutationObserver.disconnect();
|
|
183
|
+
resizeObserver?.disconnect();
|
|
184
|
+
window.removeEventListener('resize', readBoxes);
|
|
185
|
+
window.removeEventListener('scroll', readBoxes, true);
|
|
186
|
+
};
|
|
187
|
+
}, [
|
|
188
|
+
boundaries,
|
|
189
|
+
enabled,
|
|
190
|
+
legacySelector
|
|
191
|
+
]);
|
|
192
|
+
if (!mounted) return null;
|
|
193
|
+
const shouldRenderToggle = 'visible' === controlMode || 'hidden-when-off' === controlMode && enabled;
|
|
194
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
195
|
+
children: [
|
|
196
|
+
shouldRenderToggle ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("label", {
|
|
197
|
+
style: {
|
|
198
|
+
alignItems: 'center',
|
|
199
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
200
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
201
|
+
borderRadius: 12,
|
|
202
|
+
bottom: 20,
|
|
203
|
+
boxShadow: '0 16px 40px rgba(0, 0, 0, 0.16)',
|
|
204
|
+
color: '#111827',
|
|
205
|
+
display: 'flex',
|
|
206
|
+
font: '600 14px/1.2 system-ui, sans-serif',
|
|
207
|
+
gap: 8,
|
|
208
|
+
left: 20,
|
|
209
|
+
padding: '12px 14px',
|
|
210
|
+
position: 'fixed',
|
|
211
|
+
zIndex: 2147483000
|
|
212
|
+
},
|
|
213
|
+
children: [
|
|
214
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
|
|
215
|
+
checked: enabled,
|
|
216
|
+
onChange: (event)=>setEnabled(event.currentTarget.checked),
|
|
217
|
+
type: "checkbox"
|
|
218
|
+
}),
|
|
219
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
220
|
+
children: toggleLabel
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
}) : null,
|
|
224
|
+
enabled ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
225
|
+
"aria-hidden": "true",
|
|
226
|
+
children: boxes.map((box)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
227
|
+
style: {
|
|
228
|
+
border: `2px solid ${box.color}`,
|
|
229
|
+
borderRadius: 8,
|
|
230
|
+
boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
|
|
231
|
+
height: box.height,
|
|
232
|
+
left: box.left,
|
|
233
|
+
pointerEvents: 'none',
|
|
234
|
+
position: 'fixed',
|
|
235
|
+
top: box.top,
|
|
236
|
+
width: box.width,
|
|
237
|
+
zIndex: 2147482999
|
|
238
|
+
},
|
|
239
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("span", {
|
|
240
|
+
style: {
|
|
241
|
+
background: box.color,
|
|
242
|
+
borderRadius: 999,
|
|
243
|
+
color: '#111827',
|
|
244
|
+
display: 'grid',
|
|
245
|
+
font: '800 11px/1.1 system-ui, sans-serif',
|
|
246
|
+
gap: 3,
|
|
247
|
+
maxWidth: 'min(280px, calc(100vw - 24px))',
|
|
248
|
+
padding: '5px 8px',
|
|
249
|
+
position: 'absolute',
|
|
250
|
+
right: 4,
|
|
251
|
+
top: 4,
|
|
252
|
+
whiteSpace: 'nowrap'
|
|
253
|
+
},
|
|
254
|
+
children: [
|
|
255
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
256
|
+
children: box.label
|
|
257
|
+
}),
|
|
258
|
+
box.detail ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
259
|
+
style: {
|
|
260
|
+
font: '700 10px/1.1 system-ui, sans-serif',
|
|
261
|
+
opacity: 0.82,
|
|
262
|
+
overflow: 'hidden',
|
|
263
|
+
textOverflow: 'ellipsis'
|
|
264
|
+
},
|
|
265
|
+
children: box.detail
|
|
266
|
+
}) : null
|
|
267
|
+
]
|
|
268
|
+
})
|
|
269
|
+
}, box.id))
|
|
270
|
+
}) : null
|
|
271
|
+
]
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
const ultramodernBoundaryDebuggerPlugin = (options)=>({
|
|
275
|
+
name: '@modern-js/runtime/boundary-debugger',
|
|
276
|
+
setup: (api)=>{
|
|
277
|
+
api.wrapRoot((App)=>(props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
278
|
+
children: [
|
|
279
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
280
|
+
...props
|
|
281
|
+
}),
|
|
282
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(BoundaryDebugger, {
|
|
283
|
+
...options
|
|
284
|
+
})
|
|
285
|
+
]
|
|
286
|
+
}));
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
|
|
290
|
+
exports["default"] = __webpack_exports__["default"];
|
|
291
|
+
exports.ultramodernBoundaryDebuggerPlugin = __webpack_exports__.ultramodernBoundaryDebuggerPlugin;
|
|
292
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
293
|
+
"default",
|
|
294
|
+
"ultramodernBoundaryDebuggerPlugin"
|
|
295
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
296
|
+
Object.defineProperty(exports, '__esModule', {
|
|
297
|
+
value: true
|
|
298
|
+
});
|
|
@@ -125,13 +125,14 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
125
125
|
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
126
126
|
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
127
127
|
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
128
|
+
const isCloudflareWorkerSSR = 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare';
|
|
128
129
|
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
129
130
|
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
130
131
|
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.';
|
|
131
132
|
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
132
133
|
console.warn(warningMessage);
|
|
133
134
|
}
|
|
134
|
-
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
135
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
|
|
135
136
|
const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
|
|
136
137
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
137
138
|
const appContext = modernAPI.getAppContext();
|
|
@@ -148,7 +149,7 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
148
149
|
} : void 0;
|
|
149
150
|
const useLoadablePlugin = (0, utils_namespaceObject.isUseSSRBundle)(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
150
151
|
const outputConfig = {
|
|
151
|
-
module: isServerEnvironment && !useModuleFederationNodeOutput && outputModule
|
|
152
|
+
module: isServerEnvironment && !useModuleFederationNodeOutput && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
|
|
152
153
|
};
|
|
153
154
|
const useLoadableComponents = (0, utils_namespaceObject.isUseSSRBundle)(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
154
155
|
return mergeEnvironmentConfig(config, {
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
createFederatedCssLinks: ()=>createFederatedCssLinks
|
|
28
|
+
});
|
|
29
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
30
|
+
const createFederatedCssLinks = (assets, options)=>{
|
|
31
|
+
if (!assets?.length) return '';
|
|
32
|
+
const seen = new Set(options.existingAssets || []);
|
|
33
|
+
const attributes = (0, external_utils_js_namespaceObject.attributesToString)(options.attributes || {});
|
|
34
|
+
const links = [];
|
|
35
|
+
for (const asset of assets)if (!(!asset || seen.has(asset) || options.template.includes(asset))) {
|
|
36
|
+
seen.add(asset);
|
|
37
|
+
links.push(`<link${attributes} href="${asset}" rel="stylesheet" />`);
|
|
38
|
+
}
|
|
39
|
+
return links.join('');
|
|
40
|
+
};
|
|
41
|
+
exports.createFederatedCssLinks = __webpack_exports__.createFederatedCssLinks;
|
|
42
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
43
|
+
"createFederatedCssLinks"
|
|
44
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
45
|
+
Object.defineProperty(exports, '__esModule', {
|
|
46
|
+
value: true
|
|
47
|
+
});
|
|
@@ -27,8 +27,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
createReplaceHelemt: ()=>createReplaceHelemt,
|
|
28
28
|
helmetReplace: ()=>helmetReplace
|
|
29
29
|
});
|
|
30
|
-
const external_os_namespaceObject = require("os");
|
|
31
30
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
31
|
+
const EOL = '\n';
|
|
32
32
|
const RE_HTML_ATTR = /<html[^>]*>/;
|
|
33
33
|
const RE_BODY_ATTR = /<body[^>]*>/;
|
|
34
34
|
const RE_LAST_IN_HEAD = /<\/head>/;
|
|
@@ -61,7 +61,7 @@ function helmetReplace(content, helmetData) {
|
|
|
61
61
|
script,
|
|
62
62
|
style,
|
|
63
63
|
!existTitleTag ? title : ''
|
|
64
|
-
].reduce((pre, cur)=>pre + (cur.length > 0 ? ` ${cur}${
|
|
64
|
+
].reduce((pre, cur)=>pre + (cur.length > 0 ? ` ${cur}${EOL}` : ''), '');
|
|
65
65
|
return (0, external_utils_js_namespaceObject.safeReplace)(result, RE_LAST_IN_HEAD, `${helmetStr}</head>`);
|
|
66
66
|
}
|
|
67
67
|
exports.createReplaceHelemt = __webpack_exports__.createReplaceHelemt;
|
|
@@ -50,12 +50,15 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
50
50
|
if (!routeManifest) return template;
|
|
51
51
|
const { routeAssets } = routeManifest;
|
|
52
52
|
if (!routeAssets) return template;
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext) ?? [];
|
|
54
|
+
const assetEntries = [
|
|
55
|
+
...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
|
|
56
|
+
routeAssets[`async-${entryName}`]
|
|
57
|
+
].filter(Boolean);
|
|
58
|
+
const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
|
|
59
|
+
const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
|
|
60
|
+
const jsChunkStr = jsAssets.filter((asset)=>!template.includes(asset)).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
|
|
61
|
+
if (jsChunkStr) return (0, external_utils_js_namespaceObject.safeReplace)(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
|
|
59
62
|
return template;
|
|
60
63
|
}
|
|
61
64
|
return (0, external_shared_js_namespaceObject.buildHtml)(afterAppTemplate, callbacks);
|
|
@@ -40,6 +40,7 @@ const external_react_helmet_namespaceObject = require("react-helmet");
|
|
|
40
40
|
var external_react_helmet_default = /*#__PURE__*/ __webpack_require__.n(external_react_helmet_namespaceObject);
|
|
41
41
|
const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
|
|
42
42
|
const external_constants_js_namespaceObject = require("../constants.js");
|
|
43
|
+
const external_federatedCss_js_namespaceObject = require("../federatedCss.js");
|
|
43
44
|
const external_helmet_js_namespaceObject = require("../helmet.js");
|
|
44
45
|
const external_shared_js_namespaceObject = require("../shared.js");
|
|
45
46
|
const external_utils_js_namespaceObject = require("../utils.js");
|
|
@@ -55,7 +56,7 @@ const checkIsInline = (chunk, enableInline)=>{
|
|
|
55
56
|
return Boolean(enableInline);
|
|
56
57
|
};
|
|
57
58
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
58
|
-
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
59
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
59
60
|
const helmetData = external_react_helmet_default().renderStatic();
|
|
60
61
|
const callbacks = [
|
|
61
62
|
(0, external_helmet_js_namespaceObject.createReplaceHelemt)(helmetData),
|
|
@@ -65,33 +66,36 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
|
65
66
|
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
66
67
|
let css = await getCssChunks();
|
|
67
68
|
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
69
|
+
css += (0, external_federatedCss_js_namespaceObject.createFederatedCssLinks)(moduleFederationCssAssets, {
|
|
70
|
+
template,
|
|
71
|
+
existingAssets: css.match(/href="([^"]+)"/g)?.map((item)=>item.replace(/^href="/, '').replace(/"$/, ''))
|
|
72
|
+
});
|
|
68
73
|
return (0, external_utils_js_namespaceObject.safeReplace)(template, external_constants_js_namespaceObject.CHUNK_CSS_PLACEHOLDER, css);
|
|
69
74
|
async function getCssChunks() {
|
|
70
75
|
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
71
76
|
if (!routeManifest) return '';
|
|
72
77
|
const { routeAssets } = routeManifest;
|
|
73
|
-
let matchedRouteManifests;
|
|
78
|
+
let matchedRouteManifests = [];
|
|
74
79
|
const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext);
|
|
75
80
|
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
76
|
-
else {
|
|
77
|
-
if (!routerContext || !routes) return '';
|
|
81
|
+
else if (routerContext && routes) {
|
|
78
82
|
const matches = (0, router_namespaceObject.matchRoutes)(routes, routerContext.location, routerContext.basename);
|
|
79
83
|
matchedRouteManifests = matches?.map((match, index)=>{
|
|
80
84
|
if (!index) return;
|
|
81
85
|
const routeId = match.route.id;
|
|
82
86
|
if (routeId) return routeAssets[routeId];
|
|
83
|
-
}).filter(Boolean);
|
|
87
|
+
}).filter(Boolean) ?? [];
|
|
84
88
|
}
|
|
85
89
|
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
86
|
-
if (asyncEntry) matchedRouteManifests
|
|
87
|
-
const cssChunks = matchedRouteManifests
|
|
90
|
+
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
91
|
+
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
88
92
|
const { referenceCssAssets = [] } = routeManifest;
|
|
89
93
|
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
90
94
|
return [
|
|
91
95
|
...chunks,
|
|
92
96
|
..._cssChunks
|
|
93
97
|
];
|
|
94
|
-
}, [])
|
|
98
|
+
}, []);
|
|
95
99
|
const { inlineStyles } = config;
|
|
96
100
|
const styles = await Promise.all(cssChunks.map(async (chunk)=>{
|
|
97
101
|
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
buildShellBeforeTemplate: ()=>buildShellBeforeTemplate
|
|
37
|
+
});
|
|
38
|
+
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
39
|
+
const external_react_helmet_namespaceObject = require("react-helmet");
|
|
40
|
+
var external_react_helmet_default = /*#__PURE__*/ __webpack_require__.n(external_react_helmet_namespaceObject);
|
|
41
|
+
const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
|
|
42
|
+
const external_constants_js_namespaceObject = require("../constants.js");
|
|
43
|
+
const external_federatedCss_js_namespaceObject = require("../federatedCss.js");
|
|
44
|
+
const external_helmet_js_namespaceObject = require("../helmet.js");
|
|
45
|
+
const external_shared_js_namespaceObject = require("../shared.js");
|
|
46
|
+
const external_utils_js_namespaceObject = require("../utils.js");
|
|
47
|
+
const checkIsInline = (chunk, enableInline)=>{
|
|
48
|
+
if ('production' !== process.env.NODE_ENV) return false;
|
|
49
|
+
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
50
|
+
return Boolean(enableInline);
|
|
51
|
+
};
|
|
52
|
+
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
53
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName, moduleFederationCssAssets } = options;
|
|
54
|
+
const helmetData = external_react_helmet_default().renderStatic();
|
|
55
|
+
const callbacks = [
|
|
56
|
+
(0, external_helmet_js_namespaceObject.createReplaceHelemt)(helmetData),
|
|
57
|
+
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
58
|
+
];
|
|
59
|
+
return (0, external_shared_js_namespaceObject.buildHtml)(beforeAppTemplate, callbacks);
|
|
60
|
+
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
61
|
+
let css = await getCssChunks();
|
|
62
|
+
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
63
|
+
css += (0, external_federatedCss_js_namespaceObject.createFederatedCssLinks)(moduleFederationCssAssets, {
|
|
64
|
+
template,
|
|
65
|
+
existingAssets: css.match(/href="([^"]+)"/g)?.map((item)=>item.replace(/^href="/, '').replace(/"$/, ''))
|
|
66
|
+
});
|
|
67
|
+
return (0, external_utils_js_namespaceObject.safeReplace)(template, external_constants_js_namespaceObject.CHUNK_CSS_PLACEHOLDER, css);
|
|
68
|
+
async function getCssChunks() {
|
|
69
|
+
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
70
|
+
if (!routeManifest) return '';
|
|
71
|
+
const { routeAssets } = routeManifest;
|
|
72
|
+
let matchedRouteManifests = [];
|
|
73
|
+
const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext);
|
|
74
|
+
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
75
|
+
else if (routerContext && routes) {
|
|
76
|
+
const matches = (0, router_namespaceObject.matchRoutes)(routes, routerContext.location, routerContext.basename);
|
|
77
|
+
matchedRouteManifests = matches?.map((match, index)=>{
|
|
78
|
+
if (!index) return;
|
|
79
|
+
const routeId = match.route.id;
|
|
80
|
+
if (routeId) return routeAssets[routeId];
|
|
81
|
+
}).filter(Boolean) ?? [];
|
|
82
|
+
}
|
|
83
|
+
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
84
|
+
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
85
|
+
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
86
|
+
const { referenceCssAssets = [] } = routeManifest;
|
|
87
|
+
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
88
|
+
return [
|
|
89
|
+
...chunks,
|
|
90
|
+
..._cssChunks
|
|
91
|
+
];
|
|
92
|
+
}, []);
|
|
93
|
+
const { inlineStyles } = config;
|
|
94
|
+
const styles = cssChunks.map((chunk)=>{
|
|
95
|
+
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
96
|
+
checkIsInline(chunk, inlineStyles);
|
|
97
|
+
return link;
|
|
98
|
+
});
|
|
99
|
+
return `${styles.join('')}`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.buildShellBeforeTemplate = __webpack_exports__.buildShellBeforeTemplate;
|
|
104
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
105
|
+
"buildShellBeforeTemplate"
|
|
106
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
107
|
+
Object.defineProperty(exports, '__esModule', {
|
|
108
|
+
value: true
|
|
109
|
+
});
|
|
@@ -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);
|
|
@@ -80,6 +80,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
80
80
|
runtimeContext,
|
|
81
81
|
config,
|
|
82
82
|
entryName,
|
|
83
|
+
moduleFederationCssAssets,
|
|
83
84
|
styledComponentsStyleTags
|
|
84
85
|
}).then(({ shellAfter, shellBefore })=>{
|
|
85
86
|
const pendingScripts = [];
|
|
@@ -137,7 +138,8 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
137
138
|
renderLevel,
|
|
138
139
|
runtimeContext,
|
|
139
140
|
entryName,
|
|
140
|
-
config
|
|
141
|
+
config,
|
|
142
|
+
moduleFederationCssAssets
|
|
141
143
|
}).then(({ shellAfter, shellBefore })=>{
|
|
142
144
|
const fallbackHtml = `${shellBefore}${shellAfter}`;
|
|
143
145
|
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) {
|