Skip to content

Commit 6da9d39

Browse files
committed
v5.1.0 / 2020-07-28
1 parent 624665a commit 6da9d39

12 files changed

+42
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# node-dev
22

3+
## v5.1.0 / 2020-07-28
4+
5+
- [wrap.js] Improve uncaughtException handling to turn non-errors into errors (Fixes #231)
6+
- [ipc.js] Declare `NODE_DEV` as a variable
7+
- [ipc.js] Inline single line function only used twice
8+
- [tests] Filenames should be snake-case
9+
310
## v5.0.0 / 2020-07-08
411

512
- Remove `--all-deps` and `--no-deps` CLI options, use `--deps=-1` or `--deps=0` respectively

lib/ipc.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
/**
2-
* Checks if the given message is an internal node-dev message.
3-
*/
4-
function isNodeDevMessage(m) {
5-
return m.cmd === 'NODE_DEV';
6-
}
1+
const NODE_DEV = 'NODE_DEV';
72

83
/**
94
* Sends a message to the given process.
105
*/
116
exports.send = function (m, dest) {
12-
m.cmd = 'NODE_DEV';
7+
m.cmd = NODE_DEV;
138
if (!dest) dest = process;
149
if (dest.send) dest.send(m);
1510
};
1611

1712
exports.on = function (proc, type, cb) {
1813
function handleMessage(m) {
19-
if (isNodeDevMessage(m) && type in m) cb(m);
14+
if (m.cmd === NODE_DEV && type in m) cb(m);
2015
}
2116
proc.on('internalMessage', handleMessage);
2217
proc.on('message', handleMessage);
@@ -25,7 +20,7 @@ exports.on = function (proc, type, cb) {
2520
exports.relay = function (src, dest) {
2621
if (!dest) dest = process;
2722
function relayMessage(m) {
28-
if (isNodeDevMessage(m)) dest.send(m);
23+
if (m.cmd === NODE_DEV) dest.send(m);
2924
}
3025
src.on('internalMessage', relayMessage);
3126
src.on('message', relayMessage);

lib/wrap.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ if (fork) {
3535

3636
// Error handler that displays a notification and logs the stack to stderr:
3737
process.on('uncaughtException', function (err) {
38-
console.error(err.stack || err);
38+
// Sometimes uncaught exceptions are not errors
39+
const { message, name, stack } = err instanceof Error ? err : new Error(`uncaughtException ${err}`);
40+
41+
console.error(stack);
42+
3943
// If there's a custom uncaughtException handler expect it to terminate
4044
// the process.
41-
const hasCustomHandler = process.listeners('uncaughtException').length > 1;
42-
ipc.send({
43-
error: err.name || 'Error',
44-
message: err.message,
45-
willTerminate: hasCustomHandler
46-
});
45+
const willTerminate = process.listeners('uncaughtException').length > 1;
46+
47+
ipc.send({ error: name, message, willTerminate });
4748
});
4849

4950
// Hook into require() and notify the parent process about required files

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-dev",
3-
"version": "5.0.0",
3+
"version": "5.1.0",
44
"description": "Restarts your app when files are modified",
55
"keywords": [
66
"restart",

test/fixture/.node-dev.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"notify": false,
33
"ignore": [
4-
"./ignoredModule.js"
4+
"./ignored-module.js"
55
],
66
"extensions": {
77
"coffee": "coffeescript/register",

test/fixture/error-null.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require('./message');
2+
3+
// eslint-disable-next-line no-throw-literal
4+
throw null;
File renamed without changes.
File renamed without changes.

test/fixture/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var http = require('http');
22
var message = require('./message');
33

44
// Changes to this module should not cause a server restart:
5-
require('./ignoredModule');
5+
require('./ignored-module');
66

77
var server = http.createServer(function (req, res) {
88
res.writeHead(200, { 'Content-Type': 'text/plain' });

0 commit comments

Comments
 (0)