diff --git a/CMakeLists.txt b/CMakeLists.txt index ece8c1b340..eaf7b30e71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22) cmake_policy(SET CMP0091 NEW) cmake_policy(SET CMP0067 NEW) -set(Bun_VERSION "1.1.2") +set(Bun_VERSION "1.1.3") set(WEBKIT_TAG e3a2d89a0b1644cc8d5c245bd2ffee4d4bd6c1d5) set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/src/bun.js/bindings/ProcessBindingTTYWrap.cpp b/src/bun.js/bindings/ProcessBindingTTYWrap.cpp index 8cfa7089a5..c3073e693a 100644 --- a/src/bun.js/bindings/ProcessBindingTTYWrap.cpp +++ b/src/bun.js/bindings/ProcessBindingTTYWrap.cpp @@ -186,6 +186,10 @@ private: } }; +#if OS(WINDOWS) +extern "C" void Bun__setCTRLHandler(BOOL add); +#endif + const ClassInfo TTYWrapObject::s_info = { "LibuvStreamWrap"_s, @@ -251,6 +255,10 @@ JSC_DEFINE_HOST_FUNCTION(TTYWrap_functionSetMode, } #if OS(WINDOWS) + if (mode.toInt32(globalObject) == 0) { + Bun__setCTRLHandler(1); + } + int err = uv_tty_set_mode(ttyWrap->handle->tty(), mode.toInt32(globalObject)); #else // Nodejs does not throw when ttySetMode fails. An Error event is emitted instead. diff --git a/src/bun.js/bindings/c-bindings.cpp b/src/bun.js/bindings/c-bindings.cpp index 845c0b05ac..72799419a6 100644 --- a/src/bun.js/bindings/c-bindings.cpp +++ b/src/bun.js/bindings/c-bindings.cpp @@ -404,6 +404,25 @@ extern "C" void onExitSignal(int sig) } #endif +#if OS(WINDOWS) +extern "C" void Bun__restoreWindowsStdio(); +BOOL WINAPI Ctrlhandler(DWORD signal) +{ + + if (signal == CTRL_C_EVENT) { + Bun__restoreWindowsStdio(); + SetConsoleCtrlHandler(Ctrlhandler, FALSE); + } + + return FALSE; +} + +extern "C" void Bun__setCTRLHandler(BOOL add) +{ + SetConsoleCtrlHandler(Ctrlhandler, add); +} +#endif + extern "C" void bun_initialize_process() { // Disable printf() buffering. We buffer it ourselves. @@ -517,6 +536,9 @@ extern "C" void bun_initialize_process() } } } + + // add ctrl+c handler on windows + Bun__setCTRLHandler(1); #endif atexit(Bun__onExit); diff --git a/src/output.zig b/src/output.zig index bd3b3930c6..b20727ee14 100644 --- a/src/output.zig +++ b/src/output.zig @@ -148,6 +148,15 @@ pub const Source = struct { pub var console_codepage = @as(u32, 0); pub var console_output_codepage = @as(u32, 0); + pub export fn Bun__restoreWindowsStdio() callconv(.C) void { + restore(); + } + comptime { + if (Environment.isWindows) { + _ = &Bun__restoreWindowsStdio; + } + } + pub fn restore() void { const peb = std.os.windows.peb(); const stdout = peb.ProcessParameters.hStdOutput; diff --git a/test/cli/install/registry/bun-install-registry.test.ts b/test/cli/install/registry/bun-install-registry.test.ts index 8986a8c8c2..2b50119cbe 100644 --- a/test/cli/install/registry/bun-install-registry.test.ts +++ b/test/cli/install/registry/bun-install-registry.test.ts @@ -28,6 +28,7 @@ beforeAll(async () => { await new Promise(done => { verdaccioServer.on("message", (msg: { verdaccio_started: boolean }) => { if (msg.verdaccio_started) { + console.log("Verdaccio started"); done(); } }); @@ -40,6 +41,7 @@ afterAll(() => { beforeEach(async () => { packageDir = mkdtempSync(join(realpathSync(tmpdir()), "bun-install-registry-" + testCounter++ + "-")); + env.BUN_INSTALL_CACHE_DIR = join(packageDir, ".bun-cache"); await writeFile( join(packageDir, "bunfig.toml"), `