Skip to content

Commit

Permalink
removing file existance check when loading snapshot (fix for #154)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezolenko committed Jun 17, 2019
1 parent 08a16ed commit 74d267f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/host.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions dist/rollup-plugin-typescript2.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var fs = require('fs');
var crypto = _interopDefault(require('crypto'));
var fsExtra = require('fs-extra');
var fs = require('fs');
var util = _interopDefault(require('util'));
var os = _interopDefault(require('os'));
var path = require('path');
Expand Down Expand Up @@ -17242,8 +17242,9 @@ class LanguageServiceHost {
fileName = normalize(fileName);
if (lodash_9(this.snapshots, fileName))
return this.snapshots[fileName];
if (fs.existsSync(fileName)) {
this.snapshots[fileName] = tsModule.ScriptSnapshot.fromString(tsModule.sys.readFile(fileName));
const source = tsModule.sys.readFile(fileName);
if (source) {
this.snapshots[fileName] = tsModule.ScriptSnapshot.fromString(source);
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
return this.snapshots[fileName];
}
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.cjs.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions dist/rollup-plugin-typescript2.es.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import { existsSync, readdirSync, renameSync, readFileSync } from 'fs';
import crypto from 'crypto';
import { emptyDirSync, readJsonSync, writeJsonSync, ensureFileSync, removeSync, pathExistsSync, readdirSync as readdirSync$1, statSync } from 'fs-extra';
import { existsSync, readdirSync, renameSync, readFileSync } from 'fs';
import util from 'util';
import os from 'os';
import { normalize as normalize$1, join, dirname, isAbsolute, relative } from 'path';
Expand Down Expand Up @@ -17238,8 +17238,9 @@ class LanguageServiceHost {
fileName = normalize(fileName);
if (lodash_9(this.snapshots, fileName))
return this.snapshots[fileName];
if (existsSync(fileName)) {
this.snapshots[fileName] = tsModule.ScriptSnapshot.fromString(tsModule.sys.readFile(fileName));
const source = tsModule.sys.readFile(fileName);
if (source) {
this.snapshots[fileName] = tsModule.ScriptSnapshot.fromString(source);
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
return this.snapshots[fileName];
}
Expand Down
2 changes: 1 addition & 1 deletion dist/rollup-plugin-typescript2.es.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/host.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { tsModule } from "./tsproxy";
import * as tsTypes from "typescript";
import { existsSync } from "fs";
import * as _ from "lodash";
import { normalize } from "./normalize";
import { TransformerFactoryCreator } from "./ioptions";
Expand Down Expand Up @@ -47,9 +46,10 @@ export class LanguageServiceHost implements tsTypes.LanguageServiceHost
if (_.has(this.snapshots, fileName))
return this.snapshots[fileName];

if (existsSync(fileName))
const source = tsModule.sys.readFile(fileName);
if (source)
{
this.snapshots[fileName] = tsModule.ScriptSnapshot.fromString(tsModule.sys.readFile(fileName)!);
this.snapshots[fileName] = tsModule.ScriptSnapshot.fromString(source);
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
return this.snapshots[fileName];
}
Expand Down

0 comments on commit 74d267f

Please sign in to comment.