Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Run tsickle+TSC to convert inputs to Closure JS files.
const result = toClosureJS(
config.options, config.fileNames, settings, (filePath: string, contents: string) => {
fs.mkdirSync(path.dirname(filePath), {recursive: true});
fs.writeFileSync(filePath, contents, {encoding: 'utf-8'});
});
if (result.diagnostics.length) {
console.error(ts.formatDiagnostics(result.diagnostics, ts.createCompilerHost(config.options)));
return 1;
}
if (settings.externsPath) {
fs.mkdirSync(path.dirname(settings.externsPath), {recursive: true});
fs.writeFileSync(
settings.externsPath,
tsickle.getGeneratedExterns(result.externs, config.options.rootDir || ''));
}
return 0;
}
if (!gatherDiagnostics) {
gatherDiagnostics = (program) =>
gatherDiagnosticsForInputsOnly(compilerOpts, bazelOpts, program);
}
const {diagnostics, emitResult, program} = ng.performCompilation({
rootNames: files,
options: compilerOpts,
host: ngHost, emitCallback,
mergeEmitResultsCallback: tsickle.mergeEmitResults, gatherDiagnostics
});
const tsickleEmitResult = emitResult as tsickle.EmitResult;
let externs = '/** @externs */\n';
if (!diagnostics.length) {
if (bazelOpts.tsickleGenerateExterns) {
externs += tsickle.getGeneratedExterns(tsickleEmitResult.externs);
}
if (bazelOpts.manifest) {
const manifest = constructManifest(tsickleEmitResult.modulesManifest, bazelHost);
fs.writeFileSync(bazelOpts.manifest, manifest);
}
}
// If compilation fails unexpectedly, performCompilation returns no program.
// Make sure not to crash but report the diagnostics.
if (!program) return {program, diagnostics};
if (!bazelOpts.nodeModulesPrefix) {
// If there is no node modules, then metadata.json should be emitted since
// there is no other way to obtain the information
generateMetadataJson(program.getTsProgram(), files, compilerOpts.rootDirs, bazelBin, tsHost);
}
src.forEach(sr => tsccLogger.log(sr));
}
setImmediate(() => {
src.forEach(name => {
let out = tsickleOutput.get(name);
if (!out) {
tsccLogger.log(`File not emitted from tsickle: ${name}`);
} else {
pushVinylToStdInStream(out);
}
})
});
// Write externs to a temp file.
// ..only after attaching tscc's generated externs
const externs = tsickle.getGeneratedExterns(result.externs, '') +
getExternsForExternalModules(tsccSpec, transformerHost);
const tempFilePath = path.join(tempFileDir, "externs_generated.js");
fs.writeFileSync(tempFilePath, externs);
pushImmediately("]");
pushImmediately(null);
const stdInStream = new stream.Readable({read: function () {}});
return new Promise((resolve, reject) => {
/**
* Spawn compiler process with module dependency information
*/
const ccLogger = new Logger(chalk.redBright("ClosureCompiler: "), process.stderr);
ccLogger.startTask("Closure Compiler");
const compilerProcess = spawnCompiler([
"-jar", require.resolve('google-closure-compiler-java/compiler.jar'),
host: this.bazelHost,
});
const emitResult = tsickle.emit(
this.program,
this.bazelHost,
this.bazelHost.writeFile,
);
const allDiagnostics = this.gatherDiagnosticsForInputsOnly();
allDiagnostics.push(...emitResult.diagnostics);
let externs = '/** @externs */\n';
if (!emitResult.diagnostics.length) {
if (this.bazelOpts.tsickleGenerateExterns) {
externs += tsickle.getGeneratedExterns(emitResult.externs);
}
if (this.bazelOpts.manifest) {
const manifest = constructManifest(
emitResult.modulesManifest,
this.bazelHost,
);
fs.writeFileSync(this.bazelOpts.manifest, manifest, 'utf8');
}
}
if (this.bazelOpts.tsickleExternsPath) {
fs.writeFileSync(this.bazelOpts.tsickleExternsPath, externs, 'utf8');
}
this.options.expectedOuts.forEach(outputFile => {
this.originalWriteFile(outputFile, '', false);