Skip to content

Commit 45480cf

Browse files
authored
fix(cli): --filter files enhancement (#68)
1 parent 29342ff commit 45480cf

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

packages/cli/index.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ if (process.argv.includes('--threads')) {
4141

4242
class Project {
4343
worker: ReturnType<typeof worker.create> | undefined;
44+
/**
45+
* file names for passing to ts language service host (getScriptFileNames)
46+
*/
47+
rawFileNames: string[] = [];
48+
/**
49+
* file names after filter, for linting process
50+
*/
4451
fileNames: string[] = [];
4552
options: ts.CompilerOptions = {};
4653
configFile: string | undefined;
@@ -91,25 +98,25 @@ class Project {
9198

9299
const commonLine = await parseCommonLine(this.tsconfig, this.languages);
93100

94-
this.fileNames = commonLine.fileNames;
101+
this.rawFileNames = commonLine.fileNames;
95102
this.options = commonLine.options;
96103

97-
if (!this.fileNames.length) {
104+
if (!this.rawFileNames.length) {
98105
clack.log.message(`${label} ${gray(path.relative(process.cwd(), this.tsconfig))} ${gray('(0)')}`);
99106
return this;
100107
}
101108

102-
const originalFileNamesLength = this.fileNames.length;
103-
104109
if (filesFilter.size) {
105-
this.fileNames = this.fileNames.filter(f => filesFilter.has(f));
110+
this.fileNames = this.rawFileNames.filter(f => filesFilter.has(f));
106111
if (!this.fileNames.length) {
107112
clack.log.warn(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray('(No files left after filter)')}`);
108113
return this;
109114
}
115+
} else {
116+
this.fileNames = this.rawFileNames;
110117
}
111118

112-
const filteredLengthDiff = originalFileNamesLength - this.fileNames.length;
119+
const filteredLengthDiff = this.rawFileNames.length - this.fileNames.length;
113120
clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray(`(${this.fileNames.length}${filteredLengthDiff ? `, skipped ${filteredLengthDiff}` : ''})`)}`);
114121

115122
if (!process.argv.includes('--force')) {
@@ -327,7 +334,7 @@ class Project {
327334
process.exit(1);
328335
}
329336

330-
const fileNames = glob.sync(filterGlob).map(f => path.resolve(f));
337+
const fileNames = glob.sync(filterGlob, { dot: true }).map(f => path.resolve(f));
331338
for (const fileName of fileNames)
332339
filterSet.add(fileName);
333340
}
@@ -424,7 +431,7 @@ class Project {
424431
project.languages,
425432
project.configFile!,
426433
project.builtConfig!,
427-
project.fileNames,
434+
project.rawFileNames,
428435
project.options,
429436
);
430437
if (!setupSuccess) {

0 commit comments

Comments
 (0)