Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how would tsc --moduleFormatDetection affect tshy? #34

Closed
andrewbranch opened this issue Nov 20, 2023 · 1 comment
Closed

Comments

@andrewbranch
Copy link

I’m starting to dive into prototyping some stuff for microsoft/TypeScript#55221. If TypeScript had support for these options, would tshy leverage any of them? Would you have written tshy if they had already existed?

  • the ability to determine module format by reading package.jsons starting from the outDir path, not the input file path
  • the ability to determine module format by assuming all .ts/.js/.d.ts are ESM
  • the ability to determine module format by assuming all .ts/.js/.d.ts are CJS

Is there a different module format detection algorithm along these lines that would be useful for building libraries with or without tshy?

@isaacs
Copy link
Owner

isaacs commented Nov 21, 2023

  • Reading from the outDir path does make more sense, I think, whether using tshy or not, since that's where it actually matters. In most cases, presumably they're the same thing (the nearest package.json to both ./src and ./dist will typically be ./package.json), but it is more technically correct in every case I can think of, and would simplify tshy's job considerably.
  • Ability to assume that all .ts/.js/.d.ts are ESM or CJS would be helpful for tshy. This is actually how tshy's predecessors worked, where I'd do "module":"commonjs" or "module": "esnext" with "moduleResolution": "NodeNext". But it would have to be limited to a given source directory. Eg, I wouldn't want ./node_modules/foo/index.d.ts to be interpreted as ESM/CJS just because I'm interpreting ./src in some overridden way. If it was determined by the outDir, though, I wouldn't have to do that, I'd just have to write the dist package.json before calling tsc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants