- 
                Notifications
    You must be signed in to change notification settings 
- Fork 135
TSD Future #150
Description
Hey everyone!
I'm going to be jumping into this project and seeing what we can do to improve the sharing of TypeScript definitions. Development isn't (quite) going to happen instantly, so I wanted to submit a short issue that describes some of my immediate goals and see if there are other ideas of what they want to see moving forward. Feel free to create new issues with feature requests and we can label them for TSD Future.
Goal
The goal of TSD future is to seamlessly support any TypeScript definition files, from any source. By default, you should still be able to search the definitely typed repository and install from there. However, more focus will be trained onto support independent definitions, specifically ones bundled with modules. This is a primary focus because as the ecosystem grows, a single repo is going to be a challenge to scale and I would like to give more power to module authors.
Currently TSD (tsd@next) supports a feature called tsd link. It's a great first step, but comes with many drawbacks - mostly because it's just a really simple path copy and paste. It needs a bit more to be useful. In the future, you'll be able to tsd install and it will look up your dependencies via package.json or bower.json and it will install definition files. However, it'll then recursively resolve dependencies from there. Any dependencies the module has likely have their own definition files that they're depending on.
This will make tsd.d.ts less editor friendly, but the goal is to avoid having to manually edit this file and check in dependencies any more. Just as you don't check in your node_modules or bower_components, you shouldn't have to check in your type dependencies. As we resolve dependencies down the tree, if we encounter tsd.json files they'll also factor into the recursive resolution. This is important since not every module can or will adapt over night. If there are conflicts between sub-dependency definitions, we will provide a dialog for selecting the version that should be used (resulting in that flat structure we wanted, a la bower).
Doing this, we'll pull closer to the seamless usage of definition files. Similarly, the commands will be pulled closer to npm and bower. All that will be required from now on is tsd install. To remove old dependencies, you can tsd prune. Finally, tsd uninstall will remove a dependency from tsd.json. The tsd.d.ts file will always be kept in sync with hard module dependencies and the tsd.json.
To support all this, I think some changes to tsd.json are required. I'm going to change this last (avoid it if I can), but I think it's too tied to the one source approach which doesn't scale. From now on, manual definition file installations tsd install <source> should create an entry like package.json with "name": "source", where source can be any file/url (tsd.json or d.ts file). For example, the source when installed from the definitely typed repo will the raw git files. This allows anyone to host their own definitions. tsd install <module> will still fall back to the definitely typed repo and tsd search <module> will still search the repo. It is possible for this to be automated as well.
Having the name -> source mapping allows us a little more flexibility. For example, we can now check in our custom definition files and have them resolve according to the recursive algorithm since they are defined. On top of that, we can create aliases (which are supported by build tools like browserify and webpack) from one module to another. Finally, we can eventually support the module output format by TypeScript and automatically compile that into the namespaced module. That would personally be very cool to do, since it's a pretty big pain point for third-party module developers.
Ok, I think I'm done rambling but there will definitely be more to come.
Tracking
-  TSD to have command parity with NPM and Bower TSD to have parity with NPM and Bower commands #142 Alphabetize entries in installed field of tsd.json #119 Modify install command to perform 'reinstall' if invoked with no arguments #122 Create uninstall command #6 tsd install should install every definition listed in tsd.json#116
-  Perform a complete, recursive defintion resolution Packages with a / in the name don't work. #134 TS6053 File not found when import tsd.d.ts from bower distributed package #105 Does tsd linknot work? #130 Resolve dependencies for linked bundles #123 Package linker's folder scan uses hardcoded folders #109 tsd reinstall does not remove stale typings #151
- Make sure we're running on all node versions >= 0.8 and iojs Update to be compatible with Node.js 0.12 #144
- Fix general inconsistencies First argument ignored when using flags #143 tsd --save flag modifies permissions of parent directories unnecessarily #125 'undefined' being written to tsd.d.ts #120 Overlap path value install library --save each time in tsd.d.ts #112 Fix CLI query on Max etc #62 Report errors more gracefull #75 Simplify installed property in tsd.json #113 Generating tsd.json changes its parent directory's permission to 0744 #95
- Automatically install unknown dependency definitions tsd link --implicit proposal #115
- Install dependencies from any source query definitions from multiple repo #97 Support non-Github repos. #135 Allow install from seperate repo like bower #87
- Start work on a wrapper that will accept any definition file and declare as a module name
Testing
I will start work in the next few days on the future branch.
npm install -g DefinitelyTyped/tsd#future
Related
There's a few proposals in TypeScript right now to fix the definitions situation that will probably (hopefully) make most of this redundant (microsoft/TypeScript#2338, microsoft/TypeScript#2839).