diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 5dcf188..21b8796 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -1,5 +1,7 @@ +import { spawn, execFile } from "node:child_process"; import { existsSync, mkdirSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; +import { promisify } from "node:util"; import { defineCommand } from "citty"; @@ -42,6 +44,8 @@ const GITIGNORE = `data/ node_modules/ `; +const execFileAsync = promisify(execFile); + const CPU_SCHEMA_TS = `import { integer, real, sqliteTable, text } from "drizzle-orm/sqlite-core"; export const cpuUsage = sqliteTable("cpu_usage", { @@ -90,7 +94,6 @@ function writeFile(filePath: string, content: string): void { } async function runCommand(cmd: string, args: string[], cwd: string): Promise { - const { spawn } = await import("node:child_process"); await new Promise((resolve, reject) => { const child = spawn(cmd, args, { cwd, stdio: "inherit" }); child.on("close", (code) => { @@ -102,10 +105,6 @@ async function runCommand(cmd: string, args: string[], cwd: string): Promise { - const { execFile } = await import("node:child_process"); - const { promisify } = await import("node:util"); - const execFileAsync = promisify(execFile); - for (const pm of ["pnpm", "yarn", "npm"]) { try { await execFileAsync(pm, ["--version"]); @@ -223,9 +222,6 @@ async function tryRequireSqlite(nerveRoot: string): Promise { try { const modulePath = join(nerveRoot, "node_modules", "better-sqlite3"); // Use a child process to test if the native module loads - const { execFile } = await import("node:child_process"); - const { promisify } = await import("node:util"); - const execFileAsync = promisify(execFile); await execFileAsync("node", ["-e", `require(${JSON.stringify(modulePath)})`], { cwd: nerveRoot, timeout: 10_000, diff --git a/packages/cli/src/commands/start.ts b/packages/cli/src/commands/start.ts index ff23b57..f668d2f 100644 --- a/packages/cli/src/commands/start.ts +++ b/packages/cli/src/commands/start.ts @@ -1,3 +1,4 @@ +import { spawn } from "node:child_process"; import { createWriteStream, existsSync } from "node:fs"; import { mkdir } from "node:fs/promises"; import { dirname, join } from "node:path"; @@ -8,6 +9,7 @@ import { defineCommand } from "citty"; import { getLogPath, getNerveRoot, + getSocketPath, isRunning, readPidFile, removePidFile, @@ -64,7 +66,6 @@ async function runDaemon(nerveRoot: string): Promise { const logPath = getLogPath(); await mkdir(join(nerveRoot, "logs"), { recursive: true }); - const { spawn } = await import("node:child_process"); const logStream = createWriteStream(logPath, { flags: "a" }); await new Promise((resolve) => { if (logStream.pending) logStream.once("open", () => resolve()); @@ -90,7 +91,6 @@ async function runDaemon(nerveRoot: string): Promise { writePidFile(pid); - const { getSocketPath } = await import("../workspace.js"); const ready = await waitForSocket(getSocketPath(), 5000); if (!ready || !isRunning()) {