28
Vote

NPM module should export the TypeScriptCompiler

description

I can't find a good way to programmatically compile TypeScript using the NPM module. What I'd like to do is the following.
npm install typescript
var TypeScript = require('typescript');
var compiler = new TypeScript.TypeScriptCompiler();
// ... do something with the compiler here

comments

jpoehls wrote Oct 4, 2012 at 3:21 PM

Ideally TypeScript would provide an interface similar to the coffee-script compiler module which works like this:

var coffee = require('coffee-script');
coffee.compile("a = 1");
//=> '(function() {\n var a;\n\n a = 1;\n\n}).call(this);\n'

orefalo wrote Oct 4, 2012 at 8:46 PM

+10 on this one. This interface is required to smoothly integrate TS with a node asset manager...

edwinyzh wrote Oct 7, 2012 at 6:22 AM

+1! I vote this as the developer of LIVEditor (live code editor for the web, at http://liveditor.com), since I guess LIVEditor will mostly like support TypeScript in the future.

clausreinke wrote Dec 1, 2012 at 8:59 PM

Not just the compiler, also the language services, please.

'typescript.js' and friends are included in the npm package, but do not export anything.
They cannot export anything because doing so would drop them out of the global module, preventing them from other parts of the compiler, which also rely on the global module and reference path includes.

So it seems that a pre-requisite for this ticket would be to modularize the compiler (and language services), which would also be a great driver for testing and improving the external module system support.

related issue: http://typescript.codeplex.com/workitem/521

RyanCavanaugh wrote Jan 29, 2013 at 12:08 AM

Changing to suggestion assigned to Jonathan

jonturner wrote Mar 7, 2013 at 9:53 PM

We're looking into language extensions that will make it much easier to export the compiler. In 0.9.0, we're planning a way of saying "export = <symbol>" which would allow you to export the internal symbol/module that represents the compiler.

Doing so would be experimental in that the compiler API may change. We have not fully worked out all the scenarios to build the proper API, yet.

potmo wrote Mar 9 at 9:45 PM

Any updates on this?