Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add names and originalFileNames to assets #5686

Merged
merged 3 commits into from
Oct 1, 2024

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

When no explicit "fileName" is provided when emitting an asset, Rollup will associate assets with the same content. At the moment, however, this is not reflected in the bundle and the output.assetFileNames option. While every file emission can have a different name and originalFileName property, only one of them is visible via the .name and .originalFileName properties, see #5596 (comment)
This PR adds new .names and .originalFileNames properties that are arrays and contain all emitted names. At the same time, the old properties are soft-deprecated, meaning that accessing them will cause a warning in the next major version of Rollup.

cc @sapphi-red

Copy link

vercel bot commented Sep 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 1, 2024 4:30am

@lukastaegert lukastaegert changed the title Make names and originalFileNames an array Add names and originalFileNames to assets Sep 30, 2024
Copy link

github-actions bot commented Sep 30, 2024

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#original-file-names-array

Notice: Ensure you have installed the latest stable Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust.

or load it into the REPL:
https://rollup-prhuuggl2-rollup-js.vercel.app/repl/?pr=5686

Copy link

github-actions bot commented Sep 30, 2024

Performance report!

Rough benchmark

Command Mean [s] Min [s] Max [s] Relative
node _benchmark/previous/bin/rollup -i ./perf/entry.js -o _benchmark/result/previous.js 9.255 ± 0.016 9.237 9.264 1.01 ± 0.00
node _benchmark/current/bin/rollup -i ./perf/entry.js -o _benchmark/result/current.js 9.208 ± 0.015 9.192 9.219 1.00

Internal benchmark

  • BUILD: 8266ms, 751 MB
    • initialize: 0ms, 26.1 MB
    • generate module graph: 3177ms, 575 MB
      • generate ast: 1556ms (+42ms, +2.8%), 568 MB
    • sort and bind modules: 455ms, 618 MB
    • mark included statements: 4631ms, 751 MB
      • treeshaking pass 1: 1574ms, 717 MB
      • treeshaking pass 2: 756ms, 740 MB
      • treeshaking pass 3: 296ms, 746 MB
      • treeshaking pass 4: 274ms, 746 MB
      • treeshaking pass 5: 320ms, 750 MB
      • treeshaking pass 6: 263ms, 751 MB
      • treeshaking pass 7: 246ms, 751 MB
      • treeshaking pass 8: 238ms, 754 MB
      • treeshaking pass 9: 217ms, 755 MB
      • treeshaking pass 10: 219ms, 755 MB
      • treeshaking pass 11: 217ms, 751 MB
  • GENERATE: 894ms, 1.02 GB
    • initialize render: 0ms, 914 MB
    • generate chunks: 86ms, 920 MB
      • optimize chunks: 0ms, 918 MB
    • render chunks: 786ms, 1 GB
    • transform chunks: 21ms, 1.02 GB
    • generate bundle: 0ms, 1.02 GB

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.05%. Comparing base (bc7780c) to head (3deae08).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5686   +/-   ##
=======================================
  Coverage   99.04%   99.05%           
=======================================
  Files         242      242           
  Lines        9352     9387   +35     
  Branches     2473     2482    +9     
=======================================
+ Hits         9263     9298   +35     
  Misses         58       58           
  Partials       31       31           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/rollup/types.d.ts Outdated Show resolved Hide resolved
@sapphi-red
Copy link
Contributor

Thanks! I tried this PR at vitejs/vite#18240. It works for Vite's case 👍

Co-authored-by: 翠 / green <green@sapphi.red>
@lukastaegert lukastaegert merged commit d0eee9c into master Oct 1, 2024
39 checks passed
@lukastaegert lukastaegert deleted the original-file-names-array branch October 1, 2024 06:57
Copy link

github-actions bot commented Oct 1, 2024

This PR has been released as part of rollup@4.23.0. You can test it via npm install rollup.

@prisis
Copy link

prisis commented Oct 16, 2024

Hey @lukastaegert, how does the migration looks like from name to names, before i was using something like this

example:

    assetFileNames({ name }) {
        const p = "[name][extname]";

        if (!name) {
            return p;
        }

        if (name.endsWith(".css")) {
            return `css/${p}`;
        }

        if (name.endsWith(".map")) {
            return `map/${p}`;
        }

        return p;
    },

with names do i need only to check for the first entry, or do i need to check all entries in names?

@lukastaegert
Copy link
Member Author

Technically you would need to check all entries, though it will be one entry most of the time anyway. I usually would not expect the extensions to differ if the content is the same, and there is probably no reason to pick any but the first name if your just need a name and do not want to compare it to anything.

github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Dec 4, 2024
<!-- Thank you for contributing! -->

### Description

close #2496

refs #2046,
rollup/rollup#5686,
vitejs/vite#18240

<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
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.

3 participants