Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Add the generated files to the configuration so they will become part of the program.
if (ngOptions.alwaysCompileGeneratedCode) {
genFiles.forEach(genFileName => addGeneratedFileName(genFileName));
}
if (!ngOptions.skipMetadataEmit) {
host = new MetadataWriterHost(host, ngOptions, true);
}
// Create a new program since codegen files were created after making the old program
let programWithCodegen = createProgram(host, program);
tsc.typeCheck(host, programWithCodegen);
if (diagnostics) console.time('Emit');
const {diagnostics: emitDiags} =
tsickle.emitWithTsickle(programWithCodegen, tsickleHost, host, ngOptions);
if (diagnostics) console.timeEnd('Emit');
check(emitDiags);
if (diagnostics) {
(ts as any).performance.forEachMeasure(
(name: string, duration: number) => { console.error(`TS ${name}: ${duration}ms`); });
}
});
} catch (e) {
return function (_a) {
var program = _a.program, targetSourceFile = _a.targetSourceFile, writeFile = _a.writeFile, cancellationToken = _a.cancellationToken, emitOnlyDtsFiles = _a.emitOnlyDtsFiles, _b = _a.customTransformers, customTransformers = _b === void 0 ? {} : _b, host = _a.host, options = _a.options;
// tslint:disable-next-line:no-require-imports only depend on tsickle if requested
return require('tsickle').emitWithTsickle(program, tslib_1.__assign({}, tsickleHost, { options: options, host: host }), host, options, targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, {
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
});
};
}
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;
};
const transformerHost = {
host: compilerHost,
options: tsOptions,
pathToModuleName,
shouldSkipTsickleProcessing: () => false,
transformTypesToClosure: true,
};
return tsickle
.emitWithTsickle(
program,
transformerHost,
compilerHost,
tsOptions,
undefined,
(filePath, contents) => {
fs.writeFileSync(filePath, contents, {encoding: 'utf-8'});
}
)
.then(emitResult => {
const diagnostics = ts
.getPreEmitDiagnostics(program)
.concat(emitResult.diagnostics);
if (diagnostics.length) {
log(colors.red('TSickle:'), tsickle.formatDiagnostics(diagnostics));
return ({
program,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
customTransformers = {},
host,
options
}) =>
// tslint:disable-next-line:no-require-imports only depend on tsickle if requested
require('tsickle').emitWithTsickle(
program, {...tsickleHost, options, host, moduleResolutionHost: host}, host, options,
targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, {
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
});
} else {
return ({
program,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
customTransformers = {},
host,
options,
}) =>
// tslint:disable-next-line:no-require-imports only depend on tsickle if requested
require('tsickle').emitWithTsickle(
program,
{ ...tsickleHost, options, host, moduleResolutionHost: host },
host,
options,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
{
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
},
);
}
const emitCallback: ng.TsEmitCallback = ({
program,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
customTransformers = {},
}) =>
tsickle.emitWithTsickle(
program, bazelHost, bazelHost, compilerOpts, targetSourceFile, writeFile,
cancellationToken, emitOnlyDtsFiles, {
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
afterDeclarations: customTransformers.afterDeclarations,
});
return function (_a) {
var program = _a.program, targetSourceFile = _a.targetSourceFile, writeFile = _a.writeFile, cancellationToken = _a.cancellationToken, emitOnlyDtsFiles = _a.emitOnlyDtsFiles, _b = _a.customTransformers, customTransformers = _b === void 0 ? {} : _b, host = _a.host, options = _a.options;
return tsickle.emitWithTsickle(program, tsickleHost, host, options, targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, {
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
});
};
}
return ({
program,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
customTransformers = {},
host,
options
}) =>
tsickle.emitWithTsickle(
program,
tsickleHost,
host,
options,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
{
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
}
);
}
return ({
program,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
customTransformers = {},
host,
options
}) =>
tsickle.emitWithTsickle(
program, tsickleHost, tsickleOptions, host, options, targetSourceFile, writeFile,
cancellationToken, emitOnlyDtsFiles, {
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
});
}