Merge pull request #1727 from thelounge/astorije/node-6

Switch to Node v6 as the minimal supported version
This commit is contained in:
Pavel Djundik 2018-02-19 18:41:23 +02:00 committed by GitHub
commit 0044be266e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 101 additions and 101 deletions

View file

@ -42,13 +42,17 @@ rules:
no-trailing-spaces: error
no-unsafe-negation: error
no-useless-computed-key: error
no-useless-constructor: error
no-useless-return: error
no-use-before-define: [error, {functions: false}]
object-curly-spacing: [error, never]
padded-blocks: [error, never]
prefer-const: error
prefer-rest-params: error
prefer-spread: error
quote-props: [error, as-needed]
quotes: [error, double, avoid-escape]
rest-spread-spacing: error
semi-spacing: error
semi-style: [error, last]
semi: [error, always]

View file

@ -3,7 +3,6 @@ node_js:
- 9 # Current stable
- 8 # Active LTS until April 2019
- 6 # Active LTS until April 2018
- 4 # Maintenance LTS until 2018-04-01, will be dropped in The Lounge v3
matrix:
fast_finish: true

View file

@ -11,7 +11,7 @@ skip_tags: true
skip_branch_with_pr: true
environment:
nodejs_version: '4'
nodejs_version: '6'
install:
- ps: Install-Product node $env:nodejs_version

View file

