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