Skip to content

feat: support import attributes behind experimental.importAttributes - #11254

Closed
shulaoda wants to merge 1 commit into
mainfrom
feat/import-attributes-poc
Closed

shulaoda wants to merge 1 commit into
mainfrom
feat/import-attributes-poc

Conversation

@shulaoda

Copy link
Copy Markdown
Member

PoC of the import attributes RFC behind experimental.importAttributes. Refs #2758.

@netlify

netlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 71c9831
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6ae9df5a87e5e4bd3ad33ed7
😎 Deploy Preview https://deploy-preview-11254--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-import-attributes-poc-rolldown-rs.voidzero-docs.workers.dev (commit 71c9831)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://4ebfda4a-rolldown-rs.voidzero-docs.workers.dev 71c9831 2026-11-03T13:25:07.415Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://760f5738-rolldown-rs.voidzero-docs.workers.dev 36a8ef4 2026-10-29T09:52:49.141Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://84313cdb-rolldown-rs.voidzero-docs.workers.dev 5e51a9a 2026-10-29T08:19:24.718Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c02b66aa-rolldown-rs.voidzero-docs.workers.dev bd6245c 2026-10-29T08:10:25.646Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://107cb153-rolldown-rs.voidzero-docs.workers.dev abbdcfb 2026-10-29T06:58:53.943Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://68e5b846-rolldown-rs.voidzero-docs.workers.dev 225fa0d 2026-10-29T02:31:25.246Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://44f05217-rolldown-rs.voidzero-docs.workers.dev 07d12e5 2026-10-26T09:08:00.495Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://e921bce0-rolldown-rs.voidzero-docs.workers.dev 17471b2 2026-10-26T03:20:35.183Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://60b33869-rolldown-rs.voidzero-docs.workers.dev 9bf4298 2026-10-25T22:07:41.978Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://73860ea2-rolldown-rs.voidzero-docs.workers.dev dd94f08 2026-10-25T02:10:44.792Z Visit the dashboard ↗

View all previews: View all previews ↗

@shulaoda
shulaoda force-pushed the feat/import-attributes-poc branch from 0b9eeb5 to 74a4005 Compare October 22, 2026 01:19
@shulaoda
shulaoda force-pushed the feat/import-attributes-poc branch 4 times, most recently from dd94f08 to 9bf4298 Compare October 25, 2026 22:05
@shulaoda
shulaoda force-pushed the feat/import-attributes-poc branch 2 times, most recently from 17471b2 to 07d12e5 Compare October 26, 2026 09:06
@shulaoda

Copy link
Copy Markdown
Member Author

/ecosystem-ci run

@pkg-pr-new

This comment was marked as outdated.

@vite-ecosystem-ci

This comment was marked as outdated.

