@bleedingdev/modern-js-runtime 3.9.0-ultramodern.3 → 3.9.0-ultramodern.5

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.
Files changed (160) hide show
  1. package/dist/cjs/cli/code.js +3 -1
  2. package/dist/cjs/cli/ssr/index.js +2 -74
  3. package/dist/cjs/core/browser/hydrate.js +6 -1
  4. package/dist/cjs/core/context/index.js +4 -43
  5. package/dist/cjs/core/context/public.js +4 -7
  6. package/dist/cjs/core/context/runtime.js +17 -5
  7. package/dist/cjs/core/react/wrapper.js +22 -65
  8. package/dist/cjs/core/server/helmet.js +5 -4
  9. package/dist/cjs/core/server/requestResponse.js +4 -4
  10. package/dist/cjs/core/server/routerCleanup.js +2 -2
  11. package/dist/cjs/core/server/shared.js +171 -4
  12. package/dist/cjs/core/server/stream/afterTemplate.js +21 -16
  13. package/dist/cjs/core/server/stream/beforeTemplate.js +34 -25
  14. package/dist/cjs/core/server/stream/beforeTemplate.worker.js +28 -21
  15. package/dist/cjs/core/server/stream/createReadableStream.js +208 -123
  16. package/dist/cjs/core/server/stream/createReadableStream.worker.js +159 -90
  17. package/dist/cjs/core/server/stream/deferredScript.js +3 -3
  18. package/dist/cjs/core/server/stream/shared.js +2 -2
  19. package/dist/cjs/core/server/string/index.js +100 -64
  20. package/dist/cjs/core/server/string/loadable.js +34 -19
  21. package/dist/cjs/core/server/string/ssrData.js +5 -12
  22. package/dist/cjs/core/server/utils.js +1 -2
  23. package/dist/cjs/exports/head.js +7 -14
  24. package/dist/cjs/router/runtime/PrefetchLink.js +67 -123
  25. package/dist/cjs/router/runtime/hooks.js +13 -2
  26. package/dist/cjs/router/runtime/internal.js +7 -45
  27. package/dist/cjs/router/runtime/plugin.js +2 -8
  28. package/dist/cjs/router/runtime/plugin.node.js +2 -30
  29. package/dist/cjs/router/runtime/redirect.js +1 -1
  30. package/dist/esm/cli/code.mjs +3 -1
  31. package/dist/esm/cli/ssr/index.mjs +3 -72
  32. package/dist/esm/core/browser/hydrate.mjs +7 -2
  33. package/dist/esm/core/context/index.mjs +2 -5
  34. package/dist/esm/core/context/public.mjs +1 -5
  35. package/dist/esm/core/context/runtime.mjs +13 -4
  36. package/dist/esm/core/react/wrapper.mjs +21 -67
  37. package/dist/esm/core/server/helmet.mjs +5 -4
  38. package/dist/esm/core/server/requestResponse.mjs +3 -3
  39. package/dist/esm/core/server/routerCleanup.mjs +1 -1
  40. package/dist/esm/core/server/shared.mjs +153 -1
  41. package/dist/esm/core/server/stream/afterTemplate.mjs +23 -18
  42. package/dist/esm/core/server/stream/beforeTemplate.mjs +37 -28
  43. package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +31 -24
  44. package/dist/esm/core/server/stream/createReadableStream.mjs +207 -122
  45. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +149 -90
  46. package/dist/esm/core/server/stream/deferredScript.mjs +3 -3
  47. package/dist/esm/core/server/stream/shared.mjs +2 -2
  48. package/dist/esm/core/server/string/index.mjs +104 -68
  49. package/dist/esm/core/server/string/loadable.mjs +34 -19
  50. package/dist/esm/core/server/string/ssrData.mjs +5 -12
  51. package/dist/esm/core/server/utils.mjs +1 -2
  52. package/dist/esm/exports/head.mjs +7 -14
  53. package/dist/esm/router/runtime/PrefetchLink.mjs +67 -123
  54. package/dist/esm/router/runtime/hooks.mjs +9 -1
  55. package/dist/esm/router/runtime/internal.mjs +2 -33
  56. package/dist/esm/router/runtime/plugin.mjs +1 -7
  57. package/dist/esm/router/runtime/plugin.node.mjs +1 -29
  58. package/dist/esm/router/runtime/redirect.mjs +1 -1
  59. package/dist/esm-node/cli/code.mjs +3 -1
  60. package/dist/esm-node/cli/ssr/index.mjs +3 -72
  61. package/dist/esm-node/core/browser/hydrate.mjs +7 -2
  62. package/dist/esm-node/core/context/index.mjs +2 -5
  63. package/dist/esm-node/core/context/public.mjs +1 -5
  64. package/dist/esm-node/core/context/runtime.mjs +13 -4
  65. package/dist/esm-node/core/react/wrapper.mjs +21 -67
  66. package/dist/esm-node/core/server/helmet.mjs +5 -4
  67. package/dist/esm-node/core/server/requestResponse.mjs +3 -3
  68. package/dist/esm-node/core/server/routerCleanup.mjs +1 -1
  69. package/dist/esm-node/core/server/shared.mjs +153 -1
  70. package/dist/esm-node/core/server/stream/afterTemplate.mjs +23 -18
  71. package/dist/esm-node/core/server/stream/beforeTemplate.mjs +37 -28
  72. package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +31 -24
  73. package/dist/esm-node/core/server/stream/createReadableStream.mjs +207 -122
  74. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +149 -90
  75. package/dist/esm-node/core/server/stream/deferredScript.mjs +3 -3
  76. package/dist/esm-node/core/server/stream/shared.mjs +2 -2
  77. package/dist/esm-node/core/server/string/index.mjs +104 -68
  78. package/dist/esm-node/core/server/string/loadable.mjs +34 -19
  79. package/dist/esm-node/core/server/string/ssrData.mjs +5 -12
  80. package/dist/esm-node/core/server/utils.mjs +1 -2
  81. package/dist/esm-node/exports/head.mjs +7 -14
  82. package/dist/esm-node/router/runtime/PrefetchLink.mjs +67 -123
  83. package/dist/esm-node/router/runtime/hooks.mjs +9 -1
  84. package/dist/esm-node/router/runtime/internal.mjs +2 -33
  85. package/dist/esm-node/router/runtime/plugin.mjs +1 -7
  86. package/dist/esm-node/router/runtime/plugin.node.mjs +1 -29
  87. package/dist/esm-node/router/runtime/redirect.mjs +1 -1
  88. package/dist/types/cli/ssr/index.d.ts +0 -3
  89. package/dist/types/core/context/index.d.ts +4 -6
  90. package/dist/types/core/context/public.d.ts +1 -23
  91. package/dist/types/core/context/runtime.d.ts +26 -2
  92. package/dist/types/core/react/wrapper.d.ts +6 -0
  93. package/dist/types/core/server/helmet.d.ts +4 -5
  94. package/dist/types/core/server/shared.d.ts +23 -0
  95. package/dist/types/core/server/stream/afterTemplate.d.ts +2 -1
  96. package/dist/types/core/server/stream/beforeTemplate.d.ts +4 -1
  97. package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +4 -1
  98. package/dist/types/core/server/stream/shared.d.ts +1 -1
  99. package/dist/types/core/server/string/loadable.d.ts +6 -3
  100. package/dist/types/core/server/string/ssrData.d.ts +2 -1
  101. package/dist/types/core/server/string/types.d.ts +1 -5
  102. package/dist/types/exports/head.d.ts +2 -2
  103. package/dist/types/router/runtime/PrefetchLink.d.ts +27 -2
  104. package/dist/types/router/runtime/hooks.d.ts +19 -2
  105. package/dist/types/router/runtime/internal.d.ts +4 -21
  106. package/dist/types/router/runtime/types.d.ts +2 -43
  107. package/package.json +9 -38
  108. package/rstest.config.mts +32 -2
  109. package/dist/cjs/boundary-debugger/index.js +0 -317
  110. package/dist/cjs/core/context/extensions.js +0 -74
  111. package/dist/cjs/core/context/helmetContext.js +0 -54
  112. package/dist/cjs/core/server/federatedCss.js +0 -58
  113. package/dist/cjs/core/server/scriptOrder.js +0 -140
  114. package/dist/cjs/module-federation/consume-surface.js +0 -199
  115. package/dist/cjs/module-federation/distributed-ssr.js +0 -135
  116. package/dist/cjs/module-federation/index.js +0 -316
  117. package/dist/cjs/module-federation/last-known-good.js +0 -157
  118. package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +0 -129
  119. package/dist/cjs/module-federation/surface-resolution-types.js +0 -61
  120. package/dist/cjs/router/runtime/lifecycle.js +0 -167
  121. package/dist/cjs/router/runtime/provider.js +0 -153
  122. package/dist/esm/boundary-debugger/index.mjs +0 -277
  123. package/dist/esm/core/context/extensions.mjs +0 -33
  124. package/dist/esm/core/context/helmetContext.mjs +0 -13
  125. package/dist/esm/core/server/federatedCss.mjs +0 -20
  126. package/dist/esm/core/server/scriptOrder.mjs +0 -90
  127. package/dist/esm/module-federation/consume-surface.mjs +0 -158
  128. package/dist/esm/module-federation/distributed-ssr.mjs +0 -82
  129. package/dist/esm/module-federation/index.mjs +0 -115
  130. package/dist/esm/module-federation/last-known-good.mjs +0 -113
  131. package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +0 -89
  132. package/dist/esm/module-federation/surface-resolution-types.mjs +0 -8
  133. package/dist/esm/router/runtime/lifecycle.mjs +0 -105
  134. package/dist/esm/router/runtime/provider.mjs +0 -100
  135. package/dist/esm-node/boundary-debugger/index.mjs +0 -278
  136. package/dist/esm-node/core/context/extensions.mjs +0 -34
  137. package/dist/esm-node/core/context/helmetContext.mjs +0 -14
  138. package/dist/esm-node/core/server/federatedCss.mjs +0 -21
  139. package/dist/esm-node/core/server/scriptOrder.mjs +0 -91
  140. package/dist/esm-node/module-federation/consume-surface.mjs +0 -159
  141. package/dist/esm-node/module-federation/distributed-ssr.mjs +0 -83
  142. package/dist/esm-node/module-federation/index.mjs +0 -116
  143. package/dist/esm-node/module-federation/last-known-good.mjs +0 -114
  144. package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +0 -90
  145. package/dist/esm-node/module-federation/surface-resolution-types.mjs +0 -9
  146. package/dist/esm-node/router/runtime/lifecycle.mjs +0 -106
  147. package/dist/esm-node/router/runtime/provider.mjs +0 -101
  148. package/dist/types/boundary-debugger/index.d.ts +0 -28
  149. package/dist/types/core/context/extensions.d.ts +0 -35
  150. package/dist/types/core/context/helmetContext.d.ts +0 -10
  151. package/dist/types/core/server/federatedCss.d.ts +0 -5
  152. package/dist/types/core/server/scriptOrder.d.ts +0 -25
  153. package/dist/types/module-federation/consume-surface.d.ts +0 -104
  154. package/dist/types/module-federation/distributed-ssr.d.ts +0 -61
  155. package/dist/types/module-federation/index.d.ts +0 -71
  156. package/dist/types/module-federation/last-known-good.d.ts +0 -52
  157. package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +0 -25
  158. package/dist/types/module-federation/surface-resolution-types.d.ts +0 -23
  159. package/dist/types/router/runtime/lifecycle.d.ts +0 -27
  160. package/dist/types/router/runtime/provider.d.ts +0 -78
