Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add typecheck workflow #540

Merged
merged 8 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Typecheck
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
typecheck:
name: Run typecheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- shell: bash
run: |
pnpm install --no-frozen-lockfile

- shell: bash
run: pnpm run typecheck
1 change: 1 addition & 0 deletions examples/canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"scripts": {
"build": "vite build",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist/ node_modules/",
"dev": "vite serve",
"start": "vite preview --host --port 5173"
Expand Down
1 change: 1 addition & 0 deletions examples/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"scripts": {
"build": "vite build",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist/ node_modules/",
"dev": "vite serve",
"start": "vite preview --host --port 5173"
Expand Down
7 changes: 3 additions & 4 deletions examples/chat/src/objects/chat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type DRP, type ResolveConflictsType } from "@ts-drp/object";
import { ActionType, SemanticsType } from "@ts-drp/types";
import { type IDRP, type ResolveConflictsType, ActionType, SemanticsType } from "@ts-drp/types";

export class Chat implements DRP {
export class Chat implements IDRP {
semanticsType: SemanticsType = SemanticsType.pair;
// store messages as strings in the format (timestamp, message, peerId)
messages: Set<string>;
Expand All @@ -17,7 +16,7 @@ export class Chat implements DRP {
return this.messages;
}

resolveConflicts(_): ResolveConflictsType {
resolveConflicts(): ResolveConflictsType {
return { action: ActionType.Nop };
}
}
1 change: 1 addition & 0 deletions examples/grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"scripts": {
"build": "vite build",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist/ node_modules/",
"dev": "vite serve",
"start": "vite preview --host --port 5173"
Expand Down
5 changes: 3 additions & 2 deletions examples/grid/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DRPNode, type DRPNodeConfig } from "@ts-drp/node";
import { enableTracing, type IMetrics, OpentelemetryMetrics } from "@ts-drp/tracer";
import { DRPNode } from "@ts-drp/node";
import { enableTracing, OpentelemetryMetrics } from "@ts-drp/tracer";
import { type DRPNodeConfig, type IMetrics } from "@ts-drp/types";

import { env } from "./env";
import { Grid } from "./objects/grid";
Expand Down
11 changes: 8 additions & 3 deletions examples/grid/src/objects/grid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { type DRP, type ResolveConflictsType } from "@ts-drp/object";
import { ActionType, SemanticsType, type Vertex } from "@ts-drp/types";
import {
type IDRP,
type ResolveConflictsType,
ActionType,
SemanticsType,
type Vertex,
} from "@ts-drp/types";

export class Grid implements DRP {
export class Grid implements IDRP {
semanticsType: SemanticsType = SemanticsType.pair;
positions: Map<string, { x: number; y: number }>;

Expand Down
4 changes: 2 additions & 2 deletions examples/grid/src/state.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DRPNode } from "@ts-drp/node";
import { type DRPObject } from "@ts-drp/object";
import { type IDRPObject } from "@ts-drp/types";

import { type Grid } from "./objects/grid";

interface GridState {
node: DRPNode;
drpObject: DRPObject | undefined;
drpObject: IDRPObject | undefined;
gridDRP: Grid | undefined;
peers: string[];
discoveryPeers: string[];
Expand Down
1 change: 1 addition & 0 deletions examples/grid/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineConfig({
"@ts-drp": path.resolve(__dirname, "../../packages"),
},
},
// @ts-expect-error -- test is a valid property
test: {
exclude: ["**/node_modules", "**/e2e"],
},
Expand Down
1 change: 1 addition & 0 deletions examples/local-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"scripts": {
"build": "vite build",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist/ node_modules/",
"dev": "vite serve"
},
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"type": "module",
"scripts": {
"bench": "vitest bench",
"build": "pnpm build:packages && pnpm build:examples",
"build": "pnpm -r build",
"build:examples": "pnpm --filter 'ts-drp-example*' build",
"build:packages": "pnpm --filter '@ts-drp/*' build",
"clean": "pnpm --filter '@ts-drp/*' clean && rm -r node_modules/ docs/",
Expand All @@ -34,6 +34,7 @@
"proto-gen:types": "buf generate packages/types/src/proto -o packages/types/src/proto",
"release": "release-it",
"test": "vitest",
"typecheck": "pnpm --parallel typecheck",
"watch": "pnpm --parallel --filter '@ts-drp/*' watch"
},
"dependencies": {
Expand All @@ -45,7 +46,7 @@
"@playwright/test": "^1.49.1",
"@release-it-plugins/workspaces": "^4.2.0",
"@typescript-eslint/parser": "^8.21.0",
"@vitest/coverage-v8": "3.0.5",
"@vitest/coverage-v8": "^3.0.5",
"assemblyscript": "^0.27.29",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/blueprints/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
}
},
"scripts": {
"build": "tsc -b",
"build": "tsc -b tsconfig.build.json",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist/ node_modules/",
"prepack": "tsc -b",
"test": "vitest",
"watch": "tsc -b -w"
},
"dependencies": {
"@thi.ng/random": "^4.1.0",
"@ts-drp/object": "0.8.5",
"@ts-drp/types": "0.8.5"
}
}
24 changes: 19 additions & 5 deletions packages/blueprints/tests/AddMul.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionType } from "@ts-drp/types";
import { ActionType, type Vertex } from "@ts-drp/types";
import { beforeEach, describe, expect, test } from "vitest";

import { AddMulDRP } from "../src/AddMul/index.js";
Expand All @@ -25,12 +25,15 @@ describe("AddMulDRP tests", () => {

test("Test: Add (Weird inputs)", () => {
drp.add(5);
// @ts-expect-error - weird input
drp.add("");
expect(drp.query_value()).toEqual(5);

// @ts-expect-error - weird input
drp.add(true);
expect(drp.query_value()).toEqual(5);

// @ts-expect-error - weird input
drp.add({});
expect(drp.query_value()).toEqual(5);
});
Expand All @@ -51,12 +54,15 @@ describe("AddMulDRP tests", () => {

test("Test: Mul (Weird inputs)", () => {
drp.add(5);
// @ts-expect-error - weird input
drp.mul("");
expect(drp.query_value()).toEqual(5);

// @ts-expect-error - weird input
drp.mul(true);
expect(drp.query_value()).toEqual(5);

// @ts-expect-error - weird input
drp.mul({});
expect(drp.query_value()).toEqual(5);
});
Expand All @@ -76,15 +82,19 @@ describe("AddMulDRP tests", () => {
});

test("Test: initialValue (Weird inputs)", () => {
// @ts-expect-error - weird input
drp = new AddMulDRP("10");
expect(drp.query_value()).toEqual(0);

// @ts-expect-error - weird input
drp = new AddMulDRP(true);
expect(drp.query_value()).toEqual(0);

// @ts-expect-error - weird input
drp = new AddMulDRP({});
expect(drp.query_value()).toEqual(0);

// @ts-expect-error - weird input
drp = new AddMulDRP([]);
expect(drp.query_value()).toEqual(0);
});
Expand Down Expand Up @@ -166,24 +176,28 @@ describe("AddMulDRP tests", () => {
});

test("Test: resolveConflicts (Weird inputs)", () => {
const vertex1 = {
const vertex1: Vertex = {
hash: "1",
// @ts-expect-error - operation is missing
operation: {
opType: "add",
},
};
const vertex2 = {
const vertex2: Vertex = {
hash: "2",
// @ts-expect-error - operation is missing
operation: {
opType: "mulx",
},
};
const vertex3 = {
const vertex3: Vertex = {
// @ts-expect-error - operation is missing
operation: {
opType: "mul",
},
};
const vertex4 = {};
// @ts-expect-error - operation is missing
const vertex4: Vertex = {};

let action = drp.resolveConflicts([vertex1, vertex2]);
expect(action).toEqual({ action: ActionType.Nop });
Expand Down
1 change: 1 addition & 0 deletions packages/blueprints/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extends": "./tsconfig.json","exclude": ["tests/**/*.ts"]}
12 changes: 6 additions & 6 deletions packages/blueprints/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"compilerOptions": {
"outDir": "dist"
},
"references": [
{
"path": "../object"
}
"include": [
"src/**/*.ts",
"tests/**/*.ts"
],
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.asc.ts"]
"exclude": [
"src/**/*.asc.ts"
]
}
3 changes: 2 additions & 1 deletion packages/interval-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
}
},
"scripts": {
"build": "tsc -b",
"build": "tsc -b tsconfig.build.json",
"clean": "rm -rf dist/ node_modules/",
"cli": "tsx ./src/run.ts",
"prebuild": "node -p \"'export const VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
"prepack": "tsc -b",
"test": "vitest",
"typecheck": "tsc --noEmit",
"watch": "tsc -b -w"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/interval-runner/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extends": "./tsconfig.json","exclude": ["tests/**/*.ts"]}
4 changes: 2 additions & 2 deletions packages/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
}
},
"scripts": {
"build": "tsc -b",
"build": "tsc -b tsconfig.build.json",
"clean": "rm -rf dist/ node_modules/",
"prepack": "tsc -b",
"typecheck": "tsc --noEmit",
"watch": "tsc -b -w"
},
"dependencies": {
Expand All @@ -33,7 +34,6 @@
"@libp2p/crypto": "^5.0.5",
"@libp2p/interface": "^2.1.3",
"@noble/secp256k1": "^2.2.3",
"@ts-drp/object": "0.8.5",
"@ts-drp/types": "^0.8.5",
"uint8arrays": "^5.1.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/keychain/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extends": "./tsconfig.json","exclude": ["tests/**/*.ts"]}
2 changes: 1 addition & 1 deletion packages/keychain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "dist"
},
"include": ["src/**/*.ts", "src/**/*.js"]
"include": ["src/**/*.ts", "src/**/*.js", "tests/**/*.ts"]
}
4 changes: 2 additions & 2 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
}
},
"scripts": {
"build": "tsc -b",
"build": "tsc -b tsconfig.build.json",
"clean": "rm -rf dist/ node_modules/",
"prepack": "tsc -b",
"typecheck": "tsc --noEmit",
"watch": "tsc -b -w"
},
"dependencies": {
"@ts-drp/types": "^0.8.5",
"loglevel": "^1.9.2",
"loglevel-plugin-prefix": "^0.8.4",
"@ts-drp/types": "^0.8.5"
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions packages/logger/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extends": "./tsconfig.json","exclude": ["tests/**/*.ts"]}
5 changes: 4 additions & 1 deletion packages/logger/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"compilerOptions": {
"outDir": "dist"
},
"include": ["src/**/*.ts"]
"include": [
"src/**/*.ts",
"tests/**/*.ts"
]
}
6 changes: 4 additions & 2 deletions packages/network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
}
},
"scripts": {
"build": "tsc -b",
"build": "tsc -b tsconfig.build.json",
"clean": "rm -rf dist/ node_modules/",
"prepack": "tsc -b",
"test": "vitest",
"typecheck": "tsc --noEmit",
"watch": "tsc -b -w"
},
"devDependencies": {
"@ts-drp/keychain": "0.8.5",
"race-event": "^1.3.0"
},
"dependencies": {
Expand All @@ -41,8 +43,8 @@
"@libp2p/crypto": "^5.0.5",
"@libp2p/dcutr": "^2.0.6",
"@libp2p/devtools-metrics": "^1.1.5",
"@libp2p/interface": "^2.1.3",
"@libp2p/identify": "^3.0.6",
"@libp2p/interface": "^2.1.3",
"@libp2p/ping": "2.0.11",
"@libp2p/pubsub-peer-discovery": "^11.0.0",
"@libp2p/webrtc": "^5.0.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/network/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Keychain } from "@ts-drp/keychain/src/keychain.js";
import { Keychain } from "@ts-drp/keychain";
import { beforeAll, describe, expect, test } from "vitest";

import { DRPNetworkNode } from "../src/node.js";
Expand Down
Loading