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

feat(alias): add warning to avoid unintended duplicate modules #1634

Conversation

sapphi-red
Copy link
Contributor

Rollup Plugin Name: alias

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

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

resolves rollup/rollup#5250

Description

When the alias plugin is configured like this

// rollup.config.js
alias({ entries: { $: 'src' } })

and there a file like

import { test as test1 } from './sub.js';
import { test as test2 } from '$/sub.js';

console.log(test1);
console.log(test2);

https://stackblitz.com/edit/rollup-repro-s5tmli?file=src%2Fmain.js

then, import './sub.js' and import '$/sub.js' resolves to different module. (The same file is included in the bundle twice.)
I believe this is not what people expect. Also IMO the fact that "import 'src/sub.js' doesn't work but $/sub.js works" is difficult to understand.

This PR adds a warning to catch these cases.

The warning will be shown for those that is using the alias plugin to duplicate the module, but I guess no one would do that. It'd be easier to create a different plugin in that case.

Copy link
Collaborator

@shellscape shellscape left a comment

Choose a reason for hiding this comment

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

this is great thank you

@shellscape shellscape merged commit 018f1b0 into rollup:master Nov 25, 2023
5 checks passed
@sapphi-red sapphi-red deleted the feat/add-warning-for-unintended-duplicate-module branch November 26, 2023 11:34
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.

Duplicated modules included in bundle when plugin resolved a relative path for id
2 participants