How to use the tsickle.formatDiagnostics function in tsickle

To help you get started, we’ve selected a few tsickle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ampproject / amphtml / build-system / compile / typescript.js View on Github external
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;
  };
github ampproject / amphtml / build-system / compile / typescript.js View on Github external
.then(emitResult => {
      const diagnostics = ts
        .getPreEmitDiagnostics(program)
        .concat(emitResult.diagnostics);
      if (diagnostics.length) {
        log(colors.red('TSickle:'), tsickle.formatDiagnostics(diagnostics));
      }
      endBuildStep('Transpiled', srcFilename, startTime);
    });
};