Files
hyperframes/packages/cli/bin/hyperframes.mjs
T

29 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
import { runtimeVersionError, runtimeVersionJson } from "../dist/runtimeVersion.js";
// The plugin launcher starts npx outside the project so npm cannot pick the CLI from it,
// and names the project here. Nested CLI runs keep the working folder their caller gives them.
const projectDir = process.env.HYPERFRAMES_PLUGIN_CWD;
delete process.env.HYPERFRAMES_PLUGIN_CWD;
if (projectDir) {
process.chdir(projectDir);
// npm's shell resets PWD to the folder npx started in; commands read the project name from it.
process.env.PWD = projectDir;
}
const error = runtimeVersionError(process.versions.node);
if (error) {
console.error(error);
const json = runtimeVersionJson(error, process.argv.slice(2));
if (json) console.log(json);
process.exitCode = 1;
} else {
// Reuses V8 bytecode across runs, from HyperFrames' private cache folder only; Node 22.0 has no such API.
(await import("../dist/compileCache.js")).enablePrivateCompileCache();
if (process.env.HYPERFRAMES_HANG_REPORT) (await import("../dist/hangReport.js")).watchForHang();
const warm = process.argv[2] === "check" ? await import("../dist/warmCheckClient.js") : undefined;
if (warm?.warmCheckEligible()) process.once("exit", () => warm.startNextWarmCheck());
if (!(warm?.warmCheckEligible() && (await warm.runWarmCheck()))) await import("../dist/cli.js");
}