@module-federation/node 2.7.32 → 2.7.33

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 (122) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +31 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  3. package/dist/plugins/ChunkCorrelationPlugin.js +308 -0
  4. package/dist/plugins/ChunkCorrelationPlugin.js.map +1 -0
  5. package/dist/plugins/ChunkCorrelationPlugin.mjs +305 -0
  6. package/dist/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
  7. package/dist/src/filesystem/stratagies.d.mts +21 -0
  8. package/dist/src/filesystem/stratagies.d.ts +10 -7
  9. package/dist/src/filesystem/stratagies.js +97 -116
  10. package/dist/src/filesystem/stratagies.js.map +1 -1
  11. package/dist/src/filesystem/stratagies.mjs +103 -0
  12. package/dist/src/filesystem/stratagies.mjs.map +1 -0
  13. package/dist/src/index.d.mts +8 -0
  14. package/dist/src/index.d.ts +8 -7
  15. package/dist/src/index.js +16 -22
  16. package/dist/src/index.mjs +9 -0
  17. package/dist/src/plugins/AutomaticPublicPathPlugin.d.mts +12 -0
  18. package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +9 -7
  19. package/dist/src/plugins/AutomaticPublicPathPlugin.js +26 -35
  20. package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -1
  21. package/dist/src/plugins/AutomaticPublicPathPlugin.mjs +28 -0
  22. package/dist/src/plugins/AutomaticPublicPathPlugin.mjs.map +1 -0
  23. package/dist/src/plugins/ChunkCorrelationPlugin.d.mts +5 -0
  24. package/dist/src/plugins/ChunkCorrelationPlugin.d.ts +4 -61
  25. package/dist/src/plugins/ChunkCorrelationPlugin.js +8 -440
  26. package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -1
  27. package/dist/src/plugins/ChunkCorrelationPlugin.mjs +8 -0
  28. package/dist/src/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
  29. package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.mts +21 -0
  30. package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.ts +16 -13
  31. package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +68 -118
  32. package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -1
  33. package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs +70 -0
  34. package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs.map +1 -0
  35. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.mts +46 -0
  36. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +39 -34
  37. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +110 -126
  38. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -1
  39. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs +111 -0
  40. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs.map +1 -0
  41. package/dist/src/plugins/EntryChunkTrackerPlugin.d.mts +17 -0
  42. package/dist/src/plugins/EntryChunkTrackerPlugin.d.ts +14 -10
  43. package/dist/src/plugins/EntryChunkTrackerPlugin.js +30 -32
  44. package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -1
  45. package/dist/src/plugins/EntryChunkTrackerPlugin.mjs +38 -0
  46. package/dist/src/plugins/EntryChunkTrackerPlugin.mjs.map +1 -0
  47. package/dist/src/plugins/NodeFederationPlugin.d.mts +54 -0
  48. package/dist/src/plugins/NodeFederationPlugin.d.ts +33 -26
  49. package/dist/src/plugins/NodeFederationPlugin.js +69 -84
  50. package/dist/src/plugins/NodeFederationPlugin.js.map +1 -1
  51. package/dist/src/plugins/NodeFederationPlugin.mjs +70 -0
  52. package/dist/src/plugins/NodeFederationPlugin.mjs.map +1 -0
  53. package/dist/src/plugins/RemotePublicPathRuntimeModule.d.mts +15 -0
  54. package/dist/src/plugins/RemotePublicPathRuntimeModule.d.ts +12 -8
  55. package/dist/src/plugins/RemotePublicPathRuntimeModule.js +34 -35
  56. package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -1
  57. package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs +132 -0
  58. package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs.map +1 -0
  59. package/dist/src/plugins/StreamingTargetPlugin.d.mts +32 -0
  60. package/dist/src/plugins/StreamingTargetPlugin.d.ts +19 -16
  61. package/dist/src/plugins/StreamingTargetPlugin.js +43 -56
  62. package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -1
  63. package/dist/src/plugins/StreamingTargetPlugin.mjs +46 -0
  64. package/dist/src/plugins/StreamingTargetPlugin.mjs.map +1 -0
  65. package/dist/src/plugins/UniversalFederationPlugin.d.mts +49 -0
  66. package/dist/src/plugins/UniversalFederationPlugin.d.ts +26 -23
  67. package/dist/src/plugins/UniversalFederationPlugin.js +58 -81
  68. package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -1
  69. package/dist/src/plugins/UniversalFederationPlugin.mjs +61 -0
  70. package/dist/src/plugins/UniversalFederationPlugin.mjs.map +1 -0
  71. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.mts +9 -0
  72. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.ts +6 -3
  73. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js +17 -17
  74. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js.map +1 -1
  75. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs +25 -0
  76. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs.map +1 -0
  77. package/dist/src/plugins/webpackChunkUtilities.d.mts +55 -0
  78. package/dist/src/plugins/webpackChunkUtilities.d.ts +14 -9
  79. package/dist/src/plugins/webpackChunkUtilities.js +195 -257
  80. package/dist/src/plugins/webpackChunkUtilities.js.map +1 -1
  81. package/dist/src/plugins/webpackChunkUtilities.mjs +234 -0
  82. package/dist/src/plugins/webpackChunkUtilities.mjs.map +1 -0
  83. package/dist/src/recordDynamicRemoteEntryHashPlugin.d.mts +7 -0
  84. package/dist/src/recordDynamicRemoteEntryHashPlugin.d.ts +5 -2
  85. package/dist/src/recordDynamicRemoteEntryHashPlugin.js +24 -61
  86. package/dist/src/recordDynamicRemoteEntryHashPlugin.js.map +1 -1
  87. package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs +26 -0
  88. package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs.map +1 -0
  89. package/dist/src/runtimePlugin.d.mts +27 -0
  90. package/dist/src/runtimePlugin.d.ts +24 -19
  91. package/dist/src/runtimePlugin.js +157 -252
  92. package/dist/src/runtimePlugin.js.map +1 -1
  93. package/dist/src/runtimePlugin.mjs +169 -0
  94. package/dist/src/runtimePlugin.mjs.map +1 -0
  95. package/dist/src/types/index.d.mts +8 -0
  96. package/dist/src/types/index.d.ts +8 -3
  97. package/dist/src/types/index.js +1 -3
  98. package/dist/src/types/index.mjs +1 -0
  99. package/dist/src/utils/flush-chunks.d.mts +15 -0
  100. package/dist/src/utils/flush-chunks.d.ts +7 -3
  101. package/dist/src/utils/flush-chunks.js +87 -161
  102. package/dist/src/utils/flush-chunks.js.map +1 -1
  103. package/dist/src/utils/flush-chunks.mjs +99 -0
  104. package/dist/src/utils/flush-chunks.mjs.map +1 -0
  105. package/dist/src/utils/hot-reload.d.mts +16 -0
  106. package/dist/src/utils/hot-reload.d.ts +14 -10
  107. package/dist/src/utils/hot-reload.js +177 -264
  108. package/dist/src/utils/hot-reload.js.map +1 -1
  109. package/dist/src/utils/hot-reload.mjs +194 -0
  110. package/dist/src/utils/hot-reload.mjs.map +1 -0
  111. package/dist/src/utils/index.d.mts +3 -0
  112. package/dist/src/utils/index.d.ts +3 -2
  113. package/dist/src/utils/index.js +15 -19
  114. package/dist/src/utils/index.mjs +4 -0
  115. package/package.json +59 -15
  116. package/dist/jest.config.d.ts +0 -11
  117. package/dist/jest.config.js +0 -19
  118. package/dist/jest.config.js.map +0 -1
  119. package/dist/package.json +0 -82
  120. package/dist/src/index.js.map +0 -1
  121. package/dist/src/types/index.js.map +0 -1
  122. package/dist/src/utils/index.js.map +0 -1
