@module-federation/utilities 3.1.82 → 3.1.84
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/Logger.js +60 -0
- package/dist/cjs/components/ErrorBoundary.js +96 -0
- package/dist/cjs/components/FederationBoundary.js +101 -0
- package/dist/cjs/index.js +170 -0
- package/dist/cjs/plugins/DelegateModulesPlugin.js +130 -0
- package/dist/cjs/types/index.js +33 -0
- package/dist/cjs/utils/common.js +173 -0
- package/dist/cjs/utils/getRuntimeRemotes.js +102 -0
- package/dist/cjs/utils/getRuntimeRemotes.test.js +98 -0
- package/dist/cjs/utils/importDelegateModule.test.js +101 -0
- package/dist/cjs/utils/importDelegatedModule.js +124 -0
- package/dist/cjs/utils/importRemote.js +174 -0
- package/dist/cjs/utils/isEmpty.js +56 -0
- package/dist/cjs/utils/pure.js +212 -0
- package/dist/cjs/utils/react.js +71 -0
- package/dist/esm/Logger.mjs +14 -0
- package/dist/esm/components/ErrorBoundary.mjs +33 -0
- package/dist/esm/components/FederationBoundary.mjs +38 -0
- package/dist/esm/index.mjs +34 -0
- package/dist/esm/plugins/DelegateModulesPlugin.mjs +84 -0
- package/dist/esm/types/index.mjs +6 -0
- package/dist/esm/utils/common.mjs +126 -0
- package/dist/esm/utils/getRuntimeRemotes.mjs +52 -0
- package/dist/esm/utils/getRuntimeRemotes.test.mjs +87 -0
- package/dist/esm/utils/importDelegateModule.test.mjs +90 -0
- package/dist/esm/utils/importDelegatedModule.mjs +74 -0
- package/dist/esm/utils/importRemote.mjs +137 -0
- package/dist/esm/utils/isEmpty.mjs +10 -0
- package/dist/esm/utils/pure.mjs +164 -0
- package/dist/esm/utils/react.mjs +8 -0
- package/package.json +2 -2
- package/dist/index.cjs.js +0 -555
- package/dist/index.d.ts +0 -1
- package/dist/index.esm.js +0 -543
- /package/dist/{src → types}/Logger.d.ts +0 -0
- /package/dist/{src → types}/components/ErrorBoundary.d.ts +0 -0
- /package/dist/{src → types}/components/FederationBoundary.d.ts +0 -0
- /package/dist/{src → types}/index.d.ts +0 -0
- /package/dist/{src → types}/plugins/DelegateModulesPlugin.d.ts +0 -0
- /package/dist/{src → types}/types/index.d.ts +0 -0
- /package/dist/{src → types}/utils/common.d.ts +0 -0
- /package/dist/{src → types}/utils/getRuntimeRemotes.d.ts +0 -0
- /package/dist/{src → types}/utils/importDelegatedModule.d.ts +0 -0
- /package/dist/{src → types}/utils/importRemote.d.ts +0 -0
- /package/dist/{src → types}/utils/isEmpty.d.ts +0 -0
- /package/dist/{src → types}/utils/pure.d.ts +0 -0
- /package/dist/{src → types}/utils/react.d.ts +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/define_property_getters
|
|
14
|
+
(() => {
|
|
15
|
+
__webpack_require__.d = (exports, definition) => {
|
|
16
|
+
for(var key in definition) {
|
|
17
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
18
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
// webpack/runtime/has_own_property
|
|
24
|
+
(() => {
|
|
25
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
26
|
+
})();
|
|
27
|
+
// webpack/runtime/make_namespace_object
|
|
28
|
+
(() => {
|
|
29
|
+
// define __esModule on exports
|
|
30
|
+
__webpack_require__.r = (exports) => {
|
|
31
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
32
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
/************************************************************************/
|
|
38
|
+
var __webpack_exports__ = {};
|
|
39
|
+
// ESM COMPAT FLAG
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
|
|
42
|
+
// EXPORTS
|
|
43
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
44
|
+
injectScript: () => (/* binding */ injectScript),
|
|
45
|
+
getContainer: () => (/* binding */ getContainer),
|
|
46
|
+
createRuntimeVariables: () => (/* binding */ createRuntimeVariables),
|
|
47
|
+
getModule: () => (/* binding */ getModule)
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
;// CONCATENATED MODULE: external "./pure.js"
|
|
51
|
+
const external_pure_js_namespaceObject = require("./pure.js");
|
|
52
|
+
;// CONCATENATED MODULE: ./src/utils/common.ts
|
|
53
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
54
|
+
const createContainerSharingScope = (asyncContainer)=>{
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
return asyncContainer.then(function(container) {
|
|
57
|
+
if (!__webpack_require__.S['default']) {
|
|
58
|
+
// not always a promise, so we wrap it in a resolve
|
|
59
|
+
return Promise.resolve(__webpack_require__.I('default')).then(function() {
|
|
60
|
+
return container;
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
return container;
|
|
64
|
+
}
|
|
65
|
+
}).then(function(container) {
|
|
66
|
+
try {
|
|
67
|
+
// WARNING: here might be a potential BUG.
|
|
68
|
+
// `container.init` does not return a Promise, and here we do not call `then` on it.
|
|
69
|
+
// But according to [docs](https://webpack.js.org/concepts/module-federation/#dynamic-remote-containers)
|
|
70
|
+
// it must be async.
|
|
71
|
+
// The problem may be in Proxy in NextFederationPlugin.js.
|
|
72
|
+
// or maybe a bug in the webpack itself - instead of returning rejected promise it just throws an error.
|
|
73
|
+
// But now everything works properly and we keep this code as is.
|
|
74
|
+
container.init(__webpack_require__.S['default']);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
// maybe container already initialized so nothing to throw
|
|
77
|
+
}
|
|
78
|
+
return container;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Return initialized remote container by remote's key or its runtime remote item data.
|
|
83
|
+
*
|
|
84
|
+
* `runtimeRemoteItem` might be
|
|
85
|
+
* { global, url } - values obtained from webpack remotes option `global@url`
|
|
86
|
+
* or
|
|
87
|
+
* { asyncContainer } - async container is a promise that resolves to the remote container
|
|
88
|
+
*/ const injectScript = async (keyOrRuntimeRemoteItem)=>{
|
|
89
|
+
const asyncContainer = (0,external_pure_js_namespaceObject.loadScript)(keyOrRuntimeRemoteItem);
|
|
90
|
+
return createContainerSharingScope(asyncContainer);
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Creates runtime variables from the provided remotes.
|
|
94
|
+
* If the value of a remote starts with 'promise ' or 'external ', it is transformed into a function that returns the promise call.
|
|
95
|
+
* Otherwise, the value is stringified.
|
|
96
|
+
* @param {Remotes} remotes - The remotes to create runtime variables from.
|
|
97
|
+
* @returns {Record<string, string>} - The created runtime variables.
|
|
98
|
+
*/ const createRuntimeVariables = (remotes)=>{
|
|
99
|
+
if (!remotes) {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
return Object.entries(remotes).reduce((acc, [key, value])=>{
|
|
103
|
+
if (value.startsWith('promise ') || value.startsWith('external ')) {
|
|
104
|
+
const promiseCall = value.split(' ')[1];
|
|
105
|
+
acc[key] = `function() {
|
|
106
|
+
return ${promiseCall}
|
|
107
|
+
}`;
|
|
108
|
+
} else {
|
|
109
|
+
acc[key] = JSON.stringify(value);
|
|
110
|
+
}
|
|
111
|
+
return acc;
|
|
112
|
+
}, {});
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Returns initialized webpack RemoteContainer.
|
|
116
|
+
* If its' script does not loaded - then load & init it firstly.
|
|
117
|
+
*/ const getContainer = async (remoteContainer)=>{
|
|
118
|
+
if (!remoteContainer) {
|
|
119
|
+
throw Error(`Remote container options is empty`);
|
|
120
|
+
}
|
|
121
|
+
const containerScope = typeof window !== 'undefined' ? window : globalThis.__remote_scope__;
|
|
122
|
+
let containerKey;
|
|
123
|
+
if (typeof remoteContainer === 'string') {
|
|
124
|
+
containerKey = remoteContainer;
|
|
125
|
+
} else {
|
|
126
|
+
containerKey = remoteContainer.uniqueKey;
|
|
127
|
+
if (!containerScope[containerKey]) {
|
|
128
|
+
const container = await injectScript({
|
|
129
|
+
global: remoteContainer.global,
|
|
130
|
+
url: remoteContainer.url
|
|
131
|
+
});
|
|
132
|
+
if (!container) {
|
|
133
|
+
throw Error(`Remote container ${remoteContainer.url} is empty`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return containerScope[containerKey];
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Return remote module from container.
|
|
141
|
+
* If you provide `exportName` it automatically return exact property value from module.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* remote.getModule('./pages/index', 'default')
|
|
145
|
+
*/ const getModule = async ({ remoteContainer, modulePath, exportName })=>{
|
|
146
|
+
const container = await getContainer(remoteContainer);
|
|
147
|
+
try {
|
|
148
|
+
const modFactory = await (container === null || container === void 0 ? void 0 : container.get(modulePath));
|
|
149
|
+
if (!modFactory) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
const mod = modFactory();
|
|
153
|
+
if (exportName) {
|
|
154
|
+
return mod && typeof mod === 'object' ? mod[exportName] : undefined;
|
|
155
|
+
} else {
|
|
156
|
+
return mod;
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error(error);
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
exports.createRuntimeVariables = __webpack_exports__.createRuntimeVariables;
|
|
165
|
+
exports.getContainer = __webpack_exports__.getContainer;
|
|
166
|
+
exports.getModule = __webpack_exports__.getModule;
|
|
167
|
+
exports.injectScript = __webpack_exports__.injectScript;
|
|
168
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
169
|
+
if(["createRuntimeVariables","getContainer","getModule","injectScript"].indexOf(__webpack_i__) === -1) {
|
|
170
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/define_property_getters
|
|
14
|
+
(() => {
|
|
15
|
+
__webpack_require__.d = (exports, definition) => {
|
|
16
|
+
for(var key in definition) {
|
|
17
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
18
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
// webpack/runtime/has_own_property
|
|
24
|
+
(() => {
|
|
25
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
26
|
+
})();
|
|
27
|
+
// webpack/runtime/make_namespace_object
|
|
28
|
+
(() => {
|
|
29
|
+
// define __esModule on exports
|
|
30
|
+
__webpack_require__.r = (exports) => {
|
|
31
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
32
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
/************************************************************************/
|
|
38
|
+
var __webpack_exports__ = {};
|
|
39
|
+
// ESM COMPAT FLAG
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
|
|
42
|
+
// EXPORTS
|
|
43
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
44
|
+
getRuntimeRemotes: () => (/* binding */ getRuntimeRemotes)
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
;// CONCATENATED MODULE: external "./pure.js"
|
|
48
|
+
const external_pure_js_namespaceObject = require("./pure.js");
|
|
49
|
+
;// CONCATENATED MODULE: ./src/utils/getRuntimeRemotes.ts
|
|
50
|
+
|
|
51
|
+
const getRuntimeRemotes = ()=>{
|
|
52
|
+
try {
|
|
53
|
+
return Object.entries(external_pure_js_namespaceObject.remoteVars).reduce(function(acc, item) {
|
|
54
|
+
const [key, value] = item;
|
|
55
|
+
// if its an object with a thenable (eagerly executing function)
|
|
56
|
+
if (typeof value === 'object' && typeof value.then === 'function') {
|
|
57
|
+
acc[key] = {
|
|
58
|
+
asyncContainer: value
|
|
59
|
+
};
|
|
60
|
+
} else if (typeof value === 'function') {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
acc[key] = {
|
|
63
|
+
asyncContainer: value
|
|
64
|
+
};
|
|
65
|
+
} else if (typeof value === 'string' && value.startsWith('internal ')) {
|
|
66
|
+
const [request, query] = value.replace('internal ', '').split('?');
|
|
67
|
+
if (query) {
|
|
68
|
+
const remoteSyntax = new URLSearchParams(query).get('remote');
|
|
69
|
+
if (remoteSyntax) {
|
|
70
|
+
const [url, global] = (0,external_pure_js_namespaceObject.extractUrlAndGlobal)(remoteSyntax);
|
|
71
|
+
acc[key] = {
|
|
72
|
+
global,
|
|
73
|
+
url
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else if (typeof value === 'string') {
|
|
78
|
+
const [url, global] = (0,external_pure_js_namespaceObject.extractUrlAndGlobal)(value);
|
|
79
|
+
acc[key] = {
|
|
80
|
+
global,
|
|
81
|
+
url
|
|
82
|
+
};
|
|
83
|
+
} else {
|
|
84
|
+
//@ts-ignore
|
|
85
|
+
console.warn('remotes process', process.env.REMOTES);
|
|
86
|
+
throw new Error(`[mf] Invalid value received for runtime_remote "${key}"`);
|
|
87
|
+
}
|
|
88
|
+
return acc;
|
|
89
|
+
}, {});
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.warn('Unable to retrieve runtime remotes: ', err);
|
|
92
|
+
}
|
|
93
|
+
return {};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
exports.getRuntimeRemotes = __webpack_exports__.getRuntimeRemotes;
|
|
97
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
98
|
+
if(["getRuntimeRemotes"].indexOf(__webpack_i__) === -1) {
|
|
99
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
var __webpack_exports__ = {};
|
|
10
|
+
|
|
11
|
+
;// CONCATENATED MODULE: external "./getRuntimeRemotes.js"
|
|
12
|
+
const external_getRuntimeRemotes_js_namespaceObject = require("./getRuntimeRemotes.js");
|
|
13
|
+
;// CONCATENATED MODULE: external "./pure.js"
|
|
14
|
+
const external_pure_js_namespaceObject = require("./pure.js");
|
|
15
|
+
;// CONCATENATED MODULE: ./src/utils/getRuntimeRemotes.test.ts
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
xdescribe('getRuntimeRemotes', ()=>{
|
|
19
|
+
afterEach(()=>{
|
|
20
|
+
Object.keys(external_pure_js_namespaceObject.remoteVars).forEach((key)=>{
|
|
21
|
+
delete external_pure_js_namespaceObject.remoteVars[key];
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
test('returns an empty object if REMOTES is not set', ()=>{
|
|
25
|
+
const remotes = (0,external_getRuntimeRemotes_js_namespaceObject.getRuntimeRemotes)();
|
|
26
|
+
expect(remotes).toEqual({});
|
|
27
|
+
});
|
|
28
|
+
test('parses asyncContainer from thenable object', ()=>{
|
|
29
|
+
const thenable = Promise.resolve({
|
|
30
|
+
get: ()=>true,
|
|
31
|
+
init: ()=>true
|
|
32
|
+
});
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
external_pure_js_namespaceObject.remoteVars.thenable = thenable;
|
|
35
|
+
const remotes = (0,external_getRuntimeRemotes_js_namespaceObject.getRuntimeRemotes)();
|
|
36
|
+
expect(remotes).toEqual({
|
|
37
|
+
thenable: {
|
|
38
|
+
asyncContainer: thenable
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
test('parses asyncContainer from lazily executing function', ()=>{
|
|
43
|
+
const lazyFunction = ()=>Promise.resolve({
|
|
44
|
+
get: ()=>true,
|
|
45
|
+
init: ()=>true
|
|
46
|
+
});
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
external_pure_js_namespaceObject.remoteVars.lazyFunction = lazyFunction;
|
|
49
|
+
const remotes = (0,external_getRuntimeRemotes_js_namespaceObject.getRuntimeRemotes)();
|
|
50
|
+
expect(remotes).toHaveProperty('lazyFunction.asyncContainer');
|
|
51
|
+
expect(typeof remotes['lazyFunction'].asyncContainer).toBe('function');
|
|
52
|
+
});
|
|
53
|
+
test('parses delegate module', ()=>{
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
Object.assign(external_pure_js_namespaceObject.remoteVars, {
|
|
56
|
+
delegate: 'internal some_module?remote=remoteGlobal@https://example.com/remoteEntry.js'
|
|
57
|
+
});
|
|
58
|
+
const remotes = (0,external_getRuntimeRemotes_js_namespaceObject.getRuntimeRemotes)();
|
|
59
|
+
expect(remotes).toEqual({
|
|
60
|
+
delegate: {
|
|
61
|
+
global: 'remoteGlobal',
|
|
62
|
+
url: 'https://example.com/remoteEntry.js'
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
test('parses global@url string', ()=>{
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
external_pure_js_namespaceObject.remoteVars.remote = 'remoteGlobal@https://example.com/remoteEntry.js';
|
|
69
|
+
const remotes = (0,external_getRuntimeRemotes_js_namespaceObject.getRuntimeRemotes)();
|
|
70
|
+
expect(remotes).toEqual({
|
|
71
|
+
remote: {
|
|
72
|
+
global: 'remoteGlobal',
|
|
73
|
+
url: 'https://example.com/remoteEntry.js'
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
test('console.warn should be called for unsupported types', ()=>{
|
|
78
|
+
console.warn = jest.fn();
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
external_pure_js_namespaceObject.remoteVars.unsupported = 42;
|
|
81
|
+
// Call the function that triggers the warning message
|
|
82
|
+
(0,external_getRuntimeRemotes_js_namespaceObject.getRuntimeRemotes)();
|
|
83
|
+
// Check that console.warn was called with the correct message
|
|
84
|
+
//@ts-ignore
|
|
85
|
+
expect(console.warn.mock.calls[0][0]).toMatch(/Unable to retrieve runtime remotes/);
|
|
86
|
+
//@ts-ignore
|
|
87
|
+
console.log(console.warn.mock.calls[0][1].message);
|
|
88
|
+
//@ts-ignore
|
|
89
|
+
expect(console.warn.mock.calls[0][1].message).toMatch(/runtime_remote/);
|
|
90
|
+
//@ts-ignore
|
|
91
|
+
expect(console.warn.mock.calls[0][1].message).toMatch(/unsupported/);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
96
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
97
|
+
}
|
|
98
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/global
|
|
14
|
+
(() => {
|
|
15
|
+
__webpack_require__.g = (() => {
|
|
16
|
+
if (typeof globalThis === 'object') return globalThis;
|
|
17
|
+
try {
|
|
18
|
+
return this || new Function('return this')();
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (typeof window === 'object') return window;
|
|
21
|
+
}
|
|
22
|
+
})();
|
|
23
|
+
})();
|
|
24
|
+
/************************************************************************/
|
|
25
|
+
var __webpack_exports__ = {};
|
|
26
|
+
|
|
27
|
+
;// CONCATENATED MODULE: external "./importDelegatedModule.js"
|
|
28
|
+
const external_importDelegatedModule_js_namespaceObject = require("./importDelegatedModule.js");
|
|
29
|
+
;// CONCATENATED MODULE: external "./pure.js"
|
|
30
|
+
const external_pure_js_namespaceObject = require("./pure.js");
|
|
31
|
+
;// CONCATENATED MODULE: ./src/utils/importDelegateModule.test.ts
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
jest.mock('./pure');
|
|
35
|
+
describe('importDelegatedModule', ()=>{
|
|
36
|
+
let mockLoadScript;
|
|
37
|
+
let mockRuntimeRemote;
|
|
38
|
+
beforeEach(()=>{
|
|
39
|
+
mockLoadScript = jest.fn();
|
|
40
|
+
mockRuntimeRemote = {
|
|
41
|
+
get: jest.fn(),
|
|
42
|
+
init: jest.fn()
|
|
43
|
+
};
|
|
44
|
+
external_pure_js_namespaceObject.loadScript.mockImplementation(()=>Promise.resolve(mockRuntimeRemote));
|
|
45
|
+
});
|
|
46
|
+
afterEach(()=>{
|
|
47
|
+
jest.resetAllMocks();
|
|
48
|
+
});
|
|
49
|
+
it('should successfully import a delegated module', async ()=>{
|
|
50
|
+
const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)('test');
|
|
51
|
+
expect(external_pure_js_namespaceObject.loadScript).toHaveBeenCalledWith('test');
|
|
52
|
+
expect(result).toBe(mockRuntimeRemote);
|
|
53
|
+
});
|
|
54
|
+
it('should handle the case when globalThis is not defined', async ()=>{
|
|
55
|
+
const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)({
|
|
56
|
+
global: 'test'
|
|
57
|
+
});
|
|
58
|
+
expect(external_pure_js_namespaceObject.loadScript).toHaveBeenCalledWith({
|
|
59
|
+
global: 'test'
|
|
60
|
+
});
|
|
61
|
+
expect(result).toBe(mockRuntimeRemote);
|
|
62
|
+
});
|
|
63
|
+
// Test case for when the module has a function property
|
|
64
|
+
it('should return a Promise that resolves to the result when the module is a Promise', async ()=>{
|
|
65
|
+
__webpack_require__.g.window = undefined;
|
|
66
|
+
mockRuntimeRemote.get.mockImplementation(()=>Promise.resolve('test'));
|
|
67
|
+
const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)({
|
|
68
|
+
global: 'test'
|
|
69
|
+
});
|
|
70
|
+
expect(await result.get('test')).toBe('test');
|
|
71
|
+
__webpack_require__.g.window = {}; // Reset window object
|
|
72
|
+
});
|
|
73
|
+
// Test case for when the module has a non-function property
|
|
74
|
+
xit('should define a non-function property on the result when the module has a non-function property', async ()=>{
|
|
75
|
+
__webpack_require__.g.window = undefined;
|
|
76
|
+
mockRuntimeRemote.get.mockImplementation(()=>Promise.resolve(()=>({
|
|
77
|
+
testProp: 'test'
|
|
78
|
+
})));
|
|
79
|
+
const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)({
|
|
80
|
+
global: 'test'
|
|
81
|
+
});
|
|
82
|
+
const getterFunction = await result.get('testProp');
|
|
83
|
+
const getter = getterFunction();
|
|
84
|
+
expect(getter).toBe('test');
|
|
85
|
+
});
|
|
86
|
+
// Test case for when the module is a Promise
|
|
87
|
+
it('should return a Promise that resolves to the result when the module is a Promise', async ()=>{
|
|
88
|
+
__webpack_require__.g.window = undefined;
|
|
89
|
+
mockRuntimeRemote.get.mockImplementation(()=>Promise.resolve('test'));
|
|
90
|
+
const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)({
|
|
91
|
+
global: 'test'
|
|
92
|
+
});
|
|
93
|
+
expect(result.get('test')).resolves.toBe('test');
|
|
94
|
+
__webpack_require__.g.window = {}; // Reset window object
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
99
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
100
|
+
}
|
|
101
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/define_property_getters
|
|
14
|
+
(() => {
|
|
15
|
+
__webpack_require__.d = (exports, definition) => {
|
|
16
|
+
for(var key in definition) {
|
|
17
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
18
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
// webpack/runtime/has_own_property
|
|
24
|
+
(() => {
|
|
25
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
26
|
+
})();
|
|
27
|
+
// webpack/runtime/make_namespace_object
|
|
28
|
+
(() => {
|
|
29
|
+
// define __esModule on exports
|
|
30
|
+
__webpack_require__.r = (exports) => {
|
|
31
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
32
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
/************************************************************************/
|
|
38
|
+
var __webpack_exports__ = {};
|
|
39
|
+
// ESM COMPAT FLAG
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
|
|
42
|
+
// EXPORTS
|
|
43
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
44
|
+
importDelegatedModule: () => (/* binding */ importDelegatedModule)
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
;// CONCATENATED MODULE: external "./pure.js"
|
|
48
|
+
const external_pure_js_namespaceObject = require("./pure.js");
|
|
49
|
+
;// CONCATENATED MODULE: ./src/utils/importDelegatedModule.ts
|
|
50
|
+
|
|
51
|
+
const importDelegatedModule = async (keyOrRuntimeRemoteItem)=>{
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
return (0,external_pure_js_namespaceObject.loadScript)(keyOrRuntimeRemoteItem).then((asyncContainer)=>{
|
|
54
|
+
return asyncContainer;
|
|
55
|
+
}).then((asyncContainer)=>{
|
|
56
|
+
// most of this is only needed because of legacy promise based implementation
|
|
57
|
+
// can remove proxies once we remove promise based implementations
|
|
58
|
+
if (typeof window === 'undefined') {
|
|
59
|
+
if (!Object.hasOwnProperty.call(keyOrRuntimeRemoteItem, 'globalThis')) {
|
|
60
|
+
return asyncContainer;
|
|
61
|
+
}
|
|
62
|
+
// return asyncContainer;
|
|
63
|
+
//TODO: need to solve chunk flushing with delegated modules
|
|
64
|
+
return {
|
|
65
|
+
get: function(arg) {
|
|
66
|
+
//@ts-ignore
|
|
67
|
+
return asyncContainer.get(arg).then((f)=>{
|
|
68
|
+
const m = f();
|
|
69
|
+
const result = {
|
|
70
|
+
__esModule: m.__esModule
|
|
71
|
+
};
|
|
72
|
+
for(const prop in m){
|
|
73
|
+
if (typeof m[prop] === 'function') {
|
|
74
|
+
Object.defineProperty(result, prop, {
|
|
75
|
+
get: function() {
|
|
76
|
+
return function() {
|
|
77
|
+
//@ts-ignore
|
|
78
|
+
if (globalThis.usedChunks) {
|
|
79
|
+
//@ts-ignore
|
|
80
|
+
globalThis.usedChunks.add(//@ts-ignore
|
|
81
|
+
`${keyOrRuntimeRemoteItem.global}->${arg}`);
|
|
82
|
+
}
|
|
83
|
+
//eslint-disable-next-line prefer-rest-params
|
|
84
|
+
return m[prop](...arguments);
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
enumerable: true
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
Object.defineProperty(result, prop, {
|
|
91
|
+
get: ()=>{
|
|
92
|
+
//@ts-ignore
|
|
93
|
+
if (globalThis.usedChunks) {
|
|
94
|
+
//@ts-ignore
|
|
95
|
+
globalThis.usedChunks.add(//@ts-ignore
|
|
96
|
+
`${keyOrRuntimeRemoteItem.global}->${arg}`);
|
|
97
|
+
}
|
|
98
|
+
return m[prop];
|
|
99
|
+
},
|
|
100
|
+
enumerable: true
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (m.then) {
|
|
105
|
+
return Promise.resolve(()=>result);
|
|
106
|
+
}
|
|
107
|
+
return ()=>result;
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
init: asyncContainer.init
|
|
111
|
+
};
|
|
112
|
+
} else {
|
|
113
|
+
return asyncContainer;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
exports.importDelegatedModule = __webpack_exports__.importDelegatedModule;
|
|
119
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
120
|
+
if(["importDelegatedModule"].indexOf(__webpack_i__) === -1) {
|
|
121
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|