Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
49d941da
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
49d941da
编写于
5月 10, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: test
上级
8f1a6a57
变更
20
显示空白变更内容
内联
并排
Showing
20 changed file
with
202 addition
and
183 deletion
+202
-183
.github/workflows/size-check.yml
.github/workflows/size-check.yml
+1
-0
package.json
package.json
+1
-1
packages/uni-api/__tests__/helpers/api.spec.ts
packages/uni-api/__tests__/helpers/api.spec.ts
+0
-7
packages/uni-api/__tests__/helpers/protocol.spec.ts
packages/uni-api/__tests__/helpers/protocol.spec.ts
+27
-33
packages/uni-api/src/helpers/protocol.ts
packages/uni-api/src/helpers/protocol.ts
+15
-5
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+8
-5
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+8
-5
packages/uni-mp-alipay/dist/uni.api.esm.js
packages/uni-mp-alipay/dist/uni.api.esm.js
+8
-5
packages/uni-mp-baidu/dist/uni.api.esm.js
packages/uni-mp-baidu/dist/uni.api.esm.js
+8
-5
packages/uni-mp-qq/dist/uni.api.esm.js
packages/uni-mp-qq/dist/uni.api.esm.js
+8
-5
packages/uni-mp-toutiao/dist/uni.api.esm.js
packages/uni-mp-toutiao/dist/uni.api.esm.js
+8
-5
packages/uni-mp-weixin/dist/uni.api.esm.js
packages/uni-mp-weixin/dist/uni.api.esm.js
+8
-5
packages/uni-quickapp-webview/dist/uni.api.esm.js
packages/uni-quickapp-webview/dist/uni.api.esm.js
+8
-5
packages/vite-plugin-uni/__tests__/easycom.spec.ts
packages/vite-plugin-uni/__tests__/easycom.spec.ts
+6
-40
packages/vite-plugin-uni/__tests__/example/pages.json
packages/vite-plugin-uni/__tests__/example/pages.json
+12
-0
packages/vite-plugin-uni/src/config/define.ts
packages/vite-plugin-uni/src/config/define.ts
+3
-3
packages/vite-plugin-uni/src/configResolved/config.ts
packages/vite-plugin-uni/src/configResolved/config.ts
+2
-5
packages/vite-plugin-uni/src/configResolved/plugins/mainJs.ts
...ages/vite-plugin-uni/src/configResolved/plugins/mainJs.ts
+2
-5
packages/vite-plugin-uni/src/utils/easycom.ts
packages/vite-plugin-uni/src/utils/easycom.ts
+45
-44
packages/vite-plugin-uni/src/utils/ssr.ts
packages/vite-plugin-uni/src/utils/ssr.ts
+24
-0
未找到文件。
.github/workflows/size-check.yml
浏览文件 @
49d941da
...
...
@@ -19,3 +19,4 @@ jobs:
github_token
:
${{ secrets.GITHUB_TOKEN }}
build_script
:
build
files
:
packages/size-check/dist/size-check.es.js packages/size-check/dist/style.css packages/uni-app/dist/uni-app.es.js packages/uni-h5-vue/dist/vue.runtime.esm.js packages/uni-mp-vue/dist/vue.runtime.esm.js packages/uni-mp-alipay/dist/uni.api.esm.js packages/uni-mp-alipay/dist/uni.mp.esm.js packages/uni-mp-baidu/dist/uni.api.esm.js packages/uni-mp-baidu/dist/uni.mp.esm.js packages/uni-mp-qq/dist/uni.api.esm.js packages/uni-mp-qq/dist/uni.mp.esm.js packages/uni-mp-toutiao/dist/uni.api.esm.js packages/uni-mp-toutiao/dist/uni.mp.esm.js packages/uni-mp-weixin/dist/uni.api.esm.js packages/uni-mp-weixin/dist/uni.mp.esm.js packages/uni-quickapp-webview/dist/uni.api.esm.js packages/uni-quickapp-webview/dist/uni.mp.esm.js
-
run
:
npm run test
package.json
浏览文件 @
49d941da
...
...
@@ -6,7 +6,7 @@
],
"scripts"
:
{
"build"
:
"node scripts/build.js"
,
"size"
:
"
size-limit
"
,
"size"
:
"
npm run build size-check
"
,
"lint"
:
"eslint packages/*/src/**/*.ts"
,
"format"
:
"prettier --write --parser typescript
\"
packages/**/*.ts?(x)
\"
"
,
"ls-lint"
:
"ls-lint"
,
...
...
packages/uni-api/__tests__/helpers/api.spec.ts
浏览文件 @
49d941da
import
{
createOnApi
}
from
'
../../src/helpers/api/index
'
import
{
normalizeErrMsg
}
from
'
../../src/helpers/api/callback
'
describe
(
'
api
'
,
()
=>
{
test
(
'
normalizeErrMsg
'
,
()
=>
{
...
...
@@ -13,10 +12,4 @@ describe('api', () => {
normalizeErrMsg
(
'
redirectTo:fail page not found
'
,
'
navigateTo
'
)
).
toEqual
(
'
navigateTo:fail page not found
'
)
})
test
(
'
createOnApi
'
,
()
=>
{
createOnApi
<
typeof
uni
.
onCompassChange
>
(
'
onCompassChange
'
,
(
callback
:
Function
)
=>
{}
)
})
})
packages/uni-api/__tests__/helpers/protocol.spec.ts
浏览文件 @
49d941da
import
{
validateProtocols
,
API_TYPE_ON_PROTOCOLS
,
}
from
'
../../src/helpers/protocol
'
import
{
validateProtocols
}
from
'
../../src/helpers/protocol
'
import
{
Upx2pxProtocol
}
from
'
../../src/protocols/base/upx2px
'
import
{
CreateCanvasContextProtocol
}
from
'
../../src/protocols/context/context
'
describe
(
'
protocol
'
,
()
=>
{
...
...
@@ -10,26 +7,14 @@ describe('protocol', () => {
})
test
(
'
validate upx2px
'
,
()
=>
{
expect
(
validateProtocols
(
'
upx2px
'
,
[
1
],
Upx2pxProtocol
)).
toBeFalsy
()
expect
(
validateProtocols
(
'
upx2px
'
,
[],
Upx2pxProtocol
)).
toEqual
({
errMsg
:
`upx2px:fail Missing required args: "upx"`
,
validateProtocols
(
'
upx2px
'
,
[],
Upx2pxProtocol
,
(
name
,
msg
)
=>
{
expect
(
name
).
toBe
(
'
upx2px
'
)
expect
(
msg
).
toBe
(
`Missing required args: "upx"`
)
})
expect
(
validateProtocols
(
'
upx2px
'
,
[
true
],
Upx2pxProtocol
)).
toEqual
({
errMsg
:
`upx2px:fail Invalid args: type check failed for args "upx". Expected Number, String, got Boolean with value true.`
,
})
})
test
(
'
validate onLocationChange
'
,
()
=>
{
expect
(
validateProtocols
(
'
onLocationChange
'
,
[()
=>
{}],
API_TYPE_ON_PROTOCOLS
)
).
toBeFalsy
()
expect
(
validateProtocols
(
'
onLocationChange
'
,
[],
API_TYPE_ON_PROTOCOLS
)
).
toEqual
({
errMsg
:
`onLocationChange:fail Missing required args: "callback"`
,
})
expect
(
validateProtocols
(
'
onLocationChange
'
,
[
1
],
API_TYPE_ON_PROTOCOLS
)
).
toEqual
({
errMsg
:
`onLocationChange:fail Invalid args: type check failed for args "callback". Expected Function, got Number with value 1.`
,
validateProtocols
(
'
upx2px
'
,
[
true
],
Upx2pxProtocol
,
(
_name
,
msg
)
=>
{
expect
(
msg
).
toBe
(
`Invalid args: type check failed for args "upx". Expected Number, String, got Boolean with value true.`
)
})
})
test
(
'
validate createCanvasContext
'
,
()
=>
{
...
...
@@ -40,15 +25,24 @@ describe('protocol', () => {
CreateCanvasContextProtocol
)
).
toBeFalsy
()
expect
(
validateProtocols
(
'
createCanvasContext
'
,
[],
CreateCanvasContextProtocol
)
).
toEqual
({
errMsg
:
`createCanvasContext:fail Missing required args: "canvasId"`
,
})
expect
(
validateProtocols
(
'
createCanvasContext
'
,
[
1
],
CreateCanvasContextProtocol
)
).
toEqual
({
errMsg
:
`createCanvasContext:fail Invalid args: type check failed for args "canvasId". Expected String with value "1", got Number with value 1.`
,
})
validateProtocols
(
'
createCanvasContext
'
,
[],
CreateCanvasContextProtocol
,
(
_name
,
msg
)
=>
{
expect
(
msg
).
toBe
(
`Missing required args: "canvasId"`
)
}
)
validateProtocols
(
'
createCanvasContext
'
,
[
1
],
CreateCanvasContextProtocol
,
(
_name
,
msg
)
=>
{
expect
(
msg
).
toBe
(
`Invalid args: type check failed for args "canvasId". Expected String with value "1", got Number with value 1.`
)
}
)
})
})
packages/uni-api/src/helpers/protocol.ts
浏览文件 @
49d941da
...
...
@@ -51,8 +51,12 @@ function validateProtocolFail(name: string, msg: string) {
function
validateProtocol
(
name
:
string
,
data
:
Record
<
string
,
any
>
,
protocol
?:
ApiProtocol
<
any
>
protocol
?:
ApiProtocol
<
any
>
,
onFail
?:
(
name
:
string
,
msg
:
string
)
=>
void
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
...
...
@@ -61,7 +65,7 @@ function validateProtocol(
!
hasOwn
(
data
,
key
)
)
if
(
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
)
on
Fail
(
name
,
errMsg
)
}
}
}
...
...
@@ -69,13 +73,19 @@ function validateProtocol(
export
function
validateProtocols
(
name
:
string
,
args
:
any
[],
protocol
?:
ApiProtocols
<
any
>
protocol
?:
ApiProtocols
<
any
>
,
onFail
?:
(
name
:
string
,
msg
:
string
)
=>
void
)
{
if
(
!
protocol
)
{
return
}
if
(
!
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
)
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
)
}
const
len
=
protocol
.
length
const
argsLen
=
args
.
length
...
...
@@ -85,7 +95,7 @@ export function validateProtocols(
if
(
argsLen
>
i
)
{
data
[
opts
.
name
!
]
=
args
[
i
]
}
validateProtocol
(
name
,
data
,
{
[
opts
.
name
!
]:
opts
})
validateProtocol
(
name
,
data
,
{
[
opts
.
name
!
]:
opts
}
,
onFail
)
}
}
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
49d941da
...
...
@@ -476,20 +476,23 @@ function elemInArray(str, arr) {
function
validateProtocolFail
(
name
,
msg
)
{
console
.
warn
(
`
${
name
}
:
${
msg
}
`
);
}
function
validateProtocol
(
name
,
data
,
protocol
)
{
function
validateProtocol
(
name
,
data
,
protocol
,
onFail
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
;
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
data
[
key
],
protocol
[
key
],
!
shared
.
hasOwn
(
data
,
key
));
if
(
shared
.
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
);
on
Fail
(
name
,
errMsg
);
}
}
}
function
validateProtocols
(
name
,
args
,
protocol
)
{
function
validateProtocols
(
name
,
args
,
protocol
,
onFail
)
{
if
(
!
protocol
)
{
return
;
}
if
(
!
shared
.
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
);
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
);
}
const
len
=
protocol
.
length
;
const
argsLen
=
args
.
length
;
...
...
@@ -499,7 +502,7 @@ function validateProtocols(name, args, protocol) {
if
(
argsLen
>
i2
)
{
data
[
opts
.
name
]
=
args
[
i2
];
}
validateProtocol
(
name
,
data
,
{[
opts
.
name
]:
opts
});
validateProtocol
(
name
,
data
,
{[
opts
.
name
]:
opts
}
,
onFail
);
}
}
function
validateProp
(
name
,
value
,
prop
,
isAbsent
)
{
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
49d941da
...
...
@@ -1270,20 +1270,23 @@ function elemsInArray(strArr, optionalVal) {
function
validateProtocolFail
(
name
,
msg
)
{
console
.
warn
(
`
${
name
}
:
${
msg
}
`
);
}
function
validateProtocol
(
name
,
data
,
protocol
)
{
function
validateProtocol
(
name
,
data
,
protocol
,
onFail
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
;
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
data
[
key
],
protocol
[
key
],
!
hasOwn
(
data
,
key
));
if
(
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
);
on
Fail
(
name
,
errMsg
);
}
}
}
function
validateProtocols
(
name
,
args
,
protocol
)
{
function
validateProtocols
(
name
,
args
,
protocol
,
onFail
)
{
if
(
!
protocol
)
{
return
;
}
if
(
!
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
);
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
);
}
const
len
=
protocol
.
length
;
const
argsLen
=
args
.
length
;
...
...
@@ -1293,7 +1296,7 @@ function validateProtocols(name, args, protocol) {
if
(
argsLen
>
i2
)
{
data
[
opts
.
name
]
=
args
[
i2
];
}
validateProtocol
(
name
,
data
,
{[
opts
.
name
]:
opts
});
validateProtocol
(
name
,
data
,
{[
opts
.
name
]:
opts
}
,
onFail
);
}
}
function
validateProp
(
name
,
value
,
prop
,
isAbsent
)
{
...
...
packages/uni-mp-alipay/dist/uni.api.esm.js
浏览文件 @
49d941da
...
...
@@ -3,20 +3,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawTy
function
validateProtocolFail
(
name
,
msg
)
{
console
.
warn
(
`
${
name
}
:
${
msg
}
`
);
}
function
validateProtocol
(
name
,
data
,
protocol
)
{
function
validateProtocol
(
name
,
data
,
protocol
,
onFail
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
;
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
data
[
key
],
protocol
[
key
],
!
hasOwn
(
data
,
key
));
if
(
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
);
on
Fail
(
name
,
errMsg
);
}
}
}
function
validateProtocols
(
name
,
args
,
protocol
)
{
function
validateProtocols
(
name
,
args
,
protocol
,
onFail
)
{
if
(
!
protocol
)
{
return
;
}
if
(
!
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
);
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
);
}
const
len
=
protocol
.
length
;
const
argsLen
=
args
.
length
;
...
...
@@ -26,7 +29,7 @@ function validateProtocols(name, args, protocol) {
if
(
argsLen
>
i
)
{
data
[
opts
.
name
]
=
args
[
i
];
}
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
});
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
}
,
onFail
);
}
}
function
validateProp
(
name
,
value
,
prop
,
isAbsent
)
{
...
...
packages/uni-mp-baidu/dist/uni.api.esm.js
浏览文件 @
49d941da
...
...
@@ -3,20 +3,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawTy
function
validateProtocolFail
(
name
,
msg
)
{
console
.
warn
(
`
${
name
}
:
${
msg
}
`
);
}
function
validateProtocol
(
name
,
data
,
protocol
)
{
function
validateProtocol
(
name
,
data
,
protocol
,
onFail
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
;
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
data
[
key
],
protocol
[
key
],
!
hasOwn
(
data
,
key
));
if
(
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
);
on
Fail
(
name
,
errMsg
);
}
}
}
function
validateProtocols
(
name
,
args
,
protocol
)
{
function
validateProtocols
(
name
,
args
,
protocol
,
onFail
)
{
if
(
!
protocol
)
{
return
;
}
if
(
!
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
);
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
);
}
const
len
=
protocol
.
length
;
const
argsLen
=
args
.
length
;
...
...
@@ -26,7 +29,7 @@ function validateProtocols(name, args, protocol) {
if
(
argsLen
>
i
)
{
data
[
opts
.
name
]
=
args
[
i
];
}
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
});
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
}
,
onFail
);
}
}
function
validateProp
(
name
,
value
,
prop
,
isAbsent
)
{
...
...
packages/uni-mp-qq/dist/uni.api.esm.js
浏览文件 @
49d941da
...
...
@@ -3,20 +3,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawTy
function
validateProtocolFail
(
name
,
msg
)
{
console
.
warn
(
`
${
name
}
:
${
msg
}
`
);
}
function
validateProtocol
(
name
,
data
,
protocol
)
{
function
validateProtocol
(
name
,
data
,
protocol
,
onFail
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
;
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
data
[
key
],
protocol
[
key
],
!
hasOwn
(
data
,
key
));
if
(
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
);
on
Fail
(
name
,
errMsg
);
}
}
}
function
validateProtocols
(
name
,
args
,
protocol
)
{
function
validateProtocols
(
name
,
args
,
protocol
,
onFail
)
{
if
(
!
protocol
)
{
return
;
}
if
(
!
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
);
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
);
}
const
len
=
protocol
.
length
;
const
argsLen
=
args
.
length
;
...
...
@@ -26,7 +29,7 @@ function validateProtocols(name, args, protocol) {
if
(
argsLen
>
i
)
{
data
[
opts
.
name
]
=
args
[
i
];
}
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
});
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
}
,
onFail
);
}
}
function
validateProp
(
name
,
value
,
prop
,
isAbsent
)
{
...
...
packages/uni-mp-toutiao/dist/uni.api.esm.js
浏览文件 @
49d941da
...
...
@@ -3,20 +3,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawTy
function
validateProtocolFail
(
name
,
msg
)
{
console
.
warn
(
`
${
name
}
:
${
msg
}
`
);
}
function
validateProtocol
(
name
,
data
,
protocol
)
{
function
validateProtocol
(
name
,
data
,
protocol
,
onFail
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
;
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
data
[
key
],
protocol
[
key
],
!
hasOwn
(
data
,
key
));
if
(
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
);
on
Fail
(
name
,
errMsg
);
}
}
}
function
validateProtocols
(
name
,
args
,
protocol
)
{
function
validateProtocols
(
name
,
args
,
protocol
,
onFail
)
{
if
(
!
protocol
)
{
return
;
}
if
(
!
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
);
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
);
}
const
len
=
protocol
.
length
;
const
argsLen
=
args
.
length
;
...
...
@@ -26,7 +29,7 @@ function validateProtocols(name, args, protocol) {
if
(
argsLen
>
i
)
{
data
[
opts
.
name
]
=
args
[
i
];
}
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
});
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
}
,
onFail
);
}
}
function
validateProp
(
name
,
value
,
prop
,
isAbsent
)
{
...
...
packages/uni-mp-weixin/dist/uni.api.esm.js
浏览文件 @
49d941da
...
...
@@ -3,20 +3,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawTy
function
validateProtocolFail
(
name
,
msg
)
{
console
.
warn
(
`
${
name
}
:
${
msg
}
`
);
}
function
validateProtocol
(
name
,
data
,
protocol
)
{
function
validateProtocol
(
name
,
data
,
protocol
,
onFail
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
;
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
data
[
key
],
protocol
[
key
],
!
hasOwn
(
data
,
key
));
if
(
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
);
on
Fail
(
name
,
errMsg
);
}
}
}
function
validateProtocols
(
name
,
args
,
protocol
)
{
function
validateProtocols
(
name
,
args
,
protocol
,
onFail
)
{
if
(
!
protocol
)
{
return
;
}
if
(
!
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
);
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
);
}
const
len
=
protocol
.
length
;
const
argsLen
=
args
.
length
;
...
...
@@ -26,7 +29,7 @@ function validateProtocols(name, args, protocol) {
if
(
argsLen
>
i
)
{
data
[
opts
.
name
]
=
args
[
i
];
}
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
});
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
}
,
onFail
);
}
}
function
validateProp
(
name
,
value
,
prop
,
isAbsent
)
{
...
...
packages/uni-quickapp-webview/dist/uni.api.esm.js
浏览文件 @
49d941da
...
...
@@ -3,20 +3,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawTy
function
validateProtocolFail
(
name
,
msg
)
{
console
.
warn
(
`
${
name
}
:
${
msg
}
`
);
}
function
validateProtocol
(
name
,
data
,
protocol
)
{
function
validateProtocol
(
name
,
data
,
protocol
,
onFail
)
{
if
(
!
onFail
)
{
onFail
=
validateProtocolFail
;
}
for
(
const
key
in
protocol
)
{
const
errMsg
=
validateProp
(
key
,
data
[
key
],
protocol
[
key
],
!
hasOwn
(
data
,
key
));
if
(
isString
(
errMsg
))
{
validateProtocol
Fail
(
name
,
errMsg
);
on
Fail
(
name
,
errMsg
);
}
}
}
function
validateProtocols
(
name
,
args
,
protocol
)
{
function
validateProtocols
(
name
,
args
,
protocol
,
onFail
)
{
if
(
!
protocol
)
{
return
;
}
if
(
!
isArray
(
protocol
))
{
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
);
return
validateProtocol
(
name
,
args
[
0
]
||
Object
.
create
(
null
),
protocol
,
onFail
);
}
const
len
=
protocol
.
length
;
const
argsLen
=
args
.
length
;
...
...
@@ -26,7 +29,7 @@ function validateProtocols(name, args, protocol) {
if
(
argsLen
>
i
)
{
data
[
opts
.
name
]
=
args
[
i
];
}
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
});
validateProtocol
(
name
,
data
,
{
[
opts
.
name
]:
opts
}
,
onFail
);
}
}
function
validateProp
(
name
,
value
,
prop
,
isAbsent
)
{
...
...
packages/vite-plugin-uni/__tests__/easycom.spec.ts
浏览文件 @
49d941da
import
path
from
'
path
'
import
{
initEasycom
,
matchEasycom
}
from
'
../src/easycom
'
import
{
initEasycom
s
,
matchEasycom
}
from
'
../src/utils
'
const
rootDir
=
path
.
resolve
(
__dirname
,
'
example
'
)
const
dirs
=
[
path
.
resolve
(
__dirname
,
'
example/components
'
),
path
.
resolve
(
__dirname
,
'
example/uni_modules/plugin/components
'
),
]
describe
(
'
easycom
'
,
()
=>
{
test
(
'
initEasycom with dirs
'
,
()
=>
{
expect
(
initEasycom
({
dirs
,
rootDir
})
).
toEqual
([
expect
(
initEasycom
s
(
rootDir
,
'
h5
'
).
easycoms
).
toEqual
([
{
pattern
:
new
RegExp
(
'
^test$
'
),
replacement
:
'
@/components/test/test.vue
'
,
...
...
@@ -23,46 +19,16 @@ describe('easycom', () => {
pattern
:
new
RegExp
(
'
^test2$
'
),
replacement
:
'
@/uni_modules/plugin/components/test2/test2.vue
'
,
},
{
pattern
:
new
RegExp
(
'
^uni-(.*)
'
),
replacement
:
'
@/components/uni-$1.vue
'
,
},
])
expect
(
matchEasycom
(
'
test
'
)).
toBe
(
'
@/components/test/test.vue
'
)
expect
(
matchEasycom
(
'
test1
'
)).
toBe
(
'
@/components/test1/test1.vue
'
)
expect
(
matchEasycom
(
'
test2
'
)).
toBe
(
'
@/uni_modules/plugin/components/test2/test2.vue
'
)
})
test
(
'
initEasycom with custom
'
,
()
=>
{
expect
(
initEasycom
({
custom
:
{
'
^uni-(.*)
'
:
'
@/components/uni-$1.vue
'
}
})
).
toEqual
([
{
pattern
:
new
RegExp
(
'
^uni-(.*)
'
),
replacement
:
'
@/components/uni-$1.vue
'
,
},
])
expect
(
matchEasycom
(
'
test
'
)).
toBe
(
false
)
expect
(
matchEasycom
(
'
uni-test1
'
)).
toBe
(
'
@/components/uni-test1.vue
'
)
})
test
(
'
initEasycom with dirs and custom
'
,
()
=>
{
expect
(
initEasycom
({
dirs
,
rootDir
,
custom
:
{
'
^test$
'
:
'
@/components/uni-test.vue
'
},
})
).
toEqual
([
{
pattern
:
new
RegExp
(
'
^test$
'
),
replacement
:
'
@/components/uni-test.vue
'
,
},
{
pattern
:
new
RegExp
(
'
^test1$
'
),
replacement
:
'
@/components/test1/test1.vue
'
,
},
{
pattern
:
new
RegExp
(
'
^test2$
'
),
replacement
:
'
@/uni_modules/plugin/components/test2/test2.vue
'
,
},
])
expect
(
matchEasycom
(
'
test
'
)).
toBe
(
'
@/components/uni-test.vue
'
)
})
})
packages/vite-plugin-uni/__tests__/example/pages.json
0 → 100644
浏览文件 @
49d941da
{
"pages"
:
[
{
"path"
:
"pages/index/index"
}
],
"easycom"
:
{
"custom"
:
{
"^uni-(.*)"
:
"@/components/uni-$1.vue"
}
}
}
packages/vite-plugin-uni/src/config/define.ts
浏览文件 @
49d941da
...
...
@@ -4,11 +4,11 @@ import {
parsePagesJsonOnce
,
parseManifestJsonOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
initFeatures
}
from
'
../utils
'
import
{
initFeatures
,
isSsr
,
isSsrManifest
}
from
'
../utils
'
export
function
createDefine
(
{
inputDir
,
platform
}:
VitePluginUniResolvedOptions
,
{
server
}
:
UserConfig
,
config
:
UserConfig
,
{
command
}:
ConfigEnv
):
UserConfig
[
'
define
'
]
{
return
initFeatures
({
...
...
@@ -17,6 +17,6 @@ export function createDefine(
platform
,
pagesJson
:
parsePagesJsonOnce
(
inputDir
,
platform
),
manifestJson
:
parseManifestJsonOnce
(
inputDir
),
ssr
:
!!
(
server
&&
server
.
middlewareMode
),
ssr
:
isSsr
(
command
,
config
)
||
isSsrManifest
(
command
,
config
),
})
}
packages/vite-plugin-uni/src/configResolved/config.ts
浏览文件 @
49d941da
import
{
ResolvedConfig
}
from
'
vite
'
import
{
rewriteSsrNativeTag
,
rewriteSsrRenderStyle
}
from
'
../utils
'
import
{
isSsr
,
rewriteSsrNativeTag
,
rewriteSsrRenderStyle
}
from
'
../utils
'
// import alias from 'module-alias'
export
function
initConfig
(
config
:
ResolvedConfig
)
{
if
(
(
config
.
command
===
'
serve
'
&&
config
.
server
.
middlewareMode
)
||
(
config
.
command
===
'
build
'
&&
config
.
build
.
ssr
)
)
{
if
(
isSsr
(
config
.
command
,
config
))
{
rewriteSsrNativeTag
()
rewriteSsrRenderStyle
(
process
.
env
.
UNI_INPUT_DIR
)
}
...
...
packages/vite-plugin-uni/src/configResolved/plugins/mainJs.ts
浏览文件 @
49d941da
...
...
@@ -2,6 +2,7 @@ import path from 'path'
import
slash
from
'
slash
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
VitePluginUniResolvedOptions
}
from
'
../..
'
import
{
isSsr
,
isSsrManifest
}
from
'
../../utils
'
export
function
uniMainJsPlugin
(
config
:
ResolvedConfig
,
...
...
@@ -12,11 +13,7 @@ export function uniMainJsPlugin(
const
mainTsPath
=
mainPath
+
'
.ts
'
const
pagesJsonJsPath
=
slash
(
path
.
resolve
(
options
.
inputDir
,
'
pages.json.js
'
))
const
isSSR
=
config
.
command
===
'
serve
'
?
!!
config
.
server
.
middlewareMode
:
config
.
command
===
'
build
'
?
!!
(
config
.
build
.
ssr
||
config
.
build
.
ssrManifest
)
:
false
isSsr
(
config
.
command
,
config
)
||
isSsrManifest
(
config
.
command
,
config
)
return
{
name
:
'
vite:uni-main-js
'
,
transform
(
code
,
id
,
ssr
)
{
...
...
packages/vite-plugin-uni/src/utils/easycom.ts
浏览文件 @
49d941da
...
...
@@ -38,8 +38,7 @@ function clearEasycom() {
easycomsInvalidCache
.
clear
()
}
export
const
initEasycomsOnce
=
once
(
(
inputDir
:
string
,
platform
:
UniApp
.
PLATFORM
)
=>
{
export
function
initEasycoms
(
inputDir
:
string
,
platform
:
UniApp
.
PLATFORM
)
{
const
buildInComponentsDir
=
path
.
resolve
(
require
.
resolve
(
'
@dcloudio/uni-components
'
),
'
../lib
'
...
...
@@ -80,10 +79,12 @@ export const initEasycomsOnce = once(
res
.
options
=
initEasycomOptions
()
initEasycom
(
res
.
options
)
},
easycoms
,
}
return
res
}
)
}
export
const
initEasycomsOnce
=
once
(
initEasycoms
)
function
initUniModulesEasycomDirs
(
uniModulesDir
:
string
)
{
if
(
!
fs
.
existsSync
(
uniModulesDir
))
{
...
...
packages/vite-plugin-uni/src/utils/ssr.ts
浏览文件 @
49d941da
...
...
@@ -7,6 +7,30 @@ import {
Rpx2UnitOptions
,
}
from
'
@dcloudio/uni-shared
'
import
{
parseRpx2UnitOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
ConfigEnv
,
ResolvedConfig
,
UserConfig
}
from
'
vite
'
export
function
isSsr
(
command
:
ConfigEnv
[
'
command
'
],
config
:
UserConfig
|
ResolvedConfig
)
{
if
(
command
===
'
serve
'
)
{
return
!!
(
config
.
server
&&
config
.
server
.
middlewareMode
)
}
if
(
command
===
'
build
'
)
{
return
!!
(
config
.
build
&&
config
.
build
.
ssr
)
}
return
false
}
export
function
isSsrManifest
(
command
:
ConfigEnv
[
'
command
'
],
config
:
UserConfig
|
ResolvedConfig
)
{
if
(
command
===
'
build
'
)
{
return
!!
(
config
.
build
&&
config
.
build
.
ssrManifest
)
}
return
false
}
function
serializeDefine
(
define
:
Record
<
string
,
any
>
):
string
{
let
res
=
`{`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录