@ -89,9 +89,9 @@ function onPushButton() {
userVisibleOnly: true,
}).then((subscription) => {
const rawKey = subscription.getKey ? subscription.getKey("p256dh") : "";
const key = rawKey ? window.btoa(String.fromCharCode.apply(null, new Uint8Array(rawKey))) : "";
const key = rawKey ? window.btoa(String.fromCharCode(...new Uint8Array(rawKey))) : "";
const rawAuthSecret = subscription.getKey ? subscription.getKey("auth") : "";
const authSecret = rawAuthSecret ? window.btoa(String.fromCharCode.apply(null, new Uint8Array(rawAuthSecret))) : "";
const authSecret = rawAuthSecret ? window.btoa(String.fromCharCode(...new Uint8Array(rawAuthSecret))) : "";
socket.emit("push:register", {
token: storage.get("token"),

View file

@ -5,14 +5,33 @@
process.chdir(__dirname);
// Perform node version check before loading any other files or modules
// Doing this check as soon as possible allows us to avoid ES6 parser errors or other issues
// Doing this check as soon as possible allows us to avoid ES6 parser errors or
// other issues
// Try to display messages nicely, but gracefully degrade if anything goes wrong
var pkg = require("./package.json");
if (!require("semver").satisfies(process.version, pkg.engines.node)) {
/* eslint-disable no-console */
console.error("=== WARNING!");
console.error("=== The oldest supported Node.js version is", pkg.engines.node);
console.error("=== We strongly encourage you to upgrade, see https://nodejs.org/en/download/package-manager/ for more details\n");
/* eslint-enable no-console */
let colors;
let log;
try {
colors = require("colors/safe");
} catch (e) {
colors = {};
colors.green = colors.red = colors.bold = (x) => x;
}
try {
log = require("./src/log");
} catch (e) {
log = {};
log.error = (msg) => console.error(`[ERROR] ${msg}`); // eslint-disable-line no-console
}
log.error(`The Lounge requires Node.js ${colors.green(pkg.engines.node)} (current version: ${colors.red(process.version)})`);
log.error(colors.bold("Please upgrade Node.js in order to use The Lounge"));
log.error("See https://nodejs.org/en/download/package-manager/ for more details");
process.exit(1);
}
require("./src/command-line");

View file

@ -35,7 +35,7 @@
],
"license": "MIT",
"engines": {
"node": ">=4.2.0"
"node": ">=6"
},
"dependencies": {
"bcryptjs": "2.4.3",

View file

@ -16,7 +16,7 @@ request.get({
const shortname = prepareShortName(emojiStrategy[key].shortname);
// Skip tones, at least for now
if (shortname.indexOf("tone") > -1) {
if (shortname.includes("tone")) {
continue;
}

View file

@ -65,11 +65,7 @@ var inputs = [
return plugins;
}, {});
function Client(manager, name, config) {
if (typeof config !== "object") {
config = {};
}
function Client(manager, name, config = {}) {
_.merge(this, {
awayMessage: config.awayMessage || "",
lastActiveChannel: -1,

View file

@ -10,11 +10,6 @@ const colors = require("colors/safe");
const Helper = require("../helper");
const Utils = require("./utils");
if (require("semver").lt(process.version, "6.0.0")) {
log.warn(`Support of Node.js v4 is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3.`);
log.warn("Please upgrade to Node.js v6 or more recent.");
}
program.version(Helper.getVersion(), "-v, --version")
.option("--home <path>", `${colors.bold.red("[DEPRECATED]")} Use the ${colors.green("THELOUNGE_HOME")} environment variable instead.`)
.option(

View file

@ -24,7 +24,7 @@ program
return;
}
if (users.indexOf(name) !== -1) {
if (users.includes(name)) {
log.error(`User ${colors.bold(name)} already exists.`);
return;
}

View file

@ -24,7 +24,7 @@ program
return;
}
if (users.indexOf(name) === -1) {
if (!users.includes(name)) {
log.error(`User ${colors.bold(name)} does not exist.`);
return;
}

View file

@ -23,7 +23,7 @@ program
return;
}
if (users.indexOf(name) === -1) {
if (!users.includes(name)) {
log.error(`User ${colors.bold(name)} does not exist.`);
return;
}

View file

@ -5,41 +5,38 @@ var moment = require("moment");
const read = require("read");
var Helper = require("./helper");
function timestamp(type, messageArgs) {
var format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
var tz = Helper.config.logs.timezone || "UTC+00:00";
function timestamp() {
const format = Helper.config.logs.format || "YYYY-MM-DD HH:mm:ss";
const tz = Helper.config.logs.timezone || "UTC+00:00";
const time = moment().utcOffset(tz).format(format);
var time = moment().utcOffset(tz).format(format);
Array.prototype.unshift.call(messageArgs, colors.dim(time), type);
return messageArgs;
return colors.dim(time);
}
/* eslint-disable no-console */
exports.error = function() {
console.error.apply(console, timestamp(colors.red("[ERROR]"), arguments));
exports.error = function(...args) {
console.error(timestamp(), colors.red("[ERROR]"), ...args);
};
exports.warn = function() {
console.error.apply(console, timestamp(colors.yellow("[WARN]"), arguments));
exports.warn = function(...args) {
console.error(timestamp(), colors.yellow("[WARN]"), ...args);
};
exports.info = function() {
console.log.apply(console, timestamp(colors.blue("[INFO]"), arguments));
exports.info = function(...args) {
console.log(timestamp(), colors.blue("[INFO]"), ...args);
};
exports.debug = function() {
console.log.apply(console, timestamp(colors.green("[DEBUG]"), arguments));
exports.debug = function(...args) {
console.log(timestamp(), colors.green("[DEBUG]"), ...args);
};
exports.raw = function() {
console.log.apply(console, arguments);
exports.raw = function(...args) {
console.log(...args);
};
/* eslint-enable no-console */
exports.prompt = (options, callback) => {
options.prompt = timestamp(colors.cyan("[PROMPT]"), [options.text]).join(" ");
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
read(options, callback);
};

View file

@ -5,7 +5,7 @@ var Msg = require("../../models/msg");
exports.commands = ["slap", "me"];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
if (chan.type !== Chan.Type.CHANNEL && chan.type !== Chan.Type.QUERY) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
@ -15,7 +15,6 @@ exports.input = function(network, chan, cmd, args) {
return;
}
var irc = network.irc;
var text;
switch (cmd) {
@ -31,7 +30,7 @@ exports.input = function(network, chan, cmd, args) {
irc.action(chan.name, text);
if (!network.irc.network.cap.isEnabled("echo-message")) {
if (!irc.network.cap.isEnabled("echo-message")) {
irc.emit("action", {
nick: irc.user.nick,
target: chan.name,

View file

@ -9,7 +9,7 @@ exports.commands = [
"banlist",
];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
if (chan.type !== Chan.Type.CHANNEL) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
@ -32,13 +32,13 @@ exports.input = function(network, chan, cmd, args) {
switch (cmd) {
case "ban":
network.irc.ban(chan.name, args[0]);
irc.ban(chan.name, args[0]);
break;
case "unban":
network.irc.unban(chan.name, args[0]);
irc.unban(chan.name, args[0]);
break;
case "banlist":
network.irc.banlist(chan.name);
irc.banlist(chan.name);
break;
}
};

View file

@ -5,13 +5,13 @@ var Msg = require("../../models/msg");
exports.commands = ["connect", "server"];
exports.allowDisconnected = true;
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
if (args.length === 0) {
if (!network.irc || !network.irc.connection) {
if (!irc || !irc.connection) {
return;
}
if (network.irc.connection.connected) {
if (irc.connection.connected) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: "You are already connected.",
@ -19,7 +19,7 @@ exports.input = function(network, chan, cmd, args) {
return;
}
network.irc.connection.connect();
irc.connection.connect();
return;
}

View file

@ -2,9 +2,8 @@
exports.commands = ["ctcp"];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
if (args.length > 1) {
var irc = network.irc;
irc.ctcpRequest(args[0], args.slice(1).join(" "));
}
};

View file

@ -4,8 +4,8 @@ const Helper = require("../../helper");
exports.commands = ["disconnect"];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
var quitMessage = args[0] ? args.join(" ") : Helper.config.leaveMessage;
network.irc.quit(quitMessage);
irc.quit(quitMessage);
};

View file

@ -5,9 +5,7 @@ var Msg = require("../../models/msg");
exports.commands = ["invite"];
exports.input = function(network, chan, cmd, args) {
var irc = network.irc;
exports.input = function({irc}, chan, cmd, args) {
if (args.length === 2) {
irc.raw("INVITE", args[0], args[1]); // Channel provided in the command
} else if (args.length === 1 && chan.type === Chan.Type.CHANNEL) {

View file

@ -5,7 +5,7 @@ var Msg = require("../../models/msg");
exports.commands = ["kick"];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
if (chan.type !== Chan.Type.CHANNEL) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
@ -16,7 +16,6 @@ exports.input = function(network, chan, cmd, args) {
}
if (args.length !== 0) {
var irc = network.irc;
irc.raw("KICK", chan.name, args[0], args.slice(1).join(" "));
}

View file

@ -4,6 +4,6 @@ exports.commands = ["list"];
exports.input = function(network, chan, cmd, args) {
network.chanCache = [];
network.irc.list.apply(network.irc, args);
network.irc.list(...args);
return true;
};

View file

@ -13,7 +13,7 @@ exports.commands = [
"devoice",
];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc, nick}, chan, cmd, args) {
if (cmd !== "mode") {
if (chan.type !== Chan.Type.CHANNEL) {
chan.pushMessage(this, new Msg({
@ -43,17 +43,15 @@ exports.input = function(network, chan, cmd, args) {
}[cmd];
args.forEach(function(target) {
network.irc.raw("MODE", chan.name, mode, target);
irc.raw("MODE", chan.name, mode, target);
});
return;
}
if (args.length === 0 || args[0][0] === "+" || args[0][0] === "-") {
args.unshift(chan.type === Chan.Type.CHANNEL || chan.type === Chan.Type.QUERY ? chan.name : network.nick);
args.unshift(chan.type === Chan.Type.CHANNEL || chan.type === Chan.Type.QUERY ? chan.name : nick);
}
args.unshift("MODE");
network.irc.raw.apply(network.irc, args);
irc.raw("MODE", ...args);
};

View file

@ -22,7 +22,7 @@ exports.input = function(network, chan, cmd, args) {
}
var char = target[0];
if (network.irc.network.options.CHANTYPES && network.irc.network.options.CHANTYPES.indexOf(char) !== -1) {
if (network.irc.network.options.CHANTYPES && network.irc.network.options.CHANTYPES.includes(char)) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: "You can not open query windows for channels, use /join instead.",

View file

@ -2,9 +2,8 @@
exports.commands = ["raw", "send", "quote"];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
if (args.length !== 0) {
var irc = network.irc;
irc.raw(args);
}

View file

@ -5,7 +5,7 @@ var Chan = require("../../models/chan");
exports.commands = ["cycle", "rejoin"];
exports.input = function(network, chan) {
exports.input = function({irc}, chan) {
if (chan.type !== Chan.Type.CHANNEL) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
@ -14,8 +14,8 @@ exports.input = function(network, chan) {
return;
}
network.irc.part(chan.name, "Rejoining");
network.irc.join(chan.name);
irc.part(chan.name, "Rejoining");
irc.join(chan.name);
return true;
};

View file

@ -5,7 +5,7 @@ var Msg = require("../../models/msg");
exports.commands = ["topic"];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
if (chan.type !== Chan.Type.CHANNEL) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
@ -14,6 +14,6 @@ exports.input = function(network, chan, cmd, args) {
return;
}
network.irc.setTopic(chan.name, args.join(" "));
irc.setTopic(chan.name, args.join(" "));
return true;
};

View file

@ -2,14 +2,14 @@
exports.commands = ["whois"];
exports.input = function(network, chan, cmd, args) {
exports.input = function({irc}, chan, cmd, args) {
if (args.length === 1) {
// This queries server of the other user and not of the current user, which
// does not know idle time.
// See http://superuser.com/a/272069/208074.
network.irc.raw("WHOIS", args[0], args[0]);
irc.raw("WHOIS", args[0], args[0]);
} else {
// Re-assembling the command parsed in client.js
network.irc.raw(`${cmd} ${args.join(" ")}`);
irc.raw(`${cmd} ${args.join(" ")}`);
}
};

View file

@ -114,7 +114,7 @@ module.exports = function(irc, network) {
}
// No prefetch URLs unless are simple MESSAGE or ACTION types
if ([Msg.Type.MESSAGE, Msg.Type.ACTION].indexOf(data.type) !== -1) {
if ([Msg.Type.MESSAGE, Msg.Type.ACTION].includes(data.type)) {
LinkPrefetch(client, chan, msg);
}

View file

@ -94,7 +94,7 @@ module.exports = function(irc, network) {
if (!add) {
_.pull(user.modes, changedMode);
} else if (user.modes.indexOf(changedMode) === -1) {
} else if (!user.modes.includes(changedMode)) {
user.modes.push(changedMode);
user.modes.sort(function(a, b) {
return userModeSortPriority[a] - userModeSortPriority[b];

View file

@ -38,13 +38,13 @@ class WebPush {
}
push(client, payload, onlyToOffline) {
_.forOwn(client.config.sessions, (session, token) => {
if (session.pushSubscription) {
if (onlyToOffline && _.find(client.attachedClients, {token: token}) !== undefined) {
_.forOwn(client.config.sessions, ({pushSubscription}, token) => {
if (pushSubscription) {
if (onlyToOffline && _.find(client.attachedClients, {token}) !== undefined) {
return;
}
this.pushSingle(client, session.pushSubscription, payload);
this.pushSingle(client, pushSubscription, payload);
}
});
}
@ -56,8 +56,8 @@ class WebPush {
if (error.statusCode >= 400 && error.statusCode < 500) {
log.warn(`WebPush subscription for ${client.name} returned an error (${error.statusCode}), removing subscription`);
_.forOwn(client.config.sessions, (session, token) => {
if (session.pushSubscription && session.pushSubscription.endpoint === subscription.endpoint) {
_.forOwn(client.config.sessions, ({pushSubscription}, token) => {
if (pushSubscription && pushSubscription.endpoint === subscription.endpoint) {
client.unregisterPushSubscription(token);
}
});

View file

@ -20,8 +20,8 @@ describe("Commands", function() {
lastCommand: null,
nick: "xPaw",
irc: {
raw: function() {
testableNetwork.lastCommand = Array.prototype.join.call(arguments, " ");
raw: function(...args) {
testableNetwork.lastCommand = args.join(" ");
},
},
};

View file

@ -24,11 +24,9 @@ MockClient.prototype.createMessage = function(opts) {
};
function mockLogger(callback) {
return function() {
// TODO: Use ...args with The Lounge v3: add `...args` as function argument
// and replaced the next line with `args.join(", ")`
const stdout = Array.prototype.slice.call(arguments).join(" ")
.replace( // Removes ANSI colors. See https://stackoverflow.com/a/29497680
return function(...args) {
// Concats and removes ANSI colors. See https://stackoverflow.com/a/29497680
const stdout = args.join(" ").replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
""
);

View file

@ -101,7 +101,7 @@ const config = {
// automatically split all vendor dependencies into a separate bundle
new webpack.optimize.CommonsChunkPlugin({
name: "js/bundle.vendor.js",
minChunks: (module) => module.context && module.context.indexOf("node_modules") !== -1,
minChunks: (module) => module.context && module.context.includes("node_modules"),
}),
],
};