@@ -1,239 +1,177 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateHmrCode = generateHmrCode;
4
- exports.getInitialChunkIds = getInitialChunkIds;
5
- exports.generateLoadingCode = generateLoadingCode;
6
- exports.generateHmrManifestCode = generateHmrManifestCode;
7
- exports.handleOnChunkLoad = handleOnChunkLoad;
8
- exports.generateLoadScript = generateLoadScript;
9
- exports.generateInstallChunk = generateInstallChunk;
10
- exports.generateExternalInstallChunkCode = generateExternalInstallChunkCode;
11
- const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
12
- const { RuntimeGlobals, Template } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
+ let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
4
+
5
+ //#region src/plugins/webpackChunkUtilities.ts
6
+ const { RuntimeGlobals, Template } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
13
7
  /**
14
- * Generates the hot module replacement (HMR) code.
15
- * @param {boolean} withHmr - Flag indicating whether HMR is enabled.
16
- * @param {string} rootOutputDir - The root output directory.
17
- * @returns {string} - The generated HMR code.
18
- */
8
+ * Generates the hot module replacement (HMR) code.
9
+ * @param {boolean} withHmr - Flag indicating whether HMR is enabled.
10
+ * @param {string} rootOutputDir - The root output directory.
11
+ * @returns {string} - The generated HMR code.
12
+ */
19
13
  function generateHmrCode(withHmr, rootOutputDir) {
20
- if (!withHmr) {
21
- return '// no HMR';
22
- }
23
- return Template.asString([
24
- // Function to load updated chunk
25
- 'function loadUpdateChunk(chunkId, updatedModulesList) {',
26
- Template.indent([
27
- 'return new Promise(function(resolve, reject) {',
28
- Template.indent([
29
- // Construct filename for the updated chunk
30
- `var filename = require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
31
- // Read the updated chunk file
32
- "require('fs').readFile(filename, 'utf-8', function(err, content) {",
33
- Template.indent([
34
- 'if(err) return reject(err);',
35
- 'var update = {};',
36
- // Execute the updated chunk in the current context
37
- "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" +
38
- "(update, require, require('path').dirname(filename), filename);",
39
- 'var updatedModules = update.modules;',
40
- 'var runtime = update.runtime;',
41
- // Iterate over the updated modules
42
- 'for(var moduleId in updatedModules) {',
43
- Template.indent([
44
- `if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
45
- Template.indent([
46
- `currentUpdate[moduleId] = updatedModules[moduleId];`,
47
- 'if(updatedModulesList) updatedModulesList.push(moduleId);',
48
- ]),
49
- '}',
50
- ]),
51
- '}',
52
- 'if(runtime) currentUpdateRuntime.push(runtime);',
53
- 'resolve();',
54
- ]),
55
- '});',
56
- ]),
57
- '});',
58
- ]),
59
- '}',
60
- '',
61
- // Replace placeholders in the HMR runtime code
62
- Template.getFunctionContent(
63
- // eslint-disable-next-line @typescript-eslint/no-var-requires
64
- require('webpack/lib/hmr/JavascriptHotModuleReplacement.runtime.js'))
65
- .replace(/\$key\$/g, 'readFileVm')
66
- .replace(/\$installedChunks\$/g, 'installedChunks')
67
- .replace(/\$loadUpdateChunk\$/g, 'loadUpdateChunk')
68
- .replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache)
69
- .replace(/\$moduleFactories\$/g, RuntimeGlobals.moduleFactories)
70
- .replace(/\$ensureChunkHandlers\$/g, RuntimeGlobals.ensureChunkHandlers)
71
- .replace(/\$hasOwnProperty\$/g, RuntimeGlobals.hasOwnProperty)
72
- .replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData)
73
- .replace(/\$hmrDownloadUpdateHandlers\$/g, RuntimeGlobals.hmrDownloadUpdateHandlers)
74
- .replace(/\$hmrInvalidateModuleHandlers\$/g, RuntimeGlobals.hmrInvalidateModuleHandlers),
75
- ]);
14
+ if (!withHmr) return "// no HMR";
15
+ return Template.asString([
16
+ "function loadUpdateChunk(chunkId, updatedModulesList) {",
17
+ Template.indent([
18
+ "return new Promise(function(resolve, reject) {",
19
+ Template.indent([
20
+ `var filename = require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
21
+ "require('fs').readFile(filename, 'utf-8', function(err, content) {",
22
+ Template.indent([
23
+ "if(err) return reject(err);",
24
+ "var update = {};",
25
+ "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)(update, require, require('path').dirname(filename), filename);",
26
+ "var updatedModules = update.modules;",
27
+ "var runtime = update.runtime;",
28
+ "for(var moduleId in updatedModules) {",
29
+ Template.indent([
30
+ `if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,
31
+ Template.indent([`currentUpdate[moduleId] = updatedModules[moduleId];`, "if(updatedModulesList) updatedModulesList.push(moduleId);"]),
32
+ "}"
33
+ ]),
34
+ "}",
35
+ "if(runtime) currentUpdateRuntime.push(runtime);",
36
+ "resolve();"
37
+ ]),
38
+ "});"
39
+ ]),
40
+ "});"
41
+ ]),
42
+ "}",
43
+ "",
44
+ Template.getFunctionContent(require("webpack/lib/hmr/JavascriptHotModuleReplacement.runtime.js")).replace(/\$key\$/g, "readFileVm").replace(/\$installedChunks\$/g, "installedChunks").replace(/\$loadUpdateChunk\$/g, "loadUpdateChunk").replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache).replace(/\$moduleFactories\$/g, RuntimeGlobals.moduleFactories).replace(/\$ensureChunkHandlers\$/g, RuntimeGlobals.ensureChunkHandlers).replace(/\$hasOwnProperty\$/g, RuntimeGlobals.hasOwnProperty).replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData).replace(/\$hmrDownloadUpdateHandlers\$/g, RuntimeGlobals.hmrDownloadUpdateHandlers).replace(/\$hmrInvalidateModuleHandlers\$/g, RuntimeGlobals.hmrInvalidateModuleHandlers)
45
+ ]);
76
46
  }
