From 7303cb3ce12ee6611d1bd77c6a1e69d2382378f2 Mon Sep 17 00:00:00 2001 From: VanshikaSabharwal Date: Wed, 15 Apr 2026 11:12:46 +0530 Subject: [PATCH 1/3] fixed the type --- src/utils.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index f4888b4..ca3e419 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,7 +6,7 @@ */ import { MetaCallJSON } from '@metacall/protocol/deployment'; -import archiver, { Archiver } from 'archiver'; +import archiver from 'archiver'; import { parse } from 'dotenv'; import { promises as fs } from 'fs'; import { prompt } from 'inquirer'; @@ -109,7 +109,7 @@ export const zip = async ( pulse?: (name: string) => void, hide?: () => void, ignorePatterns?: string[] -): Promise => { +): Promise => { // Apply ignore patterns files = filterFiles(files, ignorePatterns); const archive = archiver('zip', { @@ -137,13 +137,19 @@ export const zip = async ( : archive.file(file, { name: relative(source, file) }); } - if (hide) { - archive.on('finish', () => hide()); - } + // Collect chunks into a Blob. The archiver package extends readable-stream's + // Transform (not Node.js native stream.Readable), so passing the Archiver + // directly to protocol upload() would fail its instanceof Readable check. + const chunks: Buffer[] = []; + archive.on('data', (chunk: Buffer) => chunks.push(chunk)); await archive.finalize(); - return archive; + if (hide) hide(); + + return new Blob([Buffer.concat(chunks)], { + type: 'application/x-zip-compressed' + }); }; /** From a40f973ccd69e6bd5a382d3a65bde40f3d53aba0 Mon Sep 17 00:00:00 2001 From: VanshikaSabharwal Date: Fri, 17 Apr 2026 21:17:44 +0530 Subject: [PATCH 2/3] promisified and removed linting errors --- src/utils.ts | 78 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index ca3e419..00ab733 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -110,45 +110,69 @@ export const zip = async ( hide?: () => void, ignorePatterns?: string[] ): Promise => { - // Apply ignore patterns files = filterFiles(files, ignorePatterns); + const archive = archiver('zip', { zlib: { level: 9 } }); - if (progress) { - archive.on('progress', data => - progress( - 'Compressing and deploying...', - data.fs.processedBytes / data.fs.totalBytes - ) - ); - } + const chunks: Buffer[] = []; - if (pulse) { - archive.on('entry', (entry: archiver.EntryData) => pulse(entry.name)); - } + return new Promise((resolve, reject) => { + if (progress) { + archive.on('progress', data => { + progress( + 'Compressing and deploying...', + data.fs.processedBytes / data.fs.totalBytes + ); + }); + } + + if (pulse) { + archive.on('entry', (entry: archiver.EntryData) => { + pulse(entry.name); + }); + } - files = files.map(file => join(source, file)); + archive.on('data', (chunk: Buffer) => { + chunks.push(chunk); + }); - for (const file of files) { - (await fs.stat(file)).isDirectory() - ? archive.directory(file, basename(file)) - : archive.file(file, { name: relative(source, file) }); - } + archive.on('end', () => { + if (hide) { + archive.on('finish', () => hide()); + } - // Collect chunks into a Blob. The archiver package extends readable-stream's - // Transform (not Node.js native stream.Readable), so passing the Archiver - // directly to protocol upload() would fail its instanceof Readable check. - const chunks: Buffer[] = []; - archive.on('data', (chunk: Buffer) => chunks.push(chunk)); + resolve( + new Blob([Buffer.concat(chunks)], { + type: 'application/x-zip-compressed' + }) + ); + }); + + archive.on('error', reject); - await archive.finalize(); + void (async () => { + try { + const fullPaths = files.map(file => join(source, file)); - if (hide) hide(); + for (const file of fullPaths) { + const stat = await fs.stat(file); - return new Blob([Buffer.concat(chunks)], { - type: 'application/x-zip-compressed' + if (stat.isDirectory()) { + archive.directory(file, basename(file)); + } else { + archive.file(file, { + name: relative(source, file) + }); + } + } + + await archive.finalize(); + } catch (err) { + reject(err); + } + })(); }); }; From 0deb5af0815b4c4370d999f2ec67b820fa756ebd Mon Sep 17 00:00:00 2001 From: VanshikaSabharwal Date: Sat, 18 Apr 2026 11:12:07 +0530 Subject: [PATCH 3/3] promisified the data part only --- src/utils.ts | 71 ++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 00ab733..b169453 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,62 +118,51 @@ export const zip = async ( const chunks: Buffer[] = []; - return new Promise((resolve, reject) => { - if (progress) { - archive.on('progress', data => { - progress( - 'Compressing and deploying...', - data.fs.processedBytes / data.fs.totalBytes - ); - }); - } - - if (pulse) { - archive.on('entry', (entry: archiver.EntryData) => { - pulse(entry.name); - }); - } + if (progress) { + archive.on('progress', data => { + progress( + 'Compressing and deploying...', + data.fs.processedBytes / data.fs.totalBytes + ); + }); + } - archive.on('data', (chunk: Buffer) => { - chunks.push(chunk); + if (pulse) { + archive.on('entry', (entry: archiver.EntryData) => { + pulse(entry.name); }); + } + const dataPromise = new Promise((resolve, reject) => { + archive.on('data', (chunk: Buffer) => chunks.push(chunk)); archive.on('end', () => { if (hide) { archive.on('finish', () => hide()); } - resolve( new Blob([Buffer.concat(chunks)], { type: 'application/x-zip-compressed' }) ); }); - archive.on('error', reject); - - void (async () => { - try { - const fullPaths = files.map(file => join(source, file)); - - for (const file of fullPaths) { - const stat = await fs.stat(file); - - if (stat.isDirectory()) { - archive.directory(file, basename(file)); - } else { - archive.file(file, { - name: relative(source, file) - }); - } - } - - await archive.finalize(); - } catch (err) { - reject(err); - } - })(); }); + + const fullPaths = files.map(file => join(source, file)); + + for (const file of fullPaths) { + const stat = await fs.stat(file); + + if (stat.isDirectory()) { + archive.directory(file, basename(file)); + } else { + archive.file(file, { name: relative(source, file) }); + } + } + + await archive.finalize(); + + return dataPromise; }; /**