Skip to content

Commit 35b972e

Browse files
committed
CR feedback / Change upper limit / Add disableSizeLimit compiler option
# Conflicts: # src/compiler/commandLineParser.ts # src/compiler/diagnosticMessages.json
1 parent 708fb97 commit 35b972e

File tree

7 files changed

+65
-30
lines changed

7 files changed

+65
-30
lines changed

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ namespace ts {
305305
name: "noCustomAsyncPromise",
306306
type: "boolean",
307307
experimental: true
308+
},
309+
{
310+
name: "disableSizeLimit",
311+
type: "boolean",
312+
description: Diagnostics.Disable_the_upper_limit_for_the_total_file_size_of_a_project
308313
}
309314
];
310315

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,10 @@
24582458
"category": "Message",
24592459
"code": 6112
24602460
},
2461+
"Disable the upper limit for the total file size of a project.": {
2462+
"category": "Message",
2463+
"code": 6113
2464+
},
24612465
"Variable '{0}' implicitly has an '{1}' type.": {
24622466
"category": "Error",
24632467
"code": 7005
@@ -2662,7 +2666,7 @@
26622666
"category": "Error",
26632667
"code": 17010
26642668
},
2665-
"Too many javascript files in the project. Consider add to the `exclude` list in the config file.": {
2669+
"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'": {
26662670
"category": "Error",
26672671
"code": 17012
26682672
}

src/compiler/program.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,24 +394,38 @@ namespace ts {
394394
(oldOptions.target !== options.target) ||
395395
(oldOptions.noLib !== options.noLib) ||
396396
(oldOptions.jsx !== options.jsx) ||
397-
(oldOptions.allowJs !== options.allowJs)) {
397+
(oldOptions.allowJs !== options.allowJs) ||
398+
(oldOptions.disableSizeLimit !== options.disableSizeLimit)) {
398399
oldProgram = undefined;
399400
}
400401
}
401402

402403
if (!tryReuseStructureFromOldProgram()) {
403-
let programSize = 0;
404-
for (const name of rootNames) {
405-
const path = toPath(name, currentDirectory, getCanonicalFileName);
406-
if (programSize <= maxProgramSize) {
407-
processRootFile(name, /*isDefaultLib*/ false);
408-
if (!hasTypeScriptFileExtension(name) && filesByName.get(path)) {
409-
programSize += filesByName.get(path).text.length;
404+
if (options.disableSizeLimit === true) {
405+
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
406+
}
407+
else {
408+
let programSize = 0;
409+
for (const name of rootNames) {
410+
const path = toPath(name, currentDirectory, getCanonicalFileName);
411+
if (programSize <= maxProgramSize) {
412+
processRootFile(name, /*isDefaultLib*/ false);
413+
const file = filesByName.get(path);
414+
if (!hasTypeScriptFileExtension(name) && file && file.text) {
415+
programSize += file.text.length;
416+
}
417+
}
418+
else {
419+
// If the program size limit was reached when processing a file, this file is
420+
// likely in the problematic folder than contains too many files
421+
const commonSourceDirectory = getCommonSourceDirectory();
422+
let rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory.length, path.indexOf(directorySeparator, commonSourceDirectory.length)));
423+
if (rootLevelDirectory[rootLevelDirectory.length - 1] !== directorySeparator) {
424+
rootLevelDirectory += directorySeparator;
425+
}
426+
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));
427+
break;
410428
}
411-
}
412-
else {
413-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Too_many_javascript_files_in_the_project_Consider_add_to_the_exclude_list_in_the_config_file));
414-
break;
415429
}
416430
}
417431

src/compiler/sys.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -478,17 +478,19 @@ namespace ts {
478478
const name = combinePaths(path, current);
479479
if (!contains(exclude, getCanonicalPath(name))) {
480480
// fs.statSync would throw an exception if the file is a symlink
481-
// whose linked file doesn't exist. fs.lstatSync would return a stat
482-
// object for the symlink file itself in this case
483-
const stat = _fs.lstatSync(name);
484-
if (stat.isFile()) {
485-
if (!extension || fileExtensionIs(name, extension)) {
486-
result.push(name);
481+
// whose linked file doesn't exist.
482+
try {
483+
const stat = _fs.statSync(name);
484+
if (stat.isFile()) {
485+
if (!extension || fileExtensionIs(name, extension)) {
486+
result.push(name);
487+
}
488+
}
489+
else if (stat.isDirectory()) {
490+
directories.push(name);
487491
}
488492
}
489-
else if (stat.isDirectory()) {
490-
directories.push(name);
491-
}
493+
catch (e) { }
492494
}
493495
}
494496
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
@@ -2863,5 +2863,5 @@ namespace ts {
28632863
return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
28642864
}
28652865

2866-
export const maxProgramSize = 35 * 1024 * 1024;
2866+
export const maxProgramSize = 20 * 1024 * 1024;
28672867
}

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)