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

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