privatenumber / tsx

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

Support `customConditions` in `tsconfig.json` #574

Open colinhacks opened 3 months ago

colinhacks commented 3 months ago

Acknowledgements

Minimal reproduction URL

This is actually a feature request sorry :(

It would be cool if tsx automatically read customConditions from tsconfig.json and passed it to node using --conditions.

Problem & expected behavior (under 200 words)

"Repro" is https://github.com/colinhacks/live-typescript-monorepo

gh repo clone https://github.com/colinhacks/live-typescript-monorepo
cd live-typescript-monorepo/custom-conditions
pnpm i
cd packages/pkg-b
tsx index.ts # module resolution error
tsx --conditions source index.ts # works!

I'm using custom export conditions in my TypeScript monorepo (described in more detail here). Since tsconfig.json already supports the customConditions compiler option for specifying custom export conditions, it would be cool if tsx could read that and incorporate it into module resolution automatically.

Bugs are expected to be fixed by those affected by it

Compensating engineering work financially will speed up resolution

privatenumber commented 3 months ago

Feature requests are reserved for sponsors, but I'll accept this for you @colinhacks!

This should be trivial to support for ESM, but it may be challenging with the CJS resolver as it doesn't seem to offer a way to accept conditions: https://github.com/nodejs/node/blob/main/lib/internal/modules/cjs/loader.js#L1126

DASPRiD commented 3 months ago

I just ran into this as well in a mono repo. For now you can work around this with the following command line instead:

tsx -C development your-script.ts