allegro / typescript-strict-plugin

Typescript plugin that allows turning on strict mode in specific files or directories.
MIT License
338 stars 29 forks source link

Add support for typescript project in monorepo project. #44

Closed neenjaw closed 2 years ago

neenjaw commented 2 years ago

First of all, this is a great plugin, thanks for creating and maintaining this project.

My organization maintains a monorepo whose code has evolved over a number of years from vanilla js -> FlowJS -> now Typescript. That said we have been working to correct and improve the codebase incrementally as the code is owned over a large number of developers -- this tool fits our use-case exactly to do these improvements incrementally.

So our monorepo structure (with respect to typescript) looks like:

.
├── frontend
│   └── tsconfig.json
└── tsconfig.json

The first level one is used only at this point for tooling resolution (vscode language server, etc), and our build only occurs at the second level tsconfig.

When trying to add --project ./frontend/tsconfig.json I noticed that the plugin was not able to find our typescript project. Doing a bit of code spelunking it appears that the root directory used is the root location for the plugin even if specified within a nested tsconfig.

I forked the project and have a set of minimal changes which would add non-root project support (via the tsc --project flag), wondering if this would be a useful addition to your codebase?

I have the diff of changes here in this branch: https://github.com/allegro/typescript-strict-plugin/compare/master...neenjaw:typescript-strict-plugin:add-non-root-project-support

Usage in action after the proposed changes:

running tsc-strict before update-strict-comments

➜  webapp git:(strictify-ts-plugin) ✗ yarn tsc-strict --project ./frontend/tsconfig.json
# => list of many files with errors.
💥 Found 9008 errors

running update-strict-comments

➜  webapp git:(add-strictify-ts-plugin) yarn update-strict-comments --project ./frontend/tsconfig.json
🎯 Found 7217 strict files
🔧 Updated comments in 2223 files
✨  Done in 37.29s.

running tsc-strict

➜  webapp git:(strictify-ts-plugin) ✗ yarn tsc-strict --project ./frontend/tsconfig.json
🎯 Found 4994 strict files
🎉 All files passed
✨  Done in 35.33s.
KostkaBrukowa commented 2 years ago

Hey! Thanks for the issue! You can make a PR and we will test it, but at a first glance it looks cool!

neenjaw commented 2 years ago

Hey @KostkaBrukowa!

I have opened a PR at #45 as requested. Looking forward to your review and testing. If there is anything needed, let me know. 😄