-
Notifications
You must be signed in to change notification settings - Fork 16
/
install_util.ts
35 lines (29 loc) 路 984 Bytes
/
install_util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { join, NAME } from "./deps.ts";
function homedir(os: typeof Deno.build.os): string {
if (os === "windows") {
return Deno.env.get("USERPROFILE")!;
}
return Deno.env.get("HOME")!;
}
export function wasmCacheDir(
os = Deno.build.os,
getHomeDir = homedir,
maybeDenoDir = Deno.env.get("DENO_DIR"),
): string {
return maybeDenoDir
? join(maybeDenoDir, NAME)
: join(getHomeDir(os), ".deno", NAME);
}
export function wasmPath(): string {
return join(wasmCacheDir(), "esbuild-0.12.8.wasm");
}
export async function installWasm() {
const wasmUrl =
`https://deno.land/x/esbuild_loader@v0.12.8/vendor/esbuild.wasm`;
console.log(`Downloading esbuild wasm from ${wasmUrl}`);
const res = await fetch(wasmUrl);
const bytes = new Uint8Array(await res.arrayBuffer());
const size = (bytes.byteLength / 1024 / 1024).toFixed(2);
await Deno.writeFile(wasmPath(), bytes);
console.log(`Saved esbuild wasm (${size}MB) at the path ${wasmPath()}`);
}