Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
9f17f581
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看板
提交
9f17f581
编写于
6月 14, 2024
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app-harmony): uni_modules
上级
bcfab83c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
142 addition
and
8 deletion
+142
-8
packages/shims-node.d.ts
packages/shims-node.d.ts
+1
-1
packages/uni-cli-shared/src/uni_modules.ts
packages/uni-cli-shared/src/uni_modules.ts
+28
-0
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
+70
-3
packages/uni-uts-v1/src/arkts.ts
packages/uni-uts-v1/src/arkts.ts
+40
-3
packages/uni-uts-v1/src/index.ts
packages/uni-uts-v1/src/index.ts
+1
-1
packages/uts/src/types.ts
packages/uts/src/types.ts
+2
-0
未找到文件。
packages/shims-node.d.ts
浏览文件 @
9f17f581
...
...
@@ -14,7 +14,7 @@ declare namespace NodeJS {
UNI_UTS_JS_CODE_FORMAT
?:
'
cjs
'
|
'
es
'
UNI_UTS_MODULE_TYPE
?:
'
built-in
'
|
''
UNI_UTS_MODULE_PREFIX
?:
string
UNI_UTS_TARGET_LANGUAGE
?:
'
javascript
'
|
'
kotlin
'
|
'
swift
'
UNI_UTS_TARGET_LANGUAGE
?:
'
javascript
'
|
'
kotlin
'
|
'
swift
'
|
'
arkts
'
UNI_INPUT_DIR
:
string
UNI_OUTPUT_DIR
:
string
...
...
packages/uni-cli-shared/src/uni_modules.ts
浏览文件 @
9f17f581
...
...
@@ -123,6 +123,34 @@ export function parseUniExtApis(
return
injects
}
export
function
parseUniExtApi
(
pluginDir
:
string
,
pluginId
:
string
,
vite
=
true
,
platform
:
typeof
process
.
env
.
UNI_UTS_PLATFORM
,
language
:
UTSTargetLanguage
=
'
javascript
'
)
{
const
pkgPath
=
path
.
resolve
(
pluginDir
,
'
package.json
'
)
if
(
!
fs
.
existsSync
(
pkgPath
))
{
return
}
let
exports
:
Exports
|
undefined
const
pkg
=
JSON
.
parse
(
fs
.
readFileSync
(
pkgPath
,
'
utf8
'
))
if
(
pkg
&&
pkg
.
uni_modules
&&
pkg
.
uni_modules
[
'
uni-ext-api
'
])
{
exports
=
pkg
.
uni_modules
[
'
uni-ext-api
'
]
}
if
(
exports
)
{
return
parseInjects
(
vite
,
platform
,
language
,
`@/uni_modules/
${
pluginId
}
`
,
pluginDir
,
exports
)
}
}
type
Inject
=
string
|
string
[]
export
type
Injects
=
{
[
name
:
string
]:
...
...
packages/uni-cli-shared/src/vite/plugins/uts/uni_modules.ts
浏览文件 @
9f17f581
...
...
@@ -10,9 +10,10 @@ import {
checkEncryptUniModules
,
getUniExtApiPlugins
,
parseUTSModuleDeps
,
parseUniExtApi
,
resolveEncryptUniModule
,
}
from
'
../../../uni_modules
'
import
{
enableSourceMap
}
from
'
../../../utils
'
import
{
camelize
,
enableSourceMap
}
from
'
../../../utils
'
import
{
parseManifestJsonOnce
}
from
'
../../../json
'
const
UTSProxyRE
=
/
\?
uts-proxy$/
...
...
@@ -56,7 +57,7 @@ export function uniUTSAppUniModulesPlugin(
utsPlugins
.
add
(
path
.
basename
(
pluginDir
))
const
pkgJson
=
require
(
path
.
join
(
pluginDir
,
'
package.json
'
))
const
isExtApi
=
!!
pkgJson
.
uni_modules
?.[
'
uni-ext-api
'
]
const
extApiProvider
=
resolveExtApiProvider
(
pkgJson
)
// 如果是 provider 扩展,需要判断 provider 的宿主插件是否在本地,在的话,自动导入该宿主插件包名
let
uniExtApiProviderServicePlugin
=
''
...
...
@@ -84,6 +85,7 @@ export function uniUTSAppUniModulesPlugin(
if
(
process
.
env
.
UNI_PLATFORM
===
'
app-harmony
'
)
{
return
compiler
.
compileArkTS
(
pluginDir
,
{
isX
:
!!
options
.
x
,
isExtApi
,
})
}
...
...
@@ -197,7 +199,11 @@ export function uniUTSAppUniModulesPlugin(
}
}
},
async
generateBundle
()
{},
async
generateBundle
()
{
if
(
process
.
env
.
UNI_PLATFORM
===
'
app-harmony
'
)
{
genAppHarmonyIndex
(
inputDir
,
utsPlugins
)
}
},
}
}
...
...
@@ -268,3 +274,64 @@ export function uniDecryptUniModulesPlugin(): Plugin {
},
}
}
function
genAppHarmonyIndex
(
inputDir
:
string
,
utsPlugins
:
Set
<
string
>
)
{
if
(
!
process
.
env
.
UNI_APP_HARMONY_PROJECT_PATH
)
{
return
}
const
uniModulesDir
=
path
.
resolve
(
inputDir
,
'
uni_modules
'
)
const
importCodes
:
string
[]
=
[]
const
extApiCodes
:
string
[]
=
[]
const
registerCodes
:
string
[]
=
[]
utsPlugins
.
forEach
((
plugin
)
=>
{
const
injects
=
parseUniExtApi
(
path
.
resolve
(
uniModulesDir
,
plugin
),
plugin
,
true
,
'
app-harmony
'
,
'
arkts
'
)
if
(
injects
)
{
Object
.
keys
(
injects
).
forEach
((
key
)
=>
{
const
inject
=
injects
[
key
]
if
(
Array
.
isArray
(
inject
)
&&
inject
.
length
>
1
)
{
const
apiName
=
inject
[
1
]
importCodes
.
push
(
`import {
${
inject
[
1
]}
} from './
${
plugin
}
/utssdk/app-harmony'`
)
extApiCodes
.
push
(
`uni.
${
apiName
}
=
${
apiName
}
`
)
}
})
}
else
{
const
ident
=
camelize
(
plugin
)
importCodes
.
push
(
`import * as
${
ident
}
from './
${
plugin
}
/utssdk/app-harmony'`
)
registerCodes
.
push
(
`uni.registerUTSPlugin('uni_modules/
${
plugin
}
',
${
ident
}
)`
)
}
})
fs
.
writeFileSync
(
path
.
resolve
(
resolveUTSCompiler
().
resolveAppHarmonyUniModulesRootDir
(
process
.
env
.
UNI_APP_HARMONY_PROJECT_PATH
),
'
index.generated.ets
'
),
`// This file is automatically generated by uni-app.
// Do not modify this file -- YOUR CHANGES WILL BE ERASED!
${
importCodes
.
join
(
'
\n
'
)}
export function initUniModules(uni: ESObject) {
initUniExtApi(uni)
${
registerCodes
.
join
(
'
\n
'
)}
}
function initUniExtApi(uni: ESObject) {
${
extApiCodes
.
join
(
'
\n
'
)}
}
`
)
}
packages/uni-uts-v1/src/arkts.ts
浏览文件 @
9f17f581
...
...
@@ -6,10 +6,11 @@ import type { CompileResult } from '.'
interface
ArkTSCompilerOptions
{
isX
?:
boolean
isExtApi
?:
boolean
}
export
async
function
compileArkTS
(
pluginDir
:
string
,
_
:
ArkTSCompilerOptions
{
isExtApi
}
:
ArkTSCompilerOptions
):
Promise
<
CompileResult
|
void
>
{
if
(
!
process
.
env
.
UNI_APP_HARMONY_PROJECT_PATH
)
{
console
.
error
(
'
manifest.json -> app-harmony -> projectPath is required
'
)
...
...
@@ -28,6 +29,37 @@ export async function compileArkTS(
projectPath
,
pluginId
)
const
globals
=
[
'
IUniError
'
,
'
IUTSObject
'
,
'
UniError
'
,
'
UTSObject
'
,
'
UTSJSONObject
'
,
'
string
'
,
'
ComponentPublicInstance
'
,
'
ComponentInternalInstance
'
,
]
const
banners
:
string
[]
=
[
`import {
${
globals
.
join
(
'
,
'
)}
} from '../../../../uni-app/lib/uts'`
,
]
if
(
isExtApi
)
{
const
globals
=
[
'
defineAsyncApi
'
,
'
defineSyncApi
'
,
'
defineTaskApi
'
,
'
defineOnApi
'
,
'
defineOffApi
'
,
'
ApiExcutor
'
,
'
ProtocolOptions
'
,
'
ApiOptions
'
,
'
ErrRes
'
,
]
banners
.
push
(
`import {
${
globals
.
join
(
'
,
'
)}
} from '../../../../uni-app/lib/uni-api-shared'`
)
}
const
buildOptions
:
UTSBundleOptions
=
{
hbxVersion
:
process
.
env
.
HX_Version
||
process
.
env
.
UNI_COMPILER_VERSION
,
input
:
{
...
...
@@ -55,6 +87,8 @@ export async function compileArkTS(
treeshake
:
{
noSideEffects
:
true
,
},
banner
:
banners
.
join
(
'
\n
'
),
// footer:''
},
}
const
result
=
await
bundle
(
UTSTarget
.
ARKTS
,
buildOptions
)
...
...
@@ -65,7 +99,7 @@ export async function compileArkTS(
}
}
return
{
code
:
requireUTSPluginCode
(
pluginId
),
code
:
requireUTSPluginCode
(
pluginId
,
!!
isExtApi
),
deps
,
encrypt
:
true
,
dir
:
outputUniModuleDir
,
...
...
@@ -74,7 +108,10 @@ export async function compileArkTS(
}
}
function
requireUTSPluginCode
(
pluginId
:
string
)
{
function
requireUTSPluginCode
(
pluginId
:
string
,
isExtApi
:
boolean
)
{
if
(
isExtApi
)
{
return
`export default uni`
}
return
`export default uni.requireUTSPlugin('uni_modules/
${
pluginId
}
')`
}
...
...
packages/uni-uts-v1/src/index.ts
浏览文件 @
9f17f581
...
...
@@ -44,7 +44,7 @@ import { uvueOutDir } from './uvue/index'
export
*
from
'
./tsc
'
export
{
compileArkTS
}
from
'
./arkts
'
export
{
compileArkTS
,
resolveAppHarmonyUniModulesRootDir
}
from
'
./arkts
'
export
const
sourcemap
=
{
generateCodeFrameWithKotlinStacktrace
,
...
...
packages/uts/src/types.ts
浏览文件 @
9f17f581
...
...
@@ -45,6 +45,8 @@ export type UTSOutputOptions = {
outDir
:
string
outFilename
?:
string
package
:
string
banner
?:
string
footer
?:
string
imports
?:
string
[]
sourceMap
?:
boolean
|
string
inlineSourcesContent
?:
boolean
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录