()
| 230 | |
| 231 | // Check if running in debug/inspection mode |
| 232 | function isBeingDebugged() { |
| 233 | const isBun = isRunningWithBun(); |
| 234 | |
| 235 | // Check for inspect flags in process arguments (including all variants) |
| 236 | const hasInspectArg = process.execArgv.some(arg => { |
| 237 | if (isBun) { |
| 238 | // Note: Bun has an issue with single-file executables where application arguments |
| 239 | // from process.argv leak into process.execArgv (similar to https://github.com/oven-sh/bun/issues/11673) |
| 240 | // This breaks use of --debug mode if we omit this branch |
| 241 | // We're fine to skip that check, because Bun doesn't support Node.js legacy --debug or --debug-brk flags |
| 242 | return /--inspect(-brk)?/.test(arg); |
| 243 | } else { |
| 244 | // In Node.js, check for both --inspect and legacy --debug flags |
| 245 | return /--inspect(-brk)?|--debug(-brk)?/.test(arg); |
| 246 | } |
| 247 | }); |
| 248 | |
| 249 | // Check if NODE_OPTIONS contains inspect flags |
| 250 | const hasInspectEnv = process.env.NODE_OPTIONS && /--inspect(-brk)?|--debug(-brk)?/.test(process.env.NODE_OPTIONS); |
| 251 | |
| 252 | // Check if inspector is available and active (indicates debugging) |
| 253 | try { |
| 254 | // Dynamic import would be better but is async - use global object instead |
| 255 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 256 | const inspector = (global as any).require('inspector'); |
| 257 | const hasInspectorUrl = !!inspector.url(); |
| 258 | return hasInspectorUrl || hasInspectArg || hasInspectEnv; |
| 259 | } catch { |
| 260 | // Ignore error and fall back to argument detection |
| 261 | return hasInspectArg || hasInspectEnv; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // Exit if we detect node debugging or inspection |
| 266 | if ("external" !== 'ant' && isBeingDebugged()) { |
no test coverage detected