chayns-api 2.4.30 → 2.6.0-beta.0
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/constants/index.js +11 -0
- package/dist/cjs/constants/moduleContext.js +14 -0
- package/dist/cjs/host/module/ModuleHost.js +10 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugins/SequentialLoadPlugin.js +27 -0
- package/dist/cjs/util/collectCssChunks.js +46 -0
- package/dist/cjs/util/initModuleFederationSharing.js +3 -1
- package/dist/esm/constants/index.js +2 -1
- package/dist/esm/constants/moduleContext.js +8 -0
- package/dist/esm/host/module/ModuleHost.js +11 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/plugins/SequentialLoadPlugin.js +20 -0
- package/dist/esm/util/collectCssChunks.js +39 -0
- package/dist/esm/util/initModuleFederationSharing.js +3 -1
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/constants/moduleContext.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/SequentialLoadPlugin.d.ts +5 -0
- package/dist/types/util/collectCssChunks.d.ts +2 -0
- package/package.json +1 -1
|
@@ -24,4 +24,15 @@ Object.keys(_DefaultLoginDialogOptions).forEach(function (key) {
|
|
|
24
24
|
return _DefaultLoginDialogOptions[key];
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
+
});
|
|
28
|
+
var _moduleContext = require("./moduleContext");
|
|
29
|
+
Object.keys(_moduleContext).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _moduleContext[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _moduleContext[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
27
38
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ModuleContext = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
let ModuleContext = exports.ModuleContext = void 0;
|
|
9
|
+
if (!globalThis.window && globalThis._moduleContext) {
|
|
10
|
+
exports.ModuleContext = ModuleContext = globalThis._moduleContext;
|
|
11
|
+
} else {
|
|
12
|
+
exports.ModuleContext = ModuleContext = (0, _react.createContext)({});
|
|
13
|
+
globalThis._moduleContext = ModuleContext;
|
|
14
|
+
}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _moduleContext = require("../../constants/moduleContext");
|
|
8
9
|
var _loadComponent = _interopRequireDefault(require("./utils/loadComponent"));
|
|
9
10
|
var _url = require("../../util/url");
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -16,6 +17,15 @@ const System = ({
|
|
|
16
17
|
...props
|
|
17
18
|
}) => {
|
|
18
19
|
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
|
+
if (!globalThis.window) {
|
|
21
|
+
var _system$scope, _moduleContext$_syste;
|
|
22
|
+
const moduleContext = (0, _react.useContext)(_moduleContext.ModuleContext);
|
|
23
|
+
(_moduleContext$_syste = moduleContext[_system$scope = system.scope]) !== null && _moduleContext$_syste !== void 0 ? _moduleContext$_syste : moduleContext[_system$scope] = {
|
|
24
|
+
url: new URL('mf-manifest.json', system.url).toString(),
|
|
25
|
+
modules: new Set()
|
|
26
|
+
};
|
|
27
|
+
moduleContext[system.scope].modules.add(system.module);
|
|
28
|
+
}
|
|
19
29
|
return _react.default.createElement(_react.default.Suspense, {
|
|
20
30
|
fallback: fallback || ''
|
|
21
31
|
}, _react.default.createElement(Component, props));
|
package/dist/cjs/index.js
CHANGED
|
@@ -203,6 +203,18 @@ Object.keys(_appStorage).forEach(function (key) {
|
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
});
|
|
206
|
+
var _collectCssChunks = require("./util/collectCssChunks");
|
|
207
|
+
Object.keys(_collectCssChunks).forEach(function (key) {
|
|
208
|
+
if (key === "default" || key === "__esModule") return;
|
|
209
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
210
|
+
if (key in exports && exports[key] === _collectCssChunks[key]) return;
|
|
211
|
+
Object.defineProperty(exports, key, {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
get: function () {
|
|
214
|
+
return _collectCssChunks[key];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
206
218
|
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); }
|
|
207
219
|
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; }
|
|
208
220
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SequentialLoadPlugin = void 0;
|
|
7
|
+
const SequentialLoadPlugin = () => {
|
|
8
|
+
return {
|
|
9
|
+
name: 'sequential-load',
|
|
10
|
+
async beforeInitContainer(args) {
|
|
11
|
+
const manifest = args.origin.snapshotHandler.manifestCache.get(args.remoteEntryInitOptions.version);
|
|
12
|
+
const requiredShares = new Set(manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(share => share.name));
|
|
13
|
+
for (const [key, pkg] of Object.entries(args.shareScope)) {
|
|
14
|
+
if (manifest && !requiredShares.has(key)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
for (const version of Object.values(pkg)) {
|
|
18
|
+
if (!version.loaded && version.loading) {
|
|
19
|
+
await version.loading;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return args;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.SequentialLoadPlugin = SequentialLoadPlugin;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.collectCssChunks = void 0;
|
|
7
|
+
const remoteInfoCache = {};
|
|
8
|
+
const loadRemoteInfo = async url => {
|
|
9
|
+
if (remoteInfoCache[url]) {
|
|
10
|
+
return remoteInfoCache[url];
|
|
11
|
+
}
|
|
12
|
+
const res = await fetch(url);
|
|
13
|
+
if (res.status === 200) {
|
|
14
|
+
const info = await res.json();
|
|
15
|
+
remoteInfoCache[url] = info;
|
|
16
|
+
return info;
|
|
17
|
+
}
|
|
18
|
+
if (res.status === 404) {
|
|
19
|
+
remoteInfoCache[url] = null;
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`Could not load remote info from ${url}`);
|
|
23
|
+
};
|
|
24
|
+
const collectCssChunks = async modules => {
|
|
25
|
+
const p = Object.values(modules).map(async module => {
|
|
26
|
+
const info = await loadRemoteInfo(module.url);
|
|
27
|
+
const chunks = [];
|
|
28
|
+
info === null || info === void 0 || info.exposes.forEach(exposes => {
|
|
29
|
+
if (module.modules.has(exposes.path)) {
|
|
30
|
+
var _exposes$assets$css, _exposes$assets;
|
|
31
|
+
const {
|
|
32
|
+
sync = [],
|
|
33
|
+
async = []
|
|
34
|
+
} = (_exposes$assets$css = (_exposes$assets = exposes.assets) === null || _exposes$assets === void 0 ? void 0 : _exposes$assets.css) !== null && _exposes$assets$css !== void 0 ? _exposes$assets$css : {};
|
|
35
|
+
[...sync, ...async].forEach(chunk => {
|
|
36
|
+
const url = new URL(chunk, module.url);
|
|
37
|
+
chunks.push(`<link rel="stylesheet" href="${url}">`);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return chunks;
|
|
42
|
+
});
|
|
43
|
+
const r = await Promise.allSettled(p);
|
|
44
|
+
return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
|
|
45
|
+
};
|
|
46
|
+
exports.collectCssChunks = collectCssChunks;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.initModuleFederationSharing = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
9
|
+
var _SequentialLoadPlugin = require("../plugins/SequentialLoadPlugin");
|
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
let ReactDOMClient;
|
|
11
12
|
try {
|
|
@@ -48,7 +49,8 @@ const initModuleFederationSharing = ({
|
|
|
48
49
|
init({
|
|
49
50
|
name: name !== null && name !== void 0 ? name : '',
|
|
50
51
|
remotes: [],
|
|
51
|
-
shared
|
|
52
|
+
shared,
|
|
53
|
+
plugins: [(0, _SequentialLoadPlugin.SequentialLoadPlugin)()]
|
|
52
54
|
});
|
|
53
55
|
};
|
|
54
56
|
exports.initModuleFederationSharing = initModuleFederationSharing;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
1
|
+
import React, { useContext, useMemo } from 'react';
|
|
2
|
+
import { ModuleContext } from '../../constants/moduleContext';
|
|
2
3
|
import loadComponent from './utils/loadComponent';
|
|
3
4
|
import { replaceStagingUrl } from "../../util/url";
|
|
4
5
|
const System = _ref => {
|
|
@@ -8,6 +9,15 @@ const System = _ref => {
|
|
|
8
9
|
...props
|
|
9
10
|
} = _ref;
|
|
10
11
|
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
|
+
if (!globalThis.window) {
|
|
13
|
+
var _system$scope, _moduleContext$_syste;
|
|
14
|
+
const moduleContext = useContext(ModuleContext);
|
|
15
|
+
(_moduleContext$_syste = moduleContext[_system$scope = system.scope]) !== null && _moduleContext$_syste !== void 0 ? _moduleContext$_syste : moduleContext[_system$scope] = {
|
|
16
|
+
url: new URL('mf-manifest.json', system.url).toString(),
|
|
17
|
+
modules: new Set()
|
|
18
|
+
};
|
|
19
|
+
moduleContext[system.scope].modules.add(system.module);
|
|
20
|
+
}
|
|
11
21
|
return React.createElement(React.Suspense, {
|
|
12
22
|
fallback: fallback || ''
|
|
13
23
|
}, React.createElement(Component, props));
|
package/dist/esm/index.js
CHANGED
|
@@ -17,4 +17,5 @@ import * as _dialog from './calls/dialogs/index';
|
|
|
17
17
|
export { _dialog as dialog };
|
|
18
18
|
export * from './util/initModuleFederationSharing';
|
|
19
19
|
export * from './util/bindChaynsApi';
|
|
20
|
-
export * from './util/appStorage';
|
|
20
|
+
export * from './util/appStorage';
|
|
21
|
+
export * from './util/collectCssChunks';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const SequentialLoadPlugin = () => {
|
|
2
|
+
return {
|
|
3
|
+
name: 'sequential-load',
|
|
4
|
+
async beforeInitContainer(args) {
|
|
5
|
+
const manifest = args.origin.snapshotHandler.manifestCache.get(args.remoteEntryInitOptions.version);
|
|
6
|
+
const requiredShares = new Set(manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(share => share.name));
|
|
7
|
+
for (const [key, pkg] of Object.entries(args.shareScope)) {
|
|
8
|
+
if (manifest && !requiredShares.has(key)) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
for (const version of Object.values(pkg)) {
|
|
12
|
+
if (!version.loaded && version.loading) {
|
|
13
|
+
await version.loading;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return args;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const remoteInfoCache = {};
|
|
2
|
+
const loadRemoteInfo = async url => {
|
|
3
|
+
if (remoteInfoCache[url]) {
|
|
4
|
+
return remoteInfoCache[url];
|
|
5
|
+
}
|
|
6
|
+
const res = await fetch(url);
|
|
7
|
+
if (res.status === 200) {
|
|
8
|
+
const info = await res.json();
|
|
9
|
+
remoteInfoCache[url] = info;
|
|
10
|
+
return info;
|
|
11
|
+
}
|
|
12
|
+
if (res.status === 404) {
|
|
13
|
+
remoteInfoCache[url] = null;
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
throw new Error(`Could not load remote info from ${url}`);
|
|
17
|
+
};
|
|
18
|
+
export const collectCssChunks = async modules => {
|
|
19
|
+
const p = Object.values(modules).map(async module => {
|
|
20
|
+
const info = await loadRemoteInfo(module.url);
|
|
21
|
+
const chunks = [];
|
|
22
|
+
info === null || info === void 0 || info.exposes.forEach(exposes => {
|
|
23
|
+
if (module.modules.has(exposes.path)) {
|
|
24
|
+
var _exposes$assets$css, _exposes$assets;
|
|
25
|
+
const {
|
|
26
|
+
sync = [],
|
|
27
|
+
async = []
|
|
28
|
+
} = (_exposes$assets$css = (_exposes$assets = exposes.assets) === null || _exposes$assets === void 0 ? void 0 : _exposes$assets.css) !== null && _exposes$assets$css !== void 0 ? _exposes$assets$css : {};
|
|
29
|
+
[...sync, ...async].forEach(chunk => {
|
|
30
|
+
const url = new URL(chunk, module.url);
|
|
31
|
+
chunks.push(`<link rel="stylesheet" href="${url}">`);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return chunks;
|
|
36
|
+
});
|
|
37
|
+
const r = await Promise.allSettled(p);
|
|
38
|
+
return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
|
|
39
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
|
+
import { SequentialLoadPlugin } from '../plugins/SequentialLoadPlugin';
|
|
3
4
|
let ReactDOMClient;
|
|
4
5
|
try {
|
|
5
6
|
ReactDOMClient = require('react-dom/client');
|
|
@@ -42,6 +43,7 @@ export const initModuleFederationSharing = _ref => {
|
|
|
42
43
|
init({
|
|
43
44
|
name: name !== null && name !== void 0 ? name : '',
|
|
44
45
|
remotes: [],
|
|
45
|
-
shared
|
|
46
|
+
shared,
|
|
47
|
+
plugins: [SequentialLoadPlugin()]
|
|
46
48
|
});
|
|
47
49
|
};
|
package/dist/types/index.d.ts
CHANGED