chayns-api 2.6.0-beta.4 → 2.6.0-beta.5

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.
@@ -7,14 +7,17 @@ exports.loadModule = exports.default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  const loadModule = (scope, module, url, preventSingleton = false) => {
10
- if (!globalThis.moduleFederationScopes) {
10
+ if (!globalThis.moduleFederationRuntime || !globalThis.moduleFederationScopes) {
11
11
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
12
12
  }
13
+ const {
14
+ loadRemote,
15
+ registerRemotes
16
+ } = globalThis.moduleFederationRuntime;
13
17
  const {
14
18
  registeredScopes,
15
19
  moduleMap,
16
- componentMap,
17
- getInstance
20
+ componentMap
18
21
  } = globalThis.moduleFederationScopes;
19
22
  try {
20
23
  url = new URL(url).toString();
@@ -23,7 +26,7 @@ const loadModule = (scope, module, url, preventSingleton = false) => {
23
26
  if (scope in registeredScopes) {
24
27
  console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
25
28
  }
26
- getInstance().registerRemotes([{
29
+ registerRemotes([{
27
30
  shareScope: url.endsWith('v2.remoteEntry.js') || url.endsWith('mf-manifest.json') ? 'chayns-api' : 'default',
28
31
  name: scope,
29
32
  entry: url,
@@ -37,7 +40,7 @@ const loadModule = (scope, module, url, preventSingleton = false) => {
37
40
  }
38
41
  if (!(module in moduleMap[scope])) {
39
42
  const path = `${scope}/${module.replace(/^\.\//, '')}`;
40
- const promise = getInstance().loadRemote(path);
43
+ const promise = loadRemote(path);
41
44
  promise.catch(e => {
42
45
  console.error("[chayns-api] Failed to load module", scope, url, e);
43
46
  registeredScopes[scope] = '';
@@ -51,13 +54,15 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
51
54
  if (skipCompatMode) {
52
55
  console.warn('[chayns-api] skipCompatMode-option is deprecated and is set automatically now');
53
56
  }
54
- if (!globalThis.moduleFederationScopes) {
57
+ if (!globalThis.moduleFederationRuntime || !globalThis.moduleFederationScopes) {
55
58
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
56
59
  }
60
+ const {
61
+ shareScopeMap: shareScopes
62
+ } = globalThis.moduleFederationRuntime;
57
63
  const {
58
64
  componentMap,
59
- registeredScopes,
60
- getInstance
65
+ registeredScopes
61
66
  } = globalThis.moduleFederationScopes;
62
67
  if (!componentMap[scope]) {
63
68
  componentMap[scope] = {};
@@ -68,7 +73,6 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
68
73
  if (typeof Module.default === 'function') {
69
74
  return Module;
70
75
  }
71
- const shareScopes = getInstance().shareScopeMap;
72
76
  const sharedReact = (_shareScopes$chaynsA = shareScopes['chayns-api'].react) === null || _shareScopes$chaynsA === void 0 ? void 0 : _shareScopes$chaynsA[_react.default.version];
73
77
  const matchReactVersion = sharedReact && sharedReact.useIn.includes(scope) && ((_sharedReact$lib = sharedReact.lib) === null || _sharedReact$lib === void 0 ? void 0 : _sharedReact$lib.call(sharedReact)) === _react.default;
74
78
  if (!matchReactVersion || Module.default.environment !== 'production' || (Module.default.version || 1) < 2) {
@@ -19,11 +19,9 @@ const initModuleFederationSharing = ({
19
19
  if (globalThis.moduleFederationScopes) {
20
20
  return;
21
21
  }
22
- const runtime = require('@module-federation/enhanced/runtime');
23
- globalThis.moduleFederationRuntime = runtime;
24
22
  const {
25
- init
26
- } = runtime;
23
+ createInstance
24
+ } = require('@module-federation/enhanced/runtime');
27
25
  const shared = {
28
26
  react: {
29
27
  version: _react.default.version,
@@ -43,7 +41,7 @@ const initModuleFederationSharing = ({
43
41
  lib: () => ReactDOMClient
44
42
  };
45
43
  }
46
- const instance = init({
44
+ globalThis.moduleFederationRuntime = createInstance({
47
45
  name: name !== null && name !== void 0 ? name : '',
48
46
  remotes: [],
49
47
  shared,
@@ -52,8 +50,7 @@ const initModuleFederationSharing = ({
52
50
  globalThis.moduleFederationScopes = {
53
51
  registeredScopes: {},
54
52
  moduleMap: {},
55
- componentMap: {},
56
- getInstance: () => instance
53
+ componentMap: {}
57
54
  };
58
55
  };
59
56
  exports.initModuleFederationSharing = initModuleFederationSharing;
@@ -1,13 +1,16 @@
1
1
  import React from "react";
2
2
  export const loadModule = (scope, module, url, preventSingleton = false) => {
3
- if (!globalThis.moduleFederationScopes) {
3
+ if (!globalThis.moduleFederationRuntime || !globalThis.moduleFederationScopes) {
4
4
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
5
5
  }
6
+ const {
7
+ loadRemote,
8
+ registerRemotes
9
+ } = globalThis.moduleFederationRuntime;
6
10
  const {
7
11
  registeredScopes,
8
12
  moduleMap,
9
- componentMap,
10
- getInstance
13
+ componentMap
11
14
  } = globalThis.moduleFederationScopes;
12
15
  try {
13
16
  url = new URL(url).toString();
@@ -16,7 +19,7 @@ export const loadModule = (scope, module, url, preventSingleton = false) => {
16
19
  if (scope in registeredScopes) {
17
20
  console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
18
21
  }
19
- getInstance().registerRemotes([{
22
+ registerRemotes([{
20
23
  shareScope: url.endsWith('v2.remoteEntry.js') || url.endsWith('mf-manifest.json') ? 'chayns-api' : 'default',
21
24
  name: scope,
22
25
  entry: url,
@@ -30,7 +33,7 @@ export const loadModule = (scope, module, url, preventSingleton = false) => {
30
33
  }
31
34
  if (!(module in moduleMap[scope])) {
32
35
  const path = `${scope}/${module.replace(/^\.\//, '')}`;
33
- const promise = getInstance().loadRemote(path);
36
+ const promise = loadRemote(path);
34
37
  promise.catch(e => {
35
38
  console.error("[chayns-api] Failed to load module", scope, url, e);
36
39
  registeredScopes[scope] = '';
@@ -43,13 +46,15 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
43
46
  if (skipCompatMode) {
44
47
  console.warn('[chayns-api] skipCompatMode-option is deprecated and is set automatically now');
45
48
  }
46
- if (!globalThis.moduleFederationScopes) {
49
+ if (!globalThis.moduleFederationRuntime || !globalThis.moduleFederationScopes) {
47
50
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
48
51
  }
52
+ const {
53
+ shareScopeMap: shareScopes
54
+ } = globalThis.moduleFederationRuntime;
49
55
  const {
50
56
  componentMap,
51
- registeredScopes,
52
- getInstance
57
+ registeredScopes
53
58
  } = globalThis.moduleFederationScopes;
54
59
  if (!componentMap[scope]) {
55
60
  componentMap[scope] = {};
@@ -60,7 +65,6 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
60
65
  if (typeof Module.default === 'function') {
61
66
  return Module;
62
67
  }
63
- const shareScopes = getInstance().shareScopeMap;
64
68
  const sharedReact = (_shareScopes$chaynsA = shareScopes['chayns-api'].react) === null || _shareScopes$chaynsA === void 0 ? void 0 : _shareScopes$chaynsA[React.version];
65
69
  const matchReactVersion = sharedReact && sharedReact.useIn.includes(scope) && ((_sharedReact$lib = sharedReact.lib) === null || _sharedReact$lib === void 0 ? void 0 : _sharedReact$lib.call(sharedReact)) === React;
66
70
  if (!matchReactVersion || Module.default.environment !== 'production' || (Module.default.version || 1) < 2) {
@@ -12,11 +12,9 @@ export const initModuleFederationSharing = ({
12
12
  if (globalThis.moduleFederationScopes) {
13
13
  return;
14
14
  }
15
- const runtime = require('@module-federation/enhanced/runtime');
16
- globalThis.moduleFederationRuntime = runtime;
17
15
  const {
18
- init
19
- } = runtime;
16
+ createInstance
17
+ } = require('@module-federation/enhanced/runtime');
20
18
  const shared = {
21
19
  react: {
22
20
  version: React.version,
@@ -36,7 +34,7 @@ export const initModuleFederationSharing = ({
36
34
  lib: () => ReactDOMClient
37
35
  };
38
36
  }
39
- const instance = init({
37
+ globalThis.moduleFederationRuntime = createInstance({
40
38
  name: name !== null && name !== void 0 ? name : '',
41
39
  remotes: [],
42
40
  shared,
@@ -45,7 +43,6 @@ export const initModuleFederationSharing = ({
45
43
  globalThis.moduleFederationScopes = {
46
44
  registeredScopes: {},
47
45
  moduleMap: {},
48
- componentMap: {},
49
- getInstance: () => instance
46
+ componentMap: {}
50
47
  };
51
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "2.6.0-beta.4",
3
+ "version": "2.6.0-beta.5",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",