| 515 | * that can be auto-generated based on the provided target configuration. |
| 516 | */ |
| 517 | export function setup( |
| 518 | targets: TypeCheckingTarget[], |
| 519 | overrides: { |
| 520 | config?: Partial<TypeCheckingConfig>; |
| 521 | options?: ts.CompilerOptions; |
| 522 | inlining?: boolean; |
| 523 | inliningMode?: InliningMode; |
| 524 | parseOptions?: ParseTemplateOptions; |
| 525 | referenceEmitter?: ReferenceEmitter; |
| 526 | } = {}, |
| 527 | ): { |
| 528 | templateTypeChecker: TemplateTypeChecker; |
| 529 | program: ts.Program; |
| 530 | programStrategy: TsCreateProgramDriver; |
| 531 | } { |
| 532 | const files = [typescriptLibDts(), ...angularCoreDtsFiles(), angularAnimationsDts()]; |
| 533 | const fakeMetadataRegistry = new Map(); |
| 534 | const shims = new Map<AbsoluteFsPath, AbsoluteFsPath>(); |
| 535 | |
| 536 | for (const target of targets) { |
| 537 | let contents: string; |
| 538 | if (target.source !== undefined) { |
| 539 | contents = target.source; |
| 540 | } else { |
| 541 | contents = `// generated from templates\n\nexport const MODULE = true;\n\n`; |
| 542 | if (target.templates) { |
| 543 | for (const className of Object.keys(target.templates)) { |
| 544 | contents += `export class ${className} {}\n`; |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | files.push({name: target.fileName, contents}); |
| 550 | |
| 551 | if (!target.fileName.endsWith('.d.ts')) { |
| 552 | const shimName = TypeCheckShimGenerator.shimFor(target.fileName); |
| 553 | shims.set(target.fileName, shimName); |
| 554 | files.push({name: shimName, contents: 'export const MODULE = true;'}); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | const opts = overrides.options ?? {}; |
| 559 | const config = overrides.config ?? {}; |
| 560 | |
| 561 | const {program, host, options} = makeProgram( |
| 562 | files, |
| 563 | {strictNullChecks: true, skipLibCheck: true, noImplicitAny: true, ...opts}, |
| 564 | /* host */ undefined, |
| 565 | /* checkForErrors */ false, |
| 566 | ); |
| 567 | const checker = program.getTypeChecker(); |
| 568 | const logicalFs = new LogicalFileSystem(getRootDirs(host, options), host); |
| 569 | const reflectionHost = new TypeScriptReflectionHost(checker); |
| 570 | const moduleResolver = new ModuleResolver( |
| 571 | program, |
| 572 | options, |
| 573 | host, |
| 574 | /* moduleResolutionCache */ null, |