Skip to content

Commit

Permalink
fix: use zipjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Nov 30, 2023
1 parent 08b4c36 commit f21dafb
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 14 deletions.
29 changes: 29 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deps/plug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

export * from "./common.ts";
export * as compress from "https://deno.land/x/[email protected]/mod.ts";
export * as zip from "https://deno.land/x/[email protected]/mod.ts";
export * as zipjs from "https://deno.land/x/[email protected]/index.js";
2 changes: 1 addition & 1 deletion ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ import whiz from "./plugs/whiz.ts";
// protoc({});
// earthly({});
// ruff({});
// whiz({});
whiz({});
49 changes: 42 additions & 7 deletions plug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ import {
addInstall,
type AmbientAccessPlugManifest,
type DenoWorkerPlugManifest,
type DepShims,
type DownloadArgs,
type GhjkConfig,
type InstallConfig,
type PlugBase,
type PlugDep,
registerAmbientPlug,
registerDenoPlug,
registerPlug,
validators,
} from "./core/mod.ts";
import { compress, log, std_fs, std_path, std_url, zip } from "./deps/plug.ts";
import {
compress,
log,
std_fs,
std_path,
std_url,
zipjs,
} from "./deps/plug.ts";
import { initDenoWorkerPlug, isWorker } from "./core/worker.ts";
import * as asdf from "./core/asdf.ts";
import logger from "./core/logger.ts";
Expand Down Expand Up @@ -171,14 +176,44 @@ export async function unarchive(
case ".gz":
case ".tar.gz":
case ".tgz":
await compress.tgz.uncompress(path, dest);
await compress.tgz.uncompress(path, dest, {
debug: true,
});
break;
case ".tar":
await compress.tar.uncompress(path, dest);
await compress.tar.uncompress(path, dest, {
debug: true,
});
break;
case ".zip":
await zip.decompress(path, dest);
case ".zip": {
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) => {
if (entry.directory) {
await std_fs.ensureDir(std_path.resolve(dest, entry.filename));
return;
}
const filePath = std_path.resolve(dest, entry.filename);
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();
}
break;
}
default:
throw Error("unsupported archive extension: ${ext}");
}
Expand Down
7 changes: 4 additions & 3 deletions plugs/mold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Plug extends PlugBase {
);
const fileDwnPath = std_path.resolve(args.downloadPath, fileName);

await unarchive(fileDwnPath args.tmpDirPath)
await unarchive(fileDwnPath, args.tmpDirPath);

if (await std_fs.exists(args.installPath)) {
await removeFile(args.installPath, { recursive: true });
Expand Down Expand Up @@ -108,8 +108,9 @@ function downloadUrl(installVersion: string, platform: PlatformInfo) {
default:
throw new Error(`unsupported arch: ${platform.arch}`);
}
return `${repoAddress}/releases/download/${installVersion}/${repoName}-${installVersion.startsWith("v") ? installVersion.slice(1) : installVersion
}-${arch}-${os}.tar.gz`;
return `${repoAddress}/releases/download/${installVersion}/${repoName}-${
installVersion.startsWith("v") ? installVersion.slice(1) : installVersion
}-${arch}-${os}.tar.gz`;
} else {
throw new Error(`unsupported os: ${platform.os}`);
}
Expand Down
3 changes: 1 addition & 2 deletions plugs/ruff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
addInstallGlobal,
depBinShimPath,
DownloadArgs,
downloadFile,
InstallArgs,
Expand All @@ -9,7 +8,6 @@ import {
PlugBase,
registerDenoPlugGlobal,
removeFile,
spawn,
std_fs,
std_path,
std_url,
Expand Down Expand Up @@ -81,6 +79,7 @@ export class Plug extends PlugBase {
args.tmpDirPath,
std_path.resolve(args.installPath, "bin"),
);
// await Deno.chmod(std_path.resolve(args.installPath, "bin", "ruff"), 0o700);
}
}

Expand Down

0 comments on commit f21dafb

Please sign in to comment.