@module-federation/utilities 1.7.6 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,78 +1,113 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.importRemote = void 0;
4
- const tslib_1 = require("tslib");
5
- const REMOTE_ENTRY_FILE = 'remoteEntry.js';
6
- const loadRemote = (url, scope, bustRemoteEntryCache) => new Promise((resolve, reject) => {
7
- const timestamp = bustRemoteEntryCache ? `?t=${new Date().getTime()}` : '';
8
- const webpackRequire = __webpack_require__;
9
- webpackRequire.l(`${url}${timestamp}`, (event) => {
10
- var _a;
11
- if ((event === null || event === void 0 ? void 0 : event.type) === 'load') {
12
- // Script loaded successfully:
13
- return resolve();
4
+ var tslib_1 = require("tslib");
5
+ var REMOTE_ENTRY_FILE = 'remoteEntry.js';
6
+ var loadRemote = function (url, scope, bustRemoteEntryCache) {
7
+ return new Promise(function (resolve, reject) {
8
+ var timestamp = bustRemoteEntryCache ? "?t=".concat(new Date().getTime()) : '';
9
+ var webpackRequire = __webpack_require__;
10
+ webpackRequire.l("".concat(url).concat(timestamp), function (event) {
11
+ var _a;
12
+ if ((event === null || event === void 0 ? void 0 : event.type) === 'load') {
13
+ // Script loaded successfully:
14
+ return resolve();
15
+ }
16
+ var realSrc = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.src;
17
+ var error = new Error();
18
+ error.message = 'Loading script failed.\n(missing: ' + realSrc + ')';
19
+ error.name = 'ScriptExternalLoadError';
20
+ reject(error);
21
+ }, scope);
22
+ });
23
+ };
24
+ var initSharing = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
25
+ var webpackShareScopes;
26
+ return tslib_1.__generator(this, function (_a) {
27
+ switch (_a.label) {
28
+ case 0:
29
+ webpackShareScopes = __webpack_share_scopes__;
30
+ if (!!(webpackShareScopes === null || webpackShareScopes === void 0 ? void 0 : webpackShareScopes.default)) return [3 /*break*/, 2];
31
+ return [4 /*yield*/, __webpack_init_sharing__('default')];
32
+ case 1:
33
+ _a.sent();
34
+ _a.label = 2;
35
+ case 2: return [2 /*return*/];
14
36
  }
15
- const realSrc = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.src;
16
- const error = new Error();
17
- error.message = 'Loading script failed.\n(missing: ' + realSrc + ')';
18
- error.name = 'ScriptExternalLoadError';
19
- reject(error);
20
- }, scope);
21
- });
22
- const initSharing = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
23
- const webpackShareScopes = __webpack_share_scopes__;
24
- if (!(webpackShareScopes === null || webpackShareScopes === void 0 ? void 0 : webpackShareScopes.default)) {
25
- yield __webpack_init_sharing__('default');
26
- }
27
- });
37
+ });
38
+ }); };
28
39
  // __initialized and __initializing flags prevent some concurrent re-initialization corner cases
29
- const initContainer = (containerScope) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
30
- try {
31
- const webpackShareScopes = __webpack_share_scopes__;
32
- if (!containerScope.__initialized && !containerScope.__initializing) {
33
- containerScope.__initializing = true;
34
- yield containerScope.init(webpackShareScopes.default);
35
- containerScope.__initialized = true;
36
- delete containerScope.__initializing;
40
+ var initContainer = function (containerScope) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
41
+ var webpackShareScopes, error_1;
42
+ return tslib_1.__generator(this, function (_a) {
43
+ switch (_a.label) {
44
+ case 0:
45
+ _a.trys.push([0, 3, , 4]);
46
+ webpackShareScopes = __webpack_share_scopes__;
47
+ if (!(!containerScope.__initialized && !containerScope.__initializing)) return [3 /*break*/, 2];
48
+ containerScope.__initializing = true;
49
+ return [4 /*yield*/, containerScope.init(webpackShareScopes.default)];
50
+ case 1:
51
+ _a.sent();
52
+ containerScope.__initialized = true;
53
+ delete containerScope.__initializing;
54
+ _a.label = 2;
55
+ case 2: return [3 /*break*/, 4];
56
+ case 3:
57
+ error_1 = _a.sent();
58
+ console.error(error_1);
59
+ return [3 /*break*/, 4];
60
+ case 4: return [2 /*return*/];
37
61
  }
38
- }
39
- catch (error) {
40
- console.error(error);
41
- }
42
- });
62
+ });
63
+ }); };
43
64
  /*
44
65
  Dynamically import a remote module using Webpack's loading mechanism:
45
66
  https://webpack.js.org/concepts/module-federation/
46
67
  */
47
- const importRemote = ({ url, scope, module, remoteEntryFileName = REMOTE_ENTRY_FILE, bustRemoteEntryCache = true, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
48
- const remoteScope = scope;
49
- if (!window[remoteScope]) {
50
- let remoteUrl = '';
51
- if (typeof url === 'string') {
52
- remoteUrl = url;
53
- }
54
- else {
55
- remoteUrl = yield url();
56
- }
57
- // Load the remote and initialize the share scope if it's empty
58
- yield Promise.all([
59
- loadRemote(`${remoteUrl}/${remoteEntryFileName}`, scope, bustRemoteEntryCache),
60
- initSharing(),
61
- ]);
62
- if (!window[remoteScope]) {
63
- throw new Error(`Remote loaded successfully but ${scope} could not be found! Verify that the name is correct in the Webpack configuration!`);
64
- }
65
- // Initialize the container to get shared modules and get the module factory:
66
- const [, moduleFactory] = yield Promise.all([
67
- initContainer(window[remoteScope]),
68
- window[remoteScope].get(module.startsWith('./') ? module : `./${module}`),
69
- ]);
70
- return moduleFactory();
71
- }
72
- else {
73
- const moduleFactory = yield window[remoteScope].get(module.startsWith('./') ? module : `./${module}`);
74
- return moduleFactory();
75
- }
76
- });
68
+ var importRemote = function (_a) {
69
+ var url = _a.url, scope = _a.scope, module = _a.module, _b = _a.remoteEntryFileName, remoteEntryFileName = _b === void 0 ? REMOTE_ENTRY_FILE : _b, _c = _a.bustRemoteEntryCache, bustRemoteEntryCache = _c === void 0 ? true : _c;
70
+ return tslib_1.__awaiter(void 0, void 0, void 0, function () {
71
+ var remoteScope, remoteUrl, _d, moduleFactory, moduleFactory;
72
+ return tslib_1.__generator(this, function (_e) {
73
+ switch (_e.label) {
74
+ case 0:
75
+ remoteScope = scope;
76
+ if (!!window[remoteScope]) return [3 /*break*/, 6];
77
+ remoteUrl = '';
78
+ if (!(typeof url === 'string')) return [3 /*break*/, 1];
79
+ remoteUrl = url;
80
+ return [3 /*break*/, 3];
81
+ case 1: return [4 /*yield*/, url()];
82
+ case 2:
83
+ remoteUrl = _e.sent();
84
+ _e.label = 3;
85
+ case 3:
86
+ // Load the remote and initialize the share scope if it's empty
87
+ return [4 /*yield*/, Promise.all([
88
+ loadRemote("".concat(remoteUrl, "/").concat(remoteEntryFileName), scope, bustRemoteEntryCache),
89
+ initSharing(),
90
+ ])];
91
+ case 4:
92
+ // Load the remote and initialize the share scope if it's empty
93
+ _e.sent();
94
+ if (!window[remoteScope]) {
95
+ throw new Error("Remote loaded successfully but ".concat(scope, " could not be found! Verify that the name is correct in the Webpack configuration!"));
96
+ }
97
+ return [4 /*yield*/, Promise.all([
98
+ initContainer(window[remoteScope]),
99
+ window[remoteScope].get(module.startsWith('./') ? module : "./".concat(module)),
100
+ ])];
101
+ case 5:
102
+ _d = _e.sent(), moduleFactory = _d[1];
103
+ return [2 /*return*/, moduleFactory()];
104
+ case 6: return [4 /*yield*/, window[remoteScope].get(module.startsWith('./') ? module : "./".concat(module))];
105
+ case 7:
106
+ moduleFactory = _e.sent();
107
+ return [2 /*return*/, moduleFactory()];
108
+ }
109
+ });
110
+ });
111
+ };
77
112
  exports.importRemote = importRemote;
