-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Use .js extension for config/assets.js #122
Conversation
108d6a5
to
a0df541
Compare
It turns out the .mjs wasn’t necessary for this to work correclty with our standard esbuild config.
a0df541
to
0979681
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timriley @KonnorRogers I'm annoyed by the .mjs
extension as well.
Question: if we force the type: "module"
in package.json
are we getting in the way of developers that may want/need to declare a different type?
@KonnorRogers, you mentioned a potential conflict with Jest. Anything else that we should be aware of?
Are we just embellishing (.mjs
-> .js
) but creating potential obstacles?
Nothing else I'm aware of. Most new packages all support ESM. Even newer versions of Jest support ESM.
They can always override if needed. As a whole for new projects, its a pretty benign property. It's mostly legacy projects that have a hard time with it that have outdated dependencies (pretty much anything >4yrs old) |
Thanks @KonnorRogers :)
Given this, I'm happy for us to proceed here. People who need to do something different to this will know what they're doing (and in addition, if we find there's sufficient demand, we can make sure this is clear via documentation). |
If we set
"type": "module"
in ourpackage.json
(opting into ES Module-style JavaScript by default), then we can use an ordinary.js
extension forconfig/assets.js
.This feels much more conventional, less surprising to the casual user.
Opting into ES Modules makes Hanami's default assets setup more future-focused, which I think this is a good posture for us. Getting this detail right now is important, since changing this later will be costly and involve manual user changes.
Those people needing needing legacy CommonJS-style JavaScript can still use it by giving their files the
.cjs
extension (or even taking away the"type": "module"
declaration, and at that point, they likely know what they're doing).As noted by @KonnorRogers, esbuild can also help with CJS/ESM interop, too.