@module-federation/nextjs-mf 5.5.1 → 5.6.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.
Files changed (143) hide show
  1. package/README.md +1 -27
  2. package/{lib/client → client}/CombinedPages.d.ts +27 -28
  3. package/client/CombinedPages.js +38 -0
  4. package/client/CombinedPages.js.map +1 -0
  5. package/{lib/client → client}/MFClient.d.ts +72 -73
  6. package/client/MFClient.js +159 -0
  7. package/client/MFClient.js.map +1 -0
  8. package/{lib/client → client}/RemoteContainer.d.ts +46 -58
  9. package/client/RemoteContainer.js +121 -0
  10. package/client/RemoteContainer.js.map +1 -0
  11. package/{lib/client → client}/RemotePages.d.ts +49 -49
  12. package/client/RemotePages.js +138 -0
  13. package/client/RemotePages.js.map +1 -0
  14. package/{lib/client → client}/UrlNode.d.ts +17 -18
  15. package/{lib/client → client}/UrlNode.js +157 -161
  16. package/client/UrlNode.js.map +1 -0
  17. package/{lib/client → client}/helpers.d.ts +16 -17
  18. package/{lib/client → client}/helpers.js +90 -104
  19. package/client/helpers.js.map +1 -0
  20. package/client/index.d.ts +2 -0
  21. package/client/index.js +6 -0
  22. package/client/index.js.map +1 -0
  23. package/{lib/client → client}/useMFClient.d.ts +24 -25
  24. package/client/useMFClient.js +55 -0
  25. package/client/useMFClient.js.map +1 -0
  26. package/{lib/client → client}/useMFRemote.d.ts +16 -17
  27. package/client/useMFRemote.js +50 -0
  28. package/client/useMFRemote.js.map +1 -0
  29. package/jest.config.d.ts +13 -0
  30. package/jest.config.js +18 -0
  31. package/jest.config.js.map +1 -0
  32. package/package.json +19 -42
  33. package/src/include-defaults.d.ts +0 -0
  34. package/{lib → src}/include-defaults.js +4 -3
  35. package/src/include-defaults.js.map +1 -0
  36. package/src/index.d.ts +3 -0
  37. package/src/index.js +9 -0
  38. package/src/index.js.map +1 -0
  39. package/src/internal.d.ts +12 -0
  40. package/src/internal.js +260 -0
  41. package/src/internal.js.map +1 -0
  42. package/src/loaders/fixImageLoader.d.ts +16 -0
  43. package/src/loaders/fixImageLoader.js +53 -0
  44. package/src/loaders/fixImageLoader.js.map +1 -0
  45. package/src/loaders/fixUrlLoader.d.ts +13 -0
  46. package/src/loaders/fixUrlLoader.js +25 -0
  47. package/src/loaders/fixUrlLoader.js.map +1 -0
  48. package/src/loaders/helpers.d.ts +10 -0
  49. package/src/loaders/helpers.js +46 -0
  50. package/src/loaders/helpers.js.map +1 -0
  51. package/src/loaders/nextPageMapLoader.d.ts +15 -0
  52. package/src/loaders/nextPageMapLoader.js +151 -0
  53. package/src/loaders/nextPageMapLoader.js.map +1 -0
  54. package/src/loaders/patchNextClientPageLoader.d.ts +7 -0
  55. package/src/loaders/patchNextClientPageLoader.js +43 -0
  56. package/src/loaders/patchNextClientPageLoader.js.map +1 -0
  57. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +5 -0
  58. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +19 -0
  59. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -0
  60. package/src/plugins/ChildFederationPlugin.d.ts +9 -0
  61. package/src/plugins/ChildFederationPlugin.js +281 -0
  62. package/src/plugins/ChildFederationPlugin.js.map +1 -0
  63. package/src/plugins/DevHmrFixInvalidPongPlugin.d.ts +11 -0
  64. package/src/plugins/DevHmrFixInvalidPongPlugin.js +55 -0
  65. package/src/plugins/DevHmrFixInvalidPongPlugin.js.map +1 -0
  66. package/src/plugins/ModuleFederationPlugin.d.ts +7 -0
  67. package/src/plugins/ModuleFederationPlugin.js +50 -0
  68. package/src/plugins/ModuleFederationPlugin.js.map +1 -0
  69. package/src/plugins/NextFederationPlugin.d.ts +9 -0
  70. package/src/plugins/NextFederationPlugin.js +111 -0
  71. package/src/plugins/NextFederationPlugin.js.map +1 -0
  72. package/src/plugins/RemoveRRRuntimePlugin.d.ts +5 -0
  73. package/src/plugins/RemoveRRRuntimePlugin.js +39 -0
  74. package/src/plugins/RemoveRRRuntimePlugin.js.map +1 -0
  75. package/utils/Template.d.ts +148 -0
  76. package/utils/Template.js +381 -0
  77. package/utils/Template.js.map +1 -0
  78. package/utils/build-utils.d.ts +3 -0
  79. package/utils/build-utils.js +175 -0
  80. package/utils/build-utils.js.map +1 -0
  81. package/utils/index.d.ts +1 -0
  82. package/utils/index.js +7 -0
  83. package/utils/index.js.map +1 -0
  84. package/.prettierignore +0 -2
  85. package/.prettierrc +0 -7
  86. package/LICENSE +0 -21
  87. package/lib/ModuleFederationPlugin.js +0 -84
  88. package/lib/NextFederationPlugin.js +0 -513
  89. package/lib/_virtual/Template.js +0 -7
  90. package/lib/_virtual/UrlNode.js +0 -9
  91. package/lib/_virtual/_commonjsHelpers.js +0 -44
  92. package/lib/_virtual/_fast-glob.js +0 -16
  93. package/lib/_virtual/_fs.js +0 -16
  94. package/lib/_virtual/_path.js +0 -16
  95. package/lib/_virtual/_tslib.js +0 -277
  96. package/lib/_virtual/_webpack-sources.js +0 -16
  97. package/lib/_virtual/fs.js +0 -4
  98. package/lib/_virtual/fs2.js +0 -7
  99. package/lib/_virtual/helpers.js +0 -7
  100. package/lib/_virtual/nextPageMapLoader.js +0 -7
  101. package/lib/_virtual/options.js +0 -7
  102. package/lib/_virtual/utils.js +0 -7
  103. package/lib/build-utils.js +0 -176
  104. package/lib/client/CombinedPages.d.ts.map +0 -1
  105. package/lib/client/CombinedPages.js +0 -60
  106. package/lib/client/MFClient.d.ts.map +0 -1
  107. package/lib/client/MFClient.js +0 -213
  108. package/lib/client/RemoteContainer.d.ts.map +0 -1
  109. package/lib/client/RemoteContainer.js +0 -162
  110. package/lib/client/RemotePages.d.ts.map +0 -1
  111. package/lib/client/RemotePages.js +0 -194
  112. package/lib/client/UrlNode.d.ts.map +0 -1
  113. package/lib/client/helpers.d.ts.map +0 -1
  114. package/lib/client/useMFClient.d.ts.map +0 -1
  115. package/lib/client/useMFClient.js +0 -79
  116. package/lib/client/useMFRemote.d.ts.map +0 -1
  117. package/lib/client/useMFRemote.js +0 -72
  118. package/lib/dependencies/webpack/lib/Template.js +0 -437
  119. package/lib/dependencies/webpack/lib/container/options.js +0 -102
  120. package/lib/dependencies/webpack/lib/sharing/utils.js +0 -104
  121. package/lib/dependencies/webpack/lib/util/fs.js +0 -359
  122. package/lib/index.js +0 -3
  123. package/lib/internal.js +0 -271
  124. package/lib/loaders/UrlNode.js +0 -219
  125. package/lib/loaders/fixImageLoader.js +0 -65
  126. package/lib/loaders/fixUrlLoader.js +0 -25
  127. package/lib/loaders/helpers.js +0 -60
  128. package/lib/loaders/nextPageMapLoader.js +0 -200
  129. package/lib/loaders/patchNextClientPageLoader.js +0 -53
  130. package/lib/node-plugin/streaming/CommonJsChunkLoadingPlugin.js +0 -94
  131. package/lib/node-plugin/streaming/LoadFileChunkLoadingRuntimeModule.js +0 -414
  132. package/lib/node-plugin/streaming/index.js +0 -46
  133. package/lib/node-plugin/streaming/loadScript.js +0 -59
  134. package/lib/plugins/DevHmrFixInvalidPongPlugin.js +0 -82
  135. package/lib/utils.js +0 -125
  136. package/node-plugin/README.md +0 -27
  137. package/node-plugin/package.json +0 -4
  138. package/node-plugin/streaming/CommonJsChunkLoadingPlugin.js +0 -89
  139. package/node-plugin/streaming/LoadFileChunkLoadingRuntimeModule.js +0 -410
  140. package/node-plugin/streaming/NodeRuntime.js +0 -245
  141. package/node-plugin/streaming/index.js +0 -42
  142. package/node-plugin/streaming/loadScript.js +0 -51
  143. package/tsconfig.json +0 -33
@@ -1,72 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('../_virtual/_tslib.js');
6
- var React = require('react');
7
- var RemoteContainer = require('./RemoteContainer.js');
8
-
9
- function _interopNamespace(e) {
10
- if (e && e.__esModule) return e;
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n["default"] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
-
29
- var isBrowser = typeof window !== 'undefined';
30
- /**
31
- * React hook which provides an access to RemoteContainer in Module Federation
32
- *
33
- * @param global - can be a global variable name OR connection string "global@url"
34
- */
35
- function useMFRemote(global) {
36
- var remote;
37
- if (isBrowser) {
38
- // on client (we get instances from global variable because webpack breaks Singletons)
39
- var MFClient_1 = window.mf_client;
40
- remote = MFClient_1.remotes[global] || MFClient_1.registerRemote(global);
41
- }
42
- else {
43
- // on server side
44
- remote = RemoteContainer.RemoteContainer.createSingleton(global);
45
- }
46
- var _a = _tslib.__read(React__namespace.useState(remote.isLoaded()), 2), loaded = _a[0], setLoaded = _a[1];
47
- var _b = _tslib.__read(React__namespace.useState(remote.error), 2), error = _b[0], setError = _b[1];
48
- React__namespace.useEffect(function () {
49
- var handleLoadComplete = function () {
50
- setLoaded(true);
51
- };
52
- var handleLoadError = function (e) {
53
- setError(e);
54
- };
55
- if (!loaded && remote.isLoaded()) {
56
- handleLoadComplete();
57
- }
58
- remote.events.on('loadComplete', handleLoadComplete);
59
- remote.events.on('loadError', handleLoadError);
60
- return function () {
61
- remote.events.off('loadComplete', handleLoadComplete);
62
- remote.events.off('loadError', handleLoadError);
63
- };
64
- }, [remote]);
65
- return {
66
- remote: remote,
67
- loaded: loaded,
68
- error: error,
69
- };
70
- }
71
-
72
- exports.useMFRemote = useMFRemote;
@@ -1,437 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('../../../_virtual/_commonjsHelpers.js');
6
- var Template$1 = require('../../../_virtual/Template.js');
7
- require('../../../_virtual/_webpack-sources.js');
8
- var require$$0 = require('webpack-sources');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
-
12
- var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
13
-
14
- /*
15
- MIT License http://www.opensource.org/licenses/mit-license.php
16
- Author Tobias Koppers @sokra
17
- */
18
-
19
- (function (module) {
20
- "use strict";
21
-
22
- const { ConcatSource, PrefixSource } = require$$0__default["default"];
23
-
24
- /** @typedef {import("webpack-sources").Source} Source */
25
- /** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
26
- /** @typedef {import("./Chunk")} Chunk */
27
- /** @typedef {import("./ChunkGraph")} ChunkGraph */
28
- /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
29
- /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
30
- /** @typedef {import("./Compilation").PathData} PathData */
31
- /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
32
- /** @typedef {import("./Module")} Module */
33
- /** @typedef {import("./ModuleGraph")} ModuleGraph */
34
- /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
35
- /** @typedef {import("./RuntimeModule")} RuntimeModule */
36
- /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
37
- /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
38
- /** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
39
-
40
- const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
41
- const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
42
- const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
43
- const NUMBER_OF_IDENTIFIER_START_CHARS = DELTA_A_TO_Z * 2 + 2; // a-z A-Z _ $
44
- const NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
45
- NUMBER_OF_IDENTIFIER_START_CHARS + 10; // a-z A-Z _ $ 0-9
46
- const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g;
47
- const INDENT_MULTILINE_REGEX = /^\t/gm;
48
- const LINE_SEPARATOR_REGEX = /\r?\n/g;
49
- const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-zA-Z$_])/;
50
- const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$]+/g;
51
- const COMMENT_END_REGEX = /\*\//g;
52
- const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
53
- const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
54
-
55
- /**
56
- * @typedef {Object} RenderManifestOptions
57
- * @property {Chunk} chunk the chunk used to render
58
- * @property {string} hash
59
- * @property {string} fullHash
60
- * @property {OutputOptions} outputOptions
61
- * @property {CodeGenerationResults} codeGenerationResults
62
- * @property {{javascript: ModuleTemplate}} moduleTemplates
63
- * @property {DependencyTemplates} dependencyTemplates
64
- * @property {RuntimeTemplate} runtimeTemplate
65
- * @property {ModuleGraph} moduleGraph
66
- * @property {ChunkGraph} chunkGraph
67
- */
68
-
69
- /** @typedef {RenderManifestEntryTemplated | RenderManifestEntryStatic} RenderManifestEntry */
70
-
71
- /**
72
- * @typedef {Object} RenderManifestEntryTemplated
73
- * @property {function(): Source} render
74
- * @property {string | function(PathData, AssetInfo=): string} filenameTemplate
75
- * @property {PathData=} pathOptions
76
- * @property {AssetInfo=} info
77
- * @property {string} identifier
78
- * @property {string=} hash
79
- * @property {boolean=} auxiliary
80
- */
81
-
82
- /**
83
- * @typedef {Object} RenderManifestEntryStatic
84
- * @property {function(): Source} render
85
- * @property {string} filename
86
- * @property {AssetInfo} info
87
- * @property {string} identifier
88
- * @property {string=} hash
89
- * @property {boolean=} auxiliary
90
- */
91
-
92
- /**
93
- * @typedef {Object} HasId
94
- * @property {number | string} id
95
- */
96
-
97
- /**
98
- * @typedef {function(Module, number): boolean} ModuleFilterPredicate
99
- */
100
-
101
- class Template {
102
- /**
103
- *
104
- * @param {Function} fn a runtime function (.runtime.js) "template"
105
- * @returns {string} the updated and normalized function string
106
- */
107
- static getFunctionContent(fn) {
108
- return fn
109
- .toString()
110
- .replace(FUNCTION_CONTENT_REGEX, "")
111
- .replace(INDENT_MULTILINE_REGEX, "")
112
- .replace(LINE_SEPARATOR_REGEX, "\n");
113
- }
114
-
115
- /**
116
- * @param {string} str the string converted to identifier
117
- * @returns {string} created identifier
118
- */
119
- static toIdentifier(str) {
120
- if (typeof str !== "string") return "";
121
- return str
122
- .replace(IDENTIFIER_NAME_REPLACE_REGEX, "_$1")
123
- .replace(IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX, "_");
124
- }
125
- /**
126
- *
127
- * @param {string} str string to be converted to commented in bundle code
128
- * @returns {string} returns a commented version of string
129
- */
130
- static toComment(str) {
131
- if (!str) return "";
132
- return `/*! ${str.replace(COMMENT_END_REGEX, "* /")} */`;
133
- }
134
-
135
- /**
136
- *
137
- * @param {string} str string to be converted to "normal comment"
138
- * @returns {string} returns a commented version of string
139
- */
140
- static toNormalComment(str) {
141
- if (!str) return "";
142
- return `/* ${str.replace(COMMENT_END_REGEX, "* /")} */`;
143
- }
144
-
145
- /**
146
- * @param {string} str string path to be normalized
147
- * @returns {string} normalized bundle-safe path
148
- */
149
- static toPath(str) {
150
- if (typeof str !== "string") return "";
151
- return str
152
- .replace(PATH_NAME_NORMALIZE_REPLACE_REGEX, "-")
153
- .replace(MATCH_PADDED_HYPHENS_REPLACE_REGEX, "");
154
- }
155
-
156
- // map number to a single character a-z, A-Z or multiple characters if number is too big
157
- /**
158
- * @param {number} n number to convert to ident
159
- * @returns {string} returns single character ident
160
- */
161
- static numberToIdentifier(n) {
162
- if (n >= NUMBER_OF_IDENTIFIER_START_CHARS) {
163
- // use multiple letters
164
- return (
165
- Template.numberToIdentifier(n % NUMBER_OF_IDENTIFIER_START_CHARS) +
166
- Template.numberToIdentifierContinuation(
167
- Math.floor(n / NUMBER_OF_IDENTIFIER_START_CHARS)
168
- )
169
- );
170
- }
171
-
172
- // lower case
173
- if (n < DELTA_A_TO_Z) {
174
- return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
175
- }
176
- n -= DELTA_A_TO_Z;
177
-
178
- // upper case
179
- if (n < DELTA_A_TO_Z) {
180
- return String.fromCharCode(START_UPPERCASE_ALPHABET_CODE + n);
181
- }
182
-
183
- if (n === DELTA_A_TO_Z) return "_";
184
- return "$";
185
- }
186
-
187
- /**
188
- * @param {number} n number to convert to ident
189
- * @returns {string} returns single character ident
190
- */
191
- static numberToIdentifierContinuation(n) {
192
- if (n >= NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS) {
193
- // use multiple letters
194
- return (
195
- Template.numberToIdentifierContinuation(
196
- n % NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS
197
- ) +
198
- Template.numberToIdentifierContinuation(
199
- Math.floor(n / NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS)
200
- )
201
- );
202
- }
203
-
204
- // lower case
205
- if (n < DELTA_A_TO_Z) {
206
- return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
207
- }
208
- n -= DELTA_A_TO_Z;
209
-
210
- // upper case
211
- if (n < DELTA_A_TO_Z) {
212
- return String.fromCharCode(START_UPPERCASE_ALPHABET_CODE + n);
213
- }
214
- n -= DELTA_A_TO_Z;
215
-
216
- // numbers
217
- if (n < 10) {
218
- return `${n}`;
219
- }
220
-
221
- if (n === 10) return "_";
222
- return "$";
223
- }
224
-
225
- /**
226
- *
227
- * @param {string | string[]} s string to convert to identity
228
- * @returns {string} converted identity
229
- */
230
- static indent(s) {
231
- if (Array.isArray(s)) {
232
- return s.map(Template.indent).join("\n");
233
- } else {
234
- const str = s.trimRight();
235
- if (!str) return "";
236
- const ind = str[0] === "\n" ? "" : "\t";
237
- return ind + str.replace(/\n([^\n])/g, "\n\t$1");
238
- }
239
- }
240
-
241
- /**
242
- *
243
- * @param {string|string[]} s string to create prefix for
244
- * @param {string} prefix prefix to compose
245
- * @returns {string} returns new prefix string
246
- */
247
- static prefix(s, prefix) {
248
- const str = Template.asString(s).trim();
249
- if (!str) return "";
250
- const ind = str[0] === "\n" ? "" : prefix;
251
- return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
252
- }
253
-
254
- /**
255
- *
256
- * @param {string|string[]} str string or string collection
257
- * @returns {string} returns a single string from array
258
- */
259
- static asString(str) {
260
- if (Array.isArray(str)) {
261
- return str.join("\n");
262
- }
263
- return str;
264
- }
265
-
266
- /**
267
- * @typedef {Object} WithId
268
- * @property {string|number} id
269
- */
270
-
271
- /**
272
- * @param {WithId[]} modules a collection of modules to get array bounds for
273
- * @returns {[number, number] | false} returns the upper and lower array bounds
274
- * or false if not every module has a number based id
275
- */
276
- static getModulesArrayBounds(modules) {
277
- let maxId = -Infinity;
278
- let minId = Infinity;
279
- for (const module of modules) {
280
- const moduleId = module.id;
281
- if (typeof moduleId !== "number") return false;
282
- if (maxId < moduleId) maxId = moduleId;
283
- if (minId > moduleId) minId = moduleId;
284
- }
285
- if (minId < 16 + ("" + minId).length) {
286
- // add minId x ',' instead of 'Array(minId).concat(…)'
287
- minId = 0;
288
- }
289
- // start with -1 because the first module needs no comma
290
- let objectOverhead = -1;
291
- for (const module of modules) {
292
- // module id + colon + comma
293
- objectOverhead += `${module.id}`.length + 2;
294
- }
295
- // number of commas, or when starting non-zero the length of Array(minId).concat()
296
- const arrayOverhead = minId === 0 ? maxId : 16 + `${minId}`.length + maxId;
297
- return arrayOverhead < objectOverhead ? [minId, maxId] : false;
298
- }
299
-
300
- /**
301
- * @param {ChunkRenderContext} renderContext render context
302
- * @param {Module[]} modules modules to render (should be ordered by identifier)
303
- * @param {function(Module): Source} renderModule function to render a module
304
- * @param {string=} prefix applying prefix strings
305
- * @returns {Source} rendered chunk modules in a Source object
306
- */
307
- static renderChunkModules(renderContext, modules, renderModule, prefix = "") {
308
- const { chunkGraph } = renderContext;
309
- var source = new ConcatSource();
310
- if (modules.length === 0) {
311
- return null;
312
- }
313
- /** @type {{id: string|number, source: Source|string}[]} */
314
- const allModules = modules.map(module => {
315
- return {
316
- id: chunkGraph.getModuleId(module),
317
- source: renderModule(module) || "false"
318
- };
319
- });
320
- const bounds = Template.getModulesArrayBounds(allModules);
321
- if (bounds) {
322
- // Render a spare array
323
- const minId = bounds[0];
324
- const maxId = bounds[1];
325
- if (minId !== 0) {
326
- source.add(`Array(${minId}).concat(`);
327
- }
328
- source.add("[\n");
329
- /** @type {Map<string|number, {id: string|number, source: Source|string}>} */
330
- const modules = new Map();
331
- for (const module of allModules) {
332
- modules.set(module.id, module);
333
- }
334
- for (let idx = minId; idx <= maxId; idx++) {
335
- const module = modules.get(idx);
336
- if (idx !== minId) {
337
- source.add(",\n");
338
- }
339
- source.add(`/* ${idx} */`);
340
- if (module) {
341
- source.add("\n");
342
- source.add(module.source);
343
- }
344
- }
345
- source.add("\n" + prefix + "]");
346
- if (minId !== 0) {
347
- source.add(")");
348
- }
349
- } else {
350
- // Render an object
351
- source.add("{\n");
352
- for (let i = 0; i < allModules.length; i++) {
353
- const module = allModules[i];
354
- if (i !== 0) {
355
- source.add(",\n");
356
- }
357
- source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`);
358
- source.add(module.source);
359
- }
360
- source.add(`\n\n${prefix}}`);
361
- }
362
- return source;
363
- }
364
-
365
- /**
366
- * @param {RuntimeModule[]} runtimeModules array of runtime modules in order
367
- * @param {RenderContext & { codeGenerationResults?: CodeGenerationResults }} renderContext render context
368
- * @returns {Source} rendered runtime modules in a Source object
369
- */
370
- static renderRuntimeModules(runtimeModules, renderContext) {
371
- const source = new ConcatSource();
372
- for (const module of runtimeModules) {
373
- const codeGenerationResults = renderContext.codeGenerationResults;
374
- let runtimeSource;
375
- if (codeGenerationResults) {
376
- runtimeSource = codeGenerationResults.getSource(
377
- module,
378
- renderContext.chunk.runtime,
379
- "runtime"
380
- );
381
- } else {
382
- const codeGenResult = module.codeGeneration({
383
- chunkGraph: renderContext.chunkGraph,
384
- dependencyTemplates: renderContext.dependencyTemplates,
385
- moduleGraph: renderContext.moduleGraph,
386
- runtimeTemplate: renderContext.runtimeTemplate,
387
- runtime: renderContext.chunk.runtime
388
- });
389
- if (!codeGenResult) continue;
390
- runtimeSource = codeGenResult.sources.get("runtime");
391
- }
392
- if (runtimeSource) {
393
- source.add(Template.toNormalComment(module.identifier()) + "\n");
394
- if (!module.shouldIsolate()) {
395
- source.add(runtimeSource);
396
- source.add("\n\n");
397
- } else if (renderContext.runtimeTemplate.supportsArrowFunction()) {
398
- source.add("(() => {\n");
399
- source.add(new PrefixSource("\t", runtimeSource));
400
- source.add("\n})();\n\n");
401
- } else {
402
- source.add("!function() {\n");
403
- source.add(new PrefixSource("\t", runtimeSource));
404
- source.add("\n}();\n\n");
405
- }
406
- }
407
- }
408
- return source;
409
- }
410
-
411
- /**
412
- * @param {RuntimeModule[]} runtimeModules array of runtime modules in order
413
- * @param {RenderContext} renderContext render context
414
- * @returns {Source} rendered chunk runtime modules in a Source object
415
- */
416
- static renderChunkRuntimeModules(runtimeModules, renderContext) {
417
- return new PrefixSource(
418
- "/******/ ",
419
- new ConcatSource(
420
- "function(__webpack_require__) { // webpackRuntimeModules\n",
421
- this.renderRuntimeModules(runtimeModules, renderContext),
422
- "}\n"
423
- )
424
- );
425
- }
426
- }
427
-
428
- module.exports = Template;
429
- module.exports.NUMBER_OF_IDENTIFIER_START_CHARS =
430
- NUMBER_OF_IDENTIFIER_START_CHARS;
431
- module.exports.NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
432
- NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS;
433
- } (Template$1.Template));
434
-
435
- var Template = Template$1.Template.exports;
436
-
437
- exports["default"] = Template;
@@ -1,102 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('../../../../_virtual/_commonjsHelpers.js');
6
- var options = require('../../../../_virtual/options.js');
7
-
8
- /*
9
- MIT License http://www.opensource.org/licenses/mit-license.php
10
- Author Tobias Koppers @sokra
11
- */
12
-
13
- "use strict";
14
-
15
- /** @template T @typedef {(string | Record<string, string | string[] | T>)[] | Record<string, string | string[] | T>} ContainerOptionsFormat */
16
-
17
- /**
18
- * @template T
19
- * @template N
20
- * @param {ContainerOptionsFormat<T>} options options passed by the user
21
- * @param {function(string | string[], string) : N} normalizeSimple normalize a simple item
22
- * @param {function(T, string) : N} normalizeOptions normalize a complex item
23
- * @param {function(string, N): void} fn processing function
24
- * @returns {void}
25
- */
26
- const process = (options, normalizeSimple, normalizeOptions, fn) => {
27
- const array = items => {
28
- for (const item of items) {
29
- if (typeof item === "string") {
30
- fn(item, normalizeSimple(item, item));
31
- } else if (item && typeof item === "object") {
32
- object(item);
33
- } else {
34
- throw new Error("Unexpected options format");
35
- }
36
- }
37
- };
38
- const object = obj => {
39
- for (const [key, value] of Object.entries(obj)) {
40
- if (typeof value === "string" || Array.isArray(value)) {
41
- fn(key, normalizeSimple(value, key));
42
- } else {
43
- fn(key, normalizeOptions(value, key));
44
- }
45
- }
46
- };
47
- if (!options) {
48
- return;
49
- } else if (Array.isArray(options)) {
50
- array(options);
51
- } else if (typeof options === "object") {
52
- object(options);
53
- } else {
54
- throw new Error("Unexpected options format");
55
- }
56
- };
57
-
58
- /**
59
- * @template T
60
- * @template R
61
- * @param {ContainerOptionsFormat<T>} options options passed by the user
62
- * @param {function(string | string[], string) : R} normalizeSimple normalize a simple item
63
- * @param {function(T, string) : R} normalizeOptions normalize a complex item
64
- * @returns {[string, R][]} parsed options
65
- */
66
- const parseOptions = (options, normalizeSimple, normalizeOptions) => {
67
- /** @type {[string, R][]} */
68
- const items = [];
69
- process(options, normalizeSimple, normalizeOptions, (key, value) => {
70
- items.push([key, value]);
71
- });
72
- return items;
73
- };
74
-
75
- /**
76
- * @template T
77
- * @param {string} scope scope name
78
- * @param {ContainerOptionsFormat<T>} options options passed by the user
79
- * @returns {Record<string, string | string[] | T>} options to spread or pass
80
- */
81
- const scope = (scope, options) => {
82
- /** @type {Record<string, string | string[] | T>} */
83
- const obj = {};
84
- process(
85
- options,
86
- item => /** @type {string | string[] | T} */ (item),
87
- item => /** @type {string | string[] | T} */ (item),
88
- (key, value) => {
89
- obj[
90
- key.startsWith("./") ? `${scope}${key.slice(1)}` : `${scope}/${key}`
91
- ] = value;
92
- }
93
- );
94
- return obj;
95
- };
96
-
97
- var parseOptions_1 = options.__exports.parseOptions = parseOptions;
98
- var scope_1 = options.__exports.scope = scope;
99
-
100
- exports["default"] = options.__exports;
101
- exports.parseOptions = parseOptions_1;
102
- exports.scope = scope_1;