From 78174657e7cde49dd5c0b0e81aac0c4908bb96a6 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 31 Oct 2018 15:03:42 -0700 Subject: [PATCH 1/3] Do not add source files to container only project --- src/compiler/program.ts | 18 ++++++++++-------- .../unittests/tsserverProjectSystem.ts | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index e2f743818f2..157ea0ed959 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -694,12 +694,14 @@ namespace ts { if (!resolvedProjectReferences) { resolvedProjectReferences = projectReferences.map(parseProjectReferenceConfigFile); } - for (const parsedRef of resolvedProjectReferences) { - if (parsedRef) { - const out = parsedRef.commandLine.options.outFile || parsedRef.commandLine.options.out; - if (out) { - const dtsOutfile = changeExtension(out, ".d.ts"); - processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined); + if (rootNames.length) { + for (const parsedRef of resolvedProjectReferences) { + if (parsedRef) { + const out = parsedRef.commandLine.options.outFile || parsedRef.commandLine.options.out; + if (out) { + const dtsOutfile = changeExtension(out, ".d.ts"); + processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined); + } } } } @@ -708,7 +710,7 @@ namespace ts { forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false)); // load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders - const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, host); + const typeReferences: string[] = rootNames.length ? getAutomaticTypeDirectiveNames(options, host) : emptyArray; if (typeReferences.length) { // This containingFilename needs to match with the one used in managed-side @@ -724,7 +726,7 @@ namespace ts { // - The '--noLib' flag is used. // - A 'no-default-lib' reference comment is encountered in // processing the root files. - if (!skipDefaultLib) { + if (rootNames.length && !skipDefaultLib) { // If '--lib' is not specified, include default library file according to '--target' // otherwise, using options specified in '--lib' instead of '--target' default library file const defaultLibraryFileName = getDefaultLibraryFileName(); diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index 9f569f46d4d..87766f7f1ba 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -10520,6 +10520,8 @@ declare class TestLib { }).response; assert.deepEqual(semanticDiagnostics, []); }); + const containerProject = service.configuredProjects.get(containerConfig.path)!; + checkProjectActualFiles(containerProject, [containerConfig.path]); }); }); From 851f739c8248368c3345724ca2aaeca96a36f526 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 31 Oct 2018 15:41:07 -0700 Subject: [PATCH 2/3] Dont ignore libs since that could result in unexpected error --- src/compiler/program.ts | 2 +- src/testRunner/unittests/tsserverProjectSystem.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 157ea0ed959..ca8731a533f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -726,7 +726,7 @@ namespace ts { // - The '--noLib' flag is used. // - A 'no-default-lib' reference comment is encountered in // processing the root files. - if (rootNames.length && !skipDefaultLib) { + if (!skipDefaultLib) { // If '--lib' is not specified, include default library file according to '--target' // otherwise, using options specified in '--lib' instead of '--target' default library file const defaultLibraryFileName = getDefaultLibraryFileName(); diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index 87766f7f1ba..c4dc4b9216a 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -10521,7 +10521,12 @@ declare class TestLib { assert.deepEqual(semanticDiagnostics, []); }); const containerProject = service.configuredProjects.get(containerConfig.path)!; - checkProjectActualFiles(containerProject, [containerConfig.path]); + checkProjectActualFiles(containerProject, [containerConfig.path, libFile.path]); + const optionsDiagnostics = session.executeCommandSeq({ + command: protocol.CommandTypes.CompilerOptionsDiagnosticsFull, + arguments: { projectFileName: containerProject.projectName } + }).response; + assert.deepEqual(optionsDiagnostics, []); }); }); From 121a350c5da04ddbc5bf2243a990af17fdd03ced Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 31 Oct 2018 19:00:55 -0700 Subject: [PATCH 3/3] Instead of adding lib files, avoid creating diagnostics producing checker for container projects --- src/compiler/program.ts | 4 ++-- src/testRunner/unittests/tscWatchMode.ts | 10 ++++++++-- src/testRunner/unittests/tsserverProjectSystem.ts | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ca8731a533f..15c09a1a79b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -726,7 +726,7 @@ namespace ts { // - The '--noLib' flag is used. // - A 'no-default-lib' reference comment is encountered in // processing the root files. - if (!skipDefaultLib) { + if (rootNames.length && !skipDefaultLib) { // If '--lib' is not specified, include default library file according to '--target' // otherwise, using options specified in '--lib' instead of '--target' default library file const defaultLibraryFileName = getDefaultLibraryFileName(); @@ -1841,7 +1841,7 @@ namespace ts { } function getGlobalDiagnostics(): SortedReadonlyArray { - return sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice()); + return rootNames.length ? sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice()) : emptyArray as any as SortedReadonlyArray; } function getConfigFileParsingDiagnostics(): ReadonlyArray { diff --git a/src/testRunner/unittests/tscWatchMode.ts b/src/testRunner/unittests/tscWatchMode.ts index ca00e08fdd2..3523db7544f 100644 --- a/src/testRunner/unittests/tscWatchMode.ts +++ b/src/testRunner/unittests/tscWatchMode.ts @@ -1074,7 +1074,10 @@ namespace ts.tscWatch { const host = createWatchedSystem([file1, configFile, libFile]); const watch = createWatchOfConfigFile(configFile.path, host); - checkProgramActualFiles(watch(), [libFile.path]); + checkProgramActualFiles(watch(), emptyArray); + checkOutputErrorsInitial(host, [ + "error TS18003: No inputs were found in config file '/a/b/tsconfig.json'. Specified 'include' paths were '[\"app/*\",\"test/**/*\",\"something\"]' and 'exclude' paths were '[]'.\n" + ]); }); it("non-existing directories listed in config file input array should be able to handle @types if input file list is empty", () => { @@ -1100,7 +1103,10 @@ namespace ts.tscWatch { const host = createWatchedSystem([f, config, t1, t2], { currentDirectory: getDirectoryPath(f.path) }); const watch = createWatchOfConfigFile(config.path, host); - checkProgramActualFiles(watch(), [t1.path, t2.path]); + checkProgramActualFiles(watch(), emptyArray); + checkOutputErrorsInitial(host, [ + "tsconfig.json(1,24): error TS18002: The 'files' list in config file '/a/tsconfig.json' is empty.\n" + ]); }); it("should support files without extensions", () => { diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index c4dc4b9216a..3b7e3d61a79 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -3061,7 +3061,7 @@ namespace ts.projectSystem { const configProject = configuredProjectAt(projectService, 0); checkProjectActualFiles(configProject, lazyConfiguredProjectsFromExternalProject ? emptyArray : // Since no files opened from this project, its not loaded - [libFile.path, configFile.path]); + [configFile.path]); host.reloadFS([libFile, site]); host.checkTimeoutQueueLengthAndRun(1); @@ -10521,7 +10521,7 @@ declare class TestLib { assert.deepEqual(semanticDiagnostics, []); }); const containerProject = service.configuredProjects.get(containerConfig.path)!; - checkProjectActualFiles(containerProject, [containerConfig.path, libFile.path]); + checkProjectActualFiles(containerProject, [containerConfig.path]); const optionsDiagnostics = session.executeCommandSeq({ command: protocol.CommandTypes.CompilerOptionsDiagnosticsFull, arguments: { projectFileName: containerProject.projectName }