diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8dcc21b4d1b..9fec0b1083d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -713,6 +713,16 @@ namespace ts { errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "exclude", "Array")); } } + else { + // By default, exclude common package folders + excludeSpecs = ["node_modules", "bower_components", "jspm_packages"]; + } + + // Always exclude the output directory unless explicitly included + const outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"]; + if (outDir) { + excludeSpecs.push(outDir); + } if (fileNames === undefined && includeSpecs === undefined) { includeSpecs = ["**/*"]; @@ -885,7 +895,6 @@ namespace ts { */ function matchFileNames(fileNames: string[], include: string[], exclude: string[], basePath: string, options: CompilerOptions, host: ParseConfigHost, errors: Diagnostic[]): ExpandResult { basePath = normalizePath(basePath); - basePath = removeTrailingDirectorySeparator(basePath); // The exclude spec list is converted into a regular expression, which allows us to quickly // test whether a file or directory should be excluded before recursively traversing the @@ -941,6 +950,10 @@ namespace ts { continue; } + if (IgnoreFileNamePattern.test(file)) { + continue; + } + // We may have included a wildcard path with a lower priority // extension due to the user-defined order of entries in the // "include" array. If there is a lower priority extension in the diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ae489ad553c..cc3c2b28114 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1067,7 +1067,7 @@ namespace ts { return basePaths; } - + export function ensureScriptKind(fileName: string, scriptKind?: ScriptKind): ScriptKind { // Using scriptKind as a condition handles both: // - 'scriptKind' is unspecified and thus it is `undefined` diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 3191b8b0056..8e5e76974bf 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -367,7 +367,7 @@ namespace ts { const files: string[] = []; const directories: string[] = []; for (const entry of entries) { - // This is necessary because on some file system node fails to exclude + // This is necessary because on some file system node fails to exclude // "." and "..". See https://github.com/nodejs/node/issues/4002 if (entry === "." || entry === "..") { continue; @@ -391,10 +391,6 @@ namespace ts { function readDirectory(path: string, extensions?: string[], excludes?: string[], includes?: string[]): string[] { return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, process.cwd(), getAccessibleFileSystemEntries); } - - function getCanonicalPath(path: string): string { - return useCaseSensitiveFileNames ? path : path.toLowerCase(); - } const enum FileSystemEntryKind { File, diff --git a/src/services/shims.ts b/src/services/shims.ts index 0610c0e0b57..ba9ccdce2dc 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -81,7 +81,7 @@ namespace ts { */ readDirectory(rootDir: string, extension: string, exclude?: string, include?: string, depth?: number): string; useCaseSensitiveFileNames?(): boolean; - trace(s: string): void; + trace(s: string): void; } /// @@ -432,10 +432,10 @@ namespace ts { public directoryExists: (directoryName: string) => boolean; public realpath: (path: string) => string; - public useCaseSensitiveFileNames: boolean; + public useCaseSensitiveFileNames: boolean; constructor(private shimHost: CoreServicesShimHost) { - this.useCaseSensitiveFileNames = this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false; + this.useCaseSensitiveFileNames = this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false; if ("directoryExists" in this.shimHost) { this.directoryExists = directoryName => this.shimHost.directoryExists(directoryName); } @@ -453,7 +453,7 @@ namespace ts { JSON.stringify(extensions), JSON.stringify(exclude), JSON.stringify(include), - depth + depth )); } catch (e) { diff --git a/tests/cases/unittests/tsconfigParsing.ts b/tests/cases/unittests/tsconfigParsing.ts index 581575c9479..daa2b2bcdf0 100644 --- a/tests/cases/unittests/tsconfigParsing.ts +++ b/tests/cases/unittests/tsconfigParsing.ts @@ -50,27 +50,6 @@ namespace ts { const host: ParseConfigHost = new MockParseConfigHost(basePath, true, allFileList); 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", () => {