@shulaoda
shulaoda force-pushed the feat/import-attributes-poc branch 2 times, most recently from 225fa0d to abbdcfb Compare October 29, 2026 06:54
@shulaoda
shulaoda force-pushed the feat/import-attributes-poc branch 2 times, most recently from bd6245c to 5e51a9a Compare October 29, 2026 08:17
@shulaoda
shulaoda force-pushed the feat/import-attributes-poc branch from 36a8ef4 to 71c9831 Compare November 3, 2026 13:19
shulaoda added a commit that referenced this pull request Nov 3, 2026
… import record (#11301)

Part 1 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

Adds the data model for import attributes, aligned with Rollup 5.
Nothing reads the new option yet, so builds behave as before, except for
the legacy `assert` keyword below.

- `ImportAttributes`: the attributes of one import, kept in the order
`JSON.stringify` emits them, so equal attributes always compare and hash
the same.
- `ModuleId::with_attributes`: builds the Rollup 5 id
`rawId?attributes=<encoded JSON>` and keeps `raw_id()` for path
operations.
- `ResolvedId.attributes` and `ImportRecord.attributes`: carry the
attributes through resolution and keep what the scanner read from a
`with` clause.
- `experimental.importAttributes`: accepted by the Rust options, used by
the next PRs.
- Tests: `configVariants` accept `importAttributes`, so a fixture can
run in both modes.

Until now Rolldown supported import attributes only partially: the
`ImportAttribute` side table (#5794, #9796, #11100) kept the `with`
clause of an external import as written and picked one clause per chunk,
while attributes took no part in module identity. That side table is
gone. In this PR the `with` clause of an external is rendered from the
import record's attributes instead, so the output does not change,
except that keys are sorted and duplicates are removed. #11303 then
renders it from the module's own attributes.

The legacy `assert` keyword is deprecated. It is treated as `with`, so
its attributes are kept and an external renders a `with` clause. The
build warns with the new `DEPRECATED_IMPORT_ASSERTION` code
(`checks.deprecatedImportAssertion`). Use `with` instead. Earlier
versions kept the `assert` clause as written, which Node 22 rejects.
shulaoda added a commit that referenced this pull request Nov 3, 2026
…ty (#11302)

Part 2 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

With `experimental.importAttributes`, the same file imported with
different attributes becomes different modules. Without the option, ids
and output stay the same. Plugin hooks do not see the attributes yet.

- `import()`: the scanner also reads the static `{ with: { ... } }`
options of a dynamic import. The legacy `assert` key is read like
`with`.
- Resolution: the attributes travel through resolution into
`ResolvedId`, and `finalize_attributes` turns the id into
`rawId?attributes=...`. Dependencies are deduplicated by `(specifier,
kind, attributes)`.
- Raw id: everything that touches a file or names one uses `raw_id()`.
That covers reading and watching the module, tsconfig lookup,
`treeshake.moduleSideEffects`, `output.paths`, chunk and
`preserveModules` file names, and the file name the transformer sees.
- Module type: a `type` attribute of `json`, `text` or `bytes` selects
the built-in module type. It beats the file extension and `moduleTypes`,
but not the `moduleType` returned by a load hook.
- Diagnostics: module comments and the "Could not load" error show a
module with attributes as `dep.js with { kind: "x" }`.
- Warnings: the new `INVALID_IMPORT_ATTRIBUTE` code
(`checks.invalidImportAttribute`) reports `import()` options that cannot
be read statically, the same cases Rollup uses it for. They warn only
with the option on, because without it the options are left as written.
An `assert` key in the options warns `DEPRECATED_IMPORT_ASSERTION`, also
only with the option on here (#11303 changes that).
shulaoda added a commit that referenced this pull request Nov 3, 2026
…om their module identity (#11303)

Part 3 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

External modules now render their `with` clause from their own
attributes. Externals carry their attributes in their module id with or
without `experimental.importAttributes`, so the clause is always kept.

- ESM output: every static import and re-export of an external renders
`ExternalModule.attributes`, including the `import * as` emitted for a
namespace re-export. The record based search in `esm.rs` is removed.
- `import()`: the options of `import()` of an external are rewritten to
the final attributes, so a `resolveId` override shows up in the output.
- `import()` path: `import()` of an external gets the same path as a
static import, and stays an `import()` while it has options, because
`require()` cannot carry them.
- `assert` in `import()` options: engines ignore it, so every `import()`
left in the output gets the key rewritten to `with`, including one with
a computed specifier. It warns `DEPRECATED_IMPORT_ASSERTION` with or
without the option, like a static `assert` clause.
- Raw id: `output.globals` and the CJS `require()` of a re-exported
external use the raw id.

The old behavior (#5794, #9796, #11100) had no module identity. Two
imports of one external with different attributes were one module, and
only one clause survived. For example, `import 'ext'; import 'ext' with
{ type: 'json' }` rendered only the second import. Now they are two
externals, each with its own clause. Without the option, an external
with attributes now has a composite id in `getModuleInfo()` and
`moduleIds`.
shulaoda added a commit that referenced this pull request Nov 3, 2026
…he module id helpers to JS (#11304)

Part 4 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

Exposes the option and the module id helpers to JS. Plugin hooks still
get ids only, the next PRs add the attributes hook by hook.

- `experimental.importAttributes`: accepted by the JS options and the
validator, and passed to the binding.
- `stringifyModuleId` and `parseModuleId` in `rolldown/utils`: build and
split `rawId?attributes=...` ids with the same bytes as the Rust side.
`parseModuleId` only accepts a suffix it would produce itself, so ids
that only look similar stay as they are.
- `UniqueModuleId`: a module id, or `{ rawId, attributes }`.
- `PluginContextData.toModuleId`: composes ids on the JS side the same
way as Rust, when the option is on or the module is external, so module
options such as `meta` are stored under the right id.
shulaoda added a commit that referenced this pull request Nov 3, 2026
…d `resolveDynamicImport` hooks (#11305)

Part 5 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

`resolveId` and `resolveDynamicImport` see the attributes of an import
and can change them, in Rust and in JS. The arguments are filled with or
without `experimental.importAttributes`.

- Arguments: both hooks get `attributes`, `importerRawId` and
`importerAttributes`. `resolveDynamicImport` gets only these three, as
in Rollup 5. `resolveId` keeps `isEntry`, `kind` and `custom`.
- Return value: `attributes` replaces the attributes of the import. `{}`
removes them, and leaving it out keeps the ones written in the source.
For an external, the result is what ends up in its `with` clause.
Without the option, the returned attributes only apply to externals.
- Module options: `meta` and `moduleSideEffects` returned by the hook
are stored under the composed id, also for an external without the
option.
- Binding: empty attributes and a raw id equal to the importer are left
out, and the JS side fills in the defaults.

Not covered: builtin plugins called from JS through
`BindingCallableBuiltinPlugin` get the importer's attributes, but not
the attributes of the import itself.
shulaoda added a commit that referenced this pull request Nov 3, 2026
…nd `this.load` (#11306)

Part 6 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

`this.resolve` and `this.load` accept import attributes.

- `this.resolve(source, importer, { attributes })`: resolves a simulated
import with attributes and returns `{ id: rawId, attributes }`.
`importer` can also be `{ rawId, attributes }`.
- `this.load(...)`: takes a module id or `{ rawId, attributes }`. A
module id that contains attributes is split again. As in Rollup 5, the
attributes only come from `id`, so a `this.resolve` result passed as is
loads the module without them. Pass `{ ...resolved, id: { rawId:
resolved.id, attributes: resolved.attributes } }` instead.
- `this.resolve(source, null)` keeps working, like in Rollup.
- Rust: `PluginContextResolveOptions.attributes` and
`PluginContext::load(raw_id, attributes, ...)`.
- Builtin plugins: `vite_alias` forwards the attributes of the import it
resolves for and returns the resolved ones, and `isolated_declaration`
loads with the resolved attributes. `lazy_compilation` skips an
`import()` with attributes for now, so it is bundled as usual.
shulaoda added a commit that referenced this pull request Nov 3, 2026
…11307)

Part 7 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

`load` gets the raw id and the attributes of the module. Without
`experimental.importAttributes`, `rawId` equals `id` and `attributes` is
`{}`.

- `load(id, { rawId, attributes })`: with the option on, `id` contains
the attributes, so read the file from `rawId`.
- Binding: the extra argument is sent only for a module with attributes,
and the JS side fills in `{ rawId: id, attributes: {} }`.
- Source maps returned by `load` are resolved against `rawId`.
- The builtin data URL plugin looks its modules up by the raw id.

Known: Vite's `load(id, options?: { ssr?: boolean })` hook type does not
extend this signature (TS2430), so Vite needs to widen its options type.
shulaoda added a commit that referenced this pull request Nov 3, 2026
…ok (#11308)

Part 8 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

`transform` gets the same two fields as `load`.

- `transform(code, id, { rawId, attributes, ... })`: without
`experimental.importAttributes`, `rawId` equals `id` and `attributes` is
`{}`.
- Binding: both fields are left out for a module without attributes, and
the JS side fills in the defaults.
- Rust: `HookTransformArgs` gets `raw_id` and `attributes`, and
`PluginDriver::transform` takes the `ModuleId` and its attributes.
shulaoda added a commit that referenced this pull request Nov 4, 2026
…pes` in the asset and copy plugins (#11309)

Part 9 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

A `type` attribute also beats `moduleTypes` in the builtin asset and
copy plugins.

With `experimental.importAttributes`, `import x from './a.txt' with {
type: 'json' }` loads as JSON even when `moduleTypes` maps `.txt` to
`asset` or `copy`. This matches how the core picks the module type. A
`type` without a built-in meaning, like `css`, leaves the module to
`moduleTypes`, and so does a build without the option.

The copy plugin forwards the attributes of the import to `this.resolve`
and checks the resolved ones, so a `resolveId` override counts.
shulaoda added a commit that referenced this pull request Nov 4, 2026
…11381)

Part 10 of 11 of the import attributes stack. RFC: #11217. Full proof of
concept: #11254.

Enables the related Rollup tests, as asked in
#11310 (comment).

None of Rollup's own import attributes tests in `packages/rollup-tests`
pass as they are. The `rollup` submodule is on Rollup 4, whose tests
expect the old behavior (the `assert` keyword by default, a warning for
conflicting attributes), and the suite runs without
`experimental.importAttributes`. So the Rollup 5 versions are ported
instead.

- 17 Rollup 5 tests are ported to
`packages/rolldown/tests/fixtures/topics/import-attributes/rollup-5/`,
with the option on. The folders mirror Rollup's `test/function/samples`
and `test/form/samples`. The folder should be deleted once the submodule
moves to Rollup 5.
- Form tests check the lines with attributes instead of the whole
output.
- A few parts differ from Rollup 5, each with a comment: Rolldown sorts
attribute keys in the output, warns about the `assert` keyword, gives
`type: 'json'` its built-in meaning, and only supports `this.load` while
modules are loading.
- In `packages/rollup-tests`, the Rollup 4 originals of the ported tests
are listed in `ignored-tests.js`. The rest are grouped in
`ignored-by-unsupported-features.md` by the feature they really miss,
such as `output.importAttributesKey` or `resolveDynamicImport` with a
non-string specifier. Three stale test names are dropped.

Parts of Rollup 5 tests that need an API Rolldown does not have yet are
left out:

- `ModuleInfo.rawId` and `ModuleInfo.attributes`
- the 4th argument of the `external` function, and `{ attributes }` for
the `output.globals` and `output.paths` functions
- `this.getModuleInfo` and `this.emitFile` chunks with attributes
- `attributes` of `resolveFileUrl`, and `resolveImportMeta`
- the deprecated `importerAttributes` option of `this.resolve`
@shulaoda shulaoda closed this Nov 4, 2026
@shulaoda
shulaoda deleted the feat/import-attributes-poc branch November 4, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant