Skip to content

Commit 17e4226

Browse files
committed
TS: add compatibility types for v4.7-v5.4
And change `test-node` to use mocha with tsx instead of ts-node, since the latter has issues with esm module resolutions involving typesVersions. Syntax ref: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html#exports-is-prioritized-over-typesversions
1 parent 5ccdfe6 commit 17e4226

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed
File renamed without changes.
File renamed without changes.

lib/types/v4.7-v5.4/index.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference lib="dom" />
2+
3+
import type { ReadableStream as NodeWebReadableStream } from 'node:stream/web';
4+
type DomReadableStream<R> = ReadableStream<R>;
5+
6+
type Data = Uint8Array | string;
7+
8+
export type WebStream<T extends Data> = DomReadableStream<T>
9+
export type NodeWebStream<T extends Data> = NodeWebReadableStream<T>;
10+
11+
type Stream<T extends Data> = WebStream<T> | NodeWebStream<T>;
12+
type MaybeStream<T extends Data> = T | Stream<T>;
13+
14+
export function readToEnd<T extends Data, JoinFn extends (chunks: T[]) => any = (chunks: T[]) => T>(
15+
input: MaybeStream<T>,
16+
join?: JoinFn
17+
): Promise<ReturnType<JoinFn>>;
18+
19+
export function toStream<T extends Data, InputType extends MaybeStream<T>>(
20+
input: InputType
21+
): InputType extends T ? Stream<InputType> : InputType;
22+
23+
export function isStream<T extends Data>(input: MaybeStream<T>): input is Stream<T>;
24+
25+
export function slice<T extends Data, InputType extends MaybeStream<T>>(
26+
input: InputType,
27+
begin: number,
28+
end?: number | typeof Infinity
29+
): InputType; // same as 'typeof input'

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
"tsconfig.json"
99
],
1010
"exports": {
11-
"types": "./lib/index.d.ts",
11+
"types@<5.5": "./lib/types/v4.7-v5.4/index.d.ts",
12+
"types": "./lib/types/index.d.ts",
1213
"import": "./lib/index.js"
1314
},
14-
"types": "./lib/index.d.ts",
15+
"typesVersions": {
16+
">=5.5": { ".": ["lib/types/index.d.ts"] },
17+
">=4.7": { ".": ["lib/types/v4.7-v5.4/index.d.ts"] }
18+
},
1519
"main": "./lib/index.js",
1620
"engines": {
1721
"node": ">= 18.0.0"
@@ -66,7 +70,7 @@
6670
"test-type-definitions": "tsc --project test/tsconfig.json && tsx test/typescript.test.ts && npm run test-type-definitions-es5",
6771
"test-type-definitions-es5": "tsc --project test/tsconfig.es5.json && tsx --tsconfig test/tsconfig.es5.json test/typescript.test.ts",
6872
"test-browser": "karma start karma.conf.cjs",
69-
"test-node": "ts-mocha -n loader=ts-node/esm ./test/node.test.ts ./test/common.test.ts",
73+
"test-node": "NODE_OPTIONS='--import=tsx' mocha ./test/node.test.ts ./test/common.test.ts",
7074
"lint": "eslint lib test",
7175
"docs": "jsdoc --configure .jsdocrc.cjs --destination docs --readme README.md lib && printf '%s' 'web-stream-tools.openpgpjs.org' > docs/CNAME",
7276
"preversion": "rm -rf docs",

0 commit comments

Comments
 (0)