privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.8k stars 154 forks source link

fix: generate sourcesContent when Node.js debugger is enabled #670

Closed char8x closed 1 month ago

char8x commented 1 month ago

This PR attempts to fix the issue described here: #661

If make changes to tsx/src/run.ts, the --inspect flag will be confused with the flag of the custom program.

// run command
./dist/cli.mjs --inspect temp/test.ts --inspect-xxx

// tsx/src/run.ts
// `console.log(argv)`
[ '--inspect', 'temp/test.ts', '--inspect-xxx' ]

But in src/utils/transform/get-esbuild-options.ts, process.execArgv doesn't have this problem

// run command
./dist/cli.mjs --inspect temp/test.ts --inspect-xxx

// src/utils/transform/get-esbuild-options.ts
// `console.log(process.execArgv)`
[
  '--require',
  '/home/debian/tsx/dist/preflight.cjs',
  '--import',
  'file:///home/debian/tsx/dist/loader.mjs',
  '--inspect'
]
privatenumber commented 1 month ago

Since we can't really add tests for this, can you confirm this fixes your problem?

I published a prerelease here:

npm i 'privatenumber/tsx#npm/fix-node-debugger'

or

npx 'privatenumber/tsx#npm/fix-node-debugger' file.ts # same as `npx tsx file.ts`
char8x commented 1 month ago

I checked it out and it works.

privatenumber commented 1 month ago

Thanks for the PR @char8x !

privatenumber commented 1 month ago

This issue is now resolved in v4.19.2.

If you're able to, your sponsorship would be very much appreciated.