Skip to content
This repository was archived by the owner on Mar 4, 2022. It is now read-only.

Commit 2057f48

Browse files
authored
Chore: Misc infrastructure updates (#104)
- Upgrade all prod + dev dependencies - BREAKING: Update node engines - Switch istanbul to nyc. - Update to es-next code from at least auto-fixes.
1 parent 74ab60f commit 2057f48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3175
-2618
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
---
22
extends:
3-
- "formidable/configurations/es5-node"
3+
- "formidable/configurations/es6-node"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
npm-debug.log
33
coverage
44
.vscode
5+
.nyc_output

.nycrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"include": [
3+
"*.js",
4+
"bin/**/*.js",
5+
"lib/**/*.js"
6+
],
7+
"reporter": [
8+
"lcov",
9+
"text"
10+
],
11+
"all": true
12+
}

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ branches:
77
- master
88

99
node_js:
10-
- "4"
11-
- "6"
1210
- "8"
11+
- "10"
12+
- "12"
13+
- "13"

bin/nodejs-dashboard.js

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#!/usr/bin/env node
2+
23
"use strict";
34

4-
var SocketIO = require("socket.io");
5-
var spawn = require("cross-spawn");
6-
var commander = require("commander");
7-
var path = require("path");
5+
const SocketIO = require("socket.io");
6+
const spawn = require("cross-spawn");
7+
const commander = require("commander");
8+
const path = require("path");
89

9-
var Dashboard = require("../lib/dashboard");
10-
var config = require("../lib/config");
11-
var appPkg = require(path.resolve("package.json"));
12-
var pkg = require("../package.json");
13-
var parseSettings = require("../lib/parse-settings");
10+
const Dashboard = require("../lib/dashboard");
11+
const config = require("../lib/config");
12+
const appPkg = require(path.resolve("package.json"));
13+
const pkg = require("../package.json");
14+
const parseSettings = require("../lib/parse-settings");
1415

15-
var appName = appPkg.name || "node";
16-
var program = new commander.Command(pkg.name);
16+
const appName = appPkg.name || "node";
17+
const program = new commander.Command(pkg.name);
1718

1819
// Mimic commander syntax errors (with offsets) for consistency
1920
/* eslint-disable no-console */
20-
var exitWithError = function () {
21-
var args = Array.prototype.slice.call(arguments);
21+
const exitWithError = function () {
22+
const args = Array.prototype.slice.call(arguments);
2223
console.error();
23-
console.error.apply(console, [" "].concat(args));
24+
console.error(...[" "].concat(args));
2425
console.error();
2526
process.exit(1); // eslint-disable-line no-process-exit
2627
};
@@ -44,8 +45,8 @@ program.option("-r, --refreshinterval [ms]",
4445

4546
program.option("-s, --settings [settings]",
4647
"Overrides layout settings for given view types",
47-
function (settings) {
48-
var res = parseSettings(settings);
48+
(settings) => {
49+
const res = parseSettings(settings);
4950

5051
if (res.error) {
5152
exitWithError(res.error);
@@ -65,51 +66,54 @@ if (!program.args.length) {
6566
return;
6667
}
6768

68-
var command = program.args[0];
69-
var args = program.args.slice(1);
69+
const command = program.args[0];
70+
const args = program.args.slice(1);
7071

71-
var port = program.port;
72+
const port = program.port;
7273

7374
process.env[config.PORT_KEY] = port;
7475
process.env[config.REFRESH_INTERVAL_KEY] = program.refreshinterval;
7576
process.env[config.BLOCKED_THRESHOLD_KEY] = program.eventdelay;
7677

7778

78-
var child = spawn(command, args, {
79+
const child = spawn(command, args, {
7980
env: process.env,
8081
stdio: [null, null, null, null],
8182
detached: true
8283
});
8384

8485
console.log("Waiting for client connection on %d...", port); //eslint-disable-line
8586

86-
var server = new SocketIO(port);
87+
const server = new SocketIO(port);
8788

88-
var dashboard = new Dashboard({
89-
appName: appName,
90-
program: program,
89+
const dashboard = new Dashboard({
90+
appName,
91+
program,
9192
layoutsFile: program.layouts,
9293
settings: program.settings
9394
});
9495

95-
server.on("connection", function (socket) {
96-
socket.on("metrics", function (data) {
97-
dashboard.onEvent({ type: "metrics", data: JSON.parse(data) });
96+
server.on("connection", (socket) => {
97+
socket.on("metrics", (data) => {
98+
dashboard.onEvent({ type: "metrics",
99+
data: JSON.parse(data) });
98100
});
99101

100-
socket.on("error", function (err) {
102+
socket.on("error", (err) => {
101103
exitWithError("Received error from agent, exiting: ", err);
102104
});
103105
});
104106

105-
child.stdout.on("data", function (data) {
106-
dashboard.onEvent({ type: "stdout", data: data.toString("utf8") });
107+
child.stdout.on("data", (data) => {
108+
dashboard.onEvent({ type: "stdout",
109+
data: data.toString("utf8") });
107110
});
108111

109-
child.stderr.on("data", function (data) {
110-
dashboard.onEvent({ type: "stderr", data: data.toString("utf8") });
112+
child.stderr.on("data", (data) => {
113+
dashboard.onEvent({ type: "stderr",
114+
data: data.toString("utf8") });
111115
});
112116

113-
process.on("exit", function () {
117+
process.on("exit", () => {
114118
process.kill(process.platform === "win32" ? child.pid : -child.pid);
115119
});

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict";
2-
var dashboardAgent = require("./lib/dashboard-agent");
2+
3+
const dashboardAgent = require("./lib/dashboard-agent");
34

45
module.exports = dashboardAgent();

lib/config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"use strict";
22

3-
var pkg = require("../package.json");
3+
const pkg = require("../package.json");
44
// Env var names must comply with:
55
// http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html
66
// See: https://github.com/FormidableLabs/nodejs-dashboard/issues/75
7-
var name = pkg.name.replace("-", "_");
7+
const name = pkg.name.replace("-", "_");
88

99
module.exports = {
1010
PORT: 9838,
11-
PORT_KEY: name + "_PORT",
11+
PORT_KEY: `${name}_PORT`,
1212
REFRESH_INTERVAL: 1000,
13-
REFRESH_INTERVAL_KEY: name + "_REFRESH_INTERVAL",
13+
REFRESH_INTERVAL_KEY: `${name}_REFRESH_INTERVAL`,
1414
BLOCKED_THRESHOLD: 10,
15-
BLOCKED_THRESHOLD_KEY: name + "_BLOCKED_THRESHOLD",
15+
BLOCKED_THRESHOLD_KEY: `${name}_BLOCKED_THRESHOLD`,
1616
LAYOUTS: ""
1717
};

lib/constants.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// will be at 5s increments of time
1010
//
1111
// 300000 = 30s and the corresponding zoom will show 30s aggregates
12-
var AGGREGATE_TIME_LEVELS = [
12+
const AGGREGATE_TIME_LEVELS = [
1313
"1000",
1414
"5000",
1515
"10000",
@@ -23,11 +23,11 @@ var AGGREGATE_TIME_LEVELS = [
2323
"3600000"
2424
];
2525

26-
var MILLISECONDS_PER_SECOND = 1000;
26+
const MILLISECONDS_PER_SECOND = 1000;
2727

2828
// this array object is used to reduce ms to its highest human-readable form
2929
// see lib/providers/metrics-provider.js::getTimeIndexLabel
30-
var TIME_SCALES = [
30+
const TIME_SCALES = [
3131
{
3232
units: "ms",
3333
divisor: 1
@@ -50,7 +50,7 @@ var TIME_SCALES = [
5050
];
5151

5252
module.exports = {
53-
AGGREGATE_TIME_LEVELS: AGGREGATE_TIME_LEVELS,
54-
MILLISECONDS_PER_SECOND: MILLISECONDS_PER_SECOND,
55-
TIME_SCALES: TIME_SCALES
53+
AGGREGATE_TIME_LEVELS,
54+
MILLISECONDS_PER_SECOND,
55+
TIME_SCALES
5656
};

lib/dashboard-agent.js

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
"use strict";
22

3-
var SocketIO = require("socket.io-client");
4-
var blocked = require("blocked");
5-
var pusage = require("pidusage");
6-
var os = require("os");
7-
var _ = require("lodash");
8-
var config = require("./config");
9-
10-
var dashboardAgent = function () {
11-
12-
var options = {
3+
const SocketIO = require("socket.io-client");
4+
const blocked = require("blocked");
5+
const pusage = require("pidusage");
6+
const os = require("os");
7+
const _ = require("lodash");
8+
const config = require("./config");
9+
10+
const dashboardAgent = function () {
11+
const options = {
1312
port: process.env[config.PORT_KEY],
1413
refreshInterval: process.env[config.REFRESH_INTERVAL_KEY],
1514
blockedThreshold: process.env[config.BLOCKED_THRESHOLD_KEY]
1615
};
1716

1817
// check if the app was launched w/o the dashboard
1918
// if so, don't start any of the monitoring
20-
var enabled = options.port && options.refreshInterval && options.blockedThreshold;
19+
const enabled = options.port && options.refreshInterval && options.blockedThreshold;
2120

22-
var socket;
21+
let socket;
2322

24-
var metrics = {
23+
const metrics = {
2524
eventLoop: {
2625
delay: 0,
2726
high: 0
@@ -34,33 +33,30 @@ var dashboardAgent = function () {
3433
}
3534
};
3635

37-
var _delayed = function (delay) {
36+
const _delayed = function (delay) {
3837
metrics.eventLoop.high = Math.max(metrics.eventLoop.high, delay);
3938
metrics.eventLoop.delay = delay;
4039
};
4140

42-
var _getStats = function (cb) {
41+
const _getStats = function (cb) {
4342
_.merge(metrics.mem, process.memoryUsage());
4443

45-
pusage.stat(process.pid, function (err, stat) {
46-
44+
pusage(process.pid, (err, stat) => {
4745
if (err) {
4846
return cb(err);
4947
}
5048

5149
metrics.cpu.utilization = stat.cpu;
5250
return cb(null, metrics);
5351
});
54-
5552
};
5653

57-
var resetEventMetrics = function () {
54+
const resetEventMetrics = function () {
5855
metrics.eventLoop.delay = 0;
5956
};
6057

61-
var _emitStats = function () {
62-
63-
_getStats(function (err, newMetrics) {
58+
const _emitStats = function () {
59+
_getStats((err, newMetrics) => {
6460
if (err) {
6561
console.error("Failed to load metrics: ", err); //eslint-disable-line
6662
if (socket && socket.connected) {
@@ -72,18 +68,17 @@ var dashboardAgent = function () {
7268

7369
resetEventMetrics();
7470
});
75-
7671
};
7772

78-
var startPump = function () {
73+
const startPump = function () {
7974
if (enabled) {
80-
socket = new SocketIO("http://localhost:" + options.port);
75+
socket = new SocketIO(`http://localhost:${options.port}`);
8176
blocked(_delayed, { threshold: options.blockedThreshold });
8277
options.intervalId = setInterval(_emitStats, options.refreshInterval);
8378
}
8479
};
8580

86-
var destroy = function () {
81+
const destroy = function () {
8782
if (socket) {
8883
socket.close();
8984
socket = null;
@@ -97,10 +92,10 @@ var dashboardAgent = function () {
9792
startPump();
9893

9994
return {
100-
_delayed: _delayed,
101-
_getStats: _getStats,
102-
_emitStats: _emitStats,
103-
destroy: destroy
95+
_delayed,
96+
_getStats,
97+
_emitStats,
98+
destroy
10499
};
105100
};
106101

0 commit comments

Comments
 (0)