@module-federation/utilities 0.0.0-chore-bump-node-22-20260710161714

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -0
  3. package/dist/cjs/Logger.js +63 -0
  4. package/dist/cjs/components/ErrorBoundary.js +98 -0
  5. package/dist/cjs/components/FederationBoundary.js +103 -0
  6. package/dist/cjs/index.js +172 -0
  7. package/dist/cjs/plugins/DelegateModulesPlugin.js +133 -0
  8. package/dist/cjs/types/index.js +31 -0
  9. package/dist/cjs/utils/common.js +175 -0
  10. package/dist/cjs/utils/getRuntimeRemotes.js +104 -0
  11. package/dist/cjs/utils/getRuntimeRemotes.test.js +98 -0
  12. package/dist/cjs/utils/importDelegateModule.test.js +99 -0
  13. package/dist/cjs/utils/importDelegatedModule.js +126 -0
  14. package/dist/cjs/utils/importRemote.js +176 -0
  15. package/dist/cjs/utils/isEmpty.js +60 -0
  16. package/dist/cjs/utils/pure.js +215 -0
  17. package/dist/cjs/utils/react.js +73 -0
  18. package/dist/esm/Logger.mjs +12 -0
  19. package/dist/esm/components/ErrorBoundary.mjs +31 -0
  20. package/dist/esm/components/FederationBoundary.mjs +35 -0
  21. package/dist/esm/index.mjs +24 -0
  22. package/dist/esm/plugins/DelegateModulesPlugin.mjs +81 -0
  23. package/dist/esm/rslib-runtime.mjs +37 -0
  24. package/dist/esm/types/index.mjs +4 -0
  25. package/dist/esm/utils/common.mjs +116 -0
  26. package/dist/esm/utils/getRuntimeRemotes.mjs +50 -0
  27. package/dist/esm/utils/getRuntimeRemotes.test.mjs +84 -0
  28. package/dist/esm/utils/importDelegateModule.test.mjs +72 -0
  29. package/dist/esm/utils/importDelegatedModule.mjs +72 -0
  30. package/dist/esm/utils/importRemote.mjs +105 -0
  31. package/dist/esm/utils/isEmpty.mjs +8 -0
  32. package/dist/esm/utils/pure.mjs +138 -0
  33. package/dist/esm/utils/react.mjs +4 -0
  34. package/dist/types/Logger.d.ts +7 -0
  35. package/dist/types/components/ErrorBoundary.d.ts +19 -0
  36. package/dist/types/components/FederationBoundary.d.ts +14 -0
  37. package/dist/types/index.d.ts +10 -0
  38. package/dist/types/plugins/DelegateModulesPlugin.d.ts +18 -0
  39. package/dist/types/types/index.d.ts +76 -0
  40. package/dist/types/utils/common.d.ts +31 -0
  41. package/dist/types/utils/getRuntimeRemotes.d.ts +2 -0
  42. package/dist/types/utils/importDelegatedModule.d.ts +2 -0
  43. package/dist/types/utils/importRemote.d.ts +31 -0
  44. package/dist/types/utils/isEmpty.d.ts +1 -0
  45. package/dist/types/utils/pure.d.ts +5 -0
  46. package/dist/types/utils/react.d.ts +1 -0
  47. package/package.json +68 -0
