1 | // @ts-nocheck
|
---|
2 | /*
|
---|
3 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
4 | Author Tobias Koppers @sokra
|
---|
5 | */
|
---|
6 |
|
---|
7 | "use strict";
|
---|
8 |
|
---|
9 | var $interceptModuleExecution$ = undefined;
|
---|
10 | var $moduleCache$ = undefined;
|
---|
11 | // eslint-disable-next-line no-unused-vars
|
---|
12 | var $hmrModuleData$ = undefined;
|
---|
13 | /** @type {() => Promise} */
|
---|
14 | var $hmrDownloadManifest$ = undefined;
|
---|
15 | var $hmrDownloadUpdateHandlers$ = undefined;
|
---|
16 | var $hmrInvalidateModuleHandlers$ = undefined;
|
---|
17 | var __webpack_require__ = undefined;
|
---|
18 |
|
---|
19 | module.exports = function () {
|
---|
20 | var currentModuleData = {};
|
---|
21 | var installedModules = $moduleCache$;
|
---|
22 |
|
---|
23 | // module and require creation
|
---|
24 | var currentChildModule;
|
---|
25 | var currentParents = [];
|
---|
26 |
|
---|
27 | // status
|
---|
28 | var registeredStatusHandlers = [];
|
---|
29 | var currentStatus = "idle";
|
---|
30 |
|
---|
31 | // while downloading
|
---|
32 | var blockingPromises = 0;
|
---|
33 | var blockingPromisesWaiting = [];
|
---|
34 |
|
---|
35 | // The update info
|
---|
36 | var currentUpdateApplyHandlers;
|
---|
37 | var queuedInvalidatedModules;
|
---|
38 |
|
---|
39 | $hmrModuleData$ = currentModuleData;
|
---|
40 |
|
---|
41 | $interceptModuleExecution$.push(function (options) {
|
---|
42 | var module = options.module;
|
---|
43 | var require = createRequire(options.require, options.id);
|
---|
44 | module.hot = createModuleHotObject(options.id, module);
|
---|
45 | module.parents = currentParents;
|
---|
46 | module.children = [];
|
---|
47 | currentParents = [];
|
---|
48 | options.require = require;
|
---|
49 | });
|
---|
50 |
|
---|
51 | $hmrDownloadUpdateHandlers$ = {};
|
---|
52 | $hmrInvalidateModuleHandlers$ = {};
|
---|
53 |
|
---|
54 | function createRequire(require, moduleId) {
|
---|
55 | var me = installedModules[moduleId];
|
---|
56 | if (!me) return require;
|
---|
57 | var fn = function (request) {
|
---|
58 | if (me.hot.active) {
|
---|
59 | if (installedModules[request]) {
|
---|
60 | var parents = installedModules[request].parents;
|
---|
61 | if (parents.indexOf(moduleId) === -1) {
|
---|
62 | parents.push(moduleId);
|
---|
63 | }
|
---|
64 | } else {
|
---|
65 | currentParents = [moduleId];
|
---|
66 | currentChildModule = request;
|
---|
67 | }
|
---|
68 | if (me.children.indexOf(request) === -1) {
|
---|
69 | me.children.push(request);
|
---|
70 | }
|
---|
71 | } else {
|
---|
72 | console.warn(
|
---|
73 | "[HMR] unexpected require(" +
|
---|
74 | request +
|
---|
75 | ") from disposed module " +
|
---|
76 | moduleId
|
---|
77 | );
|
---|
78 | currentParents = [];
|
---|
79 | }
|
---|
80 | return require(request);
|
---|
81 | };
|
---|
82 | var createPropertyDescriptor = function (name) {
|
---|
83 | return {
|
---|
84 | configurable: true,
|
---|
85 | enumerable: true,
|
---|
86 | get: function () {
|
---|
87 | return require[name];
|
---|
88 | },
|
---|
89 | set: function (value) {
|
---|
90 | require[name] = value;
|
---|
91 | }
|
---|
92 | };
|
---|
93 | };
|
---|
94 | for (var name in require) {
|
---|
95 | if (Object.prototype.hasOwnProperty.call(require, name) && name !== "e") {
|
---|
96 | Object.defineProperty(fn, name, createPropertyDescriptor(name));
|
---|
97 | }
|
---|
98 | }
|
---|
99 | fn.e = function (chunkId, fetchPriority) {
|
---|
100 | return trackBlockingPromise(require.e(chunkId, fetchPriority));
|
---|
101 | };
|
---|
102 | return fn;
|
---|
103 | }
|
---|
104 |
|
---|
105 | function createModuleHotObject(moduleId, me) {
|
---|
106 | var _main = currentChildModule !== moduleId;
|
---|
107 | var hot = {
|
---|
108 | // private stuff
|
---|
109 | _acceptedDependencies: {},
|
---|
110 | _acceptedErrorHandlers: {},
|
---|
111 | _declinedDependencies: {},
|
---|
112 | _selfAccepted: false,
|
---|
113 | _selfDeclined: false,
|
---|
114 | _selfInvalidated: false,
|
---|
115 | _disposeHandlers: [],
|
---|
116 | _main: _main,
|
---|
117 | _requireSelf: function () {
|
---|
118 | currentParents = me.parents.slice();
|
---|
119 | currentChildModule = _main ? undefined : moduleId;
|
---|
120 | __webpack_require__(moduleId);
|
---|
121 | },
|
---|
122 |
|
---|
123 | // Module API
|
---|
124 | active: true,
|
---|
125 | accept: function (dep, callback, errorHandler) {
|
---|
126 | if (dep === undefined) hot._selfAccepted = true;
|
---|
127 | else if (typeof dep === "function") hot._selfAccepted = dep;
|
---|
128 | else if (typeof dep === "object" && dep !== null) {
|
---|
129 | for (var i = 0; i < dep.length; i++) {
|
---|
130 | hot._acceptedDependencies[dep[i]] = callback || function () {};
|
---|
131 | hot._acceptedErrorHandlers[dep[i]] = errorHandler;
|
---|
132 | }
|
---|
133 | } else {
|
---|
134 | hot._acceptedDependencies[dep] = callback || function () {};
|
---|
135 | hot._acceptedErrorHandlers[dep] = errorHandler;
|
---|
136 | }
|
---|
137 | },
|
---|
138 | decline: function (dep) {
|
---|
139 | if (dep === undefined) hot._selfDeclined = true;
|
---|
140 | else if (typeof dep === "object" && dep !== null)
|
---|
141 | for (var i = 0; i < dep.length; i++)
|
---|
142 | hot._declinedDependencies[dep[i]] = true;
|
---|
143 | else hot._declinedDependencies[dep] = true;
|
---|
144 | },
|
---|
145 | dispose: function (callback) {
|
---|
146 | hot._disposeHandlers.push(callback);
|
---|
147 | },
|
---|
148 | addDisposeHandler: function (callback) {
|
---|
149 | hot._disposeHandlers.push(callback);
|
---|
150 | },
|
---|
151 | removeDisposeHandler: function (callback) {
|
---|
152 | var idx = hot._disposeHandlers.indexOf(callback);
|
---|
153 | if (idx >= 0) hot._disposeHandlers.splice(idx, 1);
|
---|
154 | },
|
---|
155 | invalidate: function () {
|
---|
156 | this._selfInvalidated = true;
|
---|
157 | switch (currentStatus) {
|
---|
158 | case "idle":
|
---|
159 | currentUpdateApplyHandlers = [];
|
---|
160 | Object.keys($hmrInvalidateModuleHandlers$).forEach(function (key) {
|
---|
161 | $hmrInvalidateModuleHandlers$[key](
|
---|
162 | moduleId,
|
---|
163 | currentUpdateApplyHandlers
|
---|
164 | );
|
---|
165 | });
|
---|
166 | setStatus("ready");
|
---|
167 | break;
|
---|
168 | case "ready":
|
---|
169 | Object.keys($hmrInvalidateModuleHandlers$).forEach(function (key) {
|
---|
170 | $hmrInvalidateModuleHandlers$[key](
|
---|
171 | moduleId,
|
---|
172 | currentUpdateApplyHandlers
|
---|
173 | );
|
---|
174 | });
|
---|
175 | break;
|
---|
176 | case "prepare":
|
---|
177 | case "check":
|
---|
178 | case "dispose":
|
---|
179 | case "apply":
|
---|
180 | (queuedInvalidatedModules = queuedInvalidatedModules || []).push(
|
---|
181 | moduleId
|
---|
182 | );
|
---|
183 | break;
|
---|
184 | default:
|
---|
185 | // ignore requests in error states
|
---|
186 | break;
|
---|
187 | }
|
---|
188 | },
|
---|
189 |
|
---|
190 | // Management API
|
---|
191 | check: hotCheck,
|
---|
192 | apply: hotApply,
|
---|
193 | status: function (l) {
|
---|
194 | if (!l) return currentStatus;
|
---|
195 | registeredStatusHandlers.push(l);
|
---|
196 | },
|
---|
197 | addStatusHandler: function (l) {
|
---|
198 | registeredStatusHandlers.push(l);
|
---|
199 | },
|
---|
200 | removeStatusHandler: function (l) {
|
---|
201 | var idx = registeredStatusHandlers.indexOf(l);
|
---|
202 | if (idx >= 0) registeredStatusHandlers.splice(idx, 1);
|
---|
203 | },
|
---|
204 |
|
---|
205 | // inherit from previous dispose call
|
---|
206 | data: currentModuleData[moduleId]
|
---|
207 | };
|
---|
208 | currentChildModule = undefined;
|
---|
209 | return hot;
|
---|
210 | }
|
---|
211 |
|
---|
212 | function setStatus(newStatus) {
|
---|
213 | currentStatus = newStatus;
|
---|
214 | var results = [];
|
---|
215 |
|
---|
216 | for (var i = 0; i < registeredStatusHandlers.length; i++)
|
---|
217 | results[i] = registeredStatusHandlers[i].call(null, newStatus);
|
---|
218 |
|
---|
219 | return Promise.all(results).then(function () {});
|
---|
220 | }
|
---|
221 |
|
---|
222 | function unblock() {
|
---|
223 | if (--blockingPromises === 0) {
|
---|
224 | setStatus("ready").then(function () {
|
---|
225 | if (blockingPromises === 0) {
|
---|
226 | var list = blockingPromisesWaiting;
|
---|
227 | blockingPromisesWaiting = [];
|
---|
228 | for (var i = 0; i < list.length; i++) {
|
---|
229 | list[i]();
|
---|
230 | }
|
---|
231 | }
|
---|
232 | });
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | function trackBlockingPromise(promise) {
|
---|
237 | switch (currentStatus) {
|
---|
238 | case "ready":
|
---|
239 | setStatus("prepare");
|
---|
240 | /* fallthrough */
|
---|
241 | case "prepare":
|
---|
242 | blockingPromises++;
|
---|
243 | promise.then(unblock, unblock);
|
---|
244 | return promise;
|
---|
245 | default:
|
---|
246 | return promise;
|
---|
247 | }
|
---|
248 | }
|
---|
249 |
|
---|
250 | function waitForBlockingPromises(fn) {
|
---|
251 | if (blockingPromises === 0) return fn();
|
---|
252 | return new Promise(function (resolve) {
|
---|
253 | blockingPromisesWaiting.push(function () {
|
---|
254 | resolve(fn());
|
---|
255 | });
|
---|
256 | });
|
---|
257 | }
|
---|
258 |
|
---|
259 | function hotCheck(applyOnUpdate) {
|
---|
260 | if (currentStatus !== "idle") {
|
---|
261 | throw new Error("check() is only allowed in idle status");
|
---|
262 | }
|
---|
263 | return setStatus("check")
|
---|
264 | .then($hmrDownloadManifest$)
|
---|
265 | .then(function (update) {
|
---|
266 | if (!update) {
|
---|
267 | return setStatus(applyInvalidatedModules() ? "ready" : "idle").then(
|
---|
268 | function () {
|
---|
269 | return null;
|
---|
270 | }
|
---|
271 | );
|
---|
272 | }
|
---|
273 |
|
---|
274 | return setStatus("prepare").then(function () {
|
---|
275 | var updatedModules = [];
|
---|
276 | currentUpdateApplyHandlers = [];
|
---|
277 |
|
---|
278 | return Promise.all(
|
---|
279 | Object.keys($hmrDownloadUpdateHandlers$).reduce(function (
|
---|
280 | promises,
|
---|
281 | key
|
---|
282 | ) {
|
---|
283 | $hmrDownloadUpdateHandlers$[key](
|
---|
284 | update.c,
|
---|
285 | update.r,
|
---|
286 | update.m,
|
---|
287 | promises,
|
---|
288 | currentUpdateApplyHandlers,
|
---|
289 | updatedModules
|
---|
290 | );
|
---|
291 | return promises;
|
---|
292 | }, [])
|
---|
293 | ).then(function () {
|
---|
294 | return waitForBlockingPromises(function () {
|
---|
295 | if (applyOnUpdate) {
|
---|
296 | return internalApply(applyOnUpdate);
|
---|
297 | }
|
---|
298 | return setStatus("ready").then(function () {
|
---|
299 | return updatedModules;
|
---|
300 | });
|
---|
301 | });
|
---|
302 | });
|
---|
303 | });
|
---|
304 | });
|
---|
305 | }
|
---|
306 |
|
---|
307 | function hotApply(options) {
|
---|
308 | if (currentStatus !== "ready") {
|
---|
309 | return Promise.resolve().then(function () {
|
---|
310 | throw new Error(
|
---|
311 | "apply() is only allowed in ready status (state: " +
|
---|
312 | currentStatus +
|
---|
313 | ")"
|
---|
314 | );
|
---|
315 | });
|
---|
316 | }
|
---|
317 | return internalApply(options);
|
---|
318 | }
|
---|
319 |
|
---|
320 | function internalApply(options) {
|
---|
321 | options = options || {};
|
---|
322 |
|
---|
323 | applyInvalidatedModules();
|
---|
324 |
|
---|
325 | var results = currentUpdateApplyHandlers.map(function (handler) {
|
---|
326 | return handler(options);
|
---|
327 | });
|
---|
328 | currentUpdateApplyHandlers = undefined;
|
---|
329 |
|
---|
330 | var errors = results
|
---|
331 | .map(function (r) {
|
---|
332 | return r.error;
|
---|
333 | })
|
---|
334 | .filter(Boolean);
|
---|
335 |
|
---|
336 | if (errors.length > 0) {
|
---|
337 | return setStatus("abort").then(function () {
|
---|
338 | throw errors[0];
|
---|
339 | });
|
---|
340 | }
|
---|
341 |
|
---|
342 | // Now in "dispose" phase
|
---|
343 | var disposePromise = setStatus("dispose");
|
---|
344 |
|
---|
345 | results.forEach(function (result) {
|
---|
346 | if (result.dispose) result.dispose();
|
---|
347 | });
|
---|
348 |
|
---|
349 | // Now in "apply" phase
|
---|
350 | var applyPromise = setStatus("apply");
|
---|
351 |
|
---|
352 | var error;
|
---|
353 | var reportError = function (err) {
|
---|
354 | if (!error) error = err;
|
---|
355 | };
|
---|
356 |
|
---|
357 | var outdatedModules = [];
|
---|
358 | results.forEach(function (result) {
|
---|
359 | if (result.apply) {
|
---|
360 | var modules = result.apply(reportError);
|
---|
361 | if (modules) {
|
---|
362 | for (var i = 0; i < modules.length; i++) {
|
---|
363 | outdatedModules.push(modules[i]);
|
---|
364 | }
|
---|
365 | }
|
---|
366 | }
|
---|
367 | });
|
---|
368 |
|
---|
369 | return Promise.all([disposePromise, applyPromise]).then(function () {
|
---|
370 | // handle errors in accept handlers and self accepted module load
|
---|
371 | if (error) {
|
---|
372 | return setStatus("fail").then(function () {
|
---|
373 | throw error;
|
---|
374 | });
|
---|
375 | }
|
---|
376 |
|
---|
377 | if (queuedInvalidatedModules) {
|
---|
378 | return internalApply(options).then(function (list) {
|
---|
379 | outdatedModules.forEach(function (moduleId) {
|
---|
380 | if (list.indexOf(moduleId) < 0) list.push(moduleId);
|
---|
381 | });
|
---|
382 | return list;
|
---|
383 | });
|
---|
384 | }
|
---|
385 |
|
---|
386 | return setStatus("idle").then(function () {
|
---|
387 | return outdatedModules;
|
---|
388 | });
|
---|
389 | });
|
---|
390 | }
|
---|
391 |
|
---|
392 | function applyInvalidatedModules() {
|
---|
393 | if (queuedInvalidatedModules) {
|
---|
394 | if (!currentUpdateApplyHandlers) currentUpdateApplyHandlers = [];
|
---|
395 | Object.keys($hmrInvalidateModuleHandlers$).forEach(function (key) {
|
---|
396 | queuedInvalidatedModules.forEach(function (moduleId) {
|
---|
397 | $hmrInvalidateModuleHandlers$[key](
|
---|
398 | moduleId,
|
---|
399 | currentUpdateApplyHandlers
|
---|
400 | );
|
---|
401 | });
|
---|
402 | });
|
---|
403 | queuedInvalidatedModules = undefined;
|
---|
404 | return true;
|
---|
405 | }
|
---|
406 | }
|
---|
407 | };
|
---|