Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
6846cb50
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6846cb50
编写于
7月 28, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
740e1e86
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
135 addition
and
11 deletion
+135
-11
packages/uni-uts-vite/package.json
packages/uni-uts-vite/package.json
+3
-1
packages/uni-uts-vite/src/plugins/v1.ts
packages/uni-uts-vite/src/plugins/v1.ts
+2
-2
packages/uni-uts-vite/src/utils/compiler.ts
packages/uni-uts-vite/src/utils/compiler.ts
+126
-8
pnpm-lock.yaml
pnpm-lock.yaml
+4
-0
未找到文件。
packages/uni-uts-vite/package.json
浏览文件 @
6846cb50
...
...
@@ -27,6 +27,8 @@
},
"dependencies"
:
{
"@dcloudio/uni-cli-shared"
:
"3.0.0-alpha-3050220220719003"
,
"@dcloudio/uts"
:
"3.0.0-alpha-3050220220719003"
"@dcloudio/uni-shared"
:
"3.0.0-alpha-3050220220719003"
,
"@dcloudio/uts"
:
"3.0.0-alpha-3050220220719003"
,
"execa"
:
"^5.1.1"
}
}
packages/uni-uts-vite/src/plugins/v1.ts
浏览文件 @
6846cb50
...
...
@@ -16,6 +16,7 @@ import {
TsTypeAliasDeclaration
,
TsTypeAnnotation
,
}
from
'
../../types/types
'
import
{
compile
}
from
'
../utils/compiler
'
export
function
uniUtsV1Plugin
():
Plugin
{
// 目前仅支持 app-android
...
...
@@ -53,8 +54,7 @@ import { initUtsProxyClass, initUtsProxyFunction } from '@dcloudio/uni-app'
const pkg = '
${
pkg
}
'
${
genProxyCode
(
ast
)}
`
// TODO compile uts
await
compile
(
id
)
return
code
},
}
...
...
packages/uni-uts-vite/src/utils/compiler.ts
浏览文件 @
6846cb50
import
{
parse
,
runBuild
,
UtsTarget
}
from
'
@dcloudio/uts
'
import
os
from
'
os
'
import
fs
from
'
fs
'
import
path
from
'
path
'
import
execa
from
'
execa
'
import
{
once
}
from
'
@dcloudio/uni-shared
'
import
type
{
parse
,
bundle
,
UtsTarget
}
from
'
@dcloudio/uts
'
export
function
getUtsCompiler
():
{
parse
:
typeof
parse
runBuild
:
typeof
runBuild
bundle
:
typeof
bundle
UtsTarget
:
typeof
UtsTarget
}
{
// eslint-disable-next-line no-restricted-globals
return
require
(
'
@dcloudio/uts
'
)
}
export
function
compile
(
pluginDir
:
string
)
{
const
{
runBuild
,
UtsTarget
}
=
getUtsCompiler
()
runBuild
(
UtsTarget
.
KOTLIN
,
{
export
async
function
compile
(
filename
:
string
)
{
if
(
!
process
.
env
.
UNI_HBUILDERX_PLUGINS
)
{
return
}
const
{
bundle
,
UtsTarget
}
=
getUtsCompiler
()
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
let
time
=
Date
.
now
()
await
bundle
({
target
:
UtsTarget
.
KOTLIN
,
input
:
{
dir
:
path
.
join
(
process
.
env
.
UNI_INPUT_DIR
,
pluginDir
),
root
:
inputDir
,
filename
,
},
output
:
{
dir
:
path
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
pluginDir
)
,
outDir
:
outputDir
,
sourceMap
:
true
,
extname
:
''
,
extname
:
'
kt
'
,
},
})
console
.
log
(
'
uts compile time:
'
+
(
Date
.
now
()
-
time
)
+
'
ms
'
)
const
kotlinFile
=
resolveKotlinFile
(
filename
,
inputDir
,
outputDir
)
if
(
fs
.
existsSync
(
kotlinFile
))
{
time
=
Date
.
now
()
await
compileKotlin
(
kotlinFile
)
console
.
log
(
'
kotlin compile time:
'
+
(
Date
.
now
()
-
time
)
+
'
ms
'
)
const
jarFile
=
resolveJarPath
(
kotlinFile
)
if
(
fs
.
existsSync
(
jarFile
))
{
time
=
Date
.
now
()
await
d8
(
jarFile
)
console
.
log
(
'
d8 compile time:
'
+
(
Date
.
now
()
-
time
)
+
'
ms
'
)
}
}
}
function
resolveKotlinFile
(
filename
:
string
,
inputDir
:
string
,
outputDir
:
string
)
{
return
path
.
resolve
(
outputDir
,
path
.
relative
(
inputDir
,
filename
))
.
replace
(
path
.
extname
(
filename
),
'
.kt
'
)
}
function
resolveDirs
():
{
kotlinc
:
string
;
d8
:
string
;
lib
:
string
}
{
// eslint-disable-next-line no-restricted-globals
return
require
(
path
.
resolve
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
'
uts-kotlin-compiler
'
))
}
const
resolveKotlinc
=
once
(()
=>
{
const
{
kotlinc
}
=
resolveDirs
()
return
path
.
resolve
(
kotlinc
,
'
bin
'
,
'
kotlinc
'
+
(
os
.
platform
()
===
'
win32
'
?
'
.bat
'
:
''
)
)
})
async
function
compileKotlin
(
filename
:
string
)
{
const
kotlinc
=
resolveKotlinc
()
await
execa
(
kotlinc
,
[
filename
,
'
-cp
'
,
resolveClassPath
(),
'
-d
'
,
resolveJarPath
(
filename
)],
{
stdio
:
'
inherit
'
,
}
)
}
async
function
d8
(
filename
:
string
)
{
const
java
=
resolveJavaPath
()
const
d8
=
resolveD8Path
()
await
execa
(
java
,
[
'
-cp
'
,
d8
,
'
com.android.tools.r8.D8
'
,
filename
,
'
--min-api
'
,
'
19
'
,
'
--output
'
,
resolveDexPath
(
filename
),
],
{
stdio
:
'
inherit
'
,
}
)
}
function
resolveDexPath
(
filename
:
string
)
{
return
path
.
dirname
(
filename
)
}
function
resolveJarPath
(
filename
:
string
)
{
return
filename
.
replace
(
path
.
extname
(
filename
),
'
.jar
'
)
}
const
resolveBuiltInClassPath
=
once
(()
=>
{
const
libDir
=
resolveDirs
().
lib
return
fs
.
readdirSync
(
libDir
)
.
filter
((
file
)
=>
file
.
endsWith
(
'
.jar
'
))
.
map
((
file
)
=>
path
.
resolve
(
libDir
,
file
))
})
function
resolveClassPath
()
{
return
resolveBuiltInClassPath
().
join
(
os
.
platform
()
===
'
win32
'
?
'
;
'
:
'
:
'
)
}
const
resolveJavaPath
=
once
(()
=>
{
return
path
.
resolve
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
'
amazon-corretto
'
,
'
bin/java
'
)
})
const
resolveD8Path
=
once
(()
=>
{
const
{
d8
}
=
resolveDirs
()
return
path
.
resolve
(
d8
,
'
d8.jar
'
)
})
pnpm-lock.yaml
浏览文件 @
6846cb50
...
...
@@ -796,10 +796,14 @@ importers:
packages/uni-uts-vite
:
specifiers
:
'
@dcloudio/uni-cli-shared'
:
3.0.0-alpha-3050220220719003
'
@dcloudio/uni-shared'
:
3.0.0-alpha-3050220220719003
'
@dcloudio/uts'
:
3.0.0-alpha-3050220220719003
execa
:
^5.1.1
dependencies
:
'
@dcloudio/uni-cli-shared'
:
link:../uni-cli-shared
'
@dcloudio/uni-shared'
:
link:../uni-shared
'
@dcloudio/uts'
:
link:../uts
execa
:
5.1.1
packages/uni-vue
:
specifiers
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录