12

Closed

Request: Provide an Explicit Public API for NodeJS Module / Compilation Access

description

After a recent post on StackOverflow, I thought I would repost here as I believe this is more of a feature request than a question about how to access a feature. Please see this thread for the responses and work-arounds (http://stackoverflow.com/questions/12717309/does-typescript-provide-an-explicit-public-api-for-nodejs-module-access)
or review the below or the original question reproduced in its entirety:

From within a node app I would like to do:
var typeScript = require('typescript'); 

typeScript.compile('...')
I'm looking to implement the compiler into a build system but without access to a public API (typescript.compile, etc) this is impossible, or hacky.

Here's a more complete example of what I would like to do, though the below is for LiveScript, not TypeScript, utilitized in a plugin written for the Brunch.io build-system:
LiveScript = require 'LiveScript'
sysPath = require 'path'

module.exports = class LiveScriptCompiler
  brunchPlugin: yes
  type: 'javascript'
  extension: 'ls'

  constructor: (@config) ->
    null

  compile: (data, path, callback) ->
    try
      result = LiveScript.compile data, bare: yes
    catch err
      error = err
    finally
      callback error, result

  include: [
    (sysPath.join __dirname, '..', 'vendor', 'prelude-browser-0.6.0.js')
  ]
I believe something like this is very important for growing the language and its integration outside of the Visual Studio environment. Thoughts?
Closed Jul 28 at 11:18 PM by jonturner
As part of our move to GitHub, we're closing our CodePlex suggestions and asking that people move them to the GitHub issue tracker for further discussion. Some feature requests may already be active on GitHub, so please make sure to look for an existing issue before filing a new one.

You can find our GitHub issue tracker here:
https://github.com/microsoft/typeScript/issues

comments

jonturner wrote Feb 27, 2013 at 12:04 AM

This feature request is composed of two (possibly more) feature requests.

One of the features we're looking at for 0.9.x (http://typescript.codeplex.com/workitem/47) addresses some of this, and would let internal symbols like modules be exported for external modules. This would help a variety of situations, including the TypeScript compiler, be more easily accessed as Node.js modules.

The other part of this request is the API we'll expose. This hasn't yet been worked out, as we've been focusing on some pretty heavy-weight changes to the compiler (which you can see in the develop-0.9.x branch). Once the dust starts to settle, we can come back to intentionally shaping the API.

clausreinke wrote Feb 27, 2013 at 9:19 AM

Is there no way to use the 'components' field in this issue tracker?? I suggest components like 'modules', 'TS API', 'language services', 'npm package', etc. Being able to find related items quickly this way would help a lot.

related:

http://typescript.codeplex.com/workitem/534
http://typescript.codeplex.com/workitem/521
http://typescript.codeplex.com/workitem/97

pluma wrote Jun 19, 2013 at 5:06 PM

I was looking into a way to use typescript with browserify to translate *.ts files on the fly.

There doesn't seem to be any way to use tsc without creating files first (not even from stdin). This is a severe deficiency compared to other JS transpilers.

balupton wrote Aug 29, 2013 at 11:22 AM

+1. We'd love to add a typescript plugin to DocPad - http://docpad.org - but to do so we need an api to easily compile a source string to a compiled string.