Skip to content

Commit c7041f7

Browse files
fix(browser): bundle binding types in dts output (#8930)
Fixes #8929 The browser package's `.d.mts` files reference `binding.cjs` as external, but no type declaration file exists in the published package. This is because `resolveWasiBinding()` marks `binding.cjs` as `external: 'relative'` for all importers, including `.d.ts` files from `rolldown-plugin-dts`. The dts resolver sees the external flag and passes it through without bundling the types. Fix: skip the external redirect when the importer is a `.d.ts` file, so the dts plugin can resolve and bundle binding types inline. Co-authored-by: IWANABETHATGUY <[email protected]>
1 parent 6ab459a commit c7041f7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/rolldown/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function withShared({
155155
}
156156

157157
// alias binding file to rolldown-binding.wasi.js and mark it as external
158-
// alias its dts file to rolldown-binding.d.ts without external
158+
// skip redirection for .d.ts importers so the dts plugin can bundle types
159159
function resolveWasiBinding(isBrowserBuild?: boolean): Plugin {
160160
return {
161161
name: 'resolve-wasi-binding',
@@ -165,6 +165,8 @@ function resolveWasiBinding(isBrowserBuild?: boolean): Plugin {
165165
const resolution = await this.resolve(id, importer, options);
166166

167167
if (resolution?.id === bindingFile) {
168+
// Let .d.ts importers resolve normally so binding types get bundled inline
169+
if (importer && /\.d\.[cm]?ts$/.test(importer)) return resolution;
168170
const id = isBrowserBuild ? bindingFileWasiBrowser : bindingFileWasi;
169171
return { id, external: 'relative' };
170172
}

0 commit comments

Comments
 (0)