Skip to content

Commit a3aa000

Browse files
author
zhengbli
committed
CR feedback / Change upper limit / Add disableSizeLimit compiler option
1 parent b155fa8 commit a3aa000

7 files changed

Lines changed: 65 additions & 31 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ namespace ts {
332332
name: "noImplicitUseStrict",
333333
type: "boolean",
334334
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
335+
},
336+
{
337+
name: "disableSizeLimit",
338+
type: "boolean",
339+
description: Diagnostics.Disable_the_upper_limit_for_the_total_file_size_of_a_project
335340
}
336341
];
337342

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,7 +2620,10 @@
26202620
"category": "Message",
26212621
"code": 6112
26222622
},
2623-
2623+
"Disable the upper limit for the total file size of a project.": {
2624+
"category": "Message",
2625+
"code": 6113
2626+
},
26242627
"Variable '{0}' implicitly has an '{1}' type.": {
26252628
"category": "Error",
26262629
"code": 7005
@@ -2825,7 +2828,7 @@
28252828
"category": "Error",
28262829
"code": 17010
28272830
},
2828-
"Too many javascript files in the project. Consider add to the `exclude` list in the config file.": {
2831+
"Too many JavaScript files in the project. Use an exact 'files' list, or use the 'exclude' setting in project configuration to limit included source folders. The likely folder to exclude is '{0}'. To disable the project size limit, set the 'disableSizeLimit' compiler option to 'true'": {
28292832
"category": "Error",
28302833
"code": 17012
28312834
}

src/compiler/program.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -742,24 +742,38 @@ namespace ts {
742742
(oldOptions.target !== options.target) ||
743743
(oldOptions.noLib !== options.noLib) ||
744744
(oldOptions.jsx !== options.jsx) ||
745-
(oldOptions.allowJs !== options.allowJs)) {
745+
(oldOptions.allowJs !== options.allowJs) ||
746+
(oldOptions.disableSizeLimit !== options.disableSizeLimit)) {
746747
oldProgram = undefined;
747748
}
748749
}
749750

750751
if (!tryReuseStructureFromOldProgram()) {
751-
let programSize = 0;
752-
for (const name of rootNames) {
753-
const path = toPath(name, currentDirectory, getCanonicalFileName);
754-
if (programSize <= maxProgramSize) {
755-
processRootFile(name, /*isDefaultLib*/ false);
756-
if (!hasTypeScriptFileExtension(name) && filesByName.get(path)) {
757-
programSize += filesByName.get(path).text.length;
752+
if (options.disableSizeLimit === true) {
753+
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
754+
}
755+
else {
756+
let programSize = 0;
757+
for (const name of rootNames) {
758+
const path = toPath(name, currentDirectory, getCanonicalFileName);
759+
if (programSize <= maxProgramSize) {
760+
processRootFile(name, /*isDefaultLib*/ false);
761+
const file = filesByName.get(path);
762+
if (!hasTypeScriptFileExtension(name) && file && file.text) {
763+
programSize += file.text.length;
764+
}
765+
}
766+
else {
767+
// If the program size limit was reached when processing a file, this file is
768+
// likely in the problematic folder than contains too many files
769+
const commonSourceDirectory = getCommonSourceDirectory();
770+
let rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory.length, path.indexOf(directorySeparator, commonSourceDirectory.length)));
771+
if (rootLevelDirectory[rootLevelDirectory.length - 1] !== directorySeparator) {
772+
rootLevelDirectory += directorySeparator;
773+
}
774+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Too_many_JavaScript_files_in_the_project_Use_an_exact_files_list_or_use_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true, rootLevelDirectory));
775+
break;
758776
}
759-
}
760-
else {
761-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Too_many_javascript_files_in_the_project_Consider_add_to_the_exclude_list_in_the_config_file));
762-
break;
763777
}
764778
}
765779

src/compiler/sys.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,19 @@ namespace ts {
501501
const name = combinePaths(path, current);
502502
if (!contains(exclude, getCanonicalPath(name))) {
503503
// fs.statSync would throw an exception if the file is a symlink
504-
// whose linked file doesn't exist. fs.lstatSync would return a stat
505-
// object for the symlink file itself in this case
506-
const stat = _fs.lstatSync(name);
507-
if (stat.isFile()) {
508-
if (!extension || fileExtensionIs(name, extension)) {
509-
result.push(name);
504+
// whose linked file doesn't exist.
505+
try {
506+
const stat = _fs.statSync(name);
507+
if (stat.isFile()) {
508+
if (!extension || fileExtensionIs(name, extension)) {
509+
result.push(name);
510+
}
511+
}
512+
else if (stat.isDirectory()) {
513+
directories.push(name);
510514
}
511515
}
512-
else if (stat.isDirectory()) {
513-
directories.push(name);
514-
}
516+
catch (e) { }
515517
}
516518
}
517519
for (const current of directories) {

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,6 +2437,7 @@ namespace ts {
24372437
allowSyntheticDefaultImports?: boolean;
24382438
allowJs?: boolean;
24392439
noImplicitUseStrict?: boolean;
2440+
disableSizeLimit?: boolean;
24402441
/* @internal */ stripInternal?: boolean;
24412442

24422443
// Skip checking lib.d.ts to help speed up tests.

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2871,5 +2871,5 @@ namespace ts {
28712871
return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
28722872
}
28732873

2874-
export const maxProgramSize = 35 * 1024 * 1024;
2874+
export const maxProgramSize = 20 * 1024 * 1024;
28752875
}

src/server/editorServices.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,30 +1222,39 @@ namespace ts.server {
12221222
// As the project openning might not be complete if there are too many files,
12231223
// therefore to surface the diagnostics we need to make sure the given client file is opened.
12241224
if (clientFileName) {
1225-
const currentClientFileInfo = this.openFile(clientFileName, /*openedByClient*/ true);
1226-
project.addRoot(currentClientFileInfo);
1227-
programSize += currentClientFileInfo.content.length;
1225+
if (this.host.fileExists(clientFileName)) {
1226+
const currentClientFileInfo = this.openFile(clientFileName, /*openedByClient*/ true);
1227+
project.addRoot(currentClientFileInfo);
1228+
programSize += currentClientFileInfo.content.length;
1229+
}
1230+
else {
1231+
return { errorMsg: "specified file " + clientFileName + " not found" };
1232+
}
12281233
}
12291234

12301235
for (const rootFilename of projectOptions.files) {
12311236
if (rootFilename === clientFileName) {
12321237
continue;
12331238
}
12341239

1235-
if (programSize <= maxProgramSize) {
1236-
if (this.host.fileExists(rootFilename)) {
1240+
if (this.host.fileExists(rootFilename)) {
1241+
if (projectOptions.compilerOptions.disableSizeLimit === true) {
1242+
const info = this.openFile(rootFilename, /*openedByClient*/ false);
1243+
project.addRoot(info);
1244+
}
1245+
else if (programSize <= maxProgramSize) {
12371246
const info = this.openFile(rootFilename, /*openedByClient*/ false);
12381247
project.addRoot(info);
12391248
if (!hasTypeScriptFileExtension(rootFilename)) {
12401249
programSize += info.content.length;
12411250
}
12421251
}
12431252
else {
1244-
return { errorMsg: "specified file " + rootFilename + " not found" };
1253+
break;
12451254
}
12461255
}
12471256
else {
1248-
break;
1257+
return { errorMsg: "specified file " + rootFilename + " not found" };
12491258
}
12501259
}
12511260
project.finishGraph();

0 commit comments

Comments
 (0)