Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.transpileTs = function(srcDir, srcFilename) {
const startTime = Date.now();
const tsEntry = path.join(srcDir, srcFilename).replace(/\.js$/, '.ts');
const tsConfig = ts.convertCompilerOptionsFromJson(
{
'module': 'esnext',
'target': 'esnext',
},
srcDir
);
const tsOptions = tsConfig.options;
if (tsConfig.errors.length) {
log(colors.red('TSickle:'), tsickle.formatDiagnostics(tsConfig.errors));
}
const compilerHost = ts.createCompilerHost(tsOptions);
const program = ts.createProgram([tsEntry], tsOptions, compilerHost);
// TODO(choumx): This was partially copy-pasta'd from tsickle. Add a default
// to tsickle so this can be an optional param.
const pathToModuleName = (context, fileName) => {
fileName = fileName.replace(/\.js$/, '');
if (fileName[0] === '.') {
// './foo' or '../foo'.
// Resolve the path against the dirname of the current module.
fileName = path.join(path.dirname(context), fileName);
}
return fileName;
};
.then(emitResult => {
const diagnostics = ts
.getPreEmitDiagnostics(program)
.concat(emitResult.diagnostics);
if (diagnostics.length) {
log(colors.red('TSickle:'), tsickle.formatDiagnostics(diagnostics));
}
endBuildStep('Transpiled', srcFilename, startTime);
});
};