@@ -6,6 +6,7 @@ import worker = require('./lib/worker.js');
66import glob = require( 'glob' ) ;
77import fs = require( 'fs' ) ;
88import os = require( 'os' ) ;
9+ import minimatch = require( 'minimatch' ) ;
910import languagePlugins = require( './lib/languagePlugins.js' ) ;
1011
1112process . env . TSSLINT_CLI = '1' ;
@@ -63,7 +64,7 @@ class Project {
6364 async init (
6465 // @ts -expect-error
6566 clack : typeof import ( '@clack/prompts' ) ,
66- filesFilter : Set < string >
67+ filesFilter : string [ ]
6768 ) {
6869 this . configFile = ts . findConfigFile ( path . dirname ( this . tsconfig ) , ts . sys . fileExists , 'tsslint.config.ts' ) ;
6970
@@ -106,10 +107,14 @@ class Project {
106107 return this ;
107108 }
108109
109- if ( filesFilter . size ) {
110- this . fileNames = this . rawFileNames . filter ( f => filesFilter . has ( f ) ) ;
110+ if ( filesFilter . length ) {
111+ this . fileNames = this . rawFileNames . filter (
112+ fileName => filesFilter . some (
113+ filter => minimatch . minimatch ( fileName , filter , { dot : true } )
114+ )
115+ ) ;
111116 if ( ! this . fileNames . length ) {
112- clack . log . warn ( `${ label } ${ path . relative ( process . cwd ( ) , this . tsconfig ) } ${ gray ( '(No files left after filter)' ) } ` ) ;
117+ clack . log . message ( `${ label } ${ gray ( path . relative ( process . cwd ( ) , this . tsconfig ) ) } ${ gray ( '(No files left after filter)' ) } ` ) ;
113118 return this ;
114119 }
115120 } else {
@@ -322,31 +327,34 @@ class Project {
322327 }
323328 }
324329
325- // get filter glob option
326- let filterSet : Set < string > = new Set ( ) ;
330+ function normalizeFilterGlobPath ( filterGlob : string , expandDirToGlob = true ) {
331+ let filterPath = path . resolve ( process . cwd ( ) , filterGlob ) ;
332+ if ( expandDirToGlob && fs . existsSync ( filterPath ) && fs . statSync ( filterPath ) . isDirectory ( ) ) {
333+ filterPath = path . join ( filterPath , '**/*' ) ;
334+ }
335+ return ts . server . toNormalizedPath ( filterPath ) ;
336+ }
327337
328- const filterArgIndex = process . argv . findIndex ( arg => arg === '--filter' ) ;
338+ const filters : string [ ] = [ ] ;
339+ const filterArgIndex = process . argv . indexOf ( '--filter' ) ;
329340 if ( filterArgIndex !== - 1 ) {
330- for ( let i = filterArgIndex + 1 ; i < process . argv . length ; i ++ ) {
341+ const filterGlob = process . argv [ filterArgIndex + 1 ] ;
342+ if ( ! filterGlob || filterGlob . startsWith ( '-' ) ) {
343+ clack . log . error ( red ( `Missing argument for --filter.` ) ) ;
344+ process . exit ( 1 ) ;
345+ }
346+ filters . push ( normalizeFilterGlobPath ( filterGlob ) ) ;
347+ for ( let i = filterArgIndex + 2 ; i < process . argv . length ; i ++ ) {
331348 const filterGlob = process . argv [ i ] ;
332- if ( ! filterGlob || filterGlob . startsWith ( '-' ) ) {
333- clack . log . error ( red ( `Missing argument for --filter.` ) ) ;
334- process . exit ( 1 ) ;
349+ if ( filterGlob . startsWith ( '-' ) ) {
350+ break ;
335351 }
336-
337- const fileNames = glob . sync ( filterGlob , { dot : true } ) . map ( f => path . resolve ( f ) ) ;
338- for ( const fileName of fileNames )
339- filterSet . add ( fileName ) ;
340- }
341-
342- if ( ! filterSet . size ) {
343- clack . log . error ( red ( `No files found after --filter files.` ) ) ;
344- process . exit ( 1 ) ;
352+ filters . push ( normalizeFilterGlobPath ( filterGlob ) ) ;
345353 }
346354 }
347355
348356 for ( const [ tsconfig , languages ] of tsconfigAndLanguages ) {
349- projects . push ( await new Project ( tsconfig , languages ) . init ( clack , filterSet ) ) ;
357+ projects . push ( await new Project ( tsconfig , languages ) . init ( clack , filters ) ) ;
350358 }
351359
352360 spinner ?. start ( ) ;
0 commit comments