Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,12 @@ export class API<FromLSP extends boolean = false> implements FormatDiagnosticsHo
/** @internal */
async createBuildOrchestrator(rootNames: readonly string[], buildOrchestratorOptions: BuildOrchestratorOptions): Promise<BuildOrchestrator> {
await this.ensureInitialized();
const { cwd, dry, force, verbose, stopBuildOnErrors, overrideCompilerOptions } = buildOrchestratorOptions;
const orchestratorResponse = await this.client.apiRequest("createBuildOrchestrator", {
...buildOrchestratorOptions,
...buildOrchestratorOptions.overrideCompilerOptions,
cwd: buildOrchestratorOptions.cwd === undefined
? undefined
: toRootedDirectoryPath(buildOrchestratorOptions.cwd, this.getCurrentDirectory()),
rootNames,
cwd: cwd === undefined ? undefined : toRootedDirectoryPath(cwd, this.getCurrentDirectory()),
buildOptions: { dry, force, verbose, stopBuildOnErrors },
compilerOptions: overrideCompilerOptions,
});

const orchestrator = new BuildOrchestrator(this.client, orchestratorResponse, () => {
Expand Down Expand Up @@ -2178,6 +2177,7 @@ export interface OverrideCompilerOptions {
sourceMap?: boolean;
inlineSourceMap?: boolean;
traceResolution?: boolean;
noEmit?: boolean;
}

export class BuildOrchestrator {
Expand Down
5 changes: 4 additions & 1 deletion packages/typescript/src/api/proto.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,12 @@ export interface GetCurrentLanguageServerSnapshotParams {
changes?: LanguageServerSnapshotChanges | undefined;
}

export interface CreateBuildOrchestratorParams extends BuildOptions, CompilerOptions {
export interface CreateBuildOrchestratorParams {
rootNames: readonly string[] | null;
cwd?: RootedDirectoryPath | undefined;
/** Only a subset of these options are exposed in the API */
buildOptions?: BuildOptions | undefined;
compilerOptions?: CompilerOptions | undefined;
}

export interface CreateBuildOrchestratorResponse {
Expand Down
19 changes: 9 additions & 10 deletions packages/typescript/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,12 @@ export class API<FromLSP extends boolean = false> implements FormatDiagnosticsHo
"createBuildOrchestrator",
function (rootNames: readonly string[], buildOrchestratorOptions: BuildOrchestratorOptions): BuildOrchestrator {
owner.ensureInitialized();
const { cwd, dry, force, verbose, stopBuildOnErrors, overrideCompilerOptions } = buildOrchestratorOptions;
const orchestratorResponse = owner.client.apiRequest("createBuildOrchestrator", {
...buildOrchestratorOptions,
...buildOrchestratorOptions.overrideCompilerOptions,
cwd: buildOrchestratorOptions.cwd === undefined
? undefined
: toRootedDirectoryPath(buildOrchestratorOptions.cwd, owner.getCurrentDirectory()),
rootNames,
cwd: cwd === undefined ? undefined : toRootedDirectoryPath(cwd, owner.getCurrentDirectory()),
buildOptions: { dry, force, verbose, stopBuildOnErrors },
compilerOptions: overrideCompilerOptions,
});

const orchestrator = new BuildOrchestrator(owner.client, orchestratorResponse, () => {
Expand All @@ -609,13 +608,12 @@ export class API<FromLSP extends boolean = false> implements FormatDiagnosticsHo
},
function* (rootNames: readonly string[], buildOrchestratorOptions: BuildOrchestratorOptions): Generator<ProtocolRequest, BuildOrchestrator, ProtocolResponse["result"]> {
yield* owner.ensureInitialized.gen();
const { cwd, dry, force, verbose, stopBuildOnErrors, overrideCompilerOptions } = buildOrchestratorOptions;
const orchestratorResponse = yield* apiRequest("createBuildOrchestrator", {
...buildOrchestratorOptions,
...buildOrchestratorOptions.overrideCompilerOptions,
cwd: buildOrchestratorOptions.cwd === undefined
? undefined
: toRootedDirectoryPath(buildOrchestratorOptions.cwd, owner.getCurrentDirectory()),
rootNames,
cwd: cwd === undefined ? undefined : toRootedDirectoryPath(cwd, owner.getCurrentDirectory()),
buildOptions: { dry, force, verbose, stopBuildOnErrors },
compilerOptions: overrideCompilerOptions,
});

const orchestrator = new BuildOrchestrator(owner.client, orchestratorResponse, () => {
Expand Down Expand Up @@ -3933,6 +3931,7 @@ export interface OverrideCompilerOptions {
sourceMap?: boolean;
inlineSourceMap?: boolean;
traceResolution?: boolean;
noEmit?: boolean;
}

export class BuildOrchestrator {
Expand Down
72 changes: 71 additions & 1 deletion packages/typescript/test/async/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@ describe("BuildOrchestrator", () => {
overrideCompilerOptions: {
incremental: true,
assumeChangesOnlyAffectDirectDependencies: true,
declaration: false,
declaration: true,
declarationMap: true,
emitDeclarationOnly: false,
sourceMap: false,
Expand All @@ -1725,6 +1725,76 @@ describe("BuildOrchestrator", () => {
assert.match(fs.readFile!(toRootedFilePath("/b/dist/index.js", undefined))!, /export const b = 2/);
});

test("applies overrideCompilerOptions to the build", async () => {
const { api: disposableApi, fs } = spawnAPIWithFS({ ...files });
await using api = disposableApi;
// @ts-ignore -- Internal API exercised by source tests.
const orchestrator = await api.createBuildOrchestrator(
["/a/tsconfig.json"],
{ cwd: "/", overrideCompilerOptions: { declarationMap: true } },
);

assert.equal((await orchestrator.build()).status, 0);
assert.match(fs.readFile!(toRootedFilePath("/a/dist/index.d.ts.map", undefined))!, /"sources":\["\.\.\/src\/index\.ts"\]/);
});

test("applies build options to the build", async () => {
const { api: disposableApi, fs } = spawnAPIWithFS({ ...files });
await using api = disposableApi;
// @ts-ignore -- Internal API exercised by source tests.
const orchestrator = await api.createBuildOrchestrator(
["/a/tsconfig.json"],
{ cwd: "/", dry: true },
);

assert.equal((await orchestrator.build()).status, 0);
assert.equal(fs.readFile!(toRootedFilePath("/a/dist/index.js", undefined)), serverFS.useOS);
});

test("does not emit error-free projects when noEmit is overridden", async () => {
const { api: disposableApi, fs } = spawnAPIWithFS({
"/a/tsconfig.json": JSON.stringify({
compilerOptions: { outDir: "dist", rootDir: "src" },
files: ["src/index.ts"],
}),
"/a/src/index.ts": `export const a = 1;`,
});
await using api = disposableApi;
// @ts-ignore -- Internal API exercised by source tests.
const orchestrator = await api.createBuildOrchestrator(
["/a/tsconfig.json"],
{ cwd: "/", overrideCompilerOptions: { noEmit: true } },
);

const response = await orchestrator.build();
assert.equal(response.status, 0);
assert.equal(response.diagnostics, undefined);
assert.equal(fs.readFile!(toRootedFilePath("/a/dist/index.js", undefined)), serverFS.useOS);
});

test("does not emit when noEmit is overridden", async () => {
const source = `export const value: string = 1;`;
const { api: disposableApi, fs } = spawnAPIWithFS({
"/a/tsconfig.json": JSON.stringify({
compilerOptions: { outDir: "dist", rootDir: "src" },
files: ["src/index.ts"],
}),
"/a/src/index.ts": source,
});
await using api = disposableApi;
// @ts-ignore -- Internal API exercised by source tests.
const orchestrator = await api.createBuildOrchestrator(
["/a/tsconfig.json"],
{ cwd: "/", overrideCompilerOptions: { noEmit: true } },
);

const response = await orchestrator.build();
assert.equal(response.status, 2);
assert.equal(response.diagnostics?.length, 1);
assert.equal(response.diagnostics[0].code, 2322);
assert.equal(fs.readFile!(toRootedFilePath("/a/dist/index.js", undefined)), serverFS.useOS);
});

test("returns diagnostics in build response information", async () => {
const source = `export const value: string = 1;`;
const { api: disposableApi } = spawnAPIWithFS({
Expand Down
72 changes: 71 additions & 1 deletion packages/typescript/test/sync/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ describe("BuildOrchestrator", () => {
overrideCompilerOptions: {
incremental: true,
assumeChangesOnlyAffectDirectDependencies: true,
declaration: false,
declaration: true,
declarationMap: true,
emitDeclarationOnly: false,
sourceMap: false,
Expand All @@ -1591,6 +1591,76 @@ describe("BuildOrchestrator", () => {
assert.match(fs.readFile!(toRootedFilePath("/b/dist/index.js", undefined))!, /export const b = 2/);
});

test("applies overrideCompilerOptions to the build", () => {
const { api: disposableApi, fs } = spawnAPIWithFS({ ...files });
using api = disposableApi;
// @ts-ignore -- Internal API exercised by source tests.
const orchestrator = api.createBuildOrchestrator(
["/a/tsconfig.json"],
{ cwd: "/", overrideCompilerOptions: { declarationMap: true } },
);

assert.equal((orchestrator.build()).status, 0);
assert.match(fs.readFile!(toRootedFilePath("/a/dist/index.d.ts.map", undefined))!, /"sources":\["\.\.\/src\/index\.ts"\]/);
});

test("applies build options to the build", () => {
const { api: disposableApi, fs } = spawnAPIWithFS({ ...files });
using api = disposableApi;
// @ts-ignore -- Internal API exercised by source tests.
const orchestrator = api.createBuildOrchestrator(
["/a/tsconfig.json"],
{ cwd: "/", dry: true },
);

assert.equal((orchestrator.build()).status, 0);
assert.equal(fs.readFile!(toRootedFilePath("/a/dist/index.js", undefined)), serverFS.useOS);
});

test("does not emit error-free projects when noEmit is overridden", () => {
const { api: disposableApi, fs } = spawnAPIWithFS({
"/a/tsconfig.json": JSON.stringify({
compilerOptions: { outDir: "dist", rootDir: "src" },
files: ["src/index.ts"],
}),
"/a/src/index.ts": `export const a = 1;`,
});
using api = disposableApi;
// @ts-ignore -- Internal API exercised by source tests.
const orchestrator = api.createBuildOrchestrator(
["/a/tsconfig.json"],
{ cwd: "/", overrideCompilerOptions: { noEmit: true } },
);

const response = orchestrator.build();
assert.equal(response.status, 0);
assert.equal(response.diagnostics, undefined);
assert.equal(fs.readFile!(toRootedFilePath("/a/dist/index.js", undefined)), serverFS.useOS);
});

test("does not emit when noEmit is overridden", () => {
const source = `export const value: string = 1;`;
const { api: disposableApi, fs } = spawnAPIWithFS({
"/a/tsconfig.json": JSON.stringify({
compilerOptions: { outDir: "dist", rootDir: "src" },
files: ["src/index.ts"],
}),
"/a/src/index.ts": source,
});
using api = disposableApi;
// @ts-ignore -- Internal API exercised by source tests.
const orchestrator = api.createBuildOrchestrator(
["/a/tsconfig.json"],
{ cwd: "/", overrideCompilerOptions: { noEmit: true } },
);

const response = orchestrator.build();
assert.equal(response.status, 2);
assert.equal(response.diagnostics?.length, 1);
assert.equal(response.diagnostics[0].code, 2322);
assert.equal(fs.readFile!(toRootedFilePath("/a/dist/index.js", undefined)), serverFS.useOS);
});

test("returns diagnostics in build response information", () => {
const source = `export const value: string = 1;`;
const { api: disposableApi } = spawnAPIWithFS({
Expand Down
3 changes: 2 additions & 1 deletion tools/gen-proto/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func TestGenerate(t *testing.T) {
`import type { CompilerOptions, PluginImport } from "./compilerOptions.generated.ts";`,
`export type { CompilerOptions, PluginImport } from "./compilerOptions.generated.ts";`,
`export * from "./compilerOptions.generated.ts";`,
`export interface CreateBuildOrchestratorParams extends BuildOptions, CompilerOptions`,
`buildOptions?: BuildOptions | undefined;`,
`compilerOptions?: CompilerOptions | undefined;`,
`jsx?: JsxEmit | undefined;`,
`module?: ModuleKind | undefined;`,
`moduleResolution?: ModuleResolutionKind | undefined;`,
Expand Down
6 changes: 3 additions & 3 deletions tsc/internal/api/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,9 @@ type ProfileResult struct {
type CreateBuildOrchestratorParams struct {
RootNames []string `json:"rootNames"`
Cwd tspath.RootedDirectoryPath `json:"cwd,omitempty"`
// Only a subset of these options are exposed the API
*core.BuildOptions `json:"buildOptions,omitempty"`
*core.CompilerOptions `json:"compilerOptions,omitempty"`
// Only a subset of these options are exposed in the API
BuildOptions *core.BuildOptions `json:"buildOptions,omitempty"`
CompilerOptions *core.CompilerOptions `json:"compilerOptions,omitempty"`
}

type CreateBuildOrchestratorResponse struct {
Expand Down