78
113
  //# sourceMappingURL=importRemote.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"importRemote.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/importRemote.ts"],"names":[],"mappings":";;;;AAgBA,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAE3C,MAAM,UAAU,GAAG,CACjB,GAA+B,EAC/B,KAAmC,EACnC,oBAAiE,EACjE,EAAE,CACF,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACpC,MAAM,SAAS,GAAG,oBAAoB,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,OAAO,E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CAAC,GAAG,CAAC;wBAChB,UAAU,CACR,UAAG,SAAS,cAAI,mBAAmB,CAAE,EACrC,KAAK,EACL,oBAAoB,CACrB;wBACD,WAAW,EAAE;qBACd,CAAC,EAAA;;oBARF,+DAA+D;oBAC/D,SAOE,CAAC;oBACH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;wBACxB,MAAM,IAAI,KAAK,CACb,yCAAkC,KAAK,uFAAoF,CAC5H,CAAC;qBACH;oBAEyB,qBAAM,OAAO,CAAC,GAAG,CAAC;4BAC1C,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;4BACjC,MAAM,CAAC,WAAW,CAAuC,CAAC,GAAG,CAC5D,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,YAAK,MAAM,CAAE,CACjD;yBACF,CAAC,EAAA;;oBALI,KAAoB,SAKxB,EALO,aAAa,QAAA;oBAMtB,sBAAO,aAAa,EAAE,EAAC;wBAED,qBACpB,MAAM,CAAC,WAAW,CACnB,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,YAAK,MAAM,CAAE,CAAC,EAAA;;oBAFjD,aAAa,GAAG,SAEiC;oBACvD,sBAAO,aAAa,EAAE,EAAC;;;;CAE1B,CAAC;AA7CW,QAAA,YAAY,gBA6CvB"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isObjectEmpty = void 0;
4
- const isObjectEmpty = (obj) => {
5
- for (const x in obj) {
4
+ var isObjectEmpty = function (obj) {
5
+ for (var x in obj) {
6
6
  return false;
7
7
  }
8
8
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"isEmpty.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/isEmpty.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAmB,GAAM,EAAE,EAAE;IACxD,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB"}
1
+ {"version":3,"file":"isEmpty.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/isEmpty.ts"],"names":[],"mappings":";;;AAAO,IAAM,aAAa,GAAG,UAAmB,GAAM;IACpD,KAAK,IAAM,CAAC,IAAI,GAAG,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB"}
@@ -1,26 +0,0 @@
1
- import type { Compiler, Compilation, Chunk, Module } from 'webpack';
2
- /**
3
- * A webpack plugin that moves specified modules from chunks to runtime chunk.
4
- * @class DelegateModulesPlugin
5
- */
6
- declare class DelegateModulesPlugin {
7
- options: {
8
- debug: boolean;
9
- [key: string]: any;
10
- };
11
- _delegateModules: Set<Module>;
12
- constructor(options: {
13
- debug?: boolean;
14
- [key: string]: any;
15
- });
16
- getChunkByName(chunks: Iterable<Chunk>, name: string): Chunk | undefined;
17
- addDelegatesToChunks(compilation: Compilation, chunks: Chunk[]): void;
18
- removeDelegatesNonRuntimeChunks(compilation: Compilation, chunks: Iterable<Chunk>): void;
19
- /**
20
- * Applies the plugin to the webpack compiler.
21
- * @param {Compiler} compiler - The webpack compiler instance.
22
- */
23
- apply(compiler: Compiler): void;
24
- resolveDelegateModules(compilation: Compilation): void;
25
- }
26
- export default DelegateModulesPlugin;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * A webpack plugin that moves specified modules from chunks to runtime chunk.
5
- * @class DelegateModulesPlugin
6
- */
7
- class DelegateModulesPlugin {
8
- constructor(options) {
9
- this.options = Object.assign({ debug: false }, options);
10
- this._delegateModules = new Set();
11
- }
12
- getChunkByName(chunks, name) {
13
- for (const chunk of chunks) {
14
- if (chunk.name == name) {
15
- return chunk;
16
- }
17
- }
18
- return undefined;
19
- }
20
- addDelegatesToChunks(compilation, chunks) {
21
- for (const chunk of chunks) {
22
- this._delegateModules.forEach((module) => {
23
- if (!compilation.chunkGraph.isModuleInChunk(module, chunk)) {
24
- this.options.debug &&
25
- console.log('adding ', module.identifier(), ' to chunk', chunk.name);
26
- compilation.chunkGraph.connectChunkAndModule(chunk, module);
27
- }
28
- });
29
- }
30
- }
31
- removeDelegatesNonRuntimeChunks(compilation, chunks) {
32
- for (const chunk of chunks) {
33
- if (!chunk.hasRuntime()) {
34
- this.options.debug &&
35
- console.log('non-runtime chunk:', chunk.debugId, chunk.id, chunk.name);
36
- this._delegateModules.forEach((module) => {
37
- compilation.chunkGraph.disconnectChunkAndModule(chunk, module);
38
- });
39
- }
40
- }
41
- }
42
- /**
43
- * Applies the plugin to the webpack compiler.
44
- * @param {Compiler} compiler - The webpack compiler instance.
45
- */
46
- apply(compiler) {
47
- // Tap into compilation hooks
48
- compiler.hooks.compilation.tap('DelegateModulesPlugin', (compilation) => {
49
- // fills this._delegateModules set
50
- this.resolveDelegateModules(compilation);
51
- compilation.hooks.optimizeChunks.tap('DelegateModulesPlugin', (chunks) => {
52
- // Change this line
53
- const { runtime, container } = this.options;
54
- const runtimeChunk = this.getChunkByName(chunks, runtime);
55
- if (!runtimeChunk || !runtimeChunk.hasRuntime())
56
- return;
57
- // Get the container chunk if specified
58
- const remoteContainer = container
59
- ? this.getChunkByName(chunks, container)
60
- : null;
61
- this.options.debug &&
62
- console.log(remoteContainer === null || remoteContainer === void 0 ? void 0 : remoteContainer.name, runtimeChunk.name, this._delegateModules.size);
63
- this.addDelegatesToChunks(compilation, [remoteContainer, runtimeChunk].filter(Boolean));
64
- this.removeDelegatesNonRuntimeChunks(compilation, chunks);
65
- });
66
- });
67
- }
68
- resolveDelegateModules(compilation) {
69
- // Tap into the 'finish-modules' hook to access the module list after they are all processed
70
- compilation.hooks.finishModules.tapAsync('ModuleIDFinderPlugin', (modules, callback) => {
71
- const { remotes } = this.options;
72
- // Get the delegate module names for remote chunks if specified
73
- const knownDelegates = new Set(remotes
74
- ? Object.values(remotes).map((remote) => remote.replace('internal ', ''))
75
- : []);
76
- for (const module of modules) {
77
- // @ts-ignore
78
- if (module.resource && knownDelegates.has(module.resource)) {
79
- this._delegateModules.add(module);
80
- }
81
- }
82
- // Continue the process
83
- callback();
84
- });
85
- }
86
- }
87
- exports.default = DelegateModulesPlugin;
88
- //# sourceMappingURL=DelegateModulesPlugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DelegateModulesPlugin.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/plugins/DelegateModulesPlugin.ts"],"names":[],"mappings":";;AAQA;;;GAGG;AACH,MAAM,qBAAqB;IAIzB,YAAY,OAAgD;QAC1D,IAAI,CAAC,OAAO,mBAAK,KAAK,EAAE,KAAK,IAAK,OAAO,CAAE,CAAC;QAC5C,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,CAAC;IAED,cAAc,CAAC,MAAuB,EAAE,IAAY;QAClD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,IAAI,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE;gBACtB,OAAO,KAAK,CAAC;aACd;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,oBAAoB,CAAC,WAAwB,EAAE,MAAe;QAC5D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;gBACvC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;oBAC1D,IAAI,CAAC,OAAO,CAAC,KAAK;wBAChB,OAAO,CAAC,GAAG,CACT,SAAS,EACT,MAAM,CAAC,UAAU,EAAE,EACnB,WAAW,EACX,K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uB;YACvB,QAAQ,EAAE,CAAC;QACb,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AACD,kBAAe,qBAAqB,CAAC"}
@@ -1,2 +0,0 @@
1
- import { RuntimeRemotesMap } from '../types';
2
- export declare const getRuntimeRemotes: () => RuntimeRemotesMap;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRuntimeRemotes = void 0;
4
- const common_1 = require("./common");
5
- const getRuntimeRemotes = () => {
6
- try {
7
- const runtimeRemotes = Object.entries(common_1.remoteVars).reduce(function (acc, item) {
8
- const [key, value] = item;
9
- // if its an object with a thenable (eagerly executing function)
10
- if (typeof value === 'object' && typeof value.then === 'function') {
11
- acc[key] = { asyncContainer: value };
12
- }
13
- // if its a function that must be called (lazily executing function)
14
- else if (typeof value === 'function') {
15
- // @ts-ignore
16
- acc[key] = { asyncContainer: value };
17
- }
18
- // if its a delegate module, skip it
19
- else if (typeof value === 'string' && value.startsWith('internal ')) {
20
- const [request, query] = value.replace('internal ', '').split('?');
21
- if (query) {
22
- const remoteSyntax = new URLSearchParams(query).get('remote');
23
- if (remoteSyntax) {
24
- const [url, global] = (0, common_1.extractUrlAndGlobal)(remoteSyntax);
25
- acc[key] = { global, url };
26
- }
27
- }
28
- }
29
- // if its just a string (global@url)
30
- else if (typeof value === 'string') {
31
- const [url, global] = (0, common_1.extractUrlAndGlobal)(value);
32
- acc[key] = { global, url };
33
- }
34
- // we dont know or currently support this type
35
- else {
36
- //@ts-ignore
37
- console.log('remotes process', process.env.REMOTES);
38
- throw new Error(`[mf] Invalid value received for runtime_remote "${key}"`);
39
- }
40
- return acc;
41
- }, {});
42
- return runtimeRemotes;
43
- }
44
- catch (err) {
45
- console.warn('Unable to retrieve runtime remotes: ', err);
46
- }
47
- return {};
48
- };
49
- exports.getRuntimeRemotes = getRuntimeRemotes;
50
- //# sourceMappingURL=getRuntimeRemotes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getR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KAAK,KAAK,QAAQ,EAAE;gBAClC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,IAAA,4BAAmB,EAAC,KAAK,CAAC,CAAC;gBACjD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;aAC5B;YACD,8CAA8C;iBACzC;gBACH,YAAY;gBACZ,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACpD,MAAM,IAAI,KAAK,CACb,mDAAmD,GAAG,GAAG,CAC1D,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAuB,CAAC,CAAC;QAEzB,OAAO,cAAc,CAAC;KACvB;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;KAC3D;IAED,OAAO,EAAuB,CAAC;AACjC,CAAC,CAAC;AAlDW,QAAA,iBAAiB,qBAkD5B"}
@@ -1,2 +0,0 @@
1
- import { RuntimeRemote } from '../types';
2
- export declare const importDelegatedModule: (keyOrRuntimeRemoteItem: string | RuntimeRemote) => Promise<any>;
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.importDelegatedModule = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("./common");
6
- const importDelegatedModule = (keyOrRuntimeRemoteItem) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
7
- // @ts-ignore
8
- return (0, common_1.loadScript)(keyOrRuntimeRemoteItem)
9
- .then((asyncContainer) => {
10
- return asyncContainer;
11
- })
12
- .then((asyncContainer) => {
13
- // most of this is only needed because of legacy promise based implementation
14
- // can remove proxies once we remove promise based implementations
15
- if (typeof window === 'undefined') {
16
- if (!Object.hasOwnProperty.call(keyOrRuntimeRemoteItem, 'global')) {
17
- return asyncContainer;
18
- }
19
- // return asyncContainer;
20
- //TODO: need to solve chunk flushing with delegated modules
21
- return {
22
- get: function (arg) {
23
- //@ts-ignore
24
- return asyncContainer.get(arg).then((f) => {
25
- const m = f();
26
- const result = {
27
- __esModule: m.__esModule,
28
- };
29
- for (const prop in m) {
30
- if (typeof m[prop] === 'function') {
31
- Object.defineProperty(result, prop, {
32
- get: function () {
33
- return function () {
34
- //@ts-ignore
35
- if (global.usedChunks)
36
- //@ts-ignore
37
- global.usedChunks.add(
38
- //@ts-ignore
39
- `${keyOrRuntimeRemoteItem.global}->${arg}`);
40
- // eslint-disable-next-line prefer-rest-params
41
- return m[prop](arguments);
42
- };
43
- },
44
- enumerable: true,
45
- });
46
- }
47
- else {
48
- Object.defineProperty(result, prop, {
49
- get: () => {
50
- //@ts-ignore
51
- if (global.usedChunks)
52
- //@ts-ignore
53
- global.usedChunks.add(
54
- //@ts-ignore
55
- `${keyOrRuntimeRemoteItem.global}->${arg}`);
56
- return m[prop];
57
- },
58
- enumerable: true,
59
- });
60
- }
61
- }
62
- if (m.then) {
63
- return Promise.resolve(() => result);
64
- }
65
- return () => result;
66
- });
67
- },
68
- init: asyncContainer.init,
69
- };
70
- }
71
- else {
72
- return asyncContainer;
73
- }
74
- });
75
- });
76
- exports.importDelegatedModule = importDelegatedModule;
77
- //# sourceMappingURL=importDelegatedModule.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"importDelegatedModule.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/importDelegatedModule.ts"],"names":[],"mappings":";;;;AACA,qCAAsC;AAE/B,MAAM,qBAAqB,GAAG,CACnC,sBAA8C,EAC9C,EAAE;IACF,aAAa;IACb,OAAO,IAAA,mBAAU,EAAC,sBAAsB,CAAC;SACtC,IAAI,CAAC,CAAC,cAAsC,EAAE,EAAE;QAC/C,OAAO,cAAc,CAAC;IACxB,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,cAAsC,EAAE,EAAE;QAC/C,6EAA6E;QAC7E,kEAAkE;QAClE,IAAI,OAAO,MAAM,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