Skip to content

Commit b1cbf04

Browse files
fix: silence tsup exports warning (#114)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
1 parent 8d4b707 commit b1cbf04

File tree

8 files changed

+75
-99
lines changed

8 files changed

+75
-99
lines changed

.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"node": true,
1717
"commonjs": true
1818
},
19-
"ignorePatterns": ["tsup.config.ts"],
2019
"rules": {
2120
"import/no-extraneous-dependencies": "off",
2221
"no-restricted-syntax": "off",

README.md

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ const bench = new Bench({ time: 100 });
3939

4040
bench
4141
.add('faster task', () => {
42-
console.log('I am faster')
42+
console.log('I am faster');
4343
})
4444
.add('slower task', async () => {
45-
await new Promise(r => setTimeout(r, 1)) // we wait 1ms :)
46-
console.log('I am slower')
45+
await new Promise((r) => setTimeout(r, 1)); // we wait 1ms :)
46+
console.log('I am slower');
4747
})
48-
.todo('unimplemented bench')
48+
.todo('unimplemented bench');
4949

5050
await bench.warmup(); // make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50
5151
await bench.run();
@@ -60,9 +60,7 @@ console.table(bench.table());
6060
// │ 1 │ 'slower task' │ '828' │ 1207382.7838323202 │ '±7.07%' │ 83 │
6161
// └─────────┴───────────────┴──────────┴────────────────────┴───────────┴─────────┘
6262

63-
console.table(
64-
bench.table((task) => ({'Task name': task.name}))
65-
);
63+
console.table(bench.table((task) => ({ 'Task name': task.name })));
6664

6765
// Output:
6866
// ┌─────────┬───────────────────────┐
@@ -139,13 +137,13 @@ export type Options = {
139137
teardown?: Hook;
140138
};
141139

142-
export type Hook = (task: Task, mode: "warmup" | "run") => void | Promise<void>;
140+
export type Hook = (task: Task, mode: 'warmup' | 'run') => void | Promise<void>;
143141
```
144142

145143
- `async run()`: run the added tasks that were registered using the `add` method
146-
- `async runConcurrently(threshold: number = Infinity, mode: "bench" | "task" = "bench")`: similar to the `run` method but runs concurrently rather than sequentially. See the [Concurrency](#Concurrency) section.
147-
- `async warmup()`: warm up the benchmark tasks
148-
- `async warmupConcurrently(threshold: number = Infinity, mode: "bench" | "task" = "bench")`: warm up the benchmark tasks concurrently
144+
- `async runConcurrently(threshold: number = Infinity, mode: "bench" | "task" = "bench")`: similar to the `run` method but runs concurrently rather than sequentially. See the [Concurrency](#Concurrency) section.
145+
- `async warmup()`: warmup the benchmark tasks
146+
- `async warmupConcurrently(threshold: number = Infinity, mode: "bench" | "task" = "bench")`: warmup the benchmark tasks concurrently
149147
- `reset()`: reset each task and remove its result
150148
- `add(name: string, fn: Fn, opts?: FnOpts)`: add a benchmark task to the task map
151149
- `Fn`: `() => any | Promise<any>`
@@ -176,7 +174,7 @@ function has been executed.
176174
- `runs: number`: the number of times the task function has been executed
177175
- `result?: TaskResult`: the result object
178176
- `async run()`: run the current task and write the results in `Task.result` object
179-
- `async warmup()`: warm up the current task
177+
- `async warmup()`: warmup the current task
180178
- `setResult(result: Partial<TaskResult>)`: change the result object values
181179
- `reset()`: reset the task to make the `Task.runs` a zero-value and remove the `Task.result` object
182180

@@ -210,7 +208,6 @@ the benchmark task result object.
210208

211209
```ts
212210
export type TaskResult = {
213-
214211
/*
215212
* the last error that was thrown while running the task
216213
*/
@@ -318,40 +315,33 @@ in each class instance using the universal `addEventListener` and
318315
* Bench events
319316
*/
320317
export type BenchEvents =
321-
| "abort" // when a signal aborts
322-
| "complete" // when running a benchmark finishes
323-
| "error" // when the benchmark task throws
324-
| "reset" // when the reset function gets called
325-
| "start" // when running the benchmarks gets started
326-
| "warmup" // when the benchmarks start getting warmed up (before start)
327-
| "cycle" // when running each benchmark task gets done (cycle)
328-
| "add" // when a Task gets added to the Bench
329-
| "remove" // when a Task gets removed of the Bench
330-
| "todo"; // when a todo Task gets added to the Bench
318+
| 'abort' // when a signal aborts
319+
| 'complete' // when running a benchmark finishes
320+
| 'error' // when the benchmark task throws
321+
| 'reset' // when the reset function gets called
322+
| 'start' // when running the benchmarks gets started
323+
| 'warmup' // when the benchmarks start getting warmed up (before start)
324+
| 'cycle' // when running each benchmark task gets done (cycle)
325+
| 'add' // when a Task gets added to the Bench
326+
| 'remove' // when a Task gets removed of the Bench
327+
| 'todo'; // when a todo Task gets added to the Bench
331328

332329
/**
333330
* task events
334331
*/
335-
export type TaskEvents =
336-
| "abort"
337-
| "complete"
338-
| "error"
339-
| "reset"
340-
| "start"
341-
| "warmup"
342-
| "cycle";
332+
export type TaskEvents = 'abort' | 'complete' | 'error' | 'reset' | 'start' | 'warmup' | 'cycle';
343333
```
344334

345335
For instance:
346336

347337
```js
348338
// runs on each benchmark task's cycle
349-
bench.addEventListener("cycle", (e) => {
339+
bench.addEventListener('cycle', (e) => {
350340
const task = e.task!;
351341
});
352342

353343
// runs only on this benchmark task's cycle
354-
task.addEventListener("cycle", (e) => {
344+
task.addEventListener('cycle', (e) => {
355345
const task = e.task!;
356346
});
357347
```
@@ -365,12 +355,14 @@ export type BenchEvent = Event & {
365355
```
366356

367357
### `process.hrtime`
358+
368359
if you want more accurate results for nodejs with `process.hrtime`, then import
369-
the `hrtimeNow` function from the library and pass it to the `Bench` options.
360+
the `hrtimeNow` function from the library and pass it to the `Bench` options.
370361

371362
```ts
372363
import { hrtimeNow } from 'tinybench';
373364
```
365+
374366
It may make your benchmarks slower, check #42.
375367

376368
## Concurrency
@@ -381,20 +373,21 @@ It may make your benchmarks slower, check #42.
381373

382374
```ts
383375
// options way (recommended)
384-
bench.threshold = 10 // The maximum number of concurrent tasks to run. Defaults to Infinity.
385-
bench.concurrency = "task" // The concurrency mode to determine how tasks are run.
386-
// await bench.warmup()
387-
await bench.run()
376+
bench.threshold = 10; // The maximum number of concurrent tasks to run. Defaults to Infinity.
377+
bench.concurrency = 'task'; // The concurrency mode to determine how tasks are run.
378+
// await bench.warmup();
379+
await bench.run();
388380

389381
// standalone method way
390-
// await bench.warmupConcurrently(10, "task")
391-
await bench.runConcurrently(10, "task") // with runConcurrently, mode is set to 'bench' by default
382+
// await bench.warmupConcurrently(10, 'task');
383+
await bench.runConcurrently(10, 'task'); // with runConcurrently, mode is set to 'bench' by default
392384
```
393385

394386
## Prior art
395387

396388
- [Benchmark.js](https://github.com/bestiejs/benchmark.js)
397389
- [Mitata](https://github.com/evanwashere/mitata/)
390+
- [tatami-ng](https://github.com/poolifier/tatami-ng)
398391
- [Bema](https://github.com/prisma-labs/bema)
399392

400393
## Authors

examples/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
"name": "examples",
33
"version": "0.0.0",
44
"type": "module",
5+
"packageManager": "pnpm@8.15.9",
6+
"volta": {
7+
"node": "20.18.0",
8+
"pnpm": "8.15.9"
9+
},
510
"scripts": {
611
"build": "tsc",
7-
"all": "pnpm run simple",
12+
"all": "pnpm simple",
813
"simple": "tsx src/simple.ts",
9-
"dev:simple": "tsx watch src/simple.ts"
14+
"dev:simple": "tsx --watch src/simple.ts"
1015
},
1116
"license": "ISC",
1217
"devDependencies": {

examples/src/simple.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
import { Bench } from '../../src';
23

34
const bench = new Bench({ time: 100 });

package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,25 @@
1111
"dev": "tsup --watch",
1212
"build": "tsup",
1313
"prepare": "git config core.hooksPath .hooks",
14-
"publish": "npm run build && clean-publish",
14+
"publish": "pnpm build && clean-publish",
1515
"typecheck": "tsc --noEmit",
16-
"lint": "eslint src test examples",
17-
"lint:fix": "eslint --fix src test examples",
18-
"release": "bumpp package.json --commit --push --tag && npm run publish",
16+
"lint": "eslint src test examples tsup.config.ts",
17+
"lint:fix": "eslint --fix src test examples tsup.config.ts",
18+
"release": "bumpp package.json --commit --push --tag && pnpm publish",
1919
"test": "vitest --retry=5 --run"
2020
},
2121
"main": "./dist/index.cjs",
2222
"module": "./dist/index.js",
23-
"types": "./dist/index.d.cts",
23+
"types": "./dist/index.d.ts",
2424
"exports": {
25-
"require": "./dist/index.cjs",
26-
"import": "./dist/index.js",
27-
"default": "./dist/index.js"
25+
"require": {
26+
"types": "./dist/index.d.cts",
27+
"require": "./dist/index.cjs"
28+
},
29+
"import": {
30+
"types": "./dist/index.d.ts",
31+
"import": "./dist/index.js"
32+
}
2833
},
2934
"files": [
3035
"dist/**"
@@ -39,7 +44,7 @@
3944
"@typescript-eslint/parser": "^7.18.0",
4045
"bumpp": "^9.7.1",
4146
"changelogithub": "^0.13.11",
42-
"clean-publish": "^3.4.5",
47+
"clean-publish": "^5.0.0",
4348
"eslint": "^8.57.1",
4449
"eslint-config-airbnb-base": "^15.0.0",
4550
"eslint-plugin-import": "^2.31.0",

pnpm-lock.yaml

Lines changed: 7 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010
"skipLibCheck": true,
1111
"lib": []
1212
},
13-
"include": ["src", "test", "@types"],
14-
"exclude": ["node_modules", "dist"],
13+
"include": [
14+
"src",
15+
"test",
16+
"tsup.config.ts"
17+
],
18+
"exclude": [
19+
"node_modules",
20+
"dist"
21+
],
1522
"removeComments": true,
1623
"newLine": "lf"
1724
}

tsup.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { defineConfig } from "tsup";
1+
import { defineConfig } from 'tsup';
22

33
export default defineConfig({
4-
entry: ["src/index.ts"],
5-
outDir: "dist",
6-
format: ["esm", "cjs"],
4+
entry: ['src/index.ts'],
5+
outDir: 'dist',
6+
format: ['esm', 'cjs'],
77
minify: false,
88
minifySyntax: true,
99
minifyWhitespace: false,

0 commit comments

Comments
 (0)