/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/node_config_file.h
77 строк
3 KB
Marco Ippolito
src: support multiple versions in node.config.json
06 май 2026, 20:27
06 май 2026, 20:27
4002853
Код
Авторство
О чём код?
#ifndef SRC_NODE_CONFIG_FILE_H_ #define SRC_NODE_CONFIG_FILE_H_ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include <map> #include <string> #include <unordered_map> #include <unordered_set> #include <variant> #include <vector> #include "node_internals.h" #include "simdjson.h" #include "util-inl.h" namespace node { // When trying to parse the configuration file, we can have three possible // results: // - Valid: The file was successfully parsed and the content is valid. // - FileError: There was an error reading the file. // - InvalidContent: The file was read, but the content is invalid. enum ParseResult { Valid, FileError, InvalidContent }; // ConfigReader is the class that parses the configuration JSON file. // It reads the file provided by --experimental-config-file and // extracts the flags. class ConfigReader { public: ParseResult ParseConfig(const std::string_view& config_path); std::optional<std::string_view> GetDataFromArgs( std::vector<std::string>* args); bool HasInvalidDefaultConfigFileArgument() const; std::string GetNodeOptions(); const std::vector<std::string>& GetNamespaceFlags() const; size_t GetFlagsSize(); private: ParseResult ParseConfigObject(simdjson::ondemand::object* config_object, const std::string_view& config_path, bool allow_version_selection); ParseResult ParseNodeVersion(simdjson::ondemand::value* version_value, const std::string_view& config_path); ParseResult ParseConfigs(simdjson::ondemand::array* configs, const std::string_view& config_path); // Parse options for a specific namespace (including nodeOptions for backward // compatibility) ParseResult ParseOptions(simdjson::ondemand::object* options_object, std::unordered_set<std::string>* unique_options, const std::string& namespace_name); // Process a single option value based on its type ParseResult ProcessOptionValue( const std::pair<std::string, options_parser::OptionMappingDetails>& option_details, simdjson::ondemand::value* option_value, std::vector<std::string>* output); std::vector<std::string> node_options_; std::vector<std::string> namespace_options_; bool invalid_default_config_file_argument_ = false; // Cache for fast lookup of environment options std::unordered_map<std::string, options_parser::OptionMappingDetails> env_options_map_; bool env_options_initialized_ = false; }; } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_CONFIG_FILE_H_