API emit support to generate .d.ts / .js files from sources#3616
API emit support to generate .d.ts / .js files from sources#3616pfumagalli wants to merge 41 commits into
emit support to generate .d.ts / .js files from sources#3616Conversation
(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>
…Files`) as null (by Copilot)
(by Copilot) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
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 callsProgram.Emitwith anEmitOnlymode and optional target source file. - Extended callback-based virtual filesystem support with a
writeFilecallback for capturing emitted outputs. - Exposed
program.emit(sync + async) in native-preview, generatedEmitFlags, 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. |
(by Copilot)
|
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. |
> 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`.
|
Updated and resolved conflicts with upstream... |
Pull request overview
Adds initial end-to-end support for invoking the compiler’s
emitthrough 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:
emit(protocol + session handler) that callsProgram.EmitwithEmitOnlyand optional target source file.writeFileso emitted outputs can be captured by clients.program.emit), generatedEmitFlagsenum, and sync/async tests covering emit scenarios.