@module-federation/runtime 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -183
- package/dist/index.cjs.js +22 -3
- package/dist/index.esm.js +19 -4
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +11 -2
- package/dist/share.esm.js +11 -2
- package/dist/src/core.d.ts +1 -0
- package/dist/src/index.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -106,7 +106,7 @@ init({
|
|
|
106
106
|
{
|
|
107
107
|
name: '@demo/app2',
|
|
108
108
|
alias: 'app2',
|
|
109
|
-
entry:
|
|
109
|
+
entry: 'http://localhost:3006/remoteEntry.js',
|
|
110
110
|
},
|
|
111
111
|
],
|
|
112
112
|
});
|
|
@@ -229,32 +229,32 @@ init({
|
|
|
229
229
|
// Filter resource information that contains ignore in the resource name
|
|
230
230
|
// Only preload sub-dependent @demo/sub1-button modules
|
|
231
231
|
preloadRemote([
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
},
|
|
237
|
-
depsRemote: [{ nameOrAlias: '@demo/sub1-button' }],
|
|
232
|
+
{
|
|
233
|
+
nameOrAlias: '@demo/sub1',
|
|
234
|
+
filter(assetUrl) {
|
|
235
|
+
return assetUrl.indexOf('ignore') === -1;
|
|
238
236
|
},
|
|
237
|
+
depsRemote: [{ nameOrAlias: '@demo/sub1-button' }],
|
|
238
|
+
},
|
|
239
239
|
]);
|
|
240
240
|
|
|
241
241
|
// Preload @demo/sub2 module
|
|
242
242
|
// Preload all exposes under @demo/sub2
|
|
243
243
|
// Preload the synchronous resources and asynchronous resources of @demo/sub2
|
|
244
244
|
preloadRemote([
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
245
|
+
{
|
|
246
|
+
nameOrAlias: '@demo/sub2',
|
|
247
|
+
resourceCategory: 'all',
|
|
248
|
+
},
|
|
249
249
|
]);
|
|
250
250
|
|
|
251
251
|
// Preload expose of @demo/sub3 module
|
|
252
252
|
preloadRemote([
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
253
|
+
{
|
|
254
|
+
nameOrAlias: '@demo/sub3',
|
|
255
|
+
resourceCategory: 'all',
|
|
256
|
+
exposes: ['add'],
|
|
257
|
+
},
|
|
258
258
|
]);
|
|
259
259
|
```
|
|
260
260
|
|
|
@@ -262,52 +262,51 @@ preloadRemote([
|
|
|
262
262
|
|
|
263
263
|
Lifecycle hooks for FederationHost interaction.
|
|
264
264
|
|
|
265
|
-
|
|
265
|
+
- example
|
|
266
266
|
|
|
267
267
|
```ts
|
|
268
|
-
import { init } from '@module-federation/runtime'
|
|
268
|
+
import { init } from '@module-federation/runtime';
|
|
269
269
|
import type { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
270
270
|
|
|
271
|
-
const runtimePlugin: () => FederationRuntimePlugin =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
beforeInit
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
beforeRequest
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
afterResolve
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
onLoad
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
},
|
|
298
|
-
};
|
|
271
|
+
const runtimePlugin: () => FederationRuntimePlugin = function () {
|
|
272
|
+
return {
|
|
273
|
+
name: 'my-runtime-plugin',
|
|
274
|
+
beforeInit(args) {
|
|
275
|
+
console.log('beforeInit: ', args);
|
|
276
|
+
return args;
|
|
277
|
+
},
|
|
278
|
+
beforeRequest(args) {
|
|
279
|
+
console.log('beforeRequest: ', args);
|
|
280
|
+
return args;
|
|
281
|
+
},
|
|
282
|
+
afterResolve(args) {
|
|
283
|
+
console.log('afterResolve', args);
|
|
284
|
+
return args;
|
|
285
|
+
},
|
|
286
|
+
onLoad(args) {
|
|
287
|
+
console.log('onLoad: ', args);
|
|
288
|
+
return args;
|
|
289
|
+
},
|
|
290
|
+
async loadShare(args) {
|
|
291
|
+
console.log('loadShare:', args);
|
|
292
|
+
},
|
|
293
|
+
async beforeLoadShare(args) {
|
|
294
|
+
console.log('beforeloadShare:', args);
|
|
295
|
+
return args;
|
|
296
|
+
},
|
|
299
297
|
};
|
|
298
|
+
};
|
|
300
299
|
|
|
301
300
|
init({
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
301
|
+
name: '@demo/app-main',
|
|
302
|
+
remotes: [
|
|
303
|
+
{
|
|
304
|
+
name: '@demo/app2',
|
|
305
|
+
entry: 'http://localhost:3006/remoteEntry.js',
|
|
306
|
+
alias: 'app2',
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
plugins: [runtimePlugin()],
|
|
311
310
|
});
|
|
312
311
|
```
|
|
313
312
|
|
|
@@ -317,17 +316,17 @@ init({
|
|
|
317
316
|
|
|
318
317
|
Updates Federation Host configurations before the initialization process of remote containers.
|
|
319
318
|
|
|
320
|
-
|
|
319
|
+
- type
|
|
321
320
|
|
|
322
321
|
```ts
|
|
323
|
-
function beforeInit(args: BeforeInitOptions): BeforeInitOptions
|
|
322
|
+
function beforeInit(args: BeforeInitOptions): BeforeInitOptions;
|
|
324
323
|
|
|
325
|
-
type BeforeInitOptions ={
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
324
|
+
type BeforeInitOptions = {
|
|
325
|
+
userOptions: UserOptions;
|
|
326
|
+
options: FederationRuntimeOptions;
|
|
327
|
+
origin: FederationHost;
|
|
328
|
+
shareInfo: ShareInfos;
|
|
329
|
+
};
|
|
331
330
|
|
|
332
331
|
interface FederationRuntimeOptions {
|
|
333
332
|
id?: string;
|
|
@@ -346,15 +345,15 @@ interface FederationRuntimeOptions {
|
|
|
346
345
|
|
|
347
346
|
Called during the initialization of remote containers.
|
|
348
347
|
|
|
349
|
-
|
|
348
|
+
- type
|
|
350
349
|
|
|
351
350
|
```ts
|
|
352
|
-
function init(args: InitOptions): void
|
|
351
|
+
function init(args: InitOptions): void;
|
|
353
352
|
|
|
354
|
-
type InitOptions ={
|
|
353
|
+
type InitOptions = {
|
|
355
354
|
options: FederationRuntimeOptions;
|
|
356
355
|
origin: FederationHost;
|
|
357
|
-
}
|
|
356
|
+
};
|
|
358
357
|
```
|
|
359
358
|
|
|
360
359
|
### beforeRequest
|
|
@@ -363,16 +362,16 @@ type InitOptions ={
|
|
|
363
362
|
|
|
364
363
|
Invoked before resolving a remote container, useful for injecting the container or updating something ahead of the lookup.
|
|
365
364
|
|
|
366
|
-
|
|
365
|
+
- type
|
|
367
366
|
|
|
368
367
|
```ts
|
|
369
|
-
async function beforeRequest(args: BeforeRequestOptions): Promise<BeforeRequestOptions
|
|
368
|
+
async function beforeRequest(args: BeforeRequestOptions): Promise<BeforeRequestOptions>;
|
|
370
369
|
|
|
371
|
-
type BeforeRequestOptions ={
|
|
370
|
+
type BeforeRequestOptions = {
|
|
372
371
|
id: string;
|
|
373
372
|
options: FederationRuntimeOptions;
|
|
374
373
|
origin: FederationHost;
|
|
375
|
-
}
|
|
374
|
+
};
|
|
376
375
|
```
|
|
377
376
|
|
|
378
377
|
### afterResolve
|
|
@@ -381,12 +380,12 @@ type BeforeRequestOptions ={
|
|
|
381
380
|
|
|
382
381
|
Called after resolving a container, allowing redirection or modification of resolved information.
|
|
383
382
|
|
|
384
|
-
|
|
383
|
+
- type
|
|
385
384
|
|
|
386
385
|
```ts
|
|
387
|
-
async function afterResolve(args: AfterResolveOptions): Promise<AfterResolveOptions
|
|
386
|
+
async function afterResolve(args: AfterResolveOptions): Promise<AfterResolveOptions>;
|
|
388
387
|
|
|
389
|
-
type AfterResolveOptions ={
|
|
388
|
+
type AfterResolveOptions = {
|
|
390
389
|
id: string;
|
|
391
390
|
pkgNameOrAlias: string;
|
|
392
391
|
expose: string;
|
|
@@ -395,7 +394,7 @@ type AfterResolveOptions ={
|
|
|
395
394
|
origin: FederationHost;
|
|
396
395
|
remoteInfo: RemoteInfo;
|
|
397
396
|
remoteSnapshot?: ModuleInfo;
|
|
398
|
-
}
|
|
397
|
+
};
|
|
399
398
|
```
|
|
400
399
|
|
|
401
400
|
### onLoad
|
|
@@ -404,12 +403,12 @@ type AfterResolveOptions ={
|
|
|
404
403
|
|
|
405
404
|
Triggered once a federated module is loaded, allowing access and modification to the exports of the loaded file.
|
|
406
405
|
|
|
407
|
-
|
|
406
|
+
- type
|
|
408
407
|
|
|
409
408
|
```ts
|
|
410
|
-
async function onLoad(args: OnLoadOptions): Promise<void
|
|
409
|
+
async function onLoad(args: OnLoadOptions): Promise<void>;
|
|
411
410
|
|
|
412
|
-
type OnLoadOptions ={
|
|
411
|
+
type OnLoadOptions = {
|
|
413
412
|
id: string;
|
|
414
413
|
expose: string;
|
|
415
414
|
pkgNameOrAlias: string;
|
|
@@ -419,12 +418,12 @@ type OnLoadOptions ={
|
|
|
419
418
|
exposeModule: any;
|
|
420
419
|
exposeModuleFactory: any;
|
|
421
420
|
moduleInstance: Module;
|
|
422
|
-
}
|
|
421
|
+
};
|
|
423
422
|
|
|
424
423
|
type ModuleOptions = {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
}
|
|
424
|
+
remoteInfo: RemoteInfo;
|
|
425
|
+
host: FederationHost;
|
|
426
|
+
};
|
|
428
427
|
|
|
429
428
|
interface RemoteInfo {
|
|
430
429
|
name: string;
|
|
@@ -443,17 +442,17 @@ interface RemoteInfo {
|
|
|
443
442
|
|
|
444
443
|
Handles preloading logic for federated modules.
|
|
445
444
|
|
|
446
|
-
|
|
445
|
+
- type
|
|
447
446
|
|
|
448
447
|
```ts
|
|
449
|
-
function handlePreloadModule(args: HandlePreloadModuleOptions): void
|
|
448
|
+
function handlePreloadModule(args: HandlePreloadModuleOptions): void;
|
|
450
449
|
|
|
451
|
-
type HandlePreloadModuleOptions ={
|
|
450
|
+
type HandlePreloadModuleOptions = {
|
|
452
451
|
id: string;
|
|
453
452
|
name: string;
|
|
454
453
|
remoteSnapshot: ModuleInfo;
|
|
455
454
|
preloadConfig: PreloadRemoteArgs;
|
|
456
|
-
}
|
|
455
|
+
};
|
|
457
456
|
```
|
|
458
457
|
|
|
459
458
|
### errorLoadRemote
|
|
@@ -462,52 +461,51 @@ type HandlePreloadModuleOptions ={
|
|
|
462
461
|
|
|
463
462
|
Invoked if loading a federated module fails, enabling custom error handling.
|
|
464
463
|
|
|
465
|
-
|
|
464
|
+
- type
|
|
466
465
|
|
|
467
466
|
```ts
|
|
468
|
-
async function errorLoadRemote(args: ErrorLoadRemoteOptions): Promise<void | unknown
|
|
467
|
+
async function errorLoadRemote(args: ErrorLoadRemoteOptions): Promise<void | unknown>;
|
|
469
468
|
|
|
470
|
-
type ErrorLoadRemoteOptions ={
|
|
469
|
+
type ErrorLoadRemoteOptions = {
|
|
471
470
|
id: string;
|
|
472
471
|
error: unknown;
|
|
473
472
|
from: 'build' | 'runtime';
|
|
474
473
|
origin: FederationHost;
|
|
475
|
-
}
|
|
474
|
+
};
|
|
476
475
|
```
|
|
477
|
-
|
|
476
|
+
|
|
477
|
+
- example
|
|
478
478
|
|
|
479
479
|
```ts
|
|
480
|
-
import { init, loadRemote } from '@module-federation/runtime'
|
|
480
|
+
import { init, loadRemote } from '@module-federation/runtime';
|
|
481
481
|
|
|
482
482
|
import type { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
483
483
|
|
|
484
|
-
const fallbackPlugin: () => FederationRuntimePlugin =
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
},
|
|
492
|
-
};
|
|
484
|
+
const fallbackPlugin: () => FederationRuntimePlugin = function () {
|
|
485
|
+
return {
|
|
486
|
+
name: 'fallback-plugin',
|
|
487
|
+
errorLoadRemote(args) {
|
|
488
|
+
const fallback = 'fallback';
|
|
489
|
+
return fallback;
|
|
490
|
+
},
|
|
493
491
|
};
|
|
494
|
-
|
|
492
|
+
};
|
|
495
493
|
|
|
496
494
|
init({
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
495
|
+
name: '@demo/app-main',
|
|
496
|
+
remotes: [
|
|
497
|
+
{
|
|
498
|
+
name: '@demo/app2',
|
|
499
|
+
entry: 'http://localhost:3006/remoteEntry.js',
|
|
500
|
+
alias: 'app2',
|
|
501
|
+
},
|
|
502
|
+
],
|
|
503
|
+
plugins: [fallbackPlugin()],
|
|
506
504
|
});
|
|
507
505
|
|
|
508
|
-
loadRemote('app2/un-existed-module').then(mod=>{
|
|
506
|
+
loadRemote('app2/un-existed-module').then((mod) => {
|
|
509
507
|
expect(mod).toEqual('fallback');
|
|
510
|
-
})
|
|
508
|
+
});
|
|
511
509
|
```
|
|
512
510
|
|
|
513
511
|
### beforeLoadShare
|
|
@@ -516,17 +514,17 @@ loadRemote('app2/un-existed-module').then(mod=>{
|
|
|
516
514
|
|
|
517
515
|
Called before attempting to load or negotiate shared modules between federated apps.
|
|
518
516
|
|
|
519
|
-
|
|
517
|
+
- type
|
|
520
518
|
|
|
521
519
|
```ts
|
|
522
|
-
async function beforeLoadShare(args: BeforeLoadShareOptions): Promise<BeforeLoadShareOptions
|
|
520
|
+
async function beforeLoadShare(args: BeforeLoadShareOptions): Promise<BeforeLoadShareOptions>;
|
|
523
521
|
|
|
524
|
-
type BeforeLoadShareOptions ={
|
|
522
|
+
type BeforeLoadShareOptions = {
|
|
525
523
|
pkgName: string;
|
|
526
524
|
shareInfo?: Shared;
|
|
527
525
|
shared: Options['shared'];
|
|
528
526
|
origin: FederationHost;
|
|
529
|
-
}
|
|
527
|
+
};
|
|
530
528
|
```
|
|
531
529
|
|
|
532
530
|
### resolveShare
|
|
@@ -535,70 +533,66 @@ type BeforeLoadShareOptions ={
|
|
|
535
533
|
|
|
536
534
|
Allows manual resolution of shared module requests.
|
|
537
535
|
|
|
538
|
-
|
|
536
|
+
- type
|
|
539
537
|
|
|
540
538
|
```ts
|
|
541
|
-
function resolveShare(args: ResolveShareOptions): ResolveShareOptions
|
|
539
|
+
function resolveShare(args: ResolveShareOptions): ResolveShareOptions;
|
|
542
540
|
|
|
543
|
-
type ResolveShareOptions ={
|
|
541
|
+
type ResolveShareOptions = {
|
|
544
542
|
shareScopeMap: ShareScopeMap;
|
|
545
543
|
scope: string;
|
|
546
544
|
pkgName: string;
|
|
547
545
|
version: string;
|
|
548
546
|
GlobalFederation: Federation;
|
|
549
547
|
resolver: () => Shared | undefined;
|
|
550
|
-
}
|
|
548
|
+
};
|
|
551
549
|
```
|
|
552
550
|
|
|
553
|
-
|
|
551
|
+
- example
|
|
554
552
|
|
|
555
553
|
```ts
|
|
556
|
-
import { init, loadRemote } from '@module-federation/runtime'
|
|
554
|
+
import { init, loadRemote } from '@module-federation/runtime';
|
|
557
555
|
|
|
558
556
|
import type { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
559
557
|
|
|
560
|
-
const customSharedPlugin: () => FederationRuntimePlugin =
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
if (
|
|
568
|
-
pkgName !== 'react'
|
|
569
|
-
) {
|
|
570
|
-
return args;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
args.resolver = function () {
|
|
574
|
-
shareScopeMap[scope][pkgName][version] = window.React; // replace local share scope manually with desired module
|
|
575
|
-
return shareScopeMap[scope][pkgName][version];
|
|
576
|
-
};
|
|
558
|
+
const customSharedPlugin: () => FederationRuntimePlugin = function () {
|
|
559
|
+
return {
|
|
560
|
+
name: 'custom-shared-plugin',
|
|
561
|
+
resolveShare(args) {
|
|
562
|
+
const { shareScopeMap, scope, pkgName, version, GlobalFederation } = args;
|
|
563
|
+
|
|
564
|
+
if (pkgName !== 'react') {
|
|
577
565
|
return args;
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
};
|
|
566
|
+
}
|
|
581
567
|
|
|
568
|
+
args.resolver = function () {
|
|
569
|
+
shareScopeMap[scope][pkgName][version] = window.React; // replace local share scope manually with desired module
|
|
570
|
+
return shareScopeMap[scope][pkgName][version];
|
|
571
|
+
};
|
|
572
|
+
return args;
|
|
573
|
+
},
|
|
574
|
+
};
|
|
575
|
+
};
|
|
582
576
|
|
|
583
577
|
init({
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
},
|
|
578
|
+
name: '@demo/app-main',
|
|
579
|
+
shared: {
|
|
580
|
+
react: {
|
|
581
|
+
version: '17.0.0',
|
|
582
|
+
scope: 'default',
|
|
583
|
+
lib: () => React,
|
|
584
|
+
shareConfig: {
|
|
585
|
+
singleton: true,
|
|
586
|
+
requiredVersion: '^17.0.0',
|
|
594
587
|
},
|
|
595
588
|
},
|
|
596
|
-
|
|
589
|
+
},
|
|
590
|
+
plugins: [customSharedPlugin()],
|
|
597
591
|
});
|
|
598
592
|
|
|
599
|
-
window.React = ()=> 'Desired Shared';
|
|
593
|
+
window.React = () => 'Desired Shared';
|
|
600
594
|
|
|
601
|
-
loadShare(
|
|
595
|
+
loadShare('react').then((reactFactory) => {
|
|
602
596
|
expect(reactFactory()).toEqual(window.React());
|
|
603
597
|
});
|
|
604
598
|
```
|
|
@@ -609,16 +603,16 @@ loadShare("react").then((reactFactory)=>{
|
|
|
609
603
|
|
|
610
604
|
Invoked before any preload logic is executed by the preload handler.
|
|
611
605
|
|
|
612
|
-
|
|
606
|
+
- type
|
|
613
607
|
|
|
614
608
|
```ts
|
|
615
|
-
async function beforePreloadRemote(args: BeforePreloadRemoteOptions): BeforePreloadRemoteOptions
|
|
609
|
+
async function beforePreloadRemote(args: BeforePreloadRemoteOptions): BeforePreloadRemoteOptions;
|
|
616
610
|
|
|
617
|
-
type BeforePreloadRemoteOptions ={
|
|
611
|
+
type BeforePreloadRemoteOptions = {
|
|
618
612
|
preloadOps: Array<PreloadRemoteArgs>;
|
|
619
613
|
options: Options;
|
|
620
614
|
origin: FederationHost;
|
|
621
|
-
}
|
|
615
|
+
};
|
|
622
616
|
```
|
|
623
617
|
|
|
624
618
|
### generatePreloadAssets
|
|
@@ -627,19 +621,19 @@ type BeforePreloadRemoteOptions ={
|
|
|
627
621
|
|
|
628
622
|
Called for generating preload assets based on configurations.
|
|
629
623
|
|
|
630
|
-
|
|
624
|
+
- type
|
|
631
625
|
|
|
632
626
|
```ts
|
|
633
|
-
async function generatePreloadAssets(args: GeneratePreloadAssetsOptions): Promise<PreloadAssets
|
|
627
|
+
async function generatePreloadAssets(args: GeneratePreloadAssetsOptions): Promise<PreloadAssets>;
|
|
634
628
|
|
|
635
|
-
type GeneratePreloadAssetsOptions ={
|
|
629
|
+
type GeneratePreloadAssetsOptions = {
|
|
636
630
|
origin: FederationHost;
|
|
637
631
|
preloadOptions: PreloadOptions[number];
|
|
638
632
|
remote: Remote;
|
|
639
633
|
remoteInfo: RemoteInfo;
|
|
640
634
|
remoteSnapshot: ModuleInfo;
|
|
641
635
|
globalSnapshot: GlobalModuleInfo;
|
|
642
|
-
}
|
|
636
|
+
};
|
|
643
637
|
|
|
644
638
|
interface PreloadAssets {
|
|
645
639
|
cssAssets: Array<string>;
|
|
@@ -656,35 +650,34 @@ Plugin system for module loading operations.
|
|
|
656
650
|
|
|
657
651
|
`SyncHook`
|
|
658
652
|
|
|
659
|
-
|
|
653
|
+
- type
|
|
660
654
|
|
|
661
655
|
```ts
|
|
662
|
-
function createScript(args: CreateScriptOptions): HTMLScriptElement | void
|
|
656
|
+
function createScript(args: CreateScriptOptions): HTMLScriptElement | void;
|
|
663
657
|
|
|
664
|
-
type CreateScriptOptions ={
|
|
658
|
+
type CreateScriptOptions = {
|
|
665
659
|
url: string;
|
|
666
|
-
}
|
|
660
|
+
};
|
|
667
661
|
```
|
|
668
662
|
|
|
669
|
-
|
|
663
|
+
- example
|
|
670
664
|
|
|
671
665
|
```ts
|
|
672
|
-
import { init } from '@module-federation/runtime'
|
|
666
|
+
import { init } from '@module-federation/runtime';
|
|
673
667
|
import type { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
674
668
|
|
|
675
|
-
const changeScriptAttributePlugin: () => FederationRuntimePlugin =
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
return script;
|
|
686
|
-
}
|
|
669
|
+
const changeScriptAttributePlugin: () => FederationRuntimePlugin = function () {
|
|
670
|
+
return {
|
|
671
|
+
name: 'change-script-attribute',
|
|
672
|
+
createScript({ url }) {
|
|
673
|
+
if (url === testRemoteEntry) {
|
|
674
|
+
let script = document.createElement('script');
|
|
675
|
+
script.src = testRemoteEntry;
|
|
676
|
+
script.setAttribute('loader-hooks', 'isTrue');
|
|
677
|
+
script.setAttribute('crossorigin', 'anonymous');
|
|
678
|
+
return script;
|
|
687
679
|
}
|
|
688
|
-
}
|
|
680
|
+
},
|
|
689
681
|
};
|
|
682
|
+
};
|
|
690
683
|
```
|
package/dist/index.cjs.js
CHANGED
|
@@ -107,7 +107,10 @@ async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
|
107
107
|
try {
|
|
108
108
|
if (!remoteEntryExports) {
|
|
109
109
|
// eslint-disable-next-line no-eval
|
|
110
|
-
new Function('
|
|
110
|
+
new Function('callbacks', `import("${entry}").then(callbacks[0]).catch(callbacks[1])`)([
|
|
111
|
+
resolve,
|
|
112
|
+
reject
|
|
113
|
+
]);
|
|
111
114
|
} else {
|
|
112
115
|
resolve(remoteEntryExports);
|
|
113
116
|
}
|
|
@@ -136,7 +139,6 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
136
139
|
1. '${entry}' is not the correct URL, or the remoteEntry resource or name is incorrect.\n
|
|
137
140
|
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
138
141
|
`);
|
|
139
|
-
console.log(entryExports);
|
|
140
142
|
return entryExports;
|
|
141
143
|
}).catch((e)=>{
|
|
142
144
|
return e;
|
|
@@ -1276,6 +1278,19 @@ class FederationHost {
|
|
|
1276
1278
|
2. The ${pkgName} share was not registered with the 'lib' attribute.\n
|
|
1277
1279
|
`);
|
|
1278
1280
|
}
|
|
1281
|
+
initRawContainer(name, url, container) {
|
|
1282
|
+
const remoteInfo = getRemoteInfo({
|
|
1283
|
+
name,
|
|
1284
|
+
entry: url
|
|
1285
|
+
});
|
|
1286
|
+
const module = new Module({
|
|
1287
|
+
host: this,
|
|
1288
|
+
remoteInfo
|
|
1289
|
+
});
|
|
1290
|
+
module.remoteEntryExports = container;
|
|
1291
|
+
this.moduleCache.set(name, module);
|
|
1292
|
+
return module;
|
|
1293
|
+
}
|
|
1279
1294
|
async _getRemoteModuleAndOptions(id) {
|
|
1280
1295
|
const loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
1281
1296
|
id,
|
|
@@ -1590,7 +1605,7 @@ class FederationHost {
|
|
|
1590
1605
|
// not used yet
|
|
1591
1606
|
afterPreloadRemote: new AsyncHook()
|
|
1592
1607
|
});
|
|
1593
|
-
this.version = "0.0.
|
|
1608
|
+
this.version = "0.0.15";
|
|
1594
1609
|
this.moduleCache = new Map();
|
|
1595
1610
|
this.loaderHook = new PluginSystem({
|
|
1596
1611
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -1673,6 +1688,10 @@ Object.defineProperty(exports, 'loadScript', {
|
|
|
1673
1688
|
enumerable: true,
|
|
1674
1689
|
get: function () { return sdk.loadScript; }
|
|
1675
1690
|
});
|
|
1691
|
+
Object.defineProperty(exports, 'loadScriptNode', {
|
|
1692
|
+
enumerable: true,
|
|
1693
|
+
get: function () { return sdk.loadScriptNode; }
|
|
1694
|
+
});
|
|
1676
1695
|
exports.FederationHost = FederationHost;
|
|
1677
1696
|
exports.init = init;
|
|
1678
1697
|
exports.loadRemote = loadRemote;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { g as getGlobalHostPlugins, D as DEFAULT_REMOTE_TYPE, a as DEFAULT_SCOPE, b as globalLoading, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getRegisteredShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as addGlobalSnapshot, r as setGlobalSnapshotInfoByModuleInfo, t as getGlobalSnapshot, G as Global, u as getGlobalShareScope, v as formatShareConfigs, x as isBrowserEnv, y as getBuilderId, z as addUniqueItem, A as setGlobalFederationConstructor, B as getGlobalFederationInstance, C as getGlobalFederationConstructor, E as setGlobalFederationInstance } from './share.esm.js';
|
|
2
2
|
export { F as registerGlobalPlugins } from './share.esm.js';
|
|
3
3
|
import { composeKeyWithSeparator, loadScriptNode, loadScript, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
|
|
4
|
-
export { loadScript } from '@module-federation/sdk';
|
|
4
|
+
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
5
5
|
|
|
6
6
|
// Function to match a remote with its name and expose
|
|
7
7
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
@@ -105,7 +105,10 @@ async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
|
105
105
|
try {
|
|
106
106
|
if (!remoteEntryExports) {
|
|
107
107
|
// eslint-disable-next-line no-eval
|
|
108
|
-
new Function('
|
|
108
|
+
new Function('callbacks', `import("${entry}").then(callbacks[0]).catch(callbacks[1])`)([
|
|
109
|
+
resolve,
|
|
110
|
+
reject
|
|
111
|
+
]);
|
|
109
112
|
} else {
|
|
110
113
|
resolve(remoteEntryExports);
|
|
111
114
|
}
|
|
@@ -134,7 +137,6 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
134
137
|
1. '${entry}' is not the correct URL, or the remoteEntry resource or name is incorrect.\n
|
|
135
138
|
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
136
139
|
`);
|
|
137
|
-
console.log(entryExports);
|
|
138
140
|
return entryExports;
|
|
139
141
|
}).catch((e)=>{
|
|
140
142
|
return e;
|
|
@@ -1274,6 +1276,19 @@ class FederationHost {
|
|
|
1274
1276
|
2. The ${pkgName} share was not registered with the 'lib' attribute.\n
|
|
1275
1277
|
`);
|
|
1276
1278
|
}
|
|
1279
|
+
initRawContainer(name, url, container) {
|
|
1280
|
+
const remoteInfo = getRemoteInfo({
|
|
1281
|
+
name,
|
|
1282
|
+
entry: url
|
|
1283
|
+
});
|
|
1284
|
+
const module = new Module({
|
|
1285
|
+
host: this,
|
|
1286
|
+
remoteInfo
|
|
1287
|
+
});
|
|
1288
|
+
module.remoteEntryExports = container;
|
|
1289
|
+
this.moduleCache.set(name, module);
|
|
1290
|
+
return module;
|
|
1291
|
+
}
|
|
1277
1292
|
async _getRemoteModuleAndOptions(id) {
|
|
1278
1293
|
const loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
1279
1294
|
id,
|
|
@@ -1588,7 +1603,7 @@ class FederationHost {
|
|
|
1588
1603
|
// not used yet
|
|
1589
1604
|
afterPreloadRemote: new AsyncHook()
|
|
1590
1605
|
});
|
|
1591
|
-
this.version = "0.0.
|
|
1606
|
+
this.version = "0.0.15";
|
|
1592
1607
|
this.moduleCache = new Map();
|
|
1593
1608
|
this.loaderHook = new PluginSystem({
|
|
1594
1609
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -19,10 +19,19 @@ function assert(condition, msg) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
function error(msg) {
|
|
22
|
+
if (msg instanceof Error) {
|
|
23
|
+
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
24
|
+
throw msg;
|
|
25
|
+
}
|
|
22
26
|
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
23
27
|
}
|
|
24
28
|
function warn(msg) {
|
|
25
|
-
|
|
29
|
+
if (msg instanceof Error) {
|
|
30
|
+
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
31
|
+
console.warn(msg);
|
|
32
|
+
} else {
|
|
33
|
+
console.warn(`${LOG_CATEGORY}: ${msg}`);
|
|
34
|
+
}
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
function addUniqueItem(arr, item) {
|
|
@@ -176,7 +185,7 @@ function getGlobalFederationConstructor() {
|
|
|
176
185
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
177
186
|
if (isDebug) {
|
|
178
187
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
179
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.
|
|
188
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.15";
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
191
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/share.esm.js
CHANGED
|
@@ -17,10 +17,19 @@ function assert(condition, msg) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
function error(msg) {
|
|
20
|
+
if (msg instanceof Error) {
|
|
21
|
+
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
22
|
+
throw msg;
|
|
23
|
+
}
|
|
20
24
|
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
21
25
|
}
|
|
22
26
|
function warn(msg) {
|
|
23
|
-
|
|
27
|
+
if (msg instanceof Error) {
|
|
28
|
+
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
29
|
+
console.warn(msg);
|
|
30
|
+
} else {
|
|
31
|
+
console.warn(`${LOG_CATEGORY}: ${msg}`);
|
|
32
|
+
}
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
function addUniqueItem(arr, item) {
|
|
@@ -174,7 +183,7 @@ function getGlobalFederationConstructor() {
|
|
|
174
183
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
175
184
|
if (isDebug) {
|
|
176
185
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
177
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.
|
|
186
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.15";
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
189
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/src/core.d.ts
CHANGED
|
@@ -136,6 +136,7 @@ export declare class FederationHost {
|
|
|
136
136
|
initOptions(userOptions: UserOptions): Options;
|
|
137
137
|
loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
|
|
138
138
|
loadShareSync<T>(pkgName: string, customShareInfo?: Partial<Shared>): () => T | never;
|
|
139
|
+
initRawContainer(name: string, url: string, container: RemoteEntryExports): Module;
|
|
139
140
|
private _getRemoteModuleAndOptions;
|
|
140
141
|
loadRemote<T>(id: string, options?: {
|
|
141
142
|
loadFactory?: boolean;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FederationHost } from './core';
|
|
|
2
2
|
import { UserOptions, FederationRuntimePlugin } from './type';
|
|
3
3
|
export { FederationHost } from './core';
|
|
4
4
|
export { registerGlobalPlugins } from './global';
|
|
5
|
-
export { loadScript } from '@module-federation/sdk';
|
|
5
|
+
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
6
6
|
export type { Federation } from './global';
|
|
7
7
|
export type { FederationRuntimePlugin };
|
|
8
8
|
export declare function init(options: UserOptions): FederationHost;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@module-federation/sdk": "0.0.
|
|
48
|
+
"@module-federation/sdk": "0.0.15"
|
|
49
49
|
}
|
|
50
50
|
}
|