Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node/stream): Make Stream the default export #901

Merged
merged 1 commit into from
May 7, 2021
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
16 changes: 16 additions & 0 deletions node/_stream/stream.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Copyright Node.js contributors. All rights reserved. MIT License.
import { Buffer } from "../buffer.ts";
import type Duplex from "./duplex.ts";
import type eos from "./end_of_stream.ts";
import EventEmitter from "../events.ts";
import type PassThrough from "./passthrough.ts";
import type pipeline from "./pipeline.ts";
import type * as promises from "./promises.ts";
import type Readable from "./readable.ts";
import type Transform from "./transform.ts";
import type Writable from "./writable.ts";
import { types } from "../util.ts";

Expand Down Expand Up @@ -76,6 +82,16 @@ class Stream extends EventEmitter {

return dest;
}

static Readable: typeof Readable;
static Writable: typeof Writable;
static Duplex: typeof Duplex;
static Transform: typeof Transform;
static PassThrough: typeof PassThrough;
static pipeline: typeof pipeline;
static finished: typeof eos;
static promises: typeof promises;
static Stream: typeof Stream;
}

export default Stream;
24 changes: 12 additions & 12 deletions node/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@ import Stream from "./_stream/stream.ts";
import Transform from "./_stream/transform.ts";
import Writable from "./_stream/writable.ts";

const exports = {
Duplex,
finished: eos,
PassThrough,
pipeline,
promises,
Readable,
Stream,
Transform,
Writable,
};
// This is here because doing it in _stream/stream.ts created some circular dependency hell.
Stream.Readable = Readable;
Stream.Writable = Writable;
Stream.Duplex = Duplex;
Stream.Transform = Transform;
Stream.PassThrough = PassThrough;
Stream.pipeline = pipeline;
Stream.finished = eos;
Stream.promises = promises;
Stream.Stream = Stream;

export default exports;
export default Stream;
export {
Duplex,
eos as finished,
Expand All @@ -51,3 +50,4 @@ export {
Transform,
Writable,
};
export const { _isUint8Array, _uint8ArrayToBuffer } = Stream;
17 changes: 15 additions & 2 deletions node/stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
import { Readable, Transform, Writable } from "./stream.ts";
import streamDefault, {
Readable,
Stream,
Transform,
Writable,
} from "./stream.ts";
import { Buffer } from "./buffer.ts";
import { deferred } from "../async/mod.ts";
import { assert, assertEquals } from "../testing/asserts.ts";
import {
assert,
assertEquals,
assertStrictEquals,
} from "../testing/asserts.ts";
import { mustCall } from "./_utils.ts";

Deno.test("Readable and Writable stream backpressure test", async () => {
Expand Down Expand Up @@ -131,3 +140,7 @@ Deno.test("Readable can be piped through Transform", async () => {
await flushExecution;
await readableExecution;
});

Deno.test("The default export is Stream", () => {
assertStrictEquals(streamDefault, Stream);
});
Comment on lines +144 to +146
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