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