-
Notifications
You must be signed in to change notification settings - Fork 3
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
Update bindings style to be compatible with node/es modules/esbuild #6
Conversation
55e8f71
to
98d0839
Compare
98d0839
to
7afdd7d
Compare
ae84d8d
to
3cdeec6
Compare
3cdeec6
to
357cee5
Compare
src/MomentReMjs.re
Outdated
|
||
let diffWithPrecision = MomentReShared.diffWithPrecision; | ||
|
||
[@mel.module "moment"] [@mel.scope "default"] |
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.
This is also required to work with esm: [@mel.scope "default"]
.
Thanks for the PR @denis-ok ! I have a few questions:
How did it happen that we never ran into this problem before? We've been using ES6 and Commonjs for years. Is it because esbuild is more restrictive than webpack somehow on the way default exports are handled?
If this is really an issue across the board, I think it should be solved in Melange, at least for the mid-long term. Could you help me find a reproduction that we can use to submit to the repo upstream? cc @anmonteiro |
Trying to summarize the issues you're seeing: CommonJSIn order to bind to the module-exported function, we need to write: type moment
external momentNow : unit -> moment = "moment" [@@mel.module]
let () = Js.log (momentNow ()) ES6However, in ES6, one needs to write: type moment
external momentNow : unit -> moment = "default" [@@mel.module "moment"]
let () = Js.log (momentNow ()) And your issue seems to be that there's no way to reconcile the two? |
@anmonteiro I think your comment summarizes the issue, afaiu. |
I took this branch for a spin and noticed the module names were changing, so that consumers would have to rename In fe6e23b, I added a small change so that the module exposed is |
In c718fd1, i left the mjs lib public name as With these two changes, consumers like |
CHANGES: - Fix tests to work with melange v3: [ahrefs/melange-moment#7](ahrefs/melange-moment#7). - Add support for ES6, place CommonJS support under `melange-moment.cjs`: [ahrefs/melange-moment#6](ahrefs/melange-moment#6).
CHANGES: - Fix tests to work with melange v3: [ahrefs/melange-moment#7](ahrefs/melange-moment#7). - Add support for ES6, place CommonJS support under `melange-moment.cjs`: [ahrefs/melange-moment#6](ahrefs/melange-moment#6).
Description
In this PR we add two modules with bindings: one for common js environment usage and another one for es modules environment usage.
Scope of work:
Problem:
Generated code with
[@bs.module] external momentNow: unit => MomentRe.Moment.t = "moment";
doesn't work in node/es modules mode (and esbuild also emits warnings):Generated code:
Node error:
Esbuild warning:
Generated code with
[@bs.module "moment"] external momentNow: unit => MomentRe.Moment.t = "default";
works fine.Generated code: