Skip to content

Commit 8f8dd59

Browse files
committed
Meteor's input file contents are now supplied via getFileContent callback to avoid reading them
from the disk by the compiler itself (thus avoiding overhead). Mirror corrections to the tests. Urigo/angular2-meteor#102
1 parent 664df6e commit 8f8dd59

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

compiler-tests.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let testCodeLine = 'export const foo = "foo"';
4848
Tinytest.add('typescript - compiler - default options', (test) => {
4949
let compiler = new TypeScriptCompiler();
5050

51-
let inputFile = new InputFile(testCodeLine, 'foo.ts');
51+
let inputFile = new InputFile(testCodeLine, 'foo1.ts');
5252
compiler.processFilesForTarget([inputFile]);
5353

5454
test.isNotNull(inputFile.result,
@@ -62,10 +62,10 @@ Tinytest.add('typescript - compiler - extra options', (test) => {
6262
module: 'system'
6363
});
6464

65-
let inputFile = new InputFile(testCodeLine, 'foo.ts');
65+
let inputFile = new InputFile(testCodeLine, 'foo2.ts');
6666
compiler.processFilesForTarget([inputFile]);
6767

68-
test.include(inputFile.result.data, 'System.register(\"foo\"',
68+
test.include(inputFile.result.data, 'System.register(\"foo2\"',
6969
'compilation result is wrong');
7070
});
7171

@@ -90,10 +90,10 @@ Tinytest.add('typescript - compiler - tsconfig.json - config applied and watched
9090
module: 'system'
9191
}
9292
});
93-
let inputFile = new InputFile(testCodeLine, 'foo.ts');
93+
let inputFile = new InputFile(testCodeLine, 'foo3.ts');
9494
compiler.processFilesForTarget([inputFile, configFile]);
9595

96-
test.include(inputFile.result.data, 'System.register(\"foo\"',
96+
test.include(inputFile.result.data, 'System.register(\"foo3\"',
9797
'compilation result is wrong');
9898

9999
// Testing that config changes are watched.
@@ -103,7 +103,6 @@ Tinytest.add('typescript - compiler - tsconfig.json - config applied and watched
103103
'module change has no affect');
104104
});
105105

106-
107106
Tinytest.add('typescript - compiler - diagnostics - always turned on by default', (test) => {
108107
let logged = false;
109108
let compiler = new TypeScriptCompiler(null, null, msg => {
@@ -115,8 +114,8 @@ Tinytest.add('typescript - compiler - diagnostics - always turned on by default'
115114
module: 'system'
116115
}
117116
});
118-
let wrongImport = 'import {api} from "lib"';
119-
let inputFile = new InputFile(wrongImport, 'foo.ts');
117+
let wrongImport = 'import {api} from "lib";';
118+
let inputFile = new InputFile(wrongImport, 'foo4.ts');
120119
compiler.processFilesForTarget([inputFile, configFile]);
121120

122121
test.isTrue(logged, 'Diagnostics was not logged');

package.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Package.describe({
22
name: 'barbatus:typescript-compiler',
3-
version: '0.5.0-beta.3',
3+
version: '0.5.0-beta.4',
44
summary: 'TypeScript Compiler for Meteor',
55
git: 'https://github.com/barbatus/ts-compilers',
66
documentation: 'README.md'
77
});
88

99
Npm.depends({
10-
'meteor-typescript': '0.5.8',
10+
'meteor-typescript': '0.6.0-beta.1',
1111
'async': '1.4.0'
1212
});
1313

typescript-compiler.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ TypeScriptCompiler = class TypeScriptCompiler {
1818
// If tsconfig.json has changed, create new one.
1919
this.processConfig(inputFiles);
2020

21+
let filesSourceMap = new Map();
22+
inputFiles.forEach((inputFile, index) => {
23+
if (this.isConfigFile(inputFile)) return;
24+
25+
filesSourceMap.set(this.getExtendedPath(inputFile), index);
26+
});
27+
let getFileContent = filePath => {
28+
let index = filesSourceMap.get(filePath);
29+
return index !== undefined ?
30+
inputFiles[index].getContentsAsString() : null;
31+
};
32+
2133
// Filters out typings and tsconfig.
2234
// Other files should be compiled.
2335
let tsFiles = inputFiles.filter(inputFile =>
@@ -58,11 +70,12 @@ TypeScriptCompiler = class TypeScriptCompiler {
5870
typings
5971
};
6072

61-
let result = TypeScript.compile(source, options);
73+
let result = TypeScript.compile(getFileContent, options);
6274
this.processDiagnostics(inputFile,
6375
result.diagnostics, compilerOptions);
6476

6577
toBeAdded.data = result.code;
78+
toBeAdded.hash = result.hash;
6679
toBeAdded.sourceMap = result.sourceMap;
6780

6881
inputFile.addJavaScript(toBeAdded);

0 commit comments

Comments
 (0)