Skip to content

Commit

Permalink
improve portability of the UMD build:
Browse files Browse the repository at this point in the history
- replace `self` with `globalThis`
- make module detection more robust

Co-authored-by: David Chambers <[email protected]>
  • Loading branch information
chocolateboy and davidchambers committed Aug 2, 2021
1 parent 4b307da commit 766faf4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"no-undef": ["off"],
"no-unused-vars": ["off"]
}
},
{
"files": "index.js",
"globals": {"globalThis": false}
}
]
}
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
};

/* istanbul ignore else */
if (typeof module === 'object' && typeof module.exports === 'object') {
if (
typeof module === 'object' &&
module != null &&
typeof module.exports === 'object'
) {
module.exports = mapping;
} else {
self.FantasyLand = mapping;
globalThis.FantasyLand = mapping;
}

} ());
8 changes: 6 additions & 2 deletions scripts/generate-js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ cat >index.js <<EOF
};
/* istanbul ignore else */
if (typeof module === 'object' && typeof module.exports === 'object') {
if (
typeof module === 'object' &&
module != null &&
typeof module.exports === 'object'
) {
module.exports = mapping;
} else {
self.FantasyLand = mapping;
globalThis.FantasyLand = mapping;
}
} ());
Expand Down

0 comments on commit 766faf4

Please sign in to comment.