Skip to content

Commit 766faf4

Browse files
improve portability of the UMD build:
- replace `self` with `globalThis` - make module detection more robust Co-authored-by: David Chambers <dc@davidchambers.me>
1 parent 4b307da commit 766faf4

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"no-undef": ["off"],
1111
"no-unused-vars": ["off"]
1212
}
13+
},
14+
{
15+
"files": "index.js",
16+
"globals": {"globalThis": false}
1317
}
1418
]
1519
}

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
};
2929

3030
/* istanbul ignore else */
31-
if (typeof module === 'object' && typeof module.exports === 'object') {
31+
if (
32+
typeof module === 'object' &&
33+
module != null &&
34+
typeof module.exports === 'object'
35+
) {
3236
module.exports = mapping;
3337
} else {
34-
self.FantasyLand = mapping;
38+
globalThis.FantasyLand = mapping;
3539
}
3640

3741
} ());

scripts/generate-js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ cat >index.js <<EOF
1111
};
1212
1313
/* istanbul ignore else */
14-
if (typeof module === 'object' && typeof module.exports === 'object') {
14+
if (
15+
typeof module === 'object' &&
16+
module != null &&
17+
typeof module.exports === 'object'
18+
) {
1519
module.exports = mapping;
1620
} else {
17-
self.FantasyLand = mapping;
21+
globalThis.FantasyLand = mapping;
1822
}
1923
2024
} ());

0 commit comments

Comments
 (0)