diff --git a/src/options.ts b/src/options.ts index 4a388875..92aced05 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,5 +1,6 @@ // turn tar(1) style args like `C` into the more verbose things like `cwd` +import type { Minipass } from 'minipass' import { type GzipOptions, type ZlibOptions } from 'minizlib' import { type Stats } from 'node:fs' import { type ReadEntry } from './read-entry.js' @@ -248,7 +249,7 @@ export interface TarOptions { */ transform?: ( entry: ReadEntry, - ) => ReadEntry | null | undefined | false | 0 | '' + ) => ReadEntry | Minipass | null | undefined | false | 0 | '' /** * Call `chmod()` to ensure that extracted files match the entry's mode diff --git a/test/transform-type-check.ts b/test/transform-type-check.ts new file mode 100644 index 00000000..9fbe0ab4 --- /dev/null +++ b/test/transform-type-check.ts @@ -0,0 +1,16 @@ +import { Minipass } from 'minipass' +import { extract } from '../src/extract.js' +import { Unpack } from '../src/unpack.js' + +// MiniPass stream return (issue #462) +const streamTransform = () => new Minipass({ async: true }) +extract({ transform: streamTransform }, []) +new Unpack({ transform: streamTransform }) + +// entry / falsey return remains valid (issue #459) +extract({ transform: entry => entry }, []) +extract({ transform: () => undefined }, []) +extract({ transform: () => false }, []) + +import { pass } from 'tap' +pass(`transform may return a stream or a falsey value`)