Make the compiled package loadable as native ESM - #260
Open
gronke wants to merge 1 commit into
Open
Conversation
…re-exports
A browser resolves a relative specifier as a URL, so `./webserial` requests a file that does not exist and the module graph fails to load.
TypeScript rewrites no specifiers, so the extension belongs in the source.
An interface re-exported with `export { … }` emits a runtime re-export of a binding the compiled module does not have, which throws on load; `export type` emits nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Serving
lib/to a browser without a bundler fails on the first module. Two independent causes, both in the sources, since TypeScript rewrites no specifiers.Relative specifiers carry no extension. A browser resolves
./webserialas a URL and requests a file that does not exist, so the module graph never finishes loading. Every relative specifier now ends in.js, which the compiler emits verbatim and every bundler already understands.Interfaces are re-exported as values.
export { SerialOptions } from "./webserial.js"emits a runtime re-export of a binding the compiled module does not have, and the browser throws on load. Each type-only re-export is nowexport type, which emits nothing.ESPLoader,Transport,ROMand the reset classes stay value exports.The stub JSON, the other half, needs import attributes and so a newer TypeScript, which is a separate change.