From 7c47074652790e8225bb9c0d3123fc92e75d3695 Mon Sep 17 00:00:00 2001 From: Charles Xu <6831013+char8x@users.noreply.github.com> Date: Sun, 27 Oct 2024 07:23:50 +0800 Subject: [PATCH] fix: generate sourcesContent when Node.js debugger is enabled (#670) --- src/utils/transform/get-esbuild-options.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils/transform/get-esbuild-options.ts b/src/utils/transform/get-esbuild-options.ts index a9d6d44c4..a14771ce4 100644 --- a/src/utils/transform/get-esbuild-options.ts +++ b/src/utils/transform/get-esbuild-options.ts @@ -10,6 +10,12 @@ export const baseConfig = Object.freeze({ loader: 'default', }); +// match Node.js debugger flags +// https://nodejs.org/api/cli.html#--inspecthostport +const NODE_DEBUGGER_FLAG_REGEX = /^--inspect(?:-brk|-port|-publish-uid|-wait)?(?:=|$)/; + +const isNodeDebuggerEnabled = process.execArgv.some(flag => NODE_DEBUGGER_FLAG_REGEX.test(flag)); + export const cacheConfig = { ...baseConfig, @@ -17,11 +23,11 @@ export const cacheConfig = { /** * Improve performance by only generating sourcesContent - * when V8 coverage is enabled + * when V8 coverage is enabled or Node.js debugger is enabled * * https://esbuild.github.io/api/#sources-content */ - sourcesContent: Boolean(process.env.NODE_V8_COVERAGE), + sourcesContent: Boolean(process.env.NODE_V8_COVERAGE) || isNodeDebuggerEnabled, /** * Smaller output for cache and marginal performance improvement: