From 1d7214bddc6f224a3fb3d6289c805095432922da Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 30 Aug 2021 19:10:39 +0200 Subject: [PATCH] build: add option to hide console window https://github.com/nodejs/node/pull/39712 --- patches/node/.patches | 1 - ...reventing_initializeinspector_in_env.patch | 28 +++++++++---------- ...console_window_when_creating_process.patch | 21 -------------- shell/common/node_bindings.cc | 12 +++++--- 4 files changed, 22 insertions(+), 40 deletions(-) delete mode 100644 patches/node/fix_don_t_create_console_window_when_creating_process.patch diff --git a/patches/node/.patches b/patches/node/.patches index 5bdf45a79cb78..ba1e0f67fe1c8 100644 --- a/patches/node/.patches +++ b/patches/node/.patches @@ -1,5 +1,4 @@ make_module_globalpaths_a_reference.patch -fix_don_t_create_console_window_when_creating_process.patch refactor_alter_child_process_fork_to_use_execute_script_with.patch feat_add_uv_loop_watcher_queue_code.patch feat_initialize_asar_support.patch diff --git a/patches/node/fix_allow_preventing_initializeinspector_in_env.patch b/patches/node/fix_allow_preventing_initializeinspector_in_env.patch index 17adcc66aee17..8d34f346fef30 100644 --- a/patches/node/fix_allow_preventing_initializeinspector_in_env.patch +++ b/patches/node/fix_allow_preventing_initializeinspector_in_env.patch @@ -36,11 +36,11 @@ index de29d45adde76587f2a9cd50392ba45b8e24839e..09c0d22ff91856704f61024646c946a3 #endif diff --git a/src/env-inl.h b/src/env-inl.h -index b3b1ea908253b9240cc37931f34b2a8c8c9fa3ab..dc37298aa0e13bb79030123f38070d0254691b28 100644 +index 061897d95d8b5f61968c59260e609d7be724b88f..7c7ee3207089bf3e51db646a367bdd6deba18628 100644 --- a/src/env-inl.h +++ b/src/env-inl.h -@@ -877,6 +877,10 @@ inline bool Environment::tracks_unmanaged_fds() const { - return flags_ & EnvironmentFlags::kTrackUnmanagedFds; +@@ -881,6 +881,10 @@ inline bool Environment::hide_console_windows() const { + return flags_ & EnvironmentFlags::kHideConsoleWindows; } +inline bool Environment::should_initialize_inspector() const { @@ -51,31 +51,31 @@ index b3b1ea908253b9240cc37931f34b2a8c8c9fa3ab..dc37298aa0e13bb79030123f38070d02 return emit_filehandle_warning_; } diff --git a/src/env.h b/src/env.h -index 24b4a48b5f9657cc115aaa50e0f7354534ed5484..0877f5b1fe2db42acf908e0e1085626fc258ef54 100644 +index 8760bc4361f199a2e3471c4ca435f8e178c78e7e..33f34ed79452b004b5fb40e70cda6e3d0ee2d1e2 100644 --- a/src/env.h +++ b/src/env.h -@@ -1198,6 +1198,7 @@ class Environment : public MemoryRetainer { - inline bool owns_process_state() const; +@@ -1199,6 +1199,7 @@ class Environment : public MemoryRetainer { inline bool owns_inspector() const; inline bool tracks_unmanaged_fds() const; + inline bool hide_console_windows() const; + inline bool should_initialize_inspector() const; inline uint64_t thread_id() const; inline worker::Worker* worker_context() const; Environment* worker_parent_env() const; diff --git a/src/node.h b/src/node.h -index 41f79ef869128636ac04093919e8e5816b39bef9..691c16ba60b0ce8633555825e44c3ace96c5000f 100644 +index b7f3e97873ef90b635e0648639f1a287a0bd88fa..48e378079f6d05e7cc1141a8875450b125028789 100644 --- a/src/node.h +++ b/src/node.h -@@ -405,7 +405,11 @@ enum Flags : uint64_t { - kNoRegisterESMLoader = 1 << 3, - // Set this flag to make Node.js track "raw" file descriptors, i.e. managed - // by fs.open() and fs.close(), and close them during FreeEnvironment(). -- kTrackUnmanagedFds = 1 << 4 -+ kTrackUnmanagedFds = 1 << 4, +@@ -409,7 +409,11 @@ enum Flags : uint64_t { + // Set this flag to force hiding console windows when spawning child + // processes. This is usually used when embedding Node.js in GUI programs on + // Windows. +- kHideConsoleWindows = 1 << 5 ++ kHideConsoleWindows = 1 << 5, + // Controls whether or not the Environment should call InitializeInspector. + // This control is needed by embedders who may not want to initialize the V8 + // inspector in situations where it already exists. -+ kNoInitializeInspector = 1 << 5 ++ kNoInitializeInspector = 1 << 6 }; } // namespace EnvironmentFlags diff --git a/patches/node/fix_don_t_create_console_window_when_creating_process.patch b/patches/node/fix_don_t_create_console_window_when_creating_process.patch deleted file mode 100644 index 7016b8334c927..0000000000000 --- a/patches/node/fix_don_t_create_console_window_when_creating_process.patch +++ /dev/null @@ -1,21 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Shelley Vohr -Date: Mon, 30 Jul 2018 10:23:05 -0700 -Subject: fix: don't create console window when creating process - -This commit prevents console windows from being spawned when creating processes to better align with what Windows users expect and should be removed when upgrading to a version that includes https://github.com/nodejs/node/pull/21316 - -diff --git a/deps/uv/src/win/process.c b/deps/uv/src/win/process.c -index 4038fbfd290d1acc91a27ad38e248a2deb06eb68..1ebc0f50e3f0cccb4d8887322b75e61c5284ba2f 100644 ---- a/deps/uv/src/win/process.c -+++ b/deps/uv/src/win/process.c -@@ -1098,6 +1098,9 @@ int uv_spawn(uv_loop_t* loop, - process_flags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP; - } - -+ /* Don't create console window. */ -+ process_flags |= CREATE_NO_WINDOW; -+ - if (!CreateProcessW(application_path, - arguments, - NULL, diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 7bf1e9f611d74..b5796649a77b4 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -450,13 +450,15 @@ node::Environment* NodeBindings::CreateEnvironment( node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform); node::Environment* env; + uint64_t flags = node::EnvironmentFlags::kDefaultFlags | + node::EnvironmentFlags::kHideConsoleWindows; + if (browser_env_ != BrowserEnvironment::kBrowser) { // Only one ESM loader can be registered per isolate - // in renderer processes this should be blink. We need to tell Node.js // not to register its handler (overriding blinks) in non-browser processes. - uint64_t flags = node::EnvironmentFlags::kDefaultFlags | - node::EnvironmentFlags::kNoRegisterESMLoader | - node::EnvironmentFlags::kNoInitializeInspector; + flags |= node::EnvironmentFlags::kNoRegisterESMLoader | + node::EnvironmentFlags::kNoInitializeInspector; v8::TryCatch try_catch(context->GetIsolate()); env = node::CreateEnvironment( isolate_data_, context, args, exec_args, @@ -470,7 +472,9 @@ node::Environment* NodeBindings::CreateEnvironment( << process_type; } } else { - env = node::CreateEnvironment(isolate_data_, context, args, exec_args); + env = node::CreateEnvironment( + isolate_data_, context, args, exec_args, + static_cast(flags)); DCHECK(env); }