webpack-hot-middleware
Advanced tools
Comparing version 2.24.3 to 2.24.4
@@ -21,3 +21,3 @@ /*eslint-env browser*/ | ||
dir: 'ltr', | ||
textAlign: 'left' | ||
textAlign: 'left', | ||
}; | ||
@@ -36,3 +36,3 @@ | ||
lightgrey: 'EBE7E3', | ||
darkgrey: '6D7891' | ||
darkgrey: '6D7891', | ||
}; | ||
@@ -63,11 +63,13 @@ | ||
function problemType (type) { | ||
function problemType(type) { | ||
var problemColors = { | ||
errors: colors.red, | ||
warnings: colors.yellow | ||
warnings: colors.yellow, | ||
}; | ||
var color = problemColors[type] || colors.red; | ||
return ( | ||
'<span style="background-color:#' + color + '; color:#fff; padding:2px 4px; border-radius: 2px">' + | ||
type.slice(0, -1).toUpperCase() + | ||
'<span style="background-color:#' + | ||
color + | ||
'; color:#fff; padding:2px 4px; border-radius: 2px">' + | ||
type.slice(0, -1).toUpperCase() + | ||
'</span>' | ||
@@ -78,5 +80,5 @@ ); | ||
module.exports = function(options) { | ||
for (var color in options.overlayColors) { | ||
for (var color in options.ansiColors) { | ||
if (color in colors) { | ||
colors[color] = options.overlayColors[color]; | ||
colors[color] = options.ansiColors[color]; | ||
} | ||
@@ -96,4 +98,4 @@ ansiHTML.setColors(colors); | ||
showProblems: showProblems, | ||
clear: clear | ||
} | ||
clear: clear, | ||
}; | ||
}; | ||
@@ -100,0 +102,0 @@ |
@@ -5,3 +5,3 @@ /*eslint-env browser*/ | ||
var options = { | ||
path: "/__webpack_hmr", | ||
path: '/__webpack_hmr', | ||
timeout: 20 * 1000, | ||
@@ -16,3 +16,3 @@ overlay: true, | ||
overlayWarnings: false, | ||
ansiColors: {} | ||
ansiColors: {}, | ||
}; | ||
@@ -30,4 +30,4 @@ if (__resourceQuery) { | ||
"webpack-hot-middleware's client requires EventSource to work. " + | ||
"You should include a polyfill if you want to support this browser: " + | ||
"https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools" | ||
'You should include a polyfill if you want to support this browser: ' + | ||
'https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools' | ||
); | ||
@@ -47,3 +47,4 @@ } else { | ||
function setOverrides(overrides) { | ||
if (overrides.autoConnect) options.autoConnect = overrides.autoConnect == 'true'; | ||
if (overrides.autoConnect) | ||
options.autoConnect = overrides.autoConnect == 'true'; | ||
if (overrides.path) options.path = overrides.path; | ||
@@ -68,4 +69,6 @@ if (overrides.timeout) options.timeout = overrides.timeout; | ||
if (overrides.ansiColors) options.ansiColors = JSON.parse(overrides.ansiColors); | ||
if (overrides.overlayStyles) options.overlayStyles = JSON.parse(overrides.overlayStyles); | ||
if (overrides.ansiColors) | ||
options.ansiColors = JSON.parse(overrides.ansiColors); | ||
if (overrides.overlayStyles) | ||
options.overlayStyles = JSON.parse(overrides.overlayStyles); | ||
@@ -84,3 +87,3 @@ if (overrides.overlayWarnings) { | ||
var timer = setInterval(function() { | ||
if ((new Date() - lastActivity) > options.timeout) { | ||
if (new Date() - lastActivity > options.timeout) { | ||
handleDisconnect(); | ||
@@ -98,3 +101,3 @@ } | ||
function handleOnline() { | ||
if (options.log) console.log("[HMR] connected"); | ||
if (options.log) console.log('[HMR] connected'); | ||
lastActivity = new Date(); | ||
@@ -119,3 +122,3 @@ } | ||
listeners.push(fn); | ||
} | ||
}, | ||
}; | ||
@@ -140,3 +143,3 @@ } | ||
function handleMessage(event) { | ||
if (event.data == "\uD83D\uDC93") { | ||
if (event.data == '\uD83D\uDC93') { | ||
return; | ||
@@ -148,3 +151,3 @@ } | ||
if (options.warn) { | ||
console.warn("Invalid HMR message: " + event.data + "\n" + ex); | ||
console.warn('Invalid HMR message: ' + event.data + '\n' + ex); | ||
} | ||
@@ -175,3 +178,3 @@ } | ||
ansiColors: options.ansiColors, | ||
overlayStyles: options.overlayStyles | ||
overlayStyles: options.overlayStyles, | ||
}); | ||
@@ -181,8 +184,12 @@ } | ||
var styles = { | ||
errors: "color: #ff0000;", | ||
warnings: "color: #999933;" | ||
errors: 'color: #ff0000;', | ||
warnings: 'color: #999933;', | ||
}; | ||
var previousProblems = null; | ||
function log(type, obj) { | ||
var newProblems = obj[type].map(function(msg) { return strip(msg); }).join('\n'); | ||
var newProblems = obj[type] | ||
.map(function(msg) { | ||
return strip(msg); | ||
}) | ||
.join('\n'); | ||
if (previousProblems == newProblems) { | ||
@@ -195,15 +202,15 @@ return; | ||
var style = styles[type]; | ||
var name = obj.name ? "'" + obj.name + "' " : ""; | ||
var title = "[HMR] bundle " + name + "has " + obj[type].length + " " + type; | ||
var name = obj.name ? "'" + obj.name + "' " : ''; | ||
var title = '[HMR] bundle ' + name + 'has ' + obj[type].length + ' ' + type; | ||
// NOTE: console.warn or console.error will print the stack trace | ||
// which isn't helpful here, so using console.log to escape it. | ||
if (console.group && console.groupEnd) { | ||
console.group("%c" + title, style); | ||
console.log("%c" + newProblems, style); | ||
console.group('%c' + title, style); | ||
console.log('%c' + newProblems, style); | ||
console.groupEnd(); | ||
} else { | ||
console.log( | ||
"%c" + title + "\n\t%c" + newProblems.replace(/\n/g, "\n\t"), | ||
style + "font-weight: bold;", | ||
style + "font-weight: normal;" | ||
'%c' + title + '\n\t%c' + newProblems.replace(/\n/g, '\n\t'), | ||
style + 'font-weight: bold;', | ||
style + 'font-weight: normal;' | ||
); | ||
@@ -214,3 +221,3 @@ } | ||
return { | ||
cleanProblemsCache: function () { | ||
cleanProblemsCache: function() { | ||
previousProblems = null; | ||
@@ -236,3 +243,3 @@ }, | ||
overlay = customOverlay; | ||
} | ||
}, | ||
}; | ||
@@ -246,20 +253,24 @@ } | ||
function processMessage(obj) { | ||
switch(obj.action) { | ||
case "building": | ||
switch (obj.action) { | ||
case 'building': | ||
if (options.log) { | ||
console.log( | ||
"[HMR] bundle " + (obj.name ? "'" + obj.name + "' " : "") + | ||
"rebuilding" | ||
'[HMR] bundle ' + | ||
(obj.name ? "'" + obj.name + "' " : '') + | ||
'rebuilding' | ||
); | ||
} | ||
break; | ||
case "built": | ||
case 'built': | ||
if (options.log) { | ||
console.log( | ||
"[HMR] bundle " + (obj.name ? "'" + obj.name + "' " : "") + | ||
"rebuilt in " + obj.time + "ms" | ||
'[HMR] bundle ' + | ||
(obj.name ? "'" + obj.name + "' " : '') + | ||
'rebuilt in ' + | ||
obj.time + | ||
'ms' | ||
); | ||
} | ||
// fall through | ||
case "sync": | ||
// fall through | ||
case 'sync': | ||
if (obj.name && options.name && obj.name !== options.name) { | ||
@@ -309,4 +320,4 @@ return; | ||
}, | ||
setOptionsAndConnect: setOptionsAndConnect | ||
setOptionsAndConnect: setOptionsAndConnect, | ||
}; | ||
} |
@@ -9,2 +9,2 @@ var parse = require('url').parse; | ||
} | ||
} | ||
}; |
@@ -8,3 +8,4 @@ module.exports = webpackHotMiddleware; | ||
opts = opts || {}; | ||
opts.log = typeof opts.log == 'undefined' ? console.log.bind(console) : opts.log; | ||
opts.log = | ||
typeof opts.log == 'undefined' ? console.log.bind(console) : opts.log; | ||
opts.path = opts.path || '/__webpack_hmr'; | ||
@@ -18,7 +19,7 @@ opts.heartbeat = opts.heartbeat || 10 * 1000; | ||
if (compiler.hooks) { | ||
compiler.hooks.invalid.tap("webpack-hot-middleware", onInvalid); | ||
compiler.hooks.done.tap("webpack-hot-middleware", onDone); | ||
compiler.hooks.invalid.tap('webpack-hot-middleware', onInvalid); | ||
compiler.hooks.done.tap('webpack-hot-middleware', onDone); | ||
} else { | ||
compiler.plugin("invalid", onInvalid); | ||
compiler.plugin("done", onDone); | ||
compiler.plugin('invalid', onInvalid); | ||
compiler.plugin('done', onDone); | ||
} | ||
@@ -28,4 +29,4 @@ function onInvalid() { | ||
latestStats = null; | ||
if (opts.log) opts.log("webpack building..."); | ||
eventStream.publish({action: "building"}); | ||
if (opts.log) opts.log('webpack building...'); | ||
eventStream.publish({ action: 'building' }); | ||
} | ||
@@ -36,3 +37,3 @@ function onDone(statsResult) { | ||
latestStats = statsResult; | ||
publishStats("built", latestStats, eventStream, opts.log); | ||
publishStats('built', latestStats, eventStream, opts.log); | ||
} | ||
@@ -46,3 +47,3 @@ var middleware = function(req, res, next) { | ||
// the server | ||
publishStats("sync", latestStats, eventStream); | ||
publishStats('sync', latestStats, eventStream); | ||
} | ||
@@ -75,3 +76,3 @@ }; | ||
everyClient(function(client) { | ||
client.write("data: \uD83D\uDC93\n\n"); | ||
client.write('data: \uD83D\uDC93\n\n'); | ||
}); | ||
@@ -94,3 +95,3 @@ }, heartbeat).unref(); | ||
// http://nginx.org/docs/http/ngx_http_proxy_module.html#proxy_buffering | ||
'X-Accel-Buffering': 'no' | ||
'X-Accel-Buffering': 'no', | ||
}; | ||
@@ -102,3 +103,3 @@ | ||
Object.assign(headers, { | ||
'Connection': 'keep-alive', | ||
Connection: 'keep-alive', | ||
}); | ||
@@ -111,3 +112,3 @@ } | ||
clients[id] = res; | ||
req.on("close", function(){ | ||
req.on('close', function() { | ||
if (!res.finished) res.end(); | ||
@@ -119,5 +120,5 @@ delete clients[id]; | ||
everyClient(function(client) { | ||
client.write("data: " + JSON.stringify(payload) + "\n\n"); | ||
client.write('data: ' + JSON.stringify(payload) + '\n\n'); | ||
}); | ||
} | ||
}, | ||
}; | ||
@@ -133,3 +134,3 @@ } | ||
timings: true, | ||
hash: true | ||
hash: true, | ||
}); | ||
@@ -139,12 +140,18 @@ // For multi-compiler, stats will be an object with a 'children' array of stats | ||
bundles.forEach(function(stats) { | ||
var name = stats.name || ""; | ||
var name = stats.name || ''; | ||
// Fallback to compilation name in case of 1 bundle (if it exists) | ||
if (bundles.length === 1 && !name && statsResult.compilation) { | ||
name = statsResult.compilation.name || ""; | ||
name = statsResult.compilation.name || ''; | ||
} | ||
if (log) { | ||
log("webpack built " + (name ? name + " " : "") + | ||
stats.hash + " in " + stats.time + "ms"); | ||
log( | ||
'webpack built ' + | ||
(name ? name + ' ' : '') + | ||
stats.hash + | ||
' in ' + | ||
stats.time + | ||
'ms' | ||
); | ||
} | ||
@@ -158,3 +165,3 @@ eventStream.publish({ | ||
errors: stats.errors || [], | ||
modules: buildModuleMap(stats.modules) | ||
modules: buildModuleMap(stats.modules), | ||
}); | ||
@@ -161,0 +168,0 @@ }); |
{ | ||
"name": "webpack-hot-middleware", | ||
"version": "2.24.3", | ||
"version": "2.24.4", | ||
"description": "Webpack hot reloading you can attach to your own server", | ||
@@ -38,9 +38,18 @@ "keywords": [ | ||
"devDependencies": { | ||
"eslint": "^4.6.1", | ||
"eslint": "^5.14.1", | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"express": "^4.13.3", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^5.2.0", | ||
"prettier": "^1.16.4", | ||
"sinon": "^1.12.2", | ||
"supertest": "^3.1.0" | ||
"supertest": "^3.1.0", | ||
"webpack": "^4.20.2", | ||
"webpack-dev-middleware": "^3.4.0" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"arrowParens": "always" | ||
} | ||
} |
@@ -10,10 +10,10 @@ /** | ||
if (!module.hot) { | ||
throw new Error("[HMR] Hot Module Replacement is disabled."); | ||
throw new Error('[HMR] Hot Module Replacement is disabled.'); | ||
} | ||
var hmrDocsUrl = "https://webpack.js.org/concepts/hot-module-replacement/"; // eslint-disable-line max-len | ||
var hmrDocsUrl = 'https://webpack.js.org/concepts/hot-module-replacement/'; // eslint-disable-line max-len | ||
var lastHash; | ||
var failureStatuses = { abort: 1, fail: 1 }; | ||
var applyOptions = { | ||
var applyOptions = { | ||
ignoreUnaccepted: true, | ||
@@ -23,12 +23,22 @@ ignoreDeclined: true, | ||
onUnaccepted: function(data) { | ||
console.warn("Ignored an update to unaccepted module " + data.chain.join(" -> ")); | ||
console.warn( | ||
'Ignored an update to unaccepted module ' + data.chain.join(' -> ') | ||
); | ||
}, | ||
onDeclined: function(data) { | ||
console.warn("Ignored an update to declined module " + data.chain.join(" -> ")); | ||
console.warn( | ||
'Ignored an update to declined module ' + data.chain.join(' -> ') | ||
); | ||
}, | ||
onErrored: function(data) { | ||
console.error(data.error); | ||
console.warn("Ignored an error while updating module " + data.moduleId + " (" + data.type + ")"); | ||
} | ||
} | ||
console.warn( | ||
'Ignored an error while updating module ' + | ||
data.moduleId + | ||
' (' + | ||
data.type + | ||
')' | ||
); | ||
}, | ||
}; | ||
@@ -42,4 +52,4 @@ function upToDate(hash) { | ||
var reload = options.reload; | ||
if (!upToDate(hash) && module.hot.status() == "idle") { | ||
if (options.log) console.log("[HMR] Checking for updates on the server..."); | ||
if (!upToDate(hash) && module.hot.status() == 'idle') { | ||
if (options.log) console.log('[HMR] Checking for updates on the server...'); | ||
check(); | ||
@@ -52,6 +62,6 @@ } | ||
if(!updatedModules) { | ||
if (!updatedModules) { | ||
if (options.warn) { | ||
console.warn("[HMR] Cannot find update (Full reload needed)"); | ||
console.warn("[HMR] (Probably because of restarting the server)"); | ||
console.warn('[HMR] Cannot find update (Full reload needed)'); | ||
console.warn('[HMR] (Probably because of restarting the server)'); | ||
} | ||
@@ -79,3 +89,2 @@ performReload(); | ||
} | ||
}; | ||
@@ -86,6 +95,6 @@ | ||
if (result && result.then) { | ||
result.then(function(updatedModules) { | ||
cb(null, updatedModules); | ||
}); | ||
result.catch(cb); | ||
result.then(function(updatedModules) { | ||
cb(null, updatedModules); | ||
}); | ||
result.catch(cb); | ||
} | ||
@@ -99,13 +108,15 @@ } | ||
if(unacceptedModules.length > 0) { | ||
if (unacceptedModules.length > 0) { | ||
if (options.warn) { | ||
console.warn( | ||
"[HMR] The following modules couldn't be hot updated: " + | ||
"(Full reload needed)\n" + | ||
"This is usually because the modules which have changed " + | ||
"(and their parents) do not know how to hot reload themselves. " + | ||
"See " + hmrDocsUrl + " for more details." | ||
'(Full reload needed)\n' + | ||
'This is usually because the modules which have changed ' + | ||
'(and their parents) do not know how to hot reload themselves. ' + | ||
'See ' + | ||
hmrDocsUrl + | ||
' for more details.' | ||
); | ||
unacceptedModules.forEach(function(moduleId) { | ||
console.warn("[HMR] - " + (moduleMap[moduleId] || moduleId)); | ||
console.warn('[HMR] - ' + (moduleMap[moduleId] || moduleId)); | ||
}); | ||
@@ -118,8 +129,8 @@ } | ||
if (options.log) { | ||
if(!renewedModules || renewedModules.length === 0) { | ||
console.log("[HMR] Nothing hot updated."); | ||
if (!renewedModules || renewedModules.length === 0) { | ||
console.log('[HMR] Nothing hot updated.'); | ||
} else { | ||
console.log("[HMR] Updated modules:"); | ||
console.log('[HMR] Updated modules:'); | ||
renewedModules.forEach(function(moduleId) { | ||
console.log("[HMR] - " + (moduleMap[moduleId] || moduleId)); | ||
console.log('[HMR] - ' + (moduleMap[moduleId] || moduleId)); | ||
}); | ||
@@ -129,3 +140,3 @@ } | ||
if (upToDate()) { | ||
console.log("[HMR] App is up to date."); | ||
console.log('[HMR] App is up to date.'); | ||
} | ||
@@ -138,4 +149,4 @@ } | ||
if (options.warn) { | ||
console.warn("[HMR] Cannot check for update (Full reload needed)"); | ||
console.warn("[HMR] " + (err.stack || err.message)); | ||
console.warn('[HMR] Cannot check for update (Full reload needed)'); | ||
console.warn('[HMR] ' + (err.stack || err.message)); | ||
} | ||
@@ -146,3 +157,3 @@ performReload(); | ||
if (options.warn) { | ||
console.warn("[HMR] Update check failed: " + (err.stack || err.message)); | ||
console.warn('[HMR] Update check failed: ' + (err.stack || err.message)); | ||
} | ||
@@ -153,3 +164,3 @@ } | ||
if (reload) { | ||
if (options.warn) console.warn("[HMR] Reloading page"); | ||
if (options.warn) console.warn('[HMR] Reloading page'); | ||
window.location.reload(); | ||
@@ -156,0 +167,0 @@ } |
31482
674
10