Skip to content

API emit support to generate .d.ts / .js files from sources#3616

Open
pfumagalli wants to merge 41 commits into
microsoft:mainfrom
pfumagalli:feature/emit-support
Open

API emit support to generate .d.ts / .js files from sources#3616
pfumagalli wants to merge 41 commits into
microsoft:mainfrom
pfumagalli:feature/emit-support

Conversation

@pfumagalli

Copy link
Copy Markdown

Pull request overview

Adds initial end-to-end support for invoking the compiler’s emit through the TSGO API, wiring it through the Go API server and exposing it in the native-preview TypeScript client (sync + async), with virtual-FS write support to capture outputs.

Changes:

  • Added a new API method emit (protocol + session handler) that calls Program.Emit with EmitOnly and optional target source file.
  • Extended callback-based virtual filesystem support to include writeFile so emitted outputs can be captured by clients.
  • Added native-preview client API surface (program.emit), generated EmitFlags enum, and sync/async tests covering emit scenarios.

pfumagalli and others added 24 commits April 26, 2026 23:55
(by Copilot)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(by Copilot)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…itter


(by Copilot)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(by Copilot)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(by Copilot)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(by Copilot)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 27, 2026 00:27
@pfumagalli

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-to-end support for invoking the compiler’s emit via the TSGO API, plumbing it through the Go API server and exposing it in the native-preview TypeScript client, including virtual-FS write support so emitted outputs can be captured by clients.

Changes:

  • Added a new API method emit (protocol + session handler) that calls Program.Emit with an EmitOnly mode and optional target source file.
  • Extended callback-based virtual filesystem support with a writeFile callback for capturing emitted outputs.
  • Exposed program.emit (sync + async) in native-preview, generated EmitFlags, and added sync/async tests for emit scenarios.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/compiler/emitter.go Adds EmitOnlyFromByte validation helper for API inputs.
internal/api/session.go Wires new emit method to snapshot/program resolution and Program.Emit, routing writes through session FS.
internal/api/proto.go Adds emit method constant, request/response types, and NewEmitResponse adapter.
internal/api/callbackfs.go Adds callbackFS support for delegating WriteFile to the client.
_packages/native-preview/src/api/fs.ts Adds writeFile to the supported FS callback list and virtual FS implementation.
_packages/native-preview/src/api/sync/client.ts Registers writeFile callback plumbing for sync transport.
_packages/native-preview/src/api/async/client.ts Registers writeFile callback plumbing for async JSON-RPC transport.
_packages/native-preview/src/api/sync/types.ts Introduces EmitResult type for sync API surface.
_packages/native-preview/src/api/async/types.ts Introduces EmitResult type for async API surface.
_packages/native-preview/src/api/sync/api.ts Exposes EmitFlags, exports EmitResult, and adds Program.emit() (sync).
_packages/native-preview/src/api/async/api.ts Exposes EmitFlags, exports EmitResult, and adds Program.emit() (async).
_packages/native-preview/src/enums/emitFlags.ts Adds generated runtime enum for emit mode selection.
_packages/native-preview/src/enums/emitFlags.enum.ts Adds generated const enum variant for emit mode selection.
_packages/native-preview/test/sync/api.test.ts Adds sync emit tests covering all/js/dts/single-file emit cases.
_packages/native-preview/test/async/api.test.ts Adds async emit tests covering all/js/dts/single-file emit cases.
Herebyfile.mjs Registers EmitFlags for enum generation from Go sources.

Comment thread internal/api/session.go
Comment thread internal/api/proto.go
@hegrec

hegrec commented May 11, 2026

Copy link
Copy Markdown

Hey folks, any plans to merge this PR? This appears to be one of the missing links I've been hoping for. Specifically, the capability to wrap the emission pipeline with the virtual file system and serve virtual files to tsgo while subsequently capturing emissions (in my case, specifically interested in being able to capture d.ts content via writeFile on the JS side so I can store it in a custom location).

In my use case I am already leveraging the virtual file system to orchestrate the typechecking loop and this works really well. Would love to be able to have more or less the same approach with emit.

Comment thread internal/compiler/emitter.go Outdated
@RyanCavanaugh RyanCavanaugh added the No linked issue This PR doesn't say what bug it fixes label Jun 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Comment thread internal/api/session.go Outdated
@pfumagalli pfumagalli requested a review from Copilot June 11, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pfumagalli pfumagalli requested a review from Copilot June 11, 2026 20:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Comment thread internal/api/session.go Outdated
Comment thread internal/api/session.go
Comment thread internal/api/proto.go
Comment thread _packages/native-preview/src/api/sync/client.ts
Comment thread _packages/native-preview/src/api/async/client.ts
> Using a Go `byte`/`uint8` for a JSON field means invalid values
> (negative, non-integer, >255) will fail during JSON unmarshal,
> before `handleEmit` can wrap the error as `ErrClientError`. To
> keep error handling consistent and provide clearer client errors,
> consider unmarshalling `emitOnly` as an `int` (or `uint32`) and
> doing explicit validation in `handleEmit`.
@pfumagalli

Copy link
Copy Markdown
Author

Updated and resolved conflicts with upstream...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No linked issue This PR doesn't say what bug it fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants