diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..10aae4c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: Validate Worker + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + test-and-typecheck: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v5 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test + + - name: Type-check Cloudflare Worker + run: npm run typecheck diff --git a/package.json b/package.json index 01fc417..c1caa02 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dev": "wrangler dev", "tail": "wrangler tail", "matrix-login": "tsx src/matrix-login.ts", - "typecheck": "tsc --noEmit", + "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.node.json --noEmit", "test": "tsx --test src/*.test.ts" }, "keywords": [ @@ -22,6 +22,7 @@ "devDependencies": { "@cloudflare/workers-types": "^4.0.0", "@types/node": "^20.0.0", + "@types/prompts": "^2.4.9", "prompts": "^2.4.2", "tsx": "^4.0.0", "typescript": "^5.0.0", diff --git a/src/filters.test.ts b/src/filters.test.ts index d5814c0..cd7e769 100644 --- a/src/filters.test.ts +++ b/src/filters.test.ts @@ -1,4 +1,4 @@ -import assert from 'node:assert/strict'; +import * as assert from 'node:assert/strict'; import test from 'node:test'; import { evaluateImmediateFilter, diff --git a/src/matrix-login.ts b/src/matrix-login.ts index f0b7a47..da94a17 100644 --- a/src/matrix-login.ts +++ b/src/matrix-login.ts @@ -2,7 +2,7 @@ // src/matrix-login.ts // Script to login to Matrix and get a stable access token -import prompts from 'prompts'; +import prompts, { type PromptObject } from 'prompts'; interface MatrixLoginResponse { access_token: string; @@ -31,7 +31,7 @@ async function main() { try { // Get user input using prompts library - const questions = [ + const questions: PromptObject[] = [ { type: 'text', name: 'homeserver', diff --git a/tsconfig.json b/tsconfig.json index 902bbe2..fab1ffd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,9 +3,13 @@ "target": "ES2021", "module": "ES2022", "lib": ["ES2021"], - "types": ["@cloudflare/workers-types", "node"], + "types": ["@cloudflare/workers-types"], "moduleResolution": "node", "noEmit": true, "strict": true - } + }, + "include": [ + "src/index.ts", + "src/filters.ts" + ] } diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 0000000..72c92ee --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ES2021", + "module": "ES2022", + "lib": ["ES2021"], + "types": ["node"], + "moduleResolution": "node", + "noEmit": true, + "strict": true, + "allowSyntheticDefaultImports": true + }, + "include": [ + "src/matrix-login.ts", + "src/**/*.test.ts" + ] +}