77
47
  /**
78
- * Retrieves the initial chunk IDs.
79
- * @param {Chunk} chunk - The chunk object.
80
- * @param {ChunkGraph} chunkGraph - The chunk graph object.
81
- * @param {any} chunkHasJs - Function to check if a chunk has JavaScript.
82
- * @returns {Set} - The set of initial chunk IDs.
83
- */
48
+ * Retrieves the initial chunk IDs.
49
+ * @param {Chunk} chunk - The chunk object.
50
+ * @param {ChunkGraph} chunkGraph - The chunk graph object.
51
+ * @param {any} chunkHasJs - Function to check if a chunk has JavaScript.
52
+ * @returns {Set} - The set of initial chunk IDs.
53
+ */
84
54
  function getInitialChunkIds(chunk, chunkGraph, chunkHasJs) {
85
- const initialChunkIds = new Set(chunk.ids);
86
- for (const c of chunk.getAllInitialChunks()) {
87
- if (c === chunk || chunkHasJs(c, chunkGraph))
88
- continue;
89
- if (c.ids) {
90
- for (const id of c.ids)
91
- initialChunkIds.add(id);
92
- }
93
- for (const c of chunk.getAllAsyncChunks()) {
94
- if (c === chunk || chunkHasJs(c, chunkGraph))
95
- continue;
96
- if (c.ids) {
97
- for (const id of c.ids)
98
- initialChunkIds.add(id);
99
- }
100
- }
101
- }
102
- return initialChunkIds;
55
+ const initialChunkIds = new Set(chunk.ids);
56
+ for (const c of chunk.getAllInitialChunks()) {
57
+ if (c === chunk || chunkHasJs(c, chunkGraph)) continue;
58
+ if (c.ids) for (const id of c.ids) initialChunkIds.add(id);
59
+ for (const c of chunk.getAllAsyncChunks()) {
60
+ if (c === chunk || chunkHasJs(c, chunkGraph)) continue;
61
+ if (c.ids) for (const id of c.ids) initialChunkIds.add(id);
62
+ }
63
+ }
64
+ return initialChunkIds;
103
65
  }
