Repository navigation
Write a library's type declarations with its bundle - #72
Merged
Merged
Conversation
mix volt.build --declarations writes one <name>.d.ts per entry beside its bundle, without a hash. Volt.Builder.Declarations emits each module through OXC's isolated declarations, or the plugin that owns it, then bundles them as rollup-plugin-dts does: it walks the graph along the declarations' own imports so types-only modules are included, keeps the declarations the entry's exports reach and the ambient ones, hoists imports of other packages, and renames same-named declarations of different modules. Requires oxc 0.19 and quickbeam 0.11.3. Fixes #71
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.
Fixes #71. Depends on oxc 0.19 (elixir-volt/oxc_ex#8) and quickbeam 0.11.3.
mix volt.build --declarations/config :volt, declarations: truewrites one<name>.d.tsper script entry beside its bundle, unhashed, forpackage.json'stypes.How (
Volt.Builder.Declarations): each module →OXC.isolated_declarations/3(or the owning plugin'sdeclaration/3, so.vueworks through vize). The graph is walked along the declarations' imports viaVolt.Builder.Resolver, so modules that only hold types are included. Then a dts bundle in therollup-plugin-dtssense: only declarations reachable from the entry's exports are kept (plus ambientdeclare module/declare global), external imports are hoisted and deduped, project imports/re-exports/export *are resolved to the declaring module, same-named declarations in different modules get$1,$2(nearest the entry keeps its name), and oneexport { ... }list closes the file. Rolldown 1.1 has no.d.tsmodule type, so the bundling is Volt's own over OXC ASTs.Verified on phoenix_replay's client (the issue's case, with the one
replayMetadataannotation it needs): the bundle passestsc --strict, and a type-level check against tsc's own 10-file--declarationoutput shows identical export sets and compatible types. 31 modules in ~2 ms.Errors: an exported declaration without explicit types fails the build with the module path and TS9007/9010-style diagnostics;
import * as/export * asof project modules and anonymousexport defaultare reported as unsupported.Tests cover reachability, re-exports and aliases,
export *, external hoisting, JSDoc, renaming, Vue components, the error paths, and the build integration (single and multi-entry ESM).