privatenumber / tsx

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

custom tsconfig location appears to be silently ignored when it's outside of the source folder ancestry #467

Open moredip opened 9 months ago

moredip commented 9 months ago

Acknowledgements

Minimal reproduction URL

https://stackblitz.com/edit/node-49eqfc?file=README.md

Version

4.7.0

Node.js version

18.18.0

Package manager

pnpm

Operating system

Linux

Problem & Expected behavior

TL;DR

If I give tsx a tsconfig path that's a direct ancestor of the source directory then it is used as expected, but if I give it a tsconfig that's in a sibling directory then it appears to be silently ignored.

Details

I'm trying to use tsx to dynamically import jsx rendered using nano-jsx rather than React. Doing that requires configuring typescript's jsxImportSource compiler option, which in turn means providing a tsconfig.json file to tsx. For reasons that are a bit complex to get into, I sometimes need to keep that tsconfig.json outside of the folder heirarchy of the source I'm executing (my program is operating on externally provided files and I don't have permissions to add a tsconfig.json there).

What I've discovered is that tsx appears to silently ignores the compiler options of a tsconfig.json file if that file is outside of the source files' directory heirarchy.

Contributions

busybox11 commented 9 months ago

You'd probably need to use tsconfig's include directive for esbuild to process the source code. It looks like it's not present anywhere in your minimal reproduction repo.

moredip commented 8 months ago

You'd probably need to use tsconfig's include directive for esbuild to process the source code. It looks like it's not present anywhere in your minimal reproduction repo.

Thanks @busybox11, this worked! I don't really understand why though.

I updated elsewhere/_tsconfig.json as follows:

  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "nano-jsx/lib"
  },
  "include": ["../subdir/**/*"]
}

and now things are working - nano-jsx is being used instead of React - but I don't understand why adding that include directive changed things