diff options
author | 2023-08-20 19:34:33 -0700 | |
---|---|---|
committer | 2023-08-20 19:34:33 -0700 | |
commit | 3de9ce5f30ad3a2a5615acb62a25cecdd2ddef33 (patch) | |
tree | edbfe3f14bc8f09497aeea2b88d60d9a070404f4 | |
parent | 65280853acf2385eae124ef4870af2751ad662df (diff) | |
download | bun-3de9ce5f30ad3a2a5615acb62a25cecdd2ddef33.tar.gz bun-3de9ce5f30ad3a2a5615acb62a25cecdd2ddef33.tar.zst bun-3de9ce5f30ad3a2a5615acb62a25cecdd2ddef33.zip |
Implement `--inspect-brk` (#4222)
* Implement `--inspect-brk`
* Bump WebKit
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r-- | .github/workflows/bun-linux-aarch64.yml | 2 | ||||
-rw-r--r-- | .github/workflows/bun-linux-build.yml | 4 | ||||
-rw-r--r-- | .github/workflows/bun-mac-aarch64.yml | 16 | ||||
-rw-r--r-- | .github/workflows/bun-mac-x64-baseline.yml | 16 | ||||
-rw-r--r-- | .github/workflows/bun-mac-x64.yml | 16 | ||||
-rw-r--r-- | Dockerfile | 2 | ||||
-rwxr-xr-x | bun.lockb | bin | 73331 -> 73331 bytes | |||
-rw-r--r-- | package.json | 2 | ||||
m--------- | src/bun.js/WebKit | 0 | ||||
-rw-r--r-- | src/bun.js/bindings/BunDebugger.cpp | 41 | ||||
-rw-r--r-- | src/bun.js/javascript.zig | 6 | ||||
-rw-r--r-- | src/bun.js/module_loader.zig | 2 | ||||
-rw-r--r-- | src/bundler.zig | 2 | ||||
-rw-r--r-- | src/cli.zig | 16 | ||||
-rw-r--r-- | src/cli/test_command.zig | 1 | ||||
-rw-r--r-- | src/js_parser.zig | 14 | ||||
-rw-r--r-- | src/runtime.zig | 2 |
17 files changed, 101 insertions, 41 deletions
diff --git a/.github/workflows/bun-linux-aarch64.yml b/.github/workflows/bun-linux-aarch64.yml index 6d9126282..4d08f59e0 100644 --- a/.github/workflows/bun-linux-aarch64.yml +++ b/.github/workflows/bun-linux-aarch64.yml @@ -36,7 +36,7 @@ jobs: arch: aarch64 build_arch: arm64 runner: linux-arm64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-linux-arm64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-linux-arm64-lto.tar.gz" webkit_basename: "bun-webkit-linux-arm64-lto" build_machine_arch: aarch64 diff --git a/.github/workflows/bun-linux-build.yml b/.github/workflows/bun-linux-build.yml index 3b3d2efcd..3114d46bc 100644 --- a/.github/workflows/bun-linux-build.yml +++ b/.github/workflows/bun-linux-build.yml @@ -46,7 +46,7 @@ jobs: arch: x86_64 build_arch: amd64 runner: big-ubuntu - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-linux-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-linux-amd64-lto.tar.gz" webkit_basename: "bun-webkit-linux-amd64-lto" build_machine_arch: x86_64 - cpu: nehalem @@ -54,7 +54,7 @@ jobs: arch: x86_64 build_arch: amd64 runner: big-ubuntu - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-linux-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-linux-amd64-lto.tar.gz" webkit_basename: "bun-webkit-linux-amd64-lto" build_machine_arch: x86_64 diff --git a/.github/workflows/bun-mac-aarch64.yml b/.github/workflows/bun-mac-aarch64.yml index 53e15c4c7..1d24bf705 100644 --- a/.github/workflows/bun-mac-aarch64.yml +++ b/.github/workflows/bun-mac-aarch64.yml @@ -117,7 +117,7 @@ jobs: # obj: bun-obj-darwin-x64-baseline # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: true # compile_obj: false # - cpu: haswell @@ -126,7 +126,7 @@ jobs: # obj: bun-obj-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: true # compile_obj: false # - cpu: nehalem @@ -135,7 +135,7 @@ jobs: # obj: bun-obj-darwin-x64-baseline # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: false # compile_obj: true # - cpu: haswell @@ -144,7 +144,7 @@ jobs: # obj: bun-obj-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: false # compile_obj: true - cpu: native @@ -152,7 +152,7 @@ jobs: tag: bun-darwin-aarch64 obj: bun-obj-darwin-aarch64 artifact: bun-obj-darwin-aarch64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-arm64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-arm64-lto.tar.gz" runner: macos-arm64 dependencies: true compile_obj: true @@ -257,7 +257,7 @@ jobs: # package: bun-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # - cpu: haswell # arch: x86_64 # tag: bun-darwin-x64 @@ -265,14 +265,14 @@ jobs: # package: bun-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" - cpu: native arch: aarch64 tag: bun-darwin-aarch64 obj: bun-obj-darwin-aarch64 package: bun-darwin-aarch64 artifact: bun-obj-darwin-aarch64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-arm64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-arm64-lto.tar.gz" runner: macos-arm64 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/bun-mac-x64-baseline.yml b/.github/workflows/bun-mac-x64-baseline.yml index 1b750ec7d..800989bbc 100644 --- a/.github/workflows/bun-mac-x64-baseline.yml +++ b/.github/workflows/bun-mac-x64-baseline.yml @@ -117,7 +117,7 @@ jobs: obj: bun-obj-darwin-x64-baseline runner: macos-11 artifact: bun-obj-darwin-x64-baseline - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" dependencies: true compile_obj: false # - cpu: haswell @@ -126,7 +126,7 @@ jobs: # obj: bun-obj-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: true # compile_obj: false - cpu: nehalem @@ -135,7 +135,7 @@ jobs: obj: bun-obj-darwin-x64-baseline runner: macos-11 artifact: bun-obj-darwin-x64-baseline - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" dependencies: false compile_obj: true # - cpu: haswell @@ -144,7 +144,7 @@ jobs: # obj: bun-obj-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: false # compile_obj: true # - cpu: native @@ -152,7 +152,7 @@ jobs: # tag: bun-darwin-aarch64 # obj: bun-obj-darwin-aarch64 # artifact: bun-obj-darwin-aarch64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # runner: macos-arm64 # dependencies: true # compile_obj: true @@ -258,7 +258,7 @@ jobs: package: bun-darwin-x64 runner: macos-11 artifact: bun-obj-darwin-x64-baseline - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # - cpu: haswell # arch: x86_64 # tag: bun-darwin-x64 @@ -266,14 +266,14 @@ jobs: # package: bun-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # - cpu: native # arch: aarch64 # tag: bun-darwin-aarch64 # obj: bun-obj-darwin-aarch64 # package: bun-darwin-aarch64 # artifact: bun-obj-darwin-aarch64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # runner: macos-arm64 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/bun-mac-x64.yml b/.github/workflows/bun-mac-x64.yml index a7a6773d0..74a8ca5c0 100644 --- a/.github/workflows/bun-mac-x64.yml +++ b/.github/workflows/bun-mac-x64.yml @@ -117,7 +117,7 @@ jobs: # obj: bun-obj-darwin-x64-baseline # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: true # compile_obj: false - cpu: haswell @@ -126,7 +126,7 @@ jobs: obj: bun-obj-darwin-x64 runner: macos-11 artifact: bun-obj-darwin-x64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" dependencies: true compile_obj: false # - cpu: nehalem @@ -135,7 +135,7 @@ jobs: # obj: bun-obj-darwin-x64-baseline # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # dependencies: false # compile_obj: true - cpu: haswell @@ -144,7 +144,7 @@ jobs: obj: bun-obj-darwin-x64 runner: macos-11 artifact: bun-obj-darwin-x64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" dependencies: false compile_obj: true # - cpu: native @@ -152,7 +152,7 @@ jobs: # tag: bun-darwin-aarch64 # obj: bun-obj-darwin-aarch64 # artifact: bun-obj-darwin-aarch64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-arm64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-arm64-lto.tar.gz" # runner: macos-arm64 # dependencies: true # compile_obj: true @@ -260,7 +260,7 @@ jobs: # package: bun-darwin-x64 # runner: macos-11 # artifact: bun-obj-darwin-x64-baseline - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" - cpu: haswell arch: x86_64 tag: bun-darwin-x64 @@ -268,14 +268,14 @@ jobs: package: bun-darwin-x64 runner: macos-11 artifact: bun-obj-darwin-x64 - webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-amd64-lto.tar.gz" + webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-amd64-lto.tar.gz" # - cpu: native # arch: aarch64 # tag: bun-darwin-aarch64 # obj: bun-obj-darwin-aarch64 # package: bun-darwin-aarch64 # artifact: bun-obj-darwin-aarch64 - # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-3/bun-webkit-macos-arm64-lto.tar.gz" + # webkit_url: "https://github.com/oven-sh/WebKit/releases/download/2023-aug3-4/bun-webkit-macos-arm64-lto.tar.gz" # runner: macos-arm64 steps: - uses: actions/checkout@v3 diff --git a/Dockerfile b/Dockerfile index 8a0bd4414..2243e2790 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ ARG ARCH=x86_64 ARG BUILD_MACHINE_ARCH=x86_64 ARG TRIPLET=${ARCH}-linux-gnu ARG BUILDARCH=amd64 -ARG WEBKIT_TAG=2023-aug3-3 +ARG WEBKIT_TAG=2023-aug3-4 ARG ZIG_TAG=jul1 ARG ZIG_VERSION="0.11.0-dev.4006+bf827d0b5" ARG WEBKIT_BASENAME="bun-webkit-linux-$BUILDARCH" Binary files differdiff --git a/package.json b/package.json index 87d21bed3..ba3a9a0b0 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@types/react": "^18.0.25", "@typescript-eslint/eslint-plugin": "^5.31.0", "@typescript-eslint/parser": "^5.31.0", - "bun-webkit": "0.0.1-fc705595a2e10361a64f1dab56527d7b112e75c6" + "bun-webkit": "0.0.1-fd79ce3120a692f4aed314c3da3dd452b4aa865f" }, "version": "0.0.0", "prettier": "./.prettierrc.cjs" diff --git a/src/bun.js/WebKit b/src/bun.js/WebKit -Subproject fc705595a2e10361a64f1dab56527d7b112e75c +Subproject fd79ce3120a692f4aed314c3da3dd452b4aa865 diff --git a/src/bun.js/bindings/BunDebugger.cpp b/src/bun.js/bindings/BunDebugger.cpp index 41001a8f2..440a5125b 100644 --- a/src/bun.js/bindings/BunDebugger.cpp +++ b/src/bun.js/bindings/BunDebugger.cpp @@ -23,14 +23,40 @@ static WebCore::ScriptExecutionContext* debuggerScriptExecutionContext = nullptr static WTF::Lock inspectorConnectionsLock = WTF::Lock(); static WTF::HashMap<ScriptExecutionContextIdentifier, Vector<BunInspectorConnection*, 8>>* inspectorConnections = nullptr; +static bool waitingForConnection = false; +extern "C" void Debugger__didConnect(); + +class BunJSGlobalObjectDebuggable final : public JSC::JSGlobalObjectDebuggable { +public: + using Base = JSC::JSGlobalObjectDebuggable; + + BunJSGlobalObjectDebuggable(JSC::JSGlobalObject& globalObject) + : Base(globalObject) + { + } + + ~BunJSGlobalObjectDebuggable() final + { + } + + void pauseWaitingForAutomaticInspection() override + { + } + void unpauseForInitializedInspector() override + { + if (waitingForConnection) { + waitingForConnection = false; + Debugger__didConnect(); + } + } +}; + enum class ConnectionStatus : int32_t { Pending = 0, Connected = 1, Disconnecting = 2, Disconnected = 3, }; -static bool waitingForConnection = false; -extern "C" void Debugger__didConnect(); class BunInspectorConnection : public Inspector::FrontendChannel { @@ -81,15 +107,9 @@ public: Bun__eventLoop__incrementRefConcurrently(reinterpret_cast<Zig::GlobalObject*>(globalObject)->bunVM(), 1); } globalObject->setInspectable(true); - auto& inspector = globalObject->inspectorDebuggable(); inspector.setInspectable(true); - - inspector.connect(*connection); - if (waitingForConnection) { - waitingForConnection = false; - Debugger__didConnect(); - } + globalObject->inspectorController().connectFrontend(*connection, true, waitingForConnection); Inspector::JSGlobalObjectDebugger* debugger = reinterpret_cast<Inspector::JSGlobalObjectDebugger*>(globalObject->debugger()); if (debugger) { @@ -99,7 +119,6 @@ public: } connection->receiveMessagesOnInspectorThread(context, reinterpret_cast<Zig::GlobalObject*>(globalObject)); - break; } default: { @@ -415,6 +434,8 @@ extern "C" void Bun__ensureDebugger(ScriptExecutionContextIdentifier scriptId, b auto* globalObject = ScriptExecutionContext::getScriptExecutionContext(scriptId)->jsGlobalObject(); globalObject->m_inspectorController = makeUnique<Inspector::JSGlobalObjectInspectorController>(*globalObject, Bun::BunInjectedScriptHost::create()); + globalObject->m_inspectorDebuggable = makeUnique<BunJSGlobalObjectDebuggable>(*globalObject); + globalObject->setInspectable(true); auto& inspector = globalObject->inspectorDebuggable(); diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 98e61f3b0..07d3f64cf 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -748,6 +748,8 @@ pub const VirtualMachine = struct { next_debugger_id: u64 = 1, poll_ref: JSC.PollRef = .{}, wait_for_connection: bool = false, + set_breakpoint_on_first_line: bool = false, + const debug = Output.scoped(.DEBUGGER, false); extern "C" fn Bun__createJSDebugger(*JSC.JSGlobalObject) u32; @@ -784,6 +786,8 @@ pub const VirtualMachine = struct { Bun__ensureDebugger(debugger.script_execution_context_id, debugger.wait_for_connection); while (debugger.wait_for_connection) { this.eventLoop().tick(); + if (debugger.wait_for_connection) + this.eventLoop().autoTickActive(); } } @@ -1136,6 +1140,7 @@ pub const VirtualMachine = struct { this.debugger = Debugger{ .path_or_port = debugger.enable.path_or_port, .wait_for_connection = debugger.enable.wait_for_connection, + .set_breakpoint_on_first_line = debugger.enable.set_breakpoint_on_first_line, }; }, } @@ -1870,6 +1875,7 @@ pub const VirtualMachine = struct { pub fn reloadEntryPoint(this: *VirtualMachine, entry_path: []const u8) !*JSInternalPromise { this.has_loaded = false; this.main = entry_path; + this.main_hash = bun.JSC.Watcher.getHash(entry_path); try this.entry_point.generate( this.allocator, diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index be10b9722..dfb9077e2 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -403,6 +403,7 @@ pub const RuntimeTranspilerStore = struct { vm.main.len == path.text.len and vm.main_hash == hash and strings.eqlLong(vm.main, path.text, false), + .set_breakpoint_on_first_line = vm.debugger != null and vm.debugger.?.set_breakpoint_on_first_line and strings.eqlLong(vm.main, path.text, false), }; defer { @@ -1439,6 +1440,7 @@ pub const ModuleLoader = struct { .dont_bundle_twice = true, .allow_commonjs = true, .inject_jest_globals = jsc_vm.bundler.options.rewrite_jest_for_tests and is_main, + .set_breakpoint_on_first_line = is_main and jsc_vm.debugger != null and jsc_vm.debugger.?.set_breakpoint_on_first_line, }; defer { if (should_close_input_file_fd and input_file_fd != 0) { diff --git a/src/bundler.zig b/src/bundler.zig index b5912a96f..ce7d9fc42 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -1188,6 +1188,7 @@ pub const Bundler = struct { virtual_source: ?*const logger.Source = null, replace_exports: runtime.Runtime.Features.ReplaceableExport.Map = .{}, inject_jest_globals: bool = false, + set_breakpoint_on_first_line: bool = false, dont_bundle_twice: bool = false, allow_commonjs: bool = false, @@ -1302,6 +1303,7 @@ pub const Bundler = struct { var opts = js_parser.Parser.Options.init(jsx, loader); opts.legacy_transform_require_to_import = bundler.options.allow_runtime and !bundler.options.target.isBun(); opts.features.allow_runtime = bundler.options.allow_runtime; + opts.features.set_breakpoint_on_first_line = this_parse.set_breakpoint_on_first_line; opts.features.trim_unused_imports = bundler.options.trim_unused_imports orelse loader.isTypeScript(); opts.features.should_fold_typescript_constant_expressions = loader.isTypeScript() or target.isBun() or bundler.options.minify_syntax; opts.features.dynamic_require = target.isBun(); diff --git a/src/cli.zig b/src/cli.zig index 88b6aa057..0fb618afc 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -161,7 +161,8 @@ pub const Arguments = struct { clap.parseParam("--no-macros Disable macros from being executed in the bundler, transpiler and runtime") catch unreachable, clap.parseParam("--target <STR> The intended execution environment for the bundle. \"browser\", \"bun\" or \"node\"") catch unreachable, clap.parseParam("--inspect <STR>? Activate Bun's Debugger") catch unreachable, - clap.parseParam("--inspect-wait <STR>? Activate Bun's Debugger and wait for a connection before executing") catch unreachable, + clap.parseParam("--inspect-wait <STR>? Activate Bun's Debugger, wait for a connection before executing") catch unreachable, + clap.parseParam("--inspect-brk <STR>? Activate Bun's Debugger, set breakpoint on first line of code and wait") catch unreachable, clap.parseParam("<POS>... ") catch unreachable, }; @@ -530,6 +531,18 @@ pub const Arguments = struct { .path_or_port = inspect_flag, .wait_for_connection = true, } }; + } else if (args.option("--inspect-brk")) |inspect_flag| { + ctx.runtime_options.debugger = if (inspect_flag.len == 0) + Command.Debugger{ .enable = .{ + .wait_for_connection = true, + .set_breakpoint_on_first_line = true, + } } + else + Command.Debugger{ .enable = .{ + .path_or_port = inspect_flag, + .wait_for_connection = true, + .set_breakpoint_on_first_line = true, + } }; } } @@ -969,6 +982,7 @@ pub const Command = struct { enable: struct { path_or_port: []const u8 = "", wait_for_connection: bool = false, + set_breakpoint_on_first_line: bool = false, }, }; diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 5686659c8..5bf48d7d9 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -924,7 +924,6 @@ pub const TestCommand = struct { // https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines const file_prefix = if (Output.is_github_action) "::group::" else ""; - vm.main_hash = @as(u32, @truncate(bun.hash(file_path))); var repeat_count = reporter.repeat_count; var repeat_index: u32 = 0; while (repeat_index < repeat_count) : (repeat_index += 1) { diff --git a/src/js_parser.zig b/src/js_parser.zig index bb767d875..ebe2a01c9 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -2950,6 +2950,20 @@ pub const Parser = struct { before.deinit(); } + // --inspect-brk + if (p.options.features.set_breakpoint_on_first_line) { + var debugger_stmts = try p.allocator.alloc(Stmt, 1); + debugger_stmts[0] = Stmt{ + .data = .{ .s_debugger = .{} }, + .loc = logger.Loc.Empty, + }; + before.append( + js_ast.Part{ + .stmts = debugger_stmts, + }, + ) catch unreachable; + } + if (p.options.bundle) { // allocate an empty part for the bundle before.append( diff --git a/src/runtime.zig b/src/runtime.zig index 790f5b197..2c22f392e 100644 --- a/src/runtime.zig +++ b/src/runtime.zig @@ -290,6 +290,8 @@ pub const Runtime = struct { minify_syntax: bool = false, minify_identifiers: bool = false, + set_breakpoint_on_first_line: bool = false, + /// Instead of jsx("div", {}, void 0) /// -> /// { |