Skip to content

Name dynamic chunks of index files after their directory - #6630

Merged
lukastaegert merged 3 commits into
rollup:masterfrom
clean99:contrib/rollup-index-chunk-names
Nov 6, 2026
Merged

lukastaegert merged 3 commits into
rollup:masterfrom
clean99:contrib/rollup-index-chunk-names

Conversation

@clean99

@clean99 clean99 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

This PR contains:

  • bugfix

Are tests included?

  • yes

Breaking Changes?

  • no

List any relevant issue numbers:

Description

A dynamic import that resolves to a directory's index file, e.g. import('./components/button') resolving to components/button/index.js, names its chunk index. Two such imports give two chunks called index, and with the default [name]-[hash].js nothing in the file name says which feature a chunk belongs to.

For dynamic entries, the name is now taken from the directory when the file is an index file, and only when that directory name is usable as a file name part: a name that starts with .., and the empty name of a root path, are path fragments, so those entries keep index. Entry names, preserveModules paths, manualChunks and emitFile names, and ids without a parent directory (index.js, /index.js, C:/index.js) keep their current names, as the issue asked.

The new chunking-form sample imports two directories and one plain file, ..-prefixed directories, and the three ids without a parent directory, and pins the emitted names and imports in all four formats.

generated with AI

A dynamic import that resolves to a directory's index file took the name
of the file, so several such imports all produced chunks called "index".
Directory names are used instead when the module is a dynamic entry whose
alias is "index"; the name stays "index" when there is no directory to use.
A directory whose name starts with ".." made getDynamicAliasName return a
relative path fragment, which renderNamePattern then rejected as an invalid
"[name]" substitution, so a build that worked before failed. Test the
candidate through the same predicate that will judge it.

Cover the shapes that predicate must reject in the sample: a ".."-prefixed
directory and the ids without a parent folder ("index.js", "/index.js" and
"C:/index.js").
@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

@clean99 is attempting to deploy a commit to the rollup-js Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Thank you for your contribution! ❤️

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

npm install clean99/rollup#contrib/rollup-index-chunk-names

Notice: To build the native dependencies, you need Rustup installed; the required nightly toolchain is then picked up automatically from rust-toolchain.toml.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟢 Approval recommended

The change is narrowly scoped to improving dynamic index.* chunk naming while preserving existing naming sources, and it is backed by comprehensive new sample fixtures with pinned expected outputs across multiple formats plus only a minor documentation nit noted.

No open issues 🎉

What changed in this PR

This pull request updates dynamic chunk naming so that when a dynamic import resolves to a directory index.* file (e.g. import('./components/button') → components/button/index.js), the emitted chunk name uses the directory name when it is a safe filename fragment. This avoids multiple unrelated chunks all being named index and improves the clarity of [name]-[hash].js outputs. Resolves #4858.

Changes:

  • Derive dynamic-entry chunk names from the parent directory for index.* resolutions when the directory name is usable.
  • Preserve existing naming behavior for non-dynamic entries and other naming sources (e.g., explicit entry names, preserveModules, manualChunks, emitFile, and ids without a usable parent).
  • Add a chunking-form sample with pinned expected outputs across ES/CJS/AMD/System, including edge cases (..-prefixed directories and root/drive “index” ids).

Review note (nit):

  • test/chunking-form/samples/dynamic-import-directory-name/_config.js: Clarify wording about the “no parent folder” condition for /index.js and C:/index.js (root/drive parent names are not usable for chunk naming).
