Skip to content

Commit 65fb883

Browse files
committed
- normalizing paths used as snapshot cache keys (#6)
1 parent f4cd9b4 commit 65fb883

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

dist/rollup-plugin-typescript2.cjs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ var LanguageServiceHost = (function () {
127127
this.versions = {};
128128
};
129129
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
130+
fileName = this.normalize(fileName);
130131
var snapshot = ts.ScriptSnapshot.fromString(data);
131132
this.snapshots[fileName] = snapshot;
132133
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
133134
return snapshot;
134135
};
135136
LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) {
137+
fileName = this.normalize(fileName);
136138
if (_.has(this.snapshots, fileName))
137139
return this.snapshots[fileName];
138140
if (fs.existsSync(fileName)) {
@@ -146,6 +148,7 @@ var LanguageServiceHost = (function () {
146148
return this.cwd;
147149
};
148150
LanguageServiceHost.prototype.getScriptVersion = function (fileName) {
151+
fileName = this.normalize(fileName);
149152
return (this.versions[fileName] || 0).toString();
150153
};
151154
LanguageServiceHost.prototype.getScriptFileNames = function () {
@@ -157,6 +160,9 @@ var LanguageServiceHost = (function () {
157160
LanguageServiceHost.prototype.getDefaultLibFileName = function (opts) {
158161
return ts.getDefaultLibFilePath(opts);
159162
};
163+
LanguageServiceHost.prototype.normalize = function (fileName) {
164+
return fileName.split("\\").join("/");
165+
};
160166
return LanguageServiceHost;
161167
}());
162168

dist/rollup-plugin-typescript2.es.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ var LanguageServiceHost = (function () {
133133
this.versions = {};
134134
};
135135
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
136+
fileName = this.normalize(fileName);
136137
var snapshot = ScriptSnapshot.fromString(data);
137138
this.snapshots[fileName] = snapshot;
138139
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
139140
return snapshot;
140141
};
141142
LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) {
143+
fileName = this.normalize(fileName);
142144
if (has(this.snapshots, fileName))
143145
return this.snapshots[fileName];
144146
if (existsSync(fileName)) {
@@ -152,6 +154,7 @@ var LanguageServiceHost = (function () {
152154
return this.cwd;
153155
};
154156
LanguageServiceHost.prototype.getScriptVersion = function (fileName) {
157+
fileName = this.normalize(fileName);
155158
return (this.versions[fileName] || 0).toString();
156159
};
157160
LanguageServiceHost.prototype.getScriptFileNames = function () {
@@ -163,6 +166,9 @@ var LanguageServiceHost = (function () {
163166
LanguageServiceHost.prototype.getDefaultLibFileName = function (opts) {
164167
return getDefaultLibFilePath(opts);
165168
};
169+
LanguageServiceHost.prototype.normalize = function (fileName) {
170+
return fileName.split("\\").join("/");
171+
};
166172
return LanguageServiceHost;
167173
}());
168174

src/host.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
2020

2121
public setSnapshot(fileName: string, data: string): ts.IScriptSnapshot
2222
{
23+
fileName = this.normalize(fileName);
24+
2325
let snapshot = ts.ScriptSnapshot.fromString(data);
2426
this.snapshots[fileName] = snapshot;
2527
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
@@ -28,6 +30,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
2830

2931
public getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined
3032
{
33+
fileName = this.normalize(fileName);
34+
3135
if (_.has(this.snapshots, fileName))
3236
return this.snapshots[fileName];
3337

@@ -48,6 +52,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
4852

4953
public getScriptVersion(fileName: string)
5054
{
55+
fileName = this.normalize(fileName);
56+
5157
return (this.versions[fileName] || 0).toString();
5258
}
5359

@@ -65,4 +71,9 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
6571
{
6672
return ts.getDefaultLibFilePath(opts);
6773
}
74+
75+
private normalize(fileName: string)
76+
{
77+
return fileName.split("\\").join("/");
78+
}
6879
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"listFiles": true,
1212
"pretty": true,
1313
"moduleResolution": "node",
14-
"noEmitOnError": true,
14+
"noEmitOnError": false,
1515
"strictNullChecks": true,
1616
"forceConsistentCasingInFileNames": true,
1717
"noImplicitReturns": true

0 commit comments

Comments
 (0)