Skip to content

Commit

Permalink
kludge around TS pedantry
Browse files Browse the repository at this point in the history
fix: #421
  • Loading branch information
isaacs committed Jul 24, 2024
1 parent f1d7a4d commit 35d8d99
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
39 changes: 30 additions & 9 deletions src/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class PackJob {

import { Minipass } from 'minipass'
import * as zlib from 'minizlib'
//@ts-ignore
import { Yallist } from 'yallist'
import { ReadEntry } from './read-entry.js'
import {
Expand Down Expand Up @@ -68,7 +67,7 @@ import { normalizeWindowsPath } from './normalize-windows-path.js'
import { TarOptions } from './options.js'

export class Pack
extends Minipass<Minipass.ContiguousData, Buffer, WarnEvent>
extends Minipass<Buffer, ReadEntry | string, WarnEvent<Buffer>>
implements Warner
{
opt: TarOptions
Expand Down Expand Up @@ -99,6 +98,7 @@ export class Pack
[ENDED]: boolean = false

constructor(opt: TarOptions = {}) {
//@ts-ignore
super()
this.opt = opt
this.file = opt.file || ''
Expand Down Expand Up @@ -142,7 +142,7 @@ export class Pack
/* c8 ignore next */
if (!this.zip) throw new Error('impossible')
const zip = this.zip
zip.on('data', chunk => super.write(chunk))
zip.on('data', chunk => super.write(chunk as unknown as string))
zip.on('end', () => super.end())
zip.on('drain', () => this[ONDRAIN]())
this.on('resume', () => zip.resume())
Expand All @@ -166,25 +166,46 @@ export class Pack
}

[WRITE](chunk: Buffer) {
return super.write(chunk)
return super.write(chunk as unknown as string)
}

add(path: string | ReadEntry) {
this.write(path)
return this
}

//@ts-ignore
end(path?: string | ReadEntry) {
end(cb?: () => void): this
end(path: string | ReadEntry, cb?: () => void): this
end(
path: string | ReadEntry,
encoding?: Minipass.Encoding,
cb?: () => void,
): this
end(
path?: string | ReadEntry | (() => void),
encoding?: Minipass.Encoding | (() => void),
cb?: () => void,
) {
/* c8 ignore start */
if (typeof path === 'function') {
cb = path
path = undefined
}
if (typeof encoding === 'function') {
cb = encoding
encoding = undefined
}
/* c8 ignore stop */
if (path) {
this.add(path)
}
this[ENDED] = true
this[PROCESS]()
/* c8 ignore next */
if (cb) cb()
return this
}

//@ts-ignore
write(path: string | ReadEntry) {
if (this[ENDED]) {
throw new Error('write after end')
Expand Down Expand Up @@ -293,7 +314,7 @@ export class Pack
if (this.zip) {
this.zip.end(EOF)
} else {
super.write(EOF)
super.write(EOF as unknown as string)
super.end()
}
}
Expand Down Expand Up @@ -432,7 +453,7 @@ export class Pack
})
} else {
source.on('data', chunk => {
if (!super.write(chunk)) {
if (!super.write(chunk as unknown as string)) {
source.pause()
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/warn-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type Warner = {
emit(event: 'error', error: TarError): void
}

export type WarnEvent = Minipass.Events & {
export type WarnEvent<T = Buffer> = Minipass.Events<T> & {
warn: [code: string, message: string, data: WarnData]
}

Expand Down

0 comments on commit 35d8d99

Please sign in to comment.