jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.26k stars 508 forks source link

Monorepo Jest Type Definition #696

Closed Oreoz closed 4 years ago

Oreoz commented 4 years ago

Current Behavior

When you bootstrap a package using TSDX inside a Lerna monorepo, if you open the new package directly code mono/packages/tsdx type definitions of Jest load correctly.

However, when you open the monorepo directly code mono and navigate to a test inside the sub package, VSCode lights up like a Christmas tree.

Desired Behavior

If possible, it would be great to have type definitions when opening the monorepo.

Suggested Solution

I'm terrible at TypeScript bootstrapping, hence why I used TSDX.

Perhaps (most likely) it's something easily fixable on my end, but since everything else worked out of the box, it would be great if that worked too!

Who does this impact? Who is this for?

Monorepo users mainly.

Describe alternatives you've considered

I've tried tweaking the tsconfig.json and creating a new one only for my tests, but didn't get it to work properly.

Only alternative I see now is opening VSCode directly at my package instead of the monorepo, but that doesn't quite fit my workflow most of the time.

Cheers!

agilgur5 commented 4 years ago

So if you only install tsdx for one package, @types/jest is also only in that one package's node_modules. It's not in your top-level's node_modules, so your test globals aren't detected or typed. You didn't install TSDX at monorepo root, you installed it at package level, so TSDX and any features therein are only present in the specific package you installed it for.

That isn't a bug in TSDX and is more a Lerna support question or a general Node support question. You can install @types/jest at the top-level if you want, if you have Jest set-up there already. Or you can hoist TSDX to the top-level if you want to use it for multiple packages etc. Could also use something like jest-without-globals to explicitly import your Jest globals instead. Lots of options

There's an existing (very popular) issue for a monorepo template already: #122 (I've never used a Lerna monorepo so it's not my realm of expertise; Jared was going to add support for it but never did 😕). And there's also a label for everything monorepo-related. Please make sure to search the issues before reporting a new one.