chayns-api 1.1.0-23 → 1.1.0-25
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/host/module/utils/loadComponent.js +18 -1
- package/dist/esm/host/module/utils/loadComponent.js +23 -3
- package/dist/types/host/module/utils/loadComponent.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/host/module/utils/useDynamicScript.js +0 -59
- package/dist/esm/host/module/utils/useDynamicScript.js +0 -50
- package/dist/types/host/module/utils/useDynamicScript.d.ts +0 -9
|
@@ -30,7 +30,12 @@ const componentMap = {};
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
const loadModule = (scope, module, url, preventSingleton = false) => {
|
|
33
|
+
const loadModule = async (scope, module, url, preventSingleton = false) => {
|
|
34
|
+
// @ts-expect-error
|
|
35
|
+
if (typeof __webpack_init_sharing__ === 'function') {
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
await __webpack_init_sharing__('default');
|
|
38
|
+
}
|
|
34
39
|
if (registeredScopes[scope] !== url || preventSingleton) {
|
|
35
40
|
if (scope in registeredScopes) {
|
|
36
41
|
console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
|
|
@@ -77,9 +82,21 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
|
|
|
77
82
|
environment
|
|
78
83
|
} = Module.default;
|
|
79
84
|
const shareScopes = await new Promise(resolve => {
|
|
85
|
+
// @ts-expect-error
|
|
86
|
+
if (typeof __webpack_share_scopes__ !== 'undefined') {
|
|
87
|
+
// @ts-expect-error
|
|
88
|
+
const shareScopes = __webpack_share_scopes__.default;
|
|
89
|
+
console.log('__webpack_share_scopes__', shareScopes);
|
|
90
|
+
const shareList = Object.entries(shareScopes.react).map(([k, v]) => ({
|
|
91
|
+
version: k,
|
|
92
|
+
from: v.from
|
|
93
|
+
}));
|
|
94
|
+
resolve(shareList);
|
|
95
|
+
}
|
|
80
96
|
(0, _runtime.loadShareSync)('react', {
|
|
81
97
|
resolver: shareOptions => {
|
|
82
98
|
resolve(shareOptions);
|
|
99
|
+
console.log('mf runtime share scopes', shareOptions);
|
|
83
100
|
return shareOptions[0];
|
|
84
101
|
}
|
|
85
102
|
});
|
|
@@ -23,8 +23,13 @@ init({
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
export const loadModule = function (scope, module, url) {
|
|
26
|
+
export const loadModule = async function (scope, module, url) {
|
|
27
27
|
let preventSingleton = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
if (typeof __webpack_init_sharing__ === 'function') {
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
await __webpack_init_sharing__('default');
|
|
32
|
+
}
|
|
28
33
|
if (registeredScopes[scope] !== url || preventSingleton) {
|
|
29
34
|
if (scope in registeredScopes) {
|
|
30
35
|
console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
|
|
@@ -72,18 +77,33 @@ const loadComponent = function (scope, module, url) {
|
|
|
72
77
|
environment
|
|
73
78
|
} = Module.default;
|
|
74
79
|
const shareScopes = await new Promise(resolve => {
|
|
80
|
+
// @ts-expect-error
|
|
81
|
+
if (typeof __webpack_share_scopes__ !== 'undefined') {
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
const shareScopes = __webpack_share_scopes__.default;
|
|
84
|
+
console.log('__webpack_share_scopes__', shareScopes);
|
|
85
|
+
const shareList = Object.entries(shareScopes.react).map(_ref => {
|
|
86
|
+
let [k, v] = _ref;
|
|
87
|
+
return {
|
|
88
|
+
version: k,
|
|
89
|
+
from: v.from
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
resolve(shareList);
|
|
93
|
+
}
|
|
75
94
|
loadShareSync('react', {
|
|
76
95
|
resolver: shareOptions => {
|
|
77
96
|
resolve(shareOptions);
|
|
97
|
+
console.log('mf runtime share scopes', shareOptions);
|
|
78
98
|
return shareOptions[0];
|
|
79
99
|
}
|
|
80
100
|
});
|
|
81
101
|
});
|
|
82
|
-
const matchReactVersion = requiredVersion && semver.satisfies(hostVersion, requiredVersion) && !shareScopes.some(
|
|
102
|
+
const matchReactVersion = requiredVersion && semver.satisfies(hostVersion, requiredVersion) && !shareScopes.some(_ref2 => {
|
|
83
103
|
let {
|
|
84
104
|
version,
|
|
85
105
|
from
|
|
86
|
-
} =
|
|
106
|
+
} = _ref2;
|
|
87
107
|
return semver.gt(version, hostVersion) && semver.satisfies(version, requiredVersion) || scope === from.split('-').join('_');
|
|
88
108
|
});
|
|
89
109
|
if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const loadModule: (scope: any, module: any, url: any, preventSingleton?: boolean) => any
|
|
1
|
+
export declare const loadModule: (scope: any, module: any, url: any, preventSingleton?: boolean) => Promise<any>;
|
|
2
2
|
declare const loadComponent: (scope: any, module: any, url: any, skipCompatMode?: boolean, preventSingleton?: boolean) => any;
|
|
3
3
|
export default loadComponent;
|
package/package.json
CHANGED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.semaphore = exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _semaphoreAsyncAwait = _interopRequireDefault(require("semaphore-async-await"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
-
const semaphore = exports.semaphore = {};
|
|
13
|
-
const useDynamicScript = args => {
|
|
14
|
-
const [ready, setReady] = _react.default.useState(false);
|
|
15
|
-
const [failed, setFailed] = _react.default.useState(false);
|
|
16
|
-
(0, _react.useEffect)(() => {
|
|
17
|
-
if (!args.url) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
const element = document.createElement('script');
|
|
21
|
-
element.src = args.url;
|
|
22
|
-
element.type = 'text/javascript';
|
|
23
|
-
element.async = true;
|
|
24
|
-
setReady(false);
|
|
25
|
-
setFailed(false);
|
|
26
|
-
if (!(args.scope in semaphore)) {
|
|
27
|
-
semaphore[args.scope] = new _semaphoreAsyncAwait.default(1);
|
|
28
|
-
}
|
|
29
|
-
(async () => {
|
|
30
|
-
await semaphore[args.scope].acquire();
|
|
31
|
-
element.onload = () => {
|
|
32
|
-
setReady(true);
|
|
33
|
-
const listKey = args.scope + "_list";
|
|
34
|
-
if (!window[listKey]) window[listKey] = [];
|
|
35
|
-
window[listKey].push({
|
|
36
|
-
url: args.url,
|
|
37
|
-
container: window[args.scope]
|
|
38
|
-
});
|
|
39
|
-
window[args.scope] = null;
|
|
40
|
-
};
|
|
41
|
-
element.onerror = () => {
|
|
42
|
-
setReady(false);
|
|
43
|
-
setFailed(true);
|
|
44
|
-
};
|
|
45
|
-
document.head.appendChild(element);
|
|
46
|
-
})();
|
|
47
|
-
return () => {
|
|
48
|
-
semaphore[args.scope].release();
|
|
49
|
-
if (document.head.contains(element)) {
|
|
50
|
-
document.head.removeChild(element);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}, [args.url]);
|
|
54
|
-
return {
|
|
55
|
-
ready,
|
|
56
|
-
failed
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
var _default = exports.default = useDynamicScript;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import Semaphore from 'semaphore-async-await';
|
|
3
|
-
export const semaphore = {};
|
|
4
|
-
const useDynamicScript = args => {
|
|
5
|
-
const [ready, setReady] = React.useState(false);
|
|
6
|
-
const [failed, setFailed] = React.useState(false);
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
if (!args.url) {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
const element = document.createElement('script');
|
|
12
|
-
element.src = args.url;
|
|
13
|
-
element.type = 'text/javascript';
|
|
14
|
-
element.async = true;
|
|
15
|
-
setReady(false);
|
|
16
|
-
setFailed(false);
|
|
17
|
-
if (!(args.scope in semaphore)) {
|
|
18
|
-
semaphore[args.scope] = new Semaphore(1);
|
|
19
|
-
}
|
|
20
|
-
(async () => {
|
|
21
|
-
await semaphore[args.scope].acquire();
|
|
22
|
-
element.onload = () => {
|
|
23
|
-
setReady(true);
|
|
24
|
-
const listKey = args.scope + "_list";
|
|
25
|
-
if (!window[listKey]) window[listKey] = [];
|
|
26
|
-
window[listKey].push({
|
|
27
|
-
url: args.url,
|
|
28
|
-
container: window[args.scope]
|
|
29
|
-
});
|
|
30
|
-
window[args.scope] = null;
|
|
31
|
-
};
|
|
32
|
-
element.onerror = () => {
|
|
33
|
-
setReady(false);
|
|
34
|
-
setFailed(true);
|
|
35
|
-
};
|
|
36
|
-
document.head.appendChild(element);
|
|
37
|
-
})();
|
|
38
|
-
return () => {
|
|
39
|
-
semaphore[args.scope].release();
|
|
40
|
-
if (document.head.contains(element)) {
|
|
41
|
-
document.head.removeChild(element);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}, [args.url]);
|
|
45
|
-
return {
|
|
46
|
-
ready,
|
|
47
|
-
failed
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
export default useDynamicScript;
|