From 09906cde63d6c183dbbed1a10c06b0c2dfb36714 Mon Sep 17 00:00:00 2001 From: Yohe-Am <56622350+Yohe-Am@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:40:33 +0000 Subject: [PATCH] refactor(ports): move from zipjs to jszip --- deno.lock | 16 ++++++++++++++++ deps/ports.ts | 2 +- ghjk.ts | 4 ++-- utils/unarchive.ts | 45 ++++++++++++++++++--------------------------- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/deno.lock b/deno.lock index 51b5ae15..e2903f15 100644 --- a/deno.lock +++ b/deno.lock @@ -19,6 +19,18 @@ "https://raw.github.com/metatypedev/ghjk/v0.1.0-alpha/ports/whiz.ts": "https://raw.githubusercontent.com/metatypedev/ghjk/v0.1.0-alpha/ports/whiz.ts" }, "remote": { + "https://deno.land/std@0.116.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58", + "https://deno.land/std@0.116.0/_util/os.ts": "dfb186cc4e968c770ab6cc3288bd65f4871be03b93beecae57d657232ecffcac", + "https://deno.land/std@0.116.0/fs/walk.ts": "31464d75099aa3fc7764212576a8772dfabb2692783e6eabb910f874a26eac54", + "https://deno.land/std@0.116.0/path/_constants.ts": "1247fee4a79b70c89f23499691ef169b41b6ccf01887a0abd131009c5581b853", + "https://deno.land/std@0.116.0/path/_interface.ts": "1fa73b02aaa24867e481a48492b44f2598cd9dfa513c7b34001437007d3642e4", + "https://deno.land/std@0.116.0/path/_util.ts": "2e06a3b9e79beaf62687196bd4b60a4c391d862cfa007a20fc3a39f778ba073b", + "https://deno.land/std@0.116.0/path/common.ts": "f41a38a0719a1e85aa11c6ba3bea5e37c15dd009d705bd8873f94c833568cbc4", + "https://deno.land/std@0.116.0/path/glob.ts": "ea87985765b977cc284b92771003b2070c440e0807c90e1eb0ff3e095911a820", + "https://deno.land/std@0.116.0/path/mod.ts": "4465dc494f271b02569edbb4a18d727063b5dbd6ed84283ff906260970a15d12", + "https://deno.land/std@0.116.0/path/posix.ts": "34349174b9cd121625a2810837a82dd8b986bbaaad5ade690d1de75bbb4555b2", + "https://deno.land/std@0.116.0/path/separator.ts": "8fdcf289b1b76fd726a508f57d3370ca029ae6976fcde5044007f062e643ff1c", + "https://deno.land/std@0.116.0/path/win32.ts": "11549e8c6df8307a8efcfa47ad7b2a75da743eac7d4c89c9723a944661c8bd2e", "https://deno.land/std@0.129.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74", "https://deno.land/std@0.129.0/_util/os.ts": "49b92edea1e82ba295ec946de8ffd956ed123e2948d9bd1d3e901b04e4307617", "https://deno.land/std@0.129.0/archive/tar.ts": "35ea1baddec7988cc4034765a2cee7613bc8074bd40940d3f5e98f63070a716a", @@ -635,6 +647,8 @@ "https://deno.land/x/http_client@v0.0.3/src/helpers.ts": "c91aec2f0158e0f6284a98947065b08de21818dcdaa4cac78daacfad5d332146", "https://deno.land/x/http_client@v0.0.3/src/request.ts": "39ef37dbd2ea8115c284e269259feb4c839367410687a2371580206d6b2a7210", "https://deno.land/x/http_client@v0.0.3/src/response.ts": "1f47769856e63fb22048ca9ce0c7282ed75905a5209b20619fb79b47d8ee030b", + "https://deno.land/x/jszip@0.11.0/mod.ts": "5661ddc18e9ac9c07e3c5d2483bc912a7022b6af0d784bb7b05035973e640ba1", + "https://deno.land/x/jszip@0.11.0/types.ts": "1528d1279fbb64dd118c371331c641a3a5eff2b594336fb38a7659cf4c53b2d1", "https://deno.land/x/monads@v0.5.10/either/either.ts": "89f539c7d50bd0ee8d9b902f37ef16687c19b62cc9dd23454029c97fbfc15cc6", "https://deno.land/x/monads@v0.5.10/index.ts": "f0e90b8c1dd767efca137d682ac1a19b2dbae4d1990b8a79a40b4e054c69b3d6", "https://deno.land/x/monads@v0.5.10/mod.ts": "f1b16a34d47e58fdf9f1f54c49d2fe6df67b3d2e077e21638f25fbe080eee6cf", @@ -691,9 +705,11 @@ "https://deno.land/x/zod@v3.22.4/types.ts": "724185522fafe43ee56a52333958764c8c8cd6ad4effa27b42651df873fc151e", "https://esm.sh/extract-files@12.0.0/extractFiles.mjs": "58e5f1fcf50e3a362d9bde0e2c1a624a7d89d60ac2de005afd895d0d452cca62", "https://esm.sh/extract-files@12.0.0/isExtractableFile.mjs": "2757358bbc9141b93cb27d7e0ba98c1e703172dd58fb7d533a31476419d2416f", + "https://esm.sh/jszip@3.7.1": "f3872a819b015715edb05f81d973b5cd05d3d213d8eb28293ca5471fe7a71773", "https://esm.sh/v135/extract-files@12.0.0/denonext/extractFiles.js": "59b30d503c5d9ce135dd76c34ac92cf7e9f85cd129d6be2ff61553bb612ac75f", "https://esm.sh/v135/extract-files@12.0.0/denonext/isExtractableFile.js": "93462c162e29fc0e8fd7e9de3665dfd7705f03d41d2721d654f177bc2a7fe305", "https://esm.sh/v135/is-plain-obj@4.1.0/denonext/is-plain-obj.mjs": "d3d86a7174ad7935de7b00f904b6424c103bce530c502efb7f42114cbb1a555f", + "https://esm.sh/v135/jszip@3.7.1/denonext/jszip.mjs": "d31d7f9e0de9c6db3c07ca93f7301b756273d4dccb41b600461978fc313504c9", "https://raw.githubusercontent.com/metatypedev/ghjk/v0.1.0-alpha/deps/cli.ts": "6b3e3892e3373982aed490c3e70bb6f2780ad7fd59d14af38f61a9741ca48313", "https://raw.githubusercontent.com/metatypedev/ghjk/v0.1.0-alpha/deps/common.ts": "b0cf740a4dd06b5a75e1135652a51325ffd203c5b741e6586f78417ab0c971c1", "https://raw.githubusercontent.com/metatypedev/ghjk/v0.1.0-alpha/deps/ports.ts": "4f7588d0a8cc43ea7d8e699ccddabf55b7e5a5f412e9c9aed934927334990825", diff --git a/deps/ports.ts b/deps/ports.ts index 33d62761..f5eeeada 100644 --- a/deps/ports.ts +++ b/deps/ports.ts @@ -1,8 +1,8 @@ //! This contains dependencies used by plugins export * from "./common.ts"; -export * as zipjs from "https://deno.land/x/zipjs@v2.7.31/index.js"; export { Foras } from "https://deno.land/x/foras@v2.1.4/src/deno/mod.ts"; export * as std_tar from "https://deno.land/std@0.129.0/archive/tar.ts"; export * as std_streams from "https://deno.land/std@0.129.0/streams/mod.ts"; export * as std_io from "https://deno.land/std@0.129.0/io/mod.ts"; +export * as jszip from "https://deno.land/x/jszip@0.11.0/mod.ts"; diff --git a/ghjk.ts b/ghjk.ts index 2fc80651..68d95a04 100644 --- a/ghjk.ts +++ b/ghjk.ts @@ -24,12 +24,12 @@ import whiz from "./ports/whiz.ts"; // cargo_insta({}); // jco({}); // mold({}); -act({}); +// act({}); // asdf({ // pluginRepo: "https://github.com/asdf-community/asdf-cmake", // installType: "version", // }); -// protoc({ }); +protoc({}); // earthly({}); // ruff({}); // whiz({}); diff --git a/utils/unarchive.ts b/utils/unarchive.ts index 6172fcc5..8ed692ab 100644 --- a/utils/unarchive.ts +++ b/utils/unarchive.ts @@ -1,11 +1,11 @@ import { Foras, + jszip, std_fs, std_io, std_path, std_streams, std_tar, - zipjs, } from "../deps/ports.ts"; /// Uses file extension to determine type @@ -98,30 +98,21 @@ export async function unzip( path: string, dest = "./", ) { - const zipFile = await Deno.open(path, { read: true }); - const zipReader = new zipjs.ZipReader(zipFile.readable); - try { - await Promise.allSettled( - (await zipReader.getEntries()).map(async (entry) => { - const filePath = std_path.resolve(dest, entry.filename); - if (entry.directory) { - await std_fs.ensureDir(filePath); - return; - } - await std_fs.ensureDir(std_path.dirname(filePath)); - const file = await Deno.open(filePath, { - create: true, - truncate: true, - write: true, - mode: entry.externalFileAttribute >> 16, - }); - if (!entry.getData) throw Error("impossible"); - await entry.getData(file.writable); - }), - ); - } catch (err) { - throw err; - } finally { - zipReader.close(); - } + const zipArc = await jszip.readZip(path); + await Promise.allSettled( + Object.entries(zipArc.files()).map(async ([_, entry]) => { + const filePath = std_path.resolve(dest, entry.name); + if (entry.dir) { + await std_fs.ensureDir(filePath); + return; + } + await std_fs.ensureDir(std_path.dirname(filePath)); + const buf = await entry.async("uint8array"); + await Deno.writeFile(filePath, buf, { + create: true, + // FIXME: windows support + mode: Number(entry.unixPermissions ?? 0o666), + }); + }), + ); }