From 606b76d9bb7a14acc02877742540501e46cd2520 Mon Sep 17 00:00:00 2001 From: Vikram Subramanian Date: Thu, 12 Jan 2017 15:31:09 -0800 Subject: [PATCH] chore(compiler-cli): Move calculateEmitPath into CompilerHost (#13904) This is so that it can be overriden in an environment specific CompilerHost(like within Google) to customize the output paths. PR Close #13904 --- modules/@angular/compiler-cli/src/codegen.ts | 25 +------------------ .../compiler-cli/src/compiler_host.ts | 23 +++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/@angular/compiler-cli/src/codegen.ts b/modules/@angular/compiler-cli/src/codegen.ts index 7718a31ff6..31333dfe74 100644 --- a/modules/@angular/compiler-cli/src/codegen.ts +++ b/modules/@angular/compiler-cli/src/codegen.ts @@ -36,29 +36,6 @@ export class CodeGenerator { public host: ts.CompilerHost, private compiler: compiler.AotCompiler, private ngCompilerHost: CompilerHost) {} - // Write codegen in a directory structure matching the sources. - private calculateEmitPath(filePath: string): string { - let root = this.options.basePath; - for (const eachRootDir of this.options.rootDirs || []) { - if (this.options.trace) { - console.error(`Check if ${filePath} is under rootDirs element ${eachRootDir}`); - } - if (path.relative(eachRootDir, filePath).indexOf('.') !== 0) { - root = eachRootDir; - } - } - - // transplant the codegen path to be inside the `genDir` - let relativePath: string = path.relative(root, filePath); - while (relativePath.startsWith('..' + path.sep)) { - // Strip out any `..` path such as: `../node_modules/@foo` as we want to put everything - // into `genDir`. - relativePath = relativePath.substr(3); - } - - return path.join(this.options.genDir, relativePath); - } - codegen(): Promise { return this.compiler .compileAll(this.program.getSourceFiles().map( @@ -66,7 +43,7 @@ export class CodeGenerator { .then(generatedModules => { generatedModules.forEach(generatedModule => { const sourceFile = this.program.getSourceFile(generatedModule.srcFileUrl); - const emitPath = this.calculateEmitPath(generatedModule.genFileUrl); + const emitPath = this.ngCompilerHost.calculateEmitPath(generatedModule.genFileUrl); const source = GENERATED_META_FILES.test(emitPath) ? generatedModule.source : PREAMBLE + generatedModule.source; this.host.writeFile(emitPath, source, false, () => {}, [sourceFile]); diff --git a/modules/@angular/compiler-cli/src/compiler_host.ts b/modules/@angular/compiler-cli/src/compiler_host.ts index 5817134c2f..5cd142f5e5 100644 --- a/modules/@angular/compiler-cli/src/compiler_host.ts +++ b/modules/@angular/compiler-cli/src/compiler_host.ts @@ -261,6 +261,29 @@ export class CompilerHost implements AotCompilerHost { this.options.generateCodeForLibraries === false ? GENERATED_OR_DTS_FILES : GENERATED_FILES; return !excludeRegex.test(filePath); } + + calculateEmitPath(filePath: string): string { + // Write codegen in a directory structure matching the sources. + let root = this.options.basePath; + for (const eachRootDir of this.options.rootDirs || []) { + if (this.options.trace) { + console.error(`Check if ${filePath} is under rootDirs element ${eachRootDir}`); + } + if (path.relative(eachRootDir, filePath).indexOf('.') !== 0) { + root = eachRootDir; + } + } + + // transplant the codegen path to be inside the `genDir` + let relativePath: string = path.relative(root, filePath); + while (relativePath.startsWith('..' + path.sep)) { + // Strip out any `..` path such as: `../node_modules/@foo` as we want to put everything + // into `genDir`. + relativePath = relativePath.substr(3); + } + + return path.join(this.options.genDir, relativePath); + } } export class CompilerHostContextAdapter {