Skip to content

Commit 7845b85

Browse files
committed
Add lint-tsc-lib-no-dom.
1 parent 919a2e6 commit 7845b85

16 files changed

Lines changed: 126 additions & 79 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- run: make lint-ci
2626
- run: make lint-tsc-main
2727
- run: make lint-tsc-lib
28+
- run: make lint-tsc-lib-no-dom
2829
- run: make lint-tsc-bin
2930
- run: make lint-import-restrictions
3031
- run: make check-schemas

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ test-info:
103103
@echo ""
104104
@echo "Also, if you want to run all possible checks in the project, run:"
105105
@echo ""
106-
@echo " make check (≈40s, includes all of the above)"
106+
@echo " make check (≈46s, includes all of the above)"
107107
@echo ""
108108
@echo "If you want the best \"bang for your buck\" without running everything, run:"
109109
@echo ""
@@ -239,7 +239,7 @@ check-engines: update-dependencies
239239
@${BUN_RUN} "./script/check-engine-versions.ts"
240240

241241
.PHONY: lint
242-
lint: lint-biome lint-import-restrictions lint-tsc-main lint-tsc-lib lint-tsc-bin check-schemas
242+
lint: lint-biome lint-import-restrictions lint-tsc check-schemas
243243

244244
.PHONY: lint-biome
245245
lint-biome: update-dependencies
@@ -253,6 +253,9 @@ lint-ci: update-dependencies
253253
lint-import-restrictions: update-dependencies
254254
${BUN_RUN} ./script/lint/import-restrictions/main.ts
255255

256+
.PHONY: lint-tsc
257+
lint-tsc: lint-tsc-main lint-tsc-lib lint-tsc-lib-no-dom lint-tsc-bin
258+
256259
.PHONY: lint-tsc-main
257260
lint-tsc-main: update-dependencies
258261
${BUN_DX} --package typescript tsc -- --project ./tsconfig.json
@@ -261,6 +264,10 @@ lint-tsc-main: update-dependencies
261264
lint-tsc-lib: update-dependencies
262265
${BUN_DX} --package typescript tsc -- --project ./tsconfig.lib.jsonc
263266

267+
.PHONY: lint-tsc-lib-no-dom
268+
lint-tsc-lib-no-dom: update-dependencies
269+
${BUN_DX} --package typescript tsc -- --project ./tsconfig.lib.no-dom.jsonc
270+
264271
.PHONY: lint-tsc-bin
265272
lint-tsc-bin: update-dependencies
266273
${BUN_DX} --package typescript tsc -- --project ./src/bin/tsconfig.json

src/cubing/bluetooth/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// TODO: deprecate these exports?
2+
export type {
3+
ExperimentalAlgLeafEvent as MoveEvent,
4+
ExperimentalOrientationEvent as OrientationEvent,
5+
} from "../stream";
16
export { enableDebugLogging } from "./debug";
27
export { debugKeyboardConnect, KeyboardPuzzle } from "./keyboard";
3-
export type {
4-
AlgLeafEvent as MoveEvent,
5-
BluetoothPuzzle,
6-
OrientationEvent,
7-
} from "./smart-puzzle/bluetooth-puzzle";
8+
export type { BluetoothPuzzle } from "./smart-puzzle/bluetooth-puzzle";
89
export { connectSmartPuzzle } from "./smart-puzzle/connect";
910
export { GanCube } from "./smart-puzzle/gan";
1011
export { GiiKERCube } from "./smart-puzzle/giiker";

src/cubing/bluetooth/smart-puzzle/bluetooth-puzzle.ts

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
1-
import type { AlgLeaf } from "../../alg/alg-nodes/AlgNode";
21
import type { KPattern } from "../../kpuzzle/KPattern";
2+
import type {
3+
ExperimentalAlgLeafEvent,
4+
ExperimentalOrientationEvent,
5+
} from "../../stream";
36
import {
47
BasicRotationTransformer,
58
type StreamTransformer,
69
} from "../transformer";
710

811
/******** BluetoothPuzzle ********/
912

