-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathoptions.js
More file actions
178 lines (150 loc) Β· 5.06 KB
/
options.js
File metadata and controls
178 lines (150 loc) Β· 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
'use strict';
const {
ArrayPrototypeMap,
ArrayPrototypeSort,
ObjectEntries,
ObjectFromEntries,
ObjectKeys,
StringPrototypeReplace,
} = primordials;
const {
getCLIOptionsValues,
getCLIOptionsInfo,
getOptionsAsFlags,
getEmbedderOptions: getEmbedderOptionsFromBinding,
getEnvOptionsInputType,
getNamespaceOptionsInputType,
parseNodeOptionsEnvVar,
} = internalBinding('options');
let warnOnAllowUnauthorized = true;
let optionsDict;
let cliInfo;
let embedderOptions;
let optionsFlags;
// 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() {
return optionsDict ??= getCLIOptionsValues();
}
function getCLIOptionsInfoFromBinding() {
return cliInfo ??= getCLIOptionsInfo();
}
function getOptionsAsFlagsFromBinding() {
return optionsFlags ??= getOptionsAsFlags();
}
function getEmbedderOptions() {
return embedderOptions ??= getEmbedderOptionsFromBinding();
}
function generateConfigJsonSchema() {
const envOptionsMap = getEnvOptionsInputType();
const namespaceOptionsMap = getNamespaceOptionsInputType();
function createPropertyForOptionDetail(detail) {
const { type, description } = detail;
if (type === 'array') {
return {
__proto__: null,
oneOf: [
{ __proto__: null, type: 'string' },
{ __proto__: null, type: 'array', minItems: 1, items: { __proto__: null, type: 'string' } },
],
description,
};
}
return { __proto__: null, type, description };
}
const schema = {
__proto__: null,
$schema: 'https://json-schema.org/draft/2020-12/schema',
additionalProperties: false,
required: [],
properties: {
$schema: {
__proto__: null,
type: 'string',
},
nodeOptions: {
__proto__: null,
additionalProperties: false,
required: [],
properties: { __proto__: null },
type: 'object',
},
__proto__: null,
},
type: 'object',
};
// Get the root properties object for adding namespaces
const rootProperties = schema.properties;
const nodeOptions = rootProperties.nodeOptions.properties;
// Add env options to nodeOptions (backward compatibility)
for (const { 0: key, 1: type } of ObjectEntries(envOptionsMap)) {
const keyWithoutPrefix = StringPrototypeReplace(key, '--', '');
nodeOptions[keyWithoutPrefix] = createPropertyForOptionDetail(type);
}
// Add namespace properties at the root level
for (const { 0: namespace, 1: optionsMap } of namespaceOptionsMap) {
// Create namespace object at the root level
rootProperties[namespace] = {
__proto__: null,
type: 'object',
additionalProperties: false,
required: [],
properties: { __proto__: null },
};
const namespaceProperties = rootProperties[namespace].properties;
// Add all options for this namespace
for (const { 0: optionName, 1: optionType } of ObjectEntries(optionsMap)) {
const keyWithoutPrefix = StringPrototypeReplace(optionName, '--', '');
namespaceProperties[keyWithoutPrefix] = createPropertyForOptionDetail(optionType);
}
// Sort the namespace properties alphabetically
const sortedNamespaceKeys = ArrayPrototypeSort(ObjectKeys(namespaceProperties));
const sortedNamespaceProperties = ObjectFromEntries(
ArrayPrototypeMap(sortedNamespaceKeys, (key) => [key, namespaceProperties[key]]),
);
rootProperties[namespace].properties = sortedNamespaceProperties;
}
// Sort the top-level properties by key alphabetically
const sortedKeys = ArrayPrototypeSort(ObjectKeys(nodeOptions));
const sortedProperties = ObjectFromEntries(
ArrayPrototypeMap(sortedKeys, (key) => [key, nodeOptions[key]]),
);
schema.properties.nodeOptions.properties = sortedProperties;
// Also sort the root level properties
const sortedRootKeys = ArrayPrototypeSort(ObjectKeys(rootProperties));
const sortedRootProperties = ObjectFromEntries(
ArrayPrototypeMap(sortedRootKeys, (key) => [key, rootProperties[key]]),
);
schema.properties = sortedRootProperties;
return schema;
}
function refreshOptions() {
optionsDict = undefined;
}
function getOptionValue(optionName) {
return getCLIOptionsFromBinding()[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;
}
module.exports = {
getCLIOptionsInfo: getCLIOptionsInfoFromBinding,
getOptionValue,
getOptionsAsFlagsFromBinding,
getAllowUnauthorized,
getEmbedderOptions,
generateConfigJsonSchema,
parseNodeOptionsEnvVar,
refreshOptions,
};