rolldown: track native `resolveNewUrlToAsset` for `new URL(..., import.meta.url)` assets
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 12/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Active
- Tech stack
- javascript, typescript, wasm
- Domain
- build-system
Research direction
Start with src/build/plugins/asset-urls.ts in Nitro and compare its behavior with rolldown's experimental.resolveNewUrlToAsset; reproduce the three failing cases against rolldown 1.2.15 before changing anything. The issue is a tracking item: the real work spans upstream rolldown fixes and open decisions about missing files, absolute paths and JS/TS handling, so a newcomer cannot pick a single self-contained edit from it. Done means the upstream option is stable and Nitro's plugin can be removed without changing output paths.
Written by the indexing model from the issue text.
Description
Follow-up of #4930. Nitro emits files referenced with new URL("./file", import.meta.url) through its own plugin (src/build/plugins/asset-urls.ts, added in #4932). Rolldown has a native option for this, experimental.resolveNewUrlToAsset, which we'd like to use instead once the problems below are fixed upstream (stabilization is tracked in rolldown/rolldown#9561).
The output file names are the same with both (assets/[name]-[hash][extname]), so switching later doesn't change output paths.
Bugs (rolldown 1.2.15)
import { rolldown } from "rolldown";
const build = (input, plugins = []) =>
rolldown({ input, plugins, experimental: { resolveNewUrlToAsset: true } })
.then((b) => b.generate({ format: "esm" }));
// 1. src/load.js: export const u = new URL("./m.wasm", import.meta.url).href;
await build("src/load.js", [{ name: "wasm", load: (id) => id.endsWith(".wasm") ? "export default 1" : undefined }]);
// 2. src/enc.js: export const u = new URL("./my%20file.txt", import.meta.url).href; (file is `my file.txt`)
await build("src/enc.js");
// 3. src/query.js:
// export const q = new URL("./a.txt?v=1", import.meta.url).href;
// export const h = new URL("./a.txt#frag", import.meta.url).href;
await build("src/query.js");
- Internal error when a
loadhook handles the referenced file. References go throughresolveId(withkind: "new-url") andloadof all plugins. Case 1 fails with[UNHANDLEABLE_ERROR] Something went wrong inside rolldown, please report this problem ... Encountered a module with type 'asset' during AST parsing.In Nitro,unwasm(on by default) has such a hook, so building@electric-sql/pglitefails. It builds withwasm: false. - Percent-encoded paths are not decoded. Case 2 fails with
[UNRESOLVED_IMPORT] Could not resolve './my%20file.txt'. - Query and hash are dropped. Case 3 becomes
new URL("assets/a-fTpYetjL.txt", import.meta.url)for both, sourl.searchandurl.hashare lost (e.g.sprite.svg#icon).
Behavior differences (not bugs, but need a decision before switching)
- A reference to a file that doesn't exist at build time is a hard
UNRESOLVED_IMPORTerror. Nitro's plugin leaves the URL as it is. AresolveIdhook returningexternal: truefor these keeps the URL, butresolveIdcan't be filtered bykind, so it would run in JS for every import. - Absolute paths are copied into the output (
new URL("/etc/hosts", import.meta.url)emitsassets/hosts-[hash]). Nitro's plugin skips them. - JS and TS files are copied as-is, without bundling (rolldown/rolldown#7258). Nitro's plugin skips them.
- The option is experimental and may change in minor versions; rolldown/rolldown#9561 plans to rename it (
discover.newUrl).
What works the same as Nitro's plugin: strings and comments are not rewritten, trailing commas and template literals without expressions work, each file is emitted once, and relative paths from nested chunks are correct. Nitro's other transforms (e.g. replace) don't change the contents of emitted files.
Opened with AI assistance.
- Dominant language
- TypeScript
- Stars
- 11.5k
- Forks
- 968
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 64
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nitrojs/nitro
-
pending triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 2 days
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configPossibly taken @draarivpatel-ui claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 2 days
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
pending triage
Difficulty 5/5 Over a week Newbie friendliness 30/100
nitrojs/nitro#5205 · 1 reaction ·
Maintainers usually reply within 2 days
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ranxianglei/billion-context#8319 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JimLiu/open-artifact#126 ·
-
bug repro-ready
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
mksglu/context-mode#1454 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
laststance/design-world#98 ·
Maintainers usually reply within 1 day
-
Add: KCM True crimeOpenapproved check:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day