melange-re.github.io
melange-re.github.io copied to clipboard
Include package.json while installing es6 stdlib (or any es6 package?)
Rescript es6 version of stdlib included a package.json
with "type": "module"
https://github.com/rescript-lang/rescript-compiler/blob/77b6a3bcd63989d2fb015c8a2543d87f3cb45007/lib/es6/package.json
This comes useful when running nodejs apps with es6 bundling, as otherwise one has to resort to workarounds like custom node loaders, using mjs
extensions and such.
There is a workaround using dune rules:
(subdir
target
(subdir
node_modules
(subdir
melange
(rule
(alias my_melange_alias)
(action
(with-stdout-to
package.json
(run echo "{\"type\": \"module\"}")))))
(subdir
melange.belt
(rule
(alias my_melange_alias)
(action
(with-stdout-to
package.json
(run echo "{\"type\": \"module\"}")))))
(subdir
melange.runtime
(rule
(alias my_melange_alias)
(action
(with-stdout-to
package.json
(run echo "{\"type\": \"module\"}")))))))
But it has to be defined for the 3 libraries exposed by Melange, and also replicated for every melange.emit stanza used.
I wonder if Melange could include package.json
files similarly. The problem applies to any library really, so there might be some generic solution out there. Most probably it needs some coordination with Dune? 🤔
cc @denis-ok