node v2 cli support (#36309)

This commit is contained in:
Simon Klee 2026-07-17 14:45:06 +02:00 committed by GitHub
commit a1b274e6f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
75 changed files with 1502 additions and 367 deletions

View file

@ -0,0 +1,5 @@
import { text } from "node:stream/consumers"
export function readStdin() {
return text(process.stdin)
}

View file

@ -0,0 +1,26 @@
import path from "node:path"
export function selfCommand() {
const runtime = path.basename(process.execPath, path.extname(process.execPath)).toLowerCase()
if (runtime !== "bun" && runtime !== "node" && runtime !== "nodejs") return [process.execPath]
if (!process.argv[1]) throw new Error("Failed to resolve CLI entrypoint")
if (runtime === "node" || runtime === "nodejs") return [process.execPath, ...nodeFlags(), process.argv[1]]
return [process.execPath, process.argv[1]]
}
function nodeFlags() {
return process.execArgv.flatMap((arg, index, args) => {
if (index > 0 && args[index - 1] === "--conditions") return []
if (arg === "--conditions") return args[index + 1] ? [arg, args[index + 1]] : []
if (arg.startsWith("--conditions=")) return [arg]
if (
arg === "--experimental-ffi" ||
arg === "--use-system-ca" ||
arg === "--enable-source-maps" ||
arg === "--no-addons"
)
return [arg]
if (arg === "--no-warnings" || arg.startsWith("--disable-warning=")) return [arg]
return []
})
}