Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
4d0fe707
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4d0fe707
编写于
11月 04, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
e47a7913
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
168 addition
and
65 deletion
+168
-65
packages/uni-uts-v1/src/index.ts
packages/uni-uts-v1/src/index.ts
+27
-19
packages/uni-uts-v1/src/kotlin.ts
packages/uni-uts-v1/src/kotlin.ts
+26
-38
packages/uni-uts-v1/src/swift.ts
packages/uni-uts-v1/src/swift.ts
+85
-1
packages/uni-uts-v1/src/utils.ts
packages/uni-uts-v1/src/utils.ts
+30
-3
packages/vite-plugin-uni/src/cli/action.ts
packages/vite-plugin-uni/src/cli/action.ts
+0
-4
未找到文件。
packages/uni-uts-v1/src/index.ts
浏览文件 @
4d0fe707
...
...
@@ -40,37 +40,45 @@ export async function compile(module: string) {
}
}
}
else
{
// dev 模式仅 android 支持
if
(
process
.
env
.
UNI_UTS_PLATFORM
===
'
app-android
'
)
{
if
(
process
.
env
.
UNI_UTS_PLATFORM
===
'
app-android
'
||
process
.
env
.
UNI_UTS_PLATFORM
===
'
app-ios
'
)
{
// dev 模式
const
filename
=
resolvePlatformIndex
(
'
app-android
'
,
module
,
pkg
)
||
resolvePlatformIndex
(
process
.
env
.
UNI_UTS_PLATFORM
,
module
,
pkg
)
||
resolveRootIndex
(
module
,
pkg
)
const
compilerType
=
process
.
env
.
UNI_UTS_PLATFORM
===
'
app-android
'
?
'
kotlin
'
:
'
swift
'
if
(
filename
)
{
deps
.
push
(
filename
)
const
res
=
await
getCompiler
(
'
kotlin
'
).
runDev
(
filename
)
const
res
=
await
getCompiler
(
compilerType
).
runDev
(
filename
)
if
(
res
)
{
if
(
isArray
(
res
.
deps
)
&&
res
.
deps
.
length
)
{
// 添加其他文件的依赖
deps
.
push
(...
res
.
deps
)
}
const
files
:
string
[]
=
[]
if
(
process
.
env
.
UNI_APP_CHANGED_DEX_FILES
)
{
try
{
files
.
push
(...
JSON
.
parse
(
process
.
env
.
UNI_APP_CHANGED_DEX_FILES
))
}
catch
(
e
)
{}
}
if
(
res
.
dex
)
{
files
.
push
(
res
.
dex
)
if
(
res
.
type
===
'
kotlin
'
)
{
const
files
:
string
[]
=
[]
if
(
process
.
env
.
UNI_APP_CHANGED_DEX_FILES
)
{
try
{
files
.
push
(...
JSON
.
parse
(
process
.
env
.
UNI_APP_CHANGED_DEX_FILES
))
}
catch
(
e
)
{}
}
if
(
res
.
dex
)
{
files
.
push
(
res
.
dex
)
}
process
.
env
.
UNI_APP_CHANGED_DEX_FILES
=
JSON
.
stringify
([
...
new
Set
(
files
),
])
}
else
if
(
res
.
type
===
'
swift
'
)
{
if
(
code
)
{
throw
res
.
msg
}
}
process
.
env
.
UNI_APP_CHANGED_DEX_FILES
=
JSON
.
stringify
([
...
new
Set
(
files
),
])
}
}
}
else
if
(
process
.
env
.
UNI_UTS_PLATFORM
===
'
app-ios
'
)
{
process
.
env
.
UNI_APP_IOS_UTS
=
'
true
'
}
}
return
{
...
...
packages/uni-uts-v1/src/kotlin.ts
浏览文件 @
4d0fe707
...
...
@@ -5,16 +5,16 @@ import AdmZip from 'adm-zip'
import
{
sync
}
from
'
fast-glob
'
import
{
isArray
}
from
'
@vue/shared
'
import
{
installHBuilderXPlugin
,
isInHBuilderX
,
normalizePath
,
parseJson
,
resolveSourceMapPath
,
runByHBuilderX
,
}
from
'
./shared
'
import
{
CompilerServer
,
genUTSPlatformResource
,
getUtsCompiler
,
getCompilerServer
,
moveRootIndexSourceMap
,
resolveAndroidDir
,
resolvePackage
,
...
...
@@ -24,6 +24,23 @@ import {
import
{
Module
}
from
'
../types/types
'
import
{
UtsResult
}
from
'
@dcloudio/uts
'
interface
KotlinCompilerServer
extends
CompilerServer
{
getKotlincHome
():
string
getDefaultJar
():
string
[]
compile
(
options
:
{
kotlinc
:
string
[];
d8
:
string
[]
},
projectPath
:
string
):
Promise
<
boolean
>
checkDependencies
?:
(
configJsonPath
:
string
)
=>
Promise
<
{
code
:
number
;
msg
:
string
;
data
:
string
[]
}
>
checkRResources
?:
(
resDir
:
string
)
=>
Promise
<
{
code
:
number
msg
:
string
data
:
{
jarPath
:
string
;
uniModuleName
:
string
}
}
>
}
export
function
createKotlinResolveTypeReferenceName
(
_namespace
:
string
,
_ast
:
Module
...
...
@@ -55,7 +72,7 @@ export async function runKotlinProd(filename: string) {
})
}
type
RunKotlinDevResult
=
UtsResult
&
{
dex
?:
string
}
export
type
RunKotlinDevResult
=
UtsResult
&
{
type
:
'
kotlin
'
;
dex
?:
string
}
export
async
function
runKotlinDev
(
filename
:
string
...
...
@@ -65,6 +82,9 @@ export async function runKotlinDev(
return
}
const
result
=
(
await
compile
(
filename
))
as
RunKotlinDevResult
result
.
type
=
'
kotlin
'
const
kotlinFile
=
resolveUTSPlatformFile
(
filename
,
{
inputDir
:
process
.
env
.
UNI_INPUT_DIR
,
outputDir
:
process
.
env
.
UNI_OUTPUT_DIR
,
...
...
@@ -73,7 +93,9 @@ export async function runKotlinDev(
})
// 开发模式下,需要生成 dex
if
(
fs
.
existsSync
(
kotlinFile
))
{
const
compilerServer
=
getCompilerServer
()
const
compilerServer
=
getCompilerServer
<
KotlinCompilerServer
>
(
'
uniapp-runextension
'
)
if
(
!
compilerServer
)
{
throw
`项目使用了uts插件,正在安装 uts Android 运行扩展...`
}
...
...
@@ -314,37 +336,3 @@ function resolveJarPath(filename: string) {
function
resolveClassPath
(
jars
:
string
[])
{
return
jars
.
join
(
os
.
platform
()
===
'
win32
'
?
'
;
'
:
'
:
'
)
}
interface
CompilerServer
{
getKotlincHome
():
string
getDefaultJar
():
string
[]
compile
(
options
:
{
kotlinc
:
string
[];
d8
:
string
[]
},
projectPath
:
string
):
Promise
<
boolean
>
checkDependencies
?:
(
configJsonPath
:
string
)
=>
Promise
<
{
code
:
number
;
msg
:
string
;
data
:
string
[]
}
>
checkRResources
?:
(
resDir
:
string
)
=>
Promise
<
{
code
:
number
msg
:
string
data
:
{
jarPath
:
string
;
uniModuleName
:
string
}
}
>
}
function
getCompilerServer
():
CompilerServer
|
undefined
{
const
compilerServerPath
=
path
.
resolve
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
'
uniapp-runextension/out/main.js
'
)
if
(
fs
.
existsSync
(
compilerServerPath
))
{
// eslint-disable-next-line no-restricted-globals
return
require
(
compilerServerPath
)
}
else
{
if
(
runByHBuilderX
())
{
installHBuilderXPlugin
(
'
uniapp-runextension
'
)
}
else
{
console
.
error
(
compilerServerPath
+
'
is not found
'
)
}
}
}
packages/uni-uts-v1/src/swift.ts
浏览文件 @
4d0fe707
import
fs
from
'
fs-extra
'
import
{
capitalize
}
from
'
@vue/shared
'
import
{
genUTSPlatformResource
,
getCompilerServer
,
getUtsCompiler
,
moveRootIndexSourceMap
,
resolvePackage
,
resolveUTSPlatformFile
,
resolveUTSSourceMapPath
,
}
from
'
./utils
'
import
{
isInHBuilderX
}
from
'
./shared
'
import
{
UtsResult
}
from
'
@dcloudio/uts
'
import
path
from
'
path
'
function
parseSwiftPackage
(
filename
:
string
)
{
const
res
=
resolvePackage
(
filename
)
...
...
@@ -36,7 +41,75 @@ export async function runSwiftProd(filename: string) {
})
}
export
async
function
runSwiftDev
(
_filename
:
string
)
{}
export
type
RunSwiftDevResult
=
UtsResult
&
{
type
:
'
swift
'
code
:
number
msg
:
string
}
export
async
function
runSwiftDev
(
filename
:
string
)
{
// 文件有可能是 app-android 里边的,因为编译到 ios 时,为了保证不报错,可能会去读取 android 下的 uts
if
(
filename
.
includes
(
'
app-android
'
))
{
return
}
const
result
=
(
await
compile
(
filename
))
as
RunSwiftDevResult
result
.
type
=
'
swift
'
const
swiftFile
=
resolveUTSPlatformFile
(
filename
,
{
inputDir
:
process
.
env
.
UNI_INPUT_DIR
,
outputDir
:
process
.
env
.
UNI_OUTPUT_DIR
,
platform
:
'
app-ios
'
,
extname
:
'
.swift
'
,
})
// 开发模式下,需要生成 framework
if
(
fs
.
existsSync
(
swiftFile
))
{
const
compilerServer
=
getCompilerServer
<
SwiftCompilerServer
>
(
'
uts-development-ios
'
)
if
(
!
compilerServer
)
{
throw
`项目使用了uts插件,正在安装 uts iOS 运行扩展...`
}
let
projectPath
=
process
.
env
.
UNI_INPUT_DIR
const
isCli
=
isCliProject
(
projectPath
)
if
(
isCli
)
{
projectPath
=
path
.
resolve
(
projectPath
,
'
..
'
)
}
const
{
id
,
is_uni_modules
}
=
resolvePackage
(
filename
)
!
const
{
code
,
msg
}
=
await
compilerServer
.
compile
({
projectPath
,
isCli
,
type
:
1
,
pluginName
:
id
,
utsPath
:
resolveCompilerUtsPath
(
process
.
env
.
UNI_INPUT_DIR
,
is_uni_modules
),
swiftPath
:
resolveCompilerSwiftPath
(
process
.
env
.
UNI_OUTPUT_DIR
,
is_uni_modules
),
})
result
.
code
=
code
result
.
msg
=
msg
}
return
result
}
function
resolveCompilerUtsPath
(
projectPath
:
string
,
is_uni_modules
:
boolean
)
{
return
path
.
resolve
(
projectPath
,
is_uni_modules
?
'
uni_modules
'
:
'
utssdk
'
)
}
function
resolveCompilerSwiftPath
(
outputDir
:
string
,
is_uni_modules
:
boolean
)
{
return
path
.
resolve
(
outputDir
,
is_uni_modules
?
'
uni_modules
'
:
'
utssdk
'
)
}
function
isCliProject
(
projectPath
:
string
)
{
if
(
projectPath
.
endsWith
(
'
src
'
))
{
return
true
}
return
false
}
async
function
compile
(
filename
:
string
)
{
if
(
!
process
.
env
.
UNI_HBUILDERX_PLUGINS
)
{
...
...
@@ -70,3 +143,14 @@ async function compile(filename: string) {
})
return
result
}
interface
SwiftCompilerServer
{
compile
(
options
:
{
projectPath
:
string
isCli
:
boolean
type
:
1
|
2
// 1 => uni_modules , 2 => utssdk
pluginName
:
string
utsPath
:
string
swiftPath
:
string
}):
Promise
<
{
code
:
number
;
msg
:
string
}
>
}
packages/uni-uts-v1/src/utils.ts
浏览文件 @
4d0fe707
...
...
@@ -3,7 +3,12 @@ import fs from 'fs-extra'
import
type
{
parse
,
bundle
,
UtsTarget
}
from
'
@dcloudio/uts
'
import
{
camelize
,
capitalize
}
from
'
@vue/shared
'
import
{
Module
,
ModuleItem
}
from
'
../types/types
'
import
{
normalizePath
,
resolveSourceMapPath
}
from
'
./shared
'
import
{
installHBuilderXPlugin
,
normalizePath
,
resolveSourceMapPath
,
runByHBuilderX
,
}
from
'
./shared
'
export
function
resolveUTSSourceMapPath
(
_filename
:
string
)
{
return
resolveSourceMapPath
()
...
...
@@ -26,11 +31,13 @@ export function resolvePackage(filename: string) {
?
parts
.
findIndex
((
part
)
=>
part
===
'
uni_modules
'
)
:
parts
.
findIndex
((
part
)
=>
part
===
'
utssdk
'
)
if
(
index
>
-
1
)
{
const
name
=
camelize
(
parts
[
index
+
1
])
const
id
=
parts
[
index
+
1
]
const
name
=
camelize
(
id
)
return
{
i
s_uni_modules
:
isUniModules
,
i
d
,
name
,
namespace
:
'
UTSSDK
'
+
(
isUniModules
?
'
Modules
'
:
''
)
+
capitalize
(
name
),
is_uni_modules
:
isUniModules
,
}
}
}
...
...
@@ -163,3 +170,23 @@ export function createResolveTypeReferenceName(namespace: string, ast: Module) {
return
name
}
}
export
type
CompilerServer
=
{}
export
function
getCompilerServer
<
T
extends
CompilerServer
>
(
pluginName
:
'
uts-development-ios
'
|
'
uniapp-runextension
'
):
T
|
undefined
{
const
compilerServerPath
=
path
.
resolve
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
`
${
pluginName
}
/out/external`
)
if
(
fs
.
existsSync
(
compilerServerPath
))
{
// eslint-disable-next-line no-restricted-globals
return
require
(
compilerServerPath
)
}
else
{
if
(
runByHBuilderX
())
{
installHBuilderXPlugin
(
pluginName
)
}
else
{
console
.
error
(
compilerServerPath
+
'
is not found
'
)
}
}
}
packages/vite-plugin-uni/src/cli/action.ts
浏览文件 @
4d0fe707
...
...
@@ -37,10 +37,6 @@ export async function runDev(options: CliOptions & ServerOptions) {
event
.
result
.
close
()
if
(
isFirstEnd
)
{
// 首次全量同步
// iOS 平台使用了 UTS
if
(
process
.
env
.
UNI_APP_IOS_UTS
)
{
console
.
log
(
`\u200B`
+
M
[
'
uts.ios.tips
'
]
+
`\u200B`
)
}
process
.
env
.
UNI_APP_CHANGED_PAGES
=
''
process
.
env
.
UNI_APP_CHANGED_FILES
=
''
process
.
env
.
UNI_APP_CHANGED_DEX_FILES
=
''
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录