Skip to content

fix: preserve rolldown resolution if an id is externalized#213

Merged
sxzz merged 1 commit intosxzz:mainfrom
brc-dd:fix/external-relative-ignored
Mar 25, 2026
Merged

fix: preserve rolldown resolution if an id is externalized#213
sxzz merged 1 commit intosxzz:mainfrom
brc-dd:fix/external-relative-ignored

Conversation

@brc-dd
Copy link
Copy Markdown
Contributor

@brc-dd brc-dd commented Mar 21, 2026

  • This PR contains AI-generated code, but I have carefully reviewed it myself. Otherwise, my PR may be closed.
  • I understand that my PR is more likely to be rejected or requested for changes if it contains AI-generated code that I do not fully understand.

Description

Something like this doesn't work properly in tsdown currently:

  plugins: [
    {
      name: 'externalize-shared',
      async resolveId(id, importer) {
        const resolved = await this.resolve(id, importer)
        if (resolved?.id.includes('shared')) {
          return { id: resolved.id, external: 'relative' }
        }
      }
    }
  ]

It works for the JS part, like if src/foo/bar.ts has import {} from '../../shared', then the compiled dist/foo/index.js has ../shared.js, but the DTS part is left with ../../shared.

(I know this example is simple enough to be specified via external/deps.neverBundle, but the real use case has less simple logic.)

Earlier code kept the id unchanged for dts files since it returned it's own external object instead of respecting other resolveId hooks in the chain.

Linked Issues

Additional context

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 25, 2026

Open in StackBlitz

npm i https://pkg.pr.new/rolldown-plugin-dts@213

commit: deda5ab

@sxzz sxzz merged commit d6ef23c into sxzz:main Mar 25, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants