@zstackui/qiankun 2.6.3-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.
- package/LICENSE +21 -0
- package/README.md +116 -0
- package/dist/index.umd.js +8681 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/index.umd.min.js +4 -0
- package/dist/index.umd.min.js.map +1 -0
- package/dist/src/__tests__/globalState.test.d.ts +5 -0
- package/dist/src/__tests__/utils.test.d.ts +1 -0
- package/dist/src/addons/engineFlag.d.ts +6 -0
- package/dist/src/addons/index.d.ts +6 -0
- package/dist/src/addons/runtimePublicPath.d.ts +6 -0
- package/dist/src/apis.d.ts +7 -0
- package/dist/src/effects.d.ts +3 -0
- package/dist/src/error.d.ts +3 -0
- package/dist/src/errorHandler.d.ts +7 -0
- package/dist/src/globalState.d.ts +7 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/interfaces.d.ts +107 -0
- package/dist/src/loader.d.ts +8 -0
- package/dist/src/prefetch.d.ts +14 -0
- package/dist/src/sandbox/__tests__/common.test.d.ts +5 -0
- package/dist/src/sandbox/__tests__/proxySandbox.test.d.ts +10 -0
- package/dist/src/sandbox/common.d.ts +21 -0
- package/dist/src/sandbox/index.d.ts +40 -0
- package/dist/src/sandbox/legacy/__tests__/sandbox.test.d.ts +5 -0
- package/dist/src/sandbox/legacy/sandbox.d.ts +28 -0
- package/dist/src/sandbox/patchers/__tests__/css.test.d.ts +5 -0
- package/dist/src/sandbox/patchers/__tests__/interval.test.d.ts +5 -0
- package/dist/src/sandbox/patchers/css.d.ts +17 -0
- package/dist/src/sandbox/patchers/dynamicAppend/__tests__/common.test.d.ts +1 -0
- package/dist/src/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
- package/dist/src/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
- package/dist/src/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
- package/dist/src/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
- package/dist/src/sandbox/patchers/historyListener.d.ts +5 -0
- package/dist/src/sandbox/patchers/index.d.ts +9 -0
- package/dist/src/sandbox/patchers/interval.d.ts +5 -0
- package/dist/src/sandbox/patchers/windowListener.d.ts +5 -0
- package/dist/src/sandbox/proxySandbox.d.ts +23 -0
- package/dist/src/sandbox/snapshotSandbox.d.ts +20 -0
- package/dist/src/utils.d.ts +44 -0
- package/dist/src/version.d.ts +1 -0
- package/es/addons/engineFlag.d.ts +6 -0
- package/es/addons/engineFlag.js +50 -0
- package/es/addons/index.d.ts +6 -0
- package/es/addons/index.js +13 -0
- package/es/addons/runtimePublicPath.d.ts +6 -0
- package/es/addons/runtimePublicPath.js +57 -0
- package/es/apis.d.ts +7 -0
- package/es/apis.js +278 -0
- package/es/effects.d.ts +3 -0
- package/es/effects.js +33 -0
- package/es/error.d.ts +3 -0
- package/es/error.js +16 -0
- package/es/errorHandler.d.ts +7 -0
- package/es/errorHandler.js +13 -0
- package/es/globalState.d.ts +7 -0
- package/es/globalState.js +101 -0
- package/es/index.d.ts +11 -0
- package/es/index.js +11 -0
- package/es/interfaces.d.ts +107 -0
- package/es/interfaces.js +8 -0
- package/es/loader.d.ts +8 -0
- package/es/loader.js +600 -0
- package/es/prefetch.d.ts +14 -0
- package/es/prefetch.js +125 -0
- package/es/sandbox/common.d.ts +21 -0
- package/es/sandbox/common.js +157 -0
- package/es/sandbox/index.d.ts +40 -0
- package/es/sandbox/index.js +105 -0
- package/es/sandbox/legacy/sandbox.d.ts +28 -0
- package/es/sandbox/legacy/sandbox.js +142 -0
- package/es/sandbox/patchers/css.d.ts +17 -0
- package/es/sandbox/patchers/css.js +186 -0
- package/es/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
- package/es/sandbox/patchers/dynamicAppend/common.js +306 -0
- package/es/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
- package/es/sandbox/patchers/dynamicAppend/forLooseSandbox.js +77 -0
- package/es/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
- package/es/sandbox/patchers/dynamicAppend/forStrictSandbox.js +103 -0
- package/es/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
- package/es/sandbox/patchers/dynamicAppend/index.js +6 -0
- package/es/sandbox/patchers/historyListener.d.ts +5 -0
- package/es/sandbox/patchers/historyListener.js +54 -0
- package/es/sandbox/patchers/index.d.ts +9 -0
- package/es/sandbox/patchers/index.js +45 -0
- package/es/sandbox/patchers/interval.d.ts +5 -0
- package/es/sandbox/patchers/interval.js +34 -0
- package/es/sandbox/patchers/windowListener.d.ts +5 -0
- package/es/sandbox/patchers/windowListener.js +34 -0
- package/es/sandbox/proxySandbox.d.ts +23 -0
- package/es/sandbox/proxySandbox.js +315 -0
- package/es/sandbox/snapshotSandbox.d.ts +20 -0
- package/es/sandbox/snapshotSandbox.js +59 -0
- package/es/utils.d.ts +44 -0
- package/es/utils.js +215 -0
- package/es/version.d.ts +1 -0
- package/es/version.js +1 -0
- package/lib/addons/engineFlag.d.ts +6 -0
- package/lib/addons/engineFlag.js +55 -0
- package/lib/addons/index.d.ts +6 -0
- package/lib/addons/index.js +21 -0
- package/lib/addons/runtimePublicPath.d.ts +6 -0
- package/lib/addons/runtimePublicPath.js +63 -0
- package/lib/apis.d.ts +7 -0
- package/lib/apis.js +288 -0
- package/lib/effects.d.ts +3 -0
- package/lib/effects.js +42 -0
- package/lib/error.d.ts +3 -0
- package/lib/error.js +23 -0
- package/lib/errorHandler.d.ts +7 -0
- package/lib/errorHandler.js +33 -0
- package/lib/globalState.d.ts +7 -0
- package/lib/globalState.js +110 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +89 -0
- package/lib/interfaces.d.ts +107 -0
- package/lib/interfaces.js +14 -0
- package/lib/loader.d.ts +8 -0
- package/lib/loader.js +606 -0
- package/lib/prefetch.d.ts +14 -0
- package/lib/prefetch.js +132 -0
- package/lib/sandbox/common.d.ts +21 -0
- package/lib/sandbox/common.js +169 -0
- package/lib/sandbox/index.d.ts +40 -0
- package/lib/sandbox/index.js +123 -0
- package/lib/sandbox/legacy/sandbox.d.ts +28 -0
- package/lib/sandbox/legacy/sandbox.js +148 -0
- package/lib/sandbox/patchers/css.d.ts +17 -0
- package/lib/sandbox/patchers/css.js +193 -0
- package/lib/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
- package/lib/sandbox/patchers/dynamicAppend/common.js +322 -0
- package/lib/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
- package/lib/sandbox/patchers/dynamicAppend/forLooseSandbox.js +84 -0
- package/lib/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
- package/lib/sandbox/patchers/dynamicAppend/forStrictSandbox.js +110 -0
- package/lib/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
- package/lib/sandbox/patchers/dynamicAppend/index.js +19 -0
- package/lib/sandbox/patchers/historyListener.d.ts +5 -0
- package/lib/sandbox/patchers/historyListener.js +62 -0
- package/lib/sandbox/patchers/index.d.ts +9 -0
- package/lib/sandbox/patchers/index.js +57 -0
- package/lib/sandbox/patchers/interval.d.ts +5 -0
- package/lib/sandbox/patchers/interval.js +42 -0
- package/lib/sandbox/patchers/windowListener.d.ts +5 -0
- package/lib/sandbox/patchers/windowListener.js +42 -0
- package/lib/sandbox/proxySandbox.d.ts +23 -0
- package/lib/sandbox/proxySandbox.js +321 -0
- package/lib/sandbox/snapshotSandbox.d.ts +20 -0
- package/lib/sandbox/snapshotSandbox.js +65 -0
- package/lib/utils.d.ts +44 -0
- package/lib/utils.js +240 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +7 -0
- package/package.json +137 -0
package/lib/loader.js
ADDED
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.loadApp = loadApp;
|
|
8
|
+
var _concat2 = _interopRequireDefault(require("lodash/concat"));
|
|
9
|
+
var _mergeWith3 = _interopRequireDefault(require("lodash/mergeWith"));
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
var _forEach2 = _interopRequireDefault(require("lodash/forEach"));
|
|
12
|
+
var _tslib = require("tslib");
|
|
13
|
+
var _importHtmlEntry = require("import-html-entry");
|
|
14
|
+
var _addons = _interopRequireDefault(require("./addons"));
|
|
15
|
+
var _error = require("./error");
|
|
16
|
+
var _globalState = require("./globalState");
|
|
17
|
+
var _sandbox = require("./sandbox");
|
|
18
|
+
var _utils = require("./utils");
|
|
19
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
20
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); } /**
|
|
21
|
+
* @author Kuitos
|
|
22
|
+
* @since 2020-04-01
|
|
23
|
+
*/
|
|
24
|
+
function assertElementExist(element, msg) {
|
|
25
|
+
if (!element) {
|
|
26
|
+
if (msg) {
|
|
27
|
+
throw new _error.QiankunError(msg);
|
|
28
|
+
}
|
|
29
|
+
throw new _error.QiankunError('element not existed!');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function execHooksChain(hooks, app) {
|
|
33
|
+
var global = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window;
|
|
34
|
+
if (hooks.length) {
|
|
35
|
+
return hooks.reduce(function (chain, hook) {
|
|
36
|
+
return chain.then(function () {
|
|
37
|
+
return hook(app, global);
|
|
38
|
+
});
|
|
39
|
+
}, Promise.resolve());
|
|
40
|
+
}
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
function validateSingularMode(validate, app) {
|
|
44
|
+
return (0, _tslib.__awaiter)(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
45
|
+
return _regenerator().w(function (_context) {
|
|
46
|
+
while (1) switch (_context.n) {
|
|
47
|
+
case 0:
|
|
48
|
+
return _context.a(2, typeof validate === 'function' ? validate(app) : !!validate);
|
|
49
|
+
}
|
|
50
|
+
}, _callee);
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
var supportShadowDOM = document.head.attachShadow || document.head.createShadowRoot;
|
|
55
|
+
function createElement(appContent, strictStyleIsolation, scopedCSS, appInstanceId) {
|
|
56
|
+
var containerElement = document.createElement('div');
|
|
57
|
+
containerElement.innerHTML = appContent;
|
|
58
|
+
// appContent always wrapped with a singular div
|
|
59
|
+
var appElement = containerElement.firstChild;
|
|
60
|
+
if (strictStyleIsolation) {
|
|
61
|
+
if (!supportShadowDOM) {
|
|
62
|
+
console.warn('[qiankun]: As current browser not support shadow dom, your strictStyleIsolation configuration will be ignored!');
|
|
63
|
+
} else {
|
|
64
|
+
var innerHTML = appElement.innerHTML;
|
|
65
|
+
appElement.innerHTML = '';
|
|
66
|
+
var shadow;
|
|
67
|
+
if (appElement.attachShadow) {
|
|
68
|
+
shadow = appElement.attachShadow({
|
|
69
|
+
mode: 'open'
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
// createShadowRoot was proposed in initial spec, which has then been deprecated
|
|
73
|
+
shadow = appElement.createShadowRoot();
|
|
74
|
+
}
|
|
75
|
+
shadow.innerHTML = innerHTML;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (scopedCSS) {
|
|
79
|
+
var attr = appElement.getAttribute(_sandbox.css.QiankunCSSRewriteAttr);
|
|
80
|
+
if (!attr) {
|
|
81
|
+
appElement.setAttribute(_sandbox.css.QiankunCSSRewriteAttr, appInstanceId);
|
|
82
|
+
}
|
|
83
|
+
var styleNodes = appElement.querySelectorAll('style') || [];
|
|
84
|
+
(0, _forEach2.default)(styleNodes, function (stylesheetElement) {
|
|
85
|
+
_sandbox.css.process(appElement, stylesheetElement, appInstanceId);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return appElement;
|
|
89
|
+
}
|
|
90
|
+
/** generate app wrapper dom getter */
|
|
91
|
+
function getAppWrapperGetter(appInstanceId, useLegacyRender, strictStyleIsolation, scopedCSS, elementGetter) {
|
|
92
|
+
return function () {
|
|
93
|
+
if (useLegacyRender) {
|
|
94
|
+
if (strictStyleIsolation) throw new _error.QiankunError('strictStyleIsolation can not be used with legacy render!');
|
|
95
|
+
if (scopedCSS) throw new _error.QiankunError('experimentalStyleIsolation can not be used with legacy render!');
|
|
96
|
+
var appWrapper = document.getElementById((0, _utils.getWrapperId)(appInstanceId));
|
|
97
|
+
assertElementExist(appWrapper, "Wrapper element for ".concat(appInstanceId, " is not existed!"));
|
|
98
|
+
return appWrapper;
|
|
99
|
+
}
|
|
100
|
+
var element = elementGetter();
|
|
101
|
+
assertElementExist(element, "Wrapper element for ".concat(appInstanceId, " is not existed!"));
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
if (strictStyleIsolation && supportShadowDOM) {
|
|
104
|
+
return element.shadowRoot;
|
|
105
|
+
}
|
|
106
|
+
return element;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
var rawAppendChild = HTMLElement.prototype.appendChild;
|
|
110
|
+
var rawRemoveChild = HTMLElement.prototype.removeChild;
|
|
111
|
+
/**
|
|
112
|
+
* Get the render function
|
|
113
|
+
* If the legacy render function is provide, used as it, otherwise we will insert the app element to target container by qiankun
|
|
114
|
+
* @param appInstanceId
|
|
115
|
+
* @param appContent
|
|
116
|
+
* @param legacyRender
|
|
117
|
+
*/
|
|
118
|
+
function getRender(appInstanceId, appContent, legacyRender) {
|
|
119
|
+
var render = function render(_ref, phase) {
|
|
120
|
+
var element = _ref.element,
|
|
121
|
+
loading = _ref.loading,
|
|
122
|
+
container = _ref.container;
|
|
123
|
+
if (legacyRender) {
|
|
124
|
+
if (process.env.NODE_ENV === 'development') {
|
|
125
|
+
console.error('[qiankun] Custom rendering function is deprecated and will be removed in 3.0, you can use the container element setting instead!');
|
|
126
|
+
}
|
|
127
|
+
return legacyRender({
|
|
128
|
+
loading: loading,
|
|
129
|
+
appContent: element ? appContent : ''
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
var containerElement = (0, _utils.getContainer)(container);
|
|
133
|
+
// The container might have be removed after micro app unmounted.
|
|
134
|
+
// Such as the micro app unmount lifecycle called by a react componentWillUnmount lifecycle, after micro app unmounted, the react component might also be removed
|
|
135
|
+
if (phase !== 'unmounted') {
|
|
136
|
+
var errorMsg = function () {
|
|
137
|
+
switch (phase) {
|
|
138
|
+
case 'loading':
|
|
139
|
+
case 'mounting':
|
|
140
|
+
return "Target container with ".concat(container, " not existed while ").concat(appInstanceId, " ").concat(phase, "!");
|
|
141
|
+
case 'mounted':
|
|
142
|
+
return "Target container with ".concat(container, " not existed after ").concat(appInstanceId, " ").concat(phase, "!");
|
|
143
|
+
default:
|
|
144
|
+
return "Target container with ".concat(container, " not existed while ").concat(appInstanceId, " rendering!");
|
|
145
|
+
}
|
|
146
|
+
}();
|
|
147
|
+
assertElementExist(containerElement, errorMsg);
|
|
148
|
+
}
|
|
149
|
+
if (containerElement && !containerElement.contains(element)) {
|
|
150
|
+
// clear the container
|
|
151
|
+
while (containerElement.firstChild) {
|
|
152
|
+
rawRemoveChild.call(containerElement, containerElement.firstChild);
|
|
153
|
+
}
|
|
154
|
+
// append the element to container if it exist
|
|
155
|
+
if (element) {
|
|
156
|
+
rawAppendChild.call(containerElement, element);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
};
|
|
161
|
+
return render;
|
|
162
|
+
}
|
|
163
|
+
function getLifecyclesFromExports(scriptExports, appName, global, globalLatestSetProp) {
|
|
164
|
+
if ((0, _utils.validateExportLifecycle)(scriptExports)) {
|
|
165
|
+
return scriptExports;
|
|
166
|
+
}
|
|
167
|
+
// fallback to sandbox latest set property if it had
|
|
168
|
+
if (globalLatestSetProp) {
|
|
169
|
+
var lifecycles = global[globalLatestSetProp];
|
|
170
|
+
if ((0, _utils.validateExportLifecycle)(lifecycles)) {
|
|
171
|
+
return lifecycles;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (process.env.NODE_ENV === 'development') {
|
|
175
|
+
console.warn("[qiankun] lifecycle not found from ".concat(appName, " entry exports, fallback to get from window['").concat(appName, "']"));
|
|
176
|
+
}
|
|
177
|
+
// fallback to global variable who named with ${appName} while module exports not found
|
|
178
|
+
var globalVariableExports = global[appName];
|
|
179
|
+
if ((0, _utils.validateExportLifecycle)(globalVariableExports)) {
|
|
180
|
+
return globalVariableExports;
|
|
181
|
+
}
|
|
182
|
+
throw new _error.QiankunError("You need to export lifecycle functions in ".concat(appName, " entry"));
|
|
183
|
+
}
|
|
184
|
+
var prevAppUnmountedDeferred;
|
|
185
|
+
function loadApp(app) {
|
|
186
|
+
var configuration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
187
|
+
var lifeCycles = arguments.length > 2 ? arguments[2] : undefined;
|
|
188
|
+
var _a;
|
|
189
|
+
return (0, _tslib.__awaiter)(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee15() {
|
|
190
|
+
var _this = this;
|
|
191
|
+
var entry, appName, appInstanceId, markName, _configuration$singul, singular, _configuration$sandbo, sandbox, excludeAssetFilter, _configuration$global, globalContext, _configuration$transf, transformStorage, importEntryOpts, _yield$importEntry, template, execScripts, assetPublicPath, getExternalScripts, appContent, strictStyleIsolation, scopedCSS, initialAppWrapperElement, initialContainer, legacyRender, render, initialAppWrapperGetter, global, mountSandbox, unmountSandbox, useLooseSandbox, sandboxContainer, _mergeWith, _mergeWith$beforeUnmo, beforeUnmount, _mergeWith$afterUnmou, afterUnmount, _mergeWith$afterMount, afterMount, _mergeWith$beforeMoun, beforeMount, _mergeWith$beforeLoad, beforeLoad, scriptExports, _getLifecyclesFromExp, bootstrap, mount, unmount, update, _getMicroAppStateActi, onGlobalStateChange, setGlobalState, offGlobalStateChange, syncAppWrapperElement2Sandbox, parcelConfigGetter;
|
|
192
|
+
return _regenerator().w(function (_context15) {
|
|
193
|
+
while (1) switch (_context15.n) {
|
|
194
|
+
case 0:
|
|
195
|
+
entry = app.entry, appName = app.name;
|
|
196
|
+
appInstanceId = (0, _utils.genAppInstanceIdByName)(appName);
|
|
197
|
+
markName = "[qiankun] App ".concat(appInstanceId, " Loading");
|
|
198
|
+
if (process.env.NODE_ENV === 'development') {
|
|
199
|
+
(0, _utils.performanceMark)(markName);
|
|
200
|
+
}
|
|
201
|
+
_configuration$singul = configuration.singular, singular = _configuration$singul === void 0 ? false : _configuration$singul, _configuration$sandbo = configuration.sandbox, sandbox = _configuration$sandbo === void 0 ? true : _configuration$sandbo, excludeAssetFilter = configuration.excludeAssetFilter, _configuration$global = configuration.globalContext, globalContext = _configuration$global === void 0 ? window : _configuration$global, _configuration$transf = configuration.transformStorage, transformStorage = _configuration$transf === void 0 ? false : _configuration$transf, importEntryOpts = (0, _tslib.__rest)(configuration, ["singular", "sandbox", "excludeAssetFilter", "globalContext", "transformStorage"]); // get the entry html content and script executor
|
|
202
|
+
_context15.n = 1;
|
|
203
|
+
return (0, _importHtmlEntry.importEntry)(entry, importEntryOpts);
|
|
204
|
+
case 1:
|
|
205
|
+
_yield$importEntry = _context15.v;
|
|
206
|
+
template = _yield$importEntry.template;
|
|
207
|
+
execScripts = _yield$importEntry.execScripts;
|
|
208
|
+
assetPublicPath = _yield$importEntry.assetPublicPath;
|
|
209
|
+
getExternalScripts = _yield$importEntry.getExternalScripts;
|
|
210
|
+
_context15.n = 2;
|
|
211
|
+
return validateExportScript(getExternalScripts, appName);
|
|
212
|
+
case 2:
|
|
213
|
+
_context15.n = 3;
|
|
214
|
+
return validateSingularMode(singular, app);
|
|
215
|
+
case 3:
|
|
216
|
+
if (!_context15.v) {
|
|
217
|
+
_context15.n = 4;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
_context15.n = 4;
|
|
221
|
+
return prevAppUnmountedDeferred && prevAppUnmountedDeferred.promise;
|
|
222
|
+
case 4:
|
|
223
|
+
appContent = (0, _utils.getDefaultTplWrapper)(appInstanceId)(template);
|
|
224
|
+
strictStyleIsolation = (0, _typeof2.default)(sandbox) === 'object' && !!sandbox.strictStyleIsolation;
|
|
225
|
+
if (process.env.NODE_ENV === 'development' && strictStyleIsolation) {
|
|
226
|
+
console.warn("[qiankun] strictStyleIsolation configuration will be removed in 3.0, pls don't depend on it or use experimentalStyleIsolation instead!");
|
|
227
|
+
}
|
|
228
|
+
scopedCSS = (0, _utils.isEnableScopedCSS)(sandbox);
|
|
229
|
+
initialAppWrapperElement = createElement(appContent, strictStyleIsolation, scopedCSS, appInstanceId);
|
|
230
|
+
initialContainer = 'container' in app ? app.container : undefined;
|
|
231
|
+
legacyRender = 'render' in app ? app.render : undefined;
|
|
232
|
+
render = getRender(appInstanceId, appContent, legacyRender); // 第一次加载设置应用可见区域 dom 结构
|
|
233
|
+
// 确保每次应用加载前容器 dom 结构已经设置完毕
|
|
234
|
+
render({
|
|
235
|
+
element: initialAppWrapperElement,
|
|
236
|
+
loading: true,
|
|
237
|
+
container: initialContainer
|
|
238
|
+
}, 'loading');
|
|
239
|
+
initialAppWrapperGetter = getAppWrapperGetter(appInstanceId, !!legacyRender, strictStyleIsolation, scopedCSS, function () {
|
|
240
|
+
return initialAppWrapperElement;
|
|
241
|
+
});
|
|
242
|
+
global = globalContext;
|
|
243
|
+
mountSandbox = function mountSandbox() {
|
|
244
|
+
return Promise.resolve();
|
|
245
|
+
};
|
|
246
|
+
unmountSandbox = function unmountSandbox() {
|
|
247
|
+
return Promise.resolve();
|
|
248
|
+
};
|
|
249
|
+
useLooseSandbox = (0, _typeof2.default)(sandbox) === 'object' && !!sandbox.loose;
|
|
250
|
+
if (sandbox) {
|
|
251
|
+
sandboxContainer = (0, _sandbox.createSandboxContainer)(appInstanceId,
|
|
252
|
+
// FIXME should use a strict sandbox logic while remount, see https://github.com/umijs/qiankun/issues/518
|
|
253
|
+
initialAppWrapperGetter, scopedCSS, useLooseSandbox, excludeAssetFilter, global, transformStorage);
|
|
254
|
+
// 用沙箱的代理对象作为接下来使用的全局对象
|
|
255
|
+
global = sandboxContainer.instance.proxy;
|
|
256
|
+
mountSandbox = sandboxContainer.mount;
|
|
257
|
+
unmountSandbox = sandboxContainer.unmount;
|
|
258
|
+
}
|
|
259
|
+
_mergeWith = (0, _mergeWith3.default)({}, (0, _addons.default)(global, assetPublicPath), lifeCycles, function (v1, v2) {
|
|
260
|
+
return (0, _concat2.default)(v1 !== null && v1 !== void 0 ? v1 : [], v2 !== null && v2 !== void 0 ? v2 : []);
|
|
261
|
+
}), _mergeWith$beforeUnmo = _mergeWith.beforeUnmount, beforeUnmount = _mergeWith$beforeUnmo === void 0 ? [] : _mergeWith$beforeUnmo, _mergeWith$afterUnmou = _mergeWith.afterUnmount, afterUnmount = _mergeWith$afterUnmou === void 0 ? [] : _mergeWith$afterUnmou, _mergeWith$afterMount = _mergeWith.afterMount, afterMount = _mergeWith$afterMount === void 0 ? [] : _mergeWith$afterMount, _mergeWith$beforeMoun = _mergeWith.beforeMount, beforeMount = _mergeWith$beforeMoun === void 0 ? [] : _mergeWith$beforeMoun, _mergeWith$beforeLoad = _mergeWith.beforeLoad, beforeLoad = _mergeWith$beforeLoad === void 0 ? [] : _mergeWith$beforeLoad;
|
|
262
|
+
_context15.n = 5;
|
|
263
|
+
return execHooksChain((0, _utils.toArray)(beforeLoad), app, global);
|
|
264
|
+
case 5:
|
|
265
|
+
_context15.n = 6;
|
|
266
|
+
return execScripts(global, sandbox && !useLooseSandbox);
|
|
267
|
+
case 6:
|
|
268
|
+
scriptExports = _context15.v;
|
|
269
|
+
_getLifecyclesFromExp = getLifecyclesFromExports(scriptExports, appName, global, (_a = sandboxContainer === null || sandboxContainer === void 0 ? void 0 : sandboxContainer.instance) === null || _a === void 0 ? void 0 : _a.latestSetProp), bootstrap = _getLifecyclesFromExp.bootstrap, mount = _getLifecyclesFromExp.mount, unmount = _getLifecyclesFromExp.unmount, update = _getLifecyclesFromExp.update;
|
|
270
|
+
_getMicroAppStateActi = (0, _globalState.getMicroAppStateActions)(appInstanceId), onGlobalStateChange = _getMicroAppStateActi.onGlobalStateChange, setGlobalState = _getMicroAppStateActi.setGlobalState, offGlobalStateChange = _getMicroAppStateActi.offGlobalStateChange; // FIXME temporary way
|
|
271
|
+
syncAppWrapperElement2Sandbox = function syncAppWrapperElement2Sandbox(element) {
|
|
272
|
+
return initialAppWrapperElement = element;
|
|
273
|
+
};
|
|
274
|
+
parcelConfigGetter = function parcelConfigGetter() {
|
|
275
|
+
var remountContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialContainer;
|
|
276
|
+
var appWrapperElement;
|
|
277
|
+
var appWrapperGetter;
|
|
278
|
+
var parcelConfig = {
|
|
279
|
+
name: appInstanceId,
|
|
280
|
+
bootstrap: bootstrap,
|
|
281
|
+
mount: [function () {
|
|
282
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
|
|
283
|
+
var marks;
|
|
284
|
+
return _regenerator().w(function (_context2) {
|
|
285
|
+
while (1) switch (_context2.n) {
|
|
286
|
+
case 0:
|
|
287
|
+
if (process.env.NODE_ENV === 'development') {
|
|
288
|
+
marks = (0, _utils.performanceGetEntriesByName)(markName, 'mark'); // mark length is zero means the app is remounting
|
|
289
|
+
if (marks && !marks.length) {
|
|
290
|
+
(0, _utils.performanceMark)(markName);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
case 1:
|
|
294
|
+
return _context2.a(2);
|
|
295
|
+
}
|
|
296
|
+
}, _callee2);
|
|
297
|
+
}));
|
|
298
|
+
}, function () {
|
|
299
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
|
|
300
|
+
var _t;
|
|
301
|
+
return _regenerator().w(function (_context3) {
|
|
302
|
+
while (1) switch (_context3.n) {
|
|
303
|
+
case 0:
|
|
304
|
+
_context3.n = 1;
|
|
305
|
+
return validateSingularMode(singular, app);
|
|
306
|
+
case 1:
|
|
307
|
+
_t = _context3.v;
|
|
308
|
+
if (!_t) {
|
|
309
|
+
_context3.n = 2;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
_t = prevAppUnmountedDeferred;
|
|
313
|
+
case 2:
|
|
314
|
+
if (!_t) {
|
|
315
|
+
_context3.n = 3;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
return _context3.a(2, prevAppUnmountedDeferred.promise);
|
|
319
|
+
case 3:
|
|
320
|
+
return _context3.a(2, undefined);
|
|
321
|
+
}
|
|
322
|
+
}, _callee3);
|
|
323
|
+
}));
|
|
324
|
+
},
|
|
325
|
+
// initial wrapper element before app mount/remount
|
|
326
|
+
function () {
|
|
327
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
|
|
328
|
+
return _regenerator().w(function (_context4) {
|
|
329
|
+
while (1) switch (_context4.n) {
|
|
330
|
+
case 0:
|
|
331
|
+
appWrapperElement = initialAppWrapperElement;
|
|
332
|
+
appWrapperGetter = getAppWrapperGetter(appInstanceId, !!legacyRender, strictStyleIsolation, scopedCSS, function () {
|
|
333
|
+
return appWrapperElement;
|
|
334
|
+
});
|
|
335
|
+
case 1:
|
|
336
|
+
return _context4.a(2);
|
|
337
|
+
}
|
|
338
|
+
}, _callee4);
|
|
339
|
+
}));
|
|
340
|
+
},
|
|
341
|
+
// 添加 mount hook, 确保每次应用加载前容器 dom 结构已经设置完毕
|
|
342
|
+
function () {
|
|
343
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
|
|
344
|
+
var useNewContainer;
|
|
345
|
+
return _regenerator().w(function (_context5) {
|
|
346
|
+
while (1) switch (_context5.n) {
|
|
347
|
+
case 0:
|
|
348
|
+
useNewContainer = remountContainer !== initialContainer;
|
|
349
|
+
if (useNewContainer || !appWrapperElement) {
|
|
350
|
+
// element will be destroyed after unmounted, we need to recreate it if it not exist
|
|
351
|
+
// or we try to remount into a new container
|
|
352
|
+
appWrapperElement = createElement(appContent, strictStyleIsolation, scopedCSS, appInstanceId);
|
|
353
|
+
syncAppWrapperElement2Sandbox(appWrapperElement);
|
|
354
|
+
}
|
|
355
|
+
render({
|
|
356
|
+
element: appWrapperElement,
|
|
357
|
+
loading: true,
|
|
358
|
+
container: remountContainer
|
|
359
|
+
}, 'mounting');
|
|
360
|
+
case 1:
|
|
361
|
+
return _context5.a(2);
|
|
362
|
+
}
|
|
363
|
+
}, _callee5);
|
|
364
|
+
}));
|
|
365
|
+
}, mountSandbox,
|
|
366
|
+
// exec the chain after rendering to keep the behavior with beforeLoad
|
|
367
|
+
function () {
|
|
368
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee6() {
|
|
369
|
+
return _regenerator().w(function (_context6) {
|
|
370
|
+
while (1) switch (_context6.n) {
|
|
371
|
+
case 0:
|
|
372
|
+
return _context6.a(2, execHooksChain((0, _utils.toArray)(beforeMount), app, global));
|
|
373
|
+
}
|
|
374
|
+
}, _callee6);
|
|
375
|
+
}));
|
|
376
|
+
}, function (props) {
|
|
377
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee7() {
|
|
378
|
+
return _regenerator().w(function (_context7) {
|
|
379
|
+
while (1) switch (_context7.n) {
|
|
380
|
+
case 0:
|
|
381
|
+
return _context7.a(2, mount(Object.assign(Object.assign({}, props), {
|
|
382
|
+
container: appWrapperGetter(),
|
|
383
|
+
setGlobalState: setGlobalState,
|
|
384
|
+
onGlobalStateChange: onGlobalStateChange
|
|
385
|
+
})));
|
|
386
|
+
}
|
|
387
|
+
}, _callee7);
|
|
388
|
+
}));
|
|
389
|
+
},
|
|
390
|
+
// finish loading after app mounted
|
|
391
|
+
function () {
|
|
392
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee8() {
|
|
393
|
+
return _regenerator().w(function (_context8) {
|
|
394
|
+
while (1) switch (_context8.n) {
|
|
395
|
+
case 0:
|
|
396
|
+
return _context8.a(2, render({
|
|
397
|
+
element: appWrapperElement,
|
|
398
|
+
loading: false,
|
|
399
|
+
container: remountContainer
|
|
400
|
+
}, 'mounted'));
|
|
401
|
+
}
|
|
402
|
+
}, _callee8);
|
|
403
|
+
}));
|
|
404
|
+
}, function () {
|
|
405
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee9() {
|
|
406
|
+
return _regenerator().w(function (_context9) {
|
|
407
|
+
while (1) switch (_context9.n) {
|
|
408
|
+
case 0:
|
|
409
|
+
return _context9.a(2, execHooksChain((0, _utils.toArray)(afterMount), app, global));
|
|
410
|
+
}
|
|
411
|
+
}, _callee9);
|
|
412
|
+
}));
|
|
413
|
+
},
|
|
414
|
+
// initialize the unmount defer after app mounted and resolve the defer after it unmounted
|
|
415
|
+
function () {
|
|
416
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee0() {
|
|
417
|
+
return _regenerator().w(function (_context0) {
|
|
418
|
+
while (1) switch (_context0.n) {
|
|
419
|
+
case 0:
|
|
420
|
+
_context0.n = 1;
|
|
421
|
+
return validateSingularMode(singular, app);
|
|
422
|
+
case 1:
|
|
423
|
+
if (!_context0.v) {
|
|
424
|
+
_context0.n = 2;
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
prevAppUnmountedDeferred = new _utils.Deferred();
|
|
428
|
+
case 2:
|
|
429
|
+
return _context0.a(2);
|
|
430
|
+
}
|
|
431
|
+
}, _callee0);
|
|
432
|
+
}));
|
|
433
|
+
}, function () {
|
|
434
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee1() {
|
|
435
|
+
var measureName;
|
|
436
|
+
return _regenerator().w(function (_context1) {
|
|
437
|
+
while (1) switch (_context1.n) {
|
|
438
|
+
case 0:
|
|
439
|
+
if (process.env.NODE_ENV === 'development') {
|
|
440
|
+
measureName = "[qiankun] App ".concat(appInstanceId, " Loading Consuming");
|
|
441
|
+
(0, _utils.performanceMeasure)(measureName, markName);
|
|
442
|
+
}
|
|
443
|
+
case 1:
|
|
444
|
+
return _context1.a(2);
|
|
445
|
+
}
|
|
446
|
+
}, _callee1);
|
|
447
|
+
}));
|
|
448
|
+
}],
|
|
449
|
+
unmount: [function () {
|
|
450
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee10() {
|
|
451
|
+
return _regenerator().w(function (_context10) {
|
|
452
|
+
while (1) switch (_context10.n) {
|
|
453
|
+
case 0:
|
|
454
|
+
return _context10.a(2, execHooksChain((0, _utils.toArray)(beforeUnmount), app, global));
|
|
455
|
+
}
|
|
456
|
+
}, _callee10);
|
|
457
|
+
}));
|
|
458
|
+
}, function (props) {
|
|
459
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee11() {
|
|
460
|
+
return _regenerator().w(function (_context11) {
|
|
461
|
+
while (1) switch (_context11.n) {
|
|
462
|
+
case 0:
|
|
463
|
+
return _context11.a(2, unmount(Object.assign(Object.assign({}, props), {
|
|
464
|
+
container: appWrapperGetter()
|
|
465
|
+
})));
|
|
466
|
+
}
|
|
467
|
+
}, _callee11);
|
|
468
|
+
}));
|
|
469
|
+
}, unmountSandbox, function () {
|
|
470
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee12() {
|
|
471
|
+
return _regenerator().w(function (_context12) {
|
|
472
|
+
while (1) switch (_context12.n) {
|
|
473
|
+
case 0:
|
|
474
|
+
return _context12.a(2, execHooksChain((0, _utils.toArray)(afterUnmount), app, global));
|
|
475
|
+
}
|
|
476
|
+
}, _callee12);
|
|
477
|
+
}));
|
|
478
|
+
}, function () {
|
|
479
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee13() {
|
|
480
|
+
return _regenerator().w(function (_context13) {
|
|
481
|
+
while (1) switch (_context13.n) {
|
|
482
|
+
case 0:
|
|
483
|
+
render({
|
|
484
|
+
element: null,
|
|
485
|
+
loading: false,
|
|
486
|
+
container: remountContainer
|
|
487
|
+
}, 'unmounted');
|
|
488
|
+
offGlobalStateChange(appInstanceId);
|
|
489
|
+
// for gc
|
|
490
|
+
appWrapperElement = null;
|
|
491
|
+
syncAppWrapperElement2Sandbox(appWrapperElement);
|
|
492
|
+
case 1:
|
|
493
|
+
return _context13.a(2);
|
|
494
|
+
}
|
|
495
|
+
}, _callee13);
|
|
496
|
+
}));
|
|
497
|
+
}, function () {
|
|
498
|
+
return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee14() {
|
|
499
|
+
var _t2;
|
|
500
|
+
return _regenerator().w(function (_context14) {
|
|
501
|
+
while (1) switch (_context14.n) {
|
|
502
|
+
case 0:
|
|
503
|
+
_context14.n = 1;
|
|
504
|
+
return validateSingularMode(singular, app);
|
|
505
|
+
case 1:
|
|
506
|
+
_t2 = _context14.v;
|
|
507
|
+
if (!_t2) {
|
|
508
|
+
_context14.n = 2;
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
_t2 = prevAppUnmountedDeferred;
|
|
512
|
+
case 2:
|
|
513
|
+
if (!_t2) {
|
|
514
|
+
_context14.n = 3;
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
prevAppUnmountedDeferred.resolve();
|
|
518
|
+
case 3:
|
|
519
|
+
return _context14.a(2);
|
|
520
|
+
}
|
|
521
|
+
}, _callee14);
|
|
522
|
+
}));
|
|
523
|
+
}]
|
|
524
|
+
};
|
|
525
|
+
if (typeof update === 'function') {
|
|
526
|
+
parcelConfig.update = update;
|
|
527
|
+
}
|
|
528
|
+
return parcelConfig;
|
|
529
|
+
};
|
|
530
|
+
return _context15.a(2, parcelConfigGetter);
|
|
531
|
+
}
|
|
532
|
+
}, _callee15);
|
|
533
|
+
}));
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Validate micro app scripts contain lifecycle hints before execution.
|
|
537
|
+
* This performs a heuristic scan over fetched external script contents to
|
|
538
|
+
* check for presence of qiankun-required lifecycles (bootstrap/mount/unmount).
|
|
539
|
+
* If none of the scripts indicate these lifecycles, throws a QiankunError.
|
|
540
|
+
*/
|
|
541
|
+
function validateExportScript(getExternalScripts, appName) {
|
|
542
|
+
return (0, _tslib.__awaiter)(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee16() {
|
|
543
|
+
var scripts, escapedName, hasHook, concatenated, hasBootstrap, hasMount, hasUnmount, _t3;
|
|
544
|
+
return _regenerator().w(function (_context16) {
|
|
545
|
+
while (1) switch (_context16.p = _context16.n) {
|
|
546
|
+
case 0:
|
|
547
|
+
_context16.p = 0;
|
|
548
|
+
_context16.n = 1;
|
|
549
|
+
return getExternalScripts();
|
|
550
|
+
case 1:
|
|
551
|
+
scripts = _context16.v;
|
|
552
|
+
if (!(!scripts || !scripts.length)) {
|
|
553
|
+
_context16.n = 2;
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
return _context16.a(2);
|
|
557
|
+
case 2:
|
|
558
|
+
// no external scripts to validate
|
|
559
|
+
escapedName = appName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
560
|
+
hasHook = function hasHook(source, hook) {
|
|
561
|
+
var patterns = [
|
|
562
|
+
// ESM export function
|
|
563
|
+
new RegExp("export\\s+(?:async\\s+)?function\\s+".concat(hook, "\\b")),
|
|
564
|
+
// CommonJS exports assignment
|
|
565
|
+
new RegExp("exports\\.".concat(hook, "\\s*=")),
|
|
566
|
+
// CommonJS module.exports object
|
|
567
|
+
new RegExp("module\\.exports\\s*=\\s*\\{[\\s\\S]*?".concat(hook, "\\b"), 'm'),
|
|
568
|
+
// Object property function definition
|
|
569
|
+
new RegExp("".concat(hook, "\\s*:\\s*(?:async\\s*)?function\\b")),
|
|
570
|
+
// Plain function definition (best-effort)
|
|
571
|
+
new RegExp("function\\s+".concat(hook, "\\s*\\(")),
|
|
572
|
+
// Global assign to window[appName] = { ...hook... }
|
|
573
|
+
new RegExp("window\\[\\s*['\"]".concat(escapedName, "['\"]\\s*\\]\\s*=\\s*\\{[\\s\\S]*?").concat(hook, "\\b"), 'm'), new RegExp("window\\.".concat(escapedName, "\\s*=\\s*\\{[\\s\\S]*?").concat(hook, "\\b"), 'm')];
|
|
574
|
+
return patterns.some(function (re) {
|
|
575
|
+
return re.test(source);
|
|
576
|
+
});
|
|
577
|
+
}; // Merge all scripts for a holistic scan and also check individually
|
|
578
|
+
concatenated = scripts.map(function (it) {
|
|
579
|
+
var _a;
|
|
580
|
+
return (_a = it.value) !== null && _a !== void 0 ? _a : '';
|
|
581
|
+
}).join('\n');
|
|
582
|
+
hasBootstrap = hasHook(concatenated, 'bootstrap');
|
|
583
|
+
hasMount = hasHook(concatenated, 'mount');
|
|
584
|
+
hasUnmount = hasHook(concatenated, 'unmount');
|
|
585
|
+
if (hasBootstrap && hasMount && hasUnmount) {
|
|
586
|
+
_context16.n = 3;
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
throw new _error.QiankunError("You need to export lifecycle functions in ".concat(appName, " entry"));
|
|
590
|
+
case 3:
|
|
591
|
+
_context16.n = 5;
|
|
592
|
+
break;
|
|
593
|
+
case 4:
|
|
594
|
+
_context16.p = 4;
|
|
595
|
+
_t3 = _context16.v;
|
|
596
|
+
if (!(_t3 instanceof _error.QiankunError)) {
|
|
597
|
+
_context16.n = 5;
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
throw _t3;
|
|
601
|
+
case 5:
|
|
602
|
+
return _context16.a(2);
|
|
603
|
+
}
|
|
604
|
+
}, _callee16, null, [[0, 4]]);
|
|
605
|
+
}));
|
|
606
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Kuitos
|
|
3
|
+
* @since 2019-02-26
|
|
4
|
+
*/
|
|
5
|
+
import type { ImportEntryOpts } from 'import-html-entry';
|
|
6
|
+
import type { AppMetadata, PrefetchStrategy } from './interfaces';
|
|
7
|
+
declare global {
|
|
8
|
+
interface NetworkInformation {
|
|
9
|
+
saveData: boolean;
|
|
10
|
+
effectiveType: string;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare function prefetchImmediately(apps: AppMetadata[], opts?: ImportEntryOpts): void;
|
|
14
|
+
export declare function doPrefetchStrategy(apps: AppMetadata[], prefetchStrategy: PrefetchStrategy, importEntryOpts?: ImportEntryOpts): void;
|