Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
0a12503f
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
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看板
提交
0a12503f
编写于
6月 03, 2024
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(harmony): build ext api with ets format
上级
c10eaad2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
131 addition
and
41 deletion
+131
-41
packages/uni-app-harmony/build.ets.json
packages/uni-app-harmony/build.ets.json
+16
-23
packages/uni-app-harmony/src/service/api/index.ts
packages/uni-app-harmony/src/service/api/index.ts
+7
-7
packages/uni-app-harmony/vite.config.ts
packages/uni-app-harmony/vite.config.ts
+11
-5
packages/uni-cli-shared/src/uni_modules.ts
packages/uni-cli-shared/src/uni_modules.ts
+7
-3
packages/uni-runtime/src/helpers/api/index.ts
packages/uni-runtime/src/helpers/api/index.ts
+81
-0
packages/uni-runtime/src/index.ts
packages/uni-runtime/src/index.ts
+9
-3
未找到文件。
packages/uni-app-harmony/build.ets.json
浏览文件 @
0a12503f
...
...
@@ -22,32 +22,25 @@
"__APP_VIEW__"
:
"false"
,
"__NODE_JS__"
:
"false"
},
"banner"
:
"import { IUniError, UTSObject,
UTSJSONObject, string } from './uts'
\n
import { defineAsyncApi } from './uni.api'
"
,
"banner"
:
"import { IUniError, UTSObject,
string } from './uts'
\n
import { UniError, UTSJSONObject } from './uni-app-harmony-framework-dev.js'
\n
import { defineAsyncApi, ApiExcutor, ProtocolOptions, ApiOptions, ErrRes } from './uni-api-shared'
\n
"
,
"wrapper"
:
{
"name"
:
"initUniExtApi"
,
"args"
:
[[
"APP_ID"
,
"string"
]]
}
},
{
"input"
:
{
"../uni-runtime/src/helpers/api/index.ts"
:
"uni-api-shared.ets"
},
"alias"
:
{
"@dcloudio/uni-runtime"
:
"./uni-app-harmony-framework-dev.js"
},
"externals"
:
[
"./uni-app-harmony-framework-dev.js"
],
"replacements"
:
{
"__PLATFORM__"
:
"'app-harmony'"
,
"__DEV__"
:
"false"
,
"__X__"
:
"true"
,
"__APP_VIEW__"
:
"false"
,
"__NODE_JS__"
:
"false"
}
}
//
{
//
"input"
:
{
//
"src/service/index.ts"
:
"uni.runtime.ts"
//
},
//
"alias"
:
{
//
"@vue/shared"
:
"<rootDir>/packages/uni-app-harmony/src/shared"
,
//
"@dcloudio/uni-api"
:
"<rootDir>/packages/uni-api/src"
,
//
"@dcloudio/uni-app-plus"
:
"<rootDir>/packages/uni-app-plus/src"
,
//
"@dcloudio/uni-components"
:
"<rootDir>/packages/uni-components/src"
,
//
"@dcloudio/uni-core"
:
"<rootDir>/packages/uni-core/src"
,
//
"@dcloudio/uni-i18n"
:
"<rootDir>/packages/uni-i18n/src"
,
//
"@dcloudio/uni-platform"
:
"<rootDir>/packages/uni-app-harmony/src/platform"
,
//
"@dcloudio/uni-shared"
:
"<rootDir>/packages/uni-shared/src"
//
},
//
"replacements"
:
{
//
"__PLATFORM__"
:
"'app-harmony'"
,
//
"__DEV__"
:
"false"
,
//
"__X__"
:
"true"
,
//
"__APP_VIEW__"
:
"false"
,
//
"__NODE_JS__"
:
"false"
//
}
//
}
]
packages/uni-app-harmony/src/service/api/index.ts
浏览文件 @
0a12503f
export
*
from
'
./media/chooseImage
'
export
*
from
'
./media/chooseVideo
'
export
*
from
'
./media/getImageInfo
'
export
*
from
'
./media/getVideoInfo
'
export
*
from
'
./network/request
'
export
*
from
'
./network/uploadFile
'
export
*
from
'
./network/downloadFile
'
//
export * from './media/chooseImage'
//
export * from './media/chooseVideo'
//
export * from './media/getImageInfo'
//
export * from './media/getVideoInfo'
//
export * from './network/request'
//
export * from './network/uploadFile'
//
export * from './network/downloadFile'
export
*
from
'
./ui/index
'
export
*
from
'
./device/index
'
export
{
navigateTo
}
from
'
./route/navigateTo
'
...
...
packages/uni-app-harmony/vite.config.ts
浏览文件 @
0a12503f
...
...
@@ -178,7 +178,7 @@ export default defineConfig({
function
parseExtApiInjects
(
uniModulesDir
:
string
)
{
return
parseInjects
(
true
,
'
app
'
,
'
app
-harmony
'
,
'
arkts
'
,
// javascript|kotlin|swift (不传入)
''
,
uniModulesDir
,
...
...
@@ -214,20 +214,26 @@ function initArkTSExtApi() {
if
(
Object
.
keys
(
injects
).
length
===
0
)
{
continue
}
const
specifiers
:
string
[]
=
[]
const
apiSpecifiers
:
string
[]
=
[]
const
apiTypeSpecifiers
:
string
[]
=
[]
Object
.
keys
(
injects
).
forEach
((
key
)
=>
{
const
api
=
injects
[
key
][
1
]
const
apiType
=
capitalize
(
api
)
s
pecifiers
.
push
(
api
)
s
pecifiers
.
push
(
apiType
)
apiS
pecifiers
.
push
(
api
)
apiTypeS
pecifiers
.
push
(
apiType
)
defineExtApis
.
push
(
api
)
uniExtApis
.
push
(
`
${
api
}
:
${
apiType
}
`
)
})
importExtApis
.
push
(
`import {
${
s
pecifiers
.
join
(
`import {
${
apiS
pecifiers
.
join
(
'
,
'
)}
} from './
${
extApi
}
/utssdk/app-harmony/index.uts'`
)
importExtApis
.
push
(
`import {
${
apiTypeSpecifiers
.
join
(
'
,
'
)}
} from './
${
extApi
}
/utssdk/interface.uts'`
)
exportExtApis
.
push
(
`export * from './
${
extApi
}
/utssdk/app-harmony/index.uts'`
)
...
...
packages/uni-cli-shared/src/uni_modules.ts
浏览文件 @
0a12503f
...
...
@@ -189,14 +189,16 @@ export function parseInjects(
fs
.
existsSync
(
path
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
'
app-android
'
)
)
||
fs
.
existsSync
(
path
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
'
app-ios
'
))
fs
.
existsSync
(
path
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
'
app-ios
'
))
||
fs
.
existsSync
(
path
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
'
app-harmony
'
))
}
}
// 其他平台修改source,直接指向目标文件,否则 uts2js 找不到类型信息
if
(
platform
!==
'
app
'
&&
platform
!==
'
app-android
'
&&
platform
!==
'
app-ios
'
platform
!==
'
app-ios
'
&&
platform
!==
'
app-harmony
'
)
{
if
(
fs
.
existsSync
(
platformIndexFileName
))
{
source
=
`
${
source
}
/utssdk/
${
platform
}
/index.uts`
...
...
@@ -264,7 +266,9 @@ function parseInject(
}
else
{
const
defineOptions
=
define
[
d
]
as
DefineOptions
const
p
=
platform
===
'
app-android
'
||
platform
===
'
app-ios
'
platform
===
'
app-android
'
||
platform
===
'
app-ios
'
||
platform
===
'
app-harmony
'
?
'
app
'
:
platform
if
(
!
(
p
in
defineOptions
))
{
...
...
packages/uni-runtime/src/helpers/api/index.ts
0 → 100644
浏览文件 @
0a12503f
import
{
defineAsyncApi
as
originalDefineAsyncApi
,
// defineOffApi as originalDefineOffApi,
// defineOnApi as originalDefineOnApi,
// defineSyncApi as originalDefineSyncApi,
// defineTaskApi as originalDefineTaskApi,
}
from
'
@dcloudio/uni-runtime
'
type
Anything
=
Object
|
null
|
undefined
type
NullType
=
null
|
undefined
export
interface
ErrRes
{
errMsg
?:
string
|
null
errCode
?:
number
|
null
}
export
interface
ApiExcutor
<
K
>
{
resolve
:
(
res
:
K
|
void
)
=>
void
reject
:
(
errMsg
?:
string
,
errRes
?:
ErrRes
)
=>
void
}
export
interface
ProtocolOptions
{
name
?:
string
|
null
type
?:
string
|
null
required
?:
boolean
|
null
validator
?:
(
value
:
Object
)
=>
boolean
|
undefined
|
string
}
export
interface
ApiOptions
<
T
>
{
beforeInvoke
?:
(
args
:
Object
)
=>
boolean
|
void
|
string
beforeAll
?:
(
res
:
Object
)
=>
void
beforeSuccess
?:
(
res
:
Object
,
args
:
T
)
=>
void
formatArgs
?:
Map
<
string
,
Function
>
}
interface
AsyncMethodOptionLike
{
success
?:
Function
|
null
}
const
TYPE_MAP
=
new
Map
<
string
,
Object
>
([
[
'
string
'
,
String
],
[
'
number
'
,
Number
],
[
'
boolean
'
,
Boolean
],
[
'
array
'
,
Array
],
[
'
object
'
,
Object
],
])
function
getPropType
(
type
:
string
|
NullType
):
Anything
{
if
(
!
type
)
{
return
}
return
TYPE_MAP
[
type
]
}
export
function
defineAsyncApi
<
T
extends
AsyncMethodOptionLike
,
K
>
(
name
:
string
,
fn
:
(
options
:
T
,
res
:
ApiExcutor
<
K
>
)
=>
void
,
protocol
:
Map
<
string
,
ProtocolOptions
>
,
options
:
ApiOptions
<
T
>
):
Function
{
const
originalProtocol
=
{}
as
Record
<
string
,
Object
>
protocol
.
forEach
((
value
,
key
)
=>
{
const
protocol
=
(
originalProtocol
[
key
]
=
{}
as
Record
<
string
,
Anything
>
)
protocol
.
name
=
value
.
name
protocol
.
type
=
getPropType
(
value
.
type
)
protocol
.
required
=
value
.
required
protocol
.
validator
=
value
.
validator
})
const
originalFormatArgs
=
{}
as
Record
<
string
,
Function
>
if
(
options
.
formatArgs
)
{
options
.
formatArgs
.
forEach
((
value
,
key
)
=>
{
originalFormatArgs
[
key
]
=
value
})
}
const
originalOptions
=
{}
as
Record
<
string
,
Anything
>
originalOptions
.
beforeInvoke
=
options
.
beforeInvoke
originalOptions
.
beforeAll
=
options
.
beforeAll
originalOptions
.
beforeSuccess
=
options
.
beforeSuccess
originalOptions
.
formatArgs
=
originalFormatArgs
return
originalDefineAsyncApi
<
(
options
:
T
)
=>
Promise
<
K
>>
(
name
,
// @ts-expect-error
fn
,
originalProtocol
,
originalOptions
)
}
packages/uni-runtime/src/index.ts
浏览文件 @
0a12503f
...
...
@@ -6,7 +6,13 @@ export {
extend
,
isArray
,
}
from
'
@vue/shared
'
// export * from '@dcloudio/uni-api'
// export * from '@dcloudio/uni-shared'
// export * from '@dcloudio/uni-platform'
// export * from './helpers/api'
export
{
defineAsyncApi
}
from
'
@dcloudio/uni-api
'
export
{
Emitter
}
from
'
@dcloudio/uni-shared
'
export
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
export
const
__uniConfig
=
globalThis
.
__uniConfig
// @ts-expect-error TODO 处理类型冲突
export
const
UniError
=
globalThis
.
UniError
// @ts-expect-error TODO 处理类型冲突
export
const
UTSJSONObject
=
globalThis
.
UTSJSONObject
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录