meteor-typescript
Advanced tools
Comparing version
@@ -26,9 +26,6 @@ "use strict"; | ||
this.options = options; | ||
var typingsChanged = false; | ||
var typings = {}; | ||
this.filePaths = filePaths; | ||
var arch = options && options.arch; | ||
_.each(filePaths, function(filePath) { | ||
var isTypings = tsu.isTypings(filePath); | ||
if (isTypings) typings[filePath] = true; | ||
if (! this.files[filePath]) { | ||
@@ -38,4 +35,4 @@ this.files[filePath] = { version: 0 }; | ||
var arch = options.arch; | ||
var source = sourceHost.get(filePath); | ||
this.files[filePath].changed = false; | ||
// Use file path with the current dir for the cache | ||
@@ -45,11 +42,5 @@ // to avoid same file names coincidences between apps. | ||
var fileChanged = this.fileCache.isChanged(fullPath, arch, source); | ||
this.files[filePath].changed = false; | ||
if (fileChanged) { | ||
this.files[filePath].version++; | ||
this.files[filePath].changed = true; | ||
if (isTypings) { | ||
Logger.debug("declaration file %s changed", filePath); | ||
typingsChanged = true; | ||
} | ||
this.fileCache.save(fullPath, arch, source); | ||
@@ -60,19 +51,55 @@ return; | ||
this.typingsChanged = typingsChanged; | ||
this.typings = _.filter(filePaths, function(filePath) { | ||
return tsu.isTypings(filePath); | ||
}); | ||
this.typingsChanged = this.setTypings(this.typings, options); | ||
}; | ||
SH.addTypings = function(typings) { | ||
typings = this.typings.concat(typings); | ||
this.typingsChanged = this.setTypings(typings, this.options); | ||
}; | ||
SH.setTypings = function(typings, options) { | ||
var dtsMap = {}; | ||
var arch = options && options.arch; | ||
var typingsChanged = false; | ||
for (var i = 0; i < typings.length; i++) { | ||
var filePath = typings[i]; | ||
if (this.hasFile(filePath)) { | ||
dtsMap[filePath] = true; | ||
if (this.isFileChanged(filePath)) { | ||
Logger.debug("declaration file %s changed", filePath); | ||
typingsChanged = true; | ||
} | ||
continue; | ||
} | ||
var fullPath = ts.combinePaths(this.curDir, filePath); | ||
var source = this.getFile(fullPath); | ||
if (source) { | ||
dtsMap[filePath] = true; | ||
var fileChanged = this.fileCache.isChanged(fullPath, arch, source); | ||
if (fileChanged) { | ||
this.fileCache.save(fullPath, arch, source); | ||
} | ||
typingsChanged = typingsChanged || fileChanged; | ||
} | ||
}; | ||
// Investigate if the number of declaration files have changed. | ||
// In the positive case, we'll need to revaluate diagnostics | ||
// for all files of specific architecture. | ||
if (options && options.arch) { | ||
var arch = options.arch; | ||
// Check if the typings array differs from the previous value. | ||
typingsChanged = this.fileCache.isChanged(this.appId, arch, typings); | ||
if (typingsChanged) { | ||
if (arch) { | ||
// Check if typings map differs from the previous value. | ||
var mapChanged = this.fileCache.isChanged(this.appId, arch, dtsMap); | ||
if (mapChanged) { | ||
Logger.debug("typings of %s changed", arch); | ||
this.typingsChanged = typingsChanged; | ||
typingsChanged = mapChanged; | ||
} | ||
this.fileCache.save(this.appId, arch, typings); | ||
this.fileCache.save(this.appId, arch, dtsMap); | ||
} | ||
}; | ||
return typingsChanged; | ||
} | ||
SH.isFileChanged = function(filePath) { | ||
@@ -85,3 +112,4 @@ var normPath = sourceHost.normalizePath(filePath); | ||
SH.hasFile = function(filePath) { | ||
return !! this.files[filePath]; | ||
var normPath = sourceHost.normalizePath(filePath); | ||
return !! this.files[normPath]; | ||
}; | ||
@@ -125,2 +153,7 @@ | ||
var fileContent = this.getFile(filePath); | ||
return fileContent ? new StringScriptSnapshot(fileContent) : null; | ||
}; | ||
SH.getFile = function(filePath) { | ||
// Read node_modules files optimistically. | ||
@@ -132,4 +165,3 @@ var fileContent = this.fileContentMap.get(filePath); | ||
} | ||
return fileContent ? new StringScriptSnapshot(fileContent) : null; | ||
return fileContent; | ||
}; | ||
@@ -136,0 +168,0 @@ |
@@ -78,2 +78,7 @@ "use strict"; | ||
CP.getRefTypings = function(filePath) { | ||
var refs = tsu.getRefs(this.getSourceFile(filePath)); | ||
return refs.refTypings; | ||
}; | ||
CP.getTypeChecker = function() { | ||
@@ -80,0 +85,0 @@ return this.service.getProgram().getTypeChecker(); |
11
index.js
@@ -78,3 +78,2 @@ "use strict"; | ||
if (! arch) arch = "global"; | ||
if (serviceMap[arch]) return serviceMap[arch]; | ||
@@ -128,3 +127,11 @@ | ||
var serviceHost = compileService.getHost(); | ||
serviceHost.setFiles(filePaths, resOptions); | ||
if (filePaths) { | ||
serviceHost.setFiles(filePaths, resOptions); | ||
var refTypings = []; | ||
for (var i = 0; i < filePaths.length; i++) { | ||
var refTypings = refTypings.concat( | ||
compileService.getRefTypings(filePaths[i])); | ||
} | ||
serviceHost.addTypings(refTypings); | ||
} | ||
pset.end(); | ||
@@ -131,0 +138,0 @@ } |
{ | ||
"name": "meteor-typescript", | ||
"author": "@barbatus", | ||
"version": "0.7.4-beta.6", | ||
"version": "0.7.4-beta.7", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "description": "TypeScript wrapper package for use with Meteor", |
var ts = require("typescript"); | ||
var fs = require("fs"); | ||
@@ -3,0 +4,0 @@ var meteorTS = require("../index"); |
@@ -29,8 +29,6 @@ "use strict"; | ||
/** | ||
* Gets all local modules given sourceFile | ||
* uses types from (depends on). | ||
* Supports transitivity, i.e., | ||
* if some module (directly imported) re-exports | ||
* types from another module, | ||
* this another module will be in the output too. | ||
* Gets all local modules given sourceFile imports types from. | ||
* Supports transitivity, i.e., if some module (directly imported) | ||
* re-exports types from another module, this another module | ||
* will be in the output too. | ||
*/ | ||
@@ -97,3 +95,12 @@ function getDepModules(sourceFile, checker) { | ||
var modules = getDepModules(sourceFile, typeChecker); | ||
var refs = getRefs(sourceFile); | ||
return { | ||
modules: modules, | ||
refFiles: refs.refFiles, | ||
refTypings: refs.refTypings | ||
}; | ||
} | ||
function getRefs(sourceFile) { | ||
// Get references paths. | ||
@@ -121,3 +128,5 @@ // /// <reference path=".." /> | ||
var ref = sourceFile.resolvedTypeReferenceDirectiveNames[lib]; | ||
refTypings.push(ref.resolvedFileName); | ||
if (ref) { | ||
refTypings.push(ref.resolvedFileName); | ||
} | ||
} | ||
@@ -127,3 +136,2 @@ } | ||
return { | ||
modules: modules, | ||
refFiles: refFiles, | ||
@@ -219,2 +227,3 @@ refTypings: refTypings | ||
getDependencies: getDependencies, | ||
getRefs: getRefs, | ||
createDiagnostics: createDiagnostics, | ||
@@ -221,0 +230,0 @@ hasErrors: hasErrors, |
57461
2.75%1637
3.28%8
14.29%