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

Avoid mix of default and named exports #13

Open
timdp opened this issue Oct 26, 2022 · 1 comment
Open

Avoid mix of default and named exports #13

timdp opened this issue Oct 26, 2022 · 1 comment

Comments

@timdp
Copy link

timdp commented Oct 26, 2022

It's great that this plugin exposes both the modules and their filenames. However, it's somewhat tedious that it does so by exposing a named export alongside a default one. Additionally, I think one should have to zip the two arrays to match a module to its filename.

Personally, I would export an array of module records: { filename: string, module: any }[]. To help folks who aren't interested in the filenames, you could optionally also export the modules, and the same logic could be applied to the filenames.

Because this would create multiple exports, and also because a lot of people feel that default exports shouldn't be part of JS, all three exports should be named. I.e., you could import { records } (I can't think of a better name right now), but also { modules, filenames } to get the current behavior.

Sidenote: I've noticed that bundlers typically refer to the filenames with id, because they're internally treated as module identifiers. Thus, this could be an opportunity to move away from "filename" too.

@timdp
Copy link
Author

timdp commented Oct 31, 2022

I've implemented this in my own take on this plugin: https://www.npmjs.com/package/esbuild-plugin-import-pattern

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

No branches or pull requests

1 participant