Skip to content

Commit

Permalink
feat: remove dependency on web-streams-polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Mar 5, 2024
1 parent 7355339 commit c77c20b
Show file tree
Hide file tree
Showing 5 changed files with 902 additions and 35 deletions.
8 changes: 0 additions & 8 deletions common/config/rush/pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion common/config/rush/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "bc889a61b743d7da6baea855100853c1762ba21e",
"pnpmShrinkwrapHash": "b28df542a76f6fa0278a6caf978856555b64b5ff",
"preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f"
}
3 changes: 1 addition & 2 deletions libraries/stream-extra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"dependencies": {
"@yume-chan/async": "^2.2.0",
"@yume-chan/struct": "workspace:^0.0.22",
"tslib": "^2.6.2",
"web-streams-polyfill": "^4.0.0"
"tslib": "^2.6.2"
},
"devDependencies": {
"@jest/globals": "^30.0.0-alpha.2",
Expand Down
43 changes: 19 additions & 24 deletions libraries/stream-extra/src/stream.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { AbortSignal } from "web-streams-polyfill";
import {
ReadableStream as ReadableStreamPolyfill,
TransformStream as TransformStreamPolyfill,
WritableStream as WritableStreamPolyfill,
} from "web-streams-polyfill";
export * from "web-streams-polyfill";
import type {
AbortSignal,
ReadableStream as ReadableStreamType,
TransformStream as TransformStreamType,
WritableStream as WritableStreamType,
} from "./types.js";

export * from "./types.js";

/** A controller object that allows you to abort one or more DOM requests as and when desired. */
export interface AbortController {
Expand All @@ -26,26 +27,20 @@ interface AbortControllerConstructor {

interface GlobalExtension {
AbortController: AbortControllerConstructor;
ReadableStream: typeof ReadableStreamPolyfill;
WritableStream: typeof WritableStreamPolyfill;
TransformStream: typeof TransformStreamPolyfill;
ReadableStream: typeof ReadableStreamType;
WritableStream: typeof WritableStreamType;
TransformStream: typeof TransformStreamType;
}

const GLOBAL = globalThis as unknown as GlobalExtension;

export const AbortController = GLOBAL.AbortController;
const Global = globalThis as unknown as GlobalExtension;

export type ReadableStream<R = any> = ReadableStreamPolyfill<R>;
export let ReadableStream = ReadableStreamPolyfill;
export const AbortController = Global.AbortController;

export type WritableStream<W = any> = WritableStreamPolyfill<W>;
export let WritableStream = WritableStreamPolyfill;
export type ReadableStream<T = any> = ReadableStreamType<T>;
export const ReadableStream = Global.ReadableStream;

export type TransformStream<I = any, O = any> = TransformStreamPolyfill<I, O>;
export let TransformStream = TransformStreamPolyfill;
export type WritableStream<T = any> = WritableStreamType<T>;
export const WritableStream = Global.WritableStream;

if (GLOBAL.ReadableStream && GLOBAL.WritableStream && GLOBAL.TransformStream) {
ReadableStream = GLOBAL.ReadableStream;
WritableStream = GLOBAL.WritableStream;
TransformStream = GLOBAL.TransformStream;
}
export type TransformStream<I = any, O = any> = TransformStreamType<I, O>;
export const TransformStream = Global.TransformStream;
Loading

0 comments on commit c77c20b

Please sign in to comment.