Skip to content

Commit 0cb2c4a

Browse files
authored
Never ts-nocheck (#1028)
- Add node flag "--experimental-strip-types" for "npm start" - Refactor hanabi-bot to TypeScript and update ESLint configuration to get rid of the current only exception - Add Node.js engine requirement ^22.6.0 to package.json and package-lock.json
1 parent 4f20a58 commit 0cb2c4a

5 files changed

+16
-19
lines changed

eslint.config.mjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ const compat = new FlatCompat({
1313
allConfig: js.configs.all
1414
});
1515

16-
export default [{
17-
ignores: ["src/hanabi-bot.js"],
18-
}, ...compat.extends("eslint:recommended", "plugin:jsdoc/recommended"), {
16+
export default [...compat.extends("eslint:recommended", "plugin:jsdoc/recommended"), {
1917
// plugins: {
2018
// jsdoc,
2119
// },

package-lock.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
"typescript": "^5.6.3"
1111
},
1212
"scripts": {
13-
"start": "node --env-file=.env src/hanabi-bot.js",
13+
"start": "node --experimental-strip-types --env-file=.env src/hanabi-bot.ts",
1414
"replay": "node --env-file=.env src/replay.js",
1515
"self-play": "node --env-file=.env src/self-play.js",
1616
"lint": "eslint .",
1717
"test": "node --test"
18+
},
19+
"engines": {
20+
"node": "^22.6.0"
1821
}
1922
}

src/hanabi-bot.js src/hanabi-bot.ts

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
import * as https from 'https';
32

43
import { handle } from './command-handler.js';
@@ -32,12 +31,12 @@ function connect(bot_index = '') {
3231
}
3332
};
3433

35-
return new Promise((resolve, reject) => {
34+
return new Promise<string>((resolve, reject) => {
3635
// Send login request to hanab.live
3736
const req = https.request(options, (res) => {
3837
console.log(`Request status code: ${res.statusCode}`);
3938

40-
const cookie = res.headers['set-cookie'][0];
39+
const cookie = res.headers['set-cookie']?.[0];
4140
if (cookie == null) {
4241
reject('Failed to parse cookie from auth headers.');
4342
return;
@@ -58,22 +57,16 @@ function connect(bot_index = '') {
5857
});
5958
}
6059

60+
declare var WebSocket: typeof import("undici-types").WebSocket;
61+
6162
async function main() {
6263
if (Number(process.versions.node.split('.')[0]) < 22)
6364
throw new Error(`This program requires Node v22 or above! Currently using Node v${process.versions.node}.`);
6465

6566
const { index, manual } = Utils.parse_args();
6667

67-
let cookie = connect(index);
68-
6968
// Connect to server using credentials
70-
try {
71-
cookie = await cookie;
72-
}
73-
catch (error) {
74-
console.error(error);
75-
return;
76-
}
69+
const cookie = await connect(index);
7770

7871
// Establish websocket
7972
const ws = new WebSocket(`wss://${HANABI_HOSTNAME}/ws`, { headers: { Cookie: cookie } });
@@ -91,7 +84,7 @@ async function main() {
9184

9285
ws.addEventListener('message', (event) => {
9386
// Websocket messages are in the format: commandName {"field_name":"value"}
94-
const str = event.data;
87+
const str = event.data.toString();
9588
const ind = str.indexOf(' ');
9689
const [command, arg] = [str.slice(0, ind), str.slice(ind + 1)];
9790

@@ -102,4 +95,4 @@ async function main() {
10295
});
10396
}
10497

105-
main();
98+
main().catch(console.error);

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"resolveJsonModule": true,
99
"strict": false
1010
},
11-
"include": ["src/**/*.js", "src/**/*.d.ts", "test/**/*.js"],
11+
"include": ["src/**/*.js", "src/**/*.ts", "test/**/*.js"],
1212
"exclude": ["node_modules"]
1313
}

0 commit comments

Comments
 (0)