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

feat(plugin-typescript): automatically setup project references #2338

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

merceyz
Copy link
Member

@merceyz merceyz commented Jan 6, 2021

What's the problem this PR addresses?

Proof of concept of automatically setting up project references based on dependencies
https://www.typescriptlang.org/docs/handbook/project-references.html

How did you fix it?

Checklist

  • I have read the Contributing Guide.
  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@andreialecu
Copy link
Contributor

Just leaving a note here that tsconfig.json format is JSON+Comments. Seems like the current implementation doesn't handle that.

@merceyz merceyz changed the title feat(typescript): automatically setup typescript references feat(plugin-typescript): automatically setup typescript references Jan 6, 2021
@merceyz merceyz force-pushed the merceyz/typescript-references branch from 02e4a84 to fa02924 Compare January 12, 2021 21:46
@merceyz
Copy link
Member Author

merceyz commented Jan 13, 2021

cc @SimenB since Jest (https://github.com/facebook/jest) is using project references and might find this useful and/or have some thoughts on how they could use it

@merceyz merceyz changed the title feat(plugin-typescript): automatically setup typescript references feat(plugin-typescript): automatically setup project references Jan 13, 2021
@SimenB
Copy link

SimenB commented Jan 13, 2021

Woo! 🎉 I recently did jestjs/jest#10941 since we had messed up our references, having yarn handle it would be awesome. Sorta relates to microsoft/TypeScript#25376, but solves it from the package manager side instead of from TS

@merceyz merceyz force-pushed the merceyz/typescript-references branch 2 times, most recently from 9a750b2 to 6767f4f Compare February 5, 2021 17:17
@SimenB
Copy link

SimenB commented Feb 19, 2021

You probably found it while researching, but if not - we use https://github.com/azu/monorepo-utils/tree/master/packages/%40monorepo-utils/workspaces-to-typescript-project-references at work. It properly handles comments as was mentioned above here

@ikibalnyi
Copy link

Hi guys, what's the status of this feature? I would really love to make it work, is there any help needed?

@milesj
Copy link

milesj commented May 1, 2021

Not a yarn plugin, but I did something similar here: https://beemo.dev/docs/drivers/typescript#sync-project-refs

Would be nice if it was supported by yarn! Here's the actual code: https://github.com/beemojs/beemo/blob/master/packages/driver-typescript/src/commands/syncProjectRefs.ts

@schickling
Copy link

What's missing for this to be merged @merceyz @arcanis ?

@merceyz merceyz force-pushed the merceyz/typescript-references branch from e769f2b to e2c957d Compare August 18, 2021 19:13
@schickling
Copy link

schickling commented Sep 6, 2021

Another feature I'd love to see as part of this is the option to opt-in/opt-out from some packages. Is this maybe already possible? @merceyz?

Use cases:

  • If a sub-package doesn't use TS
  • ...

@SimenB
Copy link

SimenB commented Sep 6, 2021

I'd assume it only sets up references if the module referenced has a tsconfig.json file?

@schickling
Copy link

I'd assume it only sets up references if the module referenced has a tsconfig.json file?

Nope, seems to also create new ones if not existing. But I'd like to exclude even packages beyond that case.

@andreialecu
Copy link
Contributor

One thing to keep in mind is that typescript doesn't support circular references, which are quite easy to create when using workspaces.

Ref: microsoft/TypeScript#33685

@jdanil
Copy link
Contributor

jdanil commented Nov 21, 2021

If its useful, I did some testing with this today. I have a couple thoughts which may be worth consideration.

  • References are currently added for all referenced workspaces, regardless of if they are typescript projects or not (e.g. packages for shared configs like eslint need not be added to tsconfig references). This may be addressed by checking the referenced workspace to see if it contains a tsconfig.json.
  • tsconfigs are created for workspaces that had no tsconfig.json previously. This issue would mostly be addressed by resolving the above issue, but may be a good early exit check.
  • It may be worth exposing a configuration option to specify the tsconfig.json filename, as it can be customised (e.g. tsc --project tsconfig.custom.json).

FYI found some prior art here https://github.com/Dcard/yarn-plugins/tree/master/packages/tsconfig-references, although this plugin uses the "after workspace addition/removal" hooks. Probably "after all installed" makes more sense as it will update references when dependencies change, in addition to workspace addition/removal.

@andymac4182
Copy link

Any chance this could get picked back up? It would be super helpful :)

@elmpp
Copy link
Contributor

elmpp commented Feb 1, 2024 via email

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

Successfully merging this pull request may close these issues.

9 participants