Everlaw / nbts

NetBeans TypeScript editor plugin
283 stars 46 forks source link

Files at project root #38

Closed pandachris closed 7 years ago

pandachris commented 8 years ago

This enhancement allows TS project files tsconfig.json, node_modules, typings/ and typings.json to appear within a project, but above the context source root. This addresses issue #21, plus more.

My motivation was to eliminate error badges on my project caused by 3rd party libs in node_modules. I don't want to see those and they obscure errors I want to see in my own source.

I added a TsExtUtil class that scans a project for certain TS-related files/folders. When found, the utility adds these files to the nodejs process using a modified path that makes them appear to be within the source context. Code completion and source navigation continue to work. The TsExtUtil is integrated minimally into TsIndexerFactory.

For tsconfig.json, the snapshot content is altered so that the compilerOptions.outDir and compilerOptions.sourceRoot are accurate according to the altered path. The original tsconfig.json is not modified, so running tsc from the command line should still work.

External files can be placed at any level above the context source root, up to the project root. They must be adjacent to the context's path hierarchy (i.e. ../, ../../, ../../../, etc.) -- subdirectories are not searched. I believe this is consistent with nodejs convention.

jeffrey-easyesi commented 8 years ago

This seems like an extremely complicated way to solve the problem of unwanted error checking in third-party code. nbts has supported the files and exclude properties in tsconfig.json since v1.7.3.1, so all you have to do is "exclude": ["node_modules"]. (Excluded files can still be referenced explicitly, using an import or a /// <reference ...>.)

In TS 1.8, if tsconfig.json has neither a files nor exclude property, then node_modules is excluded by default, so you shouldn't have to do anything.

pandachris commented 8 years ago

Thanks for taking the time to review and respond!

I don't know if I would say "extremely" complicated... :) It's 1 new class and very little else was touched. But I know what you're saying. I would have preferred something else.

The problem is not specifically nbts: I already have node_modules in my tsconfig exclude section. When I put node_modules in a source folder then other NB modules examine it also. The complaints are not about the .ts files but about .js, .json, etc. The only way I could find to stop that was to move node_modules up a level out of the source folder.

I also considered the fact that the tsc compiler and the NB NodeJS module both support node_modules outside of the source folder. It seems like something a TS plugin should be able to do.

But honestly, the thing that matters the most for me is to eliminate those error badges. If there is an easier way that doesn't compromise something else, I'm up for it!

Best regards,

Chris

jeffrey-easyesi commented 8 years ago

In the latest release (1.8.10.0) you can now reference or import .ts files that are outside the source root or in an ignored directory.

Chris2011 commented 7 years ago

PR can be closed, or?

pandachris commented 7 years ago

Yes, closed.