Skip to content

Commit

Permalink
Rewrite in TypeScript
Browse files Browse the repository at this point in the history
This is a big one, please read carefully before upgrading from
prior versions, especially if you extend Minipass in a subclass.

*** Breaking Changes ***

- Rewritten in TypeScript as hybrid esm/cjs build, so a lot of
  types changed in subtle ways, and several behaviors got
  stricter.
- Minipass now inherits from `EventEmitter` rather than `Stream`.
  Nothing from the `Stream` class was ever used by Minipass, but
  it inherited from `Stream` to pass checks in some stream
  libraries that checked `instanceof Stream`. Unfortunately, the
  type difference in the `pipe()` method signature made it
  challenging to continue doing in TypeScript.
- It is no longer possible to change the type of data emitted
  after a Minipass stream is instantiated, as this would thwart
  TypeScript's static checks. As a consequence:
  - The `setEncoding` method and the `encoding` setter are
    deprecated. Encoding may _only_ be set in the constructor
    options object.
  - `objectMode` is no longer inferred by writing something other
    than a string or Buffer. It may _only_ be set in the
    constructor options object.
- If all existing data consumers are removed, via
  `stream.unpipe(dest)`, `stream.removeListener('data', handler)`,
  `stream.removeAllListeners('data')`, and/or
  `stream.removeAllListeners()`, then the data will stop flowing.
  Note that it is still possible to explicitly discard a stream's
  data by calling `stream.resume()` in the absence of any
  consumers.

*** Features and Fixes ***

- Removed a very subtle performance issue that made objectMode
  Minipass streams slower in some cases than node core streams.
  Minipass is now faster than node core streams for all data
  types.
- The array returned by `stream.collect()` for objectMode streams
  will have a `dataLength` property equal to 0, rather than
  undefined.
- `isStream` is moved from a static member on the Minipass class
  to a named export.
- `isWritable()` and `isReadable()` methods added.
  • Loading branch information
isaacs committed Jul 8, 2023
1 parent 9853113 commit 838c855
Show file tree
Hide file tree
Showing 122 changed files with 4,016 additions and 2,532 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x]
platform:
- os: ubuntu-latest
shell: bash
Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.*.swp
node_modules
.nyc_output/
coverage/
/index.mjs
/.nyc_output/
/coverage/
/dist
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
# chernge lerg

## 7.0

This is a big one, please read carefully before upgrading from
prior versions, especially if you extend Minipass in a subclass.

### Breaking Changes

- Rewritten in TypeScript as hybrid esm/cjs build, so a lot of
types changed in subtle ways, and several behaviors got
stricter.
- Minipass now inherits from `EventEmitter` rather than `Stream`.
Nothing from the `Stream` class was ever used by Minipass, but
it inherited from `Stream` to pass checks in some stream
libraries that checked `instanceof Stream`. Unfortunately, the
type difference in the `pipe()` method signature made it
challenging to continue doing in TypeScript.
- It is no longer possible to change the type of data emitted
after a Minipass stream is instantiated, as this would thwart
TypeScript's static checks. As a consequence:
- The `setEncoding` method and the `encoding` setter are
deprecated. Encoding may _only_ be set in the constructor
options object.
- `objectMode` is no longer inferred by writing something other
than a string or Buffer. It may _only_ be set in the
constructor options object.
- If all existing data consumers are removed, via
`stream.unpipe(dest)`, `stream.removeListener('data', handler)`,
`stream.removeAllListeners('data')`, and/or
`stream.removeAllListeners()`, then the data will stop flowing.
Note that it is still possible to explicitly discard a stream's
data by calling `stream.resume()` in the absence of any
consumers.

### Features and Fixes

- Removed a very subtle performance issue that made objectMode
Minipass streams slower in some cases than node core streams.
Minipass is now faster than node core streams for all data
types.
- The array returned by `stream.collect()` for objectMode streams
will have a `dataLength` property equal to 0, rather than
undefined.
- `isStream` is moved from a static member on the Minipass class
to a named export.
- `isWritable()` and `isReadable()` methods added.

## 6.0

- Define event argument types in an extensible manner, defaulting
Expand Down
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ written will be emitted. Otherwise, it'll do a minimal amount of
Buffer copying to ensure proper Streams semantics when `read(n)`
is called.

`objectMode` can also be set by doing `stream.objectMode = true`,
or by writing any non-string/non-buffer data. `objectMode` cannot
be set to false once it is set.
`objectMode` can only be set at instantiation. Attempting to
write something other than a String or Buffer without having set
`objectMode` in the options will throw an error.

This is not a `through` or `through2` stream. It doesn't
transform the data, it just passes it right through. If you want
Expand Down Expand Up @@ -444,7 +444,7 @@ you want.

```js
import { Minipass } from 'minipass'
const mp = new Minipass(options) // optional: { encoding, objectMode }
const mp = new Minipass(options) // options is optional
mp.write('foo')
mp.pipe(someOtherStream)
mp.end('bar')
Expand Down Expand Up @@ -483,8 +483,6 @@ Implements the user-facing portions of Node.js's `Readable` and
- `end([chunk, [encoding]], [callback])` - Signal that you have
no more data to write. This will queue an `end` event to be
fired when all the data has been consumed.
- `setEncoding(encoding)` - Set the encoding for data coming of
the stream. This can only be done once.
- `pause()` - No more data for a while, please. This also
prevents `end` from being emitted for empty streams until the
stream is resumed.
Expand Down Expand Up @@ -535,9 +533,7 @@ Implements the user-facing portions of Node.js's `Readable` and

- `bufferLength` Read-only. Total number of bytes buffered, or in
the case of objectMode, the total number of objects.
- `encoding` The encoding that has been set. (Setting this is
equivalent to calling `setEncoding(enc)` and has the same
prohibition against setting multiple times.)
- `encoding` Read-only. The encoding that has been set.
- `flowing` Read-only. Boolean indicating whether a chunk written
to the stream will be immediately emitted.
- `emittedEnd` Read-only. Boolean indicating whether the end-ish
Expand All @@ -554,7 +550,6 @@ Implements the user-facing portions of Node.js's `Readable` and
- `paused` True if the stream has been explicitly paused,
otherwise false.
- `objectMode` Indicates whether the stream is in `objectMode`.
Once set to `true`, it cannot be set to `false`.
- `aborted` Readonly property set when the `AbortSignal`
dispatches an `abort` event.

Expand Down Expand Up @@ -758,6 +753,7 @@ class SlowEnd extends Minipass {
console.log('ok, ready to end now')
super.emit('end', ...args)
}, 100)
return true
} else {
return super.emit(ev, ...args)
}
Expand Down
Loading

0 comments on commit 838c855

Please sign in to comment.