10-
// TODO: Use actual `CustomEvent`s?
11-
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
12-
/** @category Smart Puzzles */
13-
export interface AlgLeafEvent {
14-
latestAlgLeaf: AlgLeaf;
15-
timeStamp: number;
16-
debug?: Record<string, unknown>;
17-
pattern?: KPattern;
18-
quaternion?: any; // TODO: Unused
19-
}
20-
21-
// TODO: Only use the `quaternion` field in the `AlgLeafEvent`?
22-
/** @category Smart Puzzles */
23-
export interface OrientationEvent {
24-
quaternion: {
25-
x: number;
26-
y: number;
27-
z: number;
28-
w: number;
29-
};
30-
timeStamp: number;
31-
debug?: Record<string, unknown>;
32-
}
33-
3413
export interface BluetoothConfig<T> {
3514
connect:
3615
| ((
@@ -52,8 +31,10 @@ export interface BluetoothConfig<T> {
5231
/** @category Smart Puzzles */
5332
export abstract class BluetoothPuzzle extends EventTarget {
5433
public transformers: StreamTransformer[] = [];
55-
protected listeners: Array<(e: AlgLeafEvent) => void> = []; // TODO: type
56-
protected orientationListeners: Array<(e: OrientationEvent) => void> = []; // TODO: type
34+
protected listeners: Array<(e: ExperimentalAlgLeafEvent) => void> = []; // TODO: type
35+
protected orientationListeners: Array<
36+
(e: ExperimentalOrientationEvent) => void
37+
> = []; // TODO: type
5738

5839
public abstract name(): string | undefined;
5940
public abstract disconnect(): void; // TODO: Can we make this reutrn (async) on success?
@@ -63,19 +44,23 @@ export abstract class BluetoothPuzzle extends EventTarget {
6344
throw new Error("cannot get pattern");
6445
}
6546

66-
public addAlgLeafListener(listener: (e: AlgLeafEvent) => void): void {
47+
public addAlgLeafListener(
48+
listener: (e: ExperimentalAlgLeafEvent) => void,
49+
): void {
6750
this.listeners.push(listener);
6851
}
6952

70-
public addOrientationListener(listener: (e: OrientationEvent) => void): void {
53+
public addOrientationListener(
54+
listener: (e: ExperimentalOrientationEvent) => void,
55+
): void {
7156
this.orientationListeners.push(listener);
7257
}
7358

7459
public experimentalAddBasicRotationTransformer(): void {
7560
this.transformers.push(new BasicRotationTransformer());
7661
}
7762

78-
protected dispatchAlgLeaf(algLeaf: AlgLeafEvent): void {
63+
protected dispatchAlgLeaf(algLeaf: ExperimentalAlgLeafEvent): void {
7964
for (const transformer of this.transformers) {
8065
transformer.transformAlgLeaf(algLeaf);
8166
}
@@ -84,7 +69,9 @@ export abstract class BluetoothPuzzle extends EventTarget {
8469
}
8570
}
8671

87-
protected dispatchOrientation(orientationEvent: OrientationEvent): void {
72+
protected dispatchOrientation(
73+
orientationEvent: ExperimentalOrientationEvent,
74+
): void {
8875
for (const transformer of this.transformers) {
8976
transformer.transformOrientation(orientationEvent);
9077
}

src/cubing/bluetooth/transformer.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Quaternion } from "three/src/math/Quaternion.js";
22
import { Vector3 } from "three/src/math/Vector3.js";
33
import type {
4-
AlgLeafEvent,
5-
OrientationEvent,
6-
} from "./smart-puzzle/bluetooth-puzzle";
4+
ExperimentalAlgLeafEvent,
5+
ExperimentalOrientationEvent,
6+
} from "../stream";
77

88
// TODO: Combine orientation and alg leaves into a single event to handle quaternion remapping.
99
export interface StreamTransformer {
1010
// Modifies the input.
11-
transformAlgLeaf(algLeafEvent: AlgLeafEvent): void;
11+
transformAlgLeaf(algLeafEvent: ExperimentalAlgLeafEvent): void;
1212
// Modifies the input.
13-
transformOrientation(orientationEvent: OrientationEvent): void;
13+
transformOrientation(orientationEvent: ExperimentalOrientationEvent): void;
1414
}
1515

1616
function maxAxis(v: Vector3): string {
@@ -45,11 +45,13 @@ const m: { [s: string]: Quaternion } = {
4545
export class BasicRotationTransformer implements StreamTransformer {
4646
// private reorientQuat = new Quaternion();
4747

48-
public transformAlgLeaf(_algLeafEvent: AlgLeafEvent): void {
48+
public transformAlgLeaf(_algLeafEvent: ExperimentalAlgLeafEvent): void {
4949
// Nothing to do.
5050
}
5151

52-
public transformOrientation(orientationEvent: OrientationEvent): void {
52+
public transformOrientation(
53+
orientationEvent: ExperimentalOrientationEvent,
54+
): void {
5355
const { x, y, z, w } = orientationEvent.quaternion;
5456
const quat = new Quaternion(x, y, z, w);
5557

src/cubing/search/instantiator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function instantiateModuleWorkerAttempt(
7272
const worker = (await constructWorker(url, {
7373
type: "module",
7474
})) as Worker & {
75-
nodeWorker?: import("worker_threads").Worker;
75+
nodeWorker?: import("node:worker_threads").Worker;
7676
} & BunWorker;
7777

7878
worker.unref?.(); // Unref in `bun`.

src/cubing/stream/events.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// TODO: Use actual `CustomEvent`s?
2+
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
3+
4+
import type { AlgLeaf } from "../alg";
5+
import type { KPattern } from "../kpuzzle";
6+
7+
/** @category Smart Puzzles */
8+
export interface AlgLeafEvent {
9+
latestAlgLeaf: AlgLeaf;
10+
timeStamp: number;
11+
debug?: Record<string, unknown>;
12+
pattern?: KPattern;
13+
quaternion?: any; // TODO: Unused
14+
}
15+
16+
// TODO: Only use the `quaternion` field in the `AlgLeafEvent`?
17+
/** @category Smart Puzzles */
18+
export interface OrientationEvent {
19+
quaternion: {
20+
x: number;
21+
y: number;
22+
z: number;
23+
w: number;
24+
};
25+
timeStamp: number;
26+
debug?: Record<string, unknown>;
27+
}
28+
29+
export interface ProxyMoveEvent {
30+
event: "move";
31+
data: AlgLeafEvent;
32+
}
33+
export interface ProxyOrientationEvent {
34+
event: "orientation";
35+
data: OrientationEvent;
36+
}
37+
export interface ProxyResetEvent {
38+
event: "reset";
39+
}
40+
export type ProxyEvent =
41+
| ProxyMoveEvent
42+
| ProxyOrientationEvent
43+
| ProxyResetEvent;

src/cubing/stream/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
*/
66

77
export type {
8+
AlgLeafEvent as ExperimentalAlgLeafEvent,
9+
OrientationEvent as ExperimentalOrientationEvent,
810
ProxyEvent as ExperimentalProxyEvent,
911
ProxyMoveEvent as ExperimentalProxyMoveEvent,
1012
ProxyOrientationEvent as ExperimentalProxyOrientationEvent,
1113
ProxyResetEvent as ExperimentalProxyResetEvent,
12-
} from "./proxy-event";
14+
} from "./events";
1315
export { TwizzleStreamServer as ExperimentalTwizzleStreamServer } from "./twizzle/TwizzleStream";
1416
export {
1517
WebSocketProxyReceiver as ExperimentalWebSocketProxyReceiver,

src/cubing/stream/proxy-event.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/cubing/stream/websocket-proxy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { MoveEvent, OrientationEvent } from "../bluetooth";
2-
import type { ProxyEvent } from "./proxy-event";
1+
import type { AlgLeafEvent, OrientationEvent, ProxyEvent } from "./events";
32

43
export class WebSocketProxySender {
54
protected websocket: WebSocket;
@@ -10,7 +9,7 @@ export class WebSocketProxySender {
109
this.websocket.onmessage = this.onmessage.bind(this);
1110
}
1211

13-
public sendMoveEvent(e: MoveEvent): void {
12+
public sendMoveEvent(e: AlgLeafEvent): void {
1413
(e as any).latestAlgLeaf = e.latestAlgLeaf.toString(); // TODO
1514
this.sendProxyEvent({
1615
event: "move",

0 commit comments

Comments
 (0)