@bleedingdev/modern-js-federation-runtime 3.9.0-ultramodern.11 → 3.9.0-ultramodern.13
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/module-federation/consume-surface.js +6 -16
- package/dist/cjs/module-federation/index.js +16 -202
- package/dist/cjs/module-federation/telemetry.js +214 -0
- package/dist/esm/module-federation/consume-surface.mjs +3 -13
- package/dist/esm/module-federation/index.mjs +1 -109
- package/dist/esm/module-federation/telemetry.mjs +142 -0
- package/dist/esm-node/module-federation/consume-surface.mjs +3 -13
- package/dist/esm-node/module-federation/index.mjs +1 -109
- package/dist/esm-node/module-federation/telemetry.mjs +143 -0
- package/dist/types/module-federation/consume-surface.d.ts +5 -5
- package/dist/types/module-federation/index.d.ts +1 -65
- package/dist/types/module-federation/telemetry.d.ts +71 -0
- package/package.json +12 -12
- package/src/module-federation/consume-surface.ts +18 -33
- package/src/module-federation/index.ts +1 -262
- package/src/module-federation/telemetry.ts +297 -0
|
@@ -31,8 +31,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
consumeSurface: ()=>consumeSurface,
|
|
32
32
|
createSurfaceConsumer: ()=>createSurfaceConsumer
|
|
33
33
|
});
|
|
34
|
-
const external_index_js_namespaceObject = require("./index.js");
|
|
35
34
|
const external_surface_resolution_types_js_namespaceObject = require("./surface-resolution-types.js");
|
|
35
|
+
const external_telemetry_js_namespaceObject = require("./telemetry.js");
|
|
36
36
|
function classifyDiscoveryError(code) {
|
|
37
37
|
switch(code){
|
|
38
38
|
case 'major-not-published':
|
|
@@ -53,7 +53,7 @@ function toRemoteString(ref) {
|
|
|
53
53
|
}
|
|
54
54
|
async function reportFailure(options, ref, base) {
|
|
55
55
|
const remote = toRemoteString(ref);
|
|
56
|
-
const telemetry = (0,
|
|
56
|
+
const telemetry = (0, external_telemetry_js_namespaceObject.createModuleFederationFallbackTelemetry)({
|
|
57
57
|
appName: options.appName,
|
|
58
58
|
classification: base.classification,
|
|
59
59
|
error: base.error ?? base.discoveryError,
|
|
@@ -71,17 +71,7 @@ async function reportFailure(options, ref, base) {
|
|
|
71
71
|
remote,
|
|
72
72
|
status: 'degraded'
|
|
73
73
|
});
|
|
74
|
-
|
|
75
|
-
await (0, external_index_js_namespaceObject.emitModuleFederationFallbackTelemetry)({
|
|
76
|
-
appName: options.appName,
|
|
77
|
-
classification: base.classification,
|
|
78
|
-
error: base.error ?? base.discoveryError,
|
|
79
|
-
metadata: telemetry.metadata,
|
|
80
|
-
phase: base.phase,
|
|
81
|
-
remote,
|
|
82
|
-
status: 'degraded'
|
|
83
|
-
}, options.telemetry ?? {});
|
|
84
|
-
} catch {}
|
|
74
|
+
(0, external_telemetry_js_namespaceObject.emitModuleFederationFallbackPayload)(telemetry, options.telemetry);
|
|
85
75
|
const failure = {
|
|
86
76
|
ref,
|
|
87
77
|
env: options.env,
|
|
@@ -101,7 +91,7 @@ async function reportFailure(options, ref, base) {
|
|
|
101
91
|
degradedValue = await options.degraded(failure);
|
|
102
92
|
} catch (handlerError) {
|
|
103
93
|
try {
|
|
104
|
-
|
|
94
|
+
(0, external_telemetry_js_namespaceObject.emitModuleFederationFallbackTelemetry)({
|
|
105
95
|
appName: options.appName,
|
|
106
96
|
classification: base.classification,
|
|
107
97
|
error: handlerError,
|
|
@@ -150,7 +140,7 @@ async function consumeSurface(options) {
|
|
|
150
140
|
} catch (error) {
|
|
151
141
|
return reportFailure(options, ref, {
|
|
152
142
|
phase: 'discovery',
|
|
153
|
-
classification: (0,
|
|
143
|
+
classification: (0, external_telemetry_js_namespaceObject.classifyModuleFederationFallback)(error),
|
|
154
144
|
error
|
|
155
145
|
});
|
|
156
146
|
}
|
|
@@ -174,7 +164,7 @@ async function consumeSurface(options) {
|
|
|
174
164
|
} catch (error) {
|
|
175
165
|
return reportFailure(options, ref, {
|
|
176
166
|
phase: 'load',
|
|
177
|
-
classification: (0,
|
|
167
|
+
classification: (0, external_telemetry_js_namespaceObject.classifyModuleFederationFallback)(error),
|
|
178
168
|
error,
|
|
179
169
|
resolved
|
|
180
170
|
});
|
|
@@ -14,6 +14,9 @@ var __webpack_modules__ = {
|
|
|
14
14
|
},
|
|
15
15
|
"./surface-resolution-types" (module) {
|
|
16
16
|
module.exports = require("./surface-resolution-types.js");
|
|
17
|
+
},
|
|
18
|
+
"./telemetry" (module) {
|
|
19
|
+
module.exports = require("./telemetry.js");
|
|
17
20
|
}
|
|
18
21
|
};
|
|
19
22
|
var __webpack_module_cache__ = {};
|
|
@@ -66,249 +69,60 @@ var __webpack_exports__ = {};
|
|
|
66
69
|
var _consume_surface__rspack_import_0 = __webpack_require__("./consume-surface");
|
|
67
70
|
var __rspack_reexport = {};
|
|
68
71
|
for(const __rspack_import_key in _consume_surface__rspack_import_0)if ([
|
|
69
|
-
"MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT",
|
|
70
|
-
"MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT",
|
|
71
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
72
|
-
"createModuleFederationFallbackTelemetry",
|
|
73
|
-
"toModuleFederationFallbackAttributes",
|
|
74
|
-
"ModuleFederationRemoteComponentContractError",
|
|
75
|
-
"emitModuleFederationFallbackTelemetry",
|
|
76
|
-
"default",
|
|
77
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER",
|
|
78
|
-
"classifyModuleFederationFallback",
|
|
79
|
-
"ModuleFederationRemoteLoadTimeoutError",
|
|
80
72
|
"useDistributedSsrFragmentProps",
|
|
81
|
-
"
|
|
73
|
+
"default",
|
|
82
74
|
"DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY"
|
|
83
75
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_consume_surface__rspack_import_0[__rspack_import_key];
|
|
84
76
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
85
77
|
var _distributed_ssr__rspack_import_1 = __webpack_require__("./distributed-ssr");
|
|
86
78
|
var __rspack_reexport = {};
|
|
87
79
|
for(const __rspack_import_key in _distributed_ssr__rspack_import_1)if ([
|
|
88
|
-
"MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT",
|
|
89
|
-
"MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT",
|
|
90
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
91
|
-
"createModuleFederationFallbackTelemetry",
|
|
92
|
-
"toModuleFederationFallbackAttributes",
|
|
93
|
-
"ModuleFederationRemoteComponentContractError",
|
|
94
|
-
"emitModuleFederationFallbackTelemetry",
|
|
95
|
-
"default",
|
|
96
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER",
|
|
97
|
-
"classifyModuleFederationFallback",
|
|
98
|
-
"ModuleFederationRemoteLoadTimeoutError",
|
|
99
80
|
"useDistributedSsrFragmentProps",
|
|
100
|
-
"
|
|
81
|
+
"default",
|
|
101
82
|
"DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY"
|
|
102
83
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_distributed_ssr__rspack_import_1[__rspack_import_key];
|
|
103
84
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
104
85
|
var _last_known_good__rspack_import_2 = __webpack_require__("./last-known-good");
|
|
105
86
|
var __rspack_reexport = {};
|
|
106
87
|
for(const __rspack_import_key in _last_known_good__rspack_import_2)if ([
|
|
107
|
-
"MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT",
|
|
108
|
-
"MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT",
|
|
109
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
110
|
-
"createModuleFederationFallbackTelemetry",
|
|
111
|
-
"toModuleFederationFallbackAttributes",
|
|
112
|
-
"ModuleFederationRemoteComponentContractError",
|
|
113
|
-
"emitModuleFederationFallbackTelemetry",
|
|
114
|
-
"default",
|
|
115
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER",
|
|
116
|
-
"classifyModuleFederationFallback",
|
|
117
|
-
"ModuleFederationRemoteLoadTimeoutError",
|
|
118
88
|
"useDistributedSsrFragmentProps",
|
|
119
|
-
"
|
|
89
|
+
"default",
|
|
120
90
|
"DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY"
|
|
121
91
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_last_known_good__rspack_import_2[__rspack_import_key];
|
|
122
92
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
123
93
|
var _manifest_recovery_runtime_plugin__rspack_import_3 = __webpack_require__("./manifest-recovery-runtime-plugin");
|
|
124
94
|
var __rspack_reexport = {};
|
|
125
95
|
for(const __rspack_import_key in _manifest_recovery_runtime_plugin__rspack_import_3)if ([
|
|
126
|
-
"MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT",
|
|
127
|
-
"MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT",
|
|
128
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
129
|
-
"createModuleFederationFallbackTelemetry",
|
|
130
|
-
"toModuleFederationFallbackAttributes",
|
|
131
|
-
"ModuleFederationRemoteComponentContractError",
|
|
132
|
-
"emitModuleFederationFallbackTelemetry",
|
|
133
|
-
"default",
|
|
134
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER",
|
|
135
|
-
"classifyModuleFederationFallback",
|
|
136
|
-
"ModuleFederationRemoteLoadTimeoutError",
|
|
137
96
|
"useDistributedSsrFragmentProps",
|
|
138
|
-
"
|
|
97
|
+
"default",
|
|
139
98
|
"DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY"
|
|
140
99
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_manifest_recovery_runtime_plugin__rspack_import_3[__rspack_import_key];
|
|
141
100
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
142
101
|
var _surface_resolution_types__rspack_import_4 = __webpack_require__("./surface-resolution-types");
|
|
143
102
|
var __rspack_reexport = {};
|
|
144
103
|
for(const __rspack_import_key in _surface_resolution_types__rspack_import_4)if ([
|
|
145
|
-
"MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT",
|
|
146
|
-
"MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT",
|
|
147
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
148
|
-
"createModuleFederationFallbackTelemetry",
|
|
149
|
-
"toModuleFederationFallbackAttributes",
|
|
150
|
-
"ModuleFederationRemoteComponentContractError",
|
|
151
|
-
"emitModuleFederationFallbackTelemetry",
|
|
152
|
-
"default",
|
|
153
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER",
|
|
154
|
-
"classifyModuleFederationFallback",
|
|
155
|
-
"ModuleFederationRemoteLoadTimeoutError",
|
|
156
104
|
"useDistributedSsrFragmentProps",
|
|
157
|
-
"
|
|
105
|
+
"default",
|
|
158
106
|
"DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY"
|
|
159
107
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_surface_resolution_types__rspack_import_4[__rspack_import_key];
|
|
160
108
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
class ModuleFederationRemoteLoadError extends Error {
|
|
172
|
-
constructor(remote, attempts, causeError){
|
|
173
|
-
super(`Unable to load remote "${remote}" after ${attempts} attempt${attempts > 1 ? 's' : ''}: ${causeError.message}`);
|
|
174
|
-
this.name = 'ModuleFederationRemoteLoadError';
|
|
175
|
-
this.remote = remote;
|
|
176
|
-
this.attempts = attempts;
|
|
177
|
-
this.causeError = causeError;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
class ModuleFederationRemoteComponentContractError extends Error {
|
|
181
|
-
constructor(remote, exportName){
|
|
182
|
-
super(`Remote "${remote}" export "${exportName}" is not a valid React component`);
|
|
183
|
-
this.name = 'ModuleFederationRemoteComponentContractError';
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function toError(error) {
|
|
187
|
-
if (error instanceof Error) return error;
|
|
188
|
-
return new Error('string' == typeof error ? error : 'Unknown remote load error');
|
|
189
|
-
}
|
|
190
|
-
function classifyModuleFederationFallback(error) {
|
|
191
|
-
const normalizedError = toError(error);
|
|
192
|
-
if (normalizedError instanceof ModuleFederationRemoteLoadError) return classifyModuleFederationFallback(normalizedError.causeError);
|
|
193
|
-
if (normalizedError instanceof ModuleFederationRemoteLoadTimeoutError) return 'timeout';
|
|
194
|
-
if (normalizedError instanceof ModuleFederationRemoteComponentContractError) return 'contract';
|
|
195
|
-
const message = normalizedError.message;
|
|
196
|
-
if (/version|requiredVersion|singleton|share scope|shared module/i.test(message)) return 'version-skew';
|
|
197
|
-
if (/network|fetch|script|timeout|chunk|loading/i.test(message)) return 'network';
|
|
198
|
-
return 'remote-unavailable';
|
|
199
|
-
}
|
|
200
|
-
function createModuleFederationFallbackTelemetry(input) {
|
|
201
|
-
const error = void 0 !== input.error ? toError(input.error) : void 0;
|
|
202
|
-
const status = input.status ?? 'degraded';
|
|
203
|
-
const eventName = input.eventName ?? ('recovered' === status ? MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT : MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT);
|
|
204
|
-
const metadata = {
|
|
205
|
-
...input.metadata ?? {},
|
|
206
|
-
classification: input.classification,
|
|
207
|
-
remote: input.remote,
|
|
208
|
-
status
|
|
209
|
-
};
|
|
210
|
-
if (void 0 !== input.exportName) metadata.exportName = input.exportName;
|
|
211
|
-
if (void 0 !== input.runtimeDigest) metadata.runtimeDigest = input.runtimeDigest;
|
|
212
|
-
if (void 0 !== error) {
|
|
213
|
-
metadata.errorName = error.name;
|
|
214
|
-
metadata.errorMessage = error.message;
|
|
215
|
-
}
|
|
216
|
-
const payload = {
|
|
217
|
-
appName: input.appName,
|
|
218
|
-
eventName,
|
|
219
|
-
metadata,
|
|
220
|
-
phase: input.phase,
|
|
221
|
-
reason: input.classification,
|
|
222
|
-
schemaVersion: 1
|
|
223
|
-
};
|
|
224
|
-
if (void 0 !== input.entry) payload.entry = input.entry;
|
|
225
|
-
if (void 0 !== input.runtimeDigest) payload.runtimeDigest = input.runtimeDigest;
|
|
226
|
-
return payload;
|
|
227
|
-
}
|
|
228
|
-
function toModuleFederationFallbackAttributes(payload) {
|
|
229
|
-
return {
|
|
230
|
-
'data-mf-fallback-app': payload.appName,
|
|
231
|
-
'data-mf-fallback-classification': payload.reason,
|
|
232
|
-
'data-mf-fallback-phase': payload.phase,
|
|
233
|
-
'data-mf-fallback-remote': String(payload.metadata.remote),
|
|
234
|
-
'data-mf-fallback-status': String(payload.metadata.status),
|
|
235
|
-
'data-mf-telemetry-event': payload.eventName
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
async function emitModuleFederationFallbackTelemetry(input, options = {}) {
|
|
239
|
-
const payload = createModuleFederationFallbackTelemetry(input);
|
|
240
|
-
if ("u" > typeof window && 'function' == typeof window.dispatchEvent && "u" > typeof CustomEvent) window.dispatchEvent(new CustomEvent(payload.eventName, {
|
|
241
|
-
detail: payload
|
|
242
|
-
}));
|
|
243
|
-
const shouldPost = true === options.postSignal || Boolean(options.endpoint);
|
|
244
|
-
if (!shouldPost) return {
|
|
245
|
-
dispatched: true,
|
|
246
|
-
posted: false
|
|
247
|
-
};
|
|
248
|
-
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
249
|
-
if ('function' != typeof fetchImpl) return {
|
|
250
|
-
dispatched: true,
|
|
251
|
-
posted: false
|
|
252
|
-
};
|
|
253
|
-
const headers = new Headers({
|
|
254
|
-
'content-type': 'application/json'
|
|
255
|
-
});
|
|
256
|
-
if (void 0 !== options.authToken && options.authToken.length > 0) headers.set(options.authHeaderName ?? DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER, options.authToken);
|
|
257
|
-
const response = await fetchImpl(options.endpoint ?? DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, {
|
|
258
|
-
body: JSON.stringify(payload),
|
|
259
|
-
headers,
|
|
260
|
-
method: 'POST',
|
|
261
|
-
keepalive: true
|
|
262
|
-
});
|
|
263
|
-
return {
|
|
264
|
-
dispatched: true,
|
|
265
|
-
posted: true,
|
|
266
|
-
postStatus: response.status
|
|
267
|
-
};
|
|
268
|
-
}
|
|
109
|
+
var _telemetry__rspack_import_5 = __webpack_require__("./telemetry");
|
|
110
|
+
var __rspack_reexport = {};
|
|
111
|
+
for(const __rspack_import_key in _telemetry__rspack_import_5)if ([
|
|
112
|
+
"useDistributedSsrFragmentProps",
|
|
113
|
+
"default",
|
|
114
|
+
"DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY"
|
|
115
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_telemetry__rspack_import_5[__rspack_import_key];
|
|
116
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
269
117
|
__webpack_require__.d(__webpack_exports__, {
|
|
270
118
|
DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY: ()=>_distributed_ssr__rspack_import_1.DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY,
|
|
271
|
-
ModuleFederationRemoteComponentContractError: ()=>ModuleFederationRemoteComponentContractError,
|
|
272
|
-
ModuleFederationRemoteLoadError: ()=>ModuleFederationRemoteLoadError,
|
|
273
|
-
ModuleFederationRemoteLoadTimeoutError: ()=>ModuleFederationRemoteLoadTimeoutError,
|
|
274
|
-
classifyModuleFederationFallback: ()=>classifyModuleFederationFallback,
|
|
275
|
-
createModuleFederationFallbackTelemetry: ()=>createModuleFederationFallbackTelemetry,
|
|
276
|
-
emitModuleFederationFallbackTelemetry: ()=>emitModuleFederationFallbackTelemetry,
|
|
277
|
-
toModuleFederationFallbackAttributes: ()=>toModuleFederationFallbackAttributes,
|
|
278
119
|
useDistributedSsrFragmentProps: ()=>_distributed_ssr__rspack_import_1.useDistributedSsrFragmentProps
|
|
279
|
-
}, {
|
|
280
|
-
DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER: DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER,
|
|
281
|
-
DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT: DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT,
|
|
282
|
-
MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT: MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT,
|
|
283
|
-
MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT: MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT
|
|
284
120
|
});
|
|
285
121
|
})();
|
|
286
|
-
exports.DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER;
|
|
287
|
-
exports.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
|
|
288
122
|
exports.DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY = __webpack_exports__.DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY;
|
|
289
|
-
exports.MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT = __webpack_exports__.MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT;
|
|
290
|
-
exports.MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT = __webpack_exports__.MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT;
|
|
291
|
-
exports.ModuleFederationRemoteComponentContractError = __webpack_exports__.ModuleFederationRemoteComponentContractError;
|
|
292
|
-
exports.ModuleFederationRemoteLoadError = __webpack_exports__.ModuleFederationRemoteLoadError;
|
|
293
|
-
exports.ModuleFederationRemoteLoadTimeoutError = __webpack_exports__.ModuleFederationRemoteLoadTimeoutError;
|
|
294
|
-
exports.classifyModuleFederationFallback = __webpack_exports__.classifyModuleFederationFallback;
|
|
295
|
-
exports.createModuleFederationFallbackTelemetry = __webpack_exports__.createModuleFederationFallbackTelemetry;
|
|
296
|
-
exports.emitModuleFederationFallbackTelemetry = __webpack_exports__.emitModuleFederationFallbackTelemetry;
|
|
297
|
-
exports.toModuleFederationFallbackAttributes = __webpack_exports__.toModuleFederationFallbackAttributes;
|
|
298
123
|
exports.useDistributedSsrFragmentProps = __webpack_exports__.useDistributedSsrFragmentProps;
|
|
299
124
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
300
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER",
|
|
301
|
-
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
302
125
|
"DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY",
|
|
303
|
-
"MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT",
|
|
304
|
-
"MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT",
|
|
305
|
-
"ModuleFederationRemoteComponentContractError",
|
|
306
|
-
"ModuleFederationRemoteLoadError",
|
|
307
|
-
"ModuleFederationRemoteLoadTimeoutError",
|
|
308
|
-
"classifyModuleFederationFallback",
|
|
309
|
-
"createModuleFederationFallbackTelemetry",
|
|
310
|
-
"emitModuleFederationFallbackTelemetry",
|
|
311
|
-
"toModuleFederationFallbackAttributes",
|
|
312
126
|
"useDistributedSsrFragmentProps"
|
|
313
127
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
314
128
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
const MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT = 'modernjs:mf-runtime-fallback';
|
|
31
|
+
const MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT = 'modernjs:mf-runtime-recovery';
|
|
32
|
+
const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = '/_modern/contract-gates/runtime-fallback';
|
|
33
|
+
const DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER = 'x-modernjs-runtime-signal-token';
|
|
34
|
+
class ModuleFederationRemoteLoadTimeoutError extends Error {
|
|
35
|
+
constructor(remote, timeoutMs){
|
|
36
|
+
super(`Loading remote "${remote}" timed out after ${timeoutMs}ms`);
|
|
37
|
+
this.name = 'ModuleFederationRemoteLoadTimeoutError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class ModuleFederationRemoteLoadError extends Error {
|
|
41
|
+
constructor(remote, attempts, causeError){
|
|
42
|
+
super(`Unable to load remote "${remote}" after ${attempts} attempt${attempts > 1 ? 's' : ''}: ${causeError.message}`);
|
|
43
|
+
this.name = 'ModuleFederationRemoteLoadError';
|
|
44
|
+
this.remote = remote;
|
|
45
|
+
this.attempts = attempts;
|
|
46
|
+
this.causeError = causeError;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class ModuleFederationRemoteComponentContractError extends Error {
|
|
50
|
+
constructor(remote, exportName){
|
|
51
|
+
super(`Remote "${remote}" export "${exportName}" is not a valid React component`);
|
|
52
|
+
this.name = 'ModuleFederationRemoteComponentContractError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function toError(error) {
|
|
56
|
+
if (error instanceof Error) return error;
|
|
57
|
+
return new Error('string' == typeof error ? error : 'Unknown remote load error');
|
|
58
|
+
}
|
|
59
|
+
function classifyModuleFederationFallback(error) {
|
|
60
|
+
const normalizedError = toError(error);
|
|
61
|
+
if (normalizedError instanceof ModuleFederationRemoteLoadError) return classifyModuleFederationFallback(normalizedError.causeError);
|
|
62
|
+
if (normalizedError instanceof ModuleFederationRemoteLoadTimeoutError) return 'timeout';
|
|
63
|
+
if (normalizedError instanceof ModuleFederationRemoteComponentContractError) return 'contract';
|
|
64
|
+
const message = normalizedError.message;
|
|
65
|
+
if (/version|requiredVersion|singleton|share scope|shared module/i.test(message)) return 'version-skew';
|
|
66
|
+
if (/network|fetch|script|timeout|chunk|loading/i.test(message)) return 'network';
|
|
67
|
+
return 'remote-unavailable';
|
|
68
|
+
}
|
|
69
|
+
function createModuleFederationFallbackTelemetry(input) {
|
|
70
|
+
const error = void 0 !== input.error ? toError(input.error) : void 0;
|
|
71
|
+
const status = input.status ?? 'degraded';
|
|
72
|
+
const eventName = input.eventName ?? ('recovered' === status ? MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT : MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT);
|
|
73
|
+
const metadata = {
|
|
74
|
+
...input.metadata ?? {},
|
|
75
|
+
classification: input.classification,
|
|
76
|
+
remote: input.remote,
|
|
77
|
+
status
|
|
78
|
+
};
|
|
79
|
+
if (void 0 !== input.exportName) metadata.exportName = input.exportName;
|
|
80
|
+
if (void 0 !== input.runtimeDigest) metadata.runtimeDigest = input.runtimeDigest;
|
|
81
|
+
if (void 0 !== error) {
|
|
82
|
+
metadata.errorName = error.name;
|
|
83
|
+
metadata.errorMessage = error.message;
|
|
84
|
+
}
|
|
85
|
+
const payload = {
|
|
86
|
+
appName: input.appName,
|
|
87
|
+
eventName,
|
|
88
|
+
metadata,
|
|
89
|
+
phase: input.phase,
|
|
90
|
+
reason: input.classification,
|
|
91
|
+
schemaVersion: 1
|
|
92
|
+
};
|
|
93
|
+
if (void 0 !== input.entry) payload.entry = input.entry;
|
|
94
|
+
if (void 0 !== input.runtimeDigest) payload.runtimeDigest = input.runtimeDigest;
|
|
95
|
+
return payload;
|
|
96
|
+
}
|
|
97
|
+
function toModuleFederationFallbackAttributes(payload) {
|
|
98
|
+
return {
|
|
99
|
+
'data-mf-fallback-app': payload.appName,
|
|
100
|
+
'data-mf-fallback-classification': payload.reason,
|
|
101
|
+
'data-mf-fallback-phase': payload.phase,
|
|
102
|
+
'data-mf-fallback-remote': String(payload.metadata.remote),
|
|
103
|
+
'data-mf-fallback-status': String(payload.metadata.status),
|
|
104
|
+
'data-mf-telemetry-event': payload.eventName
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function emitModuleFederationFallbackTelemetry(input, options = {}) {
|
|
108
|
+
return emitModuleFederationFallbackPayload(createModuleFederationFallbackTelemetry(input), options);
|
|
109
|
+
}
|
|
110
|
+
function emitModuleFederationFallbackPayload(payload, options = {}) {
|
|
111
|
+
const delivery = deliver(payload, options);
|
|
112
|
+
try {
|
|
113
|
+
options.observe?.(payload, delivery);
|
|
114
|
+
} catch {}
|
|
115
|
+
return delivery;
|
|
116
|
+
}
|
|
117
|
+
async function deliver(payload, options) {
|
|
118
|
+
let dispatched = false;
|
|
119
|
+
let timer;
|
|
120
|
+
const controller = new AbortController();
|
|
121
|
+
try {
|
|
122
|
+
if ("u" > typeof window && 'function' == typeof window.dispatchEvent && "u" > typeof CustomEvent) {
|
|
123
|
+
window.dispatchEvent(new CustomEvent(payload.eventName, {
|
|
124
|
+
detail: payload
|
|
125
|
+
}));
|
|
126
|
+
dispatched = true;
|
|
127
|
+
}
|
|
128
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
129
|
+
if (!(true === options.postSignal || options.endpoint) || 'function' != typeof fetchImpl) return {
|
|
130
|
+
dispatched,
|
|
131
|
+
posted: false
|
|
132
|
+
};
|
|
133
|
+
const headers = new Headers({
|
|
134
|
+
'content-type': 'application/json'
|
|
135
|
+
});
|
|
136
|
+
if (options.authToken) headers.set(options.authHeaderName ?? DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER, options.authToken);
|
|
137
|
+
const timeoutMs = Number.isSafeInteger(options.timeoutMs) && (options.timeoutMs ?? 0) > 0 ? options.timeoutMs : 1000;
|
|
138
|
+
const expired = new Promise((resolve)=>{
|
|
139
|
+
timer = setTimeout(()=>{
|
|
140
|
+
controller.abort();
|
|
141
|
+
resolve(void 0);
|
|
142
|
+
}, timeoutMs);
|
|
143
|
+
});
|
|
144
|
+
const response = await Promise.race([
|
|
145
|
+
fetchImpl(options.endpoint ?? DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, {
|
|
146
|
+
body: JSON.stringify(payload),
|
|
147
|
+
headers,
|
|
148
|
+
method: 'POST',
|
|
149
|
+
keepalive: true,
|
|
150
|
+
signal: controller.signal
|
|
151
|
+
}),
|
|
152
|
+
expired
|
|
153
|
+
]);
|
|
154
|
+
return response ? {
|
|
155
|
+
dispatched,
|
|
156
|
+
posted: true,
|
|
157
|
+
postStatus: response.status
|
|
158
|
+
} : {
|
|
159
|
+
dispatched,
|
|
160
|
+
posted: false
|
|
161
|
+
};
|
|
162
|
+
} catch {
|
|
163
|
+
return {
|
|
164
|
+
dispatched,
|
|
165
|
+
posted: false
|
|
166
|
+
};
|
|
167
|
+
} finally{
|
|
168
|
+
if (void 0 !== timer) clearTimeout(timer);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
172
|
+
ModuleFederationRemoteComponentContractError: ()=>ModuleFederationRemoteComponentContractError,
|
|
173
|
+
ModuleFederationRemoteLoadError: ()=>ModuleFederationRemoteLoadError,
|
|
174
|
+
ModuleFederationRemoteLoadTimeoutError: ()=>ModuleFederationRemoteLoadTimeoutError,
|
|
175
|
+
classifyModuleFederationFallback: ()=>classifyModuleFederationFallback,
|
|
176
|
+
createModuleFederationFallbackTelemetry: ()=>createModuleFederationFallbackTelemetry,
|
|
177
|
+
emitModuleFederationFallbackPayload: ()=>emitModuleFederationFallbackPayload,
|
|
178
|
+
emitModuleFederationFallbackTelemetry: ()=>emitModuleFederationFallbackTelemetry,
|
|
179
|
+
toModuleFederationFallbackAttributes: ()=>toModuleFederationFallbackAttributes
|
|
180
|
+
}, {
|
|
181
|
+
DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER: DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER,
|
|
182
|
+
DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT: DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT,
|
|
183
|
+
MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT: MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT,
|
|
184
|
+
MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT: MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT
|
|
185
|
+
});
|
|
186
|
+
exports.DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER;
|
|
187
|
+
exports.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
|
|
188
|
+
exports.MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT = __webpack_exports__.MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT;
|
|
189
|
+
exports.MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT = __webpack_exports__.MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT;
|
|
190
|
+
exports.ModuleFederationRemoteComponentContractError = __webpack_exports__.ModuleFederationRemoteComponentContractError;
|
|
191
|
+
exports.ModuleFederationRemoteLoadError = __webpack_exports__.ModuleFederationRemoteLoadError;
|
|
192
|
+
exports.ModuleFederationRemoteLoadTimeoutError = __webpack_exports__.ModuleFederationRemoteLoadTimeoutError;
|
|
193
|
+
exports.classifyModuleFederationFallback = __webpack_exports__.classifyModuleFederationFallback;
|
|
194
|
+
exports.createModuleFederationFallbackTelemetry = __webpack_exports__.createModuleFederationFallbackTelemetry;
|
|
195
|
+
exports.emitModuleFederationFallbackPayload = __webpack_exports__.emitModuleFederationFallbackPayload;
|
|
196
|
+
exports.emitModuleFederationFallbackTelemetry = __webpack_exports__.emitModuleFederationFallbackTelemetry;
|
|
197
|
+
exports.toModuleFederationFallbackAttributes = __webpack_exports__.toModuleFederationFallbackAttributes;
|
|
198
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
199
|
+
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_AUTH_HEADER",
|
|
200
|
+
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
201
|
+
"MODULE_FEDERATION_FALLBACK_SIGNAL_EVENT",
|
|
202
|
+
"MODULE_FEDERATION_RECOVERY_SIGNAL_EVENT",
|
|
203
|
+
"ModuleFederationRemoteComponentContractError",
|
|
204
|
+
"ModuleFederationRemoteLoadError",
|
|
205
|
+
"ModuleFederationRemoteLoadTimeoutError",
|
|
206
|
+
"classifyModuleFederationFallback",
|
|
207
|
+
"createModuleFederationFallbackTelemetry",
|
|
208
|
+
"emitModuleFederationFallbackPayload",
|
|
209
|
+
"emitModuleFederationFallbackTelemetry",
|
|
210
|
+
"toModuleFederationFallbackAttributes"
|
|
211
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
212
|
+
Object.defineProperty(exports, '__esModule', {
|
|
213
|
+
value: true
|
|
214
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { classifyModuleFederationFallback, createModuleFederationFallbackTelemetry, emitModuleFederationFallbackTelemetry } from "./index.mjs";
|
|
2
1
|
import { createDiscoveryError, formatSurfaceRef, parseSurfaceRef, validateSurfaceRef } from "./surface-resolution-types.mjs";
|
|
2
|
+
import { classifyModuleFederationFallback, createModuleFederationFallbackTelemetry, emitModuleFederationFallbackPayload, emitModuleFederationFallbackTelemetry } from "./telemetry.mjs";
|
|
3
3
|
function classifyDiscoveryError(code) {
|
|
4
4
|
switch(code){
|
|
5
5
|
case 'major-not-published':
|
|
@@ -38,17 +38,7 @@ async function reportFailure(options, ref, base) {
|
|
|
38
38
|
remote,
|
|
39
39
|
status: 'degraded'
|
|
40
40
|
});
|
|
41
|
-
|
|
42
|
-
await emitModuleFederationFallbackTelemetry({
|
|
43
|
-
appName: options.appName,
|
|
44
|
-
classification: base.classification,
|
|
45
|
-
error: base.error ?? base.discoveryError,
|
|
46
|
-
metadata: telemetry.metadata,
|
|
47
|
-
phase: base.phase,
|
|
48
|
-
remote,
|
|
49
|
-
status: 'degraded'
|
|
50
|
-
}, options.telemetry ?? {});
|
|
51
|
-
} catch {}
|
|
41
|
+
emitModuleFederationFallbackPayload(telemetry, options.telemetry);
|
|
52
42
|
const failure = {
|
|
53
43
|
ref,
|
|
54
44
|
env: options.env,
|
|
@@ -68,7 +58,7 @@ async function reportFailure(options, ref, base) {
|
|
|
68
58
|
degradedValue = await options.degraded(failure);
|
|
69
59
|
} catch (handlerError) {
|
|
70
60
|
try {
|
|
71
|
-
|
|
61
|
+
emitModuleFederationFallbackTelemetry({
|
|
72
62
|
appName: options.appName,
|
|
73
63
|
classification: base.classification,
|
|
74
64
|
error: handlerError,
|