File Summary
test/​chunking-form/​samples/​dynamic-import-directory-name/​single.js Sample dynamically imported non-index module used as a baseline for naming.
test/​chunking-form/​samples/​dynamic-import-directory-name/​main.js Entry sample exercising directory index.* dynamic imports and edge-case ids.
test/​chunking-form/​samples/​dynamic-import-directory-name/​components/​other/​index.js Sample directory index.js target validating chunk name becomes other.
test/​chunking-form/​samples/​dynamic-import-directory-name/​components/​button/​index.js Sample directory index.js target validating chunk name becomes button.
test/​chunking-form/​samples/​dynamic-import-directory-name/​..components/​index.js Edge case for ..-prefixed directory name (should not be used for chunk naming).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​system/​main.js Update pinned SystemJS output imports for new chunk names.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​system/​generated-single.js Pinned expected SystemJS chunk output for single.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​system/​generated-other.js Pinned expected SystemJS chunk output for other.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​system/​generated-index4.js Pinned expected SystemJS output for an index* collision/edge-case retention.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​system/​generated-index3.js Pinned expected SystemJS output for C:/index.js edge case (keeps index*).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​system/​generated-index2.js Pinned expected SystemJS output for /index.js edge case (keeps index*).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​system/​generated-index.js Pinned expected SystemJS output for index.js with no usable parent (keeps index).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​system/​generated-button.js Pinned expected SystemJS chunk output for button.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​es/​main.js Update pinned ES output imports for new chunk names.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​es/​generated-single.js Pinned expected ES chunk output for single.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​es/​generated-other.js Pinned expected ES chunk output for other.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​es/​generated-index4.js Pinned expected ES output for an index* collision/edge-case retention.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​es/​generated-index3.js Pinned expected ES output for C:/index.js edge case (keeps index*).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​es/​generated-index2.js Pinned expected ES output for /index.js edge case (keeps index*).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​es/​generated-index.js Pinned expected ES output for index.js with no usable parent (keeps index).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​es/​generated-button.js Pinned expected ES chunk output for button.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​cjs/​main.js Update pinned CJS output requires/imports for new chunk names.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​cjs/​generated-single.js Pinned expected CJS chunk output for single.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​cjs/​generated-other.js Pinned expected CJS chunk output for other.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​cjs/​generated-index4.js Pinned expected CJS output for an index* collision/edge-case retention.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​cjs/​generated-index3.js Pinned expected CJS output for C:/index.js edge case (keeps index*).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​cjs/​generated-index2.js Pinned expected CJS output for /index.js edge case (keeps index*).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​cjs/​generated-index.js Pinned expected CJS output for index.js with no usable parent (keeps index).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​cjs/​generated-button.js Pinned expected CJS chunk output for button.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​amd/​main.js Update pinned AMD output imports for new chunk names.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​amd/​generated-single.js Pinned expected AMD chunk output for single.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​amd/​generated-other.js Pinned expected AMD chunk output for other.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​amd/​generated-index4.js Pinned expected AMD output for an index* collision/edge-case retention.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​amd/​generated-index3.js Pinned expected AMD output for C:/index.js edge case (keeps index*).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​amd/​generated-index2.js Pinned expected AMD output for /index.js edge case (keeps index*).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​amd/​generated-index.js Pinned expected AMD output for index.js with no usable parent (keeps index).
test/​chunking-form/​samples/​dynamic-import-directory-name/​_expected/​amd/​generated-button.js Pinned expected AMD chunk output for button.
test/​chunking-form/​samples/​dynamic-import-directory-name/​_config.js Test config + resolver plugin to map ./dir → dir/index.js and inject edge-case ids.
src/​utils/​relativeId.ts Add getDynamicAliasName to prefer directory names for dynamic index.* resolutions when safe.
src/​Chunk.ts Use the dynamic alias naming for dynamic entry facades while honoring predefined/user-provided names.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Performance report

  • BUILD: 7016ms, 848 MB
    • initialize: 0ms, 24 MB
    • generate module graph: 2607ms, 630 MB
      • generate ast: 1379ms (-31ms, -2.2%), 622 MB
    • sort and bind modules: 405ms, 692 MB
    • mark included statements: 3982ms, 848 MB
      • treeshaking pass 1: 2332ms, 827 MB
      • treeshaking pass 2: 465ms, 838 MB
      • treeshaking pass 3: 402ms, 830 MB
      • treeshaking pass 4: 386ms, 838 MB
      • treeshaking pass 5: 386ms, 848 MB
  • GENERATE: 596ms, 889 MB
    • initialize render: 0ms, 848 MB
    • generate chunks: 41ms, 841 MB
      • optimize chunks: 0ms, 833 MB (-2%)
    • render chunks: 529ms, 872 MB
    • transform chunks: 21ms, 889 MB
    • generate bundle: 0ms, 889 MB

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.33%. Comparing base (a70c3ed) to head (e770657).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6630      +/-   ##
==========================================
- Coverage   98.33%   98.33%   -0.01%     
==========================================
  Files         380      380              
  Lines       14050    14042       -8     
  Branches     2996     2996              
==========================================
- Hits        13816    13808       -8     
  Misses        192      192              
  Partials       42       42              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rollup Ready Ready Preview Nov 6, 2026 5:36am UTC

Request Review

@lukastaegert lukastaegert 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.

Looks good!

@lukastaegert
lukastaegert added this pull request to the merge queue Nov 6, 2026
@lukastaegert
lukastaegert removed this pull request from the merge queue due to a manual request Nov 6, 2026
@lukastaegert
lukastaegert added this pull request to the merge queue Nov 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Nov 6, 2026
@lukastaegert
lukastaegert added this pull request to the merge queue Nov 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Nov 6, 2026
@lukastaegert
lukastaegert added this pull request to the merge queue Nov 6, 2026
@lukastaegert
lukastaegert removed this pull request from the merge queue due to a manual request Nov 6, 2026
@lukastaegert
lukastaegert added this pull request to the merge queue Nov 6, 2026
Merged via the queue into rollup:master with commit 85da28c Nov 6, 2026
50 checks passed
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

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

This branch was successfully deployed

1 active deployment
Preview — e7706573 Deployed Nov 6, 2026 by vercel[bot]
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.

Ignore index suffix in dynamic chunk names

3 participants