Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
1aa3a930
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看板
提交
1aa3a930
编写于
2月 23, 2024
作者:
fxy060608
提交者:
qiang
2月 28, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uvue): 完善 uni ext api 的 provider 扩展编译
上级
47ea8ebb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
64 addition
and
17 deletion
+64
-17
packages/uni-app-uts/src/plugins/android/plugin.ts
packages/uni-app-uts/src/plugins/android/plugin.ts
+4
-0
packages/uni-cli-shared/src/uni_modules.ts
packages/uni-cli-shared/src/uni_modules.ts
+12
-0
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
+48
-17
未找到文件。
packages/uni-app-uts/src/plugins/android/plugin.ts
浏览文件 @
1aa3a930
...
...
@@ -12,6 +12,7 @@ import {
resolveMainPathOnce
,
resolveUTSCompiler
,
utsPlugins
,
buildUniExtApiProviders
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
DEFAULT_APPID
,
...
...
@@ -142,6 +143,9 @@ export function uniAppPlugin(): UniVitePlugin {
pageCount
=
parseInt
(
process
.
env
.
UNI_APP_X_PAGE_COUNT
)
||
0
}
}
await
buildUniExtApiProviders
()
const
res
=
await
resolveUTSCompiler
().
compileApp
(
path
.
join
(
tempOutputDir
,
'
main.uts
'
),
{
...
...
packages/uni-cli-shared/src/uni_modules.ts
浏览文件 @
1aa3a930
...
...
@@ -28,6 +28,12 @@ export interface Exports {
[
name
:
string
]:
Define
|
Defines
|
false
}
const
extApiProviders
:
{
plugin
:
string
;
service
:
string
;
name
?:
string
}[]
=
[]
export
function
getUniExtApiProviders
()
{
return
extApiProviders
}
export
function
parseUniExtApis
(
vite
=
true
,
platform
:
typeof
process
.
env
.
UNI_UTS_PLATFORM
,
...
...
@@ -42,6 +48,7 @@ export function parseUniExtApis(
}
const
injects
:
Injects
=
{}
extApiProviders
.
length
=
0
fs
.
readdirSync
(
uniModulesDir
).
forEach
((
uniModuleDir
)
=>
{
// 必须以 uni- 开头
if
(
!
uniModuleDir
.
startsWith
(
'
uni-
'
))
{
...
...
@@ -59,6 +66,11 @@ export function parseUniExtApis(
exports
=
pkg
.
uni_modules
[
'
uni-ext-api
'
]
}
if
(
exports
)
{
const
provider
=
exports
.
provider
as
any
if
(
provider
&&
provider
.
service
)
{
provider
.
plugin
=
uniModuleDir
extApiProviders
.
push
(
provider
)
}
const
curInjects
=
parseInjects
(
vite
,
platform
,
...
...
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
浏览文件 @
1aa3a930
...
...
@@ -5,6 +5,7 @@ import { once } from '@dcloudio/uni-shared'
import
{
resolveUTSAppModule
,
resolveUTSCompiler
}
from
'
../../../uts
'
import
{
parseVueRequest
}
from
'
../../utils
'
import
{
getUniExtApiProviders
}
from
'
../../../uni_modules
'
const
UTSProxyRE
=
/
\?
uts-proxy$/
function
isUTSProxy
(
id
:
string
)
{
...
...
@@ -29,10 +30,51 @@ interface UniUTSPluginOptions {
export
const
utsPlugins
=
new
Set
<
string
>
()
let
uniExtApiCompiler
=
async
()
=>
{}
export
function
uniUTSUniModulesPlugin
(
options
:
UniUTSPluginOptions
=
{}
):
Plugin
{
process
.
env
.
UNI_UTS_USING_ROLLUP
=
'
true
'
const
compilePlugin
=
(
pluginDir
:
string
)
=>
{
utsPlugins
.
add
(
path
.
basename
(
pluginDir
))
const
pkgJson
=
require
(
path
.
join
(
pluginDir
,
'
package.json
'
))
const
extApiProvider
=
resolveExtApiProvider
(
pkgJson
)
return
resolveUTSCompiler
().
compile
(
pluginDir
,
{
isX
:
!!
options
.
x
,
isSingleThread
:
!!
options
.
isSingleThread
,
isPlugin
:
true
,
extApis
:
options
.
extApis
,
sourceMap
:
process
.
env
.
NODE_ENV
===
'
development
'
,
transform
:
{
uniExtApiProviderName
:
extApiProvider
?.
name
,
uniExtApiProviderService
:
extApiProvider
?.
service
,
},
})
}
uniExtApiCompiler
=
async
()
=>
{
// 获取 provider 扩展
const
plugins
=
getUniExtApiProviders
()
.
filter
((
provider
)
=>
!
utsPlugins
.
has
(
provider
.
plugin
))
.
map
((
provider
)
=>
provider
.
plugin
)
for
(
const
plugin
of
plugins
)
{
const
result
=
await
compilePlugin
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni_modules
'
,
plugin
)
)
if
(
result
)
{
// 时机不对,不能addWatch
// result.deps.forEach((dep) => {
// this.addWatchFile(dep)
// })
}
}
}
return
{
name
:
'
uni:uts-uni_modules
'
,
apply
:
'
build
'
,
...
...
@@ -85,23 +127,7 @@ export function uniUTSUniModulesPlugin(
})
}
const
compile
=
once
(()
=>
{
utsPlugins
.
add
(
path
.
basename
(
pluginDir
))
const
pkgJson
=
require
(
path
.
join
(
pluginDir
,
'
package.json
'
))
const
extApiProvider
=
resolveExtApiProvider
(
pkgJson
)
return
resolveUTSCompiler
().
compile
(
pluginDir
,
{
isX
:
!!
options
.
x
,
isSingleThread
:
!!
options
.
isSingleThread
,
isPlugin
:
true
,
extApis
:
options
.
extApis
,
sourceMap
:
process
.
env
.
NODE_ENV
===
'
development
'
,
transform
:
{
uniExtApiProviderName
:
extApiProvider
?.
name
,
uniExtApiProviderService
:
extApiProvider
?.
service
,
},
})
return
compilePlugin
(
pluginDir
)
})
utsModuleCaches
.
set
(
pluginDir
,
compile
)
const
result
=
await
compile
()
...
...
@@ -117,9 +143,14 @@ export function uniUTSUniModulesPlugin(
}
}
},
async
generateBundle
()
{},
}
}
export
async
function
buildUniExtApiProviders
()
{
await
uniExtApiCompiler
()
}
export
function
resolveExtApiProvider
(
pkg
:
Record
<
string
,
any
>
)
{
const
provider
=
pkg
.
uni_modules
?.[
'
uni-ext-api
'
]?.
provider
as
|
{
name
?:
string
;
service
?:
string
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录