-
Notifications
You must be signed in to change notification settings - Fork 481
melange: don't emit empty .js files for module aliases
#12464
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
Merged
anmonteiro
merged 3 commits into
ocaml:main
from
anmonteiro:anmonteiro/melange-dont-include-empty-aliases
Sep 22, 2025
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - melange support: don't emit empty JavaScript modules for generated module | ||
| aliases. (@anmonteiro) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
test/blackbox-tests/test-cases/melange/empty-aliases-file.t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
|
|
||
| $ mkdir lib | ||
| $ cat > dune-project <<EOF | ||
| > (lang dune 3.20) | ||
| > (package (name foo)) | ||
| > (using melange 1.0) | ||
| > EOF | ||
|
|
||
| $ cat > lib/dune <<EOF | ||
| > (library | ||
| > (name foo) | ||
| > (modes melange)) | ||
| > EOF | ||
| $ cat > lib/bar.ml <<EOF | ||
| > let greeting = "hello" | ||
| > EOF | ||
|
|
||
| $ cat > dune <<EOF | ||
| > (melange.emit | ||
| > (target dist) | ||
| > (libraries foo) | ||
| > (emit_stdlib false) | ||
| > (modules)) | ||
| > EOF | ||
| $ cat > lib/bar.ml <<EOF | ||
| > let greeting = "hello" | ||
| > EOF | ||
|
|
||
| $ dune build @melange | ||
|
|
||
| No `.js` file present for the library alias `foo.js` | ||
|
|
||
| $ find _build/default/dist/lib -type f | sort | ||
| _build/default/dist/lib/bar.js | ||
|
|
||
| Now write a foo.ml file | ||
|
|
||
| $ cat > lib/dune <<EOF | ||
| > (library | ||
| > (name foo) | ||
| > (modes melange)) | ||
| > EOF | ||
| $ cat > lib/foo.ml <<EOF | ||
| > module Bar = Bar | ||
| > let x = "foo" | ||
| > EOF | ||
|
|
||
| $ dune build @melange | ||
|
|
||
| `foo.js` was manually written, therefore it's present | ||
|
|
||
| $ find _build/default/dist/ -type f | sort | ||
| _build/default/dist/lib/bar.js | ||
| _build/default/dist/lib/foo.js | ||
| $ cat _build/default/dist/lib/foo.js | ||
| // Generated by Melange | ||
| 'use strict'; | ||
|
|
||
|
|
||
| const x = "foo"; | ||
|
|
||
| module.exports = { | ||
| x, | ||
| } | ||
| /* No side effect */ | ||
|
|
||
| `(include_subdirs qualified)` | ||
|
|
||
| $ mkdir lib/sub | ||
| $ cat > lib/dune <<EOF | ||
| > (include_subdirs qualified) | ||
| > (library | ||
| > (name foo) | ||
| > (modes melange)) | ||
| > EOF | ||
| $ cat > lib/bar.ml <<EOF | ||
| > let hello = Sub.Hello.hello | ||
| > EOF | ||
| $ cat > lib/sub/hello.ml <<EOF | ||
| > let hello = "hello from sub" | ||
| > EOF | ||
| $ cat > lib/foo.ml <<EOF | ||
| > module Bar = Bar | ||
| > let x = "foo" | ||
| > EOF | ||
|
|
||
| $ dune build @melange | ||
|
|
||
| `foo.js` was manually written, therefore it's present. `sub.js` is an alias | ||
| file, and it's not present | ||
|
|
||
| $ find _build/default/dist/lib -type f | sort | ||
| _build/default/dist/lib/bar.js | ||
| _build/default/dist/lib/foo.js | ||
| _build/default/dist/lib/sub/hello.js | ||
|
|
||
| $ cat > lib/dune <<EOF | ||
| > (include_subdirs qualified) | ||
| > (library | ||
| > (name foo) | ||
| > (modes melange)) | ||
| > EOF | ||
| $ cat > lib/bar.ml <<EOF | ||
| > let hello = Sub.Hello.hello ^ Sub.world | ||
| > EOF | ||
| $ cat > lib/sub/sub.ml <<EOF | ||
| > module Hello = Hello | ||
| > let world = "world" | ||
| > EOF | ||
| $ cat > lib/sub/hello.ml <<EOF | ||
| > let hello = "hello from sub" | ||
| > EOF | ||
| $ cat > lib/foo.ml <<EOF | ||
| > module Bar = Bar | ||
| > let x = "foo" | ||
| > EOF | ||
|
|
||
| $ DUNE_SANDBOX=none dune build @melange | ||
|
|
||
| `foo.js` was manually written, therefore it's present. `sub.js` is an alias | ||
| file, and it's not present | ||
|
|
||
| $ find _build/default/dist/lib -type f | sort | ||
| _build/default/dist/lib/bar.js | ||
| _build/default/dist/lib/foo.js | ||
| _build/default/dist/lib/sub/hello.js | ||
| _build/default/dist/lib/sub/sub.js | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.