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