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

bug: Ignore external folder when globbing messages folder #1096

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

xiata
Copy link
Contributor

@xiata xiata commented Oct 3, 2024

Details

Fixes a build error that occurs when a custom .babelrc is provided in the project that makes use of @babel/preset-env.

The error

If you have a .babelrc and an external message such as src/background/messages/external/Test.ts, you will receive the following trying to build the extension:

Identifier 'messagesExternalTest' has already been declared. (38:20)

Root cause

In cli/plasmo/src/features/background-service-worker/bgsw-messaging.ts's getHandlerList function, it performs a glob of all typescript files that are within the designated messages folder. Due to messages/external (public external messaging) being contained within messages (extension internal messaging), this causes any external messaging to have a duplicate import created during build when getHandlerList is invoked with dirName: "messaging" colliding with the invokation of dirName: "messaging/external". Parcel happily removes the duplicate import, but unfortunately if you configure @babel/preset-env for your extension (e.g. targeting older browsers), this triggers a hard error from babel.

The fix

Since messages/external folder should be ignored when getHandlerList is given dirName: "messaging", simply add a glob ignore in that case.

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I agree to license this contribution under the MIT LICENSE
  • I checked the current PR for duplication.

Contacts

  • (OPTIONAL) Discord ID: xiata (469966695084195860)

If your PR is accepted, we will award you with the Contributor role on Discord server.

To join the server, visit: https://www.plasmo.com/s/d

@louisgv
Copy link
Contributor

louisgv commented Oct 8, 2024

Thanks for the PR -- good catch!

Copy link
Contributor

@louisgv louisgv left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@louisgv louisgv added this pull request to the merge queue Oct 8, 2024
Merged via the queue into PlasmoHQ:main with commit 9328971 Oct 8, 2024
1 check passed
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.

2 participants