From 4210b0e66a3a65c0510d4e19a6d57f5a2f0df9e7 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 20 May 2015 11:28:39 -0700 Subject: [PATCH] build(broccoli-typescript): refactor output removal this is just to make the code a bit more easier to follow --- tools/broccoli/broccoli-typescript.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/broccoli/broccoli-typescript.ts b/tools/broccoli/broccoli-typescript.ts index 0e7c736aee..0d586960af 100644 --- a/tools/broccoli/broccoli-typescript.ts +++ b/tools/broccoli/broccoli-typescript.ts @@ -68,14 +68,7 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin { this.rootFilePaths.splice(this.rootFilePaths.indexOf(tsFilePath), 1); this.fileRegistry[tsFilePath] = null; - - let jsFilePath = tsFilePath.replace(/\.ts$/, '.js'); - let mapFilePath = tsFilePath.replace(/.ts$/, '.js.map'); - let dtsFilePath = tsFilePath.replace(/\.ts$/, '.d.ts'); - - fs.unlinkSync(path.join(this.cachePath, jsFilePath)); - fs.unlinkSync(path.join(this.cachePath, mapFilePath)); - fs.unlinkSync(path.join(this.cachePath, dtsFilePath)); + this.removeOutputFor(tsFilePath); }); if (this.firstRun) { @@ -155,6 +148,19 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin { } } } + + + private removeOutputFor(tsFilePath: string) { + let absoluteJsFilePath = path.join(this.cachePath, tsFilePath.replace(/\.ts$/, '.js')); + let absoluteMapFilePath = path.join(this.cachePath, tsFilePath.replace(/.ts$/, '.js.map')); + let absoluteDtsFilePath = path.join(this.cachePath, tsFilePath.replace(/\.ts$/, '.d.ts')); + + if (fs.existsSync(absoluteJsFilePath)) { + fs.unlinkSync(absoluteJsFilePath); + fs.unlinkSync(absoluteMapFilePath); + fs.unlinkSync(absoluteDtsFilePath); + } + } }