Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-hot-loader

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-hot-loader - npm Package Compare versions

Comparing version 0.3.10 to 1.0.0

151

lib/HmrClient.js

@@ -19,2 +19,4 @@ 'use strict';

var hmrDocsUrl = 'https://webpack.js.org/concepts/hot-module-replacement/';
var HmrClient = function () {

@@ -26,74 +28,89 @@ function HmrClient() {

Object.defineProperty(this, 'defaultListener', {
enumerable: true,
writable: true,
value: function value(message) {
// webpackHotUpdate
if (message.action === 'built') {
_this.lastHash = message.stats.hash;
if (!_this.upToDate()) {
var status = module.hot.status();
if (status === 'idle') {
console.log(HmrClient.logPrefix, 'Checking for updates on the server...');
_this.check();
} else if (['abort', 'fail'].indexOf(status) >= 0) {
console.warn(HmrClient.logPrefix, 'Cannot apply update as a previous update ' + status + 'ed. Need to do a full reload!');
}
this.defaultListener = function (message) {
// webpackHotUpdate
if (message.action === 'built') {
_this.lastHash = message.stats.hash;
if (!_this.upToDate()) {
var status = module.hot.status();
if (status === 'idle') {
console.log(HmrClient.logPrefix, 'Checking for updates on the server...');
_this.check();
} else if (['abort', 'fail'].indexOf(status) >= 0) {
console.warn(HmrClient.logPrefix, 'Cannot apply update as a previous update ' + status + 'ed. Need to do a full reload!');
}
}
}
});
Object.defineProperty(this, 'upToDate', {
enumerable: true,
writable: true,
value: function value() {
return _this.lastHash.indexOf(__webpack_hash__) >= 0;
};
this.upToDate = function () {
return _this.lastHash.indexOf(__webpack_hash__) >= 0;
};
this.handleError = function (err) {
var status = module.hot.status();
if (['abort', 'fail'].indexOf(status) >= 0) {
console.warn(HmrClient.logPrefix, 'Cannot check for update. Need to do a full reload!');
console.warn(HmrClient.logPrefix, err.stack || err.message);
} else {
console.warn(HmrClient.logPrefix, 'Update check failed: ' + err.stack || err.message);
}
});
Object.defineProperty(this, 'check', {
enumerable: true,
writable: true,
value: function value() {
module.hot.check().then(function (updatedModules) {
if (!updatedModules) {
console.warn(HmrClient.logPrefix, 'Cannot find update. Need to do a full reload!');
console.warn(HmrClient.logPrefix, '(Probably because of restarting the webpack-dev-server)');
};
this.check = function () {
var cb = function cb(err, updatedModules) {
if (err) {
_this.handleError(err);
return;
}
if (!updatedModules) {
console.warn(HmrClient.logPrefix, 'Cannot find update. Need to do a full reload!');
console.warn(HmrClient.logPrefix, '(Probably because of restarting the webpack-dev-server)');
return;
}
var applyCallback = function applyCallback(applyErr, renewedModules) {
if (applyErr) {
_this.handleError(applyErr);
return;
}
return module.hot.apply({
ignoreUnaccepted: true,
ignoreDeclined: true,
ignoreErrored: true,
onUnaccepted: function onUnaccepted(data) {
console.warn('Ignored an update to unaccepted module ' + data.chain.join(' -> '));
},
onDeclined: function onDeclined(data) {
console.warn('Ignored an update to declined module ' + data.chain.join(' -> '));
},
onErrored: function onErrored(data) {
console.warn('Ignored an error while updating module ' + data.moduleId + ' (' + data.type + ')');
}
}).then(function (renewedModules) {
if (!_this.upToDate()) {
_this.check();
}
if (!_this.upToDate()) {
_this.check();
}
HmrClient.logApplyResult(updatedModules, renewedModules);
HmrClient.logApplyResult(updatedModules, renewedModules);
};
if (_this.upToDate()) {
console.log(HmrClient.logPrefix, 'App is up to date.');
}
});
}).catch(function (err) {
var status = module.hot.status();
if (['abort', 'fail'].indexOf(status) >= 0) {
console.warn(HmrClient.logPrefix, 'Cannot check for update. Need to do a full reload!');
console.warn(HmrClient.logPrefix, err.stack || err.message);
} else {
console.warn(HmrClient.logPrefix, 'Update check failed: ' + err.stack || err.message);
var applyResult = module.hot.apply({
ignoreUnaccepted: true,
ignoreDeclined: true,
ignoreErrored: true,
onUnaccepted: function onUnaccepted(data) {
console.warn('Ignored an update to unaccepted module ' + data.chain.join(' -> '));
},
onDeclined: function onDeclined(data) {
console.warn('Ignored an update to declined module ' + data.chain.join(' -> '));
},
onErrored: function onErrored(data) {
console.warn('Ignored an error while updating module ' + data.moduleId + ' (' + data.type + ')');
}
});
}, applyCallback);
// webpack 2 promise
if (applyResult && applyResult.then) {
applyResult.then(function (renewedModules) {
return applyCallback(null, renewedModules);
}).catch(applyCallback);
}
};
var result = module.hot.check(false, cb);
// webpack 2 promise
if (result && result.then) {
result.then(function (updatedModules) {
return cb(null, updatedModules);
}).catch(cb);
}
});
};
}

@@ -122,3 +139,3 @@

if (unacceptedModules.length > 0) {
console.warn(HmrClient.logPrefix, "The following modules couldn't be hot updated: (They would need a full reload!)");
console.warn(HmrClient.logPrefix, "The following modules couldn't be hot updated: (They would need a full reload!)\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) {

@@ -143,2 +160,6 @@ console.warn(HmrClient.logPrefix, ' - ' + moduleId);

}
if (this.upToDate()) {
console.log(HmrClient.logPrefix, 'App is up to date.');
}
}

@@ -150,7 +171,3 @@ }]);

Object.defineProperty(HmrClient, 'logPrefix', {
enumerable: true,
writable: true,
value: _LogColors2.default.cyan('[HMR]')
});
HmrClient.logPrefix = _LogColors2.default.cyan('[HMR]');
exports.default = new HmrClient().run();

@@ -81,5 +81,9 @@ 'use strict';

if (typeof options.error !== 'function') options.error = console.error.bind(console);
if (typeof options.watchOptions.aggregateTimeout === 'undefined') options.watchOptions.aggregateTimeout = 200;
if (typeof options.watchOptions.aggregateTimeout === 'undefined') {
options.watchOptions.aggregateTimeout = 200;
}
if (typeof options.stats === 'undefined') options.stats = {};
if (_typeof(options.stats) === 'object' && !options.stats.context) options.stats.context = process.cwd();
if (_typeof(options.stats) === 'object' && !options.stats.context) {
options.stats.context = process.cwd();
}
var compiler = this.context.compiler;

@@ -101,149 +105,126 @@ if (typeof compiler.outputPath === 'string' && !_pathIsAbsolute2.default.posix(compiler.outputPath) && !_pathIsAbsolute2.default.win32(compiler.outputPath)) {

Object.defineProperty(this, 'sendMessage', {
enumerable: true,
writable: true,
value: function value(action) {
_this.context.serverProcess && _this.context.serverProcess.send({
action: action,
stats: _this.context.webpackStats.toJson()
this.sendMessage = function (action) {
_this.context.serverProcess && _this.context.serverProcess.send({
action: action,
stats: _this.context.webpackStats.toJson()
});
};
this.forkProcess = function (stats) {
var getLauncherFileName = function getLauncherFileName() {
var assets = stats.compilation.assets;
var names = Object.getOwnPropertyNames(assets).filter(function (k) {
return assets[k].emitted && _path2.default.extname(assets[k].existsAt) === '.js';
});
}
});
Object.defineProperty(this, 'forkProcess', {
enumerable: true,
writable: true,
value: function value(stats) {
var getLauncherFileName = function getLauncherFileName() {
var assets = stats.compilation.assets;
var names = Object.getOwnPropertyNames(assets).filter(function (k) {
return assets[k].emitted && _path2.default.extname(assets[k].existsAt) === '.js';
});
if (names.length === 1) {
// Only one valid assets, so just return it path
return assets[names[0]].existsAt;
} else {
// Create temp launcher file which aggregates all assets.
var launcherString = names.map(function (k) {
return 'require(\'' + assets[k].existsAt.replace(/\\/g, '/') + '\');';
}).join('\n');
if (names.length === 1) {
// Only one valid assets, so just return it path
return assets[names[0]].existsAt;
}
// Create temp launcher file which aggregates all assets.
var launcherString = names.map(function (k) {
return 'require(\'' + assets[k].existsAt.replace(/\\/g, '/') + '\');';
}).join('\n');
var launcherFileName = _path2.default.resolve(stats.compilation.compiler.outputPath, 'launcher.' + stats.hash + '.js');
_this.context.fs.writeFileSync(launcherFileName, launcherString);
var launcherFileName = _path2.default.resolve(stats.compilation.compiler.outputPath, 'launcher.' + stats.hash + '.js');
_this.context.fs.writeFileSync(launcherFileName, launcherString);
// Delete created files on exit main process.
process.on('exit', function () {
_this.context.fs.unlinkSync(launcherFileName);
});
process.on('SIGINT', function () {
_this.context.fs.unlinkSync(launcherFileName);
});
// Delete created files on exit main process.
process.on('exit', function () {
_this.context.fs.unlinkSync(launcherFileName);
});
process.on('SIGINT', function () {
_this.context.fs.unlinkSync(launcherFileName);
});
return launcherFileName;
}
};
return launcherFileName;
};
// Execute built scripts
var options = {
cwd: process.cwd(),
env: process.env
};
if (process.getuid) {
options.uid = process.getuid();
options.gid = process.getgid();
}
_this.context.serverProcess = (0, _child_process.fork)(getLauncherFileName(), process.argv, options);
// Listen for serverProcess events.
_this.context.serverProcess.on('exit', function (code) {
// Exit node process when exit serverProcess.
process.exit(code);
});
// Execute built scripts
var options = {
cwd: process.cwd(),
env: process.env
};
if (process.getuid) {
options.uid = process.getuid();
options.gid = process.getgid();
}
});
Object.defineProperty(this, 'compilerDone', {
enumerable: true,
writable: true,
value: function value(stats) {
// We are now on valid state
_this.context.state = true;
_this.context.webpackStats = stats;
_this.context.serverProcess = (0, _child_process.fork)(getLauncherFileName(), process.argv, options);
// Do the stuff in nextTick, because bundle may be invalidated
// if a change happened while compiling
process.nextTick(function () {
// check if still in valid state
if (!_this.context.state) return;
// Listen for serverProcess events.
_this.context.serverProcess.on('exit', function (code) {
// Exit node process when exit serverProcess.
process.exit(code);
});
};
// print webpack output
_this.context.options.reporter({
state: true,
stats: stats,
options: _this.context.options
});
this.compilerDone = function (stats) {
// We are now on valid state
_this.context.state = true;
_this.context.webpackStats = stats;
if (_this.context.serverProcess) {
_this.sendMessage('built');
} else {
// Start compiled files in child process.
_this.forkProcess(stats);
}
// Do the stuff in nextTick, because bundle may be invalidated
// if a change happened while compiling
process.nextTick(function () {
// check if still in valid state
if (!_this.context.state) return;
// print webpack output
_this.context.options.reporter({
state: true,
stats: stats,
options: _this.context.options
});
}
});
Object.defineProperty(this, 'compilerInvalid', {
enumerable: true,
writable: true,
value: function value() {
_this.sendMessage('compile');
if (_this.context.state && !_this.context.options.noInfo && !_this.context.options.quiet) {
_this.context.options.reporter({
state: false,
options: _this.context.options
});
if (_this.context.serverProcess) {
_this.sendMessage('built');
} else {
// Start compiled files in child process.
_this.forkProcess(stats);
}
});
};
// We are now in invalid state
_this.context.state = false;
// resolve async
if (_arguments.length === 2 && typeof _arguments[1] === 'function') {
var callback = _arguments[1];
callback();
}
this.compilerInvalid = function () {
_this.sendMessage('compile');
if (_this.context.state && !_this.context.options.noInfo && !_this.context.options.quiet) {
_this.context.options.reporter({
state: false,
options: _this.context.options
});
}
});
Object.defineProperty(this, 'compilerWatch', {
enumerable: true,
writable: true,
value: function value(err) {
if (err) {
_this.context.options.error(err.stack || err);
if (err.details) _this.context.options.error(err.details);
}
// We are now in invalid state
_this.context.state = false;
// resolve async
if (_arguments.length === 2 && typeof _arguments[1] === 'function') {
var callback = _arguments[1];
callback();
}
});
Object.defineProperty(this, 'startWatch', {
enumerable: true,
writable: true,
value: function value() {
var options = _this.context.options;
var compiler = _this.context.compiler;
// start watching
_this.context.watching = compiler.watch(options.watchOptions, _this.compilerWatch);
console.info(_LogColors2.default.cyan('[HMR]'), 'Waiting webpack...');
};
this.compilerWatch = function (err) {
if (err) {
_this.context.options.error(err.stack || err);
if (err.details) _this.context.options.error(err.details);
}
});
Object.defineProperty(this, 'run', {
enumerable: true,
writable: true,
value: function value() {
_this.context.compiler.plugin('done', _this.compilerDone);
_this.context.compiler.plugin('compile', _this.compilerInvalid);
_this.startWatch();
return _this;
}
});
};
this.startWatch = function () {
var options = _this.context.options;
var compiler = _this.context.compiler;
// start watching
_this.context.watching = compiler.watch(options.watchOptions, _this.compilerWatch);
console.info(_LogColors2.default.cyan('[HMR]'), 'Waiting webpack...');
};
this.run = function () {
_this.context.compiler.plugin('done', _this.compilerDone);
_this.context.compiler.plugin('compile', _this.compilerInvalid);
_this.startWatch();
return _this;
};
};
exports.default = HmrServer;

@@ -6,6 +6,9 @@ 'use strict';

});
exports.loader = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.default = loader;
var _webpack = require('webpack');

@@ -33,3 +36,5 @@

}) : webpackConfig;
if (config.target !== 'node') throw new Error('Webpack configuration file must provide config with target "node".');
if (config.target !== 'node') {
throw new Error('Webpack configuration file must provide config with target "node".');
}

@@ -43,5 +48,7 @@ var hmrClientEntry = _path2.default.resolve(process.cwd(), 'node_modules/node-hot-loader/lib/HmrClient');

addHmrClientEntry(entry, owner);
} else if (_typeof(owner[entry]) === 'object') Object.getOwnPropertyNames(owner[entry]).forEach(function (name) {
return addHmrClientEntry(name, owner[entry]);
});
} else if (_typeof(owner[entry]) === 'object') {
Object.getOwnPropertyNames(owner[entry]).forEach(function (name) {
return addHmrClientEntry(name, owner[entry]);
});
}
};

@@ -110,3 +117,3 @@

function loader(options) {
options = Object.assign(defaultOptions, options);
options = _extends({}, defaultOptions, options);
Promise.resolve().then(function (config) {

@@ -129,4 +136,2 @@ return Promise.resolve().then(function () {

});
}
exports.loader = loader;
}

@@ -13,14 +13,11 @@ 'use strict';

Object.defineProperty(LogColors, 'defaultColors', {
enumerable: true,
writable: true,
value: {
bold: '\x1B[1m',
yellow: '\x1B[1m\x1B[33m',
red: '\x1B[1m\x1B[31m',
green: '\x1B[1m\x1B[32m',
cyan: '\x1B[1m\x1B[36m',
magenta: '\x1B[1m\x1B[35m'
}
});
LogColors.defaultColors = {
bold: '\x1B[1m',
yellow: '\x1B[1m\x1B[33m',
red: '\x1B[1m\x1B[31m',
green: '\x1B[1m\x1B[32m',
cyan: '\x1B[1m\x1B[36m',
magenta: '\x1B[1m\x1B[35m'
};
exports.default = LogColors;

@@ -33,4 +30,2 @@

return obj;
}, LogColors);
exports.default = LogColors;
}, LogColors);

@@ -18,2 +18,4 @@ #!/usr/bin/env node

var _loader2 = _interopRequireDefault(_loader);
var _package = require('../package.json');

@@ -47,2 +49,2 @@

(0, _loader.loader)(options);
(0, _loader2.default)(options);
{
"name": "node-hot-loader",
"version": "0.3.10",
"version": "1.0.0",
"description": "Hot module replacement for Node.js applications",

@@ -14,6 +14,5 @@ "main": "./lib/node-hot.js",

"prepublishOnly": "npm run clean && npm run build",
"patch-release": "npm version patch && npm publish && git push --follow-tags",
"minor-release": "npm version minor && npm publish && git push --follow-tags",
"patch": "npm version patch",
"deploy": "npm publish",
"patch-publish": "npm version patch && npm publish && git push --follow-tags",
"minor-publish": "npm version minor && npm publish && git push --follow-tags",
"major-publish": "npm version major && npm publish && git push --follow-tags",
"unpublish": "---npm unpublish node-hot-loader@0.1.0"

@@ -66,4 +65,6 @@ },

"babel-cli": "^6.26.0",
"babel-eslint": "^8.0.0",
"babel-plugin-dynamic-import-node": "^1.0.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.0",

@@ -73,4 +74,6 @@ "eslint": "^4.5.0",

"eslint-plugin-import": "^2.7.0",
"prettier": "^1.7.0",
"prettier-eslint": "^8.1.0",
"rimraf": "^2.6.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc