1
1
const async = Npm . require ( 'async' ) ;
2
2
const Future = Npm . require ( 'fibers/future' ) ;
3
+ const minimatch = Npm . require ( 'minimatch' ) ;
3
4
const TSBuild = Npm . require ( 'meteor-typescript' ) . TSBuild ;
4
5
5
6
TypeScriptCompiler = class TypeScriptCompiler {
@@ -9,6 +10,8 @@ TypeScriptCompiler = class TypeScriptCompiler {
9
10
this . extraOptions = extraOptions ;
10
11
this . maxParallelism = maxParallelism || 10 ;
11
12
this . tsconfig = TypeScript . getDefaultOptions ( ) ;
13
+ this . defExclude = [ 'node_modules/**' ] ;
14
+ this . tsconfig . exclude = this . defExclude ;
12
15
this . cfgHash = null ;
13
16
}
14
17
@@ -18,6 +21,8 @@ TypeScriptCompiler = class TypeScriptCompiler {
18
21
// If tsconfig.json has changed, create new one.
19
22
this . processConfig ( inputFiles ) ;
20
23
24
+ inputFiles = this . excludeFiles ( inputFiles ) ;
25
+
21
26
let archMap = { } , filesMap = { } ;
22
27
inputFiles . forEach ( ( inputFile , index ) => {
23
28
if ( inputFile . isConfig ( ) ) return ;
@@ -165,17 +170,41 @@ TypeScriptCompiler = class TypeScriptCompiler {
165
170
parseConfig ( cfgContent ) {
166
171
try {
167
172
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' ) ;
171
177
}
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 ) ;
172
186
173
187
return tsconfig ;
174
188
} catch ( err ) {
175
189
throw new Error ( `Format of the tsconfig is invalid: ${ err } ` ) ;
176
190
}
177
191
}
178
192
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
+
179
208
getTypings ( filePaths ) {
180
209
check ( filePaths , Array ) ;
181
210
0 commit comments