isaacs / node-tar

tar for node
ISC License
837 stars 183 forks source link

[7.0.1][Type Regression] Property 'write' in type 'Pack' is not assignable to the same property in base type 'Minipass<Buffer, ContiguousData>'. #413

Closed maka-io closed 5 months ago

maka-io commented 5 months ago

With 7.0.1:

node_modules/tar/dist/commonjs/pack.d.ts:70:5 - error TS2416: Property 'end' in type 'Pack' is not assignable to the same property in base type 'Minipass<Buffer, ContiguousData>'.
  Type '(path?: string | ReadEntry | undefined) => this' is not assignable to type '{ (cb?: (() => void) | undefined): this; (chunk: any, cb?: (() => void) | undefined): this; (chunk: any, encoding?: Encoding | undefined, cb?: (() => void) | undefined): this; }'.
    Types of parameters 'path' and 'cb' are incompatible.
      Type '(() => void) | undefined' is not assignable to type 'string | ReadEntry | undefined'.
        Type '() => void' is not assignable to type 'string | ReadEntry | undefined'.

70     end(path?: string | ReadEntry): this;
       ~~~

This works with version 6.2.1:

public async extractTarGz(tarFilePath: string, destDirectory: string): Promise<void> {
    function getFileSize(filePath: string) {
      const stats = fs.statSync(filePath);
      return stats.size;
    }

    // extract graphic
    const graphic = (process.platform === 'win32') ? '>' : '\u{1F4E6}';
    const totalSize = getFileSize(tarFilePath);
    const progressBar = new Progress(totalSize, "Extracting", graphic);

    return new Promise((resolve, reject) => {
      const extractor = tar.extract({ cwd: destDirectory });

      fs.createReadStream(tarFilePath)
        .pipe(zlib.createGunzip())  // decompressing gzip file before passing it to tar
        .pipe(extractor as ReturnType<typeof tar.extract> & NodeJS.WritableStream)
        .on('data', (chunk) => {
          progressBar.update(chunk.length);
        })
        .on('end', () => {
          progressBar.complete();
          resolve();
        })
        .on('error', (err) => {
          reject(err);
        });
    });
  }
pamelalozano16 commented 5 months ago

I think the problem might be because the minipass version is outdated. Current version: "minipass": "^5.0.0" Latest version: "minipass": "^7.0.4"

isaacs commented 5 months ago

Yeah, if you don't give the lib the deps in the range it expects, it's not gonna work.

Builds fine on my machine, please provide a reproducible test case and steps to view the error.

pamelalozano16 commented 5 months ago

Here's a minimal repo that reproduces the error: https://gist.github.com/nex3/b7b308d5b5c8d46173454beb1be844f0. To run: npm install, npx tsc.

Regarding the outdated dependency, I noticed that node-tar depends on minipass@5.0.0. I see you're behind both projects, is there a particular reason for sticking with this version? 🤔