Repository navigation
support globs in tsconfig.json files property (or just file/directory exclusions) #1927
Description
Activity
We certainly talked about this for awhile. See Anders' comment here for one large concern: #1692 (comment)
Yes, I've read that comment. Unfortunately, for larger and more complicated projects, the lack of these glob and exclusion patterns makes it impossible to use tsconfig.json at all. If editors support tsconfig.json, we would end up having to disable it due to various errors in mismatched configuration between e2e, unit tests, and the application. And, if the editor uses tsconfig.json to configure compile-on-save and auto-complete in a standard way (and doesn't support a way to override this in a custom project file format, or extension to tsconfig.json as is the case with atom-typescript for example), then we've lost all of that functionality as well.
Globs and exclusion patterns are just how large typescript projects are made managable. We manage it now with build tools like grunt and gulp which support globs and exclusions, but so far the editors and IDEs haven't been configurable in the same way, leading to messy workarounds. For example, in visual studio we have to exclude all the end to end tests from the main app project so it doesn't parse them and complain about duplicate identifiers. We then have a separate visual studio project which just includes the end to end tests. We should be doing the same thing with unit tests, but we decided not having jasmine type declarations visible from the application code was not worth creating a separate unit test project. I would rather edit files in the project all at once, like I would do in Sublime or Atom or Brackets.
MiyaGrace (@JeroMiya), perhaps the real problem here is how the projects are organised. I would consider moving the tests (both unit and end-to-end) to a separate project(s). IMO it's a better practice to keep tests and application code separate.
Reacted by TabithaThere are many style guides out there advocating for grouping files by feature. We've tried it both ways and find that grouping things by feature instead of by file type helps you be more productive, especially for larger projects with hundreds of features. You tend to work on a particular feature at a time, and it's a real pain to track down all the files related to that feature when they're spread out across multiple root directories. This way also encourages developers to write unit and end to end tests at the same time as changes to the code. I highly recommend it over keeping test code separate from the application code.
Regardless, as a compiler, TypeScript should not be opinionated about project file organization.
Reacted by Owen Buckley, Quack, Kenneth Lynne, mafo5, Hraban, Karl Gustav, Stephan Beal, Nikita Kotliarov, Guntars Ašmanis-Graham, Gábor IMRE and 19 moreFair enough. We tried the grouping files by feature before moving the test cases out. Having test code in the same place as application code made it difficult to prototype features, because a lot of time was spent fixing compilation errors in the test cases.
FWIW atom-typescript supports
filesGlobas an optional extension tofiles. See spec.Reacted by Lukas, Gábor IMRE, Nik Handyman and IAMtheIAM"filesGlob": [ "./**/*.ts", "!node_modules/**/*.ts" ]
That looks like a nice feature, because it actually plays well with "files". I wonder what the objection from the TS team is to including this.
Perhaps the argument is: One cannot post the
tsconfigto someone else to say "Hey, here's a description of all the files in my project".Edit (after morning tea)
quote from Anders Hejlsberg (@ahejlsberg)
(1) Let me drop an empty tsconfig.json file in a directory and have everything in there be a project, and (2) let me describe the exact list of files I want included. The current design covers both with a minimum of complexity. That said, I can certainly see how an "exclude" list could be useful, although I suspect we'd then need globbing as well, so the level of complexity goes up. I definitely don't want this growing into an alternate build system. The intent is more to offer tools (e.g. editors) a simple and deterministic way to decide what the compilation context for a particular file is.
Just a note: whenever atom-typescript reads a file with
filesGlobit expands thefilesin 'tsconfig.json' file so that people that are not using atom-ts will still get the correct list of files.+1
Globs are so common in use now. There could be .ts files in bower components under my project which have already been compiled to js and may have been done with a different release of TS so I wouldn't want them recompiling. I guess exclusion would handle the case but it just seems like once you support globs you won't need anything else.I think leaving this up to an IDE to edit, like atom-typescript, is a bad idea. You're basically asking every IDE to implement the logic to keep the tsconfig.json file up to date.
I'm in the same case as MiyaGrace (@JeroMiya) , complexe project (e2e, unit test and project code). The outDir option is really good to this kind of project so we can cleanly separate our TS code from the produce code : no accidental JS code modification by the team for example. And this glob option is almost mandatory for our kind of project due the number of file. Thanks to Gulp, we can handle this point but it can be really good to have this glob supported by the tscong file
panuhorsmalahti commented
on Apr 7, 2015 More actionsGlobs are definitely needed. I don't see how I could manage the complex, multi-package TypeScript-based platform at work without globbing. Referencing every file by hand would be madness and require large amount of unnecessary work.
Globbing is especially useful when working with npm. I can depend on a npm package (which includes the type definitions), and then glob them in without knowing about the internals of that package.
Using the current setup in our project I can simply build package A, which consists of multiple modules, then require it from package B and glob the type definitions without any manual work even if the file structure of package A changes.
In theory the package A could output a single type definition file, but this is not supported by TypeScript, as each module of package A will create it's on .d.ts file. I already had to do a bit magic by writing a sort of "compiler" to make the .d.ts files ambient external declaration files automatically.
Anders Hejlsberg (@ahejlsberg), Basarat Ali Syed (@basarat), a few thoughts on this.
One major issue with, .net projects in general, is with source control systems and project files. By inserting a file reference into your project file every time a new file is added to a folder you end up with additional and unnecessary churn in your repository.
On larger projects with multiple teams working on them you constantly end up with conflicting changes to files like tsconfig. As such in addition to unnecessary file churn we now have additional labor to manually merge changes to a file that could be automatically handled.
As such in addition to unnecessary file churn we now have additional labor to manually merge changes to a file that could be automatically handled.
Agreed and would be great to have
filesGlobsupported.FWIW If its a merge commit just delete the
filessection and let atom-typescript regenerate it for you. If its a rebase I chose "keep both" at each level ;). YMMV. Definitely needs glob support.We would be open to taking a PR for excludes folders.
Our problem with globs is the complexity to support it, and we usually do not like to take dependencies on other packages as it limits our interoperability and system-independence. Having said so I think it is an important feature and indead does add value. Would be open to proposals here.
87 remaining items
Chen Tao (@jagt) i haven't heard anything about use of
/// <reference path="<path to .d.ts>"being deprecated and in fact you can see that's what i ended up using in https://github.com/myusrn/acxwithng2 and https://github.com/myusrn/dnxwithng2 main.ts files to allow me to use tsconfig.json with just excludes and still retain support for d.ts sources that exist in some of the excluded folders.+1, its already a year later 😞
Reacted by Martin H. Andersen, Ash Blue, Gábor IMRE, Ken Rimple, Antoine, Jacques Lareau, Dušan Roštár, Johannes Schickling, Brett, Andrew Smith and 6 more+1
trickpattyFH20 Please use reactions now, instead of +1 comments.
Reacted by my usrn, Oskar Karlsson, Jacques Lareau, Lukas, d-ph, Julien Roncaglia, Nathaniel Whiteinge, Dušan Roštár, Saul Shanabrook, Brett and 9 moreThis would also be useful for avoiding ENOENT errors when using an editor that writes and removes backup files fairly often. I find it tripping over /.#file.ts which is often used by emacs.
For anyone interested in a workaround until
filesGlobis added totsconfig.json:I've published typescript-with-globs that you can install side-by-side with
typescriptand you can begin usingfilesGlobintsconfig.json.After installing, you can use
tscg(note the extrag) and it will first resolve the globs fromfilesGlobto thefilessection and then proceed to invoketsc.Shouldn't this be added to the
TypeScript 2.0milestone (along with the PRs)?Reacted by Michael Klein- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Jun 22, 2016 should be addressed by #8841.
Reacted by Glen, Angel D. Munoz, Michael Marvick, Kitson Kelly, Julien Roncaglia, Joel Hernández, Martin Johns, Guillaume Clochard, Victor Costan, Ondrej Slinták and 5 moreGreat, in case anyone wonder, the property for including files as well as globs is "include", like this
"include": [ "./app/**/*.ts" ],Reacted by kspdrgn and Luiz MachadoReacted by Luiz Machado- locked and limited conversation to collaborators
on Jun 18, 2018
An extension to #1692
Our ts project uses a grunt-based build system, with bower dependencies for the application and node_modules for build-tools. We will need the ability to exclude node_modules and bower_components from the build by default (unless files are referenced via /// ).
This causes an issue: we have end-to-end tests running in protractor, as well as unit tests running in jasmine, and unless we have the ability to exclude node_modules and bower_components, both will be parsed and we'll get duplicate definition errors.
In Visual Studio today, this is why we need to exclude both bower_components and node_modules from the project, because visual studio automatically parses all files in the project with no way to exclude them except to keep them out of the project altogether.
A number of third party tools have started to support tsconfig.json, and one thing I've noticed is that most of them support some sort of extension to tsconfig.json that supports file globs. I propose we just add support into the spec for file globs. For the version of typescript on npm, we can just depend on the appropriate file glob libraries in the npm ecosystem. For the Visual Studio embedded version of TypeScript, just embed the glob libraries that are needed statically in the installation.
As a fallback, if the notion of including a third party glob library is a non-starter, then the following fallback supporting a subset of the glob patterns would solve our problem at least partially.
Fallback:
Support both file and directory inclusions and exclusions in the files property: