Use @types/node@8.0.0 to validate (and fix) small node 8 api issues

This commit is contained in:
mmorrison 2019-02-19 21:15:34 -06:00
parent 916d03f879
commit f0a24b8f65
9 changed files with 49 additions and 43 deletions

View file

@ -85,6 +85,8 @@ class GameResolver {
for (const one of str.split(',')) {
const equals = one.indexOf('=');
const key = equals === -1 ? one : one.substr(0,equals);
/** @type {string|number|boolean} */
let value = equals === -1 ? '' : one.substr(equals+1);
if(value === 'true' || value === '') value = true;

View file

@ -1,7 +1,6 @@
const GameResolver = require('./GameResolver'),
ProtocolResolver = require('./ProtocolResolver'),
GlobalUdpSocket = require('./GlobalUdpSocket'),
Logger = require('./Logger');
GlobalUdpSocket = require('./GlobalUdpSocket');
const defaultOptions = {
socketTimeout: 2000,

23
package-lock.json generated
View file

@ -1,13 +1,19 @@
{
"name": "gamedig",
"version": "2.0.5",
"version": "2.0.13",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@types/cheerio": {
"version": "0.22.10",
"resolved": "https://registry.npmjs.org/@types/cheerio/-/cheerio-0.22.10.tgz",
"integrity": "sha512-fOM/Jhv51iyugY7KOBZz2ThfT1gwvsGCfWxpLpZDgkGjpEO4Le9cld07OdskikLjDUQJ43dzDaVRSFwQlpdqVg==",
"dev": true
},
"@types/node": {
"version": "10.12.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.18.tgz",
"integrity": "sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ=="
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.0.tgz",
"integrity": "sha512-j2tekvJCO7j22cs+LO6i0kRPhmQ9MXaPZ55TzOc1lzkN5b6BWqq4AFjl04s1oRRQ1v5rSe+KEvnLUSTonuls/A=="
},
"ajv": {
"version": "6.6.2",
@ -324,9 +330,12 @@
}
},
"iconv-lite": {
"version": "0.4.18",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.18.tgz",
"integrity": "sha512-sr1ZQph3UwHTR0XftSbK85OvBbxe/abLGzEnPENCQwmHf7sck8Oyu4ob3LgBxWWxRoM+QszeUyl7jbqapu2TqA=="
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"inherits": {
"version": "2.0.3",

View file

@ -27,7 +27,7 @@
"cheerio": "^1.0.0-rc.2",
"compressjs": "^1.0.2",
"gbxremote": "^0.1.4",
"iconv-lite": "^0.4.18",
"iconv-lite": "^0.4.24",
"long": "^2.4.0",
"minimist": "^1.2.0",
"moment": "^2.21.0",
@ -46,5 +46,9 @@
"games.txt",
"LICENSE",
"README.md"
]
],
"devDependencies": {
"@types/cheerio": "^0.22.10",
"@types/node": "^8.0.0"
}
}

View file

@ -9,7 +9,7 @@ class BuildAndShoot extends Core {
let m;
m = body.match(/status server for (.*?)\.?(\r|\n)/);
m = body.match(/status server for (.*?)\.?[\r\n]/);
if(m) state.name = m[1];
m = body.match(/Current uptime: (\d+)/);

View file

@ -182,7 +182,8 @@ class Core extends EventEmitter {
/**
* @template T
* @param {function(Socket):Promise<T>} fn
* @param {function(NodeJS.Socket):Promise<T>} fn
* @param {number=} port
* @returns {Promise<T>}
*/
async withTcp(fn, port) {
@ -236,7 +237,7 @@ class Core extends EventEmitter {
/**
* @template T
* @param {Socket} socket
* @param {NodeJS.Socket} socket
* @param {Buffer|string} buffer
* @param {function(Buffer):T} ondata
* @returns Promise<T>
@ -250,7 +251,7 @@ class Core extends EventEmitter {
received = Buffer.concat([received, data]);
const result = ondata(received);
if (result !== undefined) {
socket.off('data', onData);
socket.removeListener('data', onData);
resolve(result);
}
};

View file

@ -4,10 +4,6 @@ class Doom3 extends Core {
constructor() {
super();
this.encoding = 'latin1';
this.isEtqw = false;
this.hasSpaceBeforeClanTag = false;
this.hasClanTag = false;
this.hasTypeFlag = false;
}
async run(state) {
const body = await this.udpSend('\xff\xffgetInfo\x00PiNGPoNg\x00', packet => {

View file

@ -1,5 +1,4 @@
const Core = require('./core'),
HexUtil = require('../lib/HexUtil');
const Core = require('./core');
class Gamespy3 extends Core {
constructor() {

View file

@ -1,5 +1,6 @@
const gbxremote = require('gbxremote'),
Core = require('./core');
Core = require('./core'),
Promises = require('../lib/Promises');
class Nadeo extends Core {
async run(state) {
@ -59,20 +60,16 @@ class Nadeo extends Core {
async withClient(fn) {
const socket = gbxremote.createClient(this.options.port, this.options.host);
const cancelAsyncLeak = this.addCleanup(() => socket.terminate());
try {
await this.timedPromise(
new Promise((resolve,reject) => {
socket.on('connect', resolve);
socket.on('error', e => reject(new Error('GBX Remote Connection Error: ' + e)));
socket.on('close', () => reject(new Error('GBX Remote Connection Refused')));
}),
this.options.socketTimeout,
'GBX Remote Opening'
);
const connectPromise = new Promise((resolve,reject) => {
socket.on('connect', resolve);
socket.on('error', e => reject(new Error('GBX Remote Connection Error: ' + e)));
socket.on('close', () => reject(new Error('GBX Remote Connection Refused')));
});
const timeoutPromise = Promises.createTimeout(this.options.socketTimeout, 'GBX Remote Opening');
const socket = await Promise.race([connectPromise, timeoutPromise, this.abortedPromise]);
return await fn(socket);
} finally {
cancelAsyncLeak();
socket.terminate();
}
}
@ -80,16 +77,15 @@ class Nadeo extends Core {
async methodCall(client, ...cmdset) {
const cmd = cmdset[0];
const params = cmdset.slice(1);
return await this.timedPromise(
new Promise(async (resolve,reject) => {
client.methodCall(cmd, params, (err, value) => {
if (err) reject('XMLRPC error ' + JSON.stringify(err));
resolve(value);
});
}),
this.options.socketTimeout,
'GBX Method Call'
);
const sentPromise = new Promise(async (resolve,reject) => {
client.methodCall(cmd, params, (err, value) => {
if (err) reject('XMLRPC error ' + JSON.stringify(err));
resolve(value);
});
});
const timeoutPromise = Promises.createTimeout(this.options.socketTimeout, 'GBX Method Call');
return await Promise.race([sentPromise, timeoutPromise, this.abortedPromise]);
}
stripColors(str) {