Skip to content

feat: implement resolveFileUrl plugin hook#10291

Merged
graphite-app[bot] merged 1 commit into
mainfrom
07-10-feat_implement_resolvefileurl_plugin_hook
Jul 17, 2026
Merged

feat: implement resolveFileUrl plugin hook#10291
graphite-app[bot] merged 1 commit into
mainfrom
07-10-feat_implement_resolvefileurl_plugin_hook

Conversation

@sapphi-red

@sapphi-red sapphi-red commented Jul 15, 2026

Copy link
Copy Markdown
Member

This PR implements the resolveFileUrl hook, which exists in Rollup.

  1. Collect import.meta.ROLLUP_FILE_URL_* information in the AstScanner
  2. Rewrite the import.meta.ROLLUP_FILE_URL_* places in GenerateStage with the information collected

https://rollupjs.org/plugin-development/#resolvefileurl

refs vitejs/vite#22709

sapphi-red commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sapphi-red
sapphi-red force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch 2 times, most recently from 91d05f8 to d5636e2 Compare July 15, 2026 06:54
@graphite-app
graphite-app Bot changed the base branch from 07-10-fix_format_in_filenames_option_for_esm_format_should_be_es_instead_of_esm_ to graphite-base/10291 July 15, 2026 07:16
@graphite-app
graphite-app Bot force-pushed the graphite-base/10291 branch from 23f6bfe to 44cda05 Compare July 15, 2026 07:24
@graphite-app
graphite-app Bot force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch from d5636e2 to 5cf730e Compare July 15, 2026 07:24
@graphite-app
graphite-app Bot changed the base branch from graphite-base/10291 to main July 15, 2026 07:25
@graphite-app
graphite-app Bot force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch from 5cf730e to d305d46 Compare July 15, 2026 07:25
@netlify

netlify Bot commented Jul 15, 2026

Copy link
Copy Markdown

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit c31bc56
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6a59c63ba39ebb00083bff72
😎 Deploy Preview https://deploy-preview-10291--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.

@sapphi-red
sapphi-red force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch from d305d46 to 1146c28 Compare July 15, 2026 09:37
@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@rolldown/browser

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/browser@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/browser@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/debug

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/debug@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/debug@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

rolldown

pnpm add https://pkg.pr.new/rolldown/rolldown@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown@10291 -D
yarn add https://pkg.pr.new/rolldown/[email protected] -D

@rolldown/binding-android-arm64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-android-arm64@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-android-arm64@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-darwin-arm64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-arm64@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-arm64@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-darwin-x64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-x64@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-darwin-x64@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-freebsd-x64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-freebsd-x64@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-freebsd-x64@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-linux-arm-gnueabihf

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm-gnueabihf@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm-gnueabihf@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-linux-arm64-gnu

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-gnu@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-gnu@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-linux-arm64-musl

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-musl@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-arm64-musl@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-linux-ppc64-gnu

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-ppc64-gnu@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-ppc64-gnu@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-linux-s390x-gnu

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-s390x-gnu@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-s390x-gnu@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-linux-x64-gnu

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-gnu@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-gnu@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-linux-x64-musl

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-musl@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-linux-x64-musl@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-openharmony-arm64

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-openharmony-arm64@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-openharmony-arm64@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-wasm32-wasi

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-wasm32-wasi@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-wasm32-wasi@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-win32-arm64-msvc

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-arm64-msvc@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-arm64-msvc@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

@rolldown/binding-win32-x64-msvc

pnpm add https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-x64-msvc@10291 -D
npm i https://pkg.pr.new/rolldown/rolldown/@rolldown/binding-win32-x64-msvc@10291 -D
yarn add https://pkg.pr.new/rolldown/rolldown/@rolldown/[email protected] -D

commit: 072d54e

@sapphi-red
sapphi-red force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch 2 times, most recently from 6168288 to 5f32fc5 Compare July 15, 2026 11:09
@sapphi-red
sapphi-red marked this pull request as ready for review July 15, 2026 11:30
@codspeed-hq

codspeed-hq Bot commented Jul 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing 07-10-feat_implement_resolvefileurl_plugin_hook (072d54e) with main (1447684)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@IWANABETHATGUY IWANABETHATGUY left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take it or leave it — fixture coverage is already strong; two gaps if you want them closed:

  • a hashed-filename case (chunkFileNames: '[name]-[hash].js' + an emitted chunk) proving the hash placeholder in fileName/chunkId round-trips through plugin-returned code;
  • a cjs-format case — the hook is typed for 'es' | 'cjs' | 'iife' | 'umd' but only es and iife are exercised.

