• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const { getOptions, shouldNotRegisterESMLoader } = internalBinding('options');
4
5let warnOnAllowUnauthorized = true;
6
7let optionsMap;
8let aliasesMap;
9
10// getOptions() would serialize the option values from C++ land.
11// It would error if the values are queried before bootstrap is
12// complete so that we don't accidentally include runtime-dependent
13// states into a runtime-independent snapshot.
14function getOptionsFromBinding() {
15  if (!optionsMap) {
16    ({ options: optionsMap } = getOptions());
17  }
18  return optionsMap;
19}
20
21function getAliasesFromBinding() {
22  if (!aliasesMap) {
23    ({ aliases: aliasesMap } = getOptions());
24  }
25  return aliasesMap;
26}
27
28function getOptionValue(optionName) {
29  const options = getOptionsFromBinding();
30  if (optionName.startsWith('--no-')) {
31    const option = options.get('--' + optionName.slice(5));
32    return option && !option.value;
33  }
34  return options.get(optionName)?.value;
35}
36
37function getAllowUnauthorized() {
38  const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0';
39
40  if (allowUnauthorized && warnOnAllowUnauthorized) {
41    warnOnAllowUnauthorized = false;
42    process.emitWarning(
43      'Setting the NODE_TLS_REJECT_UNAUTHORIZED ' +
44      'environment variable to \'0\' makes TLS connections ' +
45      'and HTTPS requests insecure by disabling ' +
46      'certificate verification.');
47  }
48  return allowUnauthorized;
49}
50
51module.exports = {
52  get options() {
53    return getOptionsFromBinding();
54  },
55  get aliases() {
56    return getAliasesFromBinding();
57  },
58  getOptionValue,
59  getAllowUnauthorized,
60  shouldNotRegisterESMLoader
61};
62