node-hot-loader
Advanced tools
Comparing version 1.9.0 to 1.10.0
@@ -0,1 +1,7 @@ | ||
## 1.10.0 (2018-07-30) | ||
* Add logLevel option for logging with respected to webpack stats configuration. ([95bffb5](https://github.com/vlazh/node-hot-loader/commit/95bffb5)) | ||
## 1.9.0 (2018-07-13) | ||
@@ -2,0 +8,0 @@ |
@@ -16,2 +16,4 @@ 'use strict'; | ||
var _LogLevel = require('./LogLevel'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -25,7 +27,7 @@ | ||
this.logApplyResult = (updatedModules, renewedModules) => { | ||
const unacceptedModules = !renewedModules || !renewedModules.length ? updatedModules : updatedModules.filter(moduleId => renewedModules.indexOf(moduleId) < 0); | ||
this.logApplyResult = (logLevel, outdatedModules, renewedModules) => { | ||
const unacceptedModules = !renewedModules || !renewedModules.length ? outdatedModules : outdatedModules.filter(moduleId => renewedModules.indexOf(moduleId) < 0); | ||
if (unacceptedModules.length > 0) { | ||
this.logger.warn("The following modules couldn't be hot updated: (They would need restart server!)"); | ||
if (unacceptedModules.length > 0 && logLevel >= _LogLevel.LogLevel.ERRORS) { | ||
this.logger.warn("The following modules couldn't be hot updated: (They would need restart the server!)"); | ||
unacceptedModules.forEach(moduleId => { | ||
@@ -37,16 +39,26 @@ this.logger.warn(` - ${moduleId}`); | ||
if (!renewedModules || !renewedModules.length) { | ||
this.logger.info('Nothing hot updated.'); | ||
if (logLevel >= _LogLevel.LogLevel.MINIMAL) { | ||
this.logger.info('Nothing hot updated.'); | ||
} | ||
return; | ||
} | ||
this.logger.info('Updated modules:'); | ||
renewedModules.forEach(moduleId => { | ||
this.logger.info(` - ${moduleId}`); | ||
}); | ||
const numberIds = renewedModules.every(moduleId => typeof moduleId === 'number'); | ||
if (numberIds) { | ||
this.logger.info('Consider using the NamedModulesPlugin for module names.'); | ||
if (logLevel >= _LogLevel.LogLevel.NORMAL) { | ||
this.logger.info('Updated modules:'); | ||
renewedModules.forEach(moduleId => { | ||
this.logger.info(` - ${moduleId}`); | ||
}); | ||
const numberIds = renewedModules.every(moduleId => typeof moduleId === 'number'); | ||
if (numberIds) { | ||
this.logger.info('Consider using the NamedModulesPlugin for module names.'); | ||
} | ||
} | ||
if (this.upToDate()) { | ||
this.logUpToDate(logLevel); | ||
} | ||
}; | ||
this.logUpToDate = logLevel => { | ||
if (logLevel >= _LogLevel.LogLevel.MINIMAL) { | ||
this.logger.info('App is up to date.'); | ||
@@ -63,11 +75,17 @@ } | ||
this.lastHash = message.stats.hash; | ||
const { logLevel } = message; | ||
if (!this.upToDate()) { | ||
const status = module.hot.status(); | ||
if (status === 'idle') { | ||
this.logger.info('Checking for updates...'); | ||
this.check(); | ||
} else if (['abort', 'fail'].indexOf(status) >= 0) { | ||
this.logger.warn(`Cannot apply update as a previous update ${status}ed. Need to do restart server!`); | ||
if (logLevel >= _LogLevel.LogLevel.MINIMAL) { | ||
this.logger.info('Checking for updates...'); | ||
} | ||
this.check(logLevel); | ||
} else if (['abort', 'fail'].indexOf(status) >= 0 && logLevel >= _LogLevel.LogLevel.ERRORS) { | ||
this.logger.warn(`Cannot apply update as a previous update ${status}ed. Need to do restart the server!`); | ||
} | ||
} else { | ||
this.logUpToDate(logLevel); | ||
} | ||
@@ -78,7 +96,9 @@ }; | ||
this.check = () => { | ||
module.hot.check().then(updatedModules => { | ||
if (!updatedModules) { | ||
this.logger.warn('Cannot find update. Need to do restart server!'); | ||
return null; | ||
this.check = logLevel => { | ||
module.hot.check().then(outdatedModules => { | ||
if (!outdatedModules) { | ||
if (logLevel >= _LogLevel.LogLevel.ERRORS) { | ||
this.logger.warn('Cannot find update. Need to do restart the server!'); | ||
} | ||
return Promise.resolve(); | ||
} | ||
@@ -91,27 +111,35 @@ | ||
onUnaccepted: info => { | ||
this.logger.warn(`Ignored an update to unaccepted module ${info.chain.join(' -> ')}`); | ||
if (logLevel >= _LogLevel.LogLevel.ERRORS) { | ||
this.logger.warn(`Ignored an update to unaccepted module ${info.chain.join(' -> ')}`); | ||
} | ||
}, | ||
onDeclined: info => { | ||
this.logger.warn(`Ignored an update to declined module ${info.chain.join(' -> ')}`); | ||
if (logLevel >= _LogLevel.LogLevel.ERRORS) { | ||
this.logger.warn(`Ignored an update to declined module ${info.chain.join(' -> ')}`); | ||
} | ||
}, | ||
onErrored: info => { | ||
this.logger.warn(`Ignored an error while updating module ${info.moduleId} (${info.type})`); | ||
// If ignoreErrored is true and throw info.error then module.hot.status() always | ||
// equals 'apply' and module.hot.check() will not work. | ||
this.logger.error(info.error); | ||
if (logLevel >= _LogLevel.LogLevel.ERRORS) { | ||
this.logger.warn(`Ignored an error while updating module ${info.moduleId} (${info.type})`); | ||
// If ignoreErrored is true and throw info.error then module.hot.status() always | ||
// equals 'apply' and module.hot.check() will not work. | ||
this.logger.error(info.error); | ||
} | ||
} | ||
}).then(renewedModules => { | ||
if (!this.upToDate()) { | ||
this.check(); | ||
this.check(logLevel); | ||
} | ||
this.logApplyResult(updatedModules, renewedModules); | ||
this.logApplyResult(logLevel, outdatedModules, renewedModules); | ||
}); | ||
}).catch(err => { | ||
const status = module.hot.status(); | ||
if (['abort', 'fail'].indexOf(status) >= 0) { | ||
this.logger.error('Cannot check for update. Need to do restart server!'); | ||
this.logger.error(err.stack || err.message); | ||
} else { | ||
this.logger.error(`Update check failed: ${err.stack}` || err.message); | ||
if (logLevel >= _LogLevel.LogLevel.ERRORS) { | ||
const status = module.hot.status(); | ||
if (['abort', 'fail'].indexOf(status) >= 0) { | ||
this.logger.error('Cannot check for update. Need to do restart the server!'); | ||
this.logger.error(err.stack || err.message); | ||
} else { | ||
this.logger.error(`Update check failed: ${err.stack}` || err.message); | ||
} | ||
} | ||
@@ -118,0 +146,0 @@ }); |
@@ -29,2 +29,4 @@ 'use strict'; | ||
var _LogLevel = require('./LogLevel'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -36,10 +38,13 @@ | ||
static defaultReporter({ context, stateValid, stats, compilerOptions }) { | ||
// for check log level for webpack compiler only | ||
const compilerLogLevel = (0, _LogLevel.parseLogLevel)(compilerOptions.stats); | ||
if (!stateValid) { | ||
context.webpackLogger.info('Compiling...'); | ||
if (compilerLogLevel >= _LogLevel.LogLevel.MINIMAL) { | ||
context.webpackLogger.info('Compiling...'); | ||
} | ||
return; | ||
} | ||
const displayStats = !compilerOptions.quiet && compilerOptions.stats !== false && (stats.hasErrors() || stats.hasWarnings() || !compilerOptions.noInfo); | ||
if (displayStats) { | ||
if (compilerLogLevel > _LogLevel.LogLevel.NONE) { | ||
const statsInfo = stats.toString(compilerOptions.stats); | ||
@@ -52,3 +57,3 @@ if (statsInfo) { | ||
if (!compilerOptions.noInfo && !compilerOptions.quiet) { | ||
if (compilerLogLevel >= _LogLevel.LogLevel.ERRORS) { | ||
if (stats.hasErrors()) { | ||
@@ -59,2 +64,5 @@ context.webpackLogger.error('Failed to compile.'); | ||
} | ||
} | ||
if (compilerLogLevel >= _LogLevel.LogLevel.MINIMAL) { | ||
context.webpackLogger.info('Compiled successfully.'); | ||
@@ -93,9 +101,7 @@ } | ||
reporter: HmrServer.defaultReporter, | ||
// info: console.log.bind(console), | ||
// warn: console.warn.bind(console), | ||
// error: console.error.bind(console), | ||
logger: new _Logger2.default(_LogColors2.default.cyan('[HMR]')), | ||
webpackLogger: new _Logger2.default(_LogColors2.default.magenta('Webpack')), | ||
fork: false, | ||
compiler: undefined | ||
compiler: undefined, | ||
logLevel: undefined | ||
}; | ||
@@ -108,6 +114,9 @@ | ||
const logLevel = this.context.logLevel != null ? (0, _LogLevel.parseLogLevel)(this.context.logLevel) : (0, _LogLevel.parseLogLevel)(this.context.compiler.options.stats); | ||
if (this.context.fork) { | ||
this.context.serverProcess.send({ | ||
action, | ||
stats: this.context.webpackStats.toJson() | ||
stats: this.context.webpackStats.toJson(), | ||
logLevel | ||
}); | ||
@@ -117,3 +126,4 @@ } else { | ||
action, | ||
stats: this.context.webpackStats.toJson() | ||
stats: this.context.webpackStats.toJson(), | ||
logLevel | ||
}); | ||
@@ -205,6 +215,6 @@ } | ||
this.compilerInvalid = () => { | ||
this.compilerInvalid = (_, callback) => { | ||
this.sendMessage('compile'); | ||
if (this.context.stateValid && !this.context.compiler.options.noInfo && !this.context.compiler.options.quiet) { | ||
if (this.context.stateValid) { | ||
this.context.reporter({ | ||
@@ -220,4 +230,3 @@ stateValid: false, | ||
// resolve async | ||
if (arguments.length === 2 && typeof arguments[1] === 'function') { | ||
const callback = arguments[1]; | ||
if (typeof callback === 'function') { | ||
callback(); | ||
@@ -224,0 +233,0 @@ } |
@@ -28,3 +28,4 @@ #!/usr/bin/env node | ||
config: 'webpack.config.js', | ||
fork: false | ||
fork: false, | ||
logLevel: undefined | ||
}; | ||
@@ -44,4 +45,9 @@ | ||
requiresArg: false | ||
}, | ||
logLevel: { | ||
type: 'string', | ||
describe: 'Log level related to webpack stats configuration presets names. See presets from https://webpack.js.org/configuration/stats/#stats.', | ||
requiresArg: false | ||
} | ||
}).example('node-hot --config webpack.config.js', 'Using a specific webpack config file.').example('node-hot', 'Using default webpack config file.').showHelpOnFail(false, 'Use the --help option to get the list of available options.').check(args => { | ||
}).example('node-hot --config webpack.config.js', 'Using a specific webpack config file.').example('node-hot', 'Using default webpack config file.').example('node-hot --logLevel minimal', 'Set a specific logLevel for node-hot-loader.').showHelpOnFail(false, 'Use the --help option to get the list of available options.').check(args => { | ||
if (!_fs2.default.existsSync(args.config)) { | ||
@@ -51,9 +57,18 @@ throw new Error(`Webpack config file '${args.config}' not found!`); | ||
return true; | ||
}).coerce('config', value => { | ||
if (!_path2.default.isAbsolute(value)) { | ||
return _path2.default.join(process.cwd(), value); | ||
} | ||
return value; | ||
}).coerce('logLevel', value => { | ||
if (value === '') return true; | ||
if (value === 'true') return false; | ||
if (value === 'false') return false; | ||
return value; | ||
}).strict().argv; | ||
if (!_path2.default.isAbsolute(params.config)) { | ||
options.config = _path2.default.join(process.cwd(), params.config); | ||
} | ||
options.config = params.config; | ||
options.fork = params.fork; | ||
options.logLevel = params.logLevel; | ||
(0, _loader2.default)(options); |
{ | ||
"name": "node-hot-loader", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "Hot module replacement for Node.js applications", | ||
@@ -13,2 +13,3 @@ "main": "./lib/node-hot.js", | ||
"build": "babel src --out-dir lib/ --copy-files", | ||
"build:to-simple-example": "npm run clean && babel src --out-dir 'examples/simple-example/node_modules/node-hot-loader/lib/' --copy-files", | ||
"prepublishOnly": "npm run clean && npm run build", | ||
@@ -18,3 +19,2 @@ "patch-publish": "npm version patch && git commit --amend --no-edit && npm publish && git push --follow-tags", | ||
"major-publish": "npm version major && git commit --amend --no-edit && npm publish && git push --follow-tags", | ||
"unpublish": "---npm unpublish node-hot-loader@0.1.0", | ||
"version": "conventional-changelog -i CHANGELOG.md -s && git add CHANGELOG.md", | ||
@@ -68,3 +68,3 @@ "changelog": "conventional-changelog -i CHANGELOG.md -s" | ||
"@types/webpack-env": "^1.13.6", | ||
"@vzh/configs": "^1.21.1", | ||
"@vzh/configs": "^1.24.0", | ||
"babel-cli": "^6.26.0", | ||
@@ -76,3 +76,3 @@ "babel-eslint": "^8.2.2", | ||
"conventional-changelog-cli": "^2.0.1", | ||
"eslint": "^5.1.0", | ||
"eslint": "^5.2.0", | ||
"eslint-config-airbnb-base": "^13.0.0", | ||
@@ -82,5 +82,5 @@ "eslint-config-prettier": "^2.9.0", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"prettier": "^1.11.1", | ||
"prettier": "^1.14.0", | ||
"rimraf": "^2.6.1", | ||
"webpack": "^4.5.0" | ||
"webpack": "^4.16.3" | ||
}, | ||
@@ -87,0 +87,0 @@ "peerDependencies": { |
@@ -38,11 +38,16 @@ # Node Hot Loader [![npm package](https://img.shields.io/npm/v/node-hot-loader.svg?style=flat-square)](https://www.npmjs.org/package/node-hot-loader) | ||
Usage: node-hot {options} | ||
Options: | ||
--config Path to the webpack config file. If not set then search webpack.config.js in root directory. | ||
--fork Launch compiled assets in forked process. | ||
``` | ||
## Usage example | ||
### Options | ||
Name | Description | Note | ||
--- | --- | --- | ||
`--config` | Path to the webpack config file. | If not set then search webpack.config.js in root directory. | ||
`--fork` | Launch compiled assets in forked process. | | ||
`--logLevel` | Log level related to webpack stats configuration presets names. See presets from https://webpack.js.org/configuration/stats/#stats. | If not set then use webpack stats configuration. | ||
### Usage example | ||
``` | ||
node-hot --config webpack.config.server.js | ||
or | ||
node-hot --logLevel minimal | ||
``` | ||
@@ -86,3 +91,2 @@ Of course, you can add script into you package.json: | ||
import app from './app'; // configuring express app, e.g. routes and logic | ||
import DB from './services/DB'; // DB service | ||
@@ -128,12 +132,6 @@ function startServer() { | ||
// After DB initialized start server | ||
DB.connect() | ||
.then(() => { | ||
console.log('Successfully connected to MongoDB.'); | ||
console.log('Starting http server...'); | ||
return startServer(); | ||
}) | ||
.catch(err => { | ||
console.error('Error in server start script.', err); | ||
}); | ||
console.log('Starting http server...'); | ||
startServer().catch(err => { | ||
console.error('Error in server start script.', err); | ||
}); | ||
``` | ||
@@ -140,0 +138,0 @@ |
136122
18
566
139