microsoft / microsoft/TypeScript

Optimal TS monorepos: how to handle project references when projects opt out of composite within dependency chain

Aperta
#59,727 4 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@sheetalkamat ci sta già lavorando.

Dal 6/9/2024.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

project references
no output

🕗 Version & Regression Information

N/A

⏯ Playground Link

N/A

💻 Code
// Your code here
🙁 Actual behavior

Please see full description, repro and video walkthrough

🙂 Expected behavior

Please see full description, repro and video walkthrough

Additional information about the issue

I am reporting this as an issue because @jakebailey advised me that that would make sense for any time a Debug Error is reached in TS, but also to get formal guidance from the TS Team on finalizing our new TypeScript plugin for Nx.

As discussed in our sync between our teams a couple of months ago, we are building a new mechanism to sync Nx project graph (derived from package.json files and import and export statements) automatically to configuration files on disk. This is a generic mechanism, but in the context of TS, this applies to syncing project references in tsconfig.json files.

This should allow us to keep Nx out of the way of tsc where appropriate (tsc will be directly executed by Nx behind the scenes when using nx typecheck my-ts-proj or nx build my-ts-proj for example) and still allow users to run raw tsc if they wish because all the relevant config will live on disk and be up to date thanks to Nx.

The syncing mechanism is working really well already for repo's which can fully stick to composite: true throughout the codebase, but we have already run into one case on the https://github.com/typescript-eslint/typescript-eslint (where @jakebailey and @sheetalkamat kindly help out) where a couple of projects needed to opt out of composite: true and not emit declaration files at all.

As explained in detail in attached loom covering the reproduction repo, we would like some advice on how we should attempt to handle cases like this in our syncing logic.

The super brief summary of the issue causing it to hit the Debug Failure is:

  • Projects: A -> B -> C
  • B is opting out of composite
  • The root solution file can happily reference all 3 projects as hoped, despite the composite opt out of B
  • We want to be able to typecheck A, B and C
  • tsc -b --emitDeclarationOnly is used for typechecking (intentionally kept distinct from building with tsc, producing JS artifacts)
  • When typechecking the whole repo, or typechecking just A, we hit the Debug failure because of B not having any outputs before proceeding onto A

🎥 Context and issue reproduction: https://www.loom.com/share/84a7098b3d1e4a819bd598ad7fc3ae7f

🔗 Reproduction repo: https://github.com/JamesHenry/tsc-composite-false-repro

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.