@@ -1,278 +0,0 @@
1
- import "node:module";
2
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { useEffect, useMemo, useState } from "react";
4
- const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
5
- const queryParamName = 'modern-boundaries';
6
- const boundarySelector = '[data-modern-boundary-id]';
7
- const defaultLabels = {
8
- cs: {
9
- toggle: 'zobrazit hranice týmů'
10
- },
11
- en: {
12
- toggle: 'show team boundaries'
13
- }
14
- };
15
- const palette = [
16
- '#ff5a5f',
17
- '#30e27a',
18
- '#f6cf45',
19
- '#7c8cff',
20
- '#29b6f6'
21
- ];
22
- const readStoredEnabled = (storageKey, fallback)=>{
23
- if ("u" < typeof window) return fallback;
24
- try {
25
- const stored = window.localStorage.getItem(storageKey);
26
- return null === stored ? fallback : 'true' === stored;
27
- } catch {
28
- return fallback;
29
- }
30
- };
31
- const writeStoredEnabled = (storageKey, enabled)=>{
32
- if ("u" < typeof window) return;
33
- try {
34
- window.localStorage.setItem(storageKey, String(enabled));
35
- } catch {}
36
- };
37
- const parseEnabledOverride = (value)=>{
38
- if (null === value) return;
39
- const normalized = value.toLowerCase();
40
- if ('1' === normalized || 'true' === normalized) return true;
41
- if ('0' === normalized || 'false' === normalized) return false;
42
- };
43
- const readQueryEnabledOverride = ()=>{
44
- if ("u" < typeof window) return;
45
- try {
46
- return parseEnabledOverride(new URLSearchParams(window.location.search).get(queryParamName));
47
- } catch {
48
- return;
49
- }
50
- };
51
- const detectLanguage = ()=>{
52
- if ("u" < typeof document) return 'en';
53
- const htmlLanguage = document.documentElement.lang;
54
- if ('' !== htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
55
- if ("u" < typeof window) return 'en';
56
- return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
57
- };
58
- const hashBoundaryId = (id)=>{
59
- let hash = 0;
60
- for(let index = 0; index < id.length; index++)hash = 31 * hash + id.charCodeAt(index) >>> 0;
61
- return hash;
62
- };
63
- const formatRectKey = (rect)=>[
64
- Math.round(100 * rect.left) / 100,
65
- Math.round(100 * rect.top) / 100,
66
- Math.round(100 * rect.width) / 100,
67
- Math.round(100 * rect.height) / 100
68
- ].join(':');
69
- const getBoundaryId = (element)=>element.dataset.modernBoundaryId ?? element.dataset.mfRemote ?? element.getAttribute('data-mf-remote') ?? void 0;
70
- const collectBoundaryElements = (legacySelector)=>{
71
- const elements = new Set();
72
- for (const element of document.querySelectorAll(boundarySelector))elements.add(element);
73
- if (void 0 === legacySelector || '' === legacySelector) return Array.from(elements);
74
- try {
75
- for (const element of document.querySelectorAll(legacySelector))elements.add(element);
76
- } catch {}
77
- return Array.from(elements);
78
- };
79
- function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, labels = defaultLabels, legacySelector, metadata, storageKey = defaultStorageKey }) {
80
- const [mounted, setMounted] = useState(false);
81
- const [enabled, setEnabled] = useState(false);
82
- const [boxes, setBoxes] = useState([]);
83
- const boundaries = useMemo(()=>new Map(metadata.boundaries.map((entry, index)=>[
84
- entry.mfName,
85
- {
86
- ...entry,
87
- color: entry.color ?? palette[index % palette.length],
88
- label: entry.label ?? entry.appId
89
- }
90
- ])), [
91
- metadata
92
- ]);
93
- const language = mounted ? detectLanguage() : 'en';
94
- const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show team boundaries';
95
- useEffect(()=>{
96
- setMounted(true);
97
- const queryOverride = readQueryEnabledOverride();
98
- setEnabled(queryOverride ?? readStoredEnabled(storageKey, enabledByDefault));
99
- }, [
100
- enabledByDefault,
101
- storageKey
102
- ]);
103
- useEffect(()=>{
104
- if (!mounted) return;
105
- writeStoredEnabled(storageKey, enabled);
106
- }, [
107
- enabled,
108
- mounted,
109
- storageKey
110
- ]);
111
- useEffect(()=>{
112
- if (!enabled) return void setBoxes([]);
113
- let resizeObserver;
114
- const observedElements = new Set();
115
- const observeBoundaryElements = (elements)=>{
116
- if (void 0 === resizeObserver) return;
117
- for (const element of elements)if (!observedElements.has(element)) {
118
- observedElements.add(element);
119
- resizeObserver.observe(element);
120
- }
121
- };
122
- const readBoxes = ()=>{
123
- const elements = collectBoundaryElements(legacySelector);
124
- observeBoundaryElements(elements);
125
- const seenBoxes = new Set();
126
- const nextBoxes = elements.map((element)=>{
127
- const boundaryId = getBoundaryId(element);
128
- if (void 0 === boundaryId || '' === boundaryId) return;
129
- const rect = element.getBoundingClientRect();
130
- if (rect.width <= 0 || rect.height <= 0) return;
131
- const rectKey = formatRectKey(rect);
132
- const boxKey = `${boundaryId}:${rectKey}`;
133
- if (seenBoxes.has(boxKey)) return;
134
- seenBoxes.add(boxKey);
135
- const boundary = boundaries.get(boundaryId);
136
- const color = boundary?.color ?? palette[hashBoundaryId(boundaryId) % palette.length];
137
- const label = boundary?.label ?? boundary?.appId ?? boundaryId;
138
- const expose = element.dataset.modernMfExpose;
139
- const detail = void 0 !== expose && '' !== expose && expose !== label && expose !== boundaryId ? expose : void 0;
140
- const box = {
141
- color,
142
- height: rect.height,
143
- id: boxKey,
144
- label,
145
- left: rect.left,
146
- top: rect.top,
147
- width: rect.width
148
- };
149
- if (void 0 !== detail) box.detail = detail;
150
- return box;
151
- }).filter((box)=>void 0 !== box);
152
- setBoxes(nextBoxes);
153
- };
154
- resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
155
- readBoxes();
156
- const mutationObserver = new MutationObserver(readBoxes);
157
- mutationObserver.observe(document.body, {
158
- childList: true,
159
- subtree: true
160
- });
161
- window.addEventListener('resize', readBoxes);
162
- window.addEventListener('scroll', readBoxes, true);
163
- return ()=>{
164
- mutationObserver.disconnect();
165
- resizeObserver?.disconnect();
166
- window.removeEventListener('resize', readBoxes);
167
- window.removeEventListener('scroll', readBoxes, true);
168
- };
169
- }, [
170
- boundaries,
171
- enabled,
172
- legacySelector
173
- ]);
174
- if (!mounted) return null;
175
- const shouldRenderToggle = 'visible' === controlMode || 'hidden-when-off' === controlMode && enabled;
176
- return /*#__PURE__*/ jsxs(Fragment, {
177
- children: [
178
- shouldRenderToggle ? /*#__PURE__*/ jsxs("label", {
179
- style: {
180
- alignItems: 'center',
181
- background: 'rgba(255, 255, 255, 0.96)',
182
- border: '1px solid rgba(0, 0, 0, 0.1)',
183
- borderRadius: 10,
184
- boxShadow: '0 10px 28px rgba(0, 0, 0, 0.14)',
185
- color: '#111827',
186
- display: 'flex',
187
- font: '600 13px/1.2 system-ui, sans-serif',
188
- gap: 8,
189
- left: 'max(12px, env(safe-area-inset-left))',
190
- maxWidth: 'calc(100vw - 24px)',
191
- padding: '9px 11px',
192
- position: 'fixed',
193
- top: 'max(12px, env(safe-area-inset-top))',
194
- zIndex: 2147483000
195
- },
196
- children: [
197
- /*#__PURE__*/ jsx("input", {
198
- checked: enabled,
199
- onChange: (event)=>setEnabled(event.currentTarget.checked),
200
- type: "checkbox"
201
- }),
202
- /*#__PURE__*/ jsx("span", {
203
- children: toggleLabel
204
- })
205
- ]
206
- }) : null,
207
- enabled ? /*#__PURE__*/ jsx("div", {
208
- "aria-hidden": "true",
209
- children: boxes.map((box)=>/*#__PURE__*/ jsx("div", {
210
- "data-modern-boundary-overlay": "",
211
- "data-modern-boundary-overlay-id": box.id,
212
- "data-modern-boundary-overlay-label": box.label,
213
- style: {
214
- border: `2px solid ${box.color}`,
215
- borderRadius: 8,
216
- boxSizing: 'border-box',
217
- boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
218
- height: box.height,
219
- left: box.left,
220
- pointerEvents: 'none',
221
- position: 'fixed',
222
- top: box.top,
223
- width: box.width,
224
- zIndex: 2147482999
225
- },
226
- children: /*#__PURE__*/ jsxs("span", {
227
- style: {
228
- background: box.color,
229
- borderRadius: 999,
230
- color: '#111827',
231
- display: 'grid',
232
- font: '800 11px/1.1 system-ui, sans-serif',
233
- gap: 3,
234
- maxWidth: 'min(280px, calc(100vw - 24px))',
235
- padding: '5px 8px',
236
- position: 'absolute',
237
- right: 4,
238
- top: 4,
239
- whiteSpace: 'nowrap'
240
- },
241
- children: [
242
- /*#__PURE__*/ jsx("span", {
243
- children: box.label
244
- }),
245
- void 0 !== box.detail && '' !== box.detail ? /*#__PURE__*/ jsx("span", {
246
- style: {
247
- font: '700 10px/1.1 system-ui, sans-serif',
248
- opacity: 0.82,
249
- overflow: 'hidden',
250
- textOverflow: 'ellipsis'
251
- },
252
- children: box.detail
253
- }) : null
254
- ]
255
- })
256
- }, box.id))
257
- }) : null
258
- ]
259
- });
260
- }
261
- const ultramodernBoundaryDebuggerPlugin = (options)=>({
262
- name: '@modern-js/runtime/boundary-debugger',
263
- setup: (api)=>{
264
- api.wrapRoot((App)=>(props)=>/*#__PURE__*/ jsxs(Fragment, {
265
- children: [
266
- /*#__PURE__*/ jsx(App, {
267
- ...props
268
- }),
269
- /*#__PURE__*/ jsx(BoundaryDebugger, {
270
- ...options
271
- })
272
- ]
273
- }));
274
- }
275
- });
276
- const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
277
- export default boundary_debugger;
278
- export { ultramodernBoundaryDebuggerPlugin };
@@ -1,34 +0,0 @@
1
- import "node:module";
2
- const EXTENSIONS_SLOT = Symbol.for('@modern-js/runtime:context-extensions');
3
- function getStore(context) {
4
- return context[EXTENSIONS_SLOT];
5
- }
6
- function ensureStore(context) {
7
- const target = context;
8
- const store = target[EXTENSIONS_SLOT] ?? new Map();
9
- Object.defineProperty(target, EXTENSIONS_SLOT, {
10
- configurable: true,
11
- enumerable: true,
12
- value: store
13
- });
14
- return store;
15
- }
16
- function stripRuntimeContextExtensions(context) {
17
- delete context[EXTENSIONS_SLOT];
18
- }
19
- function createRuntimeContextExtension(id) {
20
- const key = Symbol.for(`@modern-js/runtime:context-extension:${id}`);
21
- return {
22
- key,
23
- get (context) {
24
- return getStore(context)?.get(key);
25
- },
26
- set (context, value) {
27
- ensureStore(context).set(key, value);
28
- },
29
- remove (context) {
30
- getStore(context)?.delete(key);
31
- }
32
- };
33
- }
34
- export { createRuntimeContextExtension, stripRuntimeContextExtensions };
@@ -1,14 +0,0 @@
1
- import "node:module";
2
- import { createRuntimeContextExtension } from "./extensions.mjs";
3
- const helmetContextExtension = createRuntimeContextExtension('@modern-js/runtime:helmet-context');
4
- function getHelmetContext(context) {
5
- return helmetContextExtension.get(context);
6
- }
7
- function ensureHelmetContext(context) {
8
- const existing = helmetContextExtension.get(context);
9
- if (void 0 !== existing) return existing;
10
- const created = {};
11
- helmetContextExtension.set(context, created);
12
- return created;
13
- }
14
- export { ensureHelmetContext, getHelmetContext };
@@ -1,21 +0,0 @@
1
- import "node:module";
2
- import { escapeHtmlAttribute } from "@modern-js/runtime-extensions";
3
- import { attributesToString, hasStylesheetLink } from "./utils.mjs";
4
- const createFederatedCssLinks = (assets, options)=>{
5
- if (void 0 === assets || 0 === assets.length) return '';
6
- const seen = new Set(options.existingAssets || []);
7
- const attributes = attributesToString(Object.fromEntries(Object.entries(options.attributes || {}).filter(([name])=>![
8
- 'href',
9
- 'rel'
10
- ].includes(name.toLowerCase()))));
11
- const links = [];
12
- for (const asset of assets){
13
- const href = escapeHtmlAttribute(asset);
14
- if (!('' === asset || seen.has(asset) || hasStylesheetLink(options.template, asset) || hasStylesheetLink(options.template, href))) {
15
- seen.add(asset);
16
- links.push(`<link${attributes} href="${href}" rel="stylesheet" />`);
17
- }
18
- }
19
- return links.join('');
20
- };
21
- export { createFederatedCssLinks };
@@ -1,91 +0,0 @@
1
- import "node:module";
2
- import { getRouterMatchedRouteIds } from "../../router/runtime/lifecycle.mjs";
3
- import { CHUNK_JS_PLACEHOLDER } from "./constants.mjs";
4
- import { attributesToString, safeReplace } from "./utils.mjs";
5
- function getScriptTags(template) {
6
- const scriptRegExp = /<script\b[^>]*\bsrc=(["'])(.*?)\1[^>]*><\/script>/g;
7
- return Array.from(template.matchAll(scriptRegExp)).map((match)=>({
8
- index: match.index ?? 0,
9
- tag: match[0],
10
- src: match[2]
11
- }));
12
- }
13
- function getAssetBasename(src) {
14
- const withoutQuery = src.split(/[?#]/)[0];
15
- return withoutQuery.split('/').pop() || withoutQuery;
16
- }
17
- function isEntryScript(src, entryName, asyncEntry) {
18
- const basename = getAssetBasename(src);
19
- const prefix = asyncEntry ? `async-${entryName}` : entryName;
20
- return basename === `${prefix}.js` || basename.startsWith(`${prefix}.`) || basename.startsWith(`${prefix}-`);
21
- }
22
- const dedupeByUrl = (chunks)=>{
23
- const seen = new Set();
24
- return chunks.filter((chunk)=>{
25
- if (void 0 === chunk.url || '' === chunk.url || seen.has(chunk.url)) return false;
26
- seen.add(chunk.url);
27
- return true;
28
- });
29
- };
30
- const isAsyncEntryScriptChunk = (chunk, entryName)=>{
31
- if (void 0 === chunk.url || !chunk.url.endsWith('.js')) return false;
32
- const asyncEntryName = `async-${entryName}`;
33
- const filename = chunk.filename ?? chunk.url;
34
- const basename = filename.split('/').pop() ?? filename;
35
- return basename === `${asyncEntryName}.js` || basename.startsWith(`${asyncEntryName}.`) || basename.startsWith(`${asyncEntryName}-`);
36
- };
37
- function getRouteAssets(runtimeContext, routeManifest = runtimeContext.routeManifest) {
38
- return routeManifest?.routeAssets;
39
- }
40
- function getMatchedRouteAssets(runtimeContext, routeManifest) {
41
- const routeAssets = getRouteAssets(runtimeContext, routeManifest);
42
- if (void 0 === routeAssets) return [];
43
- const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
44
- return matchedRouteIds.flatMap((routeId)=>routeAssets[routeId]?.assets ?? []);
45
- }
46
- function getMatchedRouteChunks(runtimeContext, routeManifest, routeAssetToChunk) {
47
- if (void 0 === routeManifest) return [];
48
- return getMatchedRouteAssets(runtimeContext, routeManifest).map(routeAssetToChunk);
49
- }
50
- const orderHydrationScriptChunks = ({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName })=>{
51
- const asyncEntryScriptChunks = [];
52
- const asyncEntryDependencyChunks = [];
53
- for (const chunk of asyncEntryChunks)if (isAsyncEntryScriptChunk(chunk, entryName)) asyncEntryScriptChunks.push(chunk);
54
- else asyncEntryDependencyChunks.push(chunk);
55
- return dedupeByUrl([
56
- ...asyncEntryDependencyChunks,
57
- ...collectedChunks,
58
- ...matchedRouteChunks,
59
- ...asyncEntryScriptChunks
60
- ]);
61
- };
62
- function injectBeforeHydrationEntryScript(template, scripts, entryName = 'index') {
63
- if ('' === scripts) return template;
64
- const scriptTags = getScriptTags(template);
65
- const target = scriptTags.find((match)=>isEntryScript(match.src, entryName, false)) ?? scriptTags.find((match)=>isEntryScript(match.src, entryName, true));
66
- if (void 0 === target) return template;
67
- return `${template.slice(0, target.index)}${scripts}${template.slice(target.index)}`;
68
- }
69
- function replaceChunkJsPlaceholder(template, scripts, entryName, placeholder = CHUNK_JS_PLACEHOLDER) {
70
- if (!template.includes(placeholder)) return template;
71
- if ('' === scripts) return safeReplace(template, placeholder, '');
72
- const withoutPlaceholder = safeReplace(template, placeholder, '');
73
- const withEarlyScripts = injectBeforeHydrationEntryScript(withoutPlaceholder, scripts, entryName);
74
- if (withEarlyScripts !== withoutPlaceholder) return withEarlyScripts;
75
- return safeReplace(template, placeholder, scripts);
76
- }
77
- function createRouteHydrationScriptTags(runtimeContext, entryName, options = {}) {
78
- const { nonce, template } = options;
79
- const routeAssets = getRouteAssets(runtimeContext);
80
- if (void 0 === routeAssets) return '';
81
- const existingScriptSrcs = void 0 === template ? new Set() : new Set(getScriptTags(template).map(({ src })=>src));
82
- const jsAssets = Array.from(new Set([
83
- ...getMatchedRouteAssets(runtimeContext),
84
- ...routeAssets[`async-${entryName}`]?.assets ?? []
85
- ].filter((asset)=>asset.endsWith('.js'))));
86
- return jsAssets.filter((asset)=>!existingScriptSrcs.has(asset)).map((asset)=>`<script${attributesToString({
87
- src: asset,
88
- nonce: nonce || void 0
89
- })}></script>`).join(' ');
90
- }
91
- export { createRouteHydrationScriptTags, getMatchedRouteChunks, injectBeforeHydrationEntryScript, orderHydrationScriptChunks, replaceChunkJsPlaceholder };
@@ -1,159 +0,0 @@
1
- import "node:module";
2
- import { classifyModuleFederationFallback, createModuleFederationFallbackTelemetry, emitModuleFederationFallbackTelemetry } from "./index.mjs";
3
- import { createDiscoveryError, formatSurfaceRef, parseSurfaceRef, validateSurfaceRef } from "./surface-resolution-types.mjs";
4
- function classifyDiscoveryError(code) {
5
- switch(code){
6
- case 'major-not-published':
7
- case 'stale-record':
8
- return 'version-skew';
9
- case 'identity-mismatch':
10
- return 'contract';
11
- case 'unknown-unit':
12
- case 'unknown-surface':
13
- case 'provider-unavailable':
14
- return 'remote-unavailable';
15
- default:
16
- return 'remote-unavailable';
17
- }
18
- }
19
- function toRemoteString(ref) {
20
- return void 0 === validateSurfaceRef(ref) ? formatSurfaceRef(ref) : `${ref.unitId}#${ref.surfaceId}`;
21
- }
22
- async function reportFailure(options, ref, base) {
23
- const remote = toRemoteString(ref);
24
- const telemetry = createModuleFederationFallbackTelemetry({
25
- appName: options.appName,
26
- classification: base.classification,
27
- error: base.error ?? base.discoveryError,
28
- metadata: {
29
- env: options.env,
30
- surfaceRef: remote,
31
- ...base.discoveryError ? {
32
- discoveryErrorCode: base.discoveryError.code
33
- } : {},
34
- ...base.resolved ? {
35
- buildMarker: base.resolved.buildMarker
36
- } : {}
37
- },
38
- phase: base.phase,
39
- remote,
40
- status: 'degraded'
41
- });
42
- try {
43
- await emitModuleFederationFallbackTelemetry({
44
- appName: options.appName,
45
- classification: base.classification,
46
- error: base.error ?? base.discoveryError,
47
- metadata: telemetry.metadata,
48
- phase: base.phase,
49
- remote,
50
- status: 'degraded'
51
- }, options.telemetry ?? {});
52
- } catch {}
53
- const failure = {
54
- ref,
55
- env: options.env,
56
- phase: base.phase,
57
- classification: base.classification,
58
- telemetry
59
- };
60
- if (base.discoveryError) failure.discoveryError = base.discoveryError;
61
- if (void 0 !== base.error) failure.error = base.error;
62
- if (base.resolved) failure.resolved = base.resolved;
63
- const critical = (options.classification ?? 'critical') === 'critical';
64
- const reason = base.discoveryError ?? (void 0 !== base.error ? base.error : createDiscoveryError('identity-mismatch', remote, `resolved record for "${remote}" is incompatible`, {
65
- env: options.env
66
- }));
67
- let degradedValue;
68
- try {
69
- degradedValue = await options.degraded(failure);
70
- } catch (handlerError) {
71
- try {
72
- await emitModuleFederationFallbackTelemetry({
73
- appName: options.appName,
74
- classification: base.classification,
75
- error: handlerError,
76
- metadata: {
77
- ...telemetry.metadata,
78
- degradedHandlerFailed: true
79
- },
80
- phase: base.phase,
81
- remote,
82
- status: 'failed'
83
- }, options.telemetry ?? {});
84
- } catch {}
85
- if (critical) throw reason;
86
- return;
87
- }
88
- if (critical) throw reason;
89
- return degradedValue;
90
- }
91
- async function consumeSurface(options) {
92
- let ref;
93
- if ('string' == typeof options.ref) {
94
- const parsed = parseSurfaceRef(options.ref);
95
- if (!parsed.ok) {
96
- const hashIndex = options.ref.indexOf('#');
97
- const echoed = -1 === hashIndex ? {
98
- unitId: options.ref,
99
- surfaceId: ''
100
- } : {
101
- unitId: options.ref.slice(0, hashIndex),
102
- surfaceId: options.ref.slice(hashIndex + 1)
103
- };
104
- return reportFailure(options, echoed, {
105
- phase: 'discovery',
106
- classification: 'remote-unavailable',
107
- discoveryError: createDiscoveryError('unknown-surface', options.ref, `SurfaceRef "${options.ref}" is not a valid canonical reference (${parsed.error.code}).`, {
108
- parseError: parsed.error,
109
- env: options.env
110
- })
111
- });
112
- }
113
- ref = parsed.ref;
114
- } else ref = options.ref;
115
- let resolution;
116
- try {
117
- resolution = await options.provider.resolve(ref, options.env);
118
- } catch (error) {
119
- return reportFailure(options, ref, {
120
- phase: 'discovery',
121
- classification: classifyModuleFederationFallback(error),
122
- error
123
- });
124
- }
125
- if (!resolution.ok) return reportFailure(options, ref, {
126
- phase: 'discovery',
127
- classification: classifyDiscoveryError(resolution.error.code),
128
- discoveryError: resolution.error
129
- });
130
- const resolved = resolution.unit;
131
- if ('incompatible' === resolved.compatibility.status) return reportFailure(options, ref, {
132
- phase: 'discovery',
133
- classification: 'contract',
134
- resolved
135
- });
136
- try {
137
- return await options.load({
138
- resolved,
139
- ref,
140
- env: options.env
141
- });
142
- } catch (error) {
143
- return reportFailure(options, ref, {
144
- phase: 'load',
145
- classification: classifyModuleFederationFallback(error),
146
- error,
147
- resolved
148
- });
149
- }
150
- }
151
- function createSurfaceConsumer(base) {
152
- return function(options) {
153
- return consumeSurface({
154
- ...base,
155
- ...options
156
- });
157
- };
158
- }
159
- export { consumeSurface, createSurfaceConsumer };
@@ -1,83 +0,0 @@
1
- import "node:module";
2
- import { jsx } from "react/jsx-runtime";
3
- import { useRuntimeContext } from "../core/context/runtime.mjs";
4
- const DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY = '__modernDistributedSsrFragments';
5
- const DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY = '__modernDistributedSsrFragmentRequest';
6
- function distributedSsrFragmentKey(remote, expose) {
7
- return `${remote}::${expose}`;
8
- }
9
- function getDistributedSsrFragmentContext(response) {
10
- const locals = response?.locals;
11
- if ('object' != typeof locals || null === locals) return;
12
- const context = DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY in locals ? locals[DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY] : void 0;
13
- if ('object' != typeof context || null === context) return;
14
- return context;
15
- }
16
- function useDistributedSsrFragmentProps({ boundaryId, expose }) {
17
- const runtimeContext = useRuntimeContext();
18
- const locals = runtimeContext.requestContext?.response?.locals;
19
- const request = 'object' == typeof locals && null !== locals && DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY in locals ? locals[DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY] : void 0;
20
- if ('object' != typeof request || null === request || !('boundaryId' in request) || request.boundaryId !== boundaryId || !('expose' in request) || request.expose !== expose) throw new Error(`Distributed SSR fragment request contract mismatch for ${boundaryId} ${expose}.`);
21
- const props = 'props' in request ? request.props : void 0;
22
- if ('object' != typeof props || null === props || Array.isArray(props)) throw new Error(`Distributed SSR fragment request props must be an object for ${boundaryId} ${expose}.`);
23
- return props;
24
- }
25
- function isThenable(value) {
26
- return void 0 !== value && 'then' in value && 'function' == typeof value.then;
27
- }
28
- function DistributedSsrBoundary({ children, expose, fallback, fragmentProps, remote }) {
29
- const runtimeContext = useRuntimeContext();
30
- const key = distributedSsrFragmentKey(remote, expose);
31
- const attributes = {
32
- 'data-modern-distributed-ssr-boundary': key
33
- };
34
- if (runtimeContext.isBrowser) return /*#__PURE__*/ jsx("div", {
35
- ...attributes,
36
- children: children
37
- });
38
- const fragmentContext = getDistributedSsrFragmentContext(runtimeContext.requestContext?.response);
39
- if (void 0 === fragmentContext) return /*#__PURE__*/ jsx("div", {
40
- ...attributes,
41
- children: children
42
- });
43
- const resolverFragmentProps = void 0 === fragmentProps ? {} : Object.fromEntries(Object.entries(fragmentProps));
44
- const fragmentOrPromise = fragmentContext.resolve?.(remote, expose, resolverFragmentProps) ?? fragmentContext.fragments?.[key];
45
- if (isThenable(fragmentOrPromise)) throw fragmentOrPromise;
46
- const fragment = fragmentOrPromise;
47
- if (fragment?.status === 'ready') return /*#__PURE__*/ jsx("div", {
48
- ...attributes,
49
- "data-modern-distributed-ssr-build": fragment.buildMarker,
50
- "data-modern-distributed-ssr-digest": fragment.digest,
51
- "data-modern-distributed-ssr-status": "ready",
52
- dangerouslySetInnerHTML: {
53
- __html: fragment.html
54
- }
55
- });
56
- return /*#__PURE__*/ jsx("div", {
57
- ...attributes,
58
- "data-modern-distributed-ssr-reason": fragment?.reason ?? 'missing',
59
- "data-modern-distributed-ssr-status": "degraded",
60
- children: fallback
61
- });
62
- }
63
- function createDistributedSsrComponent({ createComponent, expose, fallback, remote }) {
64
- let RemoteComponent;
65
- function DeferredRemoteComponent(props) {
66
- RemoteComponent ??= createComponent();
67
- return /*#__PURE__*/ jsx(RemoteComponent, {
68
- ...props
69
- });
70
- }
71
- return function(props) {
72
- return /*#__PURE__*/ jsx(DistributedSsrBoundary, {
73
- expose: expose,
74
- fallback: fallback,
75
- fragmentProps: props,
76
- remote: remote,
77
- children: /*#__PURE__*/ jsx(DeferredRemoteComponent, {
78
- ...props
79
- })
80
- });
81
- };
82
- }
83
- export { DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY, DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY, DistributedSsrBoundary, createDistributedSsrComponent, distributedSsrFragmentKey, useDistributedSsrFragmentProps };