webpack 4.8.2 → 4.9.2

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 (57) hide show
  1. package/README.md +95 -52
  2. package/bin/webpack.js +128 -43
  3. package/lib/AmdMainTemplatePlugin.js +10 -0
  4. package/lib/AsyncDependencyToInitialChunkError.js +12 -2
  5. package/lib/BannerPlugin.js +115 -101
  6. package/lib/CaseSensitiveModulesWarning.js +20 -2
  7. package/lib/Chunk.js +1 -0
  8. package/lib/ChunkGroup.js +465 -465
  9. package/lib/ChunkRenderError.js +8 -0
  10. package/lib/ChunkTemplate.js +71 -71
  11. package/lib/Compilation.js +1 -1
  12. package/lib/Compiler.js +2 -1
  13. package/lib/ContextModule.js +8 -8
  14. package/lib/DllPlugin.js +3 -1
  15. package/lib/DllReferencePlugin.js +2 -1
  16. package/lib/Entrypoint.js +54 -54
  17. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
  18. package/lib/ExportPropertyMainTemplatePlugin.js +13 -0
  19. package/lib/Generator.js +52 -52
  20. package/lib/HotModuleReplacement.runtime.js +633 -633
  21. package/lib/JsonParser.js +2 -1
  22. package/lib/LibManifestPlugin.js +9 -0
  23. package/lib/LibraryTemplatePlugin.js +66 -33
  24. package/lib/MainTemplate.js +468 -468
  25. package/lib/Module.js +3 -3
  26. package/lib/ModuleDependencyError.js +12 -2
  27. package/lib/NormalModuleFactory.js +5 -3
  28. package/lib/Parser.js +27 -23
  29. package/lib/ProgressPlugin.js +1 -1
  30. package/lib/RecordIdsPlugin.js +3 -1
  31. package/lib/RuntimeTemplate.js +1 -1
  32. package/lib/SetVarMainTemplatePlugin.js +12 -0
  33. package/lib/SourceMapDevToolPlugin.js +11 -13
  34. package/lib/Template.js +289 -290
  35. package/lib/UmdMainTemplatePlugin.js +67 -32
  36. package/lib/WebpackError.js +8 -2
  37. package/lib/compareLocations.js +20 -0
  38. package/lib/debug/ProfilingPlugin.js +416 -416
  39. package/lib/dependencies/ContextDependencyHelpers.js +142 -142
  40. package/lib/dependencies/WebpackMissingModule.js +2 -2
  41. package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -40
  42. package/lib/optimize/RuntimeChunkPlugin.js +9 -5
  43. package/lib/optimize/SplitChunksPlugin.js +195 -124
  44. package/lib/util/Queue.js +46 -46
  45. package/lib/util/SetHelpers.js +48 -48
  46. package/lib/util/SortableSet.js +106 -106
  47. package/lib/util/StackedSetMap.js +128 -128
  48. package/lib/util/cachedMerge.js +13 -0
  49. package/lib/util/identifier.js +5 -0
  50. package/lib/util/objectToMap.js +16 -16
  51. package/lib/wasm/WebAssemblyGenerator.js +280 -280
  52. package/lib/wasm/WebAssemblyParser.js +79 -79
  53. package/lib/web/JsonpMainTemplatePlugin.js +2 -2
  54. package/package.json +21 -17
  55. package/schemas/WebpackOptions.json +12 -1
  56. package/schemas/plugins/BannerPlugin.json +96 -85
  57. package/schemas/plugins/DllPlugin.json +4 -0
@@ -1,633 +1,633 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- /*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
6
- module.exports = function() {
7
- var hotApplyOnUpdate = true;
8
- var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
9
- var hotRequestTimeout = $requestTimeout$;
10
- var hotCurrentModuleData = {};
11
- var hotCurrentChildModule; // eslint-disable-line no-unused-vars
12
- var hotCurrentParents = []; // eslint-disable-line no-unused-vars
13
- var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
14
-
15
- // eslint-disable-next-line no-unused-vars
16
- function hotCreateRequire(moduleId) {
17
- var me = installedModules[moduleId];
18
- if (!me) return $require$;
19
- var fn = function(request) {
20
- if (me.hot.active) {
21
- if (installedModules[request]) {
22
- if (installedModules[request].parents.indexOf(moduleId) === -1)
23
- installedModules[request].parents.push(moduleId);
24
- } else {
25
- hotCurrentParents = [moduleId];
26
- hotCurrentChildModule = request;
27
- }
28
- if (me.children.indexOf(request) === -1) me.children.push(request);
29
- } else {
30
- console.warn(
31
- "[HMR] unexpected require(" +
32
- request +
33
- ") from disposed module " +
34
- moduleId
35
- );
36
- hotCurrentParents = [];
37
- }
38
- return $require$(request);
39
- };
40
- var ObjectFactory = function ObjectFactory(name) {
41
- return {
42
- configurable: true,
43
- enumerable: true,
44
- get: function() {
45
- return $require$[name];
46
- },
47
- set: function(value) {
48
- $require$[name] = value;
49
- }
50
- };
51
- };
52
- for (var name in $require$) {
53
- if (
54
- Object.prototype.hasOwnProperty.call($require$, name) &&
55
- name !== "e"
56
- ) {
57
- Object.defineProperty(fn, name, ObjectFactory(name));
58
- }
59
- }
60
- fn.e = function(chunkId) {
61
- if (hotStatus === "ready") hotSetStatus("prepare");
62
- hotChunksLoading++;
63
- return $require$.e(chunkId).then(finishChunkLoading, function(err) {
64
- finishChunkLoading();
65
- throw err;
66
- });
67
-
68
- function finishChunkLoading() {
69
- hotChunksLoading--;
70
- if (hotStatus === "prepare") {
71
- if (!hotWaitingFilesMap[chunkId]) {
72
- hotEnsureUpdateChunk(chunkId);
73
- }
74
- if (hotChunksLoading === 0 && hotWaitingFiles === 0) {
75
- hotUpdateDownloaded();
76
- }
77
- }
78
- }
79
- };
80
- return fn;
81
- }
82
-
83
- // eslint-disable-next-line no-unused-vars
84
- function hotCreateModule(moduleId) {
85
- var hot = {
86
- // private stuff
87
- _acceptedDependencies: {},
88
- _declinedDependencies: {},
89
- _selfAccepted: false,
90
- _selfDeclined: false,
91
- _disposeHandlers: [],
92
- _main: hotCurrentChildModule !== moduleId,
93
-
94
- // Module API
95
- active: true,
96
- accept: function(dep, callback) {
97
- if (typeof dep === "undefined") hot._selfAccepted = true;
98
- else if (typeof dep === "function") hot._selfAccepted = dep;
99
- else if (typeof dep === "object")
100
- for (var i = 0; i < dep.length; i++)
101
- hot._acceptedDependencies[dep[i]] = callback || function() {};
102
- else hot._acceptedDependencies[dep] = callback || function() {};
103
- },
104
- decline: function(dep) {
105
- if (typeof dep === "undefined") hot._selfDeclined = true;
106
- else if (typeof dep === "object")
107
- for (var i = 0; i < dep.length; i++)
108
- hot._declinedDependencies[dep[i]] = true;
109
- else hot._declinedDependencies[dep] = true;
110
- },
111
- dispose: function(callback) {
112
- hot._disposeHandlers.push(callback);
113
- },
114
- addDisposeHandler: function(callback) {
115
- hot._disposeHandlers.push(callback);
116
- },
117
- removeDisposeHandler: function(callback) {
118
- var idx = hot._disposeHandlers.indexOf(callback);
119
- if (idx >= 0) hot._disposeHandlers.splice(idx, 1);
120
- },
121
-
122
- // Management API
123
- check: hotCheck,
124
- apply: hotApply,
125
- status: function(l) {
126
- if (!l) return hotStatus;
127
- hotStatusHandlers.push(l);
128
- },
129
- addStatusHandler: function(l) {
130
- hotStatusHandlers.push(l);
131
- },
132
- removeStatusHandler: function(l) {
133
- var idx = hotStatusHandlers.indexOf(l);
134
- if (idx >= 0) hotStatusHandlers.splice(idx, 1);
135
- },
136
-
137
- //inherit from previous dispose call
138
- data: hotCurrentModuleData[moduleId]
139
- };
140
- hotCurrentChildModule = undefined;
141
- return hot;
142
- }
143
-
144
- var hotStatusHandlers = [];
145
- var hotStatus = "idle";
146
-
147
- function hotSetStatus(newStatus) {
148
- hotStatus = newStatus;
149
- for (var i = 0; i < hotStatusHandlers.length; i++)
150
- hotStatusHandlers[i].call(null, newStatus);
151
- }
152
-
153
- // while downloading
154
- var hotWaitingFiles = 0;
155
- var hotChunksLoading = 0;
156
- var hotWaitingFilesMap = {};
157
- var hotRequestedFilesMap = {};
158
- var hotAvailableFilesMap = {};
159
- var hotDeferred;
160
-
161
- // The update info
162
- var hotUpdate, hotUpdateNewHash;
163
-
164
- function toModuleId(id) {
165
- var isNumber = +id + "" === id;
166
- return isNumber ? +id : id;
167
- }
168
-
169
- function hotCheck(apply) {
170
- if (hotStatus !== "idle")
171
- throw new Error("check() is only allowed in idle status");
172
- hotApplyOnUpdate = apply;
173
- hotSetStatus("check");
174
- return hotDownloadManifest(hotRequestTimeout).then(function(update) {
175
- if (!update) {
176
- hotSetStatus("idle");
177
- return null;
178
- }
179
- hotRequestedFilesMap = {};
180
- hotWaitingFilesMap = {};
181
- hotAvailableFilesMap = update.c;
182
- hotUpdateNewHash = update.h;
183
-
184
- hotSetStatus("prepare");
185
- var promise = new Promise(function(resolve, reject) {
186
- hotDeferred = {
187
- resolve: resolve,
188
- reject: reject
189
- };
190
- });
191
- hotUpdate = {};
192
- /*foreachInstalledChunks*/
193
- {
194
- // eslint-disable-line no-lone-blocks
195
- /*globals chunkId */
196
- hotEnsureUpdateChunk(chunkId);
197
- }
198
- if (
199
- hotStatus === "prepare" &&
200
- hotChunksLoading === 0 &&
201
- hotWaitingFiles === 0
202
- ) {
203
- hotUpdateDownloaded();
204
- }
205
- return promise;
206
- });
207
- }
208
-
209
- // eslint-disable-next-line no-unused-vars
210
- function hotAddUpdateChunk(chunkId, moreModules) {
211
- if (!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
212
- return;
213
- hotRequestedFilesMap[chunkId] = false;
214
- for (var moduleId in moreModules) {
215
- if (Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
216
- hotUpdate[moduleId] = moreModules[moduleId];
217
- }
218
- }
219
- if (--hotWaitingFiles === 0 && hotChunksLoading === 0) {
220
- hotUpdateDownloaded();
221
- }
222
- }
223
-
224
- function hotEnsureUpdateChunk(chunkId) {
225
- if (!hotAvailableFilesMap[chunkId]) {
226
- hotWaitingFilesMap[chunkId] = true;
227
- } else {
228
- hotRequestedFilesMap[chunkId] = true;
229
- hotWaitingFiles++;
230
- hotDownloadUpdateChunk(chunkId);
231
- }
232
- }
233
-
234
- function hotUpdateDownloaded() {
235
- hotSetStatus("ready");
236
- var deferred = hotDeferred;
237
- hotDeferred = null;
238
- if (!deferred) return;
239
- if (hotApplyOnUpdate) {
240
- // Wrap deferred object in Promise to mark it as a well-handled Promise to
241
- // avoid triggering uncaught exception warning in Chrome.
242
- // See https://bugs.chromium.org/p/chromium/issues/detail?id=465666
243
- Promise.resolve()
244
- .then(function() {
245
- return hotApply(hotApplyOnUpdate);
246
- })
247
- .then(
248
- function(result) {
249
- deferred.resolve(result);
250
- },
251
- function(err) {
252
- deferred.reject(err);
253
- }
254
- );
255
- } else {
256
- var outdatedModules = [];
257
- for (var id in hotUpdate) {
258
- if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
259
- outdatedModules.push(toModuleId(id));
260
- }
261
- }
262
- deferred.resolve(outdatedModules);
263
- }
264
- }
265
-
266
- function hotApply(options) {
267
- if (hotStatus !== "ready")
268
- throw new Error("apply() is only allowed in ready status");
269
- options = options || {};
270
-
271
- var cb;
272
- var i;
273
- var j;
274
- var module;
275
- var moduleId;
276
-
277
- function getAffectedStuff(updateModuleId) {
278
- var outdatedModules = [updateModuleId];
279
- var outdatedDependencies = {};
280
-
281
- var queue = outdatedModules.slice().map(function(id) {
282
- return {
283
- chain: [id],
284
- id: id
285
- };
286
- });
287
- while (queue.length > 0) {
288
- var queueItem = queue.pop();
289
- var moduleId = queueItem.id;
290
- var chain = queueItem.chain;
291
- module = installedModules[moduleId];
292
- if (!module || module.hot._selfAccepted) continue;
293
- if (module.hot._selfDeclined) {
294
- return {
295
- type: "self-declined",
296
- chain: chain,
297
- moduleId: moduleId
298
- };
299
- }
300
- if (module.hot._main) {
301
- return {
302
- type: "unaccepted",
303
- chain: chain,
304
- moduleId: moduleId
305
- };
306
- }
307
- for (var i = 0; i < module.parents.length; i++) {
308
- var parentId = module.parents[i];
309
- var parent = installedModules[parentId];
310
- if (!parent) continue;
311
- if (parent.hot._declinedDependencies[moduleId]) {
312
- return {
313
- type: "declined",
314
- chain: chain.concat([parentId]),
315
- moduleId: moduleId,
316
- parentId: parentId
317
- };
318
- }
319
- if (outdatedModules.indexOf(parentId) !== -1) continue;
320
- if (parent.hot._acceptedDependencies[moduleId]) {
321
- if (!outdatedDependencies[parentId])
322
- outdatedDependencies[parentId] = [];
323
- addAllToSet(outdatedDependencies[parentId], [moduleId]);
324
- continue;
325
- }
326
- delete outdatedDependencies[parentId];
327
- outdatedModules.push(parentId);
328
- queue.push({
329
- chain: chain.concat([parentId]),
330
- id: parentId
331
- });
332
- }
333
- }
334
-
335
- return {
336
- type: "accepted",
337
- moduleId: updateModuleId,
338
- outdatedModules: outdatedModules,
339
- outdatedDependencies: outdatedDependencies
340
- };
341
- }
342
-
343
- function addAllToSet(a, b) {
344
- for (var i = 0; i < b.length; i++) {
345
- var item = b[i];
346
- if (a.indexOf(item) === -1) a.push(item);
347
- }
348
- }
349
-
350
- // at begin all updates modules are outdated
351
- // the "outdated" status can propagate to parents if they don't accept the children
352
- var outdatedDependencies = {};
353
- var outdatedModules = [];
354
- var appliedUpdate = {};
355
-
356
- var warnUnexpectedRequire = function warnUnexpectedRequire() {
357
- console.warn(
358
- "[HMR] unexpected require(" + result.moduleId + ") to disposed module"
359
- );
360
- };
361
-
362
- for (var id in hotUpdate) {
363
- if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
364
- moduleId = toModuleId(id);
365
- /** @type {TODO} */
366
- var result;
367
- if (hotUpdate[id]) {
368
- result = getAffectedStuff(moduleId);
369
- } else {
370
- result = {
371
- type: "disposed",
372
- moduleId: id
373
- };
374
- }
375
- /** @type {Error|false} */
376
- var abortError = false;
377
- var doApply = false;
378
- var doDispose = false;
379
- var chainInfo = "";
380
- if (result.chain) {
381
- chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
382
- }
383
- switch (result.type) {
384
- case "self-declined":
385
- if (options.onDeclined) options.onDeclined(result);
386
- if (!options.ignoreDeclined)
387
- abortError = new Error(
388
- "Aborted because of self decline: " +
389
- result.moduleId +
390
- chainInfo
391
- );
392
- break;
393
- case "declined":
394
- if (options.onDeclined) options.onDeclined(result);
395
- if (!options.ignoreDeclined)
396
- abortError = new Error(
397
- "Aborted because of declined dependency: " +
398
- result.moduleId +
399
- " in " +
400
- result.parentId +
401
- chainInfo
402
- );
403
- break;
404
- case "unaccepted":
405
- if (options.onUnaccepted) options.onUnaccepted(result);
406
- if (!options.ignoreUnaccepted)
407
- abortError = new Error(
408
- "Aborted because " + moduleId + " is not accepted" + chainInfo
409
- );
410
- break;
411
- case "accepted":
412
- if (options.onAccepted) options.onAccepted(result);
413
- doApply = true;
414
- break;
415
- case "disposed":
416
- if (options.onDisposed) options.onDisposed(result);
417
- doDispose = true;
418
- break;
419
- default:
420
- throw new Error("Unexception type " + result.type);
421
- }
422
- if (abortError) {
423
- hotSetStatus("abort");
424
- return Promise.reject(abortError);
425
- }
426
- if (doApply) {
427
- appliedUpdate[moduleId] = hotUpdate[moduleId];
428
- addAllToSet(outdatedModules, result.outdatedModules);
429
- for (moduleId in result.outdatedDependencies) {
430
- if (
431
- Object.prototype.hasOwnProperty.call(
432
- result.outdatedDependencies,
433
- moduleId
434
- )
435
- ) {
436
- if (!outdatedDependencies[moduleId])
437
- outdatedDependencies[moduleId] = [];
438
- addAllToSet(
439
- outdatedDependencies[moduleId],
440
- result.outdatedDependencies[moduleId]
441
- );
442
- }
443
- }
444
- }
445
- if (doDispose) {
446
- addAllToSet(outdatedModules, [result.moduleId]);
447
- appliedUpdate[moduleId] = warnUnexpectedRequire;
448
- }
449
- }
450
- }
451
-
452
- // Store self accepted outdated modules to require them later by the module system
453
- var outdatedSelfAcceptedModules = [];
454
- for (i = 0; i < outdatedModules.length; i++) {
455
- moduleId = outdatedModules[i];
456
- if (
457
- installedModules[moduleId] &&
458
- installedModules[moduleId].hot._selfAccepted
459
- )
460
- outdatedSelfAcceptedModules.push({
461
- module: moduleId,
462
- errorHandler: installedModules[moduleId].hot._selfAccepted
463
- });
464
- }
465
-
466
- // Now in "dispose" phase
467
- hotSetStatus("dispose");
468
- Object.keys(hotAvailableFilesMap).forEach(function(chunkId) {
469
- if (hotAvailableFilesMap[chunkId] === false) {
470
- hotDisposeChunk(chunkId);
471
- }
472
- });
473
-
474
- var idx;
475
- var queue = outdatedModules.slice();
476
- while (queue.length > 0) {
477
- moduleId = queue.pop();
478
- module = installedModules[moduleId];
479
- if (!module) continue;
480
-
481
- var data = {};
482
-
483
- // Call dispose handlers
484
- var disposeHandlers = module.hot._disposeHandlers;
485
- for (j = 0; j < disposeHandlers.length; j++) {
486
- cb = disposeHandlers[j];
487
- cb(data);
488
- }
489
- hotCurrentModuleData[moduleId] = data;
490
-
491
- // disable module (this disables requires from this module)
492
- module.hot.active = false;
493
-
494
- // remove module from cache
495
- delete installedModules[moduleId];
496
-
497
- // when disposing there is no need to call dispose handler
498
- delete outdatedDependencies[moduleId];
499
-
500
- // remove "parents" references from all children
501
- for (j = 0; j < module.children.length; j++) {
502
- var child = installedModules[module.children[j]];
503
- if (!child) continue;
504
- idx = child.parents.indexOf(moduleId);
505
- if (idx >= 0) {
506
- child.parents.splice(idx, 1);
507
- }
508
- }
509
- }
510
-
511
- // remove outdated dependency from module children
512
- var dependency;
513
- var moduleOutdatedDependencies;
514
- for (moduleId in outdatedDependencies) {
515
- if (
516
- Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)
517
- ) {
518
- module = installedModules[moduleId];
519
- if (module) {
520
- moduleOutdatedDependencies = outdatedDependencies[moduleId];
521
- for (j = 0; j < moduleOutdatedDependencies.length; j++) {
522
- dependency = moduleOutdatedDependencies[j];
523
- idx = module.children.indexOf(dependency);
524
- if (idx >= 0) module.children.splice(idx, 1);
525
- }
526
- }
527
- }
528
- }
529
-
530
- // Not in "apply" phase
531
- hotSetStatus("apply");
532
-
533
- hotCurrentHash = hotUpdateNewHash;
534
-
535
- // insert new code
536
- for (moduleId in appliedUpdate) {
537
- if (Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
538
- modules[moduleId] = appliedUpdate[moduleId];
539
- }
540
- }
541
-
542
- // call accept handlers
543
- var error = null;
544
- for (moduleId in outdatedDependencies) {
545
- if (
546
- Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)
547
- ) {
548
- module = installedModules[moduleId];
549
- if (module) {
550
- moduleOutdatedDependencies = outdatedDependencies[moduleId];
551
- var callbacks = [];
552
- for (i = 0; i < moduleOutdatedDependencies.length; i++) {
553
- dependency = moduleOutdatedDependencies[i];
554
- cb = module.hot._acceptedDependencies[dependency];
555
- if (cb) {
556
- if (callbacks.indexOf(cb) !== -1) continue;
557
- callbacks.push(cb);
558
- }
559
- }
560
- for (i = 0; i < callbacks.length; i++) {
561
- cb = callbacks[i];
562
- try {
563
- cb(moduleOutdatedDependencies);
564
- } catch (err) {
565
- if (options.onErrored) {
566
- options.onErrored({
567
- type: "accept-errored",
568
- moduleId: moduleId,
569
- dependencyId: moduleOutdatedDependencies[i],
570
- error: err
571
- });
572
- }
573
- if (!options.ignoreErrored) {
574
- if (!error) error = err;
575
- }
576
- }
577
- }
578
- }
579
- }
580
- }
581
-
582
- // Load self accepted modules
583
- for (i = 0; i < outdatedSelfAcceptedModules.length; i++) {
584
- var item = outdatedSelfAcceptedModules[i];
585
- moduleId = item.module;
586
- hotCurrentParents = [moduleId];
587
- try {
588
- $require$(moduleId);
589
- } catch (err) {
590
- if (typeof item.errorHandler === "function") {
591
- try {
592
- item.errorHandler(err);
593
- } catch (err2) {
594
- if (options.onErrored) {
595
- options.onErrored({
596
- type: "self-accept-error-handler-errored",
597
- moduleId: moduleId,
598
- error: err2,
599
- originalError: err
600
- });
601
- }
602
- if (!options.ignoreErrored) {
603
- if (!error) error = err2;
604
- }
605
- if (!error) error = err;
606
- }
607
- } else {
608
- if (options.onErrored) {
609
- options.onErrored({
610
- type: "self-accept-errored",
611
- moduleId: moduleId,
612
- error: err
613
- });
614
- }
615
- if (!options.ignoreErrored) {
616
- if (!error) error = err;
617
- }
618
- }
619
- }
620
- }
621
-
622
- // handle errors in accept handlers and self accepted module load
623
- if (error) {
624
- hotSetStatus("fail");
625
- return Promise.reject(error);
626
- }
627
-
628
- hotSetStatus("idle");
629
- return new Promise(function(resolve) {
630
- resolve(outdatedModules);
631
- });
632
- }
633
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ /*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
6
+ module.exports = function() {
7
+ var hotApplyOnUpdate = true;
8
+ var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
9
+ var hotRequestTimeout = $requestTimeout$;
10
+ var hotCurrentModuleData = {};
11
+ var hotCurrentChildModule; // eslint-disable-line no-unused-vars
12
+ var hotCurrentParents = []; // eslint-disable-line no-unused-vars
13
+ var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
14
+
15
+ // eslint-disable-next-line no-unused-vars
16
+ function hotCreateRequire(moduleId) {
17
+ var me = installedModules[moduleId];
18
+ if (!me) return $require$;
19
+ var fn = function(request) {
20
+ if (me.hot.active) {
21
+ if (installedModules[request]) {
22
+ if (installedModules[request].parents.indexOf(moduleId) === -1)
23
+ installedModules[request].parents.push(moduleId);
24
+ } else {
25
+ hotCurrentParents = [moduleId];
26
+ hotCurrentChildModule = request;
27
+ }
28
+ if (me.children.indexOf(request) === -1) me.children.push(request);
29
+ } else {
30
+ console.warn(
31
+ "[HMR] unexpected require(" +
32
+ request +
33
+ ") from disposed module " +
34
+ moduleId
35
+ );
36
+ hotCurrentParents = [];
37
+ }
38
+ return $require$(request);
39
+ };
40
+ var ObjectFactory = function ObjectFactory(name) {
41
+ return {
42
+ configurable: true,
43
+ enumerable: true,
44
+ get: function() {
45
+ return $require$[name];
46
+ },
47
+ set: function(value) {
48
+ $require$[name] = value;
49
+ }
50
+ };
51
+ };
52
+ for (var name in $require$) {
53
+ if (
54
+ Object.prototype.hasOwnProperty.call($require$, name) &&
55
+ name !== "e"
56
+ ) {
57
+ Object.defineProperty(fn, name, ObjectFactory(name));
58
+ }
59
+ }
60
+ fn.e = function(chunkId) {
61
+ if (hotStatus === "ready") hotSetStatus("prepare");
62
+ hotChunksLoading++;
63
+ return $require$.e(chunkId).then(finishChunkLoading, function(err) {
64
+ finishChunkLoading();
65
+ throw err;
66
+ });
67
+
68
+ function finishChunkLoading() {
69
+ hotChunksLoading--;
70
+ if (hotStatus === "prepare") {
71
+ if (!hotWaitingFilesMap[chunkId]) {
72
+ hotEnsureUpdateChunk(chunkId);
73
+ }
74
+ if (hotChunksLoading === 0 && hotWaitingFiles === 0) {
75
+ hotUpdateDownloaded();
76
+ }
77
+ }
78
+ }
79
+ };
80
+ return fn;
81
+ }
82
+
83
+ // eslint-disable-next-line no-unused-vars
84
+ function hotCreateModule(moduleId) {
85
+ var hot = {
86
+ // private stuff
87
+ _acceptedDependencies: {},
88
+ _declinedDependencies: {},
89
+ _selfAccepted: false,
90
+ _selfDeclined: false,
91
+ _disposeHandlers: [],
92
+ _main: hotCurrentChildModule !== moduleId,
93
+
94
+ // Module API
95
+ active: true,
96
+ accept: function(dep, callback) {
97
+ if (typeof dep === "undefined") hot._selfAccepted = true;
98
+ else if (typeof dep === "function") hot._selfAccepted = dep;
99
+ else if (typeof dep === "object")
100
+ for (var i = 0; i < dep.length; i++)
101
+ hot._acceptedDependencies[dep[i]] = callback || function() {};
102
+ else hot._acceptedDependencies[dep] = callback || function() {};
103
+ },
104
+ decline: function(dep) {
105
+ if (typeof dep === "undefined") hot._selfDeclined = true;
106
+ else if (typeof dep === "object")
107
+ for (var i = 0; i < dep.length; i++)
108
+ hot._declinedDependencies[dep[i]] = true;
109
+ else hot._declinedDependencies[dep] = true;
110
+ },
111
+ dispose: function(callback) {
112
+ hot._disposeHandlers.push(callback);
113
+ },
114
+ addDisposeHandler: function(callback) {
115
+ hot._disposeHandlers.push(callback);
116
+ },
117
+ removeDisposeHandler: function(callback) {
118
+ var idx = hot._disposeHandlers.indexOf(callback);
119
+ if (idx >= 0) hot._disposeHandlers.splice(idx, 1);
120
+ },
121
+
122
+ // Management API
123
+ check: hotCheck,
124
+ apply: hotApply,
125
+ status: function(l) {
126
+ if (!l) return hotStatus;
127
+ hotStatusHandlers.push(l);
128
+ },
129
+ addStatusHandler: function(l) {
130
+ hotStatusHandlers.push(l);
131
+ },
132
+ removeStatusHandler: function(l) {
133
+ var idx = hotStatusHandlers.indexOf(l);
134
+ if (idx >= 0) hotStatusHandlers.splice(idx, 1);
135
+ },
136
+
137
+ //inherit from previous dispose call
138
+ data: hotCurrentModuleData[moduleId]
139
+ };
140
+ hotCurrentChildModule = undefined;
141
+ return hot;
142
+ }
143
+
144
+ var hotStatusHandlers = [];
145
+ var hotStatus = "idle";
146
+
147
+ function hotSetStatus(newStatus) {
148
+ hotStatus = newStatus;
149
+ for (var i = 0; i < hotStatusHandlers.length; i++)
150
+ hotStatusHandlers[i].call(null, newStatus);
151
+ }
152
+
153
+ // while downloading
154
+ var hotWaitingFiles = 0;
155
+ var hotChunksLoading = 0;
156
+ var hotWaitingFilesMap = {};
157
+ var hotRequestedFilesMap = {};
158
+ var hotAvailableFilesMap = {};
159
+ var hotDeferred;
160
+
161
+ // The update info
162
+ var hotUpdate, hotUpdateNewHash;
163
+
164
+ function toModuleId(id) {
165
+ var isNumber = +id + "" === id;
166
+ return isNumber ? +id : id;
167
+ }
168
+
169
+ function hotCheck(apply) {
170
+ if (hotStatus !== "idle")
171
+ throw new Error("check() is only allowed in idle status");
172
+ hotApplyOnUpdate = apply;
173
+ hotSetStatus("check");
174
+ return hotDownloadManifest(hotRequestTimeout).then(function(update) {
175
+ if (!update) {
176
+ hotSetStatus("idle");
177
+ return null;
178
+ }
179
+ hotRequestedFilesMap = {};
180
+ hotWaitingFilesMap = {};
181
+ hotAvailableFilesMap = update.c;
182
+ hotUpdateNewHash = update.h;
183
+
184
+ hotSetStatus("prepare");
185
+ var promise = new Promise(function(resolve, reject) {
186
+ hotDeferred = {
187
+ resolve: resolve,
188
+ reject: reject
189
+ };
190
+ });
191
+ hotUpdate = {};
192
+ /*foreachInstalledChunks*/
193
+ {
194
+ // eslint-disable-line no-lone-blocks
195
+ /*globals chunkId */
196
+ hotEnsureUpdateChunk(chunkId);
197
+ }
198
+ if (
199
+ hotStatus === "prepare" &&
200
+ hotChunksLoading === 0 &&
201
+ hotWaitingFiles === 0
202
+ ) {
203
+ hotUpdateDownloaded();
204
+ }
205
+ return promise;
206
+ });
207
+ }
208
+
209
+ // eslint-disable-next-line no-unused-vars
210
+ function hotAddUpdateChunk(chunkId, moreModules) {
211
+ if (!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
212
+ return;
213
+ hotRequestedFilesMap[chunkId] = false;
214
+ for (var moduleId in moreModules) {
215
+ if (Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
216
+ hotUpdate[moduleId] = moreModules[moduleId];
217
+ }
218
+ }
219
+ if (--hotWaitingFiles === 0 && hotChunksLoading === 0) {
220
+ hotUpdateDownloaded();
221
+ }
222
+ }
223
+
224
+ function hotEnsureUpdateChunk(chunkId) {
225
+ if (!hotAvailableFilesMap[chunkId]) {
226
+ hotWaitingFilesMap[chunkId] = true;
227
+ } else {
228
+ hotRequestedFilesMap[chunkId] = true;
229
+ hotWaitingFiles++;
230
+ hotDownloadUpdateChunk(chunkId);
231
+ }
232
+ }
233
+
234
+ function hotUpdateDownloaded() {
235
+ hotSetStatus("ready");
236
+ var deferred = hotDeferred;
237
+ hotDeferred = null;
238
+ if (!deferred) return;
239
+ if (hotApplyOnUpdate) {
240
+ // Wrap deferred object in Promise to mark it as a well-handled Promise to
241
+ // avoid triggering uncaught exception warning in Chrome.
242
+ // See https://bugs.chromium.org/p/chromium/issues/detail?id=465666
243
+ Promise.resolve()
244
+ .then(function() {
245
+ return hotApply(hotApplyOnUpdate);
246
+ })
247
+ .then(
248
+ function(result) {
249
+ deferred.resolve(result);
250
+ },
251
+ function(err) {
252
+ deferred.reject(err);
253
+ }
254
+ );
255
+ } else {
256
+ var outdatedModules = [];
257
+ for (var id in hotUpdate) {
258
+ if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
259
+ outdatedModules.push(toModuleId(id));
260
+ }
261
+ }
262
+ deferred.resolve(outdatedModules);
263
+ }
264
+ }
265
+
266
+ function hotApply(options) {
267
+ if (hotStatus !== "ready")
268
+ throw new Error("apply() is only allowed in ready status");
269
+ options = options || {};
270
+
271
+ var cb;
272
+ var i;
273
+ var j;
274
+ var module;
275
+ var moduleId;
276
+
277
+ function getAffectedStuff(updateModuleId) {
278
+ var outdatedModules = [updateModuleId];
279
+ var outdatedDependencies = {};
280
+
281
+ var queue = outdatedModules.slice().map(function(id) {
282
+ return {
283
+ chain: [id],
284
+ id: id
285
+ };
286
+ });
287
+ while (queue.length > 0) {
288
+ var queueItem = queue.pop();
289
+ var moduleId = queueItem.id;
290
+ var chain = queueItem.chain;
291
+ module = installedModules[moduleId];
292
+ if (!module || module.hot._selfAccepted) continue;
293
+ if (module.hot._selfDeclined) {
294
+ return {
295
+ type: "self-declined",
296
+ chain: chain,
297
+ moduleId: moduleId
298
+ };
299
+ }
300
+ if (module.hot._main) {
301
+ return {
302
+ type: "unaccepted",
303
+ chain: chain,
304
+ moduleId: moduleId
305
+ };
306
+ }
307
+ for (var i = 0; i < module.parents.length; i++) {
308
+ var parentId = module.parents[i];
309
+ var parent = installedModules[parentId];
310
+ if (!parent) continue;
311
+ if (parent.hot._declinedDependencies[moduleId]) {
312
+ return {
313
+ type: "declined",
314
+ chain: chain.concat([parentId]),
315
+ moduleId: moduleId,
316
+ parentId: parentId
317
+ };
318
+ }
319
+ if (outdatedModules.indexOf(parentId) !== -1) continue;
320
+ if (parent.hot._acceptedDependencies[moduleId]) {
321
+ if (!outdatedDependencies[parentId])
322
+ outdatedDependencies[parentId] = [];
323
+ addAllToSet(outdatedDependencies[parentId], [moduleId]);
324
+ continue;
325
+ }
326
+ delete outdatedDependencies[parentId];
327
+ outdatedModules.push(parentId);
328
+ queue.push({
329
+ chain: chain.concat([parentId]),
330
+ id: parentId
331
+ });
332
+ }
333
+ }
334
+
335
+ return {
336
+ type: "accepted",
337
+ moduleId: updateModuleId,
338
+ outdatedModules: outdatedModules,
339
+ outdatedDependencies: outdatedDependencies
340
+ };
341
+ }
342
+
343
+ function addAllToSet(a, b) {
344
+ for (var i = 0; i < b.length; i++) {
345
+ var item = b[i];
346
+ if (a.indexOf(item) === -1) a.push(item);
347
+ }
348
+ }
349
+
350
+ // at begin all updates modules are outdated
351
+ // the "outdated" status can propagate to parents if they don't accept the children
352
+ var outdatedDependencies = {};
353
+ var outdatedModules = [];
354
+ var appliedUpdate = {};
355
+
356
+ var warnUnexpectedRequire = function warnUnexpectedRequire() {
357
+ console.warn(
358
+ "[HMR] unexpected require(" + result.moduleId + ") to disposed module"
359
+ );
360
+ };
361
+
362
+ for (var id in hotUpdate) {
363
+ if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
364
+ moduleId = toModuleId(id);
365
+ /** @type {TODO} */
366
+ var result;
367
+ if (hotUpdate[id]) {
368
+ result = getAffectedStuff(moduleId);
369
+ } else {
370
+ result = {
371
+ type: "disposed",
372
+ moduleId: id
373
+ };
374
+ }
375
+ /** @type {Error|false} */
376
+ var abortError = false;
377
+ var doApply = false;
378
+ var doDispose = false;
379
+ var chainInfo = "";
380
+ if (result.chain) {
381
+ chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
382
+ }
383
+ switch (result.type) {
384
+ case "self-declined":
385
+ if (options.onDeclined) options.onDeclined(result);
386
+ if (!options.ignoreDeclined)
387
+ abortError = new Error(
388
+ "Aborted because of self decline: " +
389
+ result.moduleId +
390
+ chainInfo
391
+ );
392
+ break;
393
+ case "declined":
394
+ if (options.onDeclined) options.onDeclined(result);
395
+ if (!options.ignoreDeclined)
396
+ abortError = new Error(
397
+ "Aborted because of declined dependency: " +
398
+ result.moduleId +
399
+ " in " +
400
+ result.parentId +
401
+ chainInfo
402
+ );
403
+ break;
404
+ case "unaccepted":
405
+ if (options.onUnaccepted) options.onUnaccepted(result);
406
+ if (!options.ignoreUnaccepted)
407
+ abortError = new Error(
408
+ "Aborted because " + moduleId + " is not accepted" + chainInfo
409
+ );
410
+ break;
411
+ case "accepted":
412
+ if (options.onAccepted) options.onAccepted(result);
413
+ doApply = true;
414
+ break;
415
+ case "disposed":
416
+ if (options.onDisposed) options.onDisposed(result);
417
+ doDispose = true;
418
+ break;
419
+ default:
420
+ throw new Error("Unexception type " + result.type);
421
+ }
422
+ if (abortError) {
423
+ hotSetStatus("abort");
424
+ return Promise.reject(abortError);
425
+ }
426
+ if (doApply) {
427
+ appliedUpdate[moduleId] = hotUpdate[moduleId];
428
+ addAllToSet(outdatedModules, result.outdatedModules);
429
+ for (moduleId in result.outdatedDependencies) {
430
+ if (
431
+ Object.prototype.hasOwnProperty.call(
432
+ result.outdatedDependencies,
433
+ moduleId
434
+ )
435
+ ) {
436
+ if (!outdatedDependencies[moduleId])
437
+ outdatedDependencies[moduleId] = [];
438
+ addAllToSet(
439
+ outdatedDependencies[moduleId],
440
+ result.outdatedDependencies[moduleId]
441
+ );
442
+ }
443
+ }
444
+ }
445
+ if (doDispose) {
446
+ addAllToSet(outdatedModules, [result.moduleId]);
447
+ appliedUpdate[moduleId] = warnUnexpectedRequire;
448
+ }
449
+ }
450
+ }
451
+
452
+ // Store self accepted outdated modules to require them later by the module system
453
+ var outdatedSelfAcceptedModules = [];
454
+ for (i = 0; i < outdatedModules.length; i++) {
455
+ moduleId = outdatedModules[i];
456
+ if (
457
+ installedModules[moduleId] &&
458
+ installedModules[moduleId].hot._selfAccepted
459
+ )
460
+ outdatedSelfAcceptedModules.push({
461
+ module: moduleId,
462
+ errorHandler: installedModules[moduleId].hot._selfAccepted
463
+ });
464
+ }
465
+
466
+ // Now in "dispose" phase
467
+ hotSetStatus("dispose");
468
+ Object.keys(hotAvailableFilesMap).forEach(function(chunkId) {
469
+ if (hotAvailableFilesMap[chunkId] === false) {
470
+ hotDisposeChunk(chunkId);
471
+ }
472
+ });
473
+
474
+ var idx;
475
+ var queue = outdatedModules.slice();
476
+ while (queue.length > 0) {
477
+ moduleId = queue.pop();
478
+ module = installedModules[moduleId];
479
+ if (!module) continue;
480
+
481
+ var data = {};
482
+
483
+ // Call dispose handlers
484
+ var disposeHandlers = module.hot._disposeHandlers;
485
+ for (j = 0; j < disposeHandlers.length; j++) {
486
+ cb = disposeHandlers[j];
487
+ cb(data);
488
+ }
489
+ hotCurrentModuleData[moduleId] = data;
490
+
491
+ // disable module (this disables requires from this module)
492
+ module.hot.active = false;
493
+
494
+ // remove module from cache
495
+ delete installedModules[moduleId];
496
+
497
+ // when disposing there is no need to call dispose handler
498
+ delete outdatedDependencies[moduleId];
499
+
500
+ // remove "parents" references from all children
501
+ for (j = 0; j < module.children.length; j++) {
502
+ var child = installedModules[module.children[j]];
503
+ if (!child) continue;
504
+ idx = child.parents.indexOf(moduleId);
505
+ if (idx >= 0) {
506
+ child.parents.splice(idx, 1);
507
+ }
508
+ }
509
+ }
510
+
511
+ // remove outdated dependency from module children
512
+ var dependency;
513
+ var moduleOutdatedDependencies;
514
+ for (moduleId in outdatedDependencies) {
515
+ if (
516
+ Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)
517
+ ) {
518
+ module = installedModules[moduleId];
519
+ if (module) {
520
+ moduleOutdatedDependencies = outdatedDependencies[moduleId];
521
+ for (j = 0; j < moduleOutdatedDependencies.length; j++) {
522
+ dependency = moduleOutdatedDependencies[j];
523
+ idx = module.children.indexOf(dependency);
524
+ if (idx >= 0) module.children.splice(idx, 1);
525
+ }
526
+ }
527
+ }
528
+ }
529
+
530
+ // Not in "apply" phase
531
+ hotSetStatus("apply");
532
+
533
+ hotCurrentHash = hotUpdateNewHash;
534
+
535
+ // insert new code
536
+ for (moduleId in appliedUpdate) {
537
+ if (Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
538
+ modules[moduleId] = appliedUpdate[moduleId];
539
+ }
540
+ }
541
+
542
+ // call accept handlers
543
+ var error = null;
544
+ for (moduleId in outdatedDependencies) {
545
+ if (
546
+ Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)
547
+ ) {
548
+ module = installedModules[moduleId];
549
+ if (module) {
550
+ moduleOutdatedDependencies = outdatedDependencies[moduleId];
551
+ var callbacks = [];
552
+ for (i = 0; i < moduleOutdatedDependencies.length; i++) {
553
+ dependency = moduleOutdatedDependencies[i];
554
+ cb = module.hot._acceptedDependencies[dependency];
555
+ if (cb) {
556
+ if (callbacks.indexOf(cb) !== -1) continue;
557
+ callbacks.push(cb);
558
+ }
559
+ }
560
+ for (i = 0; i < callbacks.length; i++) {
561
+ cb = callbacks[i];
562
+ try {
563
+ cb(moduleOutdatedDependencies);
564
+ } catch (err) {
565
+ if (options.onErrored) {
566
+ options.onErrored({
567
+ type: "accept-errored",
568
+ moduleId: moduleId,
569
+ dependencyId: moduleOutdatedDependencies[i],
570
+ error: err
571
+ });
572
+ }
573
+ if (!options.ignoreErrored) {
574
+ if (!error) error = err;
575
+ }
576
+ }
577
+ }
578
+ }
579
+ }
580
+ }
581
+
582
+ // Load self accepted modules
583
+ for (i = 0; i < outdatedSelfAcceptedModules.length; i++) {
584
+ var item = outdatedSelfAcceptedModules[i];
585
+ moduleId = item.module;
586
+ hotCurrentParents = [moduleId];
587
+ try {
588
+ $require$(moduleId);
589
+ } catch (err) {
590
+ if (typeof item.errorHandler === "function") {
591
+ try {
592
+ item.errorHandler(err);
593
+ } catch (err2) {
594
+ if (options.onErrored) {
595
+ options.onErrored({
596
+ type: "self-accept-error-handler-errored",
597
+ moduleId: moduleId,
598
+ error: err2,
599
+ originalError: err
600
+ });
601
+ }
602
+ if (!options.ignoreErrored) {
603
+ if (!error) error = err2;
604
+ }
605
+ if (!error) error = err;
606
+ }
607
+ } else {
608
+ if (options.onErrored) {
609
+ options.onErrored({
610
+ type: "self-accept-errored",
611
+ moduleId: moduleId,
612
+ error: err
613
+ });
614
+ }
615
+ if (!options.ignoreErrored) {
616
+ if (!error) error = err;
617
+ }
618
+ }
619
+ }
620
+ }
621
+
622
+ // handle errors in accept handlers and self accepted module load
623
+ if (error) {
624
+ hotSetStatus("fail");
625
+ return Promise.reject(error);
626
+ }
627
+
628
+ hotSetStatus("idle");
629
+ return new Promise(function(resolve) {
630
+ resolve(outdatedModules);
631
+ });
632
+ }
633
+ };