Report error requiring references to have composite only if the program is not container only

This commit is contained in:
Sheetal Nandi
2018-10-30 15:22:00 -07:00
parent 0481d44501
commit 60801a261c
11 changed files with 125 additions and 16 deletions

View File

@@ -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;

View File

@@ -988,4 +988,16 @@ interface Array<T> {}`
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}`)!
};
}
}

View File

@@ -1,6 +1,9 @@
namespace ts.tscWatch {
export import libFile = TestFSWithWatch.libFile;
function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray<string>, defaultOptions?: BuildOptions) {
import projectsLocation = TestFSWithWatch.tsbuildProjectsLocation;
import getFilePathInProject = TestFSWithWatch.getTsBuildProjectFilePath;
import getFileFromProject = TestFSWithWatch.getTsBuildProjectFile;
export function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray<string>, 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<File>;
/** [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);
}

View File

@@ -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<protocol.SyntacticDiagnosticsSyncRequest>({
command: protocol.CommandTypes.SyntacticDiagnosticsSync,
arguments: args
}).response;
assert.deepEqual(syntaxDiagnostics, []);
const semanticDiagnostics = session.executeCommandSeq<protocol.SemanticDiagnosticsSyncRequest>({
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", () => {

View File

@@ -0,0 +1,5 @@
namespace container {
export function getMyConst() {
return myConst;
}
}

View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"outFile": "../built/local/compositeExec.js",
"composite": true
},
"files": [
"index.ts"
],
"references": [
{ "path": "../lib", "prepend": true }
]
}

View File

@@ -0,0 +1,5 @@
namespace container {
export function getMyConst() {
return myConst;
}
}

View File

@@ -0,0 +1,11 @@
{
"compilerOptions": {
"outFile": "../built/local/exec.js"
},
"files": [
"index.ts"
],
"references": [
{ "path": "../lib", "prepend": true }
]
}

View File

@@ -0,0 +1,3 @@
namespace container {
export const myConst = 30;
}

View File

@@ -0,0 +1,11 @@
{
"compilerOptions": {
"outFile": "../built/local/lib.js",
"composite": true,
"declarationMap": true
},
"references": [],
"files": [
"index.ts"
]
}

View File

@@ -0,0 +1,8 @@
{
"files": [],
"include": [],
"references": [
{ "path": "./exec" },
{ "path": "./compositeExec" }
]
}