Skip to content

Commit

Permalink
Use readFile for declarations too
Browse files Browse the repository at this point in the history
This let's the loader survive whenever the watched file gets removed.
  • Loading branch information
Standa Opichal committed Sep 13, 2016
1 parent 04b84df commit 4822ae6
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ function findConfigFile(compiler: typeof typescript, searchPath: string, configF
return undefined;
}

function readFile(fileName) {
fileName = path.normalize(fileName);
try {
return fs.readFileSync(fileName, {encoding: 'utf8'})
}
catch (e) {
return;
}
}

// The loader is executed once for each file seen by webpack. However, we need to keep
// a persistent instance of TypeScript that contains all of the files in the program
// along with definition files and options. This function either creates an instance
Expand Down Expand Up @@ -326,16 +336,6 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
// make a (sync) resolver that follows webpack's rules
let resolver = makeResolver(loader.options);

var readFile = function(fileName) {
fileName = path.normalize(fileName);
try {
return fs.readFileSync(fileName, {encoding: 'utf8'})
}
catch (e) {
return;
}
}

var moduleResolutionHost = {
fileExists: (fileName: string) => readFile(fileName) !== undefined,
readFile: (fileName: string) => readFile(fileName)
Expand Down Expand Up @@ -516,7 +516,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
filePath = path.normalize(filePath);
var file = instance.files[filePath];
if (file) {
file.text = fs.readFileSync(filePath, {encoding: 'utf8'});
file.text = readFile(fileName) || '';
file.version++;
instance.version++;
}
Expand Down

0 comments on commit 4822ae6

Please sign in to comment.