Files
reverse-engineering-anything/scripts/run-turbo.mjs
T
Som SamantrayandYsopwnable cfaee2f5f7 feat(build): add non-turbo source-build path for freebsd (#15247)
* feat(build): add non-turbo source-build path for freebsd

* test(build): keep direct-build coverage runnable without turbo and reap build children

* test(build): use processTest fixture and long-running tag for build tests

---------

Co-authored-by: Ysopwnable <161784452+N0zoM1z0@users.noreply.github.com>
2026-12-03 12:46:27 +08:00

70 lines
2.4 KiB
JavaScript

#!/usr/bin/env node
import { readFileSync, realpathSync } from "node:fs";
import { createRequire } from "node:module";
import { resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { resolveTypeScriptCompiler } from "./run-typescript.mjs";
/** Use the pinned turbo package's platform inventory and launcher mapping. */
export const isTurboPlatformSupported = (
platform,
arch,
optionalDependencies,
) => {
if (typeof optionalDependencies !== "object" || optionalDependencies === null)
return false;
const turboPlatform =
platform === "win32"
? "windows"
: platform === "android"
? "linux"
: platform;
const turboArch = arch === "x64" ? "64" : arch;
return Object.hasOwn(
optionalDependencies,
`@turbo/${turboPlatform}-${turboArch}`,
);
};
const main = async () => {
const require = createRequire(import.meta.url);
if (!process.env.TURBO_BINARY_PATH) {
const turboPackage = JSON.parse(
readFileSync(require.resolve("turbo/package.json"), "utf8"),
);
if (
!isTurboPlatformSupported(
process.platform,
process.arch,
turboPackage.optionalDependencies,
)
) {
process.stderr.write(
`Turborepo (turbo@${turboPackage.version}) does not ship a binary for ${process.platform}/${process.arch}.\n` +
"Run `npm run build:direct` to build the runtime and packaged skill without Turborepo.\n" +
"For checks without Turborepo, run direct scripts such as `npm run metadata:check`, `npm run typecheck`, `npm run lint`, `npm run format:check`, `npm run verify:architecture-guards`, and `npm run test:local -- PATH...`, or set TURBO_BINARY_PATH to a local turbo binary.\n",
);
process.exitCode = 1;
return;
}
}
// Compute the actual host compiler before Turbo hashes or restores its tasks.
process.env.REA_TYPESCRIPT_COMPILER = resolveTypeScriptCompiler().identity;
await import(pathToFileURL(require.resolve("turbo/bin/turbo")).href);
};
const isDirectExecution = (argvPath, moduleUrl) => {
if (argvPath === undefined) return false;
try {
return (
realpathSync(resolve(argvPath)) === realpathSync(fileURLToPath(moduleUrl))
);
} catch {
return pathToFileURL(resolve(argvPath)).href === moduleUrl;
}
};
if (isDirectExecution(process.argv[1], import.meta.url)) await main();