Skip to content

Commit

Permalink
Require Node.js 14.17.0 (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Apr 30, 2022
1 parent 5c47bef commit 9d54904
Show file tree
Hide file tree
Showing 26 changed files with 41 additions and 73 deletions.
11 changes: 3 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@ module.exports = {

plugins: ['node', '@typescript-eslint'],

// We don't use babel for transpiling, but we do use features
// supported by Node.js that the default eslint parser does not
// yet understand.
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'script',
requireConfigFile: false,
babelOptions: {
plugins: ['@babel/plugin-syntax-class-properties'],
},
},

rules: {
Expand Down Expand Up @@ -68,6 +60,9 @@ module.exports = {
},
{
files: ['*.mjs'],
parserOptions: {
sourceType: 'module',
},
rules: {
'import/extensions': ['error', 'ignorePackages'],
'import/no-unresolved': ['error', {
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
name: Tests
strategy:
matrix:
node-version: ['12.x', '14.x', '16.x', '18.x']
node-version: ['14.x', '16.x', '18.x']
mongo-version: ['5.0']
include:
- node-version: '12.x'
- node-version: 'lts/*'
mongo-version: '4.2'
- node-version: '12.x'
- node-version: 'lts/*'
mongo-version: '4.4'
runs-on: ubuntu-latest
services:
Expand Down
2 changes: 1 addition & 1 deletion dev/u-wave-dev-server
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const testTransport = {
* üWave API development server.
*/
async function start() {
const port = Number(argv.port || process.env.PORT || 6042);
const port = Number(argv.port ?? process.env.PORT ?? 6042);

const uwave = require('..');

Expand Down
6 changes: 3 additions & 3 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import dotenv from 'dotenv';

dotenv.config();

const port = process.env.PORT || 80;
const port = process.env.PORT ?? 80;
const secret = Buffer.from(process.env.SECRET, 'hex');

const DEFAULT_MONGO_URL = 'mongodb://localhost:27017/uwave';
const DEFAULT_REDIS_URL = 'redis://localhost:6379';

const uw = uwave({
mongo: process.env.MONGO_CONNECTION_URL || DEFAULT_MONGO_URL,
redis: process.env.REDIS_CONNECTION_URL || DEFAULT_REDIS_URL,
mongo: process.env.MONGO_CONNECTION_URL ?? DEFAULT_MONGO_URL,
redis: process.env.REDIS_CONNECTION_URL ?? DEFAULT_REDIS_URL,
port,
secret,
// This has to be disabled so the headers do not get added to the web client too.
Expand Down
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"u-wave-core": "bin/u-wave-core"
},
"engines": {
"node": ">= 12.20.0"
"node": ">= 14.17.0"
},
"dependencies": {
"ajv": "^8.0.5",
Expand All @@ -34,7 +34,6 @@
"cookie": "^0.5.0",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"crypto-randomuuid": "^1.0.0",
"debug": "^4.1.1",
"escape-string-regexp": "^4.0.0",
"explain-error": "^1.0.4",
Expand Down Expand Up @@ -71,10 +70,7 @@
"yaml": "^2.0.0"
},
"devDependencies": {
"@babel/core": "^7.13.13",
"@babel/eslint-parser": "^7.13.10",
"@babel/plugin-syntax-class-properties": "^7.12.13",
"@tsconfig/node12": "^1.0.7",
"@tsconfig/node14": "^1.0.1",
"@types/bcryptjs": "^2.4.2",
"@types/cookie": "^0.5.0",
"@types/cookie-parser": "^1.4.2",
Expand All @@ -88,7 +84,7 @@
"@types/jsonwebtoken": "^8.5.1",
"@types/lodash": "^4.14.168",
"@types/ms": "^0.7.31",
"@types/node": "12",
"@types/node": "14",
"@types/node-fetch": "^2.5.8",
"@types/nodemailer": "^6.4.1",
"@types/passport": "^1.0.6",
Expand Down
2 changes: 1 addition & 1 deletion src/HttpApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function httpApi(uw, options) {
mailTransport: options.mailTransport,
recaptcha: options.recaptcha,
createPasswordResetEmail:
options.createPasswordResetEmail || defaultCreatePasswordResetEmail,
options.createPasswordResetEmail ?? defaultCreatePasswordResetEmail,
}))
.use('/bans', bans())
.use('/import', imports())
Expand Down
2 changes: 1 addition & 1 deletion src/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Page {
}

get pageSize() {
return this.opts.pageSize || this.length;
return this.opts.pageSize ?? this.length;
}

get filteredSize() {
Expand Down
2 changes: 1 addition & 1 deletion src/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Source {
}

get apiVersion() {
return this.plugin.api || 1;
return this.plugin.api ?? 1;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/auth/JWTStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class JWTStrategy extends Strategy {
const { bans } = req.uwave;

const token = getQueryToken(req.query)
|| getHeaderToken(req.headers)
|| getCookieToken(req.cookies);
?? getHeaderToken(req.headers)
?? getCookieToken(req.cookies);
if (!token) {
return this.pass();
}
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function seconds(str) {
* @type {import('../types').Controller}
*/
async function getCurrentUser(req) {
return toItemResponse(req.user || null, {
return toItemResponse(req.user ?? null, {
url: req.fullUrl,
});
}
Expand Down Expand Up @@ -84,7 +84,7 @@ async function refreshSession(res, api, user, options) {
const serialized = cookie.serialize('uwsession', token, {
httpOnly: true,
secure: !!options.cookieSecure,
path: options.cookiePath || '/',
path: options.cookiePath ?? '/',
maxAge: seconds('31 days'),
});
res.setHeader('Set-Cookie', serialized);
Expand Down Expand Up @@ -445,7 +445,7 @@ async function logout(req, res) {
const serialized = cookie.serialize('uwsession', '', {
httpOnly: true,
secure: !!cookieSecure,
path: cookiePath || '/',
path: cookiePath ?? '/',
maxAge: 0,
});
res.setHeader('Set-Cookie', serialized);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/now.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function getState(req) {
const booth = getBoothData(uw);
const waitlist = uw.waitlist.getUserIDs();
const waitlistLocked = uw.waitlist.isLocked();
let activePlaylist = user && user.activePlaylist
let activePlaylist = user?.activePlaylist
? uw.playlists.getUserPlaylist(user, user.activePlaylist)
: null;
const playlists = user ? uw.playlists.getUserPlaylists(user) : null;
Expand All @@ -91,7 +91,7 @@ async function getState(req) {

if (activePlaylist != null) {
activePlaylist = activePlaylist
.then((playlist) => (playlist ? playlist.id : null))
.then((playlist) => playlist?.id)
.catch((err) => {
// If the playlist was not found, our database is inconsistent. A deleted or nonexistent
// playlist should never be listed as the active playlist. Most likely this is not the
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async function getPlaylistItems(req) {
const { user } = req;
const { playlists } = req.uwave;
const { id } = req.params;
const filter = req.query.filter || undefined;
const filter = req.query.filter ?? undefined;
const pagination = getOffsetPagination(req.query);

const playlist = await playlists.getUserPlaylist(user, new ObjectId(id));
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function getConfig(req) {
const combinedSchema = config.getSchema();
const schema = combinedSchema.properties[key];

return toItemResponse(values || {}, {
return toItemResponse(values ?? {}, {
url: req.fullUrl,
meta: includeSchema ? { schema } : {},
});
Expand Down
2 changes: 1 addition & 1 deletion src/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function sendEmail(emailAddress, options) {
},
};

const transporter = nodemailer.createTransport(options.mailTransport || smtpOptions);
const transporter = nodemailer.createTransport(options.mailTransport ?? smtpOptions);

const mailOptions = { to: emailAddress, ...options.email };

Expand Down
6 changes: 3 additions & 3 deletions src/middleware/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function serializeError(err) {

if (err instanceof APIError) {
return [{
status: err.status || 500,
code: err.code || 'api-error',
status: err.status ?? 500,
code: err.code ?? 'api-error',
title: err.message,
}];
}
Expand All @@ -63,7 +63,7 @@ function serializeError(err) {
if (err.expose) {
/** @type {SerializedError} */
const apiError = {
status: err.status || 400,
status: err.status ?? 400,
code: err.code,
title: err.message,
};
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/rateLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RateLimiter.prototype.getAsync = promisify(RateLimiter.prototype.get);
* @returns {import('express').RequestHandler}
*/
function rateLimit(prefix, opts) {
const RLError = opts.error || RateLimitError;
const RLError = opts.error ?? RateLimitError;

return wrapMiddleware(async (req, res) => {
const uw = req.uwave;
Expand Down
23 changes: 0 additions & 23 deletions src/modules.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/plugins/bans.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Bans {
async getBans(filter, pagination = {}) {
const { User } = this.#uw.models;

const offset = pagination.offset || 0;
const offset = pagination.offset ?? 0;
const size = clamp(
pagination.limit == null ? 50 : pagination.limit,
0,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/chat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const randomUUID = require('crypto-randomuuid');
const { randomUUID } = require('crypto');
const routes = require('../routes/chat');

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/configStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ConfigStore {
const validate = this.#registry.get(key);
if (!validate) return undefined;

const config = (await this.load(key)) || {};
const config = (await this.load(key)) ?? {};
// Allowed to fail--just fills in defaults
validate(config);

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HistoryRepository {
async getHistory(filter, pagination = {}) {
const { HistoryEntry } = this.#uw.models;

const offset = pagination.offset || 0;
const offset = pagination.offset ?? 0;
const limit = clamp(
typeof pagination.limit === 'number' ? pagination.limit : DEFAULT_PAGE_SIZE,
0,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function toPlaylistItem(itemProps, media) {
const { start, end } = getStartEnd(itemProps, media);
return {
media,
artist: artist || media.artist,
title: title || media.title,
artist: artist ?? media.artist,
title: title ?? media.title,
start,
end,
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/waitlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class Waitlist {
}

const clampedPosition = clamp(position, 0, waitlist.length);
const beforeID = waitlist[clampedPosition] || null;
const beforeID = waitlist[clampedPosition] ?? null;

if (beforeID === user.id) {
// No change.
Expand Down
2 changes: 1 addition & 1 deletion src/sockets/AuthedConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AuthedConnection extends EventEmitter {
* @private
*/
onMessage(raw) {
const { command, data } = sjson.safeParse(raw) || {};
const { command, data } = sjson.safeParse(raw) ?? {};
if (command) {
this.emit('command', command, data);
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils/createUwave.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import uwave from 'u-wave-core';
import deleteDatabase from './deleteDatabase.mjs';
import testPlugin from './plugin.mjs';

const DB_HOST = process.env.MONGODB_HOST || 'localhost';
const DB_HOST = process.env.MONGODB_HOST ?? 'localhost';

/**
* Create a separate in-memory redis instance to run tests against.
Expand Down Expand Up @@ -46,7 +46,7 @@ async function createIsolatedRedis() {
* This can be used to run tests on CI.
*/
function createRedisConnection() {
const url = process.env.REDIS_URL || 'redis://localhost:6379';
const url = process.env.REDIS_URL ?? 'redis://localhost:6379';

async function close() {
const redis = new Redis(url);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@tsconfig/node12/tsconfig.json",
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"strict": true,
"useUnknownInCatchVariables": false,
Expand Down

0 comments on commit 9d54904

Please sign in to comment.