test(ivy): support multiple compilations in the ngtsc test env (#29380)
This commit adds support for compiling the same program repeatedly in a way that's similar to how incremental builds work in a tool such as the CLI. * support is added to the compiler entrypoint for reuse of the Program object between compilations. This is the basis of the compiler's incremental compilation model. * support is added to wrap the CompilerHost the compiler creates and cache ts.SourceFiles in between compilations. * support is added to track when files are emitted, for assertion purposes. * an 'exclude' section is added to the base tsconfig to prevent .d.ts outputs from the first compilation from becoming inputs to any subsequent compilations. PR Close #29380
This commit is contained in:

committed by
Jason Aden

parent
aaa16f286d
commit
7316212c1e
@ -22,7 +22,9 @@ import {performWatchCompilation, createPerformWatchHost} from './perform_watch'
|
||||
|
||||
export function main(
|
||||
args: string[], consoleError: (s: string) => void = console.error,
|
||||
config?: NgcParsedConfiguration, customTransformers?: api.CustomTransformers): number {
|
||||
config?: NgcParsedConfiguration, customTransformers?: api.CustomTransformers, programReuse?: {
|
||||
program: api.Program | undefined,
|
||||
}): number {
|
||||
let {project, rootNames, options, errors: configErrors, watch, emitFlags} =
|
||||
config || readNgcCommandLineAndConfiguration(args);
|
||||
if (configErrors.length) {
|
||||
@ -32,12 +34,22 @@ export function main(
|
||||
const result = watchMode(project, options, consoleError);
|
||||
return reportErrorsAndExit(result.firstCompileResult, options, consoleError);
|
||||
}
|
||||
const {diagnostics: compileDiags} = performCompilation({
|
||||
|
||||
let oldProgram: api.Program|undefined;
|
||||
if (programReuse !== undefined) {
|
||||
oldProgram = programReuse.program;
|
||||
}
|
||||
|
||||
const {diagnostics: compileDiags, program} = performCompilation({
|
||||
rootNames,
|
||||
options,
|
||||
emitFlags,
|
||||
oldProgram,
|
||||
emitCallback: createEmitCallback(options), customTransformers
|
||||
});
|
||||
if (programReuse !== undefined) {
|
||||
programReuse.program = program;
|
||||
}
|
||||
return reportErrorsAndExit(compileDiags, options, consoleError);
|
||||
}
|
||||
|
||||
|
@ -21,19 +21,18 @@ const NODE_MODULES_PACKAGE_NAME = /node_modules\/((\w|-|\.)+|(@(\w|-|\.)+\/(\w|-
|
||||
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
||||
const CSS_PREPROCESSOR_EXT = /(\.scss|\.less|\.styl)$/;
|
||||
|
||||
let augmentHostForTest: {[name: string]: Function}|null = null;
|
||||
let wrapHostForTest: ((host: ts.CompilerHost) => ts.CompilerHost)|null = null;
|
||||
|
||||
export function setAugmentHostForTest(augmentation: {[name: string]: Function} | null): void {
|
||||
augmentHostForTest = augmentation;
|
||||
export function setWrapHostForTest(wrapFn: ((host: ts.CompilerHost) => ts.CompilerHost) | null):
|
||||
void {
|
||||
wrapHostForTest = wrapFn;
|
||||
}
|
||||
|
||||
export function createCompilerHost(
|
||||
{options, tsHost = ts.createCompilerHost(options, true)}:
|
||||
{options: CompilerOptions, tsHost?: ts.CompilerHost}): CompilerHost {
|
||||
if (augmentHostForTest !== null) {
|
||||
for (const name of Object.keys(augmentHostForTest)) {
|
||||
(tsHost as any)[name] = augmentHostForTest[name];
|
||||
}
|
||||
if (wrapHostForTest !== null) {
|
||||
tsHost = wrapHostForTest(tsHost);
|
||||
}
|
||||
return tsHost;
|
||||
}
|
||||
|
Reference in New Issue
Block a user