From aaafce4ace885aa40e58b0fe7591aeb67058b8d0 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:39:58 +0000 Subject: [PATCH 1/2] Keep yauzl and yazl types out of lib's published declarations ZipArchive exposed yauzl.ZipFile and yauzl.Entry in its public members and zipOutputStream took a yazl.ZipFile, so @types/yauzl and @types/yazl had to be runtime dependencies of @clusterio/lib. They pull in @types/node and undici-types, about 2.7 MB in every server install. Entries are now typed with a local ZipEntry interface, the yauzl ZipFile is private, and zipOutputStream takes any object with an outputStream and an error event. ZipWriter.addEntry reads the compressed bytes through the new ZipArchive.openRawStream. Both type packages move to devDependencies. Co-Authored-By: Claude Opus 5.5 --- packages/lib/package.json | 4 +-- packages/lib/src/zip_ops.ts | 49 +++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/packages/lib/package.json b/packages/lib/package.json index 53a1ba2b..aca70df1 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -51,8 +51,6 @@ "dependencies": { "@sinclair/typebox": "catalog:", - "@types/yauzl": "catalog:", - "@types/yazl": "catalog:", "ajv": "^8.20.0", "chalk": "catalog:", "fast-deep-equal": "^3.1.3", @@ -71,6 +69,8 @@ "@types/triple-beam": "^1.3.5", "@types/ws": "catalog:", "@types/yargs": "catalog:", + "@types/yauzl": "catalog:", + "@types/yazl": "catalog:", "typescript": "catalog:" } } diff --git a/packages/lib/src/zip_ops.ts b/packages/lib/src/zip_ops.ts index b7087caf..c8a12037 100644 --- a/packages/lib/src/zip_ops.ts +++ b/packages/lib/src/zip_ops.ts @@ -7,10 +7,28 @@ import { PassThrough, type Readable } from "stream"; import util from "util"; import zlib from "zlib"; import yauzl from "yauzl"; -import type yazl from "yazl"; const deflateRaw = util.promisify(zlib.deflateRaw); +/** + * Entry in a ZipArchive + */ +export interface ZipEntry { + fileName: string; + fileComment: string; + versionMadeBy: number; + versionNeededToExtract: number; + generalPurposeBitFlag: number; + compressionMethod: number; + lastModFileTime: number; + lastModFileDate: number; + crc32: number; + compressedSize: number; + uncompressedSize: number; + externalFileAttributes: number; + getLastModDate(options?: { timezone?: "local" | "UTC" | null, forceDosFormat?: boolean }): Date; +} + /** * Zip archive opened for random access reading @@ -21,10 +39,9 @@ const deflateRaw = util.promisify(zlib.deflateRaw); */ export class ZipArchive { private constructor( - /** Underlying yauzl zip file. */ - public zipfile: yauzl.ZipFile, + private zipfile: yauzl.ZipFile, /** Entries by file name in the order they appear in the central directory. */ - public entries: Map, + public entries: Map, ) { } /** @@ -77,8 +94,17 @@ export class ZipArchive { * * @param entry - Entry to read, must belong to this archive. */ - openStream(entry: yauzl.Entry): Promise { - return this.zipfile.openReadStreamPromise(entry); + openStream(entry: ZipEntry): Promise { + return this.zipfile.openReadStreamPromise(entry as yauzl.Entry); + } + + /** + * Open a stream of the content of an entry as stored in the archive + * + * @param entry - Entry to read, must belong to this archive. + */ + openRawStream(entry: ZipEntry): Promise { + return this.zipfile.openReadStreamPromise(entry as yauzl.Entry, { decodeFileData: false }); } /** @@ -86,7 +112,7 @@ export class ZipArchive { * * @param entry - Entry to read, must belong to this archive. */ - async readEntry(entry: yauzl.Entry) { + async readEntry(entry: ZipEntry) { const chunks: Buffer[] = []; for await (const chunk of await this.openStream(entry)) { chunks.push(chunk); @@ -153,7 +179,10 @@ export function findRoot(zip: ZipArchive) { * * @param zipFile - zip file being written. */ -export function zipOutputStream(zipFile: yazl.ZipFile) { +export function zipOutputStream(zipFile: { + outputStream: NodeJS.ReadableStream, + on(event: "error", listener: (err: Error) => void): unknown, +}) { const output = zipFile.outputStream as Readable; zipFile.on("error", err => output.destroy(err)); return output; @@ -224,7 +253,7 @@ export class ZipWriter { * @param zip - Archive to copy from. * @param entry - Entry to copy, must belong to zip. */ - async addEntry(zip: ZipArchive, entry: yauzl.Entry) { + async addEntry(zip: ZipArchive, entry: ZipEntry) { const writerEntry: WriterEntry = { fileName: Buffer.from(entry.fileName, "utf8"), fileComment: Buffer.from(entry.fileComment, "utf8"), @@ -242,7 +271,7 @@ export class ZipWriter { offset: this.offset, }; await this.write(this.localFileHeader(writerEntry)); - const stream = await zip.zipfile.openReadStreamPromise(entry, { decodeFileData: false }); + const stream = await zip.openRawStream(entry); for await (const chunk of stream) { await this.write(chunk); } From c4a9545d282157f031d6918a23688f7b0a8ad302 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Fri, 20 Nov 2026 16:11:36 +0000 Subject: [PATCH 2/2] Explain why ZipEntry is a local type Co-Authored-By: Claude Opus 5.5 --- packages/lib/src/zip_ops.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/lib/src/zip_ops.ts b/packages/lib/src/zip_ops.ts index c8a12037..1d161c98 100644 --- a/packages/lib/src/zip_ops.ts +++ b/packages/lib/src/zip_ops.ts @@ -12,6 +12,9 @@ const deflateRaw = util.promisify(zlib.deflateRaw); /** * Entry in a ZipArchive + * + * Local subset of yauzl.Entry so the published declarations do not import + * yauzl, which would make @types/yauzl a runtime dependency of lib. */ export interface ZipEntry { fileName: string;