Skip to content

Commit da42405

Browse files
committed
fix: use tar.Parser instead of tar.list() for tar v7 compatibility
tar.list() in tar v7 does not emit 'data' or 'end' events on entries - it only lists metadata. tar.Parser provides readable entries that properly emit data for file contents. Also added entry.resume() for skipped entries (directories/symlinks) to ensure the stream continues parsing. Agent-Id: agent-2d976f8c-dc0a-4f5f-be80-d3b0e92832d8
1 parent 1f178a3 commit da42405

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

package-lock.json

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sources/github.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import { Readable } from "node:stream";
3333
import ignoreFactory, { type Ignore } from "ignore";
3434
import * as tar from "tar";
35-
import type { ReadEntry } from "tar";
35+
import type { Parser, ReadEntry } from "tar";
3636
import { shouldFilterFile } from "../core/file-filter.js";
3737
import { isoTimestamp } from "../core/utils.js";
3838
import type { FileEntry, FileInfo, SourceMetadata } from "../core/types.js";
@@ -302,10 +302,14 @@ export class GitHubSource implements Source {
302302
const stream = Readable.from(buffer);
303303

304304
await new Promise<void>((resolve, reject) => {
305-
const parser = tar.list({
305+
// Use tar.Parser instead of tar.list() because tar.list() in tar v7
306+
// does not emit 'data' or 'end' events on entries - it only lists metadata.
307+
// tar.Parser provides readable entries that emit data for file contents.
308+
const parser: Parser = new tar.Parser({
306309
onReadEntry: (entry: ReadEntry) => {
307310
// Skip directories and symlinks
308311
if (entry.type !== "File") {
312+
entry.resume(); // drain the entry to continue parsing
309313
return;
310314
}
311315

@@ -336,9 +340,7 @@ export class GitHubSource implements Source {
336340

337341
stream.pipe(parser);
338342
parser.on("close", resolve);
339-
// Handle parser errors (tar library types don't include error event, but the underlying stream does)
340-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
341-
(parser as any).on("error", reject);
343+
parser.on("error", reject);
342344
stream.on("error", reject);
343345
});
344346

src/sources/gitlab.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Readable } from "node:stream";
66
import ignoreFactory, { type Ignore } from "ignore";
77
import * as tar from "tar";
8-
import type { ReadEntry } from "tar";
8+
import type { Parser, ReadEntry } from "tar";
99
import { shouldFilterFile } from "../core/file-filter.js";
1010
import { isoTimestamp } from "../core/utils.js";
1111
import type { FileEntry, FileInfo, SourceMetadata } from "../core/types.js";
@@ -256,10 +256,14 @@ export class GitLabSource implements Source {
256256
const stream = Readable.from(buffer);
257257

258258
await new Promise<void>((resolve, reject) => {
259-
const parser = tar.list({
259+
// Use tar.Parser instead of tar.list() because tar.list() in tar v7
260+
// does not emit 'data' or 'end' events on entries - it only lists metadata.
261+
// tar.Parser provides readable entries that emit data for file contents.
262+
const parser: Parser = new tar.Parser({
260263
onReadEntry: (entry: ReadEntry) => {
261264
// Skip directories and symlinks
262265
if (entry.type !== "File") {
266+
entry.resume(); // drain the entry to continue parsing
263267
return;
264268
}
265269

@@ -290,9 +294,7 @@ export class GitLabSource implements Source {
290294

291295
stream.pipe(parser);
292296
parser.on("close", resolve);
293-
// Handle parser errors (tar library types don't include error event, but the underlying stream does)
294-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
295-
(parser as any).on("error", reject);
297+
parser.on("error", reject);
296298
stream.on("error", reject);
297299
});
298300

0 commit comments

Comments
 (0)