From 7d454a30a2aef23673f7a9a370c08726883ab47b Mon Sep 17 00:00:00 2001 From: James Brantly Date: Fri, 8 May 2015 21:50:52 -0400 Subject: [PATCH] Rework way the dependency graph is built (#14) --- index.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/index.ts b/index.ts index 35dfeac6d..f61fc48d4 100644 --- a/index.ts +++ b/index.ts @@ -141,7 +141,19 @@ function ensureTypeScriptInstance(options: Options, loader: any): TSInstance { getScriptSnapshot: fileName => { fileName = path.normalize(fileName); var file = files[fileName]; - if (!file) return undefined; + + if (!file) { + try { + file = files[fileName] = { + version: 0, + text: fs.readFileSync(fileName, {encoding: 'utf8'}) + } + } + catch (e) { + return; + } + } + return compiler.ScriptSnapshot.fromString(file.text); }, getCurrentDirectory: () => process.cwd(), @@ -202,26 +214,14 @@ function loader(contents) { configFileName: 'tsconfig.json' }, options); - var instance = ensureTypeScriptInstance(options, this); - - if (!Object.prototype.hasOwnProperty.call(instance.files, filePath)) { - - var filePaths = Object.keys(instance.files); - filePaths.push(filePath) + var instance = ensureTypeScriptInstance(options, this), + file = instance.files[filePath], + langService = instance.languageService; - var program = instance.compiler.createProgram(filePaths, instance.compilerOptions, instance.compiler.createCompilerHost(instance.compilerOptions)); - - program.getSourceFiles().forEach(file => { - var filePath = path.normalize(file.fileName); - if (!Object.prototype.hasOwnProperty.call(instance.files, filePath)) { - instance.files[filePath] = { version: 0, text: file.text }; - } - }) + if (!file) { + file = instance.files[filePath] = {}; } - var file = instance.files[filePath], - langService = instance.languageService; - file.text = contents; file.version++;