From d4c682e67a73e830cbaf233a4d4051b5ddbcd42d Mon Sep 17 00:00:00 2001 From: Amy Yan Date: Mon, 1 Jul 2024 16:03:38 +1000 Subject: [PATCH 1/5] feat: esm migration fix: `WebSocketServerConfigInput` types were incorrect in `WebSocketServer` constructor fix: import of `resource-counter` library fix: consistent import of `ws` library --- .eslintrc | 9 +- README.md | 2 +- benches/index.ts | 24 +- .../baseline_tcp/baseline_tcp_1KiB.chart.html | 10 +- .../baseline_tcp/baseline_tcp_1KiB.json | 202 +- .../baseline_tcp_1KiB_metrics.txt | 6 +- .../baseline_websocket_1KiB.chart.html | 10 +- .../baseline_websocket_1KiB.json | 200 +- .../baseline_websocket_1KiB_metrics.txt | 6 +- .../connection/connection_1KiB.chart.html | 10 +- .../results/connection/connection_1KiB.json | 202 +- .../connection/connection_1KiB_metrics.txt | 6 +- benches/results/metrics.txt | 24 +- benches/results/stream/stream_1KiB.chart.html | 10 +- benches/results/stream/stream_1KiB.json | 141 +- .../results/stream/stream_1KiB_metrics.txt | 6 +- benches/results/system.json | 8 +- .../suites/baseline_tcp/baseline_tcp_1KiB.ts | 18 +- .../baseline_websocket_1KiB.ts | 22 +- benches/suites/connection/connection_1KiB.ts | 24 +- benches/suites/stream/stream_1KiB.ts | 25 +- benches/utils.ts | 11 +- jest.config.js => jest.config.mjs | 27 +- package-lock.json | 4530 ++++++++--------- package.json | 79 +- scripts/test.mjs | 47 + src/WebSocketClient.ts | 38 +- src/WebSocketConnection.ts | 38 +- src/WebSocketConnectionMap.ts | 12 +- src/WebSocketServer.ts | 36 +- src/WebSocketStream.ts | 24 +- src/config.ts | 2 +- src/errors.ts | 2 +- src/events.ts | 6 +- src/index.ts | 22 +- src/message/index.ts | 6 +- src/message/types.ts | 4 +- src/message/utils.ts | 10 +- src/types.ts | 2 +- src/utils.ts | 16 +- tests/WebSocketClient.browser.test.ts | 14 +- tests/WebSocketClient.test.ts | 16 +- tests/WebSocketConnection.test.ts | 14 +- tests/WebSocketServer.test.ts | 12 +- tests/WebSocketStream.test.ts | 104 +- tests/WebSocketStreamQueue.test.ts | 10 +- tests/message/utils.test.ts | 48 +- tests/message/utils.ts | 4 +- tests/setup.ts | 3 + tests/utils.ts | 6 +- tsconfig.json | 16 +- 51 files changed, 2879 insertions(+), 3245 deletions(-) rename jest.config.js => jest.config.mjs (78%) create mode 100644 scripts/test.mjs diff --git a/.eslintrc b/.eslintrc index 786b7e5a..ea322d5e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,14 +7,13 @@ "jest": true }, "parser": "@typescript-eslint/parser", + "plugins": [ + "import" + ], "extends": [ "eslint:recommended", "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended", - "prettier" - ], - "plugins": [ - "import" + "plugin:prettier/recommended" ], "parserOptions": { "project": "tsconfig.json", diff --git a/README.md b/README.md index fd7b1cf0..08be278a 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ npm install # build the dist npm run build # run the repl (this allows you to import from ./src) -npm run ts-node +npm run tsx # run the tests npm run test # lint the source code diff --git a/benches/index.ts b/benches/index.ts index dd2d64dd..786fb5bc 100644 --- a/benches/index.ts +++ b/benches/index.ts @@ -1,13 +1,18 @@ #!/usr/bin/env ts-node -import type { Summary } from 'benny/lib/internal/common-types'; -import fs from 'fs'; -import path from 'path'; +import type { Summary } from 'benny/lib/internal/common-types.js'; +import fs from 'node:fs'; +import path from 'node:path'; +import url from 'node:url'; import si from 'systeminformation'; -import { fsWalk, resultsPath, suitesPath } from './utils'; +import { fsWalk, resultsPath, suitesPath } from './utils.js'; + +const projectPath = path.dirname(url.fileURLToPath(import.meta.url)); async function main(): Promise { - await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true }); + await fs.promises.mkdir(path.join(projectPath, 'results'), { + recursive: true, + }); // Running all suites for await (const suitePath of fsWalk(suitesPath)) { // Skip over non-ts and non-js files @@ -39,13 +44,16 @@ async function main(): Promise { system: 'model, manufacturer', }); await fs.promises.writeFile( - path.join(__dirname, 'results', 'system.json'), + path.join(projectPath, 'results', 'system.json'), JSON.stringify(systemData, null, 2), ); } -if (require.main === module) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/results/baseline_tcp/baseline_tcp_1KiB.chart.html b/benches/results/baseline_tcp/baseline_tcp_1KiB.chart.html index 4baaf506..abb59da0 100644 --- a/benches/results/baseline_tcp/baseline_tcp_1KiB.chart.html +++ b/benches/results/baseline_tcp/baseline_tcp_1KiB.chart.html @@ -28,7 +28,7 @@
- +