diff --git a/alpine.ts b/alpine.ts index a42c4f6..fd2f55a 100644 --- a/alpine.ts +++ b/alpine.ts @@ -11,7 +11,7 @@ import { import { tmpdir } from "node:os"; import path from "node:path"; import { cwd } from "node:process"; -import { execFile } from "./helpers.js"; +import { execFile } from "./helpers/better-api"; export class Alpine { dir: string; diff --git a/helpers/better-api.ts b/helpers/better-api.ts new file mode 100644 index 0000000..cf8e656 --- /dev/null +++ b/helpers/better-api.ts @@ -0,0 +1,18 @@ +import { promisify } from "node:util"; +import { + execFile as execFileCallback, + spawn as spawnCallback, +} from "node:child_process"; +import { access } from "node:fs/promises"; + +export const execFile = promisify(execFileCallback); +export const spawn = promisify(spawnCallback); + +export async function canAccess(path: string): Promise { + try { + await access(path); + return true; + } catch { + return false; + } +} diff --git a/helpers.ts b/helpers/sudo.ts similarity index 51% rename from helpers.ts rename to helpers/sudo.ts index 3d4532d..bc383d2 100644 --- a/helpers.ts +++ b/helpers/sudo.ts @@ -1,22 +1,5 @@ -import { promisify } from "node:util"; -import { - execFile as execFileCallback, - spawn as spawnCallback, -} from "node:child_process"; -import { access } from "node:fs/promises"; import { getuid } from "node:process"; - -export const execFile = promisify(execFileCallback); -export const spawn = promisify(spawnCallback); - -export async function canAccess(path: string): Promise { - try { - await access(path); - return true; - } catch { - return false; - } -} +import { execFile } from "./better-api"; export async function sudoChown(path: string, owner: string): Promise { await execFile("sudo", ["chown", owner, path]); diff --git a/index.ts b/index.ts index 20f351e..638b813 100644 --- a/index.ts +++ b/index.ts @@ -3,7 +3,8 @@ import { tmpdir } from "node:os"; import path from "node:path"; import { cwd } from "node:process"; import { Alpine } from "./alpine.js"; -import { execFile, spawn, sudoChownToRunningUser } from "./helpers.js"; +import { execFile } from "./helpers/better-api.js"; +import { sudoChownToRunningUser } from "./helpers/sudo.js"; import { setupKernel } from "./kernel.js"; import { runQemu } from "./qemu.js"; import { Runit } from "./runit/index.js"; diff --git a/kernel.ts b/kernel.ts index 7ac0225..9b79b82 100644 --- a/kernel.ts +++ b/kernel.ts @@ -2,7 +2,8 @@ import { constants } from "node:fs"; import { copyFile } from "node:fs/promises"; import path from "node:path"; import { Alpine } from "./alpine.js"; -import { canAccess, sudoChownToRunningUser, sudoRm } from "./helpers.js"; +import { canAccess } from "./helpers/better-api.js"; +import { sudoChownToRunningUser, sudoRm } from "./helpers/sudo.js"; export type Kind = "lts" | "virt"; export type Kernel = { diff --git a/qemu.ts b/qemu.ts index b49a1fb..857def3 100644 --- a/qemu.ts +++ b/qemu.ts @@ -1,7 +1,7 @@ import { mkdtemp, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; -import { execFile } from "./helpers.js"; +import { execFile } from "./helpers/better-api.js"; import { Kernel } from "./kernel.js"; export async function runQemu(