@module-federation/utilities 1.1.0 → 1.1.2
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/CHANGELOG.md +13 -0
- package/package.json +3 -2
- package/src/utils/common.d.ts +2 -4
- package/src/utils/common.js +37 -37
- package/src/utils/common.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [1.1.2](https://github.com/module-federation/nextjs-mf/compare/utils-1.1.1...utils-1.1.2) (2023-01-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* Utilities - Remove module side effect ([#488](https://github.com/module-federation/nextjs-mf/issues/488)) ([3554de7](https://github.com/module-federation/nextjs-mf/commit/3554de7912eaf7b379a6a863677c4b01da0ccf2c)), closes [#487](https://github.com/module-federation/nextjs-mf/issues/487) [#500](https://github.com/module-federation/nextjs-mf/issues/500) [#496](https://github.com/module-federation/nextjs-mf/issues/496) [#495](https://github.com/module-federation/nextjs-mf/issues/495) [#492](https://github.com/module-federation/nextjs-mf/issues/492) [#455](https://github.com/module-federation/nextjs-mf/issues/455) [#491](https://github.com/module-federation/nextjs-mf/issues/491) [#496](https://github.com/module-federation/nextjs-mf/issues/496) [#495](https://github.com/module-federation/nextjs-mf/issues/495)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.1.1](https://github.com/module-federation/nextjs-mf/compare/utils-1.1.0...utils-1.1.1) (2023-01-11)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
5
18
|
# [1.1.0](https://github.com/module-federation/nextjs-mf/compare/utils-1.0.4...utils-1.1.0) (2022-12-30)
|
|
6
19
|
|
|
7
20
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/utilities",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
7
8
|
"publishConfig": {
|
|
8
9
|
"registry": "https://registry.npmjs.org/"
|
|
9
10
|
},
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"react": "18.2.0",
|
|
17
|
-
"next": "13.
|
|
18
|
+
"next": "13.1.2"
|
|
18
19
|
},
|
|
19
20
|
"peerDependencies": {
|
|
20
21
|
"webpack": "^5.40.0"
|
package/src/utils/common.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { Remotes,
|
|
1
|
+
import type { Remotes, RuntimeRemote, WebpackRemoteContainer } from '../types';
|
|
2
2
|
export declare const extractUrlAndGlobal: (urlAndGlobal: string) => [string, string];
|
|
3
|
-
export declare const runtimeRemotes: RuntimeRemotesMap;
|
|
4
|
-
export declare const remotes: RuntimeRemotesMap;
|
|
5
3
|
/**
|
|
6
4
|
* Return initialized remote container by remote's key or its runtime remote item data.
|
|
7
5
|
*
|
|
@@ -10,5 +8,5 @@ export declare const remotes: RuntimeRemotesMap;
|
|
|
10
8
|
* or
|
|
11
9
|
* { asyncContainer } - async container is a promise that resolves to the remote container
|
|
12
10
|
*/
|
|
13
|
-
export declare const injectScript: (keyOrRuntimeRemoteItem: string | RuntimeRemote) => Promise<
|
|
11
|
+
export declare const injectScript: (keyOrRuntimeRemoteItem: string | RuntimeRemote) => Promise<WebpackRemoteContainer>;
|
|
14
12
|
export declare const createRuntimeVariables: (remotes: Remotes) => Record<string, string>;
|
package/src/utils/common.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.createRuntimeVariables = exports.injectScript = exports.
|
|
5
|
-
var remoteVars = {};
|
|
6
|
-
try {
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
remoteVars = (process.env.REMOTES || {});
|
|
9
|
-
}
|
|
10
|
-
catch (e) {
|
|
11
|
-
console.error('Error parsing REMOTES environment variable', e);
|
|
12
|
-
}
|
|
4
|
+
exports.createRuntimeVariables = exports.injectScript = exports.extractUrlAndGlobal = void 0;
|
|
13
5
|
// split the @ syntax into url and global
|
|
14
6
|
var extractUrlAndGlobal = function (urlAndGlobal) {
|
|
15
7
|
var index = urlAndGlobal.indexOf('@');
|
|
@@ -19,31 +11,35 @@ var extractUrlAndGlobal = function (urlAndGlobal) {
|
|
|
19
11
|
return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)];
|
|
20
12
|
};
|
|
21
13
|
exports.extractUrlAndGlobal = extractUrlAndGlobal;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
14
|
+
var getRuntimeRemotes = function () {
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
var remoteVars = (process.env.REMOTES || {});
|
|
17
|
+
var runtimeRemotes = Object.entries(remoteVars).reduce(function (acc, item) {
|
|
18
|
+
var key = item[0], value = item[1];
|
|
19
|
+
// if its an object with a thenable (eagerly executing function)
|
|
20
|
+
if (typeof value === 'object' && typeof value.then === 'function') {
|
|
21
|
+
acc[key] = { asyncContainer: value };
|
|
22
|
+
}
|
|
23
|
+
// if its a function that must be called (lazily executing function)
|
|
24
|
+
else if (typeof value === 'function') {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
acc[key] = { asyncContainer: value };
|
|
27
|
+
}
|
|
28
|
+
// if its just a string (global@url)
|
|
29
|
+
else if (typeof value === 'string') {
|
|
30
|
+
var _a = (0, exports.extractUrlAndGlobal)(value), url = _a[0], global_1 = _a[1];
|
|
31
|
+
acc[key] = { global: global_1, url: url };
|
|
32
|
+
}
|
|
33
|
+
// we dont know or currently support this type
|
|
34
|
+
else {
|
|
35
|
+
//@ts-ignore
|
|
36
|
+
console.log('remotes process', process.env.REMOTES);
|
|
37
|
+
throw new Error("[mf] Invalid value received for runtime_remote \"".concat(key, "\""));
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
}, {});
|
|
41
|
+
return runtimeRemotes;
|
|
42
|
+
};
|
|
47
43
|
/**
|
|
48
44
|
* Return initialized remote container by remote's key or its runtime remote item data.
|
|
49
45
|
*
|
|
@@ -53,14 +49,18 @@ exports.remotes = exports.runtimeRemotes;
|
|
|
53
49
|
* { asyncContainer } - async container is a promise that resolves to the remote container
|
|
54
50
|
*/
|
|
55
51
|
var injectScript = function (keyOrRuntimeRemoteItem) {
|
|
52
|
+
var runtimeRemotes = getRuntimeRemotes();
|
|
56
53
|
// 1) Load remote container if needed
|
|
57
54
|
var asyncContainer;
|
|
58
55
|
var reference = typeof keyOrRuntimeRemoteItem === 'string'
|
|
59
|
-
?
|
|
56
|
+
? runtimeRemotes[keyOrRuntimeRemoteItem]
|
|
60
57
|
: keyOrRuntimeRemoteItem;
|
|
61
58
|
if (reference.asyncContainer) {
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
asyncContainer =
|
|
60
|
+
typeof reference.asyncContainer.then === 'function'
|
|
61
|
+
? reference.asyncContainer
|
|
62
|
+
: // @ts-ignore
|
|
63
|
+
reference.asyncContainer();
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
66
|
// This casting is just to satisfy typescript,
|
package/src/utils/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/common.ts"],"names":[],"mappings":";AAAA,sDAAsD;;;
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/common.ts"],"names":[],"mappings":";AAAA,sDAAsD;;;AAiBtD,yCAAyC;AAClC,IAAM,mBAAmB,GAAG,UAAC,YAAoB;IACtD,IAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,KAAK,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QACnD,MAAM,IAAI,KAAK,CAAC,4BAAoB,YAAY,OAAG,CAAC,CAAC;KACtD;IACD,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AAC/E,CAAC,CAAC;AANW,QAAA,mBAAmB,uBAM9B;AAEF,IAAM,iBAAiB,GAAG;IACxB,YAAY;IACZ,IAAM,UAAU,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAe,CAAC;IAE7D,IAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,UACvD,GAAG,EACH,IAAI;QAEG,IAAA,GAAG,GAAW,IAAI,GAAf,EAAE,KAAK,GAAI,IAAI,GAAR,CAAS;QAC1B,gEAAgE;QAChE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE;YACjE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;SACtC;QACD,oEAAoE;aAC/D,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;YACpC,aAAa;YAC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