Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `createTimeSlicer` for loops that don't fit a map, such as `while` loops, tree walks and nested loops.
- `yieldToEventLoop`, which yields with the best method the runtime has: `scheduler.yield()`, then `setImmediate`, then `MessageChannel`, then `setTimeout`.
- `AbortSignal` support to stop a loop early.
- TypeScript types. Runs in Node.js 22+, Bun, Deno, browsers and Electron.
- ESM and CommonJS builds, each with TypeScript types, so both `import` and `require` work. Runs in Node.js 22+, Bun, Deno, browsers and Electron.

[unreleased]: https://github.com/RagedPanda/time-sliced/commits/main
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ await timeSlicedForEach(rows, processRow);
npm install time-sliced
```

No dependencies, with TypeScript types. Runs in Node.js 22+, Bun, Deno, browsers and Electron (main and renderer).
No dependencies. Ships ESM and CommonJS with types for both, so `import` and `require` both work. Runs in Node.js 22+, Bun, Deno, browsers and Electron (main and renderer).

## Benchmark

Expand Down
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
"description": "Run long loops without freezing the event loop: yield on a time budget, not every N items",
"license": "MIT",
"author": "Ankur Dubey (https://github.com/RagedPanda)",
"repository": "github:RagedPanda/time-sliced",
"repository": {
"type": "git",
"url": "git+https://github.com/RagedPanda/time-sliced.git"
},
"type": "module",
"main": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts",
"exports": {
".": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
},
"files": [
Expand All @@ -20,7 +31,7 @@
"node": ">=22"
},
"scripts": {
"build": "node -e \"fs.rmSync('dist', {recursive: true, force: true})\" && tsc -p tsconfig.esm.json",
"build": "node -e \"fs.rmSync('dist', {recursive: true, force: true})\" && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/mark-cjs.ts",
"typecheck": "tsc --noEmit",
"test": "node --test \"test/**/*.test.ts\"",
"bench": "node bench/event-loop-lag.ts",
Expand Down
5 changes: 5 additions & 0 deletions scripts/mark-cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// The package is "type": "module", so Node.js would read dist/cjs/*.js as ES modules.
// This nested package.json makes it read them, and their .d.ts files, as CommonJS.
import {writeFileSync} from 'node:fs';

writeFileSync(new URL('../dist/cjs/package.json', import.meta.url), `${JSON.stringify({type: 'commonjs'}, undefined, '\t')}\n`);
9 changes: 9 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.esm.json",
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "bundler",
"verbatimModuleSyntax": false,
"outDir": "dist/cjs"
}
}
Loading