From 60801a261c35a32738dbdd188818710bacdcf40c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 30 Oct 2018 15:22:00 -0700 Subject: [PATCH] Report error requiring references to have composite only if the program is not container only --- src/compiler/program.ts | 6 ++- src/harness/virtualFileSystemWithWatch.ts | 12 +++++ src/testRunner/unittests/tsbuildWatchMode.ts | 19 ++----- .../unittests/tsserverProjectSystem.ts | 49 +++++++++++++++++++ .../projects/container/compositeExec/index.ts | 5 ++ .../container/compositeExec/tsconfig.json | 12 +++++ tests/projects/container/exec/index.ts | 5 ++ tests/projects/container/exec/tsconfig.json | 11 +++++ tests/projects/container/lib/index.ts | 3 ++ tests/projects/container/lib/tsconfig.json | 11 +++++ tests/projects/container/tsconfig.json | 8 +++ 11 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 tests/projects/container/compositeExec/index.ts create mode 100644 tests/projects/container/compositeExec/tsconfig.json create mode 100644 tests/projects/container/exec/index.ts create mode 100644 tests/projects/container/exec/tsconfig.json create mode 100644 tests/projects/container/lib/index.ts create mode 100644 tests/projects/container/lib/tsconfig.json create mode 100644 tests/projects/container/tsconfig.json diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 997bdaa80c7..e2f743818f2 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2806,7 +2806,11 @@ namespace ts { } const options = resolvedRef.commandLine.options; if (!options.composite) { - createDiagnosticForReference(parentFile, index, Diagnostics.Referenced_project_0_must_have_setting_composite_Colon_true, ref.path); + // ok to not have composite if the current program is container only + const inputs = parent ? parent.commandLine.fileNames : rootNames; + if (inputs.length) { + createDiagnosticForReference(parentFile, index, Diagnostics.Referenced_project_0_must_have_setting_composite_Colon_true, ref.path); + } } if (ref.prepend) { const out = options.outFile || options.out; diff --git a/src/harness/virtualFileSystemWithWatch.ts b/src/harness/virtualFileSystemWithWatch.ts index bd31a04a0df..0ec3b8431e9 100644 --- a/src/harness/virtualFileSystemWithWatch.ts +++ b/src/harness/virtualFileSystemWithWatch.ts @@ -988,4 +988,16 @@ interface Array {}` return this.environmentVariables && this.environmentVariables.get(name) || ""; } } + + export const tsbuildProjectsLocation = "/user/username/projects"; + export function getTsBuildProjectFilePath(project: string, file: string) { + return `${tsbuildProjectsLocation}/${project}/${file}`; + } + + export function getTsBuildProjectFile(project: string, file: string): File { + return { + path: getTsBuildProjectFilePath(project, file), + content: Harness.IO.readFile(`${Harness.IO.getWorkspaceRoot()}/tests/projects/${project}/${file}`)! + }; + } } diff --git a/src/testRunner/unittests/tsbuildWatchMode.ts b/src/testRunner/unittests/tsbuildWatchMode.ts index 3461cfdb785..9178416373c 100644 --- a/src/testRunner/unittests/tsbuildWatchMode.ts +++ b/src/testRunner/unittests/tsbuildWatchMode.ts @@ -1,6 +1,9 @@ namespace ts.tscWatch { export import libFile = TestFSWithWatch.libFile; - function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray, defaultOptions?: BuildOptions) { + import projectsLocation = TestFSWithWatch.tsbuildProjectsLocation; + import getFilePathInProject = TestFSWithWatch.getTsBuildProjectFilePath; + import getFileFromProject = TestFSWithWatch.getTsBuildProjectFile; + export function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray, defaultOptions?: BuildOptions) { const host = createSolutionBuilderWithWatchHost(system); return ts.createSolutionBuilder(host, rootNames, defaultOptions || { watch: true }); } @@ -13,7 +16,6 @@ namespace ts.tscWatch { } describe("tsbuild-watch program updates", () => { - const projectsLocation = "/user/username/projects"; const project = "sample1"; const enum SubProject { core = "core", @@ -24,23 +26,10 @@ namespace ts.tscWatch { type ReadonlyFile = Readonly; /** [tsconfig, index] | [tsconfig, index, anotherModule, someDecl] */ type SubProjectFiles = [ReadonlyFile, ReadonlyFile] | [ReadonlyFile, ReadonlyFile, ReadonlyFile, ReadonlyFile]; - const root = Harness.IO.getWorkspaceRoot(); - function getProjectPath(project: string) { return `${projectsLocation}/${project}`; } - function getFilePathInProject(project: string, file: string) { - return `${projectsLocation}/${project}/${file}`; - } - - function getFileFromProject(project: string, file: string): File { - return { - path: getFilePathInProject(project, file), - content: Harness.IO.readFile(`${root}/tests/projects/${project}/${file}`)! - }; - } - function projectPath(subProject: SubProject) { return getFilePathInProject(project, subProject); } diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index 3ffd28702a2..b4a412d24e3 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -10427,6 +10427,55 @@ declare class TestLib { }); }); + describe("tsserverProjectSystem with tsbuild projects", () => { + function getProjectFiles(project: string): [File, File] { + return [ + TestFSWithWatch.getTsBuildProjectFile(project, "tsconfig.json"), + TestFSWithWatch.getTsBuildProjectFile(project, "index.ts"), + ]; + } + it("does not error on container only project", () => { + const project = "container"; + const containerLib = getProjectFiles("container/lib"); + const containerExec = getProjectFiles("container/exec"); + const containerCompositeExec = getProjectFiles("container/compositeExec"); + const containerConfig = TestFSWithWatch.getTsBuildProjectFile(project, "tsconfig.json"); + const files = [libFile, ...containerLib, ...containerExec, ...containerCompositeExec, containerConfig]; + const host = createServerHost(files); + + // ts build should succeed + const solutionBuilder = tscWatch.createSolutionBuilder(host, [containerConfig.path], {}); + solutionBuilder.buildAllProjects(); + assert.equal(host.getOutput().length, 0); + + // Open external project for the folder + const session = createSession(host); + const service = session.getProjectService(); + service.openExternalProjects([{ + projectFileName: TestFSWithWatch.getTsBuildProjectFilePath(project, project), + rootFiles: files.map(f => ({ fileName: f.path })), + options: {} + }]); + checkNumberOfProjects(service, { configuredProjects: 4 }); + files.forEach(f => { + const args: protocol.FileRequestArgs = { + file: f.path, + projectFileName: endsWith(f.path, "tsconfig.json") ? f.path : undefined + }; + const syntaxDiagnostics = session.executeCommandSeq({ + command: protocol.CommandTypes.SyntacticDiagnosticsSync, + arguments: args + }).response; + assert.deepEqual(syntaxDiagnostics, []); + const semanticDiagnostics = session.executeCommandSeq({ + command: protocol.CommandTypes.SemanticDiagnosticsSync, + arguments: args + }).response; + assert.deepEqual(semanticDiagnostics, []); + }); + }); + }); + describe("tsserverProjectSystem duplicate packages", () => { // Tests that 'moduleSpecifiers.ts' will import from the redirecting file, and not from the file it redirects to, if that can provide a global module specifier. it("works with import fixes", () => { diff --git a/tests/projects/container/compositeExec/index.ts b/tests/projects/container/compositeExec/index.ts new file mode 100644 index 00000000000..4d3216676fb --- /dev/null +++ b/tests/projects/container/compositeExec/index.ts @@ -0,0 +1,5 @@ +namespace container { + export function getMyConst() { + return myConst; + } +} \ No newline at end of file diff --git a/tests/projects/container/compositeExec/tsconfig.json b/tests/projects/container/compositeExec/tsconfig.json new file mode 100644 index 00000000000..f28a9e44eee --- /dev/null +++ b/tests/projects/container/compositeExec/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "outFile": "../built/local/compositeExec.js", + "composite": true + }, + "files": [ + "index.ts" + ], + "references": [ + { "path": "../lib", "prepend": true } + ] +} \ No newline at end of file diff --git a/tests/projects/container/exec/index.ts b/tests/projects/container/exec/index.ts new file mode 100644 index 00000000000..4d3216676fb --- /dev/null +++ b/tests/projects/container/exec/index.ts @@ -0,0 +1,5 @@ +namespace container { + export function getMyConst() { + return myConst; + } +} \ No newline at end of file diff --git a/tests/projects/container/exec/tsconfig.json b/tests/projects/container/exec/tsconfig.json new file mode 100644 index 00000000000..1a3a4c9edd1 --- /dev/null +++ b/tests/projects/container/exec/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "outFile": "../built/local/exec.js" + }, + "files": [ + "index.ts" + ], + "references": [ + { "path": "../lib", "prepend": true } + ] +} \ No newline at end of file diff --git a/tests/projects/container/lib/index.ts b/tests/projects/container/lib/index.ts new file mode 100644 index 00000000000..c89a3a3d289 --- /dev/null +++ b/tests/projects/container/lib/index.ts @@ -0,0 +1,3 @@ +namespace container { + export const myConst = 30; +} \ No newline at end of file diff --git a/tests/projects/container/lib/tsconfig.json b/tests/projects/container/lib/tsconfig.json new file mode 100644 index 00000000000..15766e83721 --- /dev/null +++ b/tests/projects/container/lib/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "outFile": "../built/local/lib.js", + "composite": true, + "declarationMap": true + }, + "references": [], + "files": [ + "index.ts" + ] +} \ No newline at end of file diff --git a/tests/projects/container/tsconfig.json b/tests/projects/container/tsconfig.json new file mode 100644 index 00000000000..854c4029fd9 --- /dev/null +++ b/tests/projects/container/tsconfig.json @@ -0,0 +1,8 @@ +{ + "files": [], + "include": [], + "references": [ + { "path": "./exec" }, + { "path": "./compositeExec" } + ] +} \ No newline at end of file