Skip to content

Commit

Permalink
fix: 修复 isNode 环境判断不严谨的问题,兼容 web worker 环境 (#153)
Browse files Browse the repository at this point in the history
Co-authored-by: kitezhou <[email protected]>
  • Loading branch information
godkite and kitezhou authored Aug 1, 2022
1 parent 964e835 commit 3d32525
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "1.3.9",
"version": "1.3.10",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "index.js",
"types": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ COS.util = {
json2xml: util.json2xml,
};
COS.getAuthorization = util.getAuth;
COS.version = '1.3.9';
COS.version = '1.3.10';

module.exports = COS;
8 changes: 7 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,13 @@ var error = function (err, opt) {
}

var isNode = function () {
return typeof window !== 'object' && typeof process === 'object' && typeof require === 'function';
// 得兜底 web worker 环境中 webpack 用了 process 插件之类的情况
return typeof window !== 'object' && typeof process === 'object' && typeof require === 'function' && !isWebWorker();
}

var isWebWorker = function () {
// 有限判断 worker 环境的 constructor name 其次用 worker 独有的 FileReaderSync 兜底 详细参考 https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Workers_API/Using_web_workers
return globalThis.constructor.name === 'DedicatedWorkerGlobalScope' || globalThis.FileReaderSync;
}

var isCIHost = function(url) {
Expand Down

0 comments on commit 3d32525

Please sign in to comment.