Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
c0c7c5d0
U
uni-app
项目概览
DCloud
/
uni-app
14 天 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c0c7c5d0
编写于
7月 20, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
faa3de6f
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
177 addition
and
5 deletion
+177
-5
jest.config.js
jest.config.js
+5
-0
packages/uni-uts-vite/__tests__/module.spec.ts
packages/uni-uts-vite/__tests__/module.spec.ts
+42
-0
packages/uni-uts-vite/build.json
packages/uni-uts-vite/build.json
+11
-0
packages/uni-uts-vite/lib/module.js
packages/uni-uts-vite/lib/module.js
+42
-0
packages/uni-uts-vite/module.ts
packages/uni-uts-vite/module.ts
+50
-0
packages/uni-uts-vite/src/plugins/uts.ts
packages/uni-uts-vite/src/plugins/uts.ts
+2
-2
packages/uts/src/api.ts
packages/uts/src/api.ts
+7
-1
packages/uts/src/index.ts
packages/uts/src/index.ts
+2
-0
rollup.config.js
rollup.config.js
+1
-0
scripts/build.js
scripts/build.js
+1
-1
scripts/test.js
scripts/test.js
+14
-1
未找到文件。
jest.config.js
浏览文件 @
c0c7c5d0
...
...
@@ -10,6 +10,11 @@ module.exports = {
__GLOBAL__
:
false
,
__VUE_OPTIONS_API__
:
true
,
__VUE_PROD_DEVTOOLS__
:
false
,
uni
:
{
requireNativePlugin
(
name
)
{
return
{}
},
},
},
coverageDirectory
:
'
coverage
'
,
coverageReporters
:
[
'
html
'
,
'
lcov
'
,
'
text
'
],
...
...
packages/uni-uts-vite/__tests__/module.spec.ts
0 → 100644
浏览文件 @
c0c7c5d0
import
{
normalizeArg
}
from
'
../module
'
describe
(
'
uts-module
'
,
()
=>
{
test
(
'
normalize args
'
,
()
=>
{
expect
(
normalizeArg
(
1
)).
toBe
(
1
)
expect
(
normalizeArg
(
'
hello
'
)).
toBe
(
'
hello
'
)
expect
(
normalizeArg
(
true
)).
toBe
(
true
)
expect
(
normalizeArg
({
callback
:
()
=>
{}
})).
toEqual
({
callback
:
{
$
$type
:
'
function
'
,
value
:
1
},
})
expect
(
normalizeArg
({
success
:
()
=>
{},
fail
:
()
=>
{},
complete
:
()
=>
{}
})
).
toEqual
({
success
:
{
$
$type
:
'
function
'
,
value
:
2
},
fail
:
{
$
$type
:
'
function
'
,
value
:
3
},
complete
:
{
$
$type
:
'
function
'
,
value
:
4
},
})
expect
(
normalizeArg
({
user
:
{
name
:
'
test
'
,
age
:
10
,
callback
()
{},
},
success
()
{},
})
).
toEqual
({
user
:
{
name
:
'
test
'
,
age
:
10
,
callback
:
{
$
$type
:
'
function
'
,
value
:
5
,
},
},
success
:
{
$
$type
:
'
function
'
,
value
:
6
,
},
})
})
})
packages/uni-uts-vite/build.json
0 → 100644
浏览文件 @
c0c7c5d0
[
{
"input"
:
{
"module.ts"
:
"lib/module.js"
},
"treeshake"
:
false
,
"compilerOptions"
:
{
"module"
:
"ESNext"
}
}
]
packages/uni-uts-vite/lib/module.js
0 → 100644
浏览文件 @
c0c7c5d0
// @ts-expect-error
const
proxy
=
uni
.
requireNativePlugin
(
'
proxy-module
'
)
// @ts-expect-error
const
moduleName
=
__MODULE_NAME__
// @ts-expect-error
const
moduleDefine
=
__MODULE_DEFINE__
var
module
=
initModule
(
moduleDefine
)
let
callbackId
=
0
const
objectToString
=
Object
.
prototype
.
toString
const
toTypeString
=
(
value
)
=>
objectToString
.
call
(
value
)
const
isPlainObject
=
(
val
)
=>
toTypeString
(
val
)
===
'
[object Object]
'
function
normalizeArg
(
arg
)
{
if
(
typeof
arg
===
'
function
'
)
{
return
{
type
:
'
function
'
,
value
:
callbackId
++
,
}
}
else
if
(
isPlainObject
(
arg
))
{
Object
.
keys
(
arg
).
forEach
((
name
)
=>
{
arg
[
name
]
=
normalizeArg
(
arg
[
name
])
})
}
return
arg
}
function
moduleGetter
(
module
,
method
)
{
return
(...
args
)
=>
{
const
params
=
args
.
map
((
arg
)
=>
normalizeArg
(
arg
))
proxy
.
invoke
({
module
,
method
,
params
},
()
=>
{})
}
}
function
initModule
(
moduleDefine
)
{
const
moduleProxy
=
{}
for
(
const
methodName
in
moduleDefine
)
{
Object
.
defineProperty
(
moduleProxy
,
methodName
,
{
enumerable
:
true
,
configurable
:
true
,
get
:
()
=>
moduleGetter
(
moduleName
,
methodName
),
})
}
}
export
{
module
as
default
,
normalizeArg
}
packages/uni-uts-vite/module.ts
0 → 100644
浏览文件 @
c0c7c5d0
declare
const
uni
:
{
requireNativePlugin
(
name
:
string
):
{
invoke
:
Function
}
}
const
moduleName
=
'
__MODULE_NAME__
'
const
moduleDefine
=
'
__MODULE_DEFINE__
'
export
default
initModule
(
moduleDefine
as
unknown
as
Record
<
string
,
boolean
>
)
let
callbackId
=
1
const
objectToString
=
Object
.
prototype
.
toString
const
toTypeString
=
(
value
:
unknown
):
string
=>
objectToString
.
call
(
value
)
const
isPlainObject
=
(
val
:
unknown
):
val
is
object
=>
toTypeString
(
val
)
===
'
[object Object]
'
export
function
normalizeArg
(
arg
:
unknown
)
{
if
(
typeof
arg
===
'
function
'
)
{
return
{
$
$type
:
'
function
'
,
value
:
callbackId
++
,
}
}
else
if
(
isPlainObject
(
arg
))
{
Object
.
keys
(
arg
).
forEach
((
name
)
=>
{
;(
arg
as
any
)[
name
]
=
normalizeArg
((
arg
as
any
)[
name
])
})
}
return
arg
}
function
moduleGetter
(
proxy
:
any
,
module
:
string
,
method
:
string
)
{
return
(...
args
:
unknown
[])
=>
{
const
params
=
args
.
map
((
arg
)
=>
normalizeArg
(
arg
))
proxy
.
invoke
({
module
,
method
,
params
},
()
=>
{})
}
}
function
initModule
(
moduleDefine
:
Record
<
string
,
unknown
>
)
{
const
proxy
=
uni
.
requireNativePlugin
(
'
proxy-module
'
)
const
moduleProxy
=
{}
for
(
const
methodName
in
moduleDefine
)
{
Object
.
defineProperty
(
moduleProxy
,
methodName
,
{
enumerable
:
true
,
configurable
:
true
,
get
:
()
=>
moduleGetter
(
proxy
,
moduleName
,
methodName
),
})
}
}
packages/uni-uts-vite/src/plugins/uts.ts
浏览文件 @
c0c7c5d0
...
...
@@ -25,8 +25,8 @@ export function uniUtsPlugin(): Plugin {
if
(
pkg
.
uni_modules
?.
type
!==
'
uts
'
)
{
return
}
//
TODO 根据平台加载
return
path
.
join
(
id
,
'
app-android/index
.uts
'
)
//
加载接口类
return
path
.
join
(
id
,
pkg
.
main
||
'
interface
.uts
'
)
},
transform
(
code
,
id
,
opts
)
{
if
(
opts
&&
opts
.
ssr
)
{
...
...
packages/uts/src/api.ts
浏览文件 @
c0c7c5d0
import
{
resolve
}
from
'
path
'
import
type
{
UtsOptions
,
UtsResult
}
from
'
./types
'
import
type
{
UtsOptions
,
Uts
ParseOptions
,
Uts
Result
}
from
'
./types
'
import
{
normalizePath
}
from
'
./utils
'
const
bindingsOverride
=
process
.
env
[
'
UTS_BINARY_PATH
'
]
...
...
@@ -36,6 +36,12 @@ function resolveOptions(options: UtsOptions) {
return
options
}
export
function
parse
(
source
:
string
,
options
:
UtsParseOptions
=
{})
{
return
bindings
.
parse
(
source
,
toBuffer
(
options
))
.
then
((
res
:
string
)
=>
JSON
.
parse
(
res
))
}
export
function
toKotlin
(
options
:
UtsOptions
):
Promise
<
UtsResult
>
{
const
kotlinOptions
=
resolveOptions
(
options
)
if
(
!
kotlinOptions
)
{
...
...
packages/uts/src/index.ts
浏览文件 @
c0c7c5d0
...
...
@@ -343,6 +343,8 @@ function buildFile(
})
}
export
{
parse
}
from
'
./api
'
export
function
runDev
(
target
:
UtsTarget
,
opts
:
ToOptions
)
{
opts
=
parseOptions
(
'
dev
'
,
target
,
opts
)
!
opts
.
silent
&&
printStartup
(
target
,
'
development
'
)
...
...
rollup.config.js
浏览文件 @
c0c7c5d0
...
...
@@ -90,6 +90,7 @@ function createConfig(entryFile, output, buildOption) {
declaration
:
shouldEmitDeclarations
,
declarationMap
:
false
,
skipLibCheck
:
true
,
...(
buildOption
.
compilerOptions
||
{}),
},
exclude
:
[
'
**/__tests__
'
,
'
test-dts
'
],
},
...
...
scripts/build.js
浏览文件 @
c0c7c5d0
...
...
@@ -166,7 +166,7 @@ async function build(target) {
],
{
stdio
:
'
inherit
'
}
)
if
(
types
)
{
if
(
types
&&
target
!==
'
uni-uts-vite
'
)
{
await
extract
(
target
)
}
}
...
...
scripts/test.js
浏览文件 @
c0c7c5d0
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
{
runBuild
,
UtsTarget
}
=
require
(
'
../packages/uts/dist
'
)
const
{
parse
,
runBuild
,
UtsTarget
}
=
require
(
'
../packages/uts/dist
'
)
const
projectDir
=
path
.
resolve
(
__dirname
,
'
../packages/playground/uts
'
)
const
start
=
Date
.
now
()
parse
(
fs
.
readFileSync
(
path
.
resolve
(
projectDir
,
'
uni_modules/test-uniplugin/interface.uts
'
),
'
utf8
'
)
).
then
((
res
)
=>
{
console
.
log
(
'
parse:
'
+
(
Date
.
now
()
-
start
)
+
'
ms
'
)
console
.
log
(
JSON
.
stringify
(
res
))
})
// uts
runBuild
(
UtsTarget
.
KOTLIN
,
{
silent
:
false
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录