Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
bac44aca
U
uni-app
项目概览
DCloud
/
uni-app
11 天 前同步成功
通知
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看板
提交
bac44aca
编写于
7月 22, 2024
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(harmony): 完善鸿蒙用户自行编写的provider支持
上级
0b7fa4a9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
106 addition
and
10 deletion
+106
-10
packages/uni-app-harmony/src/compiler/plugin.ts
packages/uni-app-harmony/src/compiler/plugin.ts
+80
-5
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
+5
-0
packages/uni-uts-v1/src/arkts.ts
packages/uni-uts-v1/src/arkts.ts
+15
-3
packages/uni-uts-v1/src/utils.ts
packages/uni-uts-v1/src/utils.ts
+6
-2
未找到文件。
packages/uni-app-harmony/src/compiler/plugin.ts
浏览文件 @
bac44aca
...
...
@@ -4,8 +4,10 @@ import {
type
UniVitePlugin
,
buildUniExtApis
,
camelize
,
formatExtApiProviderName
,
getCurrentCompiledUTSPlugins
,
getUniExtApiProviderRegisters
,
parseManifestJsonOnce
,
parseUniExtApi
,
resolveUTSCompiler
,
}
from
'
@dcloudio/uni-cli-shared
'
...
...
@@ -106,6 +108,53 @@ export function uniAppHarmonyPlugin(): UniVitePlugin {
}
}
interface
IRelatedProvider
{
service
:
string
name
:
string
}
const
ProviderServiceMap
=
{
oauth
:
{},
payment
:
{
// alipay: 'alipay',
weixin
:
'
wxpay
'
,
},
}
/**
* 获取manifest.json中勾选的provider
*/
function
getRelatedProviders
(
inputDir
:
string
):
IRelatedProvider
[]
{
const
manifest
=
parseManifestJsonOnce
(
inputDir
)
const
providers
:
IRelatedProvider
[]
=
[]
const
sdkConfigs
=
manifest
?.[
'
app-plus
'
]?.
distribute
?.
sdkConfigs
if
(
!
sdkConfigs
)
{
return
providers
}
for
(
const
service
in
sdkConfigs
)
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
sdkConfigs
,
service
))
{
const
ProviderNameMap
=
ProviderServiceMap
[
service
]
const
relatedProviders
=
sdkConfigs
[
service
]
for
(
const
name
in
relatedProviders
)
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
relatedProviders
,
name
))
{
const
providerName
=
ProviderNameMap
[
name
]
providers
.
push
({
service
,
name
:
providerName
||
name
,
})
}
}
}
}
return
providers
}
const
builtInProviders
=
[
{
service
:
'
payment
'
,
name
:
'
alipay
'
,
},
]
function
genAppHarmonyIndex
(
inputDir
:
string
,
utsPlugins
:
Set
<
string
>
)
{
if
(
!
process
.
env
.
UNI_APP_HARMONY_PROJECT_PATH
)
{
return
...
...
@@ -144,14 +193,40 @@ function genAppHarmonyIndex(inputDir: string, utsPlugins: Set<string>) {
}
})
const
relatedProviders
=
getRelatedProviders
(
inputDir
)
const
importProviderCodes
:
string
[]
=
[]
const
registerProviderCodes
:
string
[]
=
[]
const
providers
=
getUniExtApiProviderRegisters
()
providers
.
forEach
((
provider
)
=>
{
const
parts
=
provider
.
class
.
split
(
'
.
'
)
const
className
=
parts
[
parts
.
length
-
1
]
const
allProviders
=
providers
.
map
((
provider
)
=>
{
return
{
service
:
provider
.
service
,
name
:
provider
.
name
,
moduleSpecifier
:
`./
${
provider
.
plugin
}
/utssdk/app-harmony`
,
}
})
.
concat
(
builtInProviders
.
map
((
provider
)
=>
{
return
{
service
:
provider
.
service
,
name
:
provider
.
name
,
moduleSpecifier
:
`@dcloudio/uni-app-harmony/providers/uni-
${
provider
.
service
}
-
${
provider
.
name
}
`
,
}
})
)
relatedProviders
.
forEach
((
relatedProvider
)
=>
{
const
provider
=
allProviders
.
find
(
(
item
)
=>
item
.
service
===
relatedProvider
.
service
&&
item
.
name
===
relatedProvider
.
name
)
if
(
!
provider
)
{
return
}
const
className
=
formatExtApiProviderName
(
provider
.
service
,
provider
.
name
)
importProviderCodes
.
push
(
`import {
${
className
}
} from '
./
${
provider
.
plugin
}
/utssdk/app-harmony
'`
`import {
${
className
}
} from '
${
provider
.
moduleSpecifier
}
'`
)
registerProviderCodes
.
push
(
`registerUniProvider('
${
provider
.
service
}
', '
${
provider
.
name
}
', new
${
className
}
())`
...
...
@@ -159,7 +234,7 @@ function genAppHarmonyIndex(inputDir: string, utsPlugins: Set<string>) {
})
if
(
importProviderCodes
.
length
)
{
importProviderCodes
.
unshift
(
`import { registerUniProvider } from '
../uni-app/lib/uni-api-shared
'`
`import { registerUniProvider } from '
@dcloudio/uni-app-harmony
'`
)
importCodes
.
push
(...
importProviderCodes
)
extApiCodes
.
push
(...
registerProviderCodes
)
...
...
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
浏览文件 @
bac44aca
...
...
@@ -89,6 +89,11 @@ export function uniUTSAppUniModulesPlugin(
return
compiler
.
compileArkTS
(
pluginDir
,
{
isX
:
!!
options
.
x
,
isExtApi
,
transform
:
{
uniExtApiProviderName
:
extApiProvider
?.
name
,
uniExtApiProviderService
:
extApiProvider
?.
service
,
uniExtApiProviderServicePlugin
,
},
})
}
...
...
packages/uni-uts-v1/src/arkts.ts
浏览文件 @
bac44aca
import
path
from
'
path
'
import
fs
from
'
fs-extra
'
import
type
{
UTSBundleOptions
}
from
'
@dcloudio/uts
'
import
{
getUTSCompiler
}
from
'
./utils
'
import
{
formatUniProviderName
,
getUTSCompiler
}
from
'
./utils
'
import
type
{
CompileResult
}
from
'
.
'
interface
ArkTSCompilerOptions
{
isX
?:
boolean
isExtApi
?:
boolean
transform
?:
{
uniExtApiProviderName
?:
string
uniExtApiProviderService
?:
string
uniExtApiProviderServicePlugin
?:
string
}
}
export
function
getArkTSAutoImports
():
Record
<
...
...
@@ -40,7 +45,7 @@ export function getArkTSAutoImports(): Record<
}
export
async
function
compileArkTS
(
pluginDir
:
string
,
{
isExtApi
}:
ArkTSCompilerOptions
{
isExtApi
,
transform
}:
ArkTSCompilerOptions
):
Promise
<
CompileResult
|
void
>
{
if
(
!
process
.
env
.
UNI_APP_HARMONY_PROJECT_PATH
)
{
console
.
error
(
'
manifest.json -> app-harmony -> projectPath is required
'
)
...
...
@@ -60,6 +65,13 @@ export async function compileArkTS(
pluginId
)
const
autoImportExternals
=
getArkTSAutoImports
()
if
(
transform
&&
transform
.
uniExtApiProviderService
)
{
autoImportExternals
[
'
@dcloudio/uni-app-harmony
'
].
push
([
formatUniProviderName
(
transform
.
uniExtApiProviderService
),
])
}
const
buildOptions
:
UTSBundleOptions
=
{
hbxVersion
:
process
.
env
.
HX_Version
||
process
.
env
.
UNI_COMPILER_VERSION
,
input
:
{
...
...
@@ -85,7 +97,7 @@ export async function compileArkTS(
logFilename
:
false
,
isPlugin
:
true
,
transform
:
{
autoImportExternals
:
getArkTSAutoImports
()
,
autoImportExternals
,
},
treeshake
:
{
noSideEffects
:
true
,
...
...
packages/uni-uts-v1/src/utils.ts
浏览文件 @
bac44aca
...
...
@@ -822,11 +822,15 @@ export function resolveConfigProvider(
}
}
function
formatExtApiProviderName
(
service
:
string
,
nam
e
:
string
)
{
export
function
formatUniProviderName
(
servic
e
:
string
)
{
if
(
service
===
'
oauth
'
)
{
service
=
'
OAuth
'
}
return
`Uni
${
capitalize
(
camelize
(
service
))}${
capitalize
(
return
`Uni
${
capitalize
(
camelize
(
service
))}
Provider`
}
function
formatExtApiProviderName
(
service
:
string
,
name
:
string
)
{
return
`
${
formatUniProviderName
(
service
)}${
capitalize
(
camelize
(
name
)
)}
ProviderImpl`
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录