Skip to content

Commit

Permalink
update supported node.js versions (#571)
Browse files Browse the repository at this point in the history
* Remove make-promises-safe

* Require Node.js 16.20+

* correct type import paths

* fix pino-http import type

* Work around incomplete type imports w/ moduleResolution:node

* lint
  • Loading branch information
goto-bus-stop committed Jul 1, 2023
1 parent cd54c76 commit 4328e3e
Show file tree
Hide file tree
Showing 53 changed files with 239 additions and 232 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
name: Tests
strategy:
matrix:
node-version: ['14.x', '16.x', '18.x', '19.x']
node-version: ['16.x', '18.x', '20.x']
mongo-version: ['5.0', '6.0']
include:
- node-version: 'lts/*'
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
REDIS_URL: '127.0.0.1:6379'
MONGODB_HOST: '127.0.0.1:27017'
- name: Submit coverage
if: matrix.node-version == '18.x'
if: matrix.node-version == '20.x'
uses: coverallsapp/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Environment variables must be provided from the outside, eg. using docker-compose.
# Do `docker container run $THIS_IMAGE --help` to see the list.

FROM node:18-alpine
FROM node:20-alpine

WORKDIR /u-wave-core

Expand Down
1 change: 0 additions & 1 deletion bin/u-wave-core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

/* eslint-disable no-console,no-process-exit */
import 'make-promises-safe';
import fs from 'node:fs';
import explain from 'explain-error';
import Ajv from 'ajv';
Expand Down
1 change: 0 additions & 1 deletion dev/u-wave-dev-server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'make-promises-safe';
import minimist from 'minimist';
import concat from 'concat-stream';
import explain from 'explain-error';
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"u-wave-core": "bin/u-wave-core.js"
},
"engines": {
"node": ">= 14.17.0"
"node": ">= 16.20.0"
},
"dependencies": {
"@twurple/api": "^6.0.6",
Expand All @@ -45,7 +45,6 @@
"json-merge-patch": "^1.0.2",
"jsonwebtoken": "^9.0.0",
"lodash": "^4.17.15",
"make-promises-safe": "^5.1.0",
"minimist": "^1.2.5",
"mongoose": "^7.0.1",
"ms": "^2.1.2",
Expand All @@ -71,7 +70,7 @@
"yaml": "^2.0.0"
},
"devDependencies": {
"@tsconfig/node16": "^1.0.3",
"@tsconfig/node16": "^16.1.0",
"@types/bcryptjs": "^2.4.2",
"@types/cookie": "^0.5.0",
"@types/cookie-parser": "^1.4.2",
Expand All @@ -93,7 +92,6 @@
"@types/qs": "^6.9.6",
"@types/random-string": "^0.0.28",
"@types/ratelimiter": "^3.4.1",
"@types/redlock": "^4.0.1",
"@types/sinon": "^10.0.2",
"@types/supertest": "^2.0.11",
"@types/ultron": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/AuthRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AuthRegistry {
}

/**
* @param {import('./models').User} user
* @param {import('./models/index.js').User} user
*/
async createAuthToken(user) {
const token = (await randomBytes(64)).toString('hex');
Expand Down
8 changes: 4 additions & 4 deletions src/HttpApi.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fs from 'node:fs';
import http from 'node:http';
import { randomUUID } from 'node:crypto';
import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import cors from 'cors';
import helmet from 'helmet';
import http from 'node:http';
import pinoHttp from 'pino-http';
import { pinoHttp } from 'pino-http';

// routes
import authenticate from './routes/authenticate.js';
Expand Down Expand Up @@ -70,7 +70,7 @@ function defaultCreatePasswordResetEmail({ token, requestUrl }) {
*/

/**
* @param {import('./Uwave').Boot} uw
* @param {import('./Uwave.js').Boot} uw
* @param {HttpApiOptions} options
*/
async function httpApi(uw, options) {
Expand Down Expand Up @@ -158,7 +158,7 @@ async function httpApi(uw, options) {
}

/**
* @param {import('./Uwave').Boot} uw
* @param {import('./Uwave.js').Boot} uw
*/
async function errorHandling(uw) {
uw.logger.debug({ ns: 'uwave:http-api' }, 'setup HTTP error handling');
Expand Down
16 changes: 8 additions & 8 deletions src/SocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { serializeUser } from './utils/serialize.js';
const { debounce, isEmpty } = lodash;

/**
* @typedef {import('./models').User} User
* @typedef {import('./models/index.js').User} User
*/

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ function has(object, property) {

class SocketServer {
/**
* @param {import('./Uwave').Boot} uw
* @param {import('./Uwave.js').Boot} uw
* @param {{ secret: Buffer|string }} options
*/
static async plugin(uw, options) {
Expand Down Expand Up @@ -114,14 +114,14 @@ class SocketServer {
/**
* Handlers for commands that come in from the server side.
*
* @type {import('./redisMessages').ServerActions}
* @type {import('./redisMessages.js').ServerActions}
*/
#serverActions;

/**
* Create a socket server.
*
* @param {import('./Uwave').default} uw üWave Core instance.
* @param {import('./Uwave.js').default} uw üWave Core instance.
* @param {object} options Socket server options.
* @param {number} [options.timeout] Time in seconds to wait for disconnected
* users to reconnect before removing them.
Expand All @@ -143,7 +143,7 @@ class SocketServer {
this.#redisSubscription = uw.redis.duplicate();

this.options = {
/** @type {(_socket: import('ws') | undefined, err: Error) => void} */
/** @type {(_socket: import('ws').WebSocket | undefined, err: Error) => void} */
onError: (_socket, err) => {
throw err;
},
Expand Down Expand Up @@ -453,7 +453,7 @@ class SocketServer {
}

/**
* @param {import('ws')} socket
* @param {import('ws').WebSocket} socket
* @param {import('http').IncomingMessage} request
* @private
*/
Expand All @@ -467,7 +467,7 @@ class SocketServer {
}

/**
* @param {import('ws')} socket
* @param {import('ws').WebSocket} socket
* @param {Error} error
* @private
*/
Expand Down Expand Up @@ -502,7 +502,7 @@ class SocketServer {
/**
* Create a connection instance for an unauthenticated user.
*
* @param {import('ws')} socket
* @param {import('ws').WebSocket} socket
* @private
*/
createGuestConnection(socket) {
Expand Down
10 changes: 5 additions & 5 deletions src/Source.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SourceNoImportError } from './errors/index.js';

/**
* @typedef {import('./models').User} User
* @typedef {import('./models').Playlist} Playlist
* @typedef {import('./plugins/playlists').PlaylistItemDesc} PlaylistItemDesc
* @typedef {import('./models/index.js').User} User
* @typedef {import('./models/index.js').Playlist} Playlist
* @typedef {import('./plugins/playlists.js').PlaylistItemDesc} PlaylistItemDesc
*/

/**
Expand Down Expand Up @@ -34,7 +34,7 @@ import { SourceNoImportError } from './errors/index.js';
*/
class SourceContext {
/**
* @param {import('./Uwave').default} uw
* @param {import('./Uwave.js').default} uw
* @param {Source} source
* @param {User} user
*/
Expand Down Expand Up @@ -79,7 +79,7 @@ class ImportContext extends SourceContext {
*/
class Source {
/**
* @param {import('./Uwave').default} uw
* @param {import('./Uwave.js').default} uw
* @param {string} sourceType
* @param {SourcePlugin} sourcePlugin
*/
Expand Down
40 changes: 20 additions & 20 deletions src/Uwave.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const DEFAULT_MONGO_URL = 'mongodb://localhost:27017/uwave';
const DEFAULT_REDIS_URL = 'redis://localhost:6379';

/**
* @typedef {import('./Source').SourcePlugin} SourcePlugin
* @typedef {import('./Source.js').SourcePlugin} SourcePlugin
*/

/**
Expand All @@ -40,7 +40,7 @@ const DEFAULT_REDIS_URL = 'redis://localhost:6379';
* mongo?: string,
* redis?: string | RedisOptions,
* logger?: import('pino').LoggerOptions,
* } & import('./HttpApi').HttpApiOptions} Options
* } & import('./HttpApi.js').HttpApiOptions} Options
*/

class UwaveServer extends EventEmitter {
Expand All @@ -55,66 +55,66 @@ class UwaveServer extends EventEmitter {
// @ts-expect-error TS2564 Definitely assigned in a plugin
express;

/** @type {import('./models').Models} */
/** @type {import('./models/index.js').Models} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
models;

/** @type {import('./plugins/acl').Acl} */
/** @type {import('./plugins/acl.js').Acl} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
acl;

/** @type {import('./plugins/bans').Bans} */
/** @type {import('./plugins/bans.js').Bans} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
bans;

/** @type {import('./plugins/booth').Booth} */
/** @type {import('./plugins/booth.js').Booth} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
booth;

/** @type {import('./plugins/chat').Chat} */
/** @type {import('./plugins/chat.js').Chat} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
chat;

/** @type {import('./plugins/configStore').ConfigStore} */
/** @type {import('./plugins/configStore.js').ConfigStore} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
config;

/** @type {import('./plugins/emotes').Emotes|null} */
/** @type {import('./plugins/emotes.js').Emotes|null} */
emotes = null;

/** @type {import('./plugins/history').HistoryRepository} */
/** @type {import('./plugins/history.js').HistoryRepository} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
history;

/** @type {import('./plugins/migrations').Migrate} */
/** @type {import('./plugins/migrations.js').Migrate} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
migrate;

/** @type {import('./plugins/motd').MOTD} */
/** @type {import('./plugins/motd.js').MOTD} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
motd;

/** @type {import('./plugins/passport').Passport} */
/** @type {import('./plugins/passport.js').Passport} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
passport;

/** @type {import('./plugins/playlists').PlaylistsRepository} */
/** @type {import('./plugins/playlists.js').PlaylistsRepository} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
playlists;

/** @type {import('./plugins/users').UsersRepository} */
/** @type {import('./plugins/users.js').UsersRepository} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
users;

/** @type {import('./plugins/waitlist').Waitlist} */
/** @type {import('./plugins/waitlist.js').Waitlist} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
waitlist;

/** @type {import('./HttpApi').HttpApi} */
/** @type {import('./HttpApi.js').HttpApi} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
httpApi;

/** @type {import('./SocketServer').default} */
/** @type {import('./SocketServer.js').default} */
// @ts-expect-error TS2564 Definitely assigned in a plugin
socketServer;

Expand Down Expand Up @@ -304,9 +304,9 @@ class UwaveServer extends EventEmitter {
/**
* Publish an event to the üWave channel.
*
* @template {keyof import('./redisMessages').ServerActionParameters} CommandName
* @template {keyof import('./redisMessages.js').ServerActionParameters} CommandName
* @param {CommandName} command
* @param {import('./redisMessages').ServerActionParameters[CommandName]} data
* @param {import('./redisMessages.js').ServerActionParameters[CommandName]} data
*/
publish(command, data) {
this.redis.publish('uwave', JSON.stringify({
Expand Down
2 changes: 1 addition & 1 deletion src/auth/JWTStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Strategy } from 'passport';
import jwt from 'jsonwebtoken';
import { BannedError } from '../errors/index.js';

/** @typedef {import('../models').User} User */
/** @typedef {import('../models/index.js').User} User */

/**
* @param {Record<string, string>} cookies
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/acl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import toItemResponse from '../utils/toItemResponse.js';

/**
* @type {import('../types').AuthenticatedController}
* @type {import('../types.js').AuthenticatedController}
*/
async function list(req) {
const { acl } = req.uwave;
Expand All @@ -22,7 +22,7 @@ async function list(req) {
*/

/**
* @type {import('../types').AuthenticatedController<CreateRoleParams, {}, CreateRoleBody>}
* @type {import('../types.js').AuthenticatedController<CreateRoleParams, {}, CreateRoleBody>}
*/
async function createRole(req, res) {
const { name } = req.params;
Expand All @@ -38,7 +38,7 @@ async function createRole(req, res) {
}

/**
* @type {import('../types').AuthenticatedController}
* @type {import('../types.js').AuthenticatedController}
*/
async function deleteRole(req) {
const { name } = req.params;
Expand Down
Loading

0 comments on commit 4328e3e

Please sign in to comment.