talkis/scripts/run-vite.mjs
David Perov 2f0bc345c5
Some checks are pending
CI / cargo check (linux) (push) Waiting to run
CI / cargo check (macos) (push) Waiting to run
CI / cargo check (windows) (push) Waiting to run
CI / tsc + hotkey smoke (push) Waiting to run
Release v0.3.6
2026-07-02 18:14:59 +03:00

56 lines
1.5 KiB
JavaScript

import { spawn } from "node:child_process";
import { existsSync, mkdirSync, copyFileSync, chmodSync } from "node:fs";
import { dirname, join } from "node:path";
import { tmpdir } from "node:os";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const rootDir = dirname(dirname(new URL(import.meta.url).pathname));
function resolvePackageFile(packageName, relativePath) {
return join(dirname(require.resolve(`${packageName}/package.json`)), relativePath);
}
function prepareEsbuildBinary() {
if (process.platform !== "darwin") return undefined;
const source = resolvePackageFile("esbuild", "bin/esbuild");
if (!existsSync(source)) return undefined;
const targetDir = join(tmpdir(), "talkis-esbuild");
const target = join(targetDir, `esbuild-${process.platform}-${process.arch}`);
mkdirSync(targetDir, { recursive: true });
copyFileSync(source, target);
chmodSync(target, 0o755);
return target;
}
function resolveViteBin() {
const binName = process.platform === "win32" ? "vite.cmd" : "vite";
return join(rootDir, "node_modules", ".bin", binName);
}
const env = { ...process.env };
const esbuildBinary = prepareEsbuildBinary();
if (esbuildBinary) {
env.ESBUILD_BINARY_PATH = esbuildBinary;
}
const child = spawn(resolveViteBin(), process.argv.slice(2), {
cwd: rootDir,
env,
stdio: "inherit",
shell: process.platform === "win32",
});
child.on("exit", (code, signal) => {
if (signal) {
process.kill(process.pid, signal);
return;
}
process.exit(code ?? 1);
});