Skip to content

Commit 60801a2

Browse files
committed
Report error requiring references to have composite only if the program is not container only
1 parent 0481d44 commit 60801a2

File tree

11 files changed

+125
-16
lines changed

11 files changed

+125
-16
lines changed

src/compiler/program.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2806,7 +2806,11 @@ namespace ts {
28062806
}
28072807
const options = resolvedRef.commandLine.options;
28082808
if (!options.composite) {
2809-
createDiagnosticForReference(parentFile, index, Diagnostics.Referenced_project_0_must_have_setting_composite_Colon_true, ref.path);
2809+
// ok to not have composite if the current program is container only
2810+
const inputs = parent ? parent.commandLine.fileNames : rootNames;
2811+
if (inputs.length) {
2812+
createDiagnosticForReference(parentFile, index, Diagnostics.Referenced_project_0_must_have_setting_composite_Colon_true, ref.path);
2813+
}
28102814
}
28112815
if (ref.prepend) {
28122816
const out = options.outFile || options.out;

src/harness/virtualFileSystemWithWatch.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,4 +988,16 @@ interface Array<T> {}`
988988
return this.environmentVariables && this.environmentVariables.get(name) || "";
989989
}
990990
}
991+
992+
export const tsbuildProjectsLocation = "/user/username/projects";
993+
export function getTsBuildProjectFilePath(project: string, file: string) {
994+
return `${tsbuildProjectsLocation}/${project}/${file}`;
995+
}
996+
997+
export function getTsBuildProjectFile(project: string, file: string): File {
998+
return {
999+
path: getTsBuildProjectFilePath(project, file),
1000+
content: Harness.IO.readFile(`${Harness.IO.getWorkspaceRoot()}/tests/projects/${project}/${file}`)!
1001+
};
1002+
}
9911003
}

src/testRunner/unittests/tsbuildWatchMode.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
namespace ts.tscWatch {
22
export import libFile = TestFSWithWatch.libFile;
3-
function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray<string>, defaultOptions?: BuildOptions) {
3+
import projectsLocation = TestFSWithWatch.tsbuildProjectsLocation;
4+
import getFilePathInProject = TestFSWithWatch.getTsBuildProjectFilePath;
5+
import getFileFromProject = TestFSWithWatch.getTsBuildProjectFile;
6+
export function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray<string>, defaultOptions?: BuildOptions) {
47
const host = createSolutionBuilderWithWatchHost(system);
58
return ts.createSolutionBuilder(host, rootNames, defaultOptions || { watch: true });
69
}
@@ -13,7 +16,6 @@ namespace ts.tscWatch {
1316
}
1417

1518
describe("tsbuild-watch program updates", () => {
16-
const projectsLocation = "/user/username/projects";
1719
const project = "sample1";
1820
const enum SubProject {
1921
core = "core",
@@ -24,23 +26,10 @@ namespace ts.tscWatch {
2426
type ReadonlyFile = Readonly<File>;
2527
/** [tsconfig, index] | [tsconfig, index, anotherModule, someDecl] */
2628
type SubProjectFiles = [ReadonlyFile, ReadonlyFile] | [ReadonlyFile, ReadonlyFile, ReadonlyFile, ReadonlyFile];
27-
const root = Harness.IO.getWorkspaceRoot();
28-
2929
function getProjectPath(project: string) {
3030
return `${projectsLocation}/${project}`;
3131
}
3232

33-
function getFilePathInProject(project: string, file: string) {
34-
return `${projectsLocation}/${project}/${file}`;
35-
}
36-
37-
function getFileFromProject(project: string, file: string): File {
38-
return {
39-
path: getFilePathInProject(project, file),
40-
content: Harness.IO.readFile(`${root}/tests/projects/${project}/${file}`)!
41-
};
42-
}
43-
4433
function projectPath(subProject: SubProject) {
4534
return getFilePathInProject(project, subProject);
4635
}

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10427,6 +10427,55 @@ declare class TestLib {
1042710427
});
1042810428
});
1042910429

10430+
describe("tsserverProjectSystem with tsbuild projects", () => {
10431+
function getProjectFiles(project: string): [File, File] {
10432+
return [
10433+
TestFSWithWatch.getTsBuildProjectFile(project, "tsconfig.json"),
10434+
TestFSWithWatch.getTsBuildProjectFile(project, "index.ts"),
10435+
];
10436+
}
10437+
it("does not error on container only project", () => {
10438+
const project = "container";
10439+
const containerLib = getProjectFiles("container/lib");
10440+
const containerExec = getProjectFiles("container/exec");
10441+
const containerCompositeExec = getProjectFiles("container/compositeExec");
10442+
const containerConfig = TestFSWithWatch.getTsBuildProjectFile(project, "tsconfig.json");
10443+
const files = [libFile, ...containerLib, ...containerExec, ...containerCompositeExec, containerConfig];
10444+
const host = createServerHost(files);
10445+
10446+
// ts build should succeed
10447+
const solutionBuilder = tscWatch.createSolutionBuilder(host, [containerConfig.path], {});
10448+
solutionBuilder.buildAllProjects();
10449+
assert.equal(host.getOutput().length, 0);
10450+
10451+
// Open external project for the folder
10452+
const session = createSession(host);
10453+
const service = session.getProjectService();
10454+
service.openExternalProjects([{
10455+
projectFileName: TestFSWithWatch.getTsBuildProjectFilePath(project, project),
10456+
rootFiles: files.map(f => ({ fileName: f.path })),
10457+
options: {}
10458+
}]);
10459+
checkNumberOfProjects(service, { configuredProjects: 4 });
10460+
files.forEach(f => {
10461+
const args: protocol.FileRequestArgs = {
10462+
file: f.path,
10463+
projectFileName: endsWith(f.path, "tsconfig.json") ? f.path : undefined
10464+
};
10465+
const syntaxDiagnostics = session.executeCommandSeq<protocol.SyntacticDiagnosticsSyncRequest>({
10466+
command: protocol.CommandTypes.SyntacticDiagnosticsSync,
10467+
arguments: args
10468+
}).response;
10469+
assert.deepEqual(syntaxDiagnostics, []);
10470+
const semanticDiagnostics = session.executeCommandSeq<protocol.SemanticDiagnosticsSyncRequest>({
10471+
command: protocol.CommandTypes.SemanticDiagnosticsSync,
10472+
arguments: args
10473+
}).response;
10474+
assert.deepEqual(semanticDiagnostics, []);
10475+
});
10476+
});
10477+
});
10478+
1043010479
describe("tsserverProjectSystem duplicate packages", () => {
1043110480
// 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.
1043210481
it("works with import fixes", () => {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace container {
2+
export function getMyConst() {
3+
return myConst;
4+
}
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"outFile": "../built/local/compositeExec.js",
4+
"composite": true
5+
},
6+
"files": [
7+
"index.ts"
8+
],
9+
"references": [
10+
{ "path": "../lib", "prepend": true }
11+
]
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace container {
2+
export function getMyConst() {
3+
return myConst;
4+
}
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"outFile": "../built/local/exec.js"
4+
},
5+
"files": [
6+
"index.ts"
7+
],
8+
"references": [
9+
{ "path": "../lib", "prepend": true }
10+
]
11+
}

tests/projects/container/lib/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace container {
2+
export const myConst = 30;
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"outFile": "../built/local/lib.js",
4+
"composite": true,
5+
"declarationMap": true
6+
},
7+
"references": [],
8+
"files": [
9+
"index.ts"
10+
]
11+
}

0 commit comments

Comments
 (0)