@@ -0,0 +1,133 @@
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
+ // webpack/runtime/define_property_getters
13
+ (() => {
14
+ __webpack_require__.d = (exports, getters, values) => {
15
+ var define = (defs, kind) => {
16
+ for(var key in defs) {
17
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
18
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
19
+ }
20
+ }
21
+ };
22
+ define(getters, "get");
23
+ define(values, "value");
24
+ };
25
+ })();
26
+ // webpack/runtime/has_own_property
27
+ (() => {
28
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
29
+ })();
30
+ // webpack/runtime/make_namespace_object
31
+ (() => {
32
+ // define __esModule on exports
33
+ __webpack_require__.r = (exports) => {
34
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
35
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
36
+ }
37
+ Object.defineProperty(exports, '__esModule', { value: true });
38
+ };
39
+ })();
40
+ var __webpack_exports__ = {};
41
+ __webpack_require__.r(__webpack_exports__);
42
+ class DelegateModulesPlugin {
43
+ getChunkByName(chunks, name) {
44
+ for (const chunk of chunks){
45
+ if (chunk.name === name) {
46
+ return chunk;
47
+ }
48
+ }
49
+ return undefined;
50
+ }
51
+ addDelegatesToChunks(compilation, chunks) {
52
+ for (const chunk of chunks){
53
+ this._delegateModules.forEach((module)=>{
54
+ this.addModuleAndDependenciesToChunk(module, chunk, compilation);
55
+ });
56
+ }
57
+ }
58
+ addModuleAndDependenciesToChunk(module, chunk, compilation) {
59
+ if (!compilation.chunkGraph.isModuleInChunk(module, chunk)) {
60
+ if (this.options.debug) {
61
+ console.log('adding ', module.identifier(), ' to chunk', chunk.name);
62
+ }
63
+ compilation.chunkGraph.connectChunkAndModule(chunk, module);
64
+ }
65
+ }
66
+ removeDelegatesNonRuntimeChunks(compilation, chunks) {
67
+ for (const chunk of chunks){
68
+ if (!chunk.hasRuntime()) {
69
+ this.options.debug && console.log('non-runtime chunk:', chunk.debugId, chunk.id, chunk.name);
70
+ for (const [id, module] of this._delegateModules){
71
+ compilation.chunkGraph.disconnectChunkAndModule(chunk, module);
72
+ }
73
+ }
74
+ }
75
+ }
76
+ apply(compiler) {
77
+ compiler.hooks.thisCompilation.tap('DelegateModulesPlugin', (compilation)=>{
78
+ compilation.hooks.finishModules.tapAsync('DelegateModulesPlugin', (modules, callback)=>{
79
+ const { remotes } = this.options;
80
+ const knownDelegates = new Set(remotes ? Object.values(remotes).map((remote)=>remote.replace('internal ', '')) : []);
81
+ for (const module of modules){
82
+ const normalModule = module;
83
+ if (normalModule) {
84
+ const mid = normalModule.identifier();
85
+ if (normalModule?.userRequest?.startsWith('webpack/container/reference')) {
86
+ this._delegateModules.set(mid, normalModule);
87
+ }
88
+ }
89
+ if (normalModule.resource && knownDelegates.has(normalModule.resource)) {
90
+ this._delegateModules.set(normalModule.resource, normalModule);
91
+ }
92
+ }
93
+ callback();
94
+ });
95
+ compilation.hooks.optimizeChunks.tap('DelegateModulesPlugin', (chunks)=>{
96
+ const { runtime, container } = this.options;
97
+ const runtimeChunk = this.getChunkByName(chunks, runtime);
98
+ if (!runtimeChunk || !runtimeChunk.hasRuntime()) {
99
+ return;
100
+ }
101
+ // Get the container chunk if specified
102
+ const remoteContainer = container ? this.getChunkByName(chunks, container) : null;
103
+ this.options.debug && console.log(remoteContainer?.name, runtimeChunk.name, this._delegateModules.size);
104
+ this.addDelegatesToChunks(compilation, [
105
+ remoteContainer,
106
+ runtimeChunk
107
+ ].filter(Boolean));
108
+ this.removeDelegatesNonRuntimeChunks(compilation, chunks);
109
+ });
110
+ });
111
+ }
112
+ constructor(options){
113
+ this.options = {
114
+ debug: false,
115
+ ...options
116
+ };
117
+ this._delegateModules = new Map();
118
+ }
119
+ }
120
+ /* export default */ const __rspack_default_export = (DelegateModulesPlugin);
121
+
122
+ __webpack_require__.d(__webpack_exports__, {
123
+ }, {
124
+ "default": __rspack_default_export
125
+ });
126
+
127
+ exports["default"] = __webpack_exports__["default"];
128
+ for(var __rspack_i in __webpack_exports__) {
129
+ if(["default"].indexOf(__rspack_i) === -1) {
130
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
131
+ }
132
+ }
133
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,31 @@
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
+ // webpack/runtime/make_namespace_object
13
+ (() => {
14
+ // define __esModule on exports
15
+ __webpack_require__.r = (exports) => {
16
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
17
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
18
+ }
19
+ Object.defineProperty(exports, '__esModule', { value: true });
20
+ };
21
+ })();
22
+ var __webpack_exports__ = {};
23
+ __webpack_require__.r(__webpack_exports__);
24
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
25
+ /// <reference path="../../../../webpack/module.d.ts" />
26
+
27
+
28
+ for(var __rspack_i in __webpack_exports__) {
29
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
30
+ }
31
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,175 @@
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
+ // webpack/runtime/define_property_getters
13
+ (() => {
14
+ __webpack_require__.d = (exports, getters, values) => {
15
+ var define = (defs, kind) => {
16
+ for(var key in defs) {
17
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
18
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
19
+ }
20
+ }
21
+ };
22
+ define(getters, "get");
23
+ define(values, "value");
24
+ };
25
+ })();
26
+ // webpack/runtime/has_own_property
27
+ (() => {
28
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
29
+ })();
30
+ // webpack/runtime/make_namespace_object
31
+ (() => {
32
+ // define __esModule on exports
33
+ __webpack_require__.r = (exports) => {
34
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
35
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
36
+ }
37
+ Object.defineProperty(exports, '__esModule', { value: true });
38
+ };
39
+ })();
40
+ var __webpack_exports__ = {};
41
+ // ESM COMPAT FLAG
42
+ __webpack_require__.r(__webpack_exports__);
43
+
44
+ // EXPORTS
45
+ __webpack_require__.d(__webpack_exports__, {
46
+ createRuntimeVariables: () => (/* binding */ createRuntimeVariables),
47
+ getContainer: () => (/* binding */ getContainer),
48
+ getModule: () => (/* binding */ getModule),
49
+ injectScript: () => (/* binding */ injectScript)
50
+ });
51
+
52
+ ;// CONCATENATED MODULE: external "./pure.js"
53
+ const external_pure_js_namespaceObject = require("./pure.js");
54
+ ;// CONCATENATED MODULE: ./src/utils/common.ts
55
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
56
+ const createContainerSharingScope = (asyncContainer)=>{
57
+ // @ts-ignore
58
+ return asyncContainer.then(function(container) {
59
+ if (!__webpack_require__.S['default']) {
60
+ // not always a promise, so we wrap it in a resolve
61
+ return Promise.resolve(__webpack_require__.I('default')).then(function() {
62
+ return container;
63
+ });
64
+ } else {
65
+ return container;
66
+ }
67
+ }).then(function(container) {
68
+ try {
69
+ // WARNING: here might be a potential BUG.
70
+ // `container.init` does not return a Promise, and here we do not call `then` on it.
71
+ // But according to [docs](https://webpack.js.org/concepts/module-federation/#dynamic-remote-containers)
72
+ // it must be async.
73
+ // The problem may be in Proxy in NextFederationPlugin.js.
74
+ // or maybe a bug in the webpack itself - instead of returning rejected promise it just throws an error.
75
+ // But now everything works properly and we keep this code as is.
76
+ container.init(__webpack_require__.S['default']);
77
+ } catch (e) {
78
+ // maybe container already initialized so nothing to throw
79
+ }
80
+ return container;
81
+ });
82
+ };
83
+ /**
84
+ * Return initialized remote container by remote's key or its runtime remote item data.
85
+ *
86
+ * `runtimeRemoteItem` might be
87
+ * { global, url } - values obtained from webpack remotes option `global@url`
88
+ * or
89
+ * { asyncContainer } - async container is a promise that resolves to the remote container
90
+ */ const injectScript = async (keyOrRuntimeRemoteItem)=>{
91
+ const asyncContainer = (0,external_pure_js_namespaceObject.loadScript)(keyOrRuntimeRemoteItem);
92
+ return createContainerSharingScope(asyncContainer);
93
+ };
94
+ /**
95
+ * Creates runtime variables from the provided remotes.
96
+ * If the value of a remote starts with 'promise ' or 'external ', it is transformed into a function that returns the promise call.
97
+ * Otherwise, the value is stringified.
98
+ * @param {Remotes} remotes - The remotes to create runtime variables from.
99
+ * @returns {Record<string, string>} - The created runtime variables.
100
+ */ const createRuntimeVariables = (remotes)=>{
101
+ if (!remotes) {
102
+ return {};
103
+ }
104
+ return Object.entries(remotes).reduce((acc, [key, value])=>{
105
+ if (value.startsWith('promise ') || value.startsWith('external ')) {
106
+ const promiseCall = value.split(' ')[1];
107
+ acc[key] = `function() {
108
+ return ${promiseCall}
109
+ }`;
110
+ } else {
111
+ acc[key] = JSON.stringify(value);
112
+ }
113
+ return acc;
114
+ }, {});
115
+ };
116
+ /**
117
+ * Returns initialized webpack RemoteContainer.
118
+ * If its' script does not loaded - then load & init it firstly.
119
+ */ const getContainer = async (remoteContainer)=>{
120
+ if (!remoteContainer) {
121
+ throw Error(`Remote container options is empty`);
122
+ }
123
+ const containerScope = typeof window !== 'undefined' ? window : globalThis.__remote_scope__;
124
+ let containerKey;
125
+ if (typeof remoteContainer === 'string') {
126
+ containerKey = remoteContainer;
127
+ } else {
128
+ containerKey = remoteContainer.uniqueKey;
129
+ if (!containerScope[containerKey]) {
130
+ const container = await injectScript({
131
+ global: remoteContainer.global,
132
+ url: remoteContainer.url
133
+ });
134
+ if (!container) {
135
+ throw Error(`Remote container ${remoteContainer.url} is empty`);
136
+ }
137
+ }
138
+ }
139
+ return containerScope[containerKey];
140
+ };
141
+ /**
142
+ * Return remote module from container.
143
+ * If you provide `exportName` it automatically return exact property value from module.
144
+ *
145
+ * @example
146
+ * remote.getModule('./pages/index', 'default')
147
+ */ const getModule = async ({ remoteContainer, modulePath, exportName })=>{
148
+ const container = await getContainer(remoteContainer);
149
+ try {
150
+ const modFactory = await container?.get(modulePath);
151
+ if (!modFactory) {
152
+ return undefined;
153
+ }
154
+ const mod = modFactory();
155
+ if (exportName) {
156
+ return mod && typeof mod === 'object' ? mod[exportName] : undefined;
157
+ } else {
158
+ return mod;
159
+ }
160
+ } catch (error) {
161
+ console.error(error);
162
+ return undefined;
163
+ }
164
+ };
165
+
166
+ exports.createRuntimeVariables = __webpack_exports__.createRuntimeVariables;
167
+ exports.getContainer = __webpack_exports__.getContainer;
168
+ exports.getModule = __webpack_exports__.getModule;
169
+ exports.injectScript = __webpack_exports__.injectScript;
170
+ for(var __rspack_i in __webpack_exports__) {
171
+ if(["createRuntimeVariables","getContainer","getModule","injectScript"].indexOf(__rspack_i) === -1) {
172
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
173
+ }
174
+ }
175
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,104 @@
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
+ // webpack/runtime/define_property_getters
13
+ (() => {
14
+ __webpack_require__.d = (exports, getters, values) => {
15
+ var define = (defs, kind) => {
16
+ for(var key in defs) {
17
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
18
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
19
+ }
20
+ }
21
+ };
22
+ define(getters, "get");
23
+ define(values, "value");
24
+ };
25
+ })();
26
+ // webpack/runtime/has_own_property
27
+ (() => {
28
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
29
+ })();
30
+ // webpack/runtime/make_namespace_object
31
+ (() => {
32
+ // define __esModule on exports
33
+ __webpack_require__.r = (exports) => {
34
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
35
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
36
+ }
37
+ Object.defineProperty(exports, '__esModule', { value: true });
38
+ };
39
+ })();
40
+ var __webpack_exports__ = {};
41
+ // ESM COMPAT FLAG
42
+ __webpack_require__.r(__webpack_exports__);
43
+
44
+ // EXPORTS
45
+ __webpack_require__.d(__webpack_exports__, {
46
+ getRuntimeRemotes: () => (/* binding */ getRuntimeRemotes)
47
+ });
48
+
49
+ ;// CONCATENATED MODULE: external "./pure.js"
50
+ const external_pure_js_namespaceObject = require("./pure.js");
51
+ ;// CONCATENATED MODULE: ./src/utils/getRuntimeRemotes.ts
52
+
53
+ const getRuntimeRemotes = ()=>{
54
+ try {
55
+ return Object.entries(external_pure_js_namespaceObject.remoteVars).reduce(function(acc, item) {
56
+ const [key, value] = item;
57
+ // if its an object with a thenable (eagerly executing function)
58
+ if (typeof value === 'object' && typeof value.then === 'function') {
59
+ acc[key] = {
60
+ asyncContainer: value
61
+ };
62
+ } else if (typeof value === 'function') {
63
+ // @ts-ignore
64
+ acc[key] = {
65
+ asyncContainer: value
66
+ };
67
+ } else if (typeof value === 'string' && value.startsWith('internal ')) {
68
+ const [request, query] = value.replace('internal ', '').split('?');
69
+ if (query) {
70
+ const remoteSyntax = new URLSearchParams(query).get('remote');
71
+ if (remoteSyntax) {
72
+ const [url, global] = (0,external_pure_js_namespaceObject.extractUrlAndGlobal)(remoteSyntax);
73
+ acc[key] = {
74
+ global,
75
+ url
76
+ };
77
+ }
78
+ }
79
+ } else if (typeof value === 'string') {
80
+ const [url, global] = (0,external_pure_js_namespaceObject.extractUrlAndGlobal)(value);
81
+ acc[key] = {
82
+ global,
83
+ url
84
+ };
85
+ } else {
86
+ //@ts-ignore
87
+ console.warn('remotes process', process.env.REMOTES);
88
+ throw new Error(`[mf] Invalid value received for runtime_remote "${key}"`);
89
+ }
90
+ return acc;
91
+ }, {});
92
+ } catch (err) {
93
+ console.warn('Unable to retrieve runtime remotes: ', err);
94
+ }
95
+ return {};
96
+ };
97
+
98
+ exports.getRuntimeRemotes = __webpack_exports__.getRuntimeRemotes;
99
+ for(var __rspack_i in __webpack_exports__) {
100
+ if(["getRuntimeRemotes"].indexOf(__rspack_i) === -1) {
101
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
102
+ }
103
+ }
104
+ 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 __rspack_i in __webpack_exports__) {
96
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
97
+ }
98
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,99 @@
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
+ // webpack/runtime/global
13
+ (() => {
14
+ __webpack_require__.g = (() => {
15
+ if (typeof globalThis === 'object') return globalThis;
16
+ try {
17
+ return this || new Function('return this')();
18
+ } catch (e) {
19
+ if (typeof window === 'object') return window;
20
+ }
21
+ })();
22
+ })();
23
+ var __webpack_exports__ = {};
24
+
25
+ ;// CONCATENATED MODULE: external "./importDelegatedModule.js"
26
+ const external_importDelegatedModule_js_namespaceObject = require("./importDelegatedModule.js");
27
+ ;// CONCATENATED MODULE: external "./pure.js"
28
+ const external_pure_js_namespaceObject = require("./pure.js");
29
+ ;// CONCATENATED MODULE: ./src/utils/importDelegateModule.test.ts
30
+
31
+
32
+ jest.mock('./pure');
33
+ describe('importDelegatedModule', ()=>{
34
+ let mockLoadScript;
35
+ let mockRuntimeRemote;
36
+ beforeEach(()=>{
37
+ mockLoadScript = jest.fn();
38
+ mockRuntimeRemote = {
39
+ get: jest.fn(),
40
+ init: jest.fn()
41
+ };
42
+ external_pure_js_namespaceObject.loadScript.mockImplementation(()=>Promise.resolve(mockRuntimeRemote));
43
+ });
44
+ afterEach(()=>{
45
+ jest.resetAllMocks();
46
+ });
47
+ it('should successfully import a delegated module', async ()=>{
48
+ const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)('test');
49
+ expect(external_pure_js_namespaceObject.loadScript).toHaveBeenCalledWith('test');
50
+ expect(result).toBe(mockRuntimeRemote);
51
+ });
52
+ it('should handle the case when globalThis is not defined', async ()=>{
53
+ const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)({
54
+ global: 'test'
55
+ });
56
+ expect(external_pure_js_namespaceObject.loadScript).toHaveBeenCalledWith({
57
+ global: 'test'
58
+ });
59
+ expect(result).toBe(mockRuntimeRemote);
60
+ });
61
+ // Test case for when the module has a function property
62
+ it('should return a Promise that resolves to the result when the module is a Promise', async ()=>{
63
+ __webpack_require__.g.window = undefined;
64
+ mockRuntimeRemote.get.mockImplementation(()=>Promise.resolve('test'));
65
+ const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)({
66
+ global: 'test'
67
+ });
68
+ expect(await result.get('test')).toBe('test');
69
+ __webpack_require__.g.window = {}; // Reset window object
70
+ });
71
+ // Test case for when the module has a non-function property
72
+ xit('should define a non-function property on the result when the module has a non-function property', async ()=>{
73
+ __webpack_require__.g.window = undefined;
74
+ mockRuntimeRemote.get.mockImplementation(()=>Promise.resolve(()=>({
75
+ testProp: 'test'
76
+ })));
77
+ const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)({
78
+ global: 'test'
79
+ });
80
+ const getterFunction = await result.get('testProp');
81
+ const getter = getterFunction();
82
+ expect(getter).toBe('test');
83
+ });
84
+ // Test case for when the module is a Promise
85
+ it('should return a Promise that resolves to the result when the module is a Promise', async ()=>{
86
+ __webpack_require__.g.window = undefined;
87
+ mockRuntimeRemote.get.mockImplementation(()=>Promise.resolve('test'));
88
+ const result = await (0,external_importDelegatedModule_js_namespaceObject.importDelegatedModule)({
89
+ global: 'test'
90
+ });
91
+ expect(result.get('test')).resolves.toBe('test');
92
+ __webpack_require__.g.window = {}; // Reset window object
93
+ });
94
+ });
95
+
96
+ for(var __rspack_i in __webpack_exports__) {
97
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
98
+ }
99
+ Object.defineProperty(exports, '__esModule', { value: true });