* Returns the cached TypeScript compiler or loads it * if it is not found in the cache. * * @private * @param {Object} [options] - Optional compiler options. * @return {compileCallback} The TypeScript compiler. * @throws {VMError} If the TypeScript module can't be found.
(options)
| 37 | * @throws {VMError} If the TypeScript module can't be found. |
| 38 | */ |
| 39 | function getTypeScriptCompiler(options) { |
| 40 | try { |
| 41 | // The warning generated by webpack can be disabled by setting: |
| 42 | // ignoreWarnings[].message = /Can't resolve 'typescript'/ |
| 43 | |
| 44 | const typescript = require('typescript'); |
| 45 | return (code, filename) => { |
| 46 | return typescript.transpileModule(code, { |
| 47 | fileName: filename, |
| 48 | compilerOptions: Object.assign({ |
| 49 | module: typescript.ModuleKind.CommonJS, |
| 50 | }, options) |
| 51 | }).outputText; |
| 52 | }; |
| 53 | } catch (e) { |
| 54 | throw new VMError('TypeScript compiler is not installed.'); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Remove the shebang from source code. |
no test coverage detected
searching dependent graphs…