diff --git a/bun.lockb b/bun.lockb index 9fd11384..6bb20f81 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index e67b0178..a2a4dcb9 100644 --- a/package.json +++ b/package.json @@ -53,12 +53,14 @@ "@std/semver": "npm:@jsr/std__semver", "@supabase/supabase-js": "^2.45.2", "@tomasklaen/checksum": "^1.1.0", + "@types/adm-zip": "^0.5.5", "@types/node": "^22.5.0", "@types/prettyjson": "^0.0.33", "@types/tmp": "^0.2.6", "@typescript-eslint/eslint-plugin": "^8.3.0", "@typescript-eslint/parser": "^8.3.0", "@vercel/ncc": "^0.38.1", + "adm-zip": "^0.5.16", "ci-info": "^4.0.0", "commander": "12.1.0", "esbuild": "^0.24.0", @@ -66,7 +68,6 @@ "git-format-staged": "3.1.1", "husky": "^9.1.5", "is-wsl": "^3.1.0", - "jszip": "^3.10.1", "ky": "^1.7.2", "latest-version": "^9.0.0", "open": "^10.1.0", diff --git a/src/utils.ts b/src/utils.ts index dd6679f9..4ec84f21 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,7 +4,7 @@ import type { Buffer } from 'node:buffer' import type { ExtConfigPairs } from './config' import type { Database } from './types/supabase.types' import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs' -import { homedir } from 'node:os' +import { homedir, platform as osPlatform } from 'node:os' import { dirname, join, relative, resolve, sep } from 'node:path' import { cwd, exit } from 'node:process' import { findMonorepoRoot, findNXMonorepoRoot, isMonorepo, isNXMonorepo } from '@capacitor/cli/dist/util/monorepotools' @@ -12,8 +12,8 @@ import { findInstallCommand, findPackageManagerRunner, findPackageManagerType } import { confirm as confirmC, isCancel, log, select, spinner as spinnerC } from '@clack/prompts' import { createClient, FunctionsHttpError } from '@supabase/supabase-js' import { checksum as getChecksum } from '@tomasklaen/checksum' +import AdmZip from 'adm-zip' import { program } from 'commander' -import JSZip from 'jszip' import ky from 'ky' import prettyjson from 'prettyjson' import * as tus from 'tus-js-client' @@ -695,11 +695,25 @@ export interface uploadUrlsType { } export async function zipFile(filePath: string): Promise { - log.info('Zipping file') - const zip = new JSZip() + if (osPlatform() === 'win32') { + return zipFileWindows(filePath) + } + else { + return zipFileUnix(filePath) + } +} + +export function zipFileUnix(filePath: string) { + const zip = new AdmZip() + zip.addLocalFolder(filePath) + return zip.toBuffer() +} + +export async function zipFileWindows(filePath: string): Promise { + log.info('Zipping file windows mode') + const zip = new AdmZip() - // Helper function to recursively add files and folders to the ZIP archive - const addToZip = async (folderPath: string, zipPath: string) => { + const addToZip = (folderPath: string, zipPath: string) => { const items = readdirSync(folderPath) for (const item of items) { @@ -707,21 +721,18 @@ export async function zipFile(filePath: string): Promise { const stats = statSync(itemPath) if (stats.isFile()) { - const fileContent = await readFileSync(itemPath) - zip.file(join(zipPath, item).split(sep).join('/'), fileContent) + const fileContent = readFileSync(itemPath) + zip.addFile(join(zipPath, item).split(sep).join('/'), fileContent) } else if (stats.isDirectory()) { - await addToZip(itemPath, join(zipPath, item)) + addToZip(itemPath, join(zipPath, item)) } } } - // Start adding files and folders to the ZIP archive - await addToZip(filePath, '') + addToZip(filePath, '') - // Generate the ZIP file as a Buffer - const zipBuffer = await zip.generateAsync({ type: 'nodebuffer', platform: 'UNIX', compression: 'DEFLATE', compressionOptions: { level: 6 } }) - return zipBuffer + return zip.toBuffer() } export async function uploadTUS(apikey: string, data: Buffer, orgId: string, appId: string, name: string, spinner: ReturnType, localConfig: CapgoConfig): Promise {