berry icon indicating copy to clipboard operation
berry copied to clipboard

feat(plugin-typescript): automatically setup project references

Open merceyz opened this issue 4 years ago • 14 comments
trafficstars

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

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

merceyz avatar Jan 06 '21 13:01 merceyz

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

andreialecu avatar Jan 06 '21 14:01 andreialecu

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 avatar Jan 13 '21 20:01 merceyz

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

SimenB avatar Jan 13 '21 22:01 SimenB

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

SimenB avatar Feb 19 '21 07:02 SimenB

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

ikibalnyi avatar May 01 '21 12:05 ikibalnyi

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

milesj avatar May 01 '21 19:05 milesj

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

schickling avatar Aug 12 '21 15:08 schickling

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
  • ...

schickling avatar Sep 06 '21 14:09 schickling

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

SimenB avatar Sep 06 '21 14:09 SimenB

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.

schickling avatar Sep 06 '21 14:09 schickling

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

Ref: https://github.com/microsoft/TypeScript/issues/33685

andreialecu avatar Nov 20 '21 17:11 andreialecu

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.

jdanil avatar Nov 21 '21 10:11 jdanil

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

andymac4182 avatar Feb 01 '24 22:02 andymac4182

Moonrepo

On Thu, 1 Feb 2024 at 23:49, Andrew McClenaghan @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/yarnpkg/berry/pull/2338#issuecomment-1922425581, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGTCZG3OTNZM5HWVDHVNT3YRQLWNAVCNFSM4VXR2H62U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJSGI2DENJVHAYQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

elmpp avatar Feb 01 '24 22:02 elmpp