104
66
  /**
105
- * Generates the loading code for chunks.
106
- * @param {boolean} withLoading - Flag indicating whether chunk loading is enabled.
107
- * @param {string} fn - The function name.
108
- * @param {any} hasJsMatcher - Function to check if a chunk has JavaScript.
109
- * @param {string} rootOutputDir - The root output directory.
110
- * @param {Record<string, string>} remotes - The remotes object.
111
- * @param {string | undefined} name - The name of the chunk.
112
- * @returns {string} - The generated loading code.
113
- */
67
+ * Generates the loading code for chunks.
68
+ * @param {boolean} withLoading - Flag indicating whether chunk loading is enabled.
69
+ * @param {string} fn - The function name.
70
+ * @param {any} hasJsMatcher - Function to check if a chunk has JavaScript.
71
+ * @param {string} rootOutputDir - The root output directory.
72
+ * @param {Record<string, string>} remotes - The remotes object.
73
+ * @param {string | undefined} name - The name of the chunk.
74
+ * @returns {string} - The generated loading code.
75
+ */
114
76
  function generateLoadingCode(withLoading, fn, hasJsMatcher, rootOutputDir, remotes, name) {
115
- if (!withLoading) {
116
- return '// no chunk loading';
117
- }
118
- return Template.asString([
119
- '// Dynamic filesystem chunk loading for javascript',
120
- `${fn}.readFileVm = function(chunkId, promises) {`,
121
- hasJsMatcher !== false
122
- ? Template.indent([
123
- 'var installedChunkData = installedChunks[chunkId];',
124
- 'if(installedChunkData !== 0) { // 0 means "already installed".',
125
- Template.indent([
126
- '// array of [resolve, reject, promise] means "currently loading"',
127
- 'if(installedChunkData) {',
128
- Template.indent(['promises.push(installedChunkData[2]);']),
129
- '} else {',
130
- Template.indent([
131
- hasJsMatcher === true
132
- ? 'if(true) { // all chunks have JS'
133
- : `if(${hasJsMatcher('chunkId')}) {`,
134
- Template.indent([
135
- '// load the chunk and return promise to it',
136
- 'var promise = new Promise(async function(resolve, reject) {',
137
- Template.indent([
138
- 'installedChunkData = installedChunks[chunkId] = [resolve, reject];',
139
- 'function installChunkCallback(error,chunk){',
140
- Template.indent([
141
- 'if(error) return reject(error);',
142
- 'installChunk(chunk);',
143
- ]),
144
- '}',
145
- 'var fs = typeof process !== "undefined" ? require(\'fs\') : false;',
146
- `var filename = typeof process !== "undefined" ? require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId)) : false;`,
147
- 'if(fs && fs.existsSync(filename)) {',
148
- Template.indent([
149
- `loadChunkStrategy('filesystem', chunkId, ${JSON.stringify(rootOutputDir)}, remotes, installChunkCallback);`,
150
- ]),
151
- '} else { ',
152
- Template.indent([
153
- `var remotes = ${JSON.stringify(Object.values(remotes).reduce((acc, remote) => {
154
- const [global, url] = remote.split('@');
155
- acc[global] = url;
156
- return acc;
157
- }, {}))};`,
158
- `var chunkName = ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
159
- "const loadingStrategy = typeof process !== 'undefined' ? 'http-vm' : 'http-eval';",
160
- `loadChunkStrategy(loadingStrategy, chunkName,${RuntimeGlobals.require}.federation.initOptions.name, ${RuntimeGlobals.require}.federation.initOptions.remotes, installChunkCallback);`,
161
- ]),
162
- '}',
163
- ]),
164
- '});',
165
- 'promises.push(installedChunkData[2] = promise);',
166
- ]),
167
- '} else installedChunks[chunkId] = 0;',
168
- ]),
169
- '}',
170
- ]),
171
- '}',
172
- ])
173
- : Template.indent(['installedChunks[chunkId] = 0;']),
174
- '};',
175
- ]);
77
+ if (!withLoading) return "// no chunk loading";
78
+ return Template.asString([
79
+ "// Dynamic filesystem chunk loading for javascript",
80
+ `${fn}.readFileVm = function(chunkId, promises) {`,
81
+ hasJsMatcher !== false ? Template.indent([
82
+ "var installedChunkData = installedChunks[chunkId];",
83
+ "if(installedChunkData !== 0) { // 0 means \"already installed\".",
84
+ Template.indent([
85
+ "// array of [resolve, reject, promise] means \"currently loading\"",
86
+ "if(installedChunkData) {",
87
+ Template.indent(["promises.push(installedChunkData[2]);"]),
88
+ "} else {",
89
+ Template.indent([
90
+ hasJsMatcher === true ? "if(true) { // all chunks have JS" : `if(${hasJsMatcher("chunkId")}) {`,
91
+ Template.indent([
92
+ "// load the chunk and return promise to it",
93
+ "var promise = new Promise(async function(resolve, reject) {",
94
+ Template.indent([
95
+ "installedChunkData = installedChunks[chunkId] = [resolve, reject];",
96
+ "function installChunkCallback(error,chunk){",
97
+ Template.indent(["if(error) return reject(error);", "installChunk(chunk);"]),
98
+ "}",
99
+ "var fs = typeof process !== \"undefined\" ? require('fs') : false;",
100
+ `var filename = typeof process !== "undefined" ? require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId)) : false;`,
101
+ "if(fs && fs.existsSync(filename)) {",
102
+ Template.indent([`loadChunkStrategy('filesystem', chunkId, ${JSON.stringify(rootOutputDir)}, remotes, installChunkCallback);`]),
103
+ "} else { ",
104
+ Template.indent([
105
+ `var remotes = ${JSON.stringify(Object.values(remotes).reduce((acc, remote) => {
106
+ const [global, url] = remote.split("@");
107
+ acc[global] = url;
108
+ return acc;
109
+ }, {}))};`,
110
+ `var chunkName = ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
111
+ "const loadingStrategy = typeof process !== 'undefined' ? 'http-vm' : 'http-eval';",
112
+ `loadChunkStrategy(loadingStrategy, chunkName,${RuntimeGlobals.require}.federation.initOptions.name, ${RuntimeGlobals.require}.federation.initOptions.remotes, installChunkCallback);`
113
+ ]),
114
+ "}"
115
+ ]),
116
+ "});",
117
+ "promises.push(installedChunkData[2] = promise);"
118
+ ]),
119
+ "} else installedChunks[chunkId] = 0;"
120
+ ]),
121
+ "}"
122
+ ]),
123
+ "}"
124
+ ]) : Template.indent(["installedChunks[chunkId] = 0;"]),
125
+ "};"
126
+ ]);
176
127
  }
