Skip to content

Commit

Permalink
Merge pull request #3188 from Microsoft/tsConfigExclude
Browse files Browse the repository at this point in the history
Support "exclude" property in tsconfig.json
  • Loading branch information
ahejlsberg committed Jun 3, 2015
2 parents b551177 + 990f19b commit ca4bf6b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
15 changes: 8 additions & 7 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ module ts {

return {
options: getCompilerOptions(),
fileNames: getFiles(),
fileNames: getFileNames(),
errors
};

Expand Down Expand Up @@ -395,23 +395,24 @@ module ts {
return options;
}

function getFiles(): string[] {
var files: string[] = [];
function getFileNames(): string[] {
var fileNames: string[] = [];
if (hasProperty(json, "files")) {
if (json["files"] instanceof Array) {
var files = map(<string[]>json["files"], s => combinePaths(basePath, s));
fileNames = map(<string[]>json["files"], s => combinePaths(basePath, s));
}
}
else {
var sysFiles = host.readDirectory(basePath, ".ts");
var exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
var sysFiles = host.readDirectory(basePath, ".ts", exclude);
for (var i = 0; i < sysFiles.length; i++) {
var name = sysFiles[i];
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
files.push(name);
fileNames.push(name);
}
}
}
return files;
return fileNames;
}
}
}
46 changes: 31 additions & 15 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module ts {
createDirectory(path: string): void;
getExecutingFilePath(): string;
getCurrentDirectory(): string;
readDirectory(path: string, extension?: string): string[];
readDirectory(path: string, extension?: string, exclude?: string[]): string[];
getMemoryUsage?(): number;
exit(exitCode?: number): void;
}
Expand Down Expand Up @@ -109,29 +109,38 @@ module ts {
}
}

function getNames(collection: any): string[] {
function getCanonicalPath(path: string): string {
return path.toLowerCase();
}

function getNames(collection: any): string[]{
var result: string[] = [];
for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
result.push(e.item().Name);
}
return result.sort();
}

function readDirectory(path: string, extension?: string): string[] {
function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {
var result: string[] = [];
exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s)));
visitDirectory(path);
return result;
function visitDirectory(path: string) {
var folder = fso.GetFolder(path || ".");
var files = getNames(folder.files);
for (let name of files) {
if (!extension || fileExtensionIs(name, extension)) {
result.push(combinePaths(path, name));
for (let current of files) {
let name = combinePaths(path, current);
if ((!extension || fileExtensionIs(name, extension)) && !contains(exclude, getCanonicalPath(name))) {
result.push(name);
}
}
var subfolders = getNames(folder.subfolders);
for (let current of subfolders) {
visitDirectory(combinePaths(path, current));
let name = combinePaths(path, current);
if (!contains(exclude, getCanonicalPath(name))) {
visitDirectory(name);
}
}
}
}
Expand Down Expand Up @@ -222,23 +231,30 @@ module ts {
_fs.writeFileSync(fileName, data, "utf8");
}

function readDirectory(path: string, extension?: string): string[] {
function getCanonicalPath(path: string): string {
return useCaseSensitiveFileNames ? path.toLowerCase() : path;
}

function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {
var result: string[] = [];
exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s)));
visitDirectory(path);
return result;
function visitDirectory(path: string) {
var files = _fs.readdirSync(path || ".").sort();
var directories: string[] = [];
for (let current of files) {
var name = combinePaths(path, current);
var stat = _fs.statSync(name);
if (stat.isFile()) {
if (!extension || fileExtensionIs(name, extension)) {
result.push(name);
if (!contains(exclude, getCanonicalPath(name))) {
var stat = _fs.statSync(name);
if (stat.isFile()) {
if (!extension || fileExtensionIs(name, extension)) {
result.push(name);
}
}
else if (stat.isDirectory()) {
directories.push(name);
}
}
else if (stat.isDirectory()) {
directories.push(name);
}
}
for (let current of directories) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ module ts {
}

export interface ParseConfigHost {
readDirectory(rootDir: string, extension: string): string[];
readDirectory(rootDir: string, extension: string, exclude: string[]): string[];
}

export interface WriteFileCallback {
Expand Down

0 comments on commit ca4bf6b

Please sign in to comment.