Skip to content

Commit

Permalink
No default export, only named
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 9, 2023
1 parent 815a2ef commit 252523f
Show file tree
Hide file tree
Showing 38 changed files with 101 additions and 115 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# chernge lerg

## 5.0

- No default export, only a named export

## 4.2

- add AbortSignal support
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ Example:

```js
// hybrid module, either works
import Minipass from 'minipass'
import { Minipass } from 'minipass'
// or:
const Minipass = require('minipass')
const { Minipass } = require('minipass')

const stream = new Minipass()
stream.on('data', () => console.log('data event'))
Expand All @@ -116,9 +116,9 @@ options, or by setting `stream.async = true` later on.

```js
// hybrid module, either works
import Minipass from 'minipass'
import { Minipass } from 'minipass'
// or:
const Minipass = require('minipass')
const { Minipass } = require('minipass')

const asyncStream = new Minipass({ async: true })
asyncStream.on('data', () => console.log('data event'))
Expand All @@ -135,7 +135,7 @@ Switching _out_ of async mode is unsafe, as it could cause data
corruption, and so is not enabled. Example:

```js
import Minipass from 'minipass'
import { Minipass } from 'minipass'
const stream = new Minipass({ encoding: 'utf8' })
stream.on('data', chunk => console.log(chunk))
stream.async = true
Expand All @@ -156,7 +156,7 @@ To avoid this problem, once set into async mode, any attempt to
make the stream sync again will be ignored.

```js
const Minipass = require('minipass')
const { Minipass } = require('minipass')
const stream = new Minipass({ encoding: 'utf8' })
stream.on('data', chunk => console.log(chunk))
stream.async = true
Expand Down Expand Up @@ -384,7 +384,7 @@ It's a stream! Use it like a stream and it'll most likely do what
you want.

```js
import Minipass from 'minipass'
import { Minipass } from 'minipass'
const mp = new Minipass(options) // optional: { encoding, objectMode }
mp.write('foo')
mp.pipe(someOtherStream)
Expand Down
18 changes: 0 additions & 18 deletions index.d.mts

This file was deleted.

35 changes: 18 additions & 17 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,62 @@
import { EventEmitter } from 'events'
import { Stream } from 'stream'

declare namespace Minipass {
type Encoding = BufferEncoding | 'buffer' | null
export namespace Minipass {
export type Encoding = BufferEncoding | 'buffer' | null

interface Writable extends EventEmitter {
export interface Writable extends EventEmitter {
end(): any
write(chunk: any, ...args: any[]): any
}

interface Readable extends EventEmitter {
export interface Readable extends EventEmitter {
pause(): any
resume(): any
pipe(): any
}

type DualIterable<T> = Iterable<T> & AsyncIterable<T>
export type DualIterable<T> = Iterable<T> & AsyncIterable<T>

type ContiguousData = Buffer | ArrayBufferLike | ArrayBufferView | string
export type ContiguousData =
| Buffer
| ArrayBufferLike
| ArrayBufferView
| string

type BufferOrString = Buffer | string
export type BufferOrString = Buffer | string

interface SharedOptions {
export interface SharedOptions {
async?: boolean
signal?: AbortSignal
}

interface StringOptions extends SharedOptions {
export interface StringOptions extends SharedOptions {
encoding: BufferEncoding
objectMode?: boolean
}

interface BufferOptions extends SharedOptions {
export interface BufferOptions extends SharedOptions {
encoding?: null | 'buffer'
objectMode?: boolean
}

interface ObjectModeOptions extends SharedOptions {
export interface ObjectModeOptions extends SharedOptions {
objectMode: true
}

interface PipeOptions {
export interface PipeOptions {
end?: boolean
proxyErrors?: boolean
}

type Options<T> = T extends string
export type Options<T> = T extends string
? StringOptions
: T extends Buffer
? BufferOptions
: ObjectModeOptions
}

declare class Minipass<
export class Minipass<
RType extends any = Buffer,
WType extends any = RType extends Minipass.BufferOrString
? Minipass.ContiguousData
Expand Down Expand Up @@ -146,6 +150,3 @@ declare class Minipass<
[Symbol.iterator](): Generator<RType, void, void>
[Symbol.asyncIterator](): AsyncGenerator<RType, void, void>
}

export default Minipass;
export = Minipass;
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,5 +699,4 @@ class Minipass extends Stream {
}
}

Minipass.default = Minipass
module.exports = Minipass
exports.Minipass = Minipass
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"exports": {
".": {
"import": {
"types": "./index.d.mts",
"types": "./index.d.ts",
"default": "./index.mjs"
},
"require": {
Expand Down Expand Up @@ -52,7 +52,6 @@
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"license": "ISC",
"files": [
"index.d.mts",
"index.d.ts",
"index.js",
"index.mjs"
Expand Down
3 changes: 2 additions & 1 deletion scripts/transpile-to-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const { readFileSync, writeFileSync } = require('fs')
const { resolve } = require('path')
const cjs = readFileSync(resolve(__dirname, '../index.js'), 'utf8')
const esm = cjs
.replace(/module.exports\s*=\s*/, 'export default ')
.replace(/exports\.Minipass\s*=[^\n]*/, '')
.replace(/class Minipass /, 'export class Minipass ')
.replace(
/const ([a-zA-Z0-9]+)\s*=\s*require\('([^']+)'\)/g,
`import $1 from '$2'`
Expand Down
2 changes: 1 addition & 1 deletion test/abort.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const MM = require('../')
const { Minipass: MM } = require('../')
const t = require('tap')
if (typeof AbortSignal === 'undefined') {
Object.assign(global, require('node-abort-controller'))
Expand Down
2 changes: 1 addition & 1 deletion test/array-buffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const stringToArrayBuffer = s => {
return ab
}

const MP = require('../')
const { Minipass: MP } = require('../')

const e = { encoding: 'utf8' }
t.test('write array buffer', t => {
Expand Down
2 changes: 1 addition & 1 deletion test/async-duplicate-end.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Minipass = require('../')
const { Minipass } = require('../')
const t = require('tap')

t.test('async pipes should only end one time', t => {
Expand Down
2 changes: 1 addition & 1 deletion test/async-stream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const t = require('tap')
const MP = require('../')
const { Minipass: MP } = require('../')

t.test('pipe', t => {
const m = new MP({ encoding: 'utf8', async: true })
Expand Down
2 changes: 1 addition & 1 deletion test/auto-end-deferred-when-paused.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const t = require('tap')
const MP = require('../')
const { Minipass: MP } = require('../')
t.test('do not auto-end empty stream if explicitly paused', t => {
const mp = new MP()
let waitedForEnd = false
Expand Down
Loading

0 comments on commit 252523f

Please sign in to comment.