From 64c96186da7f1fe50a1015edb77e97dea95b373f Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Mon, 24 Sep 2018 11:01:48 +0100 Subject: [PATCH] refactor(ivy): move ngcc `rootDirs` computation into a function (#26082) PR Close #26082 --- .../src/ngcc/src/packages/transformer.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/compiler-cli/src/ngcc/src/packages/transformer.ts b/packages/compiler-cli/src/ngcc/src/packages/transformer.ts index a1321ec155..455c03d122 100644 --- a/packages/compiler-cli/src/ngcc/src/packages/transformer.ts +++ b/packages/compiler-cli/src/ngcc/src/packages/transformer.ts @@ -62,14 +62,7 @@ export class Transformer { // Create the TS program and necessary helpers. // TODO : create a custom compiler host that reads from .bak files if available. const host = ts.createCompilerHost(options); - let rootDirs: string[]|undefined = undefined; - if (options.rootDirs !== undefined) { - rootDirs = options.rootDirs; - } else if (options.rootDir !== undefined) { - rootDirs = [options.rootDir]; - } else { - rootDirs = [host.getCurrentDirectory()]; - } + const rootDirs = this.getRootDirs(host, options); const entryPointFilePath = entryPoint[format]; if (!entryPointFilePath) { throw new Error( @@ -113,6 +106,16 @@ export class Transformer { writeMarkerFile(entryPoint, format); } + getRootDirs(host: ts.CompilerHost, options: ts.CompilerOptions) { + if (options.rootDirs !== undefined) { + return options.rootDirs; + } else if (options.rootDir !== undefined) { + return [options.rootDir]; + } else { + return [host.getCurrentDirectory()]; + } + } + getHost(isCore: boolean, format: string, program: ts.Program, dtsMapper: DtsMapper): NgccReflectionHost { switch (format) {