mirror of
https://github.com/nodejs/node.git
synced 2025-05-12 20:54:38 +00:00

Only query embedder options when they are needed so that the bootstrap remains as stateless as possible so that the bootstrap snapshot is controlled solely by configure options, and subsequent runtime changes should be done in pre-execution. PR-URL: https://github.com/nodejs/node/pull/40357 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com>
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
getCLIOptions,
|
|
getEmbedderOptions: getEmbedderOptionsFromBinding,
|
|
} = internalBinding('options');
|
|
|
|
let warnOnAllowUnauthorized = true;
|
|
|
|
let optionsMap;
|
|
let aliasesMap;
|
|
let embedderOptions;
|
|
|
|
// getCLIOptions() 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 (!optionsMap) {
|
|
({ options: optionsMap } = getCLIOptions());
|
|
}
|
|
return optionsMap;
|
|
}
|
|
|
|
function getAliasesFromBinding() {
|
|
if (!aliasesMap) {
|
|
({ aliases: aliasesMap } = getCLIOptions());
|
|
}
|
|
return aliasesMap;
|
|
}
|
|
|
|
function getEmbedderOptions() {
|
|
if (!embedderOptions) {
|
|
embedderOptions = getEmbedderOptionsFromBinding();
|
|
}
|
|
return embedderOptions;
|
|
}
|
|
|
|
function getOptionValue(optionName) {
|
|
const options = getCLIOptionsFromBinding();
|
|
if (optionName.startsWith('--no-')) {
|
|
const option = options.get('--' + optionName.slice(5));
|
|
return option && !option.value;
|
|
}
|
|
return options.get(optionName)?.value;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
module.exports = {
|
|
get options() {
|
|
return getCLIOptionsFromBinding();
|
|
},
|
|
get aliases() {
|
|
return getAliasesFromBinding();
|
|
},
|
|
getOptionValue,
|
|
getAllowUnauthorized,
|
|
getEmbedderOptions
|
|
};
|