зеркало из https://github.com/electron/electron.git
feat: allow more Node.js cli flags in main process (#39344)
* feat: allow more Node.js cli flags in main process * docs: update cli switch documentation
This commit is contained in:
Родитель
c5b9f766f3
Коммит
2e0517c0ad
|
@ -241,19 +241,25 @@ Electron supports some of the [CLI flags][node-cli] supported by Node.js.
|
||||||
|
|
||||||
**Note:** Passing unsupported command line switches to Electron when it is not running in `ELECTRON_RUN_AS_NODE` will have no effect.
|
**Note:** Passing unsupported command line switches to Electron when it is not running in `ELECTRON_RUN_AS_NODE` will have no effect.
|
||||||
|
|
||||||
### --inspect-brk\[=\[host:]port]
|
### `--inspect-brk\[=\[host:]port]`
|
||||||
|
|
||||||
Activate inspector on host:port and break at start of user script. Default host:port is 127.0.0.1:9229.
|
Activate inspector on host:port and break at start of user script. Default host:port is 127.0.0.1:9229.
|
||||||
|
|
||||||
Aliased to `--debug-brk=[host:]port`.
|
Aliased to `--debug-brk=[host:]port`.
|
||||||
|
|
||||||
### --inspect-port=\[host:]port
|
#### `--inspect-brk-node[=[host:]port]`
|
||||||
|
|
||||||
|
Activate inspector on `host:port` and break at start of the first internal
|
||||||
|
JavaScript script executed when the inspector is available.
|
||||||
|
Default `host:port` is `127.0.0.1:9229`.
|
||||||
|
|
||||||
|
### `--inspect-port=\[host:]port`
|
||||||
|
|
||||||
Set the `host:port` to be used when the inspector is activated. Useful when activating the inspector by sending the SIGUSR1 signal. Default host is `127.0.0.1`.
|
Set the `host:port` to be used when the inspector is activated. Useful when activating the inspector by sending the SIGUSR1 signal. Default host is `127.0.0.1`.
|
||||||
|
|
||||||
Aliased to `--debug-port=[host:]port`.
|
Aliased to `--debug-port=[host:]port`.
|
||||||
|
|
||||||
### --inspect\[=\[host:]port]
|
### `--inspect\[=\[host:]port]`
|
||||||
|
|
||||||
Activate inspector on `host:port`. Default is `127.0.0.1:9229`.
|
Activate inspector on `host:port`. Default is `127.0.0.1:9229`.
|
||||||
|
|
||||||
|
@ -263,12 +269,28 @@ See the [Debugging the Main Process][debugging-main-process] guide for more deta
|
||||||
|
|
||||||
Aliased to `--debug[=[host:]port`.
|
Aliased to `--debug[=[host:]port`.
|
||||||
|
|
||||||
### --inspect-publish-uid=stderr,http
|
### `--inspect-publish-uid=stderr,http`
|
||||||
|
|
||||||
Specify ways of the inspector web socket url exposure.
|
Specify ways of the inspector web socket url exposure.
|
||||||
|
|
||||||
By default inspector websocket url is available in stderr and under /json/list endpoint on http://host:port/json/list.
|
By default inspector websocket url is available in stderr and under /json/list endpoint on http://host:port/json/list.
|
||||||
|
|
||||||
|
### `--no-deprecation`
|
||||||
|
|
||||||
|
Silence deprecation warnings.
|
||||||
|
|
||||||
|
### `--throw-deprecation`
|
||||||
|
|
||||||
|
Throw errors for deprecations.
|
||||||
|
|
||||||
|
### `--trace-deprecation`
|
||||||
|
|
||||||
|
Print stack traces for deprecations.
|
||||||
|
|
||||||
|
### `--trace-warnings`
|
||||||
|
|
||||||
|
Print stack traces for process warnings (including deprecations).
|
||||||
|
|
||||||
[app]: app.md
|
[app]: app.md
|
||||||
[append-switch]: command-line.md#commandlineappendswitchswitch-value
|
[append-switch]: command-line.md#commandlineappendswitchswitch-value
|
||||||
[debugging-main-process]: ../tutorial/debugging-main-process.md
|
[debugging-main-process]: ../tutorial/debugging-main-process.md
|
||||||
|
|
|
@ -228,21 +228,30 @@ void ErrorMessageListener(v8::Local<v8::Message> message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only allow DebugOptions in non-ELECTRON_RUN_AS_NODE mode.
|
// Only allow a specific subset of options in non-ELECTRON_RUN_AS_NODE mode.
|
||||||
// If node CLI inspect support is disabled, allow no debug options.
|
// If node CLI inspect support is disabled, allow no debug options.
|
||||||
bool IsAllowedDebugOption(base::StringPiece option) {
|
bool IsAllowedOption(base::StringPiece option) {
|
||||||
static constexpr auto options = base::MakeFixedFlatSet<base::StringPiece>({
|
static constexpr auto debug_options =
|
||||||
"--debug",
|
base::MakeFixedFlatSet<base::StringPiece>({
|
||||||
"--debug-brk",
|
"--debug",
|
||||||
"--debug-port",
|
"--debug-brk",
|
||||||
"--inspect",
|
"--debug-port",
|
||||||
"--inspect-brk",
|
"--inspect",
|
||||||
"--inspect-brk-node",
|
"--inspect-brk",
|
||||||
"--inspect-port",
|
"--inspect-brk-node",
|
||||||
"--inspect-publish-uid",
|
"--inspect-port",
|
||||||
});
|
"--inspect-publish-uid",
|
||||||
|
});
|
||||||
|
|
||||||
return electron::fuses::IsNodeCliInspectEnabled() && options.contains(option);
|
// This should be aligned with what's possible to set via the process object.
|
||||||
|
static constexpr auto options = base::MakeFixedFlatSet<base::StringPiece>(
|
||||||
|
{"--trace-warnings", "--trace-deprecation", "--throw-deprecation",
|
||||||
|
"--no-deprecation"});
|
||||||
|
|
||||||
|
if (debug_options.contains(option))
|
||||||
|
return electron::fuses::IsNodeCliInspectEnabled();
|
||||||
|
|
||||||
|
return options.contains(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize NODE_OPTIONS to pass to Node.js
|
// Initialize NODE_OPTIONS to pass to Node.js
|
||||||
|
@ -395,8 +404,9 @@ void NodeBindings::SetNodeCliFlags() {
|
||||||
#endif
|
#endif
|
||||||
const auto stripped = base::StringPiece(option).substr(0, option.find('='));
|
const auto stripped = base::StringPiece(option).substr(0, option.find('='));
|
||||||
|
|
||||||
// Only allow in no-op (--) option or DebugOptions
|
// Only allow in no-op (--) option or a small set of debug
|
||||||
if (IsAllowedDebugOption(stripped) || stripped == "--")
|
// and trace related options.
|
||||||
|
if (IsAllowedOption(stripped) || stripped == "--")
|
||||||
args.push_back(option);
|
args.push_back(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче