node-typescript
Version:
The TypeScript API exposed to nodejs. Use to compile typescript code in memory
26 lines (19 loc) • 808 B
text/typescript
/// <reference path="typings/DefinitelyTyped/node/node.d.ts" />
var fs = require('fs'),
path = require('path'),
vm = require('vm');
(function () {
var sandbox = { expTypeScript: null };
var typescriptmodulefile = require.resolve("typescript");
var location = path.dirname(typescriptmodulefile);
var tmp = module.exports._libdPath = require.resolve(location + '/lib.d.ts');
var contents = [
"(function() {",
fs.readFileSync(typescriptmodulefile, "utf8"),
"expTypeScript = TypeScript;",
"}).call({});"
].join("");
vm.runInNewContext(contents, sandbox, 'ts.vm');
var TypeScript = module.exports.TypeScript = sandbox.expTypeScript;
TypeScript.moduleGenTarget = TypeScript.ModuleGenTarget.Synchronous;
})();