Skip to content

Commit

Permalink
fix: remove DOM-related types to make tinybench environment agnostic (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 4, 2023
1 parent dfb6ef5 commit d78e6a5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 37 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "tsup",
"prepare": "git config core.hooksPath .hooks",
"publish": "npm run build && clean-publish",
"typecheck": "tsc --noEmit",
"release": "bumpp package.json --commit --push --tag && npm run publish",
"test": "vitest --no-threads"
},
Expand Down Expand Up @@ -40,7 +41,7 @@
"nano-staged": "^0.5.0",
"size-limit": "^7.0.8",
"tsup": "^5.11.7",
"typescript": "^4.5.4",
"typescript": "^5.2.2",
"vite": "^2.9.12",
"vitest": "^0.14.2"
},
Expand Down
70 changes: 40 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from '../types/index';
import { createBenchEvent } from './event';
import Task from './task';
import { AddEventListenerOptionsArgument, RemoveEventListenerOptionsArgument } from './types';
import { now } from './utils';

/**
Expand Down Expand Up @@ -134,15 +135,15 @@ export default class Bench extends EventTarget {
addEventListener<K extends BenchEvents, T = BenchEventsMap[K]>(
type: K,
listener: T,
options?: boolean | AddEventListenerOptions,
options?: AddEventListenerOptionsArgument,
): void {
super.addEventListener(type as string, listener as any, options);
}

removeEventListener<K extends BenchEvents, T = BenchEventsMap[K]>(
type: K,
listener: T,
options?: boolean | EventListenerOptions,
options?: RemoveEventListenerOptionsArgument,
) {
super.removeEventListener(type as string, listener as any, options);
}
Expand Down
5 changes: 3 additions & 2 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
import Bench from './bench';
import tTable from './constants';
import { createBenchEvent } from './event';
import { AddEventListenerOptionsArgument, RemoveEventListenerOptionsArgument } from './types';
import { getMean, getVariance, isAsyncTask } from './utils';

/**
Expand Down Expand Up @@ -247,15 +248,15 @@ export default class Task extends EventTarget {
addEventListener<K extends TaskEvents, T = TaskEventsMap[K]>(
type: K,
listener: T,
options?: boolean | AddEventListenerOptions,
options?: AddEventListenerOptionsArgument,
) {
super.addEventListener(type, listener as any, options);
}

removeEventListener<K extends TaskEvents, T = TaskEventsMap[K]>(
type: K,
listener: T,
options?: boolean | EventListenerOptions,
options?: RemoveEventListenerOptionsArgument,
) {
super.removeEventListener(type, listener as any, options);
}
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @types/node doesn't have these types globally, and we don't want to bring "dom" lib for everyone

export type RemoveEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.removeEventListener>[2];
export type AddEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.addEventListener>[2];
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"esModuleInterop": true,
"moduleResolution": "node",
"noUncheckedIndexedAccess": true,
"baseUrl": "."
"baseUrl": ".",
"skipLibCheck": true,
"lib": []
},
"include": ["src", "test", "@types"],
"exclude": ["node_modules", "dist"],
"removeComments": true,
"newLine": "lf",
"newLine": "lf"
}

0 comments on commit d78e6a5

Please sign in to comment.