Skip to content

Commit

Permalink
New change to force compiler re-compile a file for different module n…
Browse files Browse the repository at this point in the history
…ames

Fix bug in how changes of the files evaluated when constructing the rebuild map
Add new test

Urigo/angular2-meteor#102
  • Loading branch information
barbatus committed Mar 14, 2016
1 parent 5ddd131 commit 5104305
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
8 changes: 8 additions & 0 deletions cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ CCp.get = function(filePath, options, compileFn, force) {
return compileResult;
};

CCp.save = function(filePath, options, compileResult) {
var source = sourceHost.get(filePath);
var cacheKey = utils.deepHash(pkgVersion, source, options);

this._save(cacheKey, compileResult);
};

CCp.getOrDie = function(filePath, options) {
var source = sourceHost.get(filePath);
var cacheKey = utils.deepHash(pkgVersion, source, options);
Expand All @@ -186,6 +193,7 @@ CCp.resultChanged = function(filePath, options) {

exports.CompileCache = CompileCache;


function FileCache(cacheDir) {
Cache.apply(this);
this.cacheDir = ensureCacheDir(cacheDir);
Expand Down
5 changes: 5 additions & 0 deletions compile-service-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ SH.setFiles = function(filePaths, options) {
this.files[filePath] = { version: 0 };
}

if (! this.fileCache.isChanged(filePath)) {
this.files[filePath].changed = false;
}

if (this.fileCache.isChanged(filePath)) {
this.files[filePath].version++;
this.files[filePath].changed = true;
Expand All @@ -40,6 +44,7 @@ SH.setFiles = function(filePaths, options) {
typingsChanged = true;
}
this.fileCache.save(filePath);
return;
}
}, this);

Expand Down
4 changes: 4 additions & 0 deletions compile-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ CP.getSourceFile = function(filePath) {
return sourceFile;
};

CP.getReferences = function(filePath) {
return tsu.getReferences(this.getSourceFile(filePath));
};

CP.getDiagnostics = function(filePath) {
// Parse diagnostics.
var syntactic = tsu.flattenDiagnostics(
Expand Down
17 changes: 11 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ function getRebuildMap(filePaths, options) {
}

_.each(filePaths, function(filePath) {
if (! compileCache.resultChanged(filePath, options)) {
var result = compileCache.getOrDie(filePath, options);
var refs = result.references;
if (! serviceHost.isFileChanged(filePath)) {
var refs = compileService.getReferences(filePath);
if (refs) {
files[filePath] = rebuildWithNewTypings(refs.typings);
if (files[filePath]) {
Expand All @@ -112,7 +111,7 @@ function getRebuildMap(filePaths, options) {
var modules = refs.modules;
var mLen = modules.length;
for (var i = 0; i < mLen; i++) {
if (compileCache.resultChanged(modules[i], options)) {
if (serviceHost.isFileChanged(modules[i])) {
files[filePath] = true;
break;
}
Expand All @@ -134,11 +133,17 @@ BP.emit = function(filePath, moduleName) {
var options = this.options;
var useCache = options && options.useCache;

// Prepare file options which besides general ones
// should contain a module name.
var fOptions = {options: options , moduleName: moduleName};

if (useCache === false) {
return compileService.compile(filePath, moduleName);
var result = compileService.compile(filePath, moduleName);
//compileCache.save(filePath, fOptions, result);
return result;
}

return compileCache.get(filePath, options, function() {
return compileCache.get(filePath, fOptions, function() {
Logger.debug("cache miss: %s", filePath);
return compileService.compile(filePath, moduleName);
}, this.rebuildMap[filePath]);
Expand Down
18 changes: 18 additions & 0 deletions tests/ts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,23 @@ describe("meteor-typescript -> ", function() {

expect(result3).toEqual(result1);
});

it("should re-compile for a new module name", function() {
var options = {
compilerOptions: {
module: "system"
}
};
var build1 = new TSBuild(["foo14.ts"], function(filePath) {
if (filePath === "foo14.ts") return testCodeLine;
}, options);
var result1 = build1.emit("foo14.ts", "foo");

expect(result1.code).toContain("System.register(\"foo");

var result2 = build1.emit("foo14.ts", "foo1");

expect(result2.code).toContain("System.register(\"foo1");
});
});
});

0 comments on commit 5104305

Please sign in to comment.