From f62ae50b9fa94363ee6b9c1f5c3dc38b0df5426a Mon Sep 17 00:00:00 2001 From: JF Date: Wed, 20 May 2026 18:17:57 -0400 Subject: [PATCH] fix: include netcoredbg-bridge-core.js in published bundle and correct resolver path (#72) Two layered bugs caused the .NET adapter to ship broken in npm 0.19.0/0.20.0: 1. bundle-cli.js only copied netcoredbg-bridge.js by name, omitting its runtime ESM peer netcoredbg-bridge-core.js (which the spawned bridge process imports). tsup inlines into cli.mjs only; the bridge runs as a separate Node child, so the core file must exist on disk next to the entry. Switch to a recursive .js copy of dist/utils/, matching the convention used for the js-debug and CodeLLDB vendor directories. 2. DotnetDebugAdapter's bundled-NPX candidate path used '..' to resolve out of dist/, but the bundle copies the bridge *inside* dist/. Drop the stray '..' so the path matches the actual bundled layout. Also extend test-bundle.cjs to assert netcoredbg-bridge-core.js is in the bundle, closing the test gap that allowed this to ship. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../adapter-dotnet/src/DotnetDebugAdapter.ts | 4 +-- packages/mcp-debugger/scripts/bundle-cli.js | 25 +++++++++++++------ packages/mcp-debugger/test-bundle.cjs | 6 ++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/adapter-dotnet/src/DotnetDebugAdapter.ts b/packages/adapter-dotnet/src/DotnetDebugAdapter.ts index ee6eee16..213e4695 100644 --- a/packages/adapter-dotnet/src/DotnetDebugAdapter.ts +++ b/packages/adapter-dotnet/src/DotnetDebugAdapter.ts @@ -296,8 +296,8 @@ export class DotnetDebugAdapter extends EventEmitter implements IDebugAdapter { const possiblePaths = [ // Development: running from compiled adapter package dist/ path.resolve(__dirname, 'utils', 'netcoredbg-bridge.js'), - // Bundled NPX distribution (cli.mjs is in dist/, bridge copied alongside) - path.resolve(__dirname, '..', 'packages', 'adapter-dotnet', 'dist', 'utils', 'netcoredbg-bridge.js'), + // Bundled NPX distribution (cli.mjs is in dist/, bridge copied at dist/packages/adapter-dotnet/dist/utils/) + path.resolve(__dirname, 'packages', 'adapter-dotnet', 'dist', 'utils', 'netcoredbg-bridge.js'), // Monorepo source tree fallback path.resolve(__dirname, '..', '..', '..', '..', 'packages', 'adapter-dotnet', 'dist', 'utils', 'netcoredbg-bridge.js'), // CWD-relative fallback diff --git a/packages/mcp-debugger/scripts/bundle-cli.js b/packages/mcp-debugger/scripts/bundle-cli.js index 27308a8e..b7465294 100644 --- a/packages/mcp-debugger/scripts/bundle-cli.js +++ b/packages/mcp-debugger/scripts/bundle-cli.js @@ -211,15 +211,24 @@ async function bundleCLI() { console.warn('Run: pnpm -w -F @debugmcp/adapter-rust run build:adapter'); } - // Copy netcoredbg bridge script for .NET adapter - const bridgeSrc = path.join(repoRoot, 'packages/adapter-dotnet/dist/utils/netcoredbg-bridge.js'); - if (fs.existsSync(bridgeSrc)) { - const bridgeDestDir = path.join(distDir, 'packages', 'adapter-dotnet', 'dist', 'utils'); - fs.mkdirSync(bridgeDestDir, { recursive: true }); - fs.cpSync(bridgeSrc, path.join(bridgeDestDir, 'netcoredbg-bridge.js')); - console.log('Copied netcoredbg bridge script.'); + // Copy .NET adapter runtime utils. The bridge entry imports ./netcoredbg-bridge-core.js + // at runtime in the spawned child Node process, so the core file must be present on + // disk next to the entry — tsup only inlines into cli.mjs, not the spawned worker. + const dotnetUtilsSrc = path.join(repoRoot, 'packages/adapter-dotnet/dist/utils'); + if (fs.existsSync(dotnetUtilsSrc)) { + const dotnetUtilsDest = path.join(distDir, 'packages', 'adapter-dotnet', 'dist', 'utils'); + fs.mkdirSync(dotnetUtilsDest, { recursive: true }); + fs.cpSync(dotnetUtilsSrc, dotnetUtilsDest, { + recursive: true, + filter: (src) => { + const stat = fs.statSync(src); + if (stat.isDirectory()) return true; + return src.endsWith('.js'); + } + }); + console.log('Copied .NET adapter runtime utils (netcoredbg bridge + core).'); } else { - console.warn('Warning: netcoredbg-bridge.js not found; .NET debugging may fail in NPX distribution.'); + console.warn('Warning: packages/adapter-dotnet/dist/utils/ not found; .NET debugging will fail in NPX distribution.'); } // Mirror dist into the package/ directory used by npm pack artifacts. diff --git a/packages/mcp-debugger/test-bundle.cjs b/packages/mcp-debugger/test-bundle.cjs index b084dfdc..6a9ee5c7 100644 --- a/packages/mcp-debugger/test-bundle.cjs +++ b/packages/mcp-debugger/test-bundle.cjs @@ -40,9 +40,13 @@ console.log('Bundle path:', bundlePath); console.log('\nChecking for required runtime assets:'); const requiredAssets = [ { - name: 'netcoredbg bridge (.NET)', + name: 'netcoredbg bridge entry (.NET)', path: 'packages/adapter-dotnet/dist/utils/netcoredbg-bridge.js' }, + { + name: 'netcoredbg bridge core (.NET)', + path: 'packages/adapter-dotnet/dist/utils/netcoredbg-bridge-core.js' + }, { name: 'proxy bundle', path: 'proxy/proxy-bundle.cjs'