177
128
  /**
178
- * Generates the HMR manifest code.
179
- * @param {boolean} withHmrManifest - Flag indicating whether HMR manifest is enabled.
180
- * @param {string} rootOutputDir - The root output directory.
181
- * @returns {string} - The generated HMR manifest code.
182
- */
129
+ * Generates the HMR manifest code.
130
+ * @param {boolean} withHmrManifest - Flag indicating whether HMR manifest is enabled.
131
+ * @param {string} rootOutputDir - The root output directory.
132
+ * @returns {string} - The generated HMR manifest code.
133
+ */
183
134
  function generateHmrManifestCode(withHmrManifest, rootOutputDir) {
184
- if (!withHmrManifest) {
185
- return '// no HMR manifest';
186
- }
187
- return Template.asString([
188
- `${RuntimeGlobals.hmrDownloadManifest} = function() {`,
189
- Template.indent([
190
- 'return new Promise(function(resolve, reject) {',
191
- Template.indent([
192
- `var filename = require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getUpdateManifestFilename}());`,
193
- "require('fs').readFile(filename, 'utf-8', function(err, content) {",
194
- Template.indent([
195
- 'if(err) {',
196
- Template.indent([
197
- 'if(err.code === "ENOENT") return resolve();',
198
- 'return reject(err);',
199
- ]),
200
- '}',
201
- 'try { resolve(JSON.parse(content)); }',
202
- 'catch(e) { reject(e); }',
203
- ]),
204
- '});',
205
- ]),
206
- '});',
207
- ]),
208
- '}',
209
- ]);
135
+ if (!withHmrManifest) return "// no HMR manifest";
136
+ return Template.asString([
137
+ `${RuntimeGlobals.hmrDownloadManifest} = function() {`,
138
+ Template.indent([
139
+ "return new Promise(function(resolve, reject) {",
140
+ Template.indent([
141
+ `var filename = require('path').join(__dirname, ${JSON.stringify(rootOutputDir)} + ${RuntimeGlobals.getUpdateManifestFilename}());`,
142
+ "require('fs').readFile(filename, 'utf-8', function(err, content) {",
143
+ Template.indent([
144
+ "if(err) {",
145
+ Template.indent(["if(err.code === \"ENOENT\") return resolve();", "return reject(err);"]),
146
+ "}",
147
+ "try { resolve(JSON.parse(content)); }",
148
+ "catch(e) { reject(e); }"
149
+ ]),
150
+ "});"
151
+ ]),
152
+ "});"
153
+ ]),
154
+ "}"
155
+ ]);
210
156
  }
211
157
  /**
212
- * Handles the on chunk load event.
213
- * @param {boolean} withOnChunkLoad - Flag indicating whether on chunk load event is enabled.
214
- * @param {any} runtimeTemplate - The runtime template.
215
- * @returns {string} - The generated on chunk load event handler.
216
- */
158
+ * Handles the on chunk load event.
159
+ * @param {boolean} withOnChunkLoad - Flag indicating whether on chunk load event is enabled.
160
+ * @param {any} runtimeTemplate - The runtime template.
161
+ * @returns {string} - The generated on chunk load event handler.
162
+ */
217
163
  function handleOnChunkLoad(withOnChunkLoad, runtimeTemplate) {
218
- if (withOnChunkLoad) {
219
- return `${RuntimeGlobals.onChunksLoaded}.readFileVm = ${runtimeTemplate.returningFunction('installedChunks[chunkId] === 0', 'chunkId')};`;
220
- }
221
- else {
222
- return '// no on chunks loaded';
223
- }
164
+ if (withOnChunkLoad) return `${RuntimeGlobals.onChunksLoaded}.readFileVm = ${runtimeTemplate.returningFunction("installedChunks[chunkId] === 0", "chunkId")};`;
165
+ else return "// no on chunks loaded";
224
166
  }
225
167
  /**
226
- * Generates the load script for server-side execution. This function creates a script that loads a remote module
227
- * and executes it in the current context. It supports both browser and Node.js environments.
228
- * @param {any} runtimeTemplate - The runtime template used to generate the load script.
229
- * @returns {string} - The generated load script.
230
- */
168
+ * Generates the load script for server-side execution. This function creates a script that loads a remote module
169
+ * and executes it in the current context. It supports both browser and Node.js environments.
170
+ * @param {any} runtimeTemplate - The runtime template used to generate the load script.
171
+ * @returns {string} - The generated load script.
172
+ */
231
173
  function generateLoadScript(runtimeTemplate) {
232
- return Template.asString([
233
- '// load script equivalent for server side',
234
- `${RuntimeGlobals.loadScript} = ${runtimeTemplate.basicFunction('url, callback, chunkId', [
235
- Template.indent([
236
- `async function executeLoad(url, callback, name) {
174
+ return Template.asString(["// load script equivalent for server side", `${RuntimeGlobals.loadScript} = ${runtimeTemplate.basicFunction("url, callback, chunkId", [Template.indent([`async function executeLoad(url, callback, name) {
237
175
  if (!name) {
238
176
  throw new Error('__webpack_require__.l name is required for ' + url);
239
177
  }
@@ -258,47 +196,47 @@ function generateLoadScript(runtimeTemplate) {
258
196
  callback(error);
259
197
  }
260
198
 
261
- }`,
262
- `executeLoad(url, callback, chunkId);`,
263
- ]),
264
- ])}`,
265
- ]);
199
+ }`, `executeLoad(url, callback, chunkId);`])])}`]);
266
200
  }
267
201
  function generateInstallChunk(runtimeTemplate, withOnChunkLoad) {
268
- return `var installChunk = ${runtimeTemplate.basicFunction('chunk', [
269
- 'var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;',
270
- 'for(var moduleId in moreModules) {',
271
- Template.indent([
272
- `if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
273
- Template.indent([
274
- `${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`,
275
- ]),
276
- '}',
277
- ]),
278
- '}',
279
- 'if(runtime) runtime(__webpack_require__);',
280
- 'for(var i = 0; i < chunkIds.length; i++) {',
281
- Template.indent([
282
- 'if(installedChunks[chunkIds[i]]) {',
283
- Template.indent(['installedChunks[chunkIds[i]][0]();']),
284
- '}',
285
- 'installedChunks[chunkIds[i]] = 0;',
286
- ]),
287
- '}',
288
- withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : '',
289
- ])};`;
202
+ return `var installChunk = ${runtimeTemplate.basicFunction("chunk", [
203
+ "var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;",
204
+ "for(var moduleId in moreModules) {",
205
+ Template.indent([
206
+ `if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,
207
+ Template.indent([`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`]),
208
+ "}"
209
+ ]),
210
+ "}",
211
+ "if(runtime) runtime(__webpack_require__);",
212
+ "for(var i = 0; i < chunkIds.length; i++) {",
213
+ Template.indent([
214
+ "if(installedChunks[chunkIds[i]]) {",
215
+ Template.indent(["installedChunks[chunkIds[i]][0]();"]),
216
+ "}",
217
+ "installedChunks[chunkIds[i]] = 0;"
218
+ ]),
219
+ "}",
220
+ withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : ""
221
+ ])};`;
290
222
  }
291
223
  function generateExternalInstallChunkCode(withExternalInstallChunk, debug) {
292
- if (!withExternalInstallChunk) {
293
- return '// no external install chunk';
294
- }
295
- return Template.asString([
296
- 'module.exports = __webpack_require__;',
297
- `${RuntimeGlobals.externalInstallChunk} = function(){`,
298
- debug
299
- ? `console.debug('node: webpack installing to install chunk id:', arguments['0'].id);`
300
- : '',
301
- `return installChunk.apply(this, arguments)};`,
302
- ]);
224
+ if (!withExternalInstallChunk) return "// no external install chunk";
225
+ return Template.asString([
226
+ "module.exports = __webpack_require__;",
227
+ `${RuntimeGlobals.externalInstallChunk} = function(){`,
228
+ debug ? `console.debug('node: webpack installing to install chunk id:', arguments['0'].id);` : "",
229
+ `return installChunk.apply(this, arguments)};`
230
+ ]);
303
231
  }
232
+
233
+ //#endregion
234
+ exports.generateExternalInstallChunkCode = generateExternalInstallChunkCode;
235
+ exports.generateHmrCode = generateHmrCode;
236
+ exports.generateHmrManifestCode = generateHmrManifestCode;
237
+ exports.generateInstallChunk = generateInstallChunk;
238
+ exports.generateLoadScript = generateLoadScript;
239
+ exports.generateLoadingCode = generateLoadingCode;
240
+ exports.getInitialChunkIds = getInitialChunkIds;
241
+ exports.handleOnChunkLoad = handleOnChunkLoad;
304
242
  //# sourceMappingURL=webpackChunkUtilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webpackChunkUtilities.js","sourceRoot":"","sources":["../../../src/plugins/webpackChunkUtilities.ts"],"names":[],"mappings":";;AAYA,0CAsEC;AAQD,gDAmBC;AAWD,kDAmFC;AAOD,0DAiCC;AAOD,8CAcC;AAOD,gDAsCC;AACD,oDA0BC;AACD,4EAgBC;AAjWD,0FAAqF;AACrF,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,OAAO,CAC1C,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAG9B;;;;;GAKG;AACH,SAAgB,eAAe,CAC7B,OAAgB,EAChB,aAAqB;IAErB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,OAAO,QAAQ,CAAC,QAAQ,CAAC;QACvB,iCAAiC;QACjC,yDAAyD;QACzD,QAAQ,CAAC,MAAM,CAAC;YACd,gDAAgD;YAChD,QAAQ,CAAC,MA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C,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"webpackChunkUtilities.js","names":[],"sources":["../../../src/plugins/webpackChunkUtilities.ts"],"sourcesContent":["import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { RuntimeGlobals, Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nimport type { Chunk, ChunkGraph } from 'webpack';\n\n/**\n * Generates the hot module replacement (HMR) code.\n * @param {boolean} withHmr - Flag indicating whether HMR is enabled.\n * @param {string} rootOutputDir - The root output directory.\n * @returns {string} - The generated HMR code.\n */\nexport function generateHmrCode(\n withHmr: boolean,\n rootOutputDir: string,\n): string {\n if (!withHmr) {\n return '// no HMR';\n }\n\n return Template.asString([\n // Function to load updated chunk\n 'function loadUpdateChunk(chunkId, updatedModulesList) {',\n Template.indent([\n 'return new Promise(function(resolve, reject) {',\n Template.indent([\n // Construct filename for the updated chunk\n `var filename = require('path').join(__dirname, ${JSON.stringify(\n rootOutputDir,\n )} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,\n // Read the updated chunk file\n \"require('fs').readFile(filename, 'utf-8', function(err, content) {\",\n Template.indent([\n 'if(err) return reject(err);',\n 'var update = {};',\n // Execute the updated chunk in the current context\n \"require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\\\n})', filename)\" +\n \"(update, require, require('path').dirname(filename), filename);\",\n 'var updatedModules = update.modules;',\n 'var runtime = update.runtime;',\n // Iterate over the updated modules\n 'for(var moduleId in updatedModules) {',\n Template.indent([\n `if(${RuntimeGlobals.hasOwnProperty}(updatedModules, moduleId)) {`,\n Template.indent([\n `currentUpdate[moduleId] = updatedModules[moduleId];`,\n 'if(updatedModulesList) updatedModulesList.push(moduleId);',\n ]),\n '}',\n ]),\n '}',\n 'if(runtime) currentUpdateRuntime.push(runtime);',\n 'resolve();',\n ]),\n '});',\n ]),\n '});',\n ]),\n '}',\n '',\n // Replace placeholders in the HMR runtime code\n Template.getFunctionContent(\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n require('webpack/lib/hmr/JavascriptHotModuleReplacement.runtime.js'),\n )\n .replace(/\\$key\\$/g, 'readFileVm')\n .replace(/\\$installedChunks\\$/g, 'installedChunks')\n .replace(/\\$loadUpdateChunk\\$/g, 'loadUpdateChunk')\n .replace(/\\$moduleCache\\$/g, RuntimeGlobals.moduleCache)\n .replace(/\\$moduleFactories\\$/g, RuntimeGlobals.moduleFactories)\n .replace(/\\$ensureChunkHandlers\\$/g, RuntimeGlobals.ensureChunkHandlers)\n .replace(/\\$hasOwnProperty\\$/g, RuntimeGlobals.hasOwnProperty)\n .replace(/\\$hmrModuleData\\$/g, RuntimeGlobals.hmrModuleData)\n .replace(\n /\\$hmrDownloadUpdateHandlers\\$/g,\n RuntimeGlobals.hmrDownloadUpdateHandlers,\n )\n .replace(\n /\\$hmrInvalidateModuleHandlers\\$/g,\n RuntimeGlobals.hmrInvalidateModuleHandlers,\n ),\n ]);\n}\n/**\n * Retrieves the initial chunk IDs.\n * @param {Chunk} chunk - The chunk object.\n * @param {ChunkGraph} chunkGraph - The chunk graph object.\n * @param {any} chunkHasJs - Function to check if a chunk has JavaScript.\n * @returns {Set} - The set of initial chunk IDs.\n */\nexport function getInitialChunkIds(\n chunk: Chunk,\n chunkGraph: ChunkGraph,\n chunkHasJs: any,\n) {\n const initialChunkIds = new Set(chunk.ids);\n for (const c of chunk.getAllInitialChunks()) {\n if (c === chunk || chunkHasJs(c, chunkGraph)) continue;\n if (c.ids) {\n for (const id of c.ids) initialChunkIds.add(id);\n }\n for (const c of chunk.getAllAsyncChunks()) {\n if (c === chunk || chunkHasJs(c, chunkGraph)) continue;\n if (c.ids) {\n for (const id of c.ids) initialChunkIds.add(id);\n }\n }\n }\n return initialChunkIds;\n}\n/**\n * Generates the loading code for chunks.\n * @param {boolean} withLoading - Flag indicating whether chunk loading is enabled.\n * @param {string} fn - The function name.\n * @param {any} hasJsMatcher - Function to check if a chunk has JavaScript.\n * @param {string} rootOutputDir - The root output directory.\n * @param {Record<string, string>} remotes - The remotes object.\n * @param {string | undefined} name - The name of the chunk.\n * @returns {string} - The generated loading code.\n */\nexport function generateLoadingCode(\n withLoading: boolean,\n fn: string,\n hasJsMatcher: any,\n rootOutputDir: string,\n remotes: Record<string, string>,\n name: string | undefined,\n): string {\n if (!withLoading) {\n return '// no chunk loading';\n }\n\n return Template.asString([\n '// Dynamic filesystem chunk loading for javascript',\n `${fn}.readFileVm = function(chunkId, promises) {`,\n hasJsMatcher !== false\n ? Template.indent([\n 'var installedChunkData = installedChunks[chunkId];',\n 'if(installedChunkData !== 0) { // 0 means \"already installed\".',\n Template.indent([\n '// array of [resolve, reject, promise] means \"currently loading\"',\n 'if(installedChunkData) {',\n Template.indent(['promises.push(installedChunkData[2]);']),\n '} else {',\n Template.indent([\n hasJsMatcher === true\n ? 'if(true) { // all chunks have JS'\n : `if(${hasJsMatcher('chunkId')}) {`,\n Template.indent([\n '// load the chunk and return promise to it',\n 'var promise = new Promise(async function(resolve, reject) {',\n Template.indent([\n 'installedChunkData = installedChunks[chunkId] = [resolve, reject];',\n 'function installChunkCallback(error,chunk){',\n Template.indent([\n 'if(error) return reject(error);',\n 'installChunk(chunk);',\n ]),\n '}',\n 'var fs = typeof process !== \"undefined\" ? require(\\'fs\\') : false;',\n `var filename = typeof process !== \"undefined\" ? require('path').join(__dirname, ${JSON.stringify(\n rootOutputDir,\n )} + ${\n RuntimeGlobals.getChunkScriptFilename\n }(chunkId)) : false;`,\n\n 'if(fs && fs.existsSync(filename)) {',\n Template.indent([\n `loadChunkStrategy('filesystem', chunkId, ${JSON.stringify(\n rootOutputDir,\n )}, remotes, installChunkCallback);`,\n ]),\n '} else { ',\n Template.indent([\n `var remotes = ${JSON.stringify(\n Object.values(remotes).reduce(\n (acc, remote) => {\n const [global, url] = remote.split('@');\n acc[global] = url;\n return acc;\n },\n {} as Record<string, string>,\n ),\n )};`,\n\n `var chunkName = ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,\n \"const loadingStrategy = typeof process !== 'undefined' ? 'http-vm' : 'http-eval';\",\n `loadChunkStrategy(loadingStrategy, chunkName,${RuntimeGlobals.require}.federation.initOptions.name, ${RuntimeGlobals.require}.federation.initOptions.remotes, installChunkCallback);`,\n ]),\n '}',\n ]),\n '});',\n 'promises.push(installedChunkData[2] = promise);',\n ]),\n '} else installedChunks[chunkId] = 0;',\n ]),\n '}',\n ]),\n '}',\n ])\n : Template.indent(['installedChunks[chunkId] = 0;']),\n '};',\n ]);\n}\n/**\n * Generates the HMR manifest code.\n * @param {boolean} withHmrManifest - Flag indicating whether HMR manifest is enabled.\n * @param {string} rootOutputDir - The root output directory.\n * @returns {string} - The generated HMR manifest code.\n */\nexport function generateHmrManifestCode(\n withHmrManifest: boolean,\n rootOutputDir: string,\n): string {\n if (!withHmrManifest) {\n return '// no HMR manifest';\n }\n\n return Template.asString([\n `${RuntimeGlobals.hmrDownloadManifest} = function() {`,\n Template.indent([\n 'return new Promise(function(resolve, reject) {',\n Template.indent([\n `var filename = require('path').join(__dirname, ${JSON.stringify(\n rootOutputDir,\n )} + ${RuntimeGlobals.getUpdateManifestFilename}());`,\n \"require('fs').readFile(filename, 'utf-8', function(err, content) {\",\n Template.indent([\n 'if(err) {',\n Template.indent([\n 'if(err.code === \"ENOENT\") return resolve();',\n 'return reject(err);',\n ]),\n '}',\n 'try { resolve(JSON.parse(content)); }',\n 'catch(e) { reject(e); }',\n ]),\n '});',\n ]),\n '});',\n ]),\n '}',\n ]);\n}\n/**\n * Handles the on chunk load event.\n * @param {boolean} withOnChunkLoad - Flag indicating whether on chunk load event is enabled.\n * @param {any} runtimeTemplate - The runtime template.\n * @returns {string} - The generated on chunk load event handler.\n */\nexport function handleOnChunkLoad(\n withOnChunkLoad: boolean,\n runtimeTemplate: any,\n): string {\n if (withOnChunkLoad) {\n return `${\n RuntimeGlobals.onChunksLoaded\n }.readFileVm = ${runtimeTemplate.returningFunction(\n 'installedChunks[chunkId] === 0',\n 'chunkId',\n )};`;\n } else {\n return '// no on chunks loaded';\n }\n}\n/**\n * Generates the load script for server-side execution. This function creates a script that loads a remote module\n * and executes it in the current context. It supports both browser and Node.js environments.\n * @param {any} runtimeTemplate - The runtime template used to generate the load script.\n * @returns {string} - The generated load script.\n */\nexport function generateLoadScript(runtimeTemplate: any): string {\n return Template.asString([\n '// load script equivalent for server side',\n `${RuntimeGlobals.loadScript} = ${runtimeTemplate.basicFunction(\n 'url, callback, chunkId',\n [\n Template.indent([\n `async function executeLoad(url, callback, name) {\n if (!name) {\n throw new Error('__webpack_require__.l name is required for ' + url);\n }\n const usesInternalRef = name.startsWith('__webpack_require__')\n if (usesInternalRef) {\n const regex = /__webpack_require__\\\\.federation\\\\.instance\\\\.moduleCache\\\\.get\\\\(([^)]+)\\\\)/;\n const match = name.match(regex);\n if (match) {\n name = match[1].replace(/[\"']/g, '');\n }\n }\n try {\n const federation = ${RuntimeGlobals.require}.federation;\n const res = await ${RuntimeGlobals.require}.federation.runtime.loadScriptNode(url, { attrs: {} });\n const enhancedRemote = federation.instance.initRawContainer(name, url, res);\n // use normal global assignment\n if(!usesInternalRef && !globalThis[name]) {\n globalThis[name] = enhancedRemote\n }\n callback(enhancedRemote);\n } catch (error) {\n callback(error);\n }\n\n }`,\n `executeLoad(url, callback, chunkId);`,\n ]),\n ],\n )}`,\n ]);\n}\nexport function generateInstallChunk(\n runtimeTemplate: any,\n withOnChunkLoad: boolean,\n): string {\n return `var installChunk = ${runtimeTemplate.basicFunction('chunk', [\n 'var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;',\n 'for(var moduleId in moreModules) {',\n Template.indent([\n `if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`,\n Template.indent([\n `${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];`,\n ]),\n '}',\n ]),\n '}',\n 'if(runtime) runtime(__webpack_require__);',\n 'for(var i = 0; i < chunkIds.length; i++) {',\n Template.indent([\n 'if(installedChunks[chunkIds[i]]) {',\n Template.indent(['installedChunks[chunkIds[i]][0]();']),\n '}',\n 'installedChunks[chunkIds[i]] = 0;',\n ]),\n '}',\n withOnChunkLoad ? `${RuntimeGlobals.onChunksLoaded}();` : '',\n ])};`;\n}\nexport function generateExternalInstallChunkCode(\n withExternalInstallChunk: boolean,\n debug: boolean | undefined,\n): string {\n if (!withExternalInstallChunk) {\n return '// no external install chunk';\n }\n\n return Template.asString([\n 'module.exports = __webpack_require__;',\n `${RuntimeGlobals.externalInstallChunk} = function(){`,\n debug\n ? `console.debug('node: webpack installing to install chunk id:', arguments['0'].id);`\n : '',\n `return installChunk.apply(this, arguments)};`,\n ]);\n}\n"],"mappings":";;;;;AACA,MAAM,EAAE,gBAAgB,aAAa,gFACd,UAAU,CAChC;;;;;;;AASD,SAAgB,gBACd,SACA,eACQ;AACR,KAAI,CAAC,QACH,QAAO;AAGT,QAAO,SAAS,SAAS;EAEvB;EACA,SAAS,OAAO;GACd;GACA,SAAS,OAAO;IAEd,kDAAkD,KAAK,UACrD,cACD,CAAC,KAAK,eAAe,6BAA6B;IAEnD;IACA,SAAS,OAAO;KACd;KACA;KAEA;KAEA;KACA;KAEA;KACA,SAAS,OAAO;MACd,MAAM,eAAe,eAAe;MACpC,SAAS,OAAO,CACd,uDACA,4DACD,CAAC;MACF;MACD,CAAC;KACF;KACA;KACA;KACD,CAAC;IACF;IACD,CAAC;GACF;GACD,CAAC;EACF;EACA;EAEA,SAAS,mBAEP,QAAQ,4DAA4D,CACrE,CACE,QAAQ,YAAY,aAAa,CACjC,QAAQ,wBAAwB,kBAAkB,CAClD,QAAQ,wBAAwB,kBAAkB,CAClD,QAAQ,oBAAoB,eAAe,YAAY,CACvD,QAAQ,wBAAwB,eAAe,gBAAgB,CAC/D,QAAQ,4BAA4B,eAAe,oBAAoB,CACvE,QAAQ,uBAAuB,eAAe,eAAe,CAC7D,QAAQ,sBAAsB,eAAe,cAAc,CAC3D,QACC,kCACA,eAAe,0BAChB,CACA,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