@tarojs/plugin-http 3.7.0-canary.6 → 3.8.0-canary.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/LICENSE +14 -0
- package/dist/runtime.js +19 -11
- package/package.json +7 -7
- package/src/__tests__/cookie.spec.js +0 -1
- package/src/__tests__/dom.spec.js +1 -3
- package/src/runtime/Cookie.ts +1 -1
- package/src/runtime/XMLHttpRequest.ts +9 -10
- package/src/runtime/index.ts +2 -3
package/LICENSE
CHANGED
|
@@ -158,3 +158,17 @@ MIT (stencil-vue2-output-target):
|
|
|
158
158
|
The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
|
|
159
159
|
`/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
|
|
160
160
|
See `/LICENSE` for details of the license.
|
|
161
|
+
|
|
162
|
+
==================
|
|
163
|
+
|
|
164
|
+
MIT (weui):
|
|
165
|
+
The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
|
|
166
|
+
`/packages/taro-components/src/components/*.scss`
|
|
167
|
+
See `/LICENSE.txt` for details of the license.
|
|
168
|
+
|
|
169
|
+
==================
|
|
170
|
+
|
|
171
|
+
Apache-2.0 (intersection-observer):
|
|
172
|
+
The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
|
|
173
|
+
`/packages/taro-api/src/polyfill/intersection-observer.ts`
|
|
174
|
+
See `/LICENSE.txt` for details of the license.
|
package/dist/runtime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseUrl, Events, createEvent, window, document } from '@tarojs/runtime';
|
|
2
2
|
export { document } from '@tarojs/runtime';
|
|
3
|
-
import { isString, isFunction, isWebPlatform } from '@tarojs/shared';
|
|
4
3
|
import { setStorage, getStorageSync, request } from '@tarojs/taro';
|
|
4
|
+
import { isString, isFunction } from '@tarojs/shared';
|
|
5
5
|
|
|
6
6
|
/******************************************************************************
|
|
7
7
|
Copyright (c) Microsoft Corporation.
|
|
@@ -17,7 +17,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
17
17
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
18
|
PERFORMANCE OF THIS SOFTWARE.
|
|
19
19
|
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise */
|
|
20
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
@@ -31,7 +31,12 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
|
31
31
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
32
32
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
33
33
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
37
|
+
var e = new Error(message);
|
|
38
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
39
|
+
};
|
|
35
40
|
|
|
36
41
|
var _Cookie_map;
|
|
37
42
|
const STORAGE_KEY = 'PAGE_COOKIE';
|
|
@@ -357,20 +362,20 @@ function createXMLHttpRequestEvent(event, target, loaded) {
|
|
|
357
362
|
const e = createEvent(event);
|
|
358
363
|
try {
|
|
359
364
|
Object.defineProperties(e, {
|
|
360
|
-
|
|
365
|
+
currentTarget: {
|
|
361
366
|
enumerable: true,
|
|
362
367
|
value: target
|
|
363
368
|
},
|
|
364
|
-
|
|
369
|
+
target: {
|
|
365
370
|
enumerable: true,
|
|
366
371
|
value: target
|
|
367
372
|
},
|
|
368
|
-
|
|
373
|
+
loaded: {
|
|
369
374
|
enumerable: true,
|
|
370
375
|
value: loaded || 0
|
|
371
376
|
},
|
|
372
377
|
// 读 Content-Range 字段,目前来说作用不大,先和 loaded 保持一致
|
|
373
|
-
|
|
378
|
+
total: {
|
|
374
379
|
enumerable: true,
|
|
375
380
|
value: loaded || 0
|
|
376
381
|
}
|
|
@@ -505,15 +510,17 @@ class XMLHttpRequest extends Events {
|
|
|
505
510
|
}
|
|
506
511
|
}
|
|
507
512
|
getAllResponseHeaders() {
|
|
508
|
-
if (__classPrivateFieldGet(this, _XMLHttpRequest_readyState, "f") === XMLHttpRequest.UNSENT || __classPrivateFieldGet(this, _XMLHttpRequest_readyState, "f") === XMLHttpRequest.OPENED || !__classPrivateFieldGet(this, _XMLHttpRequest_resHeader, "f"))
|
|
513
|
+
if (__classPrivateFieldGet(this, _XMLHttpRequest_readyState, "f") === XMLHttpRequest.UNSENT || __classPrivateFieldGet(this, _XMLHttpRequest_readyState, "f") === XMLHttpRequest.OPENED || !__classPrivateFieldGet(this, _XMLHttpRequest_resHeader, "f")) {
|
|
509
514
|
return '';
|
|
515
|
+
}
|
|
510
516
|
return Object.keys(__classPrivateFieldGet(this, _XMLHttpRequest_resHeader, "f"))
|
|
511
517
|
.map((key) => `${key}: ${__classPrivateFieldGet(this, _XMLHttpRequest_resHeader, "f")[key]}`)
|
|
512
518
|
.join('\r\n');
|
|
513
519
|
}
|
|
514
520
|
getResponseHeader(name) {
|
|
515
|
-
if (__classPrivateFieldGet(this, _XMLHttpRequest_readyState, "f") === XMLHttpRequest.UNSENT || __classPrivateFieldGet(this, _XMLHttpRequest_readyState, "f") === XMLHttpRequest.OPENED || !__classPrivateFieldGet(this, _XMLHttpRequest_resHeader, "f"))
|
|
521
|
+
if (__classPrivateFieldGet(this, _XMLHttpRequest_readyState, "f") === XMLHttpRequest.UNSENT || __classPrivateFieldGet(this, _XMLHttpRequest_readyState, "f") === XMLHttpRequest.OPENED || !__classPrivateFieldGet(this, _XMLHttpRequest_resHeader, "f")) {
|
|
516
522
|
return null;
|
|
523
|
+
}
|
|
517
524
|
// 处理大小写不敏感
|
|
518
525
|
const key = Object.keys(__classPrivateFieldGet(this, _XMLHttpRequest_resHeader, "f")).find((item) => item.toLowerCase() === name.toLowerCase());
|
|
519
526
|
const value = key ? __classPrivateFieldGet(this, _XMLHttpRequest_resHeader, "f")[key] : null;
|
|
@@ -580,6 +587,7 @@ _XMLHttpRequest_method = new WeakMap(), _XMLHttpRequest_url = new WeakMap(), _XM
|
|
|
580
587
|
// 头信息
|
|
581
588
|
const header = Object.assign({}, __classPrivateFieldGet(this, _XMLHttpRequest_header, "f"));
|
|
582
589
|
// https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Cookies
|
|
590
|
+
// @ts-ignore
|
|
583
591
|
header.cookie = window.document.$$cookie;
|
|
584
592
|
if (!this.withCredentials) {
|
|
585
593
|
// 不同源,要求 withCredentials 为 true 才携带 cookie
|
|
@@ -648,7 +656,7 @@ _XMLHttpRequest_method = new WeakMap(), _XMLHttpRequest_url = new WeakMap(), _XM
|
|
|
648
656
|
}
|
|
649
657
|
}, _XMLHttpRequest_requestFail = function _XMLHttpRequest_requestFail(err) {
|
|
650
658
|
// 微信小程序,无论接口返回200还是其他,响应无论是否有错误,都会进入 success 回调;只有类似超时这种请求错误才会进入 fail 回调
|
|
651
|
-
//
|
|
659
|
+
//
|
|
652
660
|
/**
|
|
653
661
|
* 阿里系小程序,接口返回非200状态码,会进入 fail 回调, 此时 err 对象结构如下(当错误码为 14 或 19 时,会多返回 status、data、headers。可通过这些字段获取服务端相关错误信息):
|
|
654
662
|
{
|
|
@@ -690,7 +698,7 @@ XMLHttpRequest.HEADERS_RECEIVED = 2;
|
|
|
690
698
|
XMLHttpRequest.LOADING = 3;
|
|
691
699
|
XMLHttpRequest.DONE = 4;
|
|
692
700
|
|
|
693
|
-
if (
|
|
701
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
694
702
|
if (ENABLE_COOKIE) {
|
|
695
703
|
const _cookie = createCookieInstance();
|
|
696
704
|
Object.defineProperties(document, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/plugin-http",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0-canary.1",
|
|
4
4
|
"description": "Taro 小程序端支持使用 web 请求 的插件",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/NervJS/taro#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tarojs/runtime": "3.
|
|
27
|
-
"@tarojs/shared": "3.
|
|
28
|
-
"@tarojs/service": "3.
|
|
26
|
+
"@tarojs/runtime": "3.8.0-canary.1",
|
|
27
|
+
"@tarojs/shared": "3.8.0-canary.1",
|
|
28
|
+
"@tarojs/service": "3.8.0-canary.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@rollup/plugin-json": "^6.
|
|
31
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
32
32
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
33
33
|
"jest": "^29.3.1",
|
|
34
34
|
"jest-cli": "^29.3.1",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"rollup-plugin-node-externals": "^5.0.0",
|
|
38
38
|
"rollup-plugin-ts": "^3.0.2",
|
|
39
39
|
"ts-jest": "^29.0.5",
|
|
40
|
-
"tslib": "^2.
|
|
40
|
+
"tslib": "^2.6.2",
|
|
41
41
|
"typescript": "^4.7.4"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "rollup -c -w --bundleConfigAsCjs",
|
|
45
45
|
"build": "rollup -c --bundleConfigAsCjs",
|
|
46
46
|
"test": "jest",
|
|
47
|
-
"test:ci": "jest --ci -i --coverage
|
|
47
|
+
"test:ci": "jest --ci -i --coverage --silent"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -3,9 +3,8 @@ describe('DOM', () => {
|
|
|
3
3
|
const runtime = require('../../dist/runtime')
|
|
4
4
|
const document = runtime.document
|
|
5
5
|
global.document = runtime.document
|
|
6
|
-
|
|
7
|
-
describe('document', () => {
|
|
8
6
|
|
|
7
|
+
describe('document', () => {
|
|
9
8
|
it('document setCookie', async () => {
|
|
10
9
|
expect(document.cookie).toBe('')
|
|
11
10
|
document.cookie = 'aaa=1111-2222-33-444-abcdefgasd; path=/; expires=Mon, 18 Jan 2038 19:14:07 GMT; secure;'
|
|
@@ -15,6 +14,5 @@ describe('DOM', () => {
|
|
|
15
14
|
'aaa=1111-2222-33-444-abcdefgasd; bbb=23123-aswe-4a7a-a740-f55dfd296b1d; ccc=69asd3d81234668942'
|
|
16
15
|
)
|
|
17
16
|
})
|
|
18
|
-
|
|
19
17
|
})
|
|
20
18
|
})
|
package/src/runtime/Cookie.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
|
-
Copyright (c) 2019 wechat-miniprogram.
|
|
2
|
+
Copyright (c) 2019 wechat-miniprogram.
|
|
3
3
|
Reference and modify code by miniprogram-render/src/bom/cookie.js.
|
|
4
4
|
|
|
5
5
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -63,27 +63,27 @@ function createXMLHttpRequestEvent (event: string, target:XMLHttpRequest, loaded
|
|
|
63
63
|
const e = createEvent(event) as XMLHttpRequestEvent
|
|
64
64
|
try {
|
|
65
65
|
Object.defineProperties(e, {
|
|
66
|
-
|
|
66
|
+
currentTarget: {
|
|
67
67
|
enumerable: true,
|
|
68
68
|
value: target
|
|
69
69
|
},
|
|
70
|
-
|
|
70
|
+
target: {
|
|
71
71
|
enumerable: true,
|
|
72
72
|
value: target
|
|
73
73
|
},
|
|
74
|
-
|
|
74
|
+
loaded: {
|
|
75
75
|
enumerable: true,
|
|
76
76
|
value: loaded || 0
|
|
77
77
|
},
|
|
78
78
|
// 读 Content-Range 字段,目前来说作用不大,先和 loaded 保持一致
|
|
79
|
-
|
|
79
|
+
total: {
|
|
80
80
|
enumerable: true,
|
|
81
81
|
value: loaded || 0
|
|
82
82
|
}
|
|
83
83
|
})
|
|
84
84
|
} catch (err) {
|
|
85
85
|
// no handler
|
|
86
|
-
}
|
|
86
|
+
}
|
|
87
87
|
return e
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -226,6 +226,7 @@ export class XMLHttpRequest extends Events {
|
|
|
226
226
|
// 头信息
|
|
227
227
|
const header = Object.assign({}, this.#header)
|
|
228
228
|
// https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Cookies
|
|
229
|
+
// @ts-ignore
|
|
229
230
|
header.cookie = window.document.$$cookie
|
|
230
231
|
if (!this.withCredentials) {
|
|
231
232
|
// 不同源,要求 withCredentials 为 true 才携带 cookie
|
|
@@ -314,7 +315,7 @@ export class XMLHttpRequest extends Events {
|
|
|
314
315
|
*/
|
|
315
316
|
#requestFail (err) {
|
|
316
317
|
// 微信小程序,无论接口返回200还是其他,响应无论是否有错误,都会进入 success 回调;只有类似超时这种请求错误才会进入 fail 回调
|
|
317
|
-
//
|
|
318
|
+
//
|
|
318
319
|
/**
|
|
319
320
|
* 阿里系小程序,接口返回非200状态码,会进入 fail 回调, 此时 err 对象结构如下(当错误码为 14 或 19 时,会多返回 status、data、headers。可通过这些字段获取服务端相关错误信息):
|
|
320
321
|
{
|
|
@@ -424,8 +425,7 @@ export class XMLHttpRequest extends Events {
|
|
|
424
425
|
}
|
|
425
426
|
|
|
426
427
|
getAllResponseHeaders () {
|
|
427
|
-
if (this.#readyState === XMLHttpRequest.UNSENT || this.#readyState === XMLHttpRequest.OPENED || !this.#resHeader)
|
|
428
|
-
return ''
|
|
428
|
+
if (this.#readyState === XMLHttpRequest.UNSENT || this.#readyState === XMLHttpRequest.OPENED || !this.#resHeader) { return '' }
|
|
429
429
|
|
|
430
430
|
return Object.keys(this.#resHeader)
|
|
431
431
|
.map((key) => `${key}: ${this.#resHeader![key]}`)
|
|
@@ -433,8 +433,7 @@ export class XMLHttpRequest extends Events {
|
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
getResponseHeader (name) {
|
|
436
|
-
if (this.#readyState === XMLHttpRequest.UNSENT || this.#readyState === XMLHttpRequest.OPENED || !this.#resHeader)
|
|
437
|
-
return null
|
|
436
|
+
if (this.#readyState === XMLHttpRequest.UNSENT || this.#readyState === XMLHttpRequest.OPENED || !this.#resHeader) { return null }
|
|
438
437
|
|
|
439
438
|
// 处理大小写不敏感
|
|
440
439
|
const key = Object.keys(this.#resHeader).find((item) => item.toLowerCase() === name.toLowerCase())
|
package/src/runtime/index.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { document, window } from '@tarojs/runtime'
|
|
2
|
-
import { isWebPlatform } from '@tarojs/shared'
|
|
3
2
|
|
|
4
3
|
import { Cookie, createCookieInstance } from './Cookie'
|
|
5
4
|
import { type XMLHttpRequestEvent, XMLHttpRequest } from './XMLHttpRequest'
|
|
6
5
|
|
|
7
6
|
declare const ENABLE_COOKIE: boolean
|
|
8
7
|
|
|
9
|
-
if (
|
|
8
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
10
9
|
if (ENABLE_COOKIE) {
|
|
11
10
|
const _cookie = createCookieInstance()
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
Object.defineProperties(document, {
|
|
14
13
|
URL: {
|
|
15
14
|
get () {
|