Skip to content

Commit

Permalink
fix excessive gleam.mjs generation
Browse files Browse the repository at this point in the history
This patch fixes excessive generation by checking if `modules` is empty.

Two other possible solutions have been ruled out:

- Checking for file existence may result in not updating outdated files
- Comparing contents is slow

closes #3178
  • Loading branch information
Ofek Doitch authored and Ofek Doitch committed Jun 4, 2024
1 parent a4128b0 commit 4c1c6d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
anonymous function passed as an argument.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Fixed a bug where the compiler would unnecessarily generate `gleam.mjs`,
confusing build tools like Vite
([Ofek Doitch](https://github.com/ofekd))

## v1.2.1 - 2024-05-30

### Bug Fixes
Expand Down
8 changes: 7 additions & 1 deletion compiler-core/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ impl<'a> JavaScript<'a> {
}
self.js_module(writer, module, &js_name)?
}
self.write_prelude(writer)?;

// This check skips unnecessary `gleam.mjs` writes which confuse
// watchers and HMR build tools
if !modules.is_empty() {
self.write_prelude(writer)?;
}

Ok(())
}

Expand Down

0 comments on commit 4c1c6d6

Please sign in to comment.