@tarojs/plugin-http 3.6.2 → 3.6.3
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 +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -15
- package/dist/runtime.js +2 -2
- package/package.json +10 -6
- package/src/index.ts +17 -15
- package/src/runtime/XMLHttpRequest.ts +6 -6
- package/src/runtime/index.ts +3 -3
package/LICENSE
CHANGED
|
@@ -137,3 +137,24 @@ MIT (miniprogram-render):
|
|
|
137
137
|
The following files embed [miniprogram-render](https://github.com/Tencent/kbone) MIT:
|
|
138
138
|
`/packages/taro-plugin-http/src/runtime/Cookie.ts`
|
|
139
139
|
See `/LICENSE` for details of the license.
|
|
140
|
+
|
|
141
|
+
==================
|
|
142
|
+
|
|
143
|
+
MIT (stencil-ds-output-targets):
|
|
144
|
+
The following files embed [stencil-ds-output-targets](https://github.com/ionic-team/stencil-ds-output-targets/) MIT:
|
|
145
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/attachProps.ts`
|
|
146
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/case.ts`
|
|
147
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/dev.ts`
|
|
148
|
+
`/packages/taro-components-library-react/src/react-component-lib/utils/index.tsx`
|
|
149
|
+
`/packages/taro-components-library-react/src/react-component-lib/createComponent.tsx`
|
|
150
|
+
`/packages/taro-components-library-react/src/react-component-lib/createOverlayComponent.tsx`
|
|
151
|
+
`/packages/taro-components-library-react/src/react-component-lib/interfaces.ts`
|
|
152
|
+
`/packages/taro-components-library-vue3/src/vue-component-lib/utils.ts`
|
|
153
|
+
See `/LICENSE` for details of the license.
|
|
154
|
+
|
|
155
|
+
==================
|
|
156
|
+
|
|
157
|
+
MIT (stencil-vue2-output-target):
|
|
158
|
+
The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
|
|
159
|
+
`/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
|
|
160
|
+
See `/LICENSE` for details of the license.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,33 +3,35 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var shared = require('@tarojs/shared');
|
|
6
|
-
var path = require('path');
|
|
6
|
+
var path = require('node:path');
|
|
7
7
|
|
|
8
8
|
var name = "@tarojs/plugin-http";
|
|
9
9
|
|
|
10
10
|
var index = (ctx, options) => {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
ctx.modifyWebpackChain(({ chain }) => {
|
|
12
|
+
if (process.env.TARO_PLATFORM === 'mini') {
|
|
13
13
|
chain.plugin('definePlugin').tap((args) => {
|
|
14
14
|
var _a;
|
|
15
15
|
args[0].ENABLE_COOKIE = (_a = options.enableCookie) !== null && _a !== void 0 ? _a : false;
|
|
16
16
|
return args;
|
|
17
17
|
});
|
|
18
|
-
const
|
|
19
|
-
chain.resolve.alias.set(
|
|
18
|
+
const runtimeAlias = `${name}/dist/runtime`;
|
|
19
|
+
chain.resolve.alias.set(runtimeAlias, path.join(__dirname, 'runtime.js'));
|
|
20
20
|
// 注入相关全局BOM对象
|
|
21
21
|
chain.plugin('providerPlugin').tap((args) => {
|
|
22
22
|
var _a, _b;
|
|
23
23
|
var _c, _d;
|
|
24
|
-
args[0].XMLHttpRequest = [
|
|
25
|
-
((_a = options.disabledFormData) !== null && _a !== void 0 ? _a : true) && ((_c = args[0]).FormData || (_c.FormData = [
|
|
26
|
-
((_b = options.disabledBlob) !== null && _b !== void 0 ? _b : true) && ((_d = args[0]).Blob || (_d.Blob = [
|
|
24
|
+
args[0].XMLHttpRequest = [runtimeAlias, 'XMLHttpRequest'];
|
|
25
|
+
((_a = options.disabledFormData) !== null && _a !== void 0 ? _a : true) && ((_c = args[0]).FormData || (_c.FormData = [runtimeAlias, 'FormData']));
|
|
26
|
+
((_b = options.disabledBlob) !== null && _b !== void 0 ? _b : true) && ((_d = args[0]).Blob || (_d.Blob = [runtimeAlias, 'Blob']));
|
|
27
27
|
return args;
|
|
28
28
|
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
ctx.registerMethod({
|
|
32
|
+
name: 'onSetupClose',
|
|
33
|
+
fn(platform) {
|
|
34
|
+
if (process.env.TARO_PLATFORM === 'mini') {
|
|
33
35
|
const injectedPath = `post:${name}/dist/runtime`;
|
|
34
36
|
if (shared.isArray(platform.runtimePath)) {
|
|
35
37
|
platform.runtimePath.push(injectedPath);
|
|
@@ -37,9 +39,9 @@ var index = (ctx, options) => {
|
|
|
37
39
|
else if (shared.isString(platform.runtimePath)) {
|
|
38
40
|
platform.runtimePath = [platform.runtimePath, injectedPath];
|
|
39
41
|
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
exports.default = index;
|
package/dist/runtime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseUrl, Events, window, document } from '@tarojs/runtime';
|
|
2
2
|
export { document } from '@tarojs/runtime';
|
|
3
|
+
import { isString, isFunction, isWebPlatform } from '@tarojs/shared';
|
|
3
4
|
import { setStorage, getStorageSync, request } from '@tarojs/taro';
|
|
4
|
-
import { isString, isFunction } from '@tarojs/shared';
|
|
5
5
|
|
|
6
6
|
/******************************************************************************
|
|
7
7
|
Copyright (c) Microsoft Corporation.
|
|
@@ -625,7 +625,7 @@ XMLHttpRequest.HEADERS_RECEIVED = 2;
|
|
|
625
625
|
XMLHttpRequest.LOADING = 3;
|
|
626
626
|
XMLHttpRequest.DONE = 4;
|
|
627
627
|
|
|
628
|
-
if (
|
|
628
|
+
if (!isWebPlatform()) {
|
|
629
629
|
if (ENABLE_COOKIE) {
|
|
630
630
|
const _cookie = createCookieInstance();
|
|
631
631
|
Object.defineProperties(document, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/plugin-http",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.3",
|
|
4
4
|
"description": "Taro 小程序端支持使用 web 请求 的插件",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -23,17 +23,21 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/NervJS/taro#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tarojs/runtime": "3.6.
|
|
27
|
-
"@tarojs/
|
|
28
|
-
"@tarojs/
|
|
26
|
+
"@tarojs/runtime": "3.6.3",
|
|
27
|
+
"@tarojs/service": "3.6.3",
|
|
28
|
+
"@tarojs/shared": "3.6.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rollup/plugin-json": "^4.1.0",
|
|
32
32
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
33
|
+
"jest": "^29.3.1",
|
|
34
|
+
"jest-cli": "^29.3.1",
|
|
35
|
+
"jest-environment-node": "^29.5.0",
|
|
33
36
|
"rollup": "^3.8.1",
|
|
34
|
-
"
|
|
35
|
-
"rollup-plugin-node-externals": "^4.0.0",
|
|
37
|
+
"rollup-plugin-node-externals": "^5.0.0",
|
|
36
38
|
"rollup-plugin-ts": "^3.0.2",
|
|
39
|
+
"ts-jest": "^29.0.5",
|
|
40
|
+
"tslib": "^2.4.0",
|
|
37
41
|
"typescript": "^4.7.4"
|
|
38
42
|
},
|
|
39
43
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { name as packageName } from '../package.json'
|
|
|
5
5
|
|
|
6
6
|
import type { IPluginContext, TaroPlatformBase } from '@tarojs/service'
|
|
7
7
|
|
|
8
|
-
interface IOptions {
|
|
8
|
+
export interface IOptions {
|
|
9
9
|
/** 支持 document.cookie 和 http 设置 cookie (默认false) */
|
|
10
10
|
enableCookie?: boolean
|
|
11
11
|
/** 禁用掉 FormData 全局对象 (默认true禁用) */
|
|
@@ -15,38 +15,40 @@ interface IOptions {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export default (ctx: IPluginContext, options: IOptions) => {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
ctx.modifyWebpackChain(({ chain }) => {
|
|
19
|
+
if (process.env.TARO_PLATFORM === 'mini') {
|
|
20
20
|
chain.plugin('definePlugin').tap((args) => {
|
|
21
21
|
args[0].ENABLE_COOKIE = options.enableCookie ?? false
|
|
22
22
|
return args
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
chain.resolve.alias.set(
|
|
25
|
+
const runtimeAlias = `${packageName}/dist/runtime`
|
|
26
|
+
chain.resolve.alias.set(runtimeAlias, path.join(__dirname, 'runtime.js'))
|
|
27
27
|
// 注入相关全局BOM对象
|
|
28
28
|
chain.plugin('providerPlugin').tap((args) => {
|
|
29
|
-
args[0].XMLHttpRequest = [
|
|
29
|
+
args[0].XMLHttpRequest = [runtimeAlias, 'XMLHttpRequest']
|
|
30
30
|
|
|
31
31
|
// 实际上本runtime 没有实现 FormData 和 Blob 对象, 所以第三方库中的这2个对象会被替换成 undefined
|
|
32
32
|
// (axios这类请求库用到了这2个对象,所以要么实现它要么把它替换掉, 这里我们选择把它替换掉,这样可以确保除了上传以外的功能可以继续使用)
|
|
33
|
-
;(options.disabledFormData ?? true) && (args[0].FormData ||= [
|
|
34
|
-
;(options.disabledBlob ?? true) && (args[0].Blob ||= [
|
|
33
|
+
;(options.disabledFormData ?? true) && (args[0].FormData ||= [runtimeAlias, 'FormData'])
|
|
34
|
+
;(options.disabledBlob ?? true) && (args[0].Blob ||= [runtimeAlias, 'Blob'])
|
|
35
35
|
|
|
36
36
|
return args
|
|
37
37
|
})
|
|
38
|
-
}
|
|
38
|
+
}
|
|
39
|
+
})
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
ctx.registerMethod({
|
|
42
|
+
name: 'onSetupClose',
|
|
43
|
+
fn (platform: TaroPlatformBase) {
|
|
44
|
+
if (process.env.TARO_PLATFORM === 'mini') {
|
|
43
45
|
const injectedPath = `post:${packageName}/dist/runtime`
|
|
44
46
|
if (isArray(platform.runtimePath)) {
|
|
45
47
|
platform.runtimePath.push(injectedPath)
|
|
46
48
|
} else if (isString(platform.runtimePath)) {
|
|
47
49
|
platform.runtimePath = [platform.runtimePath, injectedPath]
|
|
48
50
|
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
})
|
|
52
54
|
}
|
|
@@ -221,31 +221,31 @@ export class XMLHttpRequest extends Events {
|
|
|
221
221
|
if (ENABLE_COOKIE) {
|
|
222
222
|
// 处理 set-cookie
|
|
223
223
|
const setCookieStr = header['Set-Cookie']
|
|
224
|
-
|
|
224
|
+
|
|
225
225
|
if (setCookieStr && typeof setCookieStr === 'string') {
|
|
226
226
|
let start = 0
|
|
227
227
|
let startSplit = 0
|
|
228
228
|
let nextSplit = setCookieStr.indexOf(',', startSplit)
|
|
229
229
|
const cookies: string[] = []
|
|
230
|
-
|
|
230
|
+
|
|
231
231
|
while (nextSplit >= 0) {
|
|
232
232
|
const lastSplitStr = setCookieStr.substring(start, nextSplit)
|
|
233
233
|
const splitStr = setCookieStr.substr(nextSplit)
|
|
234
|
-
|
|
234
|
+
|
|
235
235
|
// eslint-disable-next-line no-control-regex
|
|
236
236
|
if (/^,\s*([^,=;\x00-\x1F]+)=([^;\n\r\0\x00-\x1F]*).*/.test(splitStr)) {
|
|
237
237
|
// 分割成功,则上一片是完整 cookie
|
|
238
238
|
cookies.push(lastSplitStr)
|
|
239
239
|
start = nextSplit + 1
|
|
240
240
|
}
|
|
241
|
-
|
|
241
|
+
|
|
242
242
|
startSplit = nextSplit + 1
|
|
243
243
|
nextSplit = setCookieStr.indexOf(',', startSplit)
|
|
244
244
|
}
|
|
245
|
-
|
|
245
|
+
|
|
246
246
|
// 塞入最后一片 cookie
|
|
247
247
|
cookies.push(setCookieStr.substr(start))
|
|
248
|
-
|
|
248
|
+
|
|
249
249
|
cookies.forEach((cookie) => {
|
|
250
250
|
window.document.cookie = cookie
|
|
251
251
|
})
|
package/src/runtime/index.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { document, window } from '@tarojs/runtime'
|
|
2
|
+
import { isWebPlatform } from '@tarojs/shared'
|
|
2
3
|
|
|
3
4
|
import { Cookie, createCookieInstance } from './Cookie'
|
|
4
5
|
import { XMLHttpRequest } from './XMLHttpRequest'
|
|
5
6
|
|
|
6
7
|
declare const ENABLE_COOKIE: boolean
|
|
7
8
|
|
|
8
|
-
if (
|
|
9
|
-
|
|
9
|
+
if (!isWebPlatform()) {
|
|
10
10
|
if (ENABLE_COOKIE) {
|
|
11
|
-
|
|
12
11
|
const _cookie = createCookieInstance()
|
|
13
12
|
|
|
14
13
|
Object.defineProperties(document, {
|
|
@@ -32,4 +31,5 @@ if (process.env.TARO_ENV !== 'h5') {
|
|
|
32
31
|
|
|
33
32
|
window.XMLHttpRequest = XMLHttpRequest
|
|
34
33
|
}
|
|
34
|
+
|
|
35
35
|
export { Cookie, document, XMLHttpRequest }
|