Skip to content

Commit 53f79db

Browse files
committed
Add files exclude based on the minimatch library,
fix #11
1 parent b5f36d8 commit 53f79db

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

package.js

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

99
Npm.depends({
1010
'meteor-typescript': 'https://github.com/barbatus/meteor-typescript/tarball/35661eed0a5cbe017e8213527d144eab61614dbc',
11-
'async': '1.4.0'
11+
'async': '1.4.0',
12+
'minimatch': '3.0.0'
1213
});
1314

1415
Package.onUse(function(api) {

run_tests_ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
rm -fr "~/.cache"
44

5-
VELOCITY_TEST_PACKAGES=1 TYPESCRIPT_CACHE_DIR="~/.cache" meteor test-packages --velocity ./
5+
VELOCITY_TEST_PACKAGES=1 TYPESCRIPT_CACHE_DIR="~/.cache" meteor test-packages --release=1.2.1 --velocity ./

tests/server/unit/compiler-tests_spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ describe('typescript-compiler', () => {
2222

2323
expect(inputFile.result.data).toContain('System.register(\"foo2\"');
2424
});
25+
26+
it('should exclude from node_modules by default', () => {
27+
let compiler = new TypeScriptCompiler();
28+
29+
let inputFile = new InputFile(testCodeLine, 'node_modules/foo3.ts');
30+
compiler.processFilesForTarget([inputFile]);
31+
32+
expect(inputFile.result).toBeNull();
33+
});
2534
});
2635

2736
describe('testing tsconfig.json', () => {
@@ -43,6 +52,18 @@ describe('typescript-compiler', () => {
4352
compiler.processFilesForTarget([inputFile, configFile]);
4453
expect(inputFile.result.data).toContain('exports.foo');
4554
});
55+
56+
it('should exclude files using patterns in tsconfig.exclude', () => {
57+
let compiler = new TypeScriptCompiler();
58+
59+
let configFile = new ConfigFile({
60+
exclude: ['foo/**']
61+
});
62+
let inputFile = new InputFile(testCodeLine, 'foo/foo4.ts');
63+
compiler.processFilesForTarget([inputFile, configFile]);
64+
65+
expect(inputFile.result).toBeNull();
66+
});
4667
});
4768

4869
describe('testing diagnostics', () => {

tests/server/unit/input-file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ InputFile = class InputFile {
1010
constructor(source, fileName, arch) {
1111
this.source = source;
1212
this.fileName = fileName;
13+
this.result = null;
1314
this.arch = arch || 'os';
1415
}
1516

typescript-compiler.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const async = Npm.require('async');
22
const Future = Npm.require('fibers/future');
3+
const minimatch = Npm.require('minimatch');
34
const TSBuild = Npm.require('meteor-typescript').TSBuild;
45

56
TypeScriptCompiler = class TypeScriptCompiler {
@@ -9,6 +10,8 @@ TypeScriptCompiler = class TypeScriptCompiler {
910
this.extraOptions = extraOptions;
1011
this.maxParallelism = maxParallelism || 10;
1112
this.tsconfig = TypeScript.getDefaultOptions();
13+
this.defExclude = ['node_modules/**'];
14+
this.tsconfig.exclude = this.defExclude;
1215
this.cfgHash = null;
1316
}
1417

@@ -18,6 +21,8 @@ TypeScriptCompiler = class TypeScriptCompiler {
1821
// If tsconfig.json has changed, create new one.
1922
this.processConfig(inputFiles);
2023

24+
inputFiles = this.excludeFiles(inputFiles);
25+
2126
let archMap = {}, filesMap = {};
2227
inputFiles.forEach((inputFile, index) => {
2328
if (inputFile.isConfig()) return;
@@ -165,17 +170,41 @@ TypeScriptCompiler = class TypeScriptCompiler {
165170
parseConfig(cfgContent) {
166171
try {
167172
let tsconfig = JSON.parse(cfgContent);
168-
if (tsconfig.files) {
169-
// Allow only typings in the "files" array.
170-
tsconfig.typings = this.getTypings(tsconfig.files);
173+
174+
let files = tsconfig.files || [];
175+
if (! _.isArray(files)) {
176+
throw new Error('[tsconfig]: files is not array');
171177
}
178+
// Allow only typings in the "files" array.
179+
tsconfig.typings = this.getTypings(files);
180+
181+
let exclude = tsconfig.exclude || [];
182+
if (! _.isArray(exclude)) {
183+
throw new Error('[tsconfig]: exclude is not array');
184+
}
185+
tsconfig.exclude = exclude.concat(this.defExclude);
172186

173187
return tsconfig;
174188
} catch(err) {
175189
throw new Error(`Format of the tsconfig is invalid: ${err}`);
176190
}
177191
}
178192

193+
excludeFiles(inputFiles) {
194+
let resultFiles = inputFiles;
195+
196+
let dexclude = Logger.newDebug('exclude');
197+
for (let ex of this.tsconfig.exclude) {
198+
resultFiles = resultFiles.filter(inputFile => {
199+
dexclude.log('exclude pattern %s', ex);
200+
return ! minimatch(inputFile.getPathInPackage(), ex);
201+
});
202+
}
203+
dexclude.end();
204+
205+
return resultFiles;
206+
}
207+
179208
getTypings(filePaths) {
180209
check(filePaths, Array);
181210

0 commit comments

Comments
 (0)