Skip to content

Commit 32ffffe

Browse files
committed
Obfuscate assignment to module.exports to prevent warnings
Some javascript bundles (like vite) emit warnings when they encounter module.export in an ESM module. This just hides that assignment a little so that that warning doesn't appear.
1 parent d104a8f commit 32ffffe

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Pending
4+
5+
* Obfuscate assignment to module.exports in order to prevent warnings in javascript bundlers, like Vite. Fixes [#337](https://github.com/railsware/js-routes/issues/337).
6+
37
## [2.3.6]
48

59
* Fixed serialization of empty `Array` and empty `Hash`. Fixes [#336](https://github.com/railsware/js-routes/issues/336).

lib/routes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ RubyVariables.WRAPPER(
2727
CJS: {
2828
define(routes) {
2929
if (module) {
30-
module.exports = routes;
30+
// Some javascript processors (like vite/rolldown)
31+
// warn on using `module.exports` in an ESM module.
32+
// This just obfuscates that assignment a little so
33+
// users don't get a warning they can't fix.
34+
const _mod = module;
35+
_mod.exports = routes;
3136
}
3237
},
3338
isSupported() {

0 commit comments

Comments
 (0)