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

✨ improve(patch): prevent duplicate entrypoint imports #2451

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

kellymears
Copy link
Member

@kellymears kellymears commented Sep 19, 2023

Prevent duplicate entrypoint imports.

It is relatively easy to reproduce this. Just add a duplicate module to an entrypoint:

bud.entry({
  app: ['@scripts/app', '@scripts/app'],
})

Before compilation, bud.js validates the configuration using webpack's validation API. At this point the following error is observed:

ValidationError

✘ Invalid configuration object. Webpack has been initialized using a configuration
 object that does not match the API schema.
  - configuration[0].entry['app'].import should not contain the item
 '@scripts/app' twice.
    -> All modules are loaded upon startup. The last one is exported.

Initially, I thought about tightening the bud.entry parameter validation to prevent this, but that could cause ecosystem problems. For example, if multiple extensions add the same module to an entrypoint.

It would be possible to force extensions to check the imports array before adding a module, but this is more prone to error and doesn't confer any advantages. Since there is no scenario where a module would be intentionally included more than once it is better, I think, to dedupe each entrypoint's imports before compilation, which is what this PR does.

The solution is simple:

  1. the entrypoint imports are an array which may contain duplicate items
  2. the imports array is cast to a Set (which cannot contain duplicates)
  3. the Set is spread into a new array

Type of change

PATCH: backwards compatible change

@kellymears kellymears marked this pull request as ready for review September 19, 2023 17:30
@kellymears kellymears added the 🚀! automerge label Sep 20, 2023
@kodiakhq kodiakhq bot merged commit 93e8600 into main Sep 20, 2023
8 checks passed
@kodiakhq kodiakhq bot deleted the improve-prevent-entry-duplicates branch September 20, 2023 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant