refactor: fix types in hot
This commit is contained in:
parent
284e71b878
commit
fa20888500
|
@ -4,9 +4,10 @@
|
|||
*/
|
||||
/* globals __webpack_hash__ */
|
||||
if (module.hot) {
|
||||
/** @type {undefined|string} */
|
||||
var lastHash;
|
||||
var upToDate = function upToDate() {
|
||||
return lastHash.indexOf(__webpack_hash__) >= 0;
|
||||
return /** @type {string} */ (lastHash).indexOf(__webpack_hash__) >= 0;
|
||||
};
|
||||
var log = require("./log");
|
||||
var check = function check() {
|
||||
|
|
|
@ -3,11 +3,17 @@
|
|||
"use strict";
|
||||
|
||||
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
||||
|
||||
/**
|
||||
* @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
|
||||
* @returns {() => void} function to destroy response
|
||||
*/
|
||||
exports.keepAlive = function (options) {
|
||||
var data = options.data;
|
||||
var onError = options.onError;
|
||||
var active = options.active;
|
||||
var module = options.module;
|
||||
/** @type {import("http").IncomingMessage} */
|
||||
var response;
|
||||
var request = (
|
||||
urlBase.startsWith("https") ? require("https") : require("http")
|
||||
|
@ -27,6 +33,10 @@ exports.keepAlive = function (options) {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {Error} err error
|
||||
*/
|
||||
function errorHandler(err) {
|
||||
err.message =
|
||||
"Problem communicating active modules to the server: " + err.message;
|
||||
|
|
|
@ -9,6 +9,7 @@ if (typeof EventSource !== "function") {
|
|||
}
|
||||
|
||||
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
||||
/** @type {EventSource | undefined} */
|
||||
var activeEventSource;
|
||||
var activeKeys = new Map();
|
||||
var errorHandlers = new Set();
|
||||
|
@ -19,6 +20,10 @@ var updateEventSource = function updateEventSource() {
|
|||
activeEventSource = new EventSource(
|
||||
urlBase + Array.from(activeKeys.keys()).join("@")
|
||||
);
|
||||
/**
|
||||
* @this {EventSource}
|
||||
* @param {Event & { message?: string, filename?: string, lineno?: number, colno?: number, error?: Error }} event event
|
||||
*/
|
||||
activeEventSource.onerror = function (event) {
|
||||
errorHandlers.forEach(function (onError) {
|
||||
onError(
|
||||
|
@ -42,6 +47,10 @@ var updateEventSource = function updateEventSource() {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
|
||||
* @returns {() => void} function to destroy response
|
||||
*/
|
||||
exports.keepAlive = function (options) {
|
||||
var data = options.data;
|
||||
var onError = options.onError;
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {(string | number)[]} updatedModules updated modules
|
||||
* @param {(string | number)[] | null} renewedModules renewed modules
|
||||
*/
|
||||
module.exports = function (updatedModules, renewedModules) {
|
||||
var unacceptedModules = updatedModules.filter(function (moduleId) {
|
||||
return renewedModules && renewedModules.indexOf(moduleId) < 0;
|
||||
|
|
22
hot/log.js
22
hot/log.js
|
@ -1,7 +1,14 @@
|
|||
/** @typedef {"info" | "warning" | "error"} LogLevel */
|
||||
|
||||
/** @type {LogLevel} */
|
||||
var logLevel = "info";
|
||||
|
||||
function dummy() {}
|
||||
|
||||
/**
|
||||
* @param {LogLevel} level log level
|
||||
* @returns {boolean} true, if should log
|
||||
*/
|
||||
function shouldLog(level) {
|
||||
var shouldLog =
|
||||
(logLevel === "info" && level === "info") ||
|
||||
|
@ -10,6 +17,10 @@ function shouldLog(level) {
|
|||
return shouldLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(msg?: string) => void} logFn log function
|
||||
* @returns {(level: LogLevel, msg?: string) => void} function that logs when log level is sufficient
|
||||
*/
|
||||
function logGroup(logFn) {
|
||||
return function (level, msg) {
|
||||
if (shouldLog(level)) {
|
||||
|
@ -18,6 +29,10 @@ function logGroup(logFn) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {LogLevel} level log level
|
||||
* @param {string|Error} msg message
|
||||
*/
|
||||
module.exports = function (level, msg) {
|
||||
if (shouldLog(level)) {
|
||||
if (level === "info") {
|
||||
|
@ -42,10 +57,17 @@ module.exports.groupCollapsed = logGroup(groupCollapsed);
|
|||
|
||||
module.exports.groupEnd = logGroup(groupEnd);
|
||||
|
||||
/**
|
||||
* @param {LogLevel} level log level
|
||||
*/
|
||||
module.exports.setLogLevel = function (level) {
|
||||
logLevel = level;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Error} err error
|
||||
* @returns {string} formatted error
|
||||
*/
|
||||
module.exports.formatError = function (err) {
|
||||
var message = err.message;
|
||||
var stack = err.stack;
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
*/
|
||||
/*globals __webpack_hash__ */
|
||||
if (module.hot) {
|
||||
/** @type {undefined|string} */
|
||||
var lastHash;
|
||||
var upToDate = function upToDate() {
|
||||
return lastHash.indexOf(__webpack_hash__) >= 0;
|
||||
return /** @type {string} */ (lastHash).indexOf(__webpack_hash__) >= 0;
|
||||
};
|
||||
var log = require("./log");
|
||||
var check = function check() {
|
||||
|
|
|
@ -7,6 +7,9 @@ if (module.hot) {
|
|||
var hotPollInterval = +__resourceQuery.slice(1) || 10 * 60 * 1000;
|
||||
var log = require("./log");
|
||||
|
||||
/**
|
||||
* @param {boolean=} fromUpdate true when called from update
|
||||
*/
|
||||
var checkForUpdate = function checkForUpdate(fromUpdate) {
|
||||
if (module.hot.status() === "idle") {
|
||||
module.hot
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
/*globals __resourceQuery */
|
||||
if (module.hot) {
|
||||
var log = require("./log");
|
||||
|
||||
/**
|
||||
* @param {boolean=} fromUpdate true when called from update
|
||||
*/
|
||||
var checkForUpdate = function checkForUpdate(fromUpdate) {
|
||||
module.hot
|
||||
.check()
|
||||
|
|
|
@ -16,4 +16,10 @@ module.hot.apply({
|
|||
ignoreDeclined: true,
|
||||
ignoreErrored: true,
|
||||
}).then(() => {});
|
||||
module.hot.apply({
|
||||
ignoreUnaccepted: true,
|
||||
ignoreDeclined: true,
|
||||
ignoreErrored: true,
|
||||
onDeclined: (event) => { console.log(event.moduleId) },
|
||||
}).then(() => {});
|
||||
module.hot.apply().then(() => {});
|
||||
|
|
|
@ -10,5 +10,8 @@
|
|||
"types": ["node", "./module"],
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["test/typesCases/**/*"]
|
||||
"include": [
|
||||
"hot/**/*",
|
||||
"test/typesCases/**/*"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue