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

feat(esm): support custom conditions #675

Open colinlienard opened 1 week ago

colinlienard commented 1 week ago

Add support for customConditions in ESM.

For example, if a tsconfig contains this:

{
    "compilerOptions": {
        "customConditions": ["source"],
    }
}

passing the condition as an arg to the CLI would not be needed anymore:

- tsx --conditions source src
+ tsx src

But this is only for ESM as explained here: https://github.com/privatenumber/tsx/issues/574#issuecomment-2156442343

Related to #574

privatenumber commented 1 week ago

Thanks for the PR

This is blocked until we add condition support to the CJS resolver though. Since tsx aims to consolidate ESM and CJS, we want to avoid introducing discrepancies between them.

colinlienard commented 1 week ago

I tried adding support for CJS, but it seems quite challenging. Do you have any ideas on how to make it work? @privatenumber