Replace getport with get-port (#1314)

This commit is contained in:
Nathan Bierema 2023-01-05 20:12:28 -05:00 committed by GitHub
parent ce26486f83
commit 78eed2dd20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 142 deletions

View File

@ -49,7 +49,7 @@
"cross-spawn": "^7.0.3",
"electron": "^22.0.0",
"express": "^4.18.2",
"getport": "^0.1.0",
"get-port": "^5.1.1",
"graphql": "^16.6.0",
"knex": "^2.3.0",
"lodash": "^4.17.21",

View File

@ -1,6 +0,0 @@
declare module 'getport' {
export default function getport(
start: number,
callback: (e: Error | undefined, port: number) => void
): void;
}

View File

@ -1,21 +1,17 @@
import express from 'express';
import http from 'http';
import getPort from 'getport';
import getPort from 'get-port';
import socketClusterServer from 'socketcluster-server';
import getOptions, { Options } from './options';
import getOptions from './options';
import routes from './routes';
import createStore from './store';
// var LOG_LEVEL_NONE = 0;
const LOG_LEVEL_ERROR = 1;
// const LOG_LEVEL_NONE = 0;
// const LOG_LEVEL_ERROR = 1;
const LOG_LEVEL_WARN = 2;
const LOG_LEVEL_INFO = 3;
export interface ExtendedOptions extends Options {
allowClientPublish: boolean;
}
export default function (argv: { [arg: string]: any }): Promise<{
export default async function (argv: { [arg: string]: any }): Promise<{
portAlreadyUsed?: boolean;
listener: (eventName: 'ready') => { once(): Promise<void> };
}> {
@ -25,31 +21,24 @@ export default function (argv: { [arg: string]: any }): Promise<{
const port = options.port;
const logLevel =
options.logLevel === undefined ? LOG_LEVEL_INFO : options.logLevel;
return new Promise(function (resolve) {
// Check port already used
getPort(port, function (err, p) {
/* eslint-disable no-console */
if (err) {
if (logLevel >= LOG_LEVEL_ERROR) {
console.error(err);
}
return;
}
const p = await getPort({ port });
if (port !== p) {
if (logLevel >= LOG_LEVEL_WARN) {
console.log(`[ReduxDevTools] Server port ${port} is already used.`);
}
resolve({
return {
portAlreadyUsed: true,
listener: function (eventName: 'ready') {
listener: function () {
return {
once() {
return Promise.resolve();
},
};
},
});
} else {
};
}
if (logLevel >= LOG_LEVEL_INFO) {
console.log('[ReduxDevTools] Start server...');
console.log('-'.repeat(80) + '\n');
@ -147,9 +136,5 @@ export default function (argv: { [arg: string]: any }): Promise<{
httpServer.listen(options.port);
// @ts-expect-error Shouldn't there be a 'ready' event?
resolve(agServer);
}
/* eslint-enable no-console */
});
});
return agServer;
}

View File

@ -951,7 +951,7 @@ importers:
eslint-config-prettier: ^8.5.0
eslint-plugin-jest: ^27.1.7
express: ^4.18.2
getport: ^0.1.0
get-port: ^5.1.1
graphql: ^16.6.0
jest: ^29.3.1
knex: ^2.3.0
@ -983,7 +983,7 @@ importers:
cross-spawn: 7.0.3
electron: 22.0.0
express: 4.18.2
getport: 0.1.0
get-port: 5.1.1
graphql: 16.6.0
knex: 2.3.0_sqlite3@5.1.4
lodash: 4.17.21
@ -13892,6 +13892,11 @@ packages:
resolution: {integrity: sha512-41eOxtlGgHQRbFyA8KTH+w+32Em3cRdfBud7j67ulzmIfmaHX9doq47s0fa4P5o9H64BZX9nrYI6sJvk46Op+Q==}
dev: false
/get-port/5.1.1:
resolution: {integrity: sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==}
engines: {node: '>=8'}
dev: false
/get-stdin/4.0.1:
resolution: {integrity: sha512-F5aQMywwJ2n85s4hJPTT9RPxGmubonuB10MNYo17/xph174n2MIR33HRguhzVag10O/npM7SPk73LMZNP+FaWw==}
engines: {node: '>=0.10.0'}
@ -13932,10 +13937,6 @@ packages:
resolution: {integrity: sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==}
dev: false
/getport/0.1.0:
resolution: {integrity: sha512-hx+r6Q5IutZH+5k+zeZe78J4vzgW9IqLzfz8+hqMa9NrM1ccpgPIxrxqiBg+aioJMKcCK5qNKKcGdes3PeTlKQ==}
dev: false
/github-slugger/1.5.0:
resolution: {integrity: sha512-wIh+gKBI9Nshz2o46B0B3f5k/W+WI9ZAv6y5Dn5WJ5SK1t0TnDimB4WE5rmTD05ZAIn8HALCZVmCsvj0w0v0lw==}
dev: true