mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-25 06:24:27 +08:00
40 lines
1.9 KiB
JavaScript
40 lines
1.9 KiB
JavaScript
// The shape esbuild's ESM output gives every npm-published bundle (the
|
|
// vercel CLI's dist chunks verbatim): a banner that mints a CommonJS
|
|
// require with createRequire(import.meta.url), and a __require helper that
|
|
// routes the bundle's external requires through it. The build-time module
|
|
// walk collects `require("lit")` / import edges — a call spelled
|
|
// `__require("lit")` is INVISIBLE to it, so these loads must resolve at
|
|
// runtime the way Node resolves them: core modules unconditionally, never
|
|
// through the (absent) file-edge table. Every line printed here must match
|
|
// real Node byte-for-byte.
|
|
import { createRequire as __createRequire } from 'node:module';
|
|
const require = __createRequire(import.meta.url);
|
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : x)(function (x) {
|
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
});
|
|
|
|
// Module-init loads, exactly where the vercel help path runs them
|
|
// (bundled supports-color does __require("os") and __require("tty") at
|
|
// its wrapper's first evaluation).
|
|
const os = __require("os");
|
|
const tty = __require("tty");
|
|
|
|
// Present but never called: under Node this would load core http2; the
|
|
// island has no http2 shim and would throw HERE, at the call — lazily,
|
|
// like Node surfaces a missing module — so its mere presence must not
|
|
// break the build or the run.
|
|
export function neverCalled() {
|
|
return __require("http2");
|
|
}
|
|
|
|
export function probe() {
|
|
const lines = [];
|
|
lines.push(`platform=${os.platform()}`);
|
|
// The harness pipes both lanes' stdio, so every answer is false — but
|
|
// through the REAL isatty(3), not a constant.
|
|
lines.push(`tty=${tty.isatty(0)} ${tty.isatty(1)} ${tty.isatty(2)}`);
|
|
// Node returns false for any non-(non-negative-integer) fd, no throw.
|
|
lines.push(`ttybad=${tty.isatty(-1)} ${tty.isatty(1.5)} ${tty.isatty("x")} ${tty.isatty(undefined)}`);
|
|
return lines.join("\n");
|
|
}
|