Skip to content

Commit 3c1d051

Browse files
committed
fix: detect the Node inspector enabled via NODE_OPTIONS
## Problem The transform cache enables `sourcesContent` when Node's inspector is running so debuggers can show original TypeScript. Detection scanned only `process.execArgv` with a hand-maintained regex, so it missed the inspector when enabled through `NODE_OPTIONS` (for example, `NODE_OPTIONS='--inspect' tsx app.ts`) and did not cover `--inspect-brk-node`. It also matched `--inspect-port` and `--inspect-publish-uid`, which configure but do not enable the inspector. ## Changes Replace the regex scan with `getOptionValue(inspectFlag)` from `get-option-value@^1.0.0`. This reads both `NODE_OPTIONS` and `execArgv` and applies Node's implications, so `--inspect`, `--inspect-brk`, `--inspect-wait`, and `--inspect-brk-node` all register as the inspector being enabled. Source content is now emitted whenever the inspector is on, however it was enabled. get-option-value is a bundled devDependency, so pkgroll inlines the relevant flag and scanner while tsx keeps esbuild as its only runtime dependency.
1 parent 40380a4 commit 3c1d051

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"fs-fixture": "^2.14.0",
9595
"fs-require": "^1.6.0",
9696
"get-node": "^15.0.4",
97+
"get-option-value": "^1.0.0",
9798
"get-tsconfig": "5.0.0-beta.5",
9899
"is-glob": "^4.0.3",
99100
"kolorist": "^1.8.0",

‎pnpm-lock.yaml‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/utils/transform/get-esbuild-options.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import path from 'node:path';
2+
import { getOptionValue } from 'get-option-value';
3+
import { inspectFlag } from 'get-option-value/flags';
24
import type { TransformOptions, TransformResult } from 'esbuild';
35
import type { SourceMap } from '@ampproject/remapping';
46

@@ -10,11 +12,11 @@ export const baseConfig = Object.freeze({
1012
loader: 'default',
1113
});
1214

13-
// match Node.js debugger flags
14-
// https://nodejs.org/api/cli.html#--inspecthostport
15-
const NODE_DEBUGGER_FLAG_REGEX = /^--inspect(?:-brk|-port|-publish-uid|-wait)?(?:=|$)/;
16-
17-
const isNodeDebuggerEnabled = process.execArgv.some(flag => NODE_DEBUGGER_FLAG_REGEX.test(flag));
15+
// Whether Node's inspector is enabled — via --inspect / --inspect-brk /
16+
// --inspect-wait, on the CLI or in NODE_OPTIONS. get-option-value mirrors
17+
// Node's own resolution (implications + NODE_OPTIONS), which a manual
18+
// process.execArgv scan misses.
19+
const isNodeDebuggerEnabled = getOptionValue(inspectFlag);
1820

1921
export const cacheConfig = {
2022
...baseConfig,

0 commit comments

Comments
 (0)