From 766faf465eb003e22675899f27fbfbad928995cb Mon Sep 17 00:00:00 2001 From: chocolateboy Date: Sat, 31 Jul 2021 18:48:59 +0100 Subject: [PATCH] improve portability of the UMD build: - replace `self` with `globalThis` - make module detection more robust Co-authored-by: David Chambers --- .eslintrc.json | 4 ++++ index.js | 8 ++++++-- scripts/generate-js | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 27cde45..13bc598 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,6 +10,10 @@ "no-undef": ["off"], "no-unused-vars": ["off"] } + }, + { + "files": "index.js", + "globals": {"globalThis": false} } ] } diff --git a/index.js b/index.js index f414193..8212585 100644 --- a/index.js +++ b/index.js @@ -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; } } ()); diff --git a/scripts/generate-js b/scripts/generate-js index 0bbfa71..0aa816a 100755 --- a/scripts/generate-js +++ b/scripts/generate-js @@ -11,10 +11,14 @@ cat >index.js <