Skip to content

feat(typescript): support modules imported with import attributes in Rollup 5 - #2074

Open
lukastaegert wants to merge 1 commit into
masterfrom
feat/rollup-5/typescript
Open

lukastaegert wants to merge 1 commit into
masterfrom
feat/rollup-5/typescript

Conversation

@lukastaegert

Copy link
Copy Markdown
Member

Rollup Plugin Name: typescript

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes
  • no

Breaking Changes?

  • yes
  • no

List any relevant issue numbers:

#2037

Description

Rollup 5 appends an encoded ?attributes=... suffix to the id of every module imported with import attributes, so hooks that ran on foo.js now see foo.js?attributes=%7B%22type%22%3A%22json%22%7D.

The plugin handed the encoded id to TypeScript: addWatchFile, the file list TypeScript is configured with, and the output-file lookup all received file.ts?attributes=%7B%22type%22%3A%22ts%22%7D, so attributed modules were not compiled by the plugin and Rollup fell back to parsing raw TypeScript. importerRawId is likewise needed for the containing file under node16/nodenext, where the encoded importer makes TypeScript pick the require instead of the import condition.

Filtering stays on the composite id because @rollup/pluginutils 5.6.0 strips the attribute suffix itself, and the plugin now depends on that version. The package-local @types/node moves to ^20.19.0 because rollup 5's declarations reference Symbol.asyncDispose, which @types/node@14 no longer polyfills when it shadows the root @types/node@20 under the es6 lib.

The tests cover attribute bundling, the no-options load call that Rollup 2-4 use, and the resolve hook's importerRawId for node16 module resolution; each fails without its part of the change.

…Rollup 5

Rollup 5 appends an encoded attributes suffix to module ids. The load and resolve hooks now use the rawId/importerRawId they receive for watch files, TypeScript file lists and module resolution, so modules imported with import attributes are compiled like their plain counterparts.
The load filter keeps using the composite id because @rollup/pluginutils 5.6.0 strips the attributes suffix itself; the plugin now requires @rollup/pluginutils ^5.6.0.
The tests pass the attribute-encoded id together with the raw id, pin the resolve hook's importerRawId for node16 module resolution, and cover the hook calls that Rollup 2-4 still use; the attribute tests are skipped below Rollup 5.
The package-local @types/node is bumped to ^20.19.0 because rollup 5's type declarations reference Symbol.asyncDispose, which @types/node@14 no longer polyfills when it shadows the root @types/node@20 under the ES6 lib target.
@lukastaegert
lukastaegert marked this pull request as ready for review December 3, 2026 12:22
@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Rollup module ID with attributes] --> B[Filter strips attributes before matching]
  B --> C[load uses rawId]
  C --> D[Watch physical file]
  C --> E[Find TypeScript output]
  F[resolveId uses importerRawId] --> G[Choose TypeScript import condition]
Loading

Reviews (1) · Last reviewed commit: "feat(typescript): support modules import..." · Reviewed by Greptile

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.

1 participant