From 2480578f6d987571347f1e8fb1aca118e8facf68 Mon Sep 17 00:00:00 2001 From: c43721 Date: Tue, 14 Oct 2025 21:27:09 -0500 Subject: [PATCH 1/5] feat(ci): add lint, type checking --- .github/workflows/lint.yml | 23 +++++++++++++++++++++++ .github/workflows/typecheck.yml | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/typecheck.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..deb47ce --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Run Linter + +on: + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: denoland/setup-deno@v2 + with: + cache: true + deno-version: v2.x + + - run: deno lint diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml new file mode 100644 index 0000000..a86ae4d --- /dev/null +++ b/.github/workflows/typecheck.yml @@ -0,0 +1,23 @@ +name: Type Check + +on: + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: denoland/setup-deno@v2 + with: + cache: true + deno-version: v2.x + + - run: deno check From ebad8d4f9f5aa5aa83cb246a7654c7a5c9552adc Mon Sep 17 00:00:00 2001 From: c43721 Date: Tue, 14 Oct 2025 22:28:40 -0500 Subject: [PATCH 2/5] feat,fix: add dry publish to PRs, fix the slow types, ignore examples for lints --- .github/workflows/publish-dry.yml | 23 +++++++++++++++++++++++ deno.json | 12 +++++++++++- examples/abort-controller.ts | 2 +- src/logReceiver.ts | 9 ++------- src/types.ts | 15 +++++++++++++++ 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/publish-dry.yml diff --git a/.github/workflows/publish-dry.yml b/.github/workflows/publish-dry.yml new file mode 100644 index 0000000..6e57c9d --- /dev/null +++ b/.github/workflows/publish-dry.yml @@ -0,0 +1,23 @@ +name: Check Publish + +on: + pull_request: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + + needs: + "test" + + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@v4 + + - name: Publish package + run: npx jsr publish --dry-run diff --git a/deno.json b/deno.json index aec04d1..65faab9 100644 --- a/deno.json +++ b/deno.json @@ -3,7 +3,12 @@ "version": "1.1.5", "exports": "./src/index.ts", "publish": { - "include": ["jsr.json", "LICENSE", "README.md", "src/**/*.ts"] + "include": [ + "jsr.json", + "LICENSE", + "README.md", + "src/**/*.ts" + ] }, "tasks": { "console": "deno run --watch examples/write-to-console.ts", @@ -14,6 +19,11 @@ "useBraces": "always", "bracePosition": "sameLineUnlessHanging" }, + "lint": { + "exclude": [ + "examples/" + ] + }, "imports": { "@std/assert": "jsr:@std/assert@^1.0.15", "@std/bytes": "jsr:@std/bytes@^1.0.6", diff --git a/examples/abort-controller.ts b/examples/abort-controller.ts index 3e4cdf2..098b894 100644 --- a/examples/abort-controller.ts +++ b/examples/abort-controller.ts @@ -15,4 +15,4 @@ receiver.on("event", (message) => console.log(message)); controller.abort(); -console.log("Closed the socket") +console.log("Closed the socket"); diff --git a/src/logReceiver.ts b/src/logReceiver.ts index f040371..38e619c 100644 --- a/src/logReceiver.ts +++ b/src/logReceiver.ts @@ -2,7 +2,7 @@ import { EventEmitter } from "node:events"; import { createSocket, type RemoteInfo, type Socket } from "node:dgram"; import { parsePacket } from "./parser.ts"; -import type { EventData, TypedEventEmitter } from "./types.ts"; +import type { EventData, MessageEvents, TypedEventEmitter } from "./types.ts"; /** * The socket options for the UDP socket @@ -30,11 +30,6 @@ export interface LogReceiverOptions { signal?: AbortSignal; } -type MessageEvents = { - error: (error: Error) => void; - event: (message: EventData) => void; -}; - /** * An event emitter that will emit a message event when a valid UDP log is created on the server * @@ -99,7 +94,7 @@ type MessageEvents = { * * For security reasons, you should always use a log secret to prevent evaluation of potentially malicious messages. Do this by looking at the password field. In order to set up the log secret, you can use the `sv_logsecret` command */ -export class LogReceiver extends (EventEmitter as new () => TypedEventEmitter) implements Disposable { +export class LogReceiver extends EventEmitter implements TypedEventEmitter, Disposable { #socket: Socket; /** diff --git a/src/types.ts b/src/types.ts index ae97b66..fdcc78f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,20 @@ import type { RemoteInfo } from "node:dgram"; +/** + * The possible events that can be emitted + */ +export type MessageEvents = { + /** + * Emitted when an error occurs + */ + error: (error: Error) => void; + + /** + * Emitted when data is received from the server + */ + event: (message: EventData) => void; +}; + /** * Represents the parsed information from the message data */ From b8f4b407802342d66205630f6dfe75abab032fb4 Mon Sep 17 00:00:00 2001 From: c43721 Date: Tue, 14 Oct 2025 22:36:19 -0500 Subject: [PATCH 3/5] fix: remove needs in dry publish --- .github/workflows/publish-dry.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/publish-dry.yml b/.github/workflows/publish-dry.yml index 6e57c9d..e5f06de 100644 --- a/.github/workflows/publish-dry.yml +++ b/.github/workflows/publish-dry.yml @@ -9,9 +9,6 @@ jobs: publish: runs-on: ubuntu-latest - needs: - "test" - permissions: contents: read id-token: write From c492066c314d8d0ee563c0752cf63ed057a97273 Mon Sep 17 00:00:00 2001 From: c43721 Date: Tue, 14 Oct 2025 23:04:59 -0500 Subject: [PATCH 4/5] fix(types): fix slow types complaining --- src/logReceiver.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/logReceiver.ts b/src/logReceiver.ts index 38e619c..2f26513 100644 --- a/src/logReceiver.ts +++ b/src/logReceiver.ts @@ -30,6 +30,8 @@ export interface LogReceiverOptions { signal?: AbortSignal; } +const LogEmitter = EventEmitter as (new () => TypedEventEmitter); + /** * An event emitter that will emit a message event when a valid UDP log is created on the server * @@ -94,7 +96,7 @@ export interface LogReceiverOptions { * * For security reasons, you should always use a log secret to prevent evaluation of potentially malicious messages. Do this by looking at the password field. In order to set up the log secret, you can use the `sv_logsecret` command */ -export class LogReceiver extends EventEmitter implements TypedEventEmitter, Disposable { +export class LogReceiver extends LogEmitter implements Disposable { #socket: Socket; /** From 68243c82fefbfd8184227aed83cc26ccbc51734a Mon Sep 17 00:00:00 2001 From: c43721 Date: Tue, 14 Oct 2025 23:07:26 -0500 Subject: [PATCH 5/5] fix: rename the actions to match the file name --- .github/workflows/lint.yml | 2 +- .github/workflows/publish-dry.yml | 2 +- .github/workflows/typecheck.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index deb47ce..8789181 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,7 +9,7 @@ permissions: contents: read jobs: - test: + lint: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/publish-dry.yml b/.github/workflows/publish-dry.yml index e5f06de..d7b6b17 100644 --- a/.github/workflows/publish-dry.yml +++ b/.github/workflows/publish-dry.yml @@ -6,7 +6,7 @@ on: - main jobs: - publish: + publish-dry: runs-on: ubuntu-latest permissions: diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml index a86ae4d..49a6d99 100644 --- a/.github/workflows/typecheck.yml +++ b/.github/workflows/typecheck.yml @@ -9,7 +9,7 @@ permissions: contents: read jobs: - test: + type-check: runs-on: ubuntu-latest steps: