Skip to content

Commit

Permalink
update minipass
Browse files Browse the repository at this point in the history
This got overlooked in the previous update, and should address some of the
portability and extension challenges with various event types.
  • Loading branch information
isaacs committed May 3, 2024
1 parent bead873 commit 79a5c30
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@isaacs/fs-minipass": "^4.0.0",
"chownr": "^3.0.0",
"minipass": "^5.0.0",
"minipass": "^7.0.4",
"minizlib": "^3.0.1",
"mkdirp": "^3.0.1",
"yallist": "^5.0.0"
Expand Down
6 changes: 5 additions & 1 deletion src/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import * as zlib from 'minizlib'
import { Yallist } from 'yallist'
import { ReadEntry } from './read-entry.js'
import {
WarnEvent,
warnMethod,
type WarnData,
type Warner,
Expand Down Expand Up @@ -66,7 +67,10 @@ import path from 'path'
import { normalizeWindowsPath } from './normalize-windows-path.js'
import { TarOptions } from './options.js'

export class Pack extends Minipass implements Warner {
export class Pack
extends Minipass<Minipass.ContiguousData, Buffer, WarnEvent>
implements Warner
{
opt: TarOptions
cwd: string
maxReadSize?: number
Expand Down
6 changes: 6 additions & 0 deletions src/warn-method.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { type Minipass } from 'minipass'

/** has a warn method */
export type Warner = {
warn(code: string, message: string | Error, data: any): void
Expand All @@ -14,6 +16,10 @@ export type Warner = {
emit(event: 'error', error: TarError): void
}

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

export type WarnData = {
file?: string
cwd?: string
Expand Down
20 changes: 16 additions & 4 deletions src/write-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { ReadEntry } from './read-entry.js'
import { stripAbsolutePath } from './strip-absolute-path.js'
import { stripTrailingSlashes } from './strip-trailing-slashes.js'
import { EntryTypeName } from './types.js'
import { WarnData, Warner, warnMethod } from './warn-method.js'
import {
WarnData,
Warner,
WarnEvent,
warnMethod,
} from './warn-method.js'
import * as winchars from './winchars.js'

const prefixPath = (path: string, prefix?: string) => {
Expand Down Expand Up @@ -47,7 +52,14 @@ const AWAITDRAIN = Symbol('awaitDrain')
const ONDRAIN = Symbol('ondrain')
const PREFIX = Symbol('prefix')

export class WriteEntry extends Minipass<Buffer> implements Warner {
export class WriteEntry
extends Minipass<
Minipass.ContiguousData,
Buffer,
WarnEvent
>
implements Warner
{
path: string
portable: boolean
myuid: number = (process.getuid && process.getuid()) || 0
Expand Down Expand Up @@ -154,7 +166,7 @@ export class WriteEntry extends Minipass<Buffer> implements Warner {
return warnMethod(this, code, message, data)
}

emit(ev: string, ...data: any[]) {
emit(ev: keyof WarnEvent, ...data: any[]) {
if (ev === 'error') {
this.#hadError = true
}
Expand Down Expand Up @@ -556,7 +568,7 @@ export class WriteEntrySync extends WriteEntry implements Warner {
}

export class WriteEntryTar
extends Minipass<Buffer>
extends Minipass<Buffer, Buffer, WarnEvent>
implements Warner
{
blockLen: number = 0
Expand Down

0 comments on commit 79a5c30

Please sign in to comment.