@module-federation/sdk 0.0.0-next-20240820034939 → 0.0.0-next-20240821090741
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/index.cjs.js +13 -7
- package/dist/index.esm.js +13 -7
- package/dist/package.json +1 -1
- package/dist/src/dom.d.ts +4 -7
- package/dist/src/node.d.ts +3 -2
- package/dist/src/types/hooks.d.ts +11 -0
- package/dist/src/types/index.d.ts +1 -0
- package/dist/src/types/plugins/ModuleFederationPlugin.d.ts +9 -0
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -435,17 +435,22 @@ function createScript(info) {
|
|
|
435
435
|
script = document.createElement('script');
|
|
436
436
|
script.type = 'text/javascript';
|
|
437
437
|
script.src = info.url;
|
|
438
|
+
let createScriptRes = undefined;
|
|
438
439
|
if (info.createScriptHook) {
|
|
439
|
-
|
|
440
|
+
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
440
441
|
if (createScriptRes instanceof HTMLScriptElement) {
|
|
441
442
|
script = createScriptRes;
|
|
442
443
|
} else if (typeof createScriptRes === 'object') {
|
|
443
|
-
if (
|
|
444
|
-
|
|
444
|
+
if ('script' in createScriptRes && createScriptRes.script) {
|
|
445
|
+
script = createScriptRes.script;
|
|
446
|
+
}
|
|
447
|
+
if ('timeout' in createScriptRes && createScriptRes.timeout) {
|
|
448
|
+
timeout = createScriptRes.timeout;
|
|
449
|
+
}
|
|
445
450
|
}
|
|
446
451
|
}
|
|
447
452
|
const attrs = info.attrs;
|
|
448
|
-
if (attrs) {
|
|
453
|
+
if (attrs && !createScriptRes) {
|
|
449
454
|
Object.keys(attrs).forEach((name)=>{
|
|
450
455
|
if (script) {
|
|
451
456
|
if (name === 'async' || name === 'defer') {
|
|
@@ -511,14 +516,15 @@ function createLink(info) {
|
|
|
511
516
|
if (!link) {
|
|
512
517
|
link = document.createElement('link');
|
|
513
518
|
link.setAttribute('href', info.url);
|
|
519
|
+
let createLinkRes = undefined;
|
|
520
|
+
const attrs = info.attrs;
|
|
514
521
|
if (info.createLinkHook) {
|
|
515
|
-
|
|
522
|
+
createLinkRes = info.createLinkHook(info.url, attrs);
|
|
516
523
|
if (createLinkRes instanceof HTMLLinkElement) {
|
|
517
524
|
link = createLinkRes;
|
|
518
525
|
}
|
|
519
526
|
}
|
|
520
|
-
|
|
521
|
-
if (attrs) {
|
|
527
|
+
if (attrs && !createLinkRes) {
|
|
522
528
|
Object.keys(attrs).forEach((name)=>{
|
|
523
529
|
if (link && !link.getAttribute(name)) {
|
|
524
530
|
link.setAttribute(name, attrs[name]);
|
package/dist/index.esm.js
CHANGED
|
@@ -431,17 +431,22 @@ function createScript(info) {
|
|
|
431
431
|
script = document.createElement('script');
|
|
432
432
|
script.type = 'text/javascript';
|
|
433
433
|
script.src = info.url;
|
|
434
|
+
let createScriptRes = undefined;
|
|
434
435
|
if (info.createScriptHook) {
|
|
435
|
-
|
|
436
|
+
createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
436
437
|
if (createScriptRes instanceof HTMLScriptElement) {
|
|
437
438
|
script = createScriptRes;
|
|
438
439
|
} else if (typeof createScriptRes === 'object') {
|
|
439
|
-
if (
|
|
440
|
-
|
|
440
|
+
if ('script' in createScriptRes && createScriptRes.script) {
|
|
441
|
+
script = createScriptRes.script;
|
|
442
|
+
}
|
|
443
|
+
if ('timeout' in createScriptRes && createScriptRes.timeout) {
|
|
444
|
+
timeout = createScriptRes.timeout;
|
|
445
|
+
}
|
|
441
446
|
}
|
|
442
447
|
}
|
|
443
448
|
const attrs = info.attrs;
|
|
444
|
-
if (attrs) {
|
|
449
|
+
if (attrs && !createScriptRes) {
|
|
445
450
|
Object.keys(attrs).forEach((name)=>{
|
|
446
451
|
if (script) {
|
|
447
452
|
if (name === 'async' || name === 'defer') {
|
|
@@ -507,14 +512,15 @@ function createLink(info) {
|
|
|
507
512
|
if (!link) {
|
|
508
513
|
link = document.createElement('link');
|
|
509
514
|
link.setAttribute('href', info.url);
|
|
515
|
+
let createLinkRes = undefined;
|
|
516
|
+
const attrs = info.attrs;
|
|
510
517
|
if (info.createLinkHook) {
|
|
511
|
-
|
|
518
|
+
createLinkRes = info.createLinkHook(info.url, attrs);
|
|
512
519
|
if (createLinkRes instanceof HTMLLinkElement) {
|
|
513
520
|
link = createLinkRes;
|
|
514
521
|
}
|
|
515
522
|
}
|
|
516
|
-
|
|
517
|
-
if (attrs) {
|
|
523
|
+
if (attrs && !createLinkRes) {
|
|
518
524
|
Object.keys(attrs).forEach((name)=>{
|
|
519
525
|
if (link && !link.getAttribute(name)) {
|
|
520
526
|
link.setAttribute(name, attrs[name]);
|
package/dist/package.json
CHANGED
package/dist/src/dom.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
+
import { CreateScriptHookDom } from './types';
|
|
1
2
|
export declare function safeWrapper<T extends (...args: Array<any>) => any>(callback: T, disableWarn?: boolean): Promise<ReturnType<T> | undefined>;
|
|
2
3
|
export declare function isStaticResourcesEqual(url1: string, url2: string): boolean;
|
|
3
|
-
export type CreateScriptHookReturn = HTMLScriptElement | {
|
|
4
|
-
script?: HTMLScriptElement;
|
|
5
|
-
timeout?: number;
|
|
6
|
-
} | void;
|
|
7
4
|
export declare function createScript(info: {
|
|
8
5
|
url: string;
|
|
9
6
|
cb?: (value: void | PromiseLike<void>) => void;
|
|
10
7
|
attrs?: Record<string, any>;
|
|
11
8
|
needDeleteScript?: boolean;
|
|
12
|
-
createScriptHook?:
|
|
9
|
+
createScriptHook?: CreateScriptHookDom;
|
|
13
10
|
}): {
|
|
14
11
|
script: HTMLScriptElement;
|
|
15
12
|
needAttach: boolean;
|
|
@@ -19,12 +16,12 @@ export declare function createLink(info: {
|
|
|
19
16
|
cb: (value: void | PromiseLike<void>) => void;
|
|
20
17
|
attrs: Record<string, string>;
|
|
21
18
|
needDeleteLink?: boolean;
|
|
22
|
-
createLinkHook?: (url: string) => HTMLLinkElement | void;
|
|
19
|
+
createLinkHook?: (url: string, attrs?: Record<string, any>) => HTMLLinkElement | void;
|
|
23
20
|
}): {
|
|
24
21
|
link: HTMLLinkElement;
|
|
25
22
|
needAttach: boolean;
|
|
26
23
|
};
|
|
27
24
|
export declare function loadScript(url: string, info: {
|
|
28
25
|
attrs?: Record<string, any>;
|
|
29
|
-
createScriptHook?:
|
|
26
|
+
createScriptHook?: CreateScriptHookDom;
|
|
30
27
|
}): Promise<void>;
|
package/dist/src/node.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { CreateScriptHookNode } from './types';
|
|
2
|
+
export declare function createScriptNode(url: string, cb: (error?: Error, scriptContext?: any) => void, attrs?: Record<string, any>, createScriptHook?: CreateScriptHookNode): void;
|
|
2
3
|
export declare function loadScriptNode(url: string, info: {
|
|
3
4
|
attrs?: Record<string, any>;
|
|
4
|
-
createScriptHook?:
|
|
5
|
+
createScriptHook?: CreateScriptHookNode;
|
|
5
6
|
}): Promise<void>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type CreateScriptHookReturnNode = {
|
|
2
|
+
url: string;
|
|
3
|
+
} | void;
|
|
4
|
+
export type CreateScriptHookReturnDom = HTMLScriptElement | {
|
|
5
|
+
script?: HTMLScriptElement;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
} | void;
|
|
8
|
+
export type CreateScriptHookReturn = CreateScriptHookReturnNode | CreateScriptHookReturnDom;
|
|
9
|
+
export type CreateScriptHookNode = (url: string, attrs?: Record<string, any> | undefined) => CreateScriptHookReturnNode;
|
|
10
|
+
export type CreateScriptHookDom = (url: string, attrs?: Record<string, any> | undefined) => CreateScriptHookReturnDom;
|
|
11
|
+
export type CreateScriptHook = (url: string, attrs?: Record<string, any> | undefined) => CreateScriptHookReturn;
|
|
@@ -150,6 +150,10 @@ export interface ModuleFederationPluginOptions {
|
|
|
150
150
|
* Share scope name used for all shared modules (defaults to 'default').
|
|
151
151
|
*/
|
|
152
152
|
shareScope?: string;
|
|
153
|
+
/**
|
|
154
|
+
* load shared strategy(defaults to 'version-first').
|
|
155
|
+
*/
|
|
156
|
+
shareStrategy?: SharedStrategy;
|
|
153
157
|
/**
|
|
154
158
|
* Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.
|
|
155
159
|
*/
|
|
@@ -291,6 +295,7 @@ export interface SharedObject {
|
|
|
291
295
|
*/
|
|
292
296
|
[k: string]: SharedConfig | SharedItem;
|
|
293
297
|
}
|
|
298
|
+
export type SharedStrategy = 'version-first' | 'loaded-first';
|
|
294
299
|
/**
|
|
295
300
|
* Advanced configuration for modules that should be shared in the share scope.
|
|
296
301
|
*/
|
|
@@ -319,6 +324,10 @@ export interface SharedConfig {
|
|
|
319
324
|
* Share scope name.
|
|
320
325
|
*/
|
|
321
326
|
shareScope?: string;
|
|
327
|
+
/**
|
|
328
|
+
* load shared strategy(defaults to 'version-first').
|
|
329
|
+
*/
|
|
330
|
+
shareStrategy?: SharedStrategy;
|
|
322
331
|
/**
|
|
323
332
|
* Allow only a single version of the shared module in share scope (disabled by default).
|
|
324
333
|
*/
|