Skip to content

Commit 3d32525

Browse files
godkitekitezhou
and
kitezhou
authoredAug 1, 2022
fix: 修复 isNode 环境判断不严谨的问题,兼容 web worker 环境 (#153)
Co-authored-by: kitezhou <[email protected]>
1 parent 964e835 commit 3d32525

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed
 

Diff for: ‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-js-sdk-v5",
3-
"version": "1.3.9",
3+
"version": "1.3.10",
44
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
55
"main": "index.js",
66
"types": "index.d.ts",

Diff for: ‎src/cos.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ COS.util = {
7878
json2xml: util.json2xml,
7979
};
8080
COS.getAuthorization = util.getAuth;
81-
COS.version = '1.3.9';
81+
COS.version = '1.3.10';
8282

8383
module.exports = COS;

Diff for: ‎src/util.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,13 @@ var error = function (err, opt) {
710710
}
711711

712712
var isNode = function () {
713-
return typeof window !== 'object' && typeof process === 'object' && typeof require === 'function';
713+
// 得兜底 web worker 环境中 webpack 用了 process 插件之类的情况
714+
return typeof window !== 'object' && typeof process === 'object' && typeof require === 'function' && !isWebWorker();
715+
}
716+
717+
var isWebWorker = function () {
718+
// 有限判断 worker 环境的 constructor name 其次用 worker 独有的 FileReaderSync 兜底 详细参考 https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Workers_API/Using_web_workers
719+
return globalThis.constructor.name === 'DedicatedWorkerGlobalScope' || globalThis.FileReaderSync;
714720
}
715721

716722
var isCIHost = function(url) {

0 commit comments

Comments
 (0)