2018-11-04 20:52:50 +00:00
|
|
|
'use strict';
|
|
|
|
|
2021-08-13 02:03:25 +00:00
|
|
|
const {
|
2021-10-07 04:03:10 +00:00
|
|
|
getCLIOptions,
|
|
|
|
getEmbedderOptions: getEmbedderOptionsFromBinding,
|
2021-08-13 02:03:25 +00:00
|
|
|
} = internalBinding('options');
|
2018-11-04 20:52:50 +00:00
|
|
|
|
2020-04-18 18:25:04 +00:00
|
|
|
let warnOnAllowUnauthorized = true;
|
|
|
|
|
2021-06-10 15:23:31 +00:00
|
|
|
let optionsMap;
|
|
|
|
let aliasesMap;
|
2021-10-07 04:03:10 +00:00
|
|
|
let embedderOptions;
|
2021-06-10 15:23:31 +00:00
|
|
|
|
2021-10-07 04:03:10 +00:00
|
|
|
// getCLIOptions() would serialize the option values from C++ land.
|
2021-06-10 15:23:31 +00:00
|
|
|
// 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.
|
2021-10-07 04:03:10 +00:00
|
|
|
function getCLIOptionsFromBinding() {
|
2021-06-10 15:23:31 +00:00
|
|
|
if (!optionsMap) {
|
2021-10-07 04:03:10 +00:00
|
|
|
({ options: optionsMap } = getCLIOptions());
|
2021-06-10 15:23:31 +00:00
|
|
|
}
|
|
|
|
return optionsMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAliasesFromBinding() {
|
|
|
|
if (!aliasesMap) {
|
2021-10-07 04:03:10 +00:00
|
|
|
({ aliases: aliasesMap } = getCLIOptions());
|
2021-06-10 15:23:31 +00:00
|
|
|
}
|
|
|
|
return aliasesMap;
|
|
|
|
}
|
|
|
|
|
2021-10-07 04:03:10 +00:00
|
|
|
function getEmbedderOptions() {
|
|
|
|
if (!embedderOptions) {
|
|
|
|
embedderOptions = getEmbedderOptionsFromBinding();
|
|
|
|
}
|
|
|
|
return embedderOptions;
|
|
|
|
}
|
|
|
|
|
2021-06-11 03:28:27 +00:00
|
|
|
function refreshOptions() {
|
|
|
|
optionsMap = undefined;
|
|
|
|
aliasesMap = undefined;
|
|
|
|
}
|
|
|
|
|
2021-06-13 10:46:35 +00:00
|
|
|
function getOptionValue(optionName) {
|
2021-10-07 04:03:10 +00:00
|
|
|
const options = getCLIOptionsFromBinding();
|
2021-06-13 10:46:35 +00:00
|
|
|
if (optionName.startsWith('--no-')) {
|
|
|
|
const option = options.get('--' + optionName.slice(5));
|
|
|
|
return option && !option.value;
|
|
|
|
}
|
|
|
|
return options.get(optionName)?.value;
|
2018-11-04 20:52:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-18 18:25:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-04 20:52:50 +00:00
|
|
|
module.exports = {
|
2021-06-10 15:23:31 +00:00
|
|
|
get options() {
|
2021-10-07 04:03:10 +00:00
|
|
|
return getCLIOptionsFromBinding();
|
2021-06-10 15:23:31 +00:00
|
|
|
},
|
|
|
|
get aliases() {
|
|
|
|
return getAliasesFromBinding();
|
|
|
|
},
|
2020-04-18 18:25:04 +00:00
|
|
|
getOptionValue,
|
|
|
|
getAllowUnauthorized,
|
2021-06-11 03:28:27 +00:00
|
|
|
getEmbedderOptions,
|
|
|
|
refreshOptions
|
2018-11-04 20:52:50 +00:00
|
|
|
};
|