Created
May 9, 2014 12:38
-
-
Save k-maru/281f0f0a3119b493cc96 to your computer and use it in GitHub Desktop.
Node TypeScript Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _vm = require("vm"); | |
import _path = require("path"); | |
import _fs = require("fs"); | |
function getTypeScriptVersion(): string { | |
var typeScriptDir = _path.dirname(require.resolve("typescript")), | |
packageJsonPath = _path.resolve(typeScriptDir, "..", "package.json"); | |
if (!_fs.existsSync(packageJsonPath)) { | |
throw new Error("TypeScript not found.") | |
} | |
return JSON.parse(_fs.readFileSync(packageJsonPath, {encoding: "utf-8"}).toString()).version; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _vm = require("vm"), | |
_fs = require("fs"), | |
_path = require("path"); | |
var typeScriptDir = _path.dirname(require.resolve("typescript")), | |
typeScriptPath = _path.resolve(typeScriptDir, "typescript.js"), | |
code = _fs.readFileSync(typeScriptPath, { encoding: "utf-8" }).toString(), | |
sandbox = {}; | |
_vm.runInNewContext(code, sandbox, "typescript.js"); | |
module.exports = sandbox.TypeScript; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export = TypeScript; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment