From 2c98a0f7719c6af54255836183c09c5ccea507f1 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 15 Oct 2015 21:27:58 -0700 Subject: [PATCH] build(broccoli-typescript): add support for moduleResolution=node Closes #4779 --- tools/broccoli/broccoli-typescript.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/broccoli/broccoli-typescript.ts b/tools/broccoli/broccoli-typescript.ts index ab4e92ee7c..ebc353a5b1 100644 --- a/tools/broccoli/broccoli-typescript.ts +++ b/tools/broccoli/broccoli-typescript.ts @@ -223,10 +223,17 @@ class CustomLanguageServiceHost implements ts.LanguageServiceHost { * not worth the potential issues with stale cache records. */ getScriptSnapshot(tsFilePath: string): ts.IScriptSnapshot { - let absoluteTsFilePath = - (tsFilePath == this.defaultLibFilePath || path.isAbsolute(tsFilePath)) ? - tsFilePath : - path.join(this.treeInputPath, tsFilePath); + let absoluteTsFilePath; + + if (tsFilePath == this.defaultLibFilePath || path.isAbsolute(tsFilePath)) { + absoluteTsFilePath = tsFilePath; + } else if (this.compilerOptions.moduleResolution === ts.ModuleResolutionKind.NodeJs && + tsFilePath.match(/^node_modules/)) { + absoluteTsFilePath = path.resolve(tsFilePath); + } else { + absoluteTsFilePath = path.join(this.treeInputPath, tsFilePath); + } + if (!fs.existsSync(absoluteTsFilePath)) { // TypeScript seems to request lots of bogus paths during import path lookup and resolution,