Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing typescript project monorepo with yarn and ts 3.0

I've had following react native monorepo structure for a while now

/app
  package.json
/firebase
  /functions
    tsconfig.json
    package.json
/types
  package.json
/ios
/android
tsconfig.json

ios and android folders are respective native code, so we don't really care about them, just included here for nore complete example.

Actual projects are:

app - app logic

firebase/functions - backend logic

types - interfaces of models and stores

each has package.json file with name attribute like @MyCompany/app. This is done for yarn workspaces and allows me to easily import things between projects.

Thus far it was good and now typescript 3 came out and I want to see if there is a way to clean this up?

At the moment I have 2 tsconfig files, I believe I can somehow merge them into one?

Also, is there a way for me to define multiple .d.ts files instead of my types filder and make my model and store interfaces avaliable globally across projects somehow?

If I use typescript 3, do I need to keep yarn workspaces? These projects are not published anywhere, but deployed to different targets

like image 390
Ilja Avatar asked Aug 08 '18 19:08

Ilja


People also ask

What is Monorepo TypeScript?

Monorepos enable you to put all of your apps for a project in a single repository, share code between them, and more! And while this is not a new concept, modern tooling makes it easy to get one setup. In this article, I'll show you how you can setup a monorepo for a Node project using pnpm and TypeScript.

What is lerna for?

Lerna is a tool for managing JavaScript projects with multiple packages. Lerna manages monorepos, which can hold projects containing multiple packages within itself. Monorepos can be challenging to manage because sequential builds and publishing individual packages take a long time.


1 Answers

At the moment I have 2 tsconfig files, I believe I can somehow merge them into one?

You can't specify separate compilation targets from a single tsconfig file I believe, but if you want to lower the amount of repetition across files you can define a master tsconfig.json containing common configurations at the root of your project and have your project-specific tsconfig.jsons extend from the master.

is there a way for me to define multiple .d.ts files instead of my types filder and make my model and store interfaces available globally across projects somehow?

Yes you can certainly define as many .d.ts files as you like anywhere you like and include them either in a tsconfig.json or ad hoc per file using a triple-slash directive:

  • If you want to include them ad-hoc in each file, you'll need to use the triple-slash reference directive and pass the .d.ts filepath as the argument.
  • The easier way is to make them available to the compiler via tsconfig. If you use the "files" or "include" arrays to specify compiler inputs, simply add the relevant .d.ts files to the list. If you use only the "exclude" array, then make sure you don't exclude your .d.ts files.

You'll likely want to keep yarn workspaces around as TS 3.0 has no tooling that can replace workspaces.

Hope this helps.

like image 146
the-jackalope Avatar answered Sep 23 '22 03:09

the-jackalope