Skip to content

Commit ca4bf6b

Browse files
committed
Merge pull request #3188 from Microsoft/tsConfigExclude
Support "exclude" property in tsconfig.json
2 parents b551177 + 990f19b commit ca4bf6b

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

src/compiler/commandLineParser.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ module ts {
349349

350350
return {
351351
options: getCompilerOptions(),
352-
fileNames: getFiles(),
352+
fileNames: getFileNames(),
353353
errors
354354
};
355355

@@ -395,23 +395,24 @@ module ts {
395395
return options;
396396
}
397397

398-
function getFiles(): string[] {
399-
var files: string[] = [];
398+
function getFileNames(): string[] {
399+
var fileNames: string[] = [];
400400
if (hasProperty(json, "files")) {
401401
if (json["files"] instanceof Array) {
402-
var files = map(<string[]>json["files"], s => combinePaths(basePath, s));
402+
fileNames = map(<string[]>json["files"], s => combinePaths(basePath, s));
403403
}
404404
}
405405
else {
406-
var sysFiles = host.readDirectory(basePath, ".ts");
406+
var exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
407+
var sysFiles = host.readDirectory(basePath, ".ts", exclude);
407408
for (var i = 0; i < sysFiles.length; i++) {
408409
var name = sysFiles[i];
409410
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
410-
files.push(name);
411+
fileNames.push(name);
411412
}
412413
}
413414
}
414-
return files;
415+
return fileNames;
415416
}
416417
}
417418
}

src/compiler/sys.ts

+31-15
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module ts {
1515
createDirectory(path: string): void;
1616
getExecutingFilePath(): string;
1717
getCurrentDirectory(): string;
18-
readDirectory(path: string, extension?: string): string[];
18+
readDirectory(path: string, extension?: string, exclude?: string[]): string[];
1919
getMemoryUsage?(): number;
2020
exit(exitCode?: number): void;
2121
}
@@ -109,29 +109,38 @@ module ts {
109109
}
110110
}
111111

112-
function getNames(collection: any): string[] {
112+
function getCanonicalPath(path: string): string {
113+
return path.toLowerCase();
114+
}
115+
116+
function getNames(collection: any): string[]{
113117
var result: string[] = [];
114118
for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
115119
result.push(e.item().Name);
116120
}
117121
return result.sort();
118122
}
119123

120-
function readDirectory(path: string, extension?: string): string[] {
124+
function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {
121125
var result: string[] = [];
126+
exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s)));
122127
visitDirectory(path);
123128
return result;
124129
function visitDirectory(path: string) {
125130
var folder = fso.GetFolder(path || ".");
126131
var files = getNames(folder.files);
127-
for (let name of files) {
128-
if (!extension || fileExtensionIs(name, extension)) {
129-
result.push(combinePaths(path, name));
132+
for (let current of files) {
133+
let name = combinePaths(path, current);
134+
if ((!extension || fileExtensionIs(name, extension)) && !contains(exclude, getCanonicalPath(name))) {
135+
result.push(name);
130136
}
131137
}
132138
var subfolders = getNames(folder.subfolders);
133139
for (let current of subfolders) {
134-
visitDirectory(combinePaths(path, current));
140+
let name = combinePaths(path, current);
141+
if (!contains(exclude, getCanonicalPath(name))) {
142+
visitDirectory(name);
143+
}
135144
}
136145
}
137146
}
@@ -222,23 +231,30 @@ module ts {
222231
_fs.writeFileSync(fileName, data, "utf8");
223232
}
224233

225-
function readDirectory(path: string, extension?: string): string[] {
234+
function getCanonicalPath(path: string): string {
235+
return useCaseSensitiveFileNames ? path.toLowerCase() : path;
236+
}
237+
238+
function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {
226239
var result: string[] = [];
240+
exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s)));
227241
visitDirectory(path);
228242
return result;
229243
function visitDirectory(path: string) {
230244
var files = _fs.readdirSync(path || ".").sort();
231245
var directories: string[] = [];
232246
for (let current of files) {
233247
var name = combinePaths(path, current);
234-
var stat = _fs.statSync(name);
235-
if (stat.isFile()) {
236-
if (!extension || fileExtensionIs(name, extension)) {
237-
result.push(name);
248+
if (!contains(exclude, getCanonicalPath(name))) {
249+
var stat = _fs.statSync(name);
250+
if (stat.isFile()) {
251+
if (!extension || fileExtensionIs(name, extension)) {
252+
result.push(name);
253+
}
254+
}
255+
else if (stat.isDirectory()) {
256+
directories.push(name);
238257
}
239-
}
240-
else if (stat.isDirectory()) {
241-
directories.push(name);
242258
}
243259
}
244260
for (let current of directories) {

src/compiler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ module ts {
11681168
}
11691169

11701170
export interface ParseConfigHost {
1171-
readDirectory(rootDir: string, extension: string): string[];
1171+
readDirectory(rootDir: string, extension: string, exclude: string[]): string[];
11721172
}
11731173

11741174
export interface WriteFileCallback {

0 commit comments

Comments
 (0)