Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
f8759d76
U
uni-app
项目概览
DCloud
/
uni-app
6 天 前同步成功
通知
815
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看板
提交
f8759d76
编写于
2月 26, 2024
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uvue): 完善 ext api provider
上级
3718df1e
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
127 addition
and
18 deletion
+127
-18
packages/uni-cli-shared/src/uni_modules.ts
packages/uni-cli-shared/src/uni_modules.ts
+6
-1
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
+30
-9
packages/uni-h5/dist-x/uni-h5.cjs.js
packages/uni-h5/dist-x/uni-h5.cjs.js
+1
-0
packages/uni-h5/dist-x/uni-h5.es.js
packages/uni-h5/dist-x/uni-h5.es.js
+1
-0
packages/uni-uts-v1/src/index.ts
packages/uni-uts-v1/src/index.ts
+7
-2
packages/uni-uts-v1/src/kotlin.ts
packages/uni-uts-v1/src/kotlin.ts
+34
-0
packages/uni-uts-v1/src/swift.ts
packages/uni-uts-v1/src/swift.ts
+4
-0
packages/uni-uts-v1/src/utils.ts
packages/uni-uts-v1/src/utils.ts
+43
-6
packages/uts/src/types.ts
packages/uts/src/types.ts
+1
-0
未找到文件。
packages/uni-cli-shared/src/uni_modules.ts
浏览文件 @
f8759d76
...
...
@@ -28,7 +28,12 @@ export interface Exports {
[
name
:
string
]:
Define
|
Defines
|
false
}
const
extApiProviders
:
{
plugin
:
string
;
service
:
string
;
name
?:
string
}[]
=
[]
const
extApiProviders
:
{
plugin
:
string
service
:
string
name
?:
string
servicePlugin
?:
string
}[]
=
[]
export
function
getUniExtApiProviders
()
{
return
extApiProviders
...
...
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
浏览文件 @
f8759d76
import
type
{
Plugin
}
from
'
vite
'
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
once
}
from
'
@dcloudio/uni-shared
'
...
...
@@ -43,7 +44,21 @@ export function uniUTSUniModulesPlugin(
const
pkgJson
=
require
(
path
.
join
(
pluginDir
,
'
package.json
'
))
const
extApiProvider
=
resolveExtApiProvider
(
pkgJson
)
// 如果是 provider 扩展,需要判断 provider 的宿主插件是否在本地,在的话,自动导入该宿主插件包名
let
uniExtApiProviderServicePlugin
=
''
if
(
extApiProvider
?.
servicePlugin
)
{
if
(
fs
.
existsSync
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni_modules
'
,
extApiProvider
.
servicePlugin
)
)
)
{
uniExtApiProviderServicePlugin
=
extApiProvider
.
servicePlugin
}
}
return
resolveUTSCompiler
().
compile
(
pluginDir
,
{
isX
:
!!
options
.
x
,
isSingleThread
:
!!
options
.
isSingleThread
,
...
...
@@ -53,18 +68,19 @@ export function uniUTSUniModulesPlugin(
transform
:
{
uniExtApiProviderName
:
extApiProvider
?.
name
,
uniExtApiProviderService
:
extApiProvider
?.
service
,
uniExtApiProviderServicePlugin
,
},
})
}
uniExtApiCompiler
=
async
()
=>
{
// 获取 provider 扩展
const
plugins
=
getUniExtApiProviders
()
.
filter
((
provider
)
=>
!
utsPlugins
.
has
(
provider
.
plugin
)
)
.
map
((
provider
)
=>
provider
.
plugin
)
const
plugins
=
getUniExtApiProviders
()
.
filter
(
(
provider
)
=>
!
utsPlugins
.
has
(
provider
.
plugin
)
)
for
(
const
plugin
of
plugins
)
{
const
result
=
await
compilePlugin
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni_modules
'
,
plugin
)
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni_modules
'
,
plugin
.
plugin
)
)
if
(
result
)
{
// 时机不对,不能addWatch
...
...
@@ -153,12 +169,17 @@ export async function buildUniExtApiProviders() {
export
function
resolveExtApiProvider
(
pkg
:
Record
<
string
,
any
>
)
{
const
provider
=
pkg
.
uni_modules
?.[
'
uni-ext-api
'
]?.
provider
as
|
{
name
?:
string
;
service
?:
string
}
|
{
name
?:
string
plugin
?:
string
service
:
string
servicePlugin
:
string
}
|
undefined
if
(
provider
?.
service
)
{
return
{
name
:
provider
.
name
,
service
:
provider
.
service
,
if
(
provider
.
name
&&
!
provider
.
servicePlugin
)
{
provider
.
servicePlugin
=
'
uni-
'
+
provider
.
service
}
return
provider
}
}
packages/uni-h5/dist-x/uni-h5.cjs.js
浏览文件 @
f8759d76
...
...
@@ -866,6 +866,7 @@ class UniElement extends HTMLElement {
constructor
()
{
super
();
this
.
_props
=
{};
this
.
__isUniElement
=
true
;
}
attachVmProps
(
props2
)
{
this
.
_props
=
props2
;
...
...
packages/uni-h5/dist-x/uni-h5.es.js
浏览文件 @
f8759d76
...
...
@@ -2134,6 +2134,7 @@ class UniElement extends HTMLElement {
constructor() {
super();
this._props = {};
this.__isUniElement = true;
}
attachVmProps(props2) {
this._props = props2;
...
...
packages/uni-uts-v1/src/index.ts
浏览文件 @
f8759d76
...
...
@@ -26,6 +26,7 @@ import {
ERR_MSG_PLACEHOLDER
,
genConfigJson
,
resolveAndroidComponents
,
resolveConfigProvider
,
resolveIOSComponents
,
resolvePackage
,
}
from
'
./utils
'
...
...
@@ -190,6 +191,7 @@ export async function compile(
}
if
(
filename
)
{
await
getCompiler
(
'
kotlin
'
).
runProd
(
filename
,
androidComponents
,
{
pluginId
:
pkg
.
id
,
isX
,
isSingleThread
,
isPlugin
,
...
...
@@ -226,6 +228,7 @@ export async function compile(
}
if
(
filename
)
{
await
getCompiler
(
'
swift
'
).
runProd
(
filename
,
iosComponents
,
{
pluginId
:
pkg
.
id
,
isX
,
isSingleThread
,
isPlugin
:
true
,
// iOS 目前仅有 plugin 模式
...
...
@@ -322,7 +325,8 @@ export async function compile(
pluginRelativeDir
,
pkg
.
is_uni_modules
,
inputDir
,
outputDir
outputDir
,
resolveConfigProvider
(
utsPlatform
,
pkg
.
id
,
transform
)
)
console
.
log
(
cacheTips
(
pkg
.
id
))
...
...
@@ -369,7 +373,8 @@ export async function compile(
pluginRelativeDir
,
pkg
.
is_uni_modules
,
inputDir
,
outputDir
outputDir
,
resolveConfigProvider
(
utsPlatform
,
pkg
.
id
,
transform
)
)
const
res
=
await
getCompiler
(
compilerType
).
runDev
(
filename
,
{
components
,
...
...
packages/uni-uts-v1/src/kotlin.ts
浏览文件 @
f8759d76
...
...
@@ -30,6 +30,7 @@ import {
isUniCloudSupported
,
parseExtApiDefaultParameters
,
parseInjectModules
,
resolveConfigProvider
,
}
from
'
./utils
'
import
{
Module
}
from
'
../types/types
'
import
{
parseUTSKotlinStacktrace
,
parseUTSSyntaxError
}
from
'
./stacktrace
'
...
...
@@ -93,6 +94,7 @@ export async function runKotlinProd(
filename
:
string
,
components
:
Record
<
string
,
string
>
,
{
pluginId
,
isPlugin
,
isX
,
isSingleThread
,
...
...
@@ -101,6 +103,7 @@ export async function runKotlinProd(
transform
,
sourceMap
,
}:
{
pluginId
:
string
isPlugin
:
boolean
isX
:
boolean
isSingleThread
:
boolean
...
...
@@ -152,6 +155,7 @@ export async function runKotlinProd(
package
:
parseKotlinPackage
(
filename
).
package
+
'
.
'
,
hookClass
,
result
,
provider
:
resolveConfigProvider
(
'
app-android
'
,
pluginId
,
transform
),
})
return
result
...
...
@@ -300,6 +304,16 @@ export async function runKotlinDev(
path
.
resolve
(
path
.
dirname
(
kotlinFile
),
chunk
)
)
||
[]
)
const
uniModuleDeps
:
string
[]
=
[]
if
(
transform
?.
uniExtApiProviderServicePlugin
)
{
uniModuleDeps
.
push
(
...
getUniModulesCacheJarsByPlugin
(
cacheDir
,
transform
.
uniExtApiProviderServicePlugin
)
)
}
const
options
=
{
pageCount
:
0
,
kotlinc
:
resolveKotlincArgs
(
...
...
@@ -310,6 +324,7 @@ export async function runKotlinDev(
.
concat
(
resolveLibs
(
filename
))
.
concat
(
deps
)
.
concat
(
resDeps
)
.
concat
(
uniModuleDeps
)
// .concat(getUniModulesCacheJars(cacheDir))
// .concat(getUniModulesJars(outputDir))
),
...
...
@@ -504,6 +519,15 @@ export async function compile(
if
(
isUniCloudSupported
()
||
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
imports
.
push
(
'
io.dcloud.unicloud.*
'
)
}
// 本地 provider
if
(
transform
?.
uniExtApiProviderServicePlugin
)
{
imports
.
push
(
parseKotlinPackageWithPluginId
(
transform
.
uniExtApiProviderServicePlugin
,
true
)
+
'
.*
'
)
}
const
componentsCode
=
genComponentsCode
(
filename
,
components
,
isX
)
const
{
package
:
pluginPackage
,
id
:
pluginId
}
=
parseKotlinPackage
(
filename
)
const
input
:
UTSInputOptions
=
{
...
...
@@ -692,6 +716,16 @@ export function getUniModulesEncryptCacheJars(cacheDir: string) {
return
[]
}
function
getUniModulesCacheJarsByPlugin
(
cacheDir
:
string
,
plugin
:
string
)
{
if
(
cacheDir
)
{
return
sync
(
'
app-android/uts/uni_modules/
'
+
plugin
+
'
/index.jar
'
,
{
cwd
:
cacheDir
,
absolute
:
true
,
})
}
return
[]
}
export
function
getUniModulesCacheJars
(
cacheDir
:
string
)
{
if
(
cacheDir
)
{
return
sync
(
'
app-android/uts/uni_modules/*/index.jar
'
,
{
...
...
packages/uni-uts-v1/src/swift.ts
浏览文件 @
f8759d76
...
...
@@ -8,6 +8,7 @@ import {
isColorSupported
,
moveRootIndexSourceMap
,
parseSwiftPackageWithPluginId
,
resolveConfigProvider
,
resolveIOSDir
,
resolvePackage
,
resolveUTSPlatformFile
,
...
...
@@ -42,6 +43,7 @@ export async function runSwiftProd(
filename
:
string
,
components
:
Record
<
string
,
string
>
,
{
pluginId
,
isPlugin
,
isX
,
isSingleThread
,
...
...
@@ -50,6 +52,7 @@ export async function runSwiftProd(
sourceMap
,
hookClass
,
}:
{
pluginId
:
string
isPlugin
:
boolean
isX
:
boolean
isSingleThread
:
boolean
...
...
@@ -92,6 +95,7 @@ export async function runSwiftProd(
package
:
parseSwiftPackage
(
filename
).
namespace
,
hookClass
,
result
,
provider
:
resolveConfigProvider
(
'
app-ios
'
,
pluginId
,
transform
),
})
}
...
...
packages/uni-uts-v1/src/utils.ts
浏览文件 @
f8759d76
...
...
@@ -86,6 +86,7 @@ export interface UTSPlatformResourceOptions {
package
:
string
hookClass
:
string
result
:
UTSResult
provider
?:
{
name
:
string
;
service
:
string
;
class
:
string
}
}
export
function
genUTSPlatformResource
(
filename
:
string
,
...
...
@@ -115,7 +116,8 @@ export function genUTSPlatformResource(
utsOutputDir
,
options
.
hookClass
,
options
.
components
,
options
.
package
options
.
package
,
options
.
provider
)
// 生产模式下,需要将生成的平台文件转移到 src 下
...
...
@@ -363,9 +365,10 @@ export function genConfigJson(
pluginRelativeDir
:
string
,
is_uni_modules
:
boolean
,
inputDir
:
string
,
outputDir
:
string
outputDir
:
string
,
provider
?:
{
name
:
string
;
service
:
string
;
class
:
string
}
)
{
if
(
!
Object
.
keys
(
components
).
length
&&
!
hookClass
)
{
if
(
!
Object
.
keys
(
components
).
length
&&
!
hookClass
&&
!
provider
)
{
return
}
const
pluginId
=
basename
(
pluginRelativeDir
)
...
...
@@ -390,7 +393,8 @@ export function genConfigJson(
components
,
platform
===
'
app-android
'
?
parseKotlinPackageWithPluginId
(
pluginId
,
is_uni_modules
)
+
'
.
'
:
parseSwiftPackageWithPluginId
(
pluginId
,
is_uni_modules
)
:
parseSwiftPackageWithPluginId
(
pluginId
,
is_uni_modules
),
provider
)
}
...
...
@@ -401,13 +405,15 @@ function copyConfigJson(
outputDir
:
string
,
hookClass
:
string
,
componentsObj
:
Record
<
string
,
string
>
,
namespace
:
string
namespace
:
string
,
provider
?:
{
name
:
string
;
service
:
string
;
class
:
string
}
)
{
const
configJsonFilename
=
resolve
(
inputDir
,
'
config.json
'
)
const
outputConfigJsonFilename
=
resolve
(
outputDir
,
'
config.json
'
)
const
hasComponents
=
!!
Object
.
keys
(
componentsObj
).
length
const
hasHookClass
=
!!
hookClass
if
(
hasComponents
||
hasHookClass
)
{
const
hasProvider
=
!!
provider
if
(
hasComponents
||
hasHookClass
||
hasProvider
)
{
const
configJson
:
Record
<
string
,
any
>
=
fs
.
existsSync
(
configJsonFilename
)
?
parseJson
(
fs
.
readFileSync
(
configJsonFilename
,
'
utf8
'
))
:
{}
...
...
@@ -423,6 +429,9 @@ function copyConfigJson(
if
(
hasHookClass
)
{
configJson
.
hooksClass
=
hookClass
}
if
(
hasProvider
)
{
configJson
.
provider
=
provider
}
fs
.
outputFileSync
(
outputConfigJsonFilename
,
JSON
.
stringify
(
configJson
,
null
,
2
)
...
...
@@ -638,3 +647,31 @@ export function normalizeExtApiModules(json: Record<string, any>) {
})
return
res
}
export
function
resolveConfigProvider
(
platform
:
'
app-android
'
|
'
app-ios
'
,
plugin
:
string
,
transform
:
UTSOutputOptions
[
'
transform
'
]
)
{
if
(
transform
?.
uniExtApiProviderName
&&
transform
?.
uniExtApiProviderService
)
{
return
{
name
:
transform
.
uniExtApiProviderName
,
service
:
transform
.
uniExtApiProviderService
,
class
:
(
platform
===
'
app-android
'
?
parseKotlinPackageWithPluginId
(
plugin
,
true
)
:
parseSwiftPackageWithPluginId
(
plugin
,
true
))
+
'
.
'
+
formatExtApiProviderName
(
transform
.
uniExtApiProviderService
,
transform
.
uniExtApiProviderName
),
}
}
}
function
formatExtApiProviderName
(
service
:
string
,
name
:
string
)
{
return
`UniExtApi
${
capitalize
(
camelize
(
service
))}${
capitalize
(
camelize
(
name
)
)}
Provider`
}
packages/uts/src/types.ts
浏览文件 @
f8759d76
...
...
@@ -60,6 +60,7 @@ export type UTSOutputOptions = {
uniExtApiDefaultParameters
?:
Record
<
string
,
string
[]
>
uniExtApiProviderName
?:
string
uniExtApiProviderService
?:
string
uniExtApiProviderServicePlugin
?:
string
uvueClassNamePrefix
?:
string
uvueClassNameOnlyBasename
?:
boolean
disableReactiveObject
?:
boolean
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录