From 65fb8834eda77ad0dbf58f1e0e9457bcaeb6e6b7 Mon Sep 17 00:00:00 2001 From: ezolenko Date: Sun, 2 Apr 2017 22:40:09 -0600 Subject: [PATCH] - normalizing paths used as snapshot cache keys (#6) --- dist/rollup-plugin-typescript2.cjs.js | 6 ++++++ dist/rollup-plugin-typescript2.es.js | 6 ++++++ src/host.ts | 11 +++++++++++ tsconfig.json | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/dist/rollup-plugin-typescript2.cjs.js b/dist/rollup-plugin-typescript2.cjs.js index 31f050e..124f941 100644 --- a/dist/rollup-plugin-typescript2.cjs.js +++ b/dist/rollup-plugin-typescript2.cjs.js @@ -127,12 +127,14 @@ var LanguageServiceHost = (function () { this.versions = {}; }; LanguageServiceHost.prototype.setSnapshot = function (fileName, data) { + fileName = this.normalize(fileName); var snapshot = ts.ScriptSnapshot.fromString(data); this.snapshots[fileName] = snapshot; this.versions[fileName] = (this.versions[fileName] || 0) + 1; return snapshot; }; LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) { + fileName = this.normalize(fileName); if (_.has(this.snapshots, fileName)) return this.snapshots[fileName]; if (fs.existsSync(fileName)) { @@ -146,6 +148,7 @@ var LanguageServiceHost = (function () { return this.cwd; }; LanguageServiceHost.prototype.getScriptVersion = function (fileName) { + fileName = this.normalize(fileName); return (this.versions[fileName] || 0).toString(); }; LanguageServiceHost.prototype.getScriptFileNames = function () { @@ -157,6 +160,9 @@ var LanguageServiceHost = (function () { LanguageServiceHost.prototype.getDefaultLibFileName = function (opts) { return ts.getDefaultLibFilePath(opts); }; + LanguageServiceHost.prototype.normalize = function (fileName) { + return fileName.split("\\").join("/"); + }; return LanguageServiceHost; }()); diff --git a/dist/rollup-plugin-typescript2.es.js b/dist/rollup-plugin-typescript2.es.js index 294f1a2..25b75c9 100644 --- a/dist/rollup-plugin-typescript2.es.js +++ b/dist/rollup-plugin-typescript2.es.js @@ -133,12 +133,14 @@ var LanguageServiceHost = (function () { this.versions = {}; }; LanguageServiceHost.prototype.setSnapshot = function (fileName, data) { + fileName = this.normalize(fileName); var snapshot = ScriptSnapshot.fromString(data); this.snapshots[fileName] = snapshot; this.versions[fileName] = (this.versions[fileName] || 0) + 1; return snapshot; }; LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) { + fileName = this.normalize(fileName); if (has(this.snapshots, fileName)) return this.snapshots[fileName]; if (existsSync(fileName)) { @@ -152,6 +154,7 @@ var LanguageServiceHost = (function () { return this.cwd; }; LanguageServiceHost.prototype.getScriptVersion = function (fileName) { + fileName = this.normalize(fileName); return (this.versions[fileName] || 0).toString(); }; LanguageServiceHost.prototype.getScriptFileNames = function () { @@ -163,6 +166,9 @@ var LanguageServiceHost = (function () { LanguageServiceHost.prototype.getDefaultLibFileName = function (opts) { return getDefaultLibFilePath(opts); }; + LanguageServiceHost.prototype.normalize = function (fileName) { + return fileName.split("\\").join("/"); + }; return LanguageServiceHost; }()); diff --git a/src/host.ts b/src/host.ts index 7e4f670..2951ede 100644 --- a/src/host.ts +++ b/src/host.ts @@ -20,6 +20,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost public setSnapshot(fileName: string, data: string): ts.IScriptSnapshot { + fileName = this.normalize(fileName); + let snapshot = ts.ScriptSnapshot.fromString(data); this.snapshots[fileName] = snapshot; this.versions[fileName] = (this.versions[fileName] || 0) + 1; @@ -28,6 +30,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost public getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined { + fileName = this.normalize(fileName); + if (_.has(this.snapshots, fileName)) return this.snapshots[fileName]; @@ -48,6 +52,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost public getScriptVersion(fileName: string) { + fileName = this.normalize(fileName); + return (this.versions[fileName] || 0).toString(); } @@ -65,4 +71,9 @@ export class LanguageServiceHost implements ts.LanguageServiceHost { return ts.getDefaultLibFilePath(opts); } + + private normalize(fileName: string) + { + return fileName.split("\\").join("/"); + } } diff --git a/tsconfig.json b/tsconfig.json index 31583e0..c346a36 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ "listFiles": true, "pretty": true, "moduleResolution": "node", - "noEmitOnError": true, + "noEmitOnError": false, "strictNullChecks": true, "forceConsistentCasingInFileNames": true, "noImplicitReturns": true