◐ Shell
clean mode source ↗

src: support namespace options in configuration file · nodejs/node@8ea1fc5

@@ -13,6 +13,7 @@ const {

1313

getCLIOptionsInfo,

1414

getEmbedderOptions: getEmbedderOptionsFromBinding,

1515

getEnvOptionsInputType,

16+

getNamespaceOptionsInputType,

1617

} = internalBinding('options');

17181819

let warnOnAllowUnauthorized = true;

@@ -38,7 +39,22 @@ function getEmbedderOptions() {

3839

}

39404041

function generateConfigJsonSchema() {

41-

const map = getEnvOptionsInputType();

42+

const envOptionsMap = getEnvOptionsInputType();

43+

const namespaceOptionsMap = getNamespaceOptionsInputType();

44+45+

function createPropertyForType(type) {

46+

if (type === 'array') {

47+

return {

48+

__proto__: null,

49+

oneOf: [

50+

{ __proto__: null, type: 'string' },

51+

{ __proto__: null, items: { __proto__: null, type: 'string', minItems: 1 }, type: 'array' },

52+

],

53+

};

54+

}

55+56+

return { __proto__: null, type };

57+

}

42584359

const schema = {

4460

__proto__: null,

@@ -60,31 +76,58 @@ function generateConfigJsonSchema() {

6076

type: 'object',

6177

};

627863-

const nodeOptions = schema.properties.nodeOptions.properties;

79+

// Get the root properties object for adding namespaces

80+

const rootProperties = schema.properties;

81+

const nodeOptions = rootProperties.nodeOptions.properties;

648265-

for (const { 0: key, 1: type } of map) {

83+

// Add env options to nodeOptions (backward compatibility)

84+

for (const { 0: key, 1: type } of envOptionsMap) {

6685

const keyWithoutPrefix = StringPrototypeReplace(key, '--', '');

67-

if (type === 'array') {

68-

nodeOptions[keyWithoutPrefix] = {

69-

__proto__: null,

70-

oneOf: [

71-

{ __proto__: null, type: 'string' },

72-

{ __proto__: null, items: { __proto__: null, type: 'string', minItems: 1 }, type: 'array' },

73-

],

74-

};

75-

} else {

76-

nodeOptions[keyWithoutPrefix] = { __proto__: null, type };

86+

nodeOptions[keyWithoutPrefix] = createPropertyForType(type);

87+

}

88+89+

// Add namespace properties at the root level

90+

for (const { 0: namespace, 1: optionsMap } of namespaceOptionsMap) {

91+

// Create namespace object at the root level

92+

rootProperties[namespace] = {

93+

__proto__: null,

94+

type: 'object',

95+

additionalProperties: false,

96+

properties: { __proto__: null },

97+

};

98+99+

const namespaceProperties = rootProperties[namespace].properties;

100+101+

// Add all options for this namespace

102+

for (const { 0: optionName, 1: optionType } of optionsMap) {

103+

const keyWithoutPrefix = StringPrototypeReplace(optionName, '--', '');

104+

namespaceProperties[keyWithoutPrefix] = createPropertyForType(optionType);

77105

}

106+107+

// Sort the namespace properties alphabetically

108+

const sortedNamespaceKeys = ArrayPrototypeSort(ObjectKeys(namespaceProperties));

109+

const sortedNamespaceProperties = ObjectFromEntries(

110+

ArrayPrototypeMap(sortedNamespaceKeys, (key) => [key, namespaceProperties[key]]),

111+

);

112+

rootProperties[namespace].properties = sortedNamespaceProperties;

78113

}

7911480-

// Sort the proerties by key alphabetically.

115+

// Sort the top-level properties by key alphabetically

81116

const sortedKeys = ArrayPrototypeSort(ObjectKeys(nodeOptions));

82117

const sortedProperties = ObjectFromEntries(

83118

ArrayPrototypeMap(sortedKeys, (key) => [key, nodeOptions[key]]),

84119

);

8512086121

schema.properties.nodeOptions.properties = sortedProperties;

87122123+

// Also sort the root level properties

124+

const sortedRootKeys = ArrayPrototypeSort(ObjectKeys(rootProperties));

125+

const sortedRootProperties = ObjectFromEntries(

126+

ArrayPrototypeMap(sortedRootKeys, (key) => [key, rootProperties[key]]),

127+

);

128+129+

schema.properties = sortedRootProperties;

130+88131

return schema;

89132

}

90133