nstdlib-nightly
Version:
Node.js standard library converted to runtime-agnostic ES modules.
69 lines (57 loc) • 1.81 kB
JavaScript
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/internal/options.js
import {
getCLIOptionsValues,
getCLIOptionsInfo,
getEmbedderOptions as getEmbedderOptionsFromBinding,
} from "nstdlib/stub/binding/options";
let warnOnAllowUnauthorized = true;
let optionsDict;
let cliInfo;
let embedderOptions;
// getCLIOptionsValues() would serialize the option values from C++ land.
// It would error if the values are queried before bootstrap is
// complete so that we don't accidentally include runtime-dependent
// states into a runtime-independent snapshot.
function getCLIOptionsFromBinding() {
if (!optionsDict) {
optionsDict = getCLIOptionsValues();
}
return optionsDict;
}
function getCLIOptionsInfoFromBinding() {
if (!cliInfo) {
cliInfo = getCLIOptionsInfo();
}
return cliInfo;
}
function getEmbedderOptions() {
if (!embedderOptions) {
embedderOptions = getEmbedderOptionsFromBinding();
}
return embedderOptions;
}
function refreshOptions() {
optionsDict = undefined;
}
function getOptionValue(optionName) {
const optionsDict = getCLIOptionsFromBinding();
return optionsDict[optionName];
}
function getAllowUnauthorized() {
const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === "0";
if (allowUnauthorized && warnOnAllowUnauthorized) {
warnOnAllowUnauthorized = false;
process.emitWarning(
"Setting the NODE_TLS_REJECT_UNAUTHORIZED " +
"environment variable to '0' makes TLS connections " +
"and HTTPS requests insecure by disabling " +
"certificate verification.",
);
}
return allowUnauthorized;
}
export { getCLIOptionsInfoFromBinding as getCLIOptionsInfo };
export { getOptionValue };
export { getAllowUnauthorized };
export { getEmbedderOptions };
export { refreshOptions };