diff --git a/_main.mjs b/_main.mjs index 344f57c..8db9e28 100644 --- a/_main.mjs +++ b/_main.mjs @@ -1,11 +1,29 @@ import { spawn } from "node:child_process"; -import { dirname, join } from "node:path"; import { once } from "node:events"; +import { join, dirname } from "node:path"; +import { existsSync } from "node:fs"; const file = join(dirname(process.argv[1]), "main.ts"); // 👈 CHANGE ME! -const subprocess = spawn(`exec "$__FILE"`, { - shell: "bash", - stdio: "inherit", - env: { ...process.env, __FILE: file }, -}); -await once(subprocess, "spawn"); -subprocess.on("exit", (x) => process.exit(x)); +const response = await fetch("https://deno.com/versions.json"); +const json = await response.json(); +const tag = json.cli.find((x) => x.startsWith("v1.")); +const version = tag.slice(1); +const DENO_INSTALL = join( + process.env.RUNNER_TOOL_CACHE, + "deno", + version, + process.arch, +); +if (!existsSync(DENO_INSTALL)) { + const subprocess1 = spawn( + `curl -fsSL https://deno.land/x/install/install.sh | sh -s "$tag"`, + { shell: "bash", env: { ...process.env, DENO_INSTALL, tag } }, + ); + await once(subprocess1, "exit"); +} +const subprocess2 = spawn( + join(DENO_INSTALL, "bin", "deno"), + ["run", "-Aq", file], + { stdio: "inherit" }, +); +await once(subprocess2, "spawn"); +subprocess2.on("exit", (x) => process.exit(x));