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

Nested tsconfig file interferes with plugin #36

Closed BrettMerri closed 2 years ago

BrettMerri commented 2 years ago

I'm using yarn workspaces, and in each package I have my own tsconfig that extends the root tsconfig. The issue is, this plugin doesn't seem to work properly regardless if I add the plugin to the nested tsconfig, or the root tsconfig.

Adding plugin to nested tsconfig

When adding the plugin to the nested tsconfig and using the paths option, the paths resolve differently between the plugin and the CLI.

The issue here, I believe, is that the way I'm invoking tsc-strict is via the yarn workspace which executes it inside the nested directory, whereas the plugin is taking the entire project into account. So the paths resolve differently.

Adding plugin to root tsconfig

To solve the above issue, I moved the plugin from the nested tsconfig to the root tsconfig instead and started invoking tsc-strict at the root instead. But the nested tsconfig still seems to be interfering. The plugin simply does not work unless the nested tsconfig is removed/renamed, even though that nested tsconfig extends the root config. Is it that the plugin doesn't properly grab the paths option from the extended tsconfig?

Also, not sure if related, but running tsc-strict, files are found but they all "pass" which is definitely wrong. When the plugin was in the nested tsconfig, it found plenty of strict mode errors. Removing/renaming the nested tsconfig does not fix this so not sure what is going on here.

kamkry commented 2 years ago

Hey, thanks for reporting the issue! The problem was caused by resolving the relative paths by using process.cwd() which in the case of the plugin was always set to /, I've already got a fix for that.

When it comes to specifying the plugin config in the root tsconfig that other configs extend, you have to keep in mind that extended configs copy properties from the root and modify it under the hood, so I would use that only if you want to specify a certain directory in every package you use. I recommend specifying it explicitly in each package though to avoid future confusions.

ghost commented 2 years ago

Hello! I'm very keen on trying this plugin in our production codebase but I think this issue is also affecting us. Looking forward to your PR merged