bv-ui-core 2.8.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/global/index.js
CHANGED
@@ -6,11 +6,36 @@
|
|
6
6
|
'use strict'; /* eslint strict:0 */
|
7
7
|
|
8
8
|
var getGlobal = function () {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
var globalObj = (function () {
|
10
|
+
if (typeof globalThis !== 'undefined') { return globalThis; }
|
11
|
+
if (typeof window !== 'undefined') { return window; }
|
12
|
+
if (typeof self !== 'undefined') { return self; }
|
13
|
+
if (typeof global !== 'undefined') { return global; }
|
14
|
+
throw new Error('unable to locate global object');
|
15
|
+
})()
|
16
|
+
/*
|
17
|
+
The below code was added in case there is pollution in global namespace
|
18
|
+
windows object during transpilation with __esModule being set. Below code would support
|
19
|
+
global import in all bundle use cases
|
20
|
+
*/
|
21
|
+
if (globalObj && globalObj.__esModule) {
|
22
|
+
const override = {
|
23
|
+
get: function (target, prop, receiver) {
|
24
|
+
if (prop === 'default') {
|
25
|
+
return target
|
26
|
+
}
|
27
|
+
|
28
|
+
return Reflect.get(receiver, prop, target)
|
29
|
+
},
|
30
|
+
|
31
|
+
set: function (target, prop, value) {
|
32
|
+
Reflect.set(target, prop, value)
|
33
|
+
},
|
34
|
+
};
|
35
|
+
const proxyGlobal = new Proxy(globalObj, override)
|
36
|
+
return proxyGlobal
|
37
|
+
}
|
38
|
+
return globalObj
|
14
39
|
};
|
15
40
|
|
16
41
|
module.exports = getGlobal();
|
package/package.json
CHANGED
@@ -15,4 +15,13 @@ describe('lib/global', function () {
|
|
15
15
|
}
|
16
16
|
});
|
17
17
|
|
18
|
+
it('should export window with default pointing to windows if __esModule is set', function () {
|
19
|
+
// If we have access to the window object, compare against it.
|
20
|
+
if (typeof window !== 'undefined') {
|
21
|
+
window.__esModule = true
|
22
|
+
var global = require('../../../lib/global')
|
23
|
+
expect(global).to.eql(window);
|
24
|
+
}
|
25
|
+
});
|
26
|
+
|
18
27
|
});
|