@@ -252,13 +252,8 @@ export function create (options: CreateOptions = {}): Register {
252
252
...( options . ignoreDiagnostics || [ ] )
253
253
] . map ( Number )
254
254
255
- const ignore = options . skipIgnore ? [ ] : (
256
- options . ignore || [ '/node_modules/' ]
257
- ) . map ( str => new RegExp ( str ) )
258
-
259
255
// Require the TypeScript compiler and configuration.
260
256
const cwd = options . dir ? resolve ( options . dir ) : process . cwd ( )
261
- const isScoped = options . scope ? ( fileName : string ) => relative ( cwd , fileName ) . charAt ( 0 ) !== '.' : ( ) => true
262
257
const typeCheck = options . typeCheck === true || options . transpileOnly !== true
263
258
const compiler = require . resolve ( options . compiler || 'typescript' , { paths : [ cwd , __dirname ] } )
264
259
const ts : typeof _ts = require ( compiler )
@@ -269,6 +264,11 @@ export function create (options: CreateOptions = {}): Register {
269
264
const configDiagnosticList = filterDiagnostics ( config . errors , ignoreDiagnostics )
270
265
const outputCache = new Map < string , string > ( )
271
266
267
+ const isScoped = options . scope ? ( relname : string ) => relname . charAt ( 0 ) !== '.' : ( ) => true
268
+ const shouldIgnore = createIgnore ( options . skipIgnore ? [ ] : (
269
+ options . ignore || [ '/node_modules/' ]
270
+ ) . map ( str => new RegExp ( str ) ) )
271
+
272
272
const diagnosticHost : _ts . FormatDiagnosticsHost = {
273
273
getNewLine : ( ) => ts . sys . newLine ,
274
274
getCurrentDirectory : ( ) => cwd ,
@@ -462,18 +462,24 @@ export function create (options: CreateOptions = {}): Register {
462
462
463
463
let active = true
464
464
const enabled = ( enabled ?: boolean ) => enabled === undefined ? active : ( active = ! ! enabled )
465
- const ignored = ( fileName : string ) => ! active || ! isScoped ( fileName ) || shouldIgnore ( fileName , ignore )
465
+ const ignored = ( fileName : string ) => {
466
+ if ( ! active ) return true
467
+ const relname = relative ( cwd , fileName )
468
+ return ! isScoped ( relname ) || shouldIgnore ( relname )
469
+ }
466
470
467
471
return { ts, config, compile, getTypeInfo, ignored, enabled }
468
472
}
469
473
470
474
/**
471
475
* Check if the filename should be ignored.
472
476
*/
473
- function shouldIgnore ( filename : string , ignore : RegExp [ ] ) {
474
- const relname = normalizeSlashes ( filename )
477
+ function createIgnore ( ignore : RegExp [ ] ) {
478
+ return ( relname : string ) => {
479
+ const path = normalizeSlashes ( relname )
475
480
476
- return ignore . some ( x => x . test ( relname ) )
481
+ return ignore . some ( x => x . test ( path ) )
482
+ }
477
483
}
478
484
479
485
/**
0 commit comments