chayns-api 1.2.0-14 → 1.2.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/dist/cjs/host/ChaynsHost.js +1 -2
- package/dist/cjs/host/module/ModuleHost.js +2 -4
- package/dist/cjs/host/module/utils/loadComponent.js +5 -16
- package/dist/cjs/util/initModuleFederationSharing.js +31 -31
- package/dist/esm/host/ChaynsHost.js +1 -2
- package/dist/esm/host/module/ModuleHost.js +2 -4
- package/dist/esm/host/module/utils/loadComponent.js +3 -16
- package/dist/esm/util/initModuleFederationSharing.js +32 -31
- package/dist/types/host/ChaynsHost.d.ts +0 -1
- package/dist/types/host/module/ModuleHost.d.ts +0 -1
- package/dist/types/host/module/utils/loadComponent.d.ts +2 -2
- package/dist/types/util/initModuleFederationSharing.d.ts +3 -1
- package/package.json +1 -1
|
@@ -30,8 +30,7 @@ const ChaynsHost = ({
|
|
|
30
30
|
customData,
|
|
31
31
|
environment,
|
|
32
32
|
preventStagingReplacement,
|
|
33
|
-
dialog
|
|
34
|
-
shareScope
|
|
33
|
+
dialog
|
|
35
34
|
}) => {
|
|
36
35
|
const [isVisible, setIsVisible] = (0, _react.useState)(type !== 'client-module' && (type !== 'server-module' || !!(system !== null && system !== void 0 && system.serverUrl)));
|
|
37
36
|
(0, _react.useEffect)(() => {
|
|
@@ -15,8 +15,7 @@ const System = ({
|
|
|
15
15
|
fallback,
|
|
16
16
|
...props
|
|
17
17
|
}) => {
|
|
18
|
-
|
|
19
|
-
const Component = (0, _react.useMemo)(() => (0, _loadComponent.default)(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton, system.shareScope), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
|
|
18
|
+
const Component = (0, _react.useMemo)(() => (0, _loadComponent.default)(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
|
|
20
19
|
return /*#__PURE__*/_react.default.createElement(_react.default.Suspense, {
|
|
21
20
|
fallback: fallback || ''
|
|
22
21
|
}, /*#__PURE__*/_react.default.createElement(Component, props));
|
|
@@ -67,8 +66,7 @@ const ModuleHost = ({
|
|
|
67
66
|
url: (0, _url.replaceStagingUrl)(preventStagingReplacement, system.url, environment.buildEnvironment),
|
|
68
67
|
serverUrl: (0, _url.replaceStagingUrl)(preventStagingReplacement, system.serverUrl, environment.buildEnvironment),
|
|
69
68
|
module: system.module,
|
|
70
|
-
preventSingleton: system.preventSingleton
|
|
71
|
-
shareScope: system.shareScope
|
|
69
|
+
preventSingleton: system.preventSingleton
|
|
72
70
|
},
|
|
73
71
|
data: initialData,
|
|
74
72
|
functions: functions,
|
|
@@ -7,8 +7,7 @@ exports.loadModule = exports.default = void 0;
|
|
|
7
7
|
var _semver = _interopRequireDefault(require("semver"));
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
const loadModule = (scope, module, url, preventSingleton = false
|
|
11
|
-
console.log("share2", shareScope);
|
|
10
|
+
const loadModule = (scope, module, url, preventSingleton = false) => {
|
|
12
11
|
const {
|
|
13
12
|
loadRemote,
|
|
14
13
|
registerRemotes
|
|
@@ -22,14 +21,8 @@ const loadModule = (scope, module, url, preventSingleton = false, shareScope = '
|
|
|
22
21
|
if (scope in registeredScopes) {
|
|
23
22
|
console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
|
|
24
23
|
}
|
|
25
|
-
console.log("register remote ", {
|
|
26
|
-
shareScope,
|
|
27
|
-
name: scope,
|
|
28
|
-
entry: url,
|
|
29
|
-
alias: scope
|
|
30
|
-
});
|
|
31
24
|
registerRemotes([{
|
|
32
|
-
shareScope,
|
|
25
|
+
shareScope: url.endsWith('v2.remoteEntry.js') ? 'chayns-api' : 'default',
|
|
33
26
|
name: scope,
|
|
34
27
|
entry: url,
|
|
35
28
|
alias: scope
|
|
@@ -53,8 +46,7 @@ const loadModule = (scope, module, url, preventSingleton = false, shareScope = '
|
|
|
53
46
|
return moduleMap[scope][module];
|
|
54
47
|
};
|
|
55
48
|
exports.loadModule = loadModule;
|
|
56
|
-
const loadComponent = (scope, module, url, skipCompatMode = false, preventSingleton = false
|
|
57
|
-
console.log("share1", shareScope);
|
|
49
|
+
const loadComponent = (scope, module, url, skipCompatMode = false, preventSingleton = false) => {
|
|
58
50
|
if (skipCompatMode) {
|
|
59
51
|
console.warn('[chayns-api] skipCompatMode-option is deprecated and is set automatically now');
|
|
60
52
|
}
|
|
@@ -68,7 +60,7 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
|
|
|
68
60
|
componentMap[scope] = {};
|
|
69
61
|
}
|
|
70
62
|
if (!(module in componentMap[scope])) {
|
|
71
|
-
const promise = loadModule(scope, module, url, preventSingleton
|
|
63
|
+
const promise = loadModule(scope, module, url, preventSingleton).then(async Module => {
|
|
72
64
|
if (typeof Module.default === 'function') {
|
|
73
65
|
return Module;
|
|
74
66
|
}
|
|
@@ -81,7 +73,6 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
|
|
|
81
73
|
loadShareSync('react', {
|
|
82
74
|
resolver: shareOptions => {
|
|
83
75
|
resolve(shareOptions);
|
|
84
|
-
console.log("shareOptions", shareOptions);
|
|
85
76
|
return shareOptions[0];
|
|
86
77
|
}
|
|
87
78
|
});
|
|
@@ -92,13 +83,11 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
|
|
|
92
83
|
}) => {
|
|
93
84
|
return _semver.default.gt(version, hostVersion) && _semver.default.satisfies(version, requiredVersion) || scope === from.split('-').join('_');
|
|
94
85
|
});
|
|
95
|
-
if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development'
|
|
96
|
-
console.log("use compat mode for", scope, module);
|
|
86
|
+
if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
|
|
97
87
|
return {
|
|
98
88
|
default: Module.default.CompatComponent
|
|
99
89
|
};
|
|
100
90
|
}
|
|
101
|
-
console.log("use direct component for", scope, module);
|
|
102
91
|
return {
|
|
103
92
|
default: Module.default.Component
|
|
104
93
|
};
|
|
@@ -7,38 +7,38 @@ exports.initModuleFederationSharing = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
const initModuleFederationSharing = (
|
|
10
|
+
const initModuleFederationSharing = ({
|
|
11
|
+
name
|
|
12
|
+
}) => {
|
|
11
13
|
// forces single instance of module federation runtime
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
globalThis.moduleFederationRuntime = require('@module-federation/enhanced/runtime');
|
|
15
|
-
globalThis.moduleFederationScopes = {
|
|
16
|
-
registeredScopes: {},
|
|
17
|
-
moduleMap: {},
|
|
18
|
-
componentMap: {}
|
|
19
|
-
};
|
|
20
|
-
const {
|
|
21
|
-
init
|
|
22
|
-
} = globalThis.moduleFederationRuntime;
|
|
23
|
-
|
|
24
|
-
// init also should only be called once
|
|
25
|
-
init({
|
|
26
|
-
// will be set by chayns-toolkit via DefinePlugin
|
|
27
|
-
name: (_process$env$__PACKAG = process.env.__PACKAGE_NAME__) !== null && _process$env$__PACKAG !== void 0 ? _process$env$__PACKAG : '',
|
|
28
|
-
remotes: [],
|
|
29
|
-
shared: {
|
|
30
|
-
react: {
|
|
31
|
-
version: _react.default.version,
|
|
32
|
-
scope: 'chayns-api2',
|
|
33
|
-
lib: () => _react.default
|
|
34
|
-
},
|
|
35
|
-
'react-dom': {
|
|
36
|
-
version: _reactDom.default.version,
|
|
37
|
-
scope: 'chayns-api2',
|
|
38
|
-
lib: () => _reactDom.default
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
14
|
+
if (globalThis.moduleFederationRuntime) {
|
|
15
|
+
return;
|
|
42
16
|
}
|
|
17
|
+
globalThis.moduleFederationRuntime = require('@module-federation/enhanced/runtime');
|
|
18
|
+
globalThis.moduleFederationScopes = {
|
|
19
|
+
registeredScopes: {},
|
|
20
|
+
moduleMap: {},
|
|
21
|
+
componentMap: {}
|
|
22
|
+
};
|
|
23
|
+
const {
|
|
24
|
+
init
|
|
25
|
+
} = globalThis.moduleFederationRuntime;
|
|
26
|
+
init({
|
|
27
|
+
name: name !== null && name !== void 0 ? name : '',
|
|
28
|
+
remotes: [],
|
|
29
|
+
shared: {
|
|
30
|
+
react: {
|
|
31
|
+
version: _react.default.version,
|
|
32
|
+
scope: 'chayns-api',
|
|
33
|
+
lib: () => _react.default
|
|
34
|
+
},
|
|
35
|
+
'react-dom': {
|
|
36
|
+
version: _react.default.version,
|
|
37
|
+
// intended, because react dom.version is not identical to package json react version (hash in version)
|
|
38
|
+
scope: 'chayns-api',
|
|
39
|
+
lib: () => _reactDom.default
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
43
|
};
|
|
44
44
|
exports.initModuleFederationSharing = initModuleFederationSharing;
|
|
@@ -22,8 +22,7 @@ const ChaynsHost = _ref => {
|
|
|
22
22
|
customData,
|
|
23
23
|
environment,
|
|
24
24
|
preventStagingReplacement,
|
|
25
|
-
dialog
|
|
26
|
-
shareScope
|
|
25
|
+
dialog
|
|
27
26
|
} = _ref;
|
|
28
27
|
const [isVisible, setIsVisible] = useState(type !== 'client-module' && (type !== 'server-module' || !!(system !== null && system !== void 0 && system.serverUrl)));
|
|
29
28
|
useEffect(() => {
|
|
@@ -7,8 +7,7 @@ const System = _ref => {
|
|
|
7
7
|
fallback,
|
|
8
8
|
...props
|
|
9
9
|
} = _ref;
|
|
10
|
-
|
|
11
|
-
const Component = useMemo(() => loadComponent(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton, system.shareScope), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
|
|
10
|
+
const Component = useMemo(() => loadComponent(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
|
|
12
11
|
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
13
12
|
fallback: fallback || ''
|
|
14
13
|
}, /*#__PURE__*/React.createElement(Component, props));
|
|
@@ -60,8 +59,7 @@ const ModuleHost = _ref2 => {
|
|
|
60
59
|
url: replaceStagingUrl(preventStagingReplacement, system.url, environment.buildEnvironment),
|
|
61
60
|
serverUrl: replaceStagingUrl(preventStagingReplacement, system.serverUrl, environment.buildEnvironment),
|
|
62
61
|
module: system.module,
|
|
63
|
-
preventSingleton: system.preventSingleton
|
|
64
|
-
shareScope: system.shareScope
|
|
62
|
+
preventSingleton: system.preventSingleton
|
|
65
63
|
},
|
|
66
64
|
data: initialData,
|
|
67
65
|
functions: functions,
|
|
@@ -2,8 +2,6 @@ import semver from 'semver';
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
export const loadModule = function (scope, module, url) {
|
|
4
4
|
let preventSingleton = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
5
|
-
let shareScope = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'chayns-api2';
|
|
6
|
-
console.log("share2", shareScope);
|
|
7
5
|
const {
|
|
8
6
|
loadRemote,
|
|
9
7
|
registerRemotes
|
|
@@ -17,14 +15,8 @@ export const loadModule = function (scope, module, url) {
|
|
|
17
15
|
if (scope in registeredScopes) {
|
|
18
16
|
console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
|
|
19
17
|
}
|
|
20
|
-
console.log("register remote ", {
|
|
21
|
-
shareScope,
|
|
22
|
-
name: scope,
|
|
23
|
-
entry: url,
|
|
24
|
-
alias: scope
|
|
25
|
-
});
|
|
26
18
|
registerRemotes([{
|
|
27
|
-
shareScope,
|
|
19
|
+
shareScope: url.endsWith('v2.remoteEntry.js') ? 'chayns-api' : 'default',
|
|
28
20
|
name: scope,
|
|
29
21
|
entry: url,
|
|
30
22
|
alias: scope
|
|
@@ -50,8 +42,6 @@ export const loadModule = function (scope, module, url) {
|
|
|
50
42
|
const loadComponent = function (scope, module, url) {
|
|
51
43
|
let skipCompatMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
52
44
|
let preventSingleton = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
53
|
-
let shareScope = arguments.length > 5 ? arguments[5] : undefined;
|
|
54
|
-
console.log("share1", shareScope);
|
|
55
45
|
if (skipCompatMode) {
|
|
56
46
|
console.warn('[chayns-api] skipCompatMode-option is deprecated and is set automatically now');
|
|
57
47
|
}
|
|
@@ -65,7 +55,7 @@ const loadComponent = function (scope, module, url) {
|
|
|
65
55
|
componentMap[scope] = {};
|
|
66
56
|
}
|
|
67
57
|
if (!(module in componentMap[scope])) {
|
|
68
|
-
const promise = loadModule(scope, module, url, preventSingleton
|
|
58
|
+
const promise = loadModule(scope, module, url, preventSingleton).then(async Module => {
|
|
69
59
|
if (typeof Module.default === 'function') {
|
|
70
60
|
return Module;
|
|
71
61
|
}
|
|
@@ -78,7 +68,6 @@ const loadComponent = function (scope, module, url) {
|
|
|
78
68
|
loadShareSync('react', {
|
|
79
69
|
resolver: shareOptions => {
|
|
80
70
|
resolve(shareOptions);
|
|
81
|
-
console.log("shareOptions", shareOptions);
|
|
82
71
|
return shareOptions[0];
|
|
83
72
|
}
|
|
84
73
|
});
|
|
@@ -90,13 +79,11 @@ const loadComponent = function (scope, module, url) {
|
|
|
90
79
|
} = _ref;
|
|
91
80
|
return semver.gt(version, hostVersion) && semver.satisfies(version, requiredVersion) || scope === from.split('-').join('_');
|
|
92
81
|
});
|
|
93
|
-
if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development'
|
|
94
|
-
console.log("use compat mode for", scope, module);
|
|
82
|
+
if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
|
|
95
83
|
return {
|
|
96
84
|
default: Module.default.CompatComponent
|
|
97
85
|
};
|
|
98
86
|
}
|
|
99
|
-
console.log("use direct component for", scope, module);
|
|
100
87
|
return {
|
|
101
88
|
default: Module.default.Component
|
|
102
89
|
};
|
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
|
-
export const initModuleFederationSharing =
|
|
3
|
+
export const initModuleFederationSharing = _ref => {
|
|
4
|
+
let {
|
|
5
|
+
name
|
|
6
|
+
} = _ref;
|
|
4
7
|
// forces single instance of module federation runtime
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
globalThis.moduleFederationRuntime = require('@module-federation/enhanced/runtime');
|
|
8
|
-
globalThis.moduleFederationScopes = {
|
|
9
|
-
registeredScopes: {},
|
|
10
|
-
moduleMap: {},
|
|
11
|
-
componentMap: {}
|
|
12
|
-
};
|
|
13
|
-
const {
|
|
14
|
-
init
|
|
15
|
-
} = globalThis.moduleFederationRuntime;
|
|
16
|
-
|
|
17
|
-
// init also should only be called once
|
|
18
|
-
init({
|
|
19
|
-
// will be set by chayns-toolkit via DefinePlugin
|
|
20
|
-
name: (_process$env$__PACKAG = process.env.__PACKAGE_NAME__) !== null && _process$env$__PACKAG !== void 0 ? _process$env$__PACKAG : '',
|
|
21
|
-
remotes: [],
|
|
22
|
-
shared: {
|
|
23
|
-
react: {
|
|
24
|
-
version: React.version,
|
|
25
|
-
scope: 'chayns-api2',
|
|
26
|
-
lib: () => React
|
|
27
|
-
},
|
|
28
|
-
'react-dom': {
|
|
29
|
-
version: ReactDOM.version,
|
|
30
|
-
scope: 'chayns-api2',
|
|
31
|
-
lib: () => ReactDOM
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
8
|
+
if (globalThis.moduleFederationRuntime) {
|
|
9
|
+
return;
|
|
35
10
|
}
|
|
11
|
+
globalThis.moduleFederationRuntime = require('@module-federation/enhanced/runtime');
|
|
12
|
+
globalThis.moduleFederationScopes = {
|
|
13
|
+
registeredScopes: {},
|
|
14
|
+
moduleMap: {},
|
|
15
|
+
componentMap: {}
|
|
16
|
+
};
|
|
17
|
+
const {
|
|
18
|
+
init
|
|
19
|
+
} = globalThis.moduleFederationRuntime;
|
|
20
|
+
init({
|
|
21
|
+
name: name !== null && name !== void 0 ? name : '',
|
|
22
|
+
remotes: [],
|
|
23
|
+
shared: {
|
|
24
|
+
react: {
|
|
25
|
+
version: React.version,
|
|
26
|
+
scope: 'chayns-api',
|
|
27
|
+
lib: () => React
|
|
28
|
+
},
|
|
29
|
+
'react-dom': {
|
|
30
|
+
version: React.version,
|
|
31
|
+
// intended, because react dom.version is not identical to package json react version (hash in version)
|
|
32
|
+
scope: 'chayns-api',
|
|
33
|
+
lib: () => ReactDOM
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
36
37
|
};
|
|
@@ -24,7 +24,6 @@ type ChaynsHostType = {
|
|
|
24
24
|
environment: ChaynsReactValues["environment"];
|
|
25
25
|
preventStagingReplacement?: boolean;
|
|
26
26
|
dialog: ChaynsReactValues["dialog"];
|
|
27
|
-
shareScope?: string;
|
|
28
27
|
};
|
|
29
28
|
declare const ChaynsHost: FC<ChaynsHostType>;
|
|
30
29
|
export default ChaynsHost;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const loadModule: (scope: any, module: any, url: any, preventSingleton?: boolean
|
|
2
|
-
declare const loadComponent: (scope: any, module: any, url: any, skipCompatMode
|
|
1
|
+
export declare const loadModule: (scope: any, module: any, url: any, preventSingleton?: boolean) => any;
|
|
2
|
+
declare const loadComponent: (scope: any, module: any, url: any, skipCompatMode?: boolean, preventSingleton?: boolean) => any;
|
|
3
3
|
export default loadComponent;
|