Merge pull request #8484 from zhengbli/ignoreHiddenFiles

ignore dotted files and folders
This commit is contained in:
Zhengbo Li 2016-05-05 19:22:10 -07:00
commit d11ee08170
2 changed files with 44 additions and 4 deletions

View file

@ -652,6 +652,9 @@ namespace ts {
return output; return output;
} }
// Skip over any minified JavaScript files (ending in ".min.js")
// Skip over dotted files and folders as well
const IgnoreFileNamePattern = /(\.min\.js$)|([\\/]\.[\w.])/;
/** /**
* Parse the contents of a config file (tsconfig.json). * Parse the contents of a config file (tsconfig.json).
* @param json The contents of the config file to parse * @param json The contents of the config file to parse
@ -715,8 +718,7 @@ namespace ts {
continue; continue;
} }
// Skip over any minified JavaScript files (ending in ".min.js") if (IgnoreFileNamePattern.test(fileName)) {
if (/\.min\.js$/.test(fileName)) {
continue; continue;
} }

View file

@ -13,13 +13,41 @@ namespace ts {
assert.isTrue(undefined === parsed.config); assert.isTrue(undefined === parsed.config);
assert.isTrue(undefined !== parsed.error); assert.isTrue(undefined !== parsed.error);
} }
function assertParseErrorWithExcludesKeyword(jsonText: string) { function assertParseErrorWithExcludesKeyword(jsonText: string) {
let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText);
let parsedCommand = ts.parseJsonConfigFileContent(parsed, ts.sys, "tests/cases/unittests"); let parsedCommand = ts.parseJsonConfigFileContent(parsed, ts.sys, "tests/cases/unittests");
assert.isTrue(undefined !== parsedCommand.errors); assert.isTrue(undefined !== parsedCommand.errors);
} }
function assertParseFileList(jsonText: string, configFileName: string, basePath: string, allFileList: string[], expectedFileList: string[]) {
const json = JSON.parse(jsonText);
const host: ParseConfigHost = { readDirectory: mockReadDirectory };
const parsed = ts.parseJsonConfigFileContent(json, host, basePath, /*existingOptions*/ undefined, configFileName);
assert.isTrue(arrayIsEqualTo(parsed.fileNames.sort(), expectedFileList.sort()));
function mockReadDirectory(rootDir: string, extension: string, exclude: string[]): string[] {
const result: string[] = [];
const fullExcludeDirectories = ts.map(exclude, directory => combinePaths(rootDir, directory));
for (const file of allFileList) {
let shouldExclude = false;
for (const fullExcludeDirectorie of fullExcludeDirectories) {
if (file.indexOf(fullExcludeDirectorie) >= 0) {
shouldExclude = true;
break;
}
}
if (shouldExclude) {
continue;
}
if (fileExtensionIs(file, extension)) {
result.push(file);
}
}
return result;
}
}
it("returns empty config for file with only whitespaces", () => { it("returns empty config for file with only whitespaces", () => {
assertParseResult("", { config : {} }); assertParseResult("", { config : {} });
assertParseResult(" ", { config : {} }); assertParseResult(" ", { config : {} });
@ -108,7 +136,7 @@ namespace ts {
config: { compilerOptions: { lib: "es5,es6" } } config: { compilerOptions: { lib: "es5,es6" } }
}); });
}); });
it("returns error when tsconfig have excludes", () => { it("returns error when tsconfig have excludes", () => {
assertParseErrorWithExcludesKeyword( assertParseErrorWithExcludesKeyword(
`{ `{
@ -120,5 +148,15 @@ namespace ts {
] ]
}`); }`);
}); });
it("ignore dotted files and folders", () => {
assertParseFileList(
`{}`,
"tsconfig.json",
"/apath",
["/apath/test.ts", "/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"],
["/apath/test.ts"]
)
})
}); });
} }