@rollup/plugin-url does not use the asset mechanism

Open
#1,918 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript

Research direction

Start by locating the @rollup/plugin-url implementation and tracing its current filesystem copying, asset URL generation, and destDir/publicPath handling. Compare that behavior with Rollup's emitFile, asset output, and resolveFileUrl APIs; done means the plugin uses the asset mechanism while documenting or testing the resulting breaking behavior. No file or test path is named in the issue.

Written by the indexing model from the issue text.

Description

  • Rollup Plugin Name: @rollup/plugin-url
  • Rollup Plugin Version: 8.0.2
Expected Behavior / Situation

The plugin mechanism offers an emitFile function meant for copying asset files to the output directory. By only referencing the files through their reference ID, the build system is able to keep track of dependencies. The list of produced asset files is also reflected in the output.

Actual Behavior / Situation

@rollup/plugin-url uses regular file system operations to manually copy the files over. This is bad because among other things, it means there is no method to retrieve a list of copied asset files. As this information seems to be part of the intended output of a Rollup build, I consider this a bug (but apparently I'm wrong).

Modification Proposal

Use the correct APIs. Especially since this is an official plugin, it should absolutely set a good example and use the officially provided API for file management. I'm even willing to provide a PR for it.

While this is relatively straightforward to fix, it has some implications on the API of this plugin. For example, the emission of assets can't be turned off by the plugin anymore, only in the output settings. I believe this is intended, but it is a breaking change.

Likewise the destDir parameter won't make sense anymore, since that is also determined by the build output (and that is definitely correct). This means that if the plugin was previously used for unintended purposes of dropping files outside of the output directory, that "functionality" would be broken.

The publicPath behavior may need to be rethought in light of the default file import URL handling of Rollup. My understanding is that import.meta.url is supposed to fill that role, which would again make the parameter obsolete. For now I've opted to just replicate the current output exactly by overriding resolveFileUrl.

Dominant language
JavaScript
Stars
3.8k
Forks
635
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rollup/plugins

All issues in rollup/plugins

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.