Skip to content

Commit d11ee08

Browse files
committed
Merge pull request #8484 from zhengbli/ignoreHiddenFiles
ignore dotted files and folders
2 parents 7c043b6 + 076fe48 commit d11ee08

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,9 @@ namespace ts {
652652
return output;
653653
}
654654

655+
// Skip over any minified JavaScript files (ending in ".min.js")
656+
// Skip over dotted files and folders as well
657+
const IgnoreFileNamePattern = /(\.min\.js$)|([\\/]\.[\w.])/;
655658
/**
656659
* Parse the contents of a config file (tsconfig.json).
657660
* @param json The contents of the config file to parse
@@ -715,8 +718,7 @@ namespace ts {
715718
continue;
716719
}
717720

718-
// Skip over any minified JavaScript files (ending in ".min.js")
719-
if (/\.min\.js$/.test(fileName)) {
721+
if (IgnoreFileNamePattern.test(fileName)) {
720722
continue;
721723
}
722724

tests/cases/unittests/tsconfigParsing.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,41 @@ namespace ts {
1313
assert.isTrue(undefined === parsed.config);
1414
assert.isTrue(undefined !== parsed.error);
1515
}
16-
16+
1717
function assertParseErrorWithExcludesKeyword(jsonText: string) {
1818
let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText);
1919
let parsedCommand = ts.parseJsonConfigFileContent(parsed, ts.sys, "tests/cases/unittests");
2020
assert.isTrue(undefined !== parsedCommand.errors);
2121
}
2222

23+
function assertParseFileList(jsonText: string, configFileName: string, basePath: string, allFileList: string[], expectedFileList: string[]) {
24+
const json = JSON.parse(jsonText);
25+
const host: ParseConfigHost = { readDirectory: mockReadDirectory };
26+
const parsed = ts.parseJsonConfigFileContent(json, host, basePath, /*existingOptions*/ undefined, configFileName);
27+
assert.isTrue(arrayIsEqualTo(parsed.fileNames.sort(), expectedFileList.sort()));
28+
29+
function mockReadDirectory(rootDir: string, extension: string, exclude: string[]): string[] {
30+
const result: string[] = [];
31+
const fullExcludeDirectories = ts.map(exclude, directory => combinePaths(rootDir, directory));
32+
for (const file of allFileList) {
33+
let shouldExclude = false;
34+
for (const fullExcludeDirectorie of fullExcludeDirectories) {
35+
if (file.indexOf(fullExcludeDirectorie) >= 0) {
36+
shouldExclude = true;
37+
break;
38+
}
39+
}
40+
if (shouldExclude) {
41+
continue;
42+
}
43+
if (fileExtensionIs(file, extension)) {
44+
result.push(file);
45+
}
46+
}
47+
return result;
48+
}
49+
}
50+
2351
it("returns empty config for file with only whitespaces", () => {
2452
assertParseResult("", { config : {} });
2553
assertParseResult(" ", { config : {} });
@@ -108,7 +136,7 @@ namespace ts {
108136
config: { compilerOptions: { lib: "es5,es6" } }
109137
});
110138
});
111-
139+
112140
it("returns error when tsconfig have excludes", () => {
113141
assertParseErrorWithExcludesKeyword(
114142
`{
@@ -120,5 +148,15 @@ namespace ts {
120148
]
121149
}`);
122150
});
151+
152+
it("ignore dotted files and folders", () => {
153+
assertParseFileList(
154+
`{}`,
155+
"tsconfig.json",
156+
"/apath",
157+
["/apath/test.ts", "/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"],
158+
["/apath/test.ts"]
159+
)
160+
})
123161
});
124162
}

0 commit comments

Comments
 (0)