Skip to content

Commit 70d2938

Browse files
committed
Support "exclude" property in tsconfig.json
1 parent e3812ff commit 70d2938

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ module ts {
343343

344344
return {
345345
options: getCompilerOptions(),
346-
fileNames: getFiles(),
346+
fileNames: getFileNames(),
347347
errors
348348
};
349349

@@ -389,23 +389,24 @@ module ts {
389389
return options;
390390
}
391391

392-
function getFiles(): string[] {
393-
var files: string[] = [];
392+
function getFileNames(): string[] {
393+
var fileNames: string[] = [];
394394
if (hasProperty(json, "files")) {
395395
if (json["files"] instanceof Array) {
396-
var files = map(<string[]>json["files"], s => combinePaths(basePath, s));
396+
fileNames = map(<string[]>json["files"], s => combinePaths(basePath, s));
397397
}
398398
}
399399
else {
400-
var sysFiles = host.readDirectory(basePath, ".ts");
400+
var exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
401+
var sysFiles = host.readDirectory(basePath, ".ts", exclude);
401402
for (var i = 0; i < sysFiles.length; i++) {
402403
var name = sysFiles[i];
403404
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
404-
files.push(name);
405+
fileNames.push(name);
405406
}
406407
}
407408
}
408-
return files;
409+
return fileNames;
409410
}
410411
}
411412
}

src/compiler/sys.ts

Lines changed: 31 additions & 15 deletions
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.lstatSync(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.lstatSync(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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ module ts {
10351035
}
10361036

10371037
export interface ParseConfigHost {
1038-
readDirectory(rootDir: string, extension: string): string[];
1038+
readDirectory(rootDir: string, extension: string, exclude: string[]): string[];
10391039
}
10401040

10411041
export interface WriteFileCallback {

0 commit comments

Comments
 (0)