Skip to content

Commit b909ca1

Browse files
committed
Bump meteor-typescript NPM version,
process typings accordingly to the structure the typings util lays them out (main and browser), minor improvements to the logging Urigo/angular2-meteor#102
1 parent 788a543 commit b909ca1

File tree

3 files changed

+73
-44
lines changed

3 files changed

+73
-44
lines changed

logger.js

+24-16
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,49 @@ const util = Npm.require('util');
22

33
class Logger_ {
44
constructor() {
5-
this.llevel = process.env.TYPESCRIPT_LOG;
5+
this.llevel = process.env.TYPESCRIPT_LOG;
66
}
77

8-
newDebug(name) {
9-
let debug = new Debug(name);
10-
if (this.isDebug) debug.start();
11-
return debug;
8+
newProfiler(name) {
9+
let profiler = new Profiler(name);
10+
if (this.isProfile) profiler.start();
11+
return profiler;
1212
}
1313

1414
get isDebug() {
1515
return this.llevel >= 2;
1616
}
1717

18-
log(msg) {
18+
get isProfile() {
19+
return this.llevel >= 3;
20+
}
21+
22+
get isAssert() {
23+
return this.llevel >= 4;
24+
}
25+
26+
log(msg, ...args) {
1927
if (this.llevel >= 1) {
20-
console.log(msg);
28+
console.log.apply(null, [msg].concat(args));
2129
}
2230
}
2331

24-
debug(msg) {
32+
debug(msg, ...args) {
2533
if (this.isDebug) {
26-
console.log(msg);
34+
this.log.apply(this, msg, args);
35+
}
36+
}
37+
38+
assert(msg, ...args) {
39+
if (this.isAssert) {
40+
this.log.apply(this, msg, args);
2741
}
2842
}
2943
};
3044

3145
Logger = new Logger_();
3246

33-
class Debug {
47+
class Profiler {
3448
constructor(name) {
3549
this.name = name;
3650
}
@@ -41,12 +55,6 @@ class Debug {
4155
this._started = true;
4256
}
4357

44-
log(msg, ...args) {
45-
if (this._started) {
46-
console.log.apply(null, [msg].concat(args));
47-
}
48-
}
49-
5058
end() {
5159
if (this._started) {
5260
console.timeEnd(util.format('%s time', this.name));

package.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Package.describe({
22
name: 'barbatus:typescript-compiler',
3-
version: '0.5.7',
3+
version: '0.5.9',
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.6.4',
10+
'meteor-typescript': '0.6.9',
1111
'async': '1.4.0',
1212
'minimatch': '3.0.0'
1313
});

typescript-compiler.js

+47-26
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ TypeScriptCompiler = class TypeScriptCompiler {
2323

2424
inputFiles = this.excludeFiles(inputFiles);
2525

26-
let archMap = {}, filesMap = {};
26+
let filesMap = {}, archMap = {};
2727
inputFiles.forEach((inputFile, index) => {
28-
if (inputFile.isConfig()) return;
29-
30-
let arch = inputFile.getArch();
31-
let archFiles = archMap[arch];
32-
if (! archFiles) {
33-
archFiles = [];
34-
archMap[arch] = archFiles;
35-
}
36-
archFiles.push(inputFile);
3728
filesMap[this.getExtendedPath(inputFile)] = index;
29+
archMap[inputFile.getArch()] = [];
30+
});
31+
32+
_.keys(archMap).forEach(arch => {
33+
let archFiles = this.getArchFiles(inputFiles, arch);
34+
archMap[arch] = archFiles;
3835
});
3936

4037
let getFileContent = filePath => {
@@ -51,20 +48,21 @@ TypeScriptCompiler = class TypeScriptCompiler {
5148
let useCache = this.tsconfig.useCache;
5249
let buildOptions = { compilerOptions, typings, useCache };
5350

54-
let dcompile = Logger.newDebug('compilation');
51+
let pcompile = Logger.newProfiler('compilation');
5552
_.keys(archMap).forEach((arch, cb) => {
5653
let archFiles = archMap[arch];
5754
let filePaths = archFiles.map(inputFile => this.getExtendedPath(inputFile));
58-
dcompile.log('process files: %s', filePaths);
55+
Logger.log('process files: %s', filePaths);
5956
buildOptions.arch = arch;
60-
61-
let dbuild = Logger.newDebug('tsBuild');
57+
let pbuild = Logger.newProfiler('tsBuild');
6258
let tsBuild = new TSBuild(filePaths, getFileContent, buildOptions);
59+
pbuild.end();
6360

61+
let pfiles = Logger.newProfiler('tsEmitFiles');
6462
let future = new Future;
65-
async.each(archFiles, (inputFile, cb) => {
66-
if (inputFile.isDeclaration()) { cb(); return; };
67-
63+
// Don't emit typings.
64+
archFiles = archFiles.filter(inputFile => !inputFile.isDeclaration());
65+
async.eachLimit(archFiles, this.maxParallelism, (inputFile, cb) => {
6866
let co = compilerOptions;
6967
let source = inputFile.getContentsAsString();
7068
let inputFilePath = inputFile.getPathInPackage();
@@ -81,28 +79,27 @@ TypeScriptCompiler = class TypeScriptCompiler {
8179
let filePath = this.getExtendedPath(inputFile);
8280
let moduleName = this.getFileModuleName(inputFile, co);
8381

84-
let demit = Logger.newDebug('tsEmit');
82+
let pemit = Logger.newProfiler('tsEmit');
8583
let result = tsBuild.emit(filePath, moduleName);
8684
this.processDiagnostics(inputFile, result.diagnostics, co);
87-
demit.end();
85+
pemit.end();
8886

8987
toBeAdded.data = result.code;
9088
let module = compilerOptions.module;
9189
toBeAdded.bare = toBeAdded.bare || module === 'none';
9290
toBeAdded.hash = result.hash;
9391
toBeAdded.sourceMap = result.sourceMap;
94-
9592
inputFile.addJavaScript(toBeAdded);
9693

9794
cb();
9895
}, future.resolver());
9996

100-
future.wait();
97+
pfiles.end();
10198

102-
dbuild.end();
99+
future.wait();
103100
});
104101

105-
dcompile.end();
102+
pcompile.end();
106103
}
107104

108105
extendFiles(inputFiles, mixins) {
@@ -193,19 +190,43 @@ TypeScriptCompiler = class TypeScriptCompiler {
193190
excludeFiles(inputFiles) {
194191
let resultFiles = inputFiles;
195192

196-
let dexclude = Logger.newDebug('exclude');
193+
let pexclude = Logger.newProfiler('exclude');
197194
for (let ex of this.tsconfig.exclude) {
198195
resultFiles = resultFiles.filter(inputFile => {
199196
let path = inputFile.getPathInPackage();
200-
dexclude.log('exclude pattern %s: %s', ex, path);
197+
Logger.assert('exclude pattern %s: %s', ex, path);
201198
return ! minimatch(path, ex);
202199
});
203200
}
204-
dexclude.end();
201+
pexclude.end();
205202

206203
return resultFiles;
207204
}
208205

206+
getArchFiles(inputFiles, arch) {
207+
let archFiles = inputFiles.filter((inputFile, index) => {
208+
if (inputFile.isConfig()) return false;
209+
210+
return inputFile.getArch() === arch;
211+
});
212+
213+
// Include only typings that current arch needs,
214+
// typings/main is for the server only and
215+
// typings/browser - for the client.
216+
let excludes = arch.startsWith('web') ?
217+
['typings/main/**', 'typings/main.d.ts'] :
218+
['typings/browser/**', 'typings/browser.d.ts'];
219+
220+
for (let ex of excludes) {
221+
archFiles = archFiles.filter(inputFile => {
222+
let path = inputFile.getPathInPackage();
223+
return ! minimatch(path, ex);
224+
});
225+
}
226+
227+
return archFiles;
228+
}
229+
209230
getTypings(filePaths) {
210231
check(filePaths, Array);
211232

0 commit comments

Comments
 (0)