Add upper limit for the program size, fix readDirectory for the symlink files

This commit is contained in:
zhengbli 2016-03-11 15:56:36 -08:00
parent 7d372bf6dc
commit 4d3cff1e5a
6 changed files with 63 additions and 13 deletions

View file

@ -566,7 +566,7 @@ namespace ts {
}
else {
// by default exclude node_modules, and any specificied output directory
exclude = ["node_modules"];
exclude = ["node_modules", "bower_components"];
const outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"];
if (outDir) {
exclude.push(outDir);

View file

@ -2824,5 +2824,9 @@
"Unknown typing option '{0}'.": {
"category": "Error",
"code": 17010
},
"Too many javascript files in the project. Consider add to the `exclude` list in the config file.": {
"category": "Error",
"code": 17012
}
}

View file

@ -748,7 +748,21 @@ namespace ts {
}
if (!tryReuseStructureFromOldProgram()) {
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
let programSize = 0;
for (const name of rootNames) {
const path = toPath(name, currentDirectory, getCanonicalFileName);
if (programSize <= maxProgramSize) {
processRootFile(name, /*isDefaultLib*/ false);
if (!hasTypeScriptFileExtension(name) && filesByName.get(path)) {
programSize += filesByName.get(path).text.length;
}
}
else {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Too_many_javascript_files_in_the_project_Consider_add_to_the_exclude_list_in_the_config_file));
break;
}
}
// Do not process the default library if:
// - The '--noLib' flag is used.
// - A 'no-default-lib' reference comment is encountered in

View file

@ -74,7 +74,7 @@ namespace ts {
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
};
export var sys: System = (function () {
export var sys: System = (function() {
function getWScriptSystem(): System {
@ -404,8 +404,8 @@ namespace ts {
const watchedFileSet = createWatchedFileSet();
function isNode4OrLater(): boolean {
return parseInt(process.version.charAt(1)) >= 4;
}
return parseInt(process.version.charAt(1)) >= 4;
}
const platform: string = _os.platform();
// win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive
@ -500,7 +500,7 @@ namespace ts {
for (const current of files) {
const name = combinePaths(path, current);
if (!contains(exclude, getCanonicalPath(name))) {
const stat = _fs.statSync(name);
const stat = _fs.lstatSync(name);
if (stat.isFile()) {
if (!extension || fileExtensionIs(name, extension)) {
result.push(name);
@ -532,7 +532,7 @@ namespace ts {
// and https://github.com/Microsoft/TypeScript/issues/4643), therefore
// if the current node.js version is newer than 4, use `fs.watch` instead.
const watchSet = isNode4OrLater() ? watchedFileSet : pollingWatchedFileSet;
const watchedFile = watchSet.addFile(filePath, callback);
const watchedFile = watchSet.addFile(filePath, callback);
return {
close: () => watchSet.removeFile(watchedFile)
};
@ -562,7 +562,7 @@ namespace ts {
}
);
},
resolvePath: function (path: string): string {
resolvePath: function(path: string): string {
return _path.resolve(path);
},
fileExists,

View file

@ -2484,6 +2484,10 @@ namespace ts {
return forEach(supportedJavascriptExtensions, extension => fileExtensionIs(fileName, extension));
}
export function hasTypeScriptFileExtension(fileName: string) {
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
}
/**
* Replace each instance of non-ascii characters by one, two, three, or four escape sequences
* representing the UTF-8 encoding of the character, and return the expanded char code list.
@ -2866,4 +2870,6 @@ namespace ts {
export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean {
return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
}
export const maxProgramSize = 35 * 1024 * 1024;
}

View file

@ -1217,13 +1217,35 @@ namespace ts.server {
}
else {
const project = this.createProject(configFilename, projectOptions);
let programSize = 0;
// As the project openning might not be complete if there are too many files,
// therefore to surface the diagnostics we need to make sure the given client file is opened.
if (clientFileName) {
const currentClientFileInfo = this.openFile(clientFileName, /*openedByClient*/ true);
project.addRoot(currentClientFileInfo);
programSize += currentClientFileInfo.content.length;
}
for (const rootFilename of projectOptions.files) {
if (this.host.fileExists(rootFilename)) {
const info = this.openFile(rootFilename, /*openedByClient*/ clientFileName == rootFilename);
project.addRoot(info);
if (rootFilename === clientFileName) {
continue;
}
if (programSize <= maxProgramSize) {
if (this.host.fileExists(rootFilename)) {
const info = this.openFile(rootFilename, /*openedByClient*/ false);
project.addRoot(info);
if (!hasTypeScriptFileExtension(rootFilename)) {
programSize += info.content.length;
}
}
else {
return { errorMsg: "specified file " + rootFilename + " not found" };
}
}
else {
return { errorMsg: "specified file " + rootFilename + " not found" };
break;
}
}
project.finishGraph();
@ -1251,11 +1273,15 @@ namespace ts.server {
return error;
}
else {
const oldFileNames = project.compilerService.host.roots.map(info => info.fileName);
const oldFileNames = project.projectOptions ? project.projectOptions.files : project.compilerService.host.roots.map(info => info.fileName);
const newFileNames = projectOptions.files;
const fileNamesToRemove = oldFileNames.filter(f => newFileNames.indexOf(f) < 0);
const fileNamesToAdd = newFileNames.filter(f => oldFileNames.indexOf(f) < 0);
if (fileNamesToAdd.length === 0 && fileNamesToRemove.length === 0) {
return;
}
for (const fileName of fileNamesToRemove) {
const info = this.getScriptInfo(fileName);
if (info) {