Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
6c7955c8
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,发现更多精彩内容 >>
提交
6c7955c8
编写于
7月 21, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
e302f53b
变更
12
展开全部
显示空白变更内容
内联
并排
Showing
12 changed file
with
2213 addition
and
65 deletion
+2213
-65
packages/uni-app-plus/package.json
packages/uni-app-plus/package.json
+2
-1
packages/uni-uts-vite/__tests__/module.spec.ts
packages/uni-uts-vite/__tests__/module.spec.ts
+6
-12
packages/uni-uts-vite/dist/index.d.ts
packages/uni-uts-vite/dist/index.d.ts
+1
-1
packages/uni-uts-vite/dist/index.js
packages/uni-uts-vite/dist/index.js
+2
-1
packages/uni-uts-vite/lib/module.js
packages/uni-uts-vite/lib/module.js
+1
-4
packages/uni-uts-vite/module.ts
packages/uni-uts-vite/module.ts
+1
-4
packages/uni-uts-vite/package.json
packages/uni-uts-vite/package.json
+2
-1
packages/uni-uts-vite/src/index.ts
packages/uni-uts-vite/src/index.ts
+3
-1
packages/uni-uts-vite/src/plugins/uts.ts
packages/uni-uts-vite/src/plugins/uts.ts
+0
-40
packages/uni-uts-vite/src/plugins/v1.ts
packages/uni-uts-vite/src/plugins/v1.ts
+92
-0
packages/uni-uts-vite/types/types.d.ts
packages/uni-uts-vite/types/types.d.ts
+2101
-0
pnpm-lock.yaml
pnpm-lock.yaml
+2
-0
未找到文件。
packages/uni-app-plus/package.json
浏览文件 @
6c7955c8
...
...
@@ -42,6 +42,7 @@
},
"dependencies"
:
{
"@dcloudio/uni-app-vite"
:
"3.0.0-alpha-3050220220719003"
,
"@dcloudio/uni-app-vue"
:
"3.0.0-alpha-3050220220719003"
"@dcloudio/uni-app-vue"
:
"3.0.0-alpha-3050220220719003"
,
"@dcloudio/uni-uts-vite"
:
"3.0.0-alpha-3050220220719003"
}
}
packages/uni-uts-vite/__tests__/module.spec.ts
浏览文件 @
6c7955c8
...
...
@@ -6,14 +6,14 @@ describe('uts-module', () => {
expect
(
normalizeArg
(
'
hello
'
)).
toBe
(
'
hello
'
)
expect
(
normalizeArg
(
true
)).
toBe
(
true
)
expect
(
normalizeArg
({
callback
:
()
=>
{}
})).
toEqual
({
callback
:
{
$
$type
:
'
function
'
,
value
:
1
}
,
callback
:
1
,
})
expect
(
normalizeArg
({
success
:
()
=>
{},
fail
:
()
=>
{},
complete
:
()
=>
{}
})
).
toEqual
({
success
:
{
$
$type
:
'
function
'
,
value
:
2
}
,
fail
:
{
$
$type
:
'
function
'
,
value
:
3
}
,
complete
:
{
$
$type
:
'
function
'
,
value
:
4
}
,
success
:
2
,
fail
:
3
,
complete
:
4
,
})
expect
(
normalizeArg
({
...
...
@@ -28,15 +28,9 @@ describe('uts-module', () => {
user
:
{
name
:
'
test
'
,
age
:
10
,
callback
:
{
$
$type
:
'
function
'
,
value
:
5
,
},
},
success
:
{
$
$type
:
'
function
'
,
value
:
6
,
callback
:
5
,
},
success
:
6
,
})
})
})
packages/uni-uts-vite/dist/index.d.ts
浏览文件 @
6c7955c8
declare
const
_default
:
never
[];
declare
const
_default
:
import
(
"
vite
"
).
Plugin
[];
export
default
_default
;
packages/uni-uts-vite/dist/index.js
浏览文件 @
6c7955c8
"
use strict
"
;
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
default
=
[];
const
v1_1
=
require
(
"
./plugins/v1
"
);
exports
.
default
=
[(
0
,
v1_1
.
uniUtsV1Plugin
)()];
packages/uni-uts-vite/lib/module.js
浏览文件 @
6c7955c8
...
...
@@ -10,10 +10,7 @@ function normalizeArg(arg) {
if
(
typeof
arg
===
'
function
'
)
{
const
id
=
callbackId
++
callbacks
[
id
]
=
arg
return
{
$
$type
:
'
function
'
,
value
:
id
,
}
return
id
}
else
if
(
isPlainObject
(
arg
))
{
Object
.
keys
(
arg
).
forEach
((
name
)
=>
{
arg
[
name
]
=
normalizeArg
(
arg
[
name
])
...
...
packages/uni-uts-vite/module.ts
浏览文件 @
6c7955c8
...
...
@@ -28,10 +28,7 @@ export function normalizeArg(arg: unknown) {
if
(
typeof
arg
===
'
function
'
)
{
const
id
=
callbackId
++
callbacks
[
id
]
=
arg
return
{
$
$type
:
'
function
'
,
value
:
id
,
}
return
id
}
else
if
(
isPlainObject
(
arg
))
{
Object
.
keys
(
arg
).
forEach
((
name
)
=>
{
;(
arg
as
any
)[
name
]
=
normalizeArg
((
arg
as
any
)[
name
])
...
...
packages/uni-uts-vite/package.json
浏览文件 @
6c7955c8
...
...
@@ -26,6 +26,7 @@
"main"
:
"dist/index.js"
},
"dependencies"
:
{
"@dcloudio/uni-cli-shared"
:
"3.0.0-alpha-3050220220719003"
"@dcloudio/uni-cli-shared"
:
"3.0.0-alpha-3050220220719003"
,
"@dcloudio/uts"
:
"3.0.0-alpha-3050220220719003"
}
}
packages/uni-uts-vite/src/index.ts
浏览文件 @
6c7955c8
export
default
[]
import
{
uniUtsV1Plugin
}
from
'
./plugins/v1
'
export
default
[
uniUtsV1Plugin
()]
packages/uni-uts-vite/src/plugins/uts.ts
已删除
100644 → 0
浏览文件 @
e302f53b
import
type
{
Plugin
}
from
'
vite
'
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
parseJson
}
from
'
@dcloudio/uni-cli-shared
'
// 需要区分 android,iOS
export
function
uniUtsPlugin
():
Plugin
{
// TODO 1.0 版本,解析到 uts module 时,动态编译 uts ?
return
{
name
:
'
uts
'
,
apply
:
'
build
'
,
enforce
:
'
pre
'
,
load
(
id
,
opts
)
{
if
(
opts
&&
opts
.
ssr
)
{
return
id
}
if
(
!
id
.
includes
(
'
uni_modules
'
))
{
return
}
const
pkgPath
=
path
.
join
(
id
,
'
package.json
'
)
if
(
!
fs
.
existsSync
(
pkgPath
))
{
return
}
const
pkg
=
parseJson
(
fs
.
readFileSync
(
pkgPath
,
'
utf-8
'
))
if
(
pkg
.
uni_modules
?.
type
!==
'
uts
'
)
{
return
}
// 加载接口类
return
path
.
join
(
id
,
pkg
.
main
||
'
interface.uts
'
)
},
transform
(
code
,
id
,
opts
)
{
if
(
opts
&&
opts
.
ssr
)
{
return
}
if
(
path
.
extname
(
id
.
split
(
'
?
'
)[
0
])
!==
'
.uts
'
)
{
return
}
},
}
}
packages/uni-uts-vite/src/plugins/v1.ts
0 → 100644
浏览文件 @
6c7955c8
import
type
{
Plugin
}
from
'
vite
'
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
parseJson
,
parseVueRequest
}
from
'
@dcloudio/uni-cli-shared
'
import
{
ExportDefaultDeclaration
,
Module
,
TsTypeAnnotation
,
}
from
'
../../types/types
'
// 需要区分 android,iOS
export
function
uniUtsV1Plugin
():
Plugin
{
// TODO 1.0 版本,解析到 uts module 时,动态编译 uts ?
let
moduleCode
:
string
return
{
name
:
'
uni:uts-v1
'
,
apply
:
'
build
'
,
enforce
:
'
pre
'
,
resolveId
(
id
)
{
if
(
!
id
.
includes
(
'
uni_modules
'
))
{
return
}
const
pkgPath
=
path
.
join
(
id
,
'
package.json
'
)
if
(
!
fs
.
existsSync
(
pkgPath
))
{
return
}
const
pkg
=
parseJson
(
fs
.
readFileSync
(
pkgPath
,
'
utf-8
'
))
if
(
pkg
.
uni_modules
?.
type
!==
'
uts
'
)
{
return
}
return
(
path
.
join
(
id
,
pkg
.
main
||
'
interface.uts
'
)
+
'
?module=
'
+
path
.
basename
(
path
.
dirname
(
pkgPath
))
)
},
transform
(
code
,
id
,
opts
)
{
if
(
opts
&&
opts
.
ssr
)
{
return
}
const
{
filename
,
query
}
=
parseVueRequest
(
id
)
if
(
path
.
extname
(
filename
)
!==
'
.uts
'
)
{
return
}
const
moduleName
=
(
query
as
any
).
module
as
string
if
(
!
moduleName
)
{
return
}
// 懒加载 uts
// eslint-disable-next-line no-restricted-globals
const
{
parse
}
=
require
(
'
@dcloudio/uts
'
)
const
ast
=
parse
(
code
)
if
(
!
moduleCode
)
{
moduleCode
=
fs
.
readFileSync
(
path
.
resolve
(
__dirname
,
'
../../lib/module.js
'
),
'
utf8
'
)
}
return
moduleCode
.
replace
(
`__MODULE_NAME__`
,
moduleName
)
.
replace
(
`'__MODULE_DEFINE__'`
,
JSON
.
stringify
(
parseModuleDefines
(
ast
)))
},
}
}
function
parseModuleDefines
(
ast
:
Module
)
{
const
module
:
Record
<
string
,
{
async
:
boolean
}
>
=
{}
const
defaultDecl
=
ast
.
body
.
find
(
(
item
)
=>
item
.
type
===
'
ExportDefaultDeclaration
'
)
as
ExportDefaultDeclaration
if
(
!
defaultDecl
||
defaultDecl
.
decl
.
type
!==
'
TsInterfaceDeclaration
'
)
{
return
'
only support `export default interface Module {}`
'
}
const
body
=
defaultDecl
.
decl
.
body
.
body
body
.
forEach
((
item
)
=>
{
if
(
item
.
type
!==
'
TsMethodSignature
'
||
item
.
key
.
type
!==
'
Identifier
'
)
{
return
}
const
methodName
=
item
.
key
.
value
module
[
methodName
]
=
{
async
:
item
.
typeAnn
?
isReturnPromise
(
item
.
typeAnn
)
:
false
,
}
})
return
module
}
function
isReturnPromise
({
typeAnnotation
}:
TsTypeAnnotation
)
{
return
(
typeAnnotation
.
type
===
'
TsTypeReference
'
&&
typeAnnotation
.
typeName
.
type
===
'
Identifier
'
&&
typeAnnotation
.
typeName
.
value
===
'
Promise
'
)
}
packages/uni-uts-vite/types/types.d.ts
0 → 100644
浏览文件 @
6c7955c8
此差异已折叠。
点击以展开。
pnpm-lock.yaml
浏览文件 @
6c7955c8
...
...
@@ -190,6 +190,7 @@ importers:
'
@dcloudio/uni-h5'
:
3.0.0-alpha-3050220220719003
'
@dcloudio/uni-i18n'
:
3.0.0-alpha-3050220220719003
'
@dcloudio/uni-shared'
:
3.0.0-alpha-3050220220719003
'
@dcloudio/uni-uts-vite'
:
3.0.0-alpha-3050220220719003
'
@types/pako'
:
1.0.2
'
@vue/compiler-sfc'
:
3.2.37
autoprefixer
:
^10.4.7
...
...
@@ -199,6 +200,7 @@ importers:
dependencies
:
'
@dcloudio/uni-app-vite'
:
link:../uni-app-vite
'
@dcloudio/uni-app-vue'
:
link:../uni-app-vue
'
@dcloudio/uni-uts-vite'
:
link:../uni-uts-vite
devDependencies
:
'
@dcloudio/uni-cli-shared'
:
link:../uni-cli-shared
'
@dcloudio/uni-components'
:
link:../uni-components
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录