From fdc7037bfc0b0c74149febee54437cdef7144483 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 5 May 2016 13:06:12 -0700 Subject: [PATCH 1/2] ignore dotted files and folders --- src/compiler/commandLineParser.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index c53e2fcc2e..0336b0c7e6 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -716,7 +716,8 @@ namespace ts { } // Skip over any minified JavaScript files (ending in ".min.js") - if (/\.min\.js$/.test(fileName)) { + // Skip over dotted files and folders as well + if (/\.min\.js$/.test(fileName) || /[\\/]\.[\w.]/.test(fileName)) { continue; } From 076fe48c3ab536d937462267c5fa8608136895ab Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 5 May 2016 14:49:41 -0700 Subject: [PATCH 2/2] Add unit tests for tsconfig file list parsing --- src/compiler/commandLineParser.ts | 7 ++-- tests/cases/unittests/tsconfigParsing.ts | 42 ++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 0336b0c7e6..d08ca9bdae 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -652,6 +652,9 @@ namespace ts { 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). * @param json The contents of the config file to parse @@ -715,9 +718,7 @@ namespace ts { continue; } - // Skip over any minified JavaScript files (ending in ".min.js") - // Skip over dotted files and folders as well - if (/\.min\.js$/.test(fileName) || /[\\/]\.[\w.]/.test(fileName)) { + if (IgnoreFileNamePattern.test(fileName)) { continue; } diff --git a/tests/cases/unittests/tsconfigParsing.ts b/tests/cases/unittests/tsconfigParsing.ts index 29283acfe3..7cb72f4723 100644 --- a/tests/cases/unittests/tsconfigParsing.ts +++ b/tests/cases/unittests/tsconfigParsing.ts @@ -13,13 +13,41 @@ namespace ts { assert.isTrue(undefined === parsed.config); assert.isTrue(undefined !== parsed.error); } - + function assertParseErrorWithExcludesKeyword(jsonText: string) { let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); let parsedCommand = ts.parseJsonConfigFileContent(parsed, ts.sys, "tests/cases/unittests"); 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", () => { assertParseResult("", { config : {} }); assertParseResult(" ", { config : {} }); @@ -108,7 +136,7 @@ namespace ts { config: { compilerOptions: { lib: "es5,es6" } } }); }); - + it("returns error when tsconfig have excludes", () => { 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"] + ) + }) }); }