Comment thread crates/rolldown/src/ast_scanner/impl_visit.rs Outdated
Comment thread packages/rollup-tests/src/ignored-by-unsupported-features.md
Comment thread packages/rolldown/src/plugin/docs/plugin-hooks-resolvefileurl.md

@hyfdev hyfdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall direction and the two-stage design make sense, but I found one behavior difference that can make an otherwise successful build fail, so I'm requesting changes.

In priority order:

  1. Blocker: resolveFileUrl is called for file-URL occurrences that tree-shaking removes. See the inline comment.
  2. Rollup compatibility: ResolveFileUrlArgs omits Rollup's required attributes field. See the inline comment. This is also why the two chunking tests moved from passing to unsupported: Rollup passes {} even for an ordinary module, while this branch passes no field.
  3. Rollup compatibility: On the existing computed-property thread, Rollup 4.62.2 does support import.meta['ROLLUP_FILE_URL_x'] via its string propertyKey, so the scanner should be extended rather than restricting the finalizer.
  4. Docs: The AST-parsing behavior is worth documenting as already noted. The File URLs link should also target Interface.Plugin#resolvefileurl, and the "independent of the output format" wording should be qualified because the default IIFE/UMD fallback warns and produces {}.url.

I also verified that hash placeholders round-trip through hook-returned code, output-only plugins work, and repeated ES/CJS generation receives the correct format; I did not find issues in those paths.

Comment thread crates/rolldown/src/stages/generate_stage/resolve_file_urls.rs Outdated
Comment thread crates/rolldown_plugin/src/types/hook_resolve_file_url_args.rs
@sapphi-red
sapphi-red force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch 3 times, most recently from b20c409 to ada3be7 Compare July 16, 2026 10:36
Comment thread packages/rolldown/src/plugin/docs/plugin-hooks-resolvefileurl.md
@sapphi-red

Copy link
Copy Markdown
Member Author

I also refactored the code to use NodeId instead of Span.

@hyfdev hyfdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-reviewed the latest head. The computed-key and common whole-statement tree-shaking cases are fixed. I’m treating the remaining nested-expression liveness timing difference as non-blocking and will clarify that in the existing thread.

I found one live-code issue that still blocks approval, plus one non-blocking implementation difference; see the inline comments.

Two documentation items from my previous review also remain:

  • The File URLs page links resolveFileUrl to Interface.PluginContext; it should link to /reference/Interface.Plugin#resolvefileurl.
  • The hook documentation says the default URL works “independent of the output format”, but the current IIFE/UMD fallback warns and emits {}.url. This should be qualified to mention the need for an import.meta.url polyfill or a custom hook.

Everything else I checked looks good. The focused fixtures, injected-expression unit tests, local build, and relevant CI all pass.

Comment thread crates/rolldown/src/stages/generate_stage/resolve_file_urls.rs
Comment thread crates/rolldown_ecmascript_utils/src/injected_expression.rs Outdated

@hyfdev hyfdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sapphi-red
sapphi-red force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch from ada3be7 to ba62cde Compare July 17, 2026 03:48
@sapphi-red
sapphi-red force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch from ba62cde to 072d54e Compare July 17, 2026 03:53
@sapphi-red

Copy link
Copy Markdown
Member Author
  • The File URLs page links resolveFileUrl to Interface.PluginContext; it should link to /reference/Interface.Plugin#resolvefileurl.
  • The hook documentation says the default URL works “independent of the output format”, but the current IIFE/UMD fallback warns and emits {}.url. This should be qualified to mention the need for an import.meta.url polyfill or a custom hook.
  • resolveFileUrl() { return '42 // trailing comment'; }

Fixed these in this PR

@graphite-app

graphite-app Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Merge activity

This PR implements the `resolveFileUrl` hook, which exists in Rollup.

1. Collect `import.meta.ROLLUP_FILE_URL_*` information in the AstScanner
1. Rewrite the `import.meta.ROLLUP_FILE_URL_*` places in GenerateStage with the information collected

https://rollupjs.org/plugin-development/#resolvefileurl

refs vitejs/vite#22709
@graphite-app
graphite-app Bot force-pushed the 07-10-feat_implement_resolvefileurl_plugin_hook branch from 072d54e to c31bc56 Compare July 17, 2026 06:05
@graphite-app
graphite-app Bot merged commit c31bc56 into main Jul 17, 2026
33 of 34 checks passed
@graphite-app
graphite-app Bot deleted the 07-10-feat_implement_resolvefileurl_plugin_hook branch July 17, 2026 06:10
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.

4 participants