Browse Source

fix(build) don't pollute global state in ESM build

tags/v0.0.2
Saúl Ibarra Corretgé 2 years ago
parent
commit
89b102629f
2 changed files with 32 additions and 32 deletions
  1. 2
    29
      JitsiMeetJS.js
  2. 30
    3
      index.js

+ 2
- 29
JitsiMeetJS.js View File

@@ -71,37 +71,10 @@ function getAnalyticsAttributesFromOptions(options) {
71 71
     return attributes;
72 72
 }
73 73
 
74
-/**
75
- * Tries to deal with the following problem: {@code JitsiMeetJS} is not only
76
- * this module, it's also a global (i.e. attached to {@code window}) namespace
77
- * for all globals of the projects in the Jitsi Meet family. If lib-jitsi-meet
78
- * is loaded through an HTML {@code script} tag, {@code JitsiMeetJS} will
79
- * automatically be attached to {@code window} by webpack. Unfortunately,
80
- * webpack's source code does not check whether the global variable has already
81
- * been assigned and overwrites it. Which is OK for the module
82
- * {@code JitsiMeetJS} but is not OK for the namespace {@code JitsiMeetJS}
83
- * because it may already contain the values of other projects in the Jitsi Meet
84
- * family. The solution offered here works around webpack by merging all
85
- * existing values of the namespace {@code JitsiMeetJS} into the module
86
- * {@code JitsiMeetJS}.
87
- *
88
- * @param {Object} module - The module {@code JitsiMeetJS} (which will be
89
- * exported and may be attached to {@code window} by webpack later on).
90
- * @private
91
- * @returns {Object} - A {@code JitsiMeetJS} module which contains all existing
92
- * value of the namespace {@code JitsiMeetJS} (if any).
93
- */
94
-function _mergeNamespaceAndModule(module) {
95
-    return (
96
-        typeof window.JitsiMeetJS === 'object'
97
-            ? Object.assign({}, window.JitsiMeetJS, module)
98
-            : module);
99
-}
100
-
101 74
 /**
102 75
  * The public API of the Jitsi Meet library (a.k.a. {@code JitsiMeetJS}).
103 76
  */
104
-export default _mergeNamespaceAndModule({
77
+export default {
105 78
 
106 79
     version: '{#COMMIT_HASH#}',
107 80
 
@@ -580,4 +553,4 @@ export default _mergeNamespaceAndModule({
580 553
         ScriptUtil,
581 554
         browser
582 555
     }
583
-});
556
+};

+ 30
- 3
index.js View File

@@ -1,3 +1,30 @@
1
-// For legacy purposes, preserve the UMD of the public API of the Jitsi Meet
2
-// library (a.k.a. JitsiMeetJS).
3
-module.exports = require('./JitsiMeetJS').default;
1
+const ljm = require('./JitsiMeetJS').default;
2
+
3
+/**
4
+ * Tries to deal with the following problem: {@code JitsiMeetJS} is not only
5
+ * this module, it's also a global (i.e. attached to {@code window}) namespace
6
+ * for all globals of the projects in the Jitsi Meet family. If lib-jitsi-meet
7
+ * is loaded through an HTML {@code script} tag, {@code JitsiMeetJS} will
8
+ * automatically be attached to {@code window} by webpack. Unfortunately,
9
+ * webpack's source code does not check whether the global variable has already
10
+ * been assigned and overwrites it. Which is OK for the module
11
+ * {@code JitsiMeetJS} but is not OK for the namespace {@code JitsiMeetJS}
12
+ * because it may already contain the values of other projects in the Jitsi Meet
13
+ * family. The solution offered here works around webpack by merging all
14
+ * existing values of the namespace {@code JitsiMeetJS} into the module
15
+ * {@code JitsiMeetJS}.
16
+ *
17
+ * @param {Object} module - The module {@code JitsiMeetJS} (which will be
18
+ * exported and may be attached to {@code window} by webpack later on).
19
+ * @private
20
+ * @returns {Object} - A {@code JitsiMeetJS} module which contains all existing
21
+ * value of the namespace {@code JitsiMeetJS} (if any).
22
+ */
23
+function _mergeNamespaceAndModule(module) {
24
+    return (
25
+        typeof window.JitsiMeetJS === 'object'
26
+            ? Object.assign({}, window.JitsiMeetJS, module)
27
+            : module);
28
+}
29
+
30
+module.exports = _mergeNamespaceAndModule(ljm);

Loading…
Cancel
Save