Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/advanced-js-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ preventing any Melange code from creating values of such type.
## Use Melange code from JavaScript

As mentioned in the [build system
section](./build-system.md#commonjs-or-es6-modules), Melange allows to produce
both CommonJS and ES6 modules. In both cases, using Melange-generated JavaScript
section](./build-system.md#commonjs-or-esm-modules), Melange allows to produce
both CommonJS and ESM modules. In both cases, using Melange-generated JavaScript
code from any hand-written JavaScript file works as expected.

The following definition:
Expand All @@ -618,7 +618,7 @@ function print(name) {
exports.print = print;
```

When using ES6 (through the `(module_systems es6)` field in `melange.emit`) this
When using ESM (through the `(module_systems esm)` field in `melange.emit`) this
code will be generated:

```js
Expand All @@ -634,9 +634,9 @@ export {
So one can use either `require` or `import` (depending on the module system of
choice) to import the `print` value in a JavaScript file.

### Default ES6 values
### Default ESM values

One special case occur when working with JavaScript imports in ES6 modules that
One special case occurs when working with JavaScript imports in ESM modules that
look like this:

```js
Expand Down
26 changes: 13 additions & 13 deletions docs/build-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ Create a file named `dune-project`. This file will tell Dune a few things about
our project configuration:

```dune
(lang dune 3.8)
(lang dune 3.21)

(using melange 0.1)
(using melange 1.0)
```

The first line `(lang dune 3.8)` tells Dune which version of the "Dune language"
(the language used in `dune` files) we want to use. Melange support in Dune is
only available from version 3.8.
The first line `(lang dune 3.21)` tells Dune which version of the "Dune
language" (the language used in `dune` files) we want to use. Melange support
in Dune is only available from version 3.8.

The second line `(using melange 0.1)` tells Dune we want to use the [Melange
The second line `(using melange 1.0)` tells Dune we want to use the [Melange
extension of the Dune
language](https://dune.readthedocs.io/en/stable/reference/dune-project/using.html).

Expand Down Expand Up @@ -435,33 +435,33 @@ with Melange, check the [Dune documentation](https://dune.readthedocs.io/), and
the [Melange opam
template](https://github.com/melange-re/melange-opam-template).

#### CommonJS or ES6 modules
#### CommonJS or ESM modules

Melange produces JavaScript modules that export the functions they declare, and
declare imports for the values and modules they depend on.

By default, Melange will produce
[CommonJS](https://en.wikipedia.org/wiki/CommonJS) modules, but it is possible
to configure it to generate
[ES6](https://en.wikipedia.org/wiki/ECMAScript#6th_Edition_-_ECMAScript_2015)
[ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
modules.

Use the `module_systems` field in the [`melange.emit`
stanza](https://dune.readthedocs.io/en/stable/melange.html#melange-emit) to emit
ES6 modules:
ESM modules:

```dune
(melange.emit
(target app)
(alias my-app)
(libraries lib)
(module_systems es6))
(module_systems esm))
```

If no extension is specified, the resulting JavaScript files will use `.js`. You
can specify a different extension with a pair `(<module_system> <extension>)`,
e.g. `(module_systems (es6 mjs))`. Multiple module systems can be used in the
e.g. `(module_systems (esm mjs))`. Multiple module systems can be used in the
same field as long as their extensions are different. For example,
`(module_systems commonjs (es6 mjs))` will produce one set of JavaScript files
using CommonJS and the `.js` extension, and another using ES6 and the `.mjs`
`(module_systems commonjs (esm mjs))` will produce one set of JavaScript files
using CommonJS and the `.js` extension, and another using ESM and the `.mjs`
extension.
3 changes: 1 addition & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ template](https://github.com/melange-re/melange-esy-template/generate).
"name": "melange-project",
"dependencies": {
"ocaml": "5.1.x",
"@opam/dune": ">= 3.8.0",
"@opam/dune": ">= 3.21.0",
"@opam/melange": "*"
},
"devDependencies": {
Expand All @@ -167,4 +167,3 @@ Run:

1. `esy install` to build and make all dependencies available
2. `esy shell` to enter a Melange development environment

8 changes: 4 additions & 4 deletions docs/how-to-guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ Create a file named `dune-project` in the library root folder. This file will
tell Dune a few things about our project configuration:

```dune
(lang dune 3.8)
(lang dune 3.21)

(using melange 0.1)
(using melange 1.0)
```

### Replace the `bsconfig.json` file with one or multiple `dune` files
Expand Down Expand Up @@ -268,7 +268,7 @@ documentation](https://dune.readthedocs.io/en/stable/reference/dune/rule.html).
This setting is not configured at the library level, but rather at the
application level, using the `module_systems` field in the `melange.emit`
stanza. To read more about it, check the corresponding [build
system](./build-system.md#commonjs-or-es6-modules) section.
system](./build-system.md#commonjs-or-esm-modules) section.

Regarding the `"in-source"` configuration, the corresponding field in Dune would
be the `(promote (until-clean))` configuration, which can be added to a
Expand All @@ -279,7 +279,7 @@ documentation](https://dune.readthedocs.io/en/stable/reference/dune/rule.html#pr

Same as with `package-specs` this configuration is set at the application level,
using the `module_systems` field in the `melange.emit` stanza. Check the
[CommonJS or ES6 modules](./build-system.md#commonjs-or-es6-modules) section to
[CommonJS or ESM modules](./build-system.md#commonjs-or-esm-modules) section to
learn more about it.

#### `warnings` and `bsc-flags`
Expand Down
4 changes: 2 additions & 2 deletions docs/package-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ then `reason-react` should be added to the `dune` file under the `src` folder:
(libraries lib reason-react)
(preprocess
(pps reason-react-ppx))
(module_systems es6))
(module_systems esm))
```

Some libraries will only work after being processed by an accompanying PPX,
Expand Down Expand Up @@ -399,7 +399,7 @@ file:
(libraries lib reason-react melange-fetch)
(preprocess
(pps reason-react-ppx))
(module_systems es6))
(module_systems esm))
```

### npm packages
Expand Down
2 changes: 1 addition & 1 deletion documentation-site.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ homepage: "https://github.com/melange-re/melange-re.github.io"
bug-reports: "https://github.com/melange-re/melange-re.github.io/issues"
depends: [
"ocaml"
"dune" {>= "3.8"}
"dune" {>= "3.21"}
"reason" {>= "3.17"}
"reason-react"
"reason-react-ppx"
Expand Down
4 changes: 2 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(lang dune 3.8)
(lang dune 3.21)

(using melange 0.1)
(using melange 1.0)

(name documentation-site)
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
forAllSystems = f: nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system:
let
pkgs = nixpkgs.legacyPackages.${system}.extend (self: super: {
ocamlPackages = super.ocaml-ng.ocamlPackages_5_4.overrideScope (oself: osuper: {

ocamlPackages = super.ocaml-ng.ocamlPackages_5_4.overrideScope (oself: osuper: with oself; {
cmarkit = osuper.cmarkit.overrideAttrs (_: {
src = super.fetchFromGitHub {
owner = "dbuenzli";
Expand All @@ -19,11 +20,11 @@
# propagatedBuildInputs = (o.propagatedBuildInputs or [ ]) ++ (with oself; [ cmdliner ]);
buildPhase = ''
runHook preBuild
${oself.topkg.run} build --with-cmdliner false
${topkg.run} build --with-cmdliner false
runHook postBuild
'';
});
melange-playground = with oself; buildDunePackage {
melange-playground = buildDunePackage {
pname = "melange-playground";
inherit (melange) src version;
# nativeBuildInputs = [ cppo reason ];
Expand Down
2 changes: 1 addition & 1 deletion playground/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
melange.belt
melange.dom)
(modules) ; Empty, we just want to the js artifacts from the libraries
(module_systems es6))
(module_systems esm))

(rule
(deps
Expand Down
4 changes: 2 additions & 2 deletions scripts/advanced-js-interop.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ This test file is automatically generated from its corresponding markdown
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down
4 changes: 2 additions & 2 deletions scripts/attributes-and-extension-nodes.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ This test file is automatically generated from its corresponding markdown
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down
4 changes: 2 additions & 2 deletions scripts/bindings-cookbook.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ This test file is automatically generated from its corresponding markdown
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-system.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ This test file is automatically generated from its corresponding markdown
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down
4 changes: 2 additions & 2 deletions scripts/communicate-with-javascript.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ This test file is automatically generated from its corresponding markdown
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down
4 changes: 2 additions & 2 deletions scripts/data-types-and-runtime-rep.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ This test file is automatically generated from its corresponding markdown
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down
4 changes: 2 additions & 2 deletions scripts/extract_code_blocks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ let () =
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down
4 changes: 2 additions & 2 deletions scripts/language-concepts.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ This test file is automatically generated from its corresponding markdown
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down
4 changes: 2 additions & 2 deletions scripts/working-with-js-objects-and-values.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ This test file is automatically generated from its corresponding markdown
file. To update the tests, run `dune build @extract-code-blocks`.

$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> (lang dune 3.21)
> (using melange 1.0)
> EOF

$ cat > dune <<EOF
Expand Down