Skip to content

Commit 5104305

Browse files
committed
New change to force compiler re-compile a file for different module names
Fix bug in how changes of the files evaluated when constructing the rebuild map Add new test Urigo/angular2-meteor#102
1 parent 5ddd131 commit 5104305

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

cache.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ CCp.get = function(filePath, options, compileFn, force) {
160160
return compileResult;
161161
};
162162

163+
CCp.save = function(filePath, options, compileResult) {
164+
var source = sourceHost.get(filePath);
165+
var cacheKey = utils.deepHash(pkgVersion, source, options);
166+
167+
this._save(cacheKey, compileResult);
168+
};
169+
163170
CCp.getOrDie = function(filePath, options) {
164171
var source = sourceHost.get(filePath);
165172
var cacheKey = utils.deepHash(pkgVersion, source, options);
@@ -186,6 +193,7 @@ CCp.resultChanged = function(filePath, options) {
186193

187194
exports.CompileCache = CompileCache;
188195

196+
189197
function FileCache(cacheDir) {
190198
Cache.apply(this);
191199
this.cacheDir = ensureCacheDir(cacheDir);

compile-service-host.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ SH.setFiles = function(filePaths, options) {
3232
this.files[filePath] = { version: 0 };
3333
}
3434

35+
if (! this.fileCache.isChanged(filePath)) {
36+
this.files[filePath].changed = false;
37+
}
38+
3539
if (this.fileCache.isChanged(filePath)) {
3640
this.files[filePath].version++;
3741
this.files[filePath].changed = true;
@@ -40,6 +44,7 @@ SH.setFiles = function(filePaths, options) {
4044
typingsChanged = true;
4145
}
4246
this.fileCache.save(filePath);
47+
return;
4348
}
4449
}, this);
4550

compile-service.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ CP.getSourceFile = function(filePath) {
5757
return sourceFile;
5858
};
5959

60+
CP.getReferences = function(filePath) {
61+
return tsu.getReferences(this.getSourceFile(filePath));
62+
};
63+
6064
CP.getDiagnostics = function(filePath) {
6165
// Parse diagnostics.
6266
var syntactic = tsu.flattenDiagnostics(

index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ function getRebuildMap(filePaths, options) {
100100
}
101101

102102
_.each(filePaths, function(filePath) {
103-
if (! compileCache.resultChanged(filePath, options)) {
104-
var result = compileCache.getOrDie(filePath, options);
105-
var refs = result.references;
103+
if (! serviceHost.isFileChanged(filePath)) {
104+
var refs = compileService.getReferences(filePath);
106105
if (refs) {
107106
files[filePath] = rebuildWithNewTypings(refs.typings);
108107
if (files[filePath]) {
@@ -112,7 +111,7 @@ function getRebuildMap(filePaths, options) {
112111
var modules = refs.modules;
113112
var mLen = modules.length;
114113
for (var i = 0; i < mLen; i++) {
115-
if (compileCache.resultChanged(modules[i], options)) {
114+
if (serviceHost.isFileChanged(modules[i])) {
116115
files[filePath] = true;
117116
break;
118117
}
@@ -134,11 +133,17 @@ BP.emit = function(filePath, moduleName) {
134133
var options = this.options;
135134
var useCache = options && options.useCache;
136135

136+
// Prepare file options which besides general ones
137+
// should contain a module name.
138+
var fOptions = {options: options , moduleName: moduleName};
139+
137140
if (useCache === false) {
138-
return compileService.compile(filePath, moduleName);
141+
var result = compileService.compile(filePath, moduleName);
142+
//compileCache.save(filePath, fOptions, result);
143+
return result;
139144
}
140145

141-
return compileCache.get(filePath, options, function() {
146+
return compileCache.get(filePath, fOptions, function() {
142147
Logger.debug("cache miss: %s", filePath);
143148
return compileService.compile(filePath, moduleName);
144149
}, this.rebuildMap[filePath]);

tests/ts.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,23 @@ describe("meteor-typescript -> ", function() {
306306

307307
expect(result3).toEqual(result1);
308308
});
309+
310+
it("should re-compile for a new module name", function() {
311+
var options = {
312+
compilerOptions: {
313+
module: "system"
314+
}
315+
};
316+
var build1 = new TSBuild(["foo14.ts"], function(filePath) {
317+
if (filePath === "foo14.ts") return testCodeLine;
318+
}, options);
319+
var result1 = build1.emit("foo14.ts", "foo");
320+
321+
expect(result1.code).toContain("System.register(\"foo");
322+
323+
var result2 = build1.emit("foo14.ts", "foo1");
324+
325+
expect(result2.code).toContain("System.register(\"foo1");
326+
});
309327
});
310328
});

0 commit comments

Comments
 (0)