ttsc
Version:
General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.
26 lines (25 loc) • 1.57 kB
TypeScript
/**
* Replace a served emit's trailing external `//# sourceMappingURL=<relative>`
* comment with an inline `data:` URL whose `sources` are absolute `file://`
* URLs of the true on-disk source files.
*
* Ttsx runs tsgo-built JavaScript under the ORIGINAL `.ts` source URL. When the
* owning tsconfig emits external maps, the served text ends with a relative
* `sourceMappingURL` that Node resolves against the `.ts` script URL — where no
* `.js.map` exists — and that the per-run emit directory deletes at process
* exit anyway. Node's V8 coverage then caches the script with `data: null` and
* c8 misattributes lines (false 100%, issue #353); `--enable-source-maps`
* cannot map stack frames. Inlining the map into the served text (which V8
* captures at compile time) survives both the wrong resolution base and the
* post-exit cleanup, and absolutizing `sources` fixes the mis-rooted paths that
* mapped stack frames, debuggers, and IDE links would otherwise print.
*
* Idempotent: re-running it on already-inlined text (whose `sources` are
* already absolute `file://` URLs) reproduces the same bytes, which keeps the
* shared cross-process dependency cache deterministic.
*
* @param source - The emitted JavaScript text served under the source URL.
* @param emittedFile - On-disk path of the emitted `.js`, beside its `.map`.
* @param sourceFile - Real path of the `.ts` source the emit was built from.
*/
export declare function inlineServedSourceMap(source: string, emittedFile: string | undefined, sourceFile: string | undefined): string;