зеркало из https://github.com/electron/electron.git
fix: enable NODE_OPTIONS env var (#15158)
This commit is contained in:
Родитель
51f3fb9bde
Коммит
a0b9d47d5e
2
DEPS
2
DEPS
|
@ -12,7 +12,7 @@ vars = {
|
||||||
'chromium_version':
|
'chromium_version':
|
||||||
'69.0.3497.106',
|
'69.0.3497.106',
|
||||||
'node_version':
|
'node_version':
|
||||||
'f14ddf9d7e07739dc1dc0cbe2f7a5ba8b44906d1',
|
'4d44266b78256449dd6ae86e419e3ec07257b569',
|
||||||
|
|
||||||
'boto_version': 'f7574aa6cc2c819430c1f05e9a1a1a666ef8169b',
|
'boto_version': 'f7574aa6cc2c819430c1f05e9a1a1a666ef8169b',
|
||||||
'pyyaml_version': '3.12',
|
'pyyaml_version': '3.12',
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/common/api/event_emitter_caller.h"
|
#include "atom/common/api/event_emitter_caller.h"
|
||||||
|
@ -18,6 +19,7 @@
|
||||||
#include "base/environment.h"
|
#include "base/environment.h"
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
#include "base/run_loop.h"
|
#include "base/run_loop.h"
|
||||||
|
#include "base/strings/string_split.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "base/threading/thread_task_runner_handle.h"
|
#include "base/threading/thread_task_runner_handle.h"
|
||||||
#include "base/trace_event/trace_event.h"
|
#include "base/trace_event/trace_event.h"
|
||||||
|
@ -214,19 +216,69 @@ void NodeBindings::Initialize() {
|
||||||
// Explicitly register electron's builtin modules.
|
// Explicitly register electron's builtin modules.
|
||||||
RegisterBuiltinModules();
|
RegisterBuiltinModules();
|
||||||
|
|
||||||
// Init node.
|
// pass non-null program name to argv so it doesn't crash
|
||||||
// (we assume node::Init would not modify the parameters under embedded mode).
|
// trying to index into a nullptr
|
||||||
// NOTE: If you change this line, please ping @codebytere or @MarshallOfSound
|
int argc = 1;
|
||||||
int argc = 0;
|
|
||||||
int exec_argc = 0;
|
int exec_argc = 0;
|
||||||
const char** argv = nullptr;
|
const char* prog_name = "electron";
|
||||||
|
const char** argv = &prog_name;
|
||||||
const char** exec_argv = nullptr;
|
const char** exec_argv = nullptr;
|
||||||
|
|
||||||
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||||
|
if (env->HasVar("NODE_OPTIONS")) {
|
||||||
|
base::FilePath exe_path;
|
||||||
|
base::PathService::Get(base::FILE_EXE, &exe_path);
|
||||||
|
std::string path = exe_path.value();
|
||||||
|
std::transform(path.begin(), path.end(), path.begin(), ::tolower);
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
const bool is_packaged_app = path == "electron.exe";
|
||||||
|
#else
|
||||||
|
const bool is_packaged_app = path == "electron";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// explicitly disallow NODE_OPTIONS in packaged apps
|
||||||
|
if (is_packaged_app) {
|
||||||
|
LOG(WARNING) << "NODE_OPTIONs are not supported in packaged apps";
|
||||||
|
env->SetVar("NODE_OPTIONS", "");
|
||||||
|
} else {
|
||||||
|
const std::vector<std::string> disallowed = {
|
||||||
|
"--openssl-config", "--use-bundled-ca", "--use-openssl-ca",
|
||||||
|
"--force-fips", "--enable-fips"};
|
||||||
|
|
||||||
|
std::string options;
|
||||||
|
env->GetVar("NODE_OPTIONS", &options);
|
||||||
|
std::vector<std::string> parts = base::SplitString(
|
||||||
|
options, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||||
|
|
||||||
|
// parse passed options for unsupported options
|
||||||
|
// and remove them from the options list
|
||||||
|
std::string new_options = options;
|
||||||
|
for (const auto& disallow : disallowed) {
|
||||||
|
for (const auto& part : parts) {
|
||||||
|
if (part.find(disallow) != std::string::npos) {
|
||||||
|
LOG(WARNING) << "The NODE_OPTION" << disallow
|
||||||
|
<< "is not supported in Electron";
|
||||||
|
new_options.erase(new_options.find(part), part.length());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// overwrite new NODE_OPTIONS without unsupported variables
|
||||||
|
if (new_options != options)
|
||||||
|
env->SetVar("NODE_OPTIONS", new_options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(codebytere): this is going to be deprecated in the near future
|
||||||
|
// in favor of Init(std::vector<std::string>* argv,
|
||||||
|
// std::vector<std::string>* exec_argv)
|
||||||
node::Init(&argc, argv, &exec_argc, &exec_argv);
|
node::Init(&argc, argv, &exec_argc, &exec_argv);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
// uv_init overrides error mode to suppress the default crash dialog, bring
|
// uv_init overrides error mode to suppress the default crash dialog, bring
|
||||||
// it back if user wants to show it.
|
// it back if user wants to show it.
|
||||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
||||||
if (browser_env_ == BROWSER || env->HasVar("ELECTRON_DEFAULT_ERROR_MODE"))
|
if (browser_env_ == BROWSER || env->HasVar("ELECTRON_DEFAULT_ERROR_MODE"))
|
||||||
SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX);
|
SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,6 +24,28 @@ Windows console example:
|
||||||
The following environment variables are intended primarily for use at runtime
|
The following environment variables are intended primarily for use at runtime
|
||||||
in packaged Electron applications.
|
in packaged Electron applications.
|
||||||
|
|
||||||
|
### `NODE_OPTIONS`
|
||||||
|
|
||||||
|
Electron includes support for a subset of Node's [`NODE_OPTIONS`](https://nodejs.org/api/cli.html#cli_node_options_options). The majority are supported with the exception of those which conflict with Chromium's use of BoringSSL.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
export NODE_OPTIONS="--no-warnings --max-old-space-size=2048"
|
||||||
|
```
|
||||||
|
|
||||||
|
Unsupported options are:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
--use-bundled-ca
|
||||||
|
--force-fips
|
||||||
|
--enable-fips
|
||||||
|
--openssl-config
|
||||||
|
--use-openssl-ca
|
||||||
|
```
|
||||||
|
|
||||||
|
`NODE_OPTIONS` are explicitly disallowed in packaged apps.
|
||||||
|
|
||||||
### `GOOGLE_API_KEY`
|
### `GOOGLE_API_KEY`
|
||||||
|
|
||||||
Electron includes a hardcoded API key for making requests to Google's geocoding
|
Electron includes a hardcoded API key for making requests to Google's geocoding
|
||||||
|
|
Загрузка…
Ссылка в новой задаче