Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
9b34d37e
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
720
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b34d37e
编写于
5月 06, 2023
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
bbe6c173
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
100 addition
and
39 deletion
+100
-39
packages/uni-app-uts/src/plugins/index.ts
packages/uni-app-uts/src/plugins/index.ts
+5
-3
packages/uni-app-uts/src/plugins/pagesJson.ts
packages/uni-app-uts/src/plugins/pagesJson.ts
+16
-3
packages/uni-app-uts/src/plugins/utils.ts
packages/uni-app-uts/src/plugins/utils.ts
+32
-0
packages/uni-app-uts/src/plugins/uvue/code/script.ts
packages/uni-app-uts/src/plugins/uvue/code/script.ts
+1
-3
packages/uni-components/dist/components.js
packages/uni-components/dist/components.js
+9
-12
packages/uni-uts-v1/__tests__/compiler.spec.ts
packages/uni-uts-v1/__tests__/compiler.spec.ts
+2
-0
packages/uni-uts-v1/src/index.ts
packages/uni-uts-v1/src/index.ts
+17
-4
packages/uni-uts-v1/src/kotlin.ts
packages/uni-uts-v1/src/kotlin.ts
+8
-4
packages/uni-uts-v1/src/swift.ts
packages/uni-uts-v1/src/swift.ts
+8
-4
packages/uni-uts-v1/src/utils.ts
packages/uni-uts-v1/src/utils.ts
+1
-0
packages/uni-uts-v1/src/uvue/index.ts
packages/uni-uts-v1/src/uvue/index.ts
+1
-6
packages/uts-darwin-arm64/uts.darwin-arm64.node
packages/uts-darwin-arm64/uts.darwin-arm64.node
+0
-0
packages/uts-darwin-x64/uts.darwin-x64.node
packages/uts-darwin-x64/uts.darwin-x64.node
+0
-0
packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node
packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node
+0
-0
packages/uts-linux-x64-musl/uts.linux-x64-musl.node
packages/uts-linux-x64-musl/uts.linux-x64-musl.node
+0
-0
packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
+0
-0
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
+0
-0
未找到文件。
packages/uni-app-uts/src/plugins/index.ts
浏览文件 @
9b34d37e
...
...
@@ -123,9 +123,11 @@ function normalizeCode(code: string, isMain = false) {
return
code
}
return
`
export function main() {
definePageRoutes()
createPage(__uniRoutes[0])
${
code
}
export function main(app: IApp) {
defineAppConfig();
definePageRoutes();
(createApp()['app'] as VueApp).mount(app);
}
`
}
packages/uni-app-uts/src/plugins/pagesJson.ts
浏览文件 @
9b34d37e
...
...
@@ -4,7 +4,7 @@ import { PAGES_JSON_UTS, normalizePagesJson } from '@dcloudio/uni-cli-shared'
import
type
{
OutputAsset
}
from
'
rollup
'
import
type
{
Plugin
}
from
'
vite
'
import
{
ENTRY_FILENAME
,
genClassName
}
from
'
./utils
'
import
{
ENTRY_FILENAME
,
genClassName
,
stringifyMap
}
from
'
./utils
'
function
isPages
(
id
:
string
)
{
return
id
.
endsWith
(
PAGES_JSON_UTS
)
...
...
@@ -40,7 +40,11 @@ export function uniAppPagesPlugin(): Plugin {
const
className
=
genClassName
(
page
.
path
)
imports
.
push
(
page
.
path
)
routes
.
push
(
`{ path: "
${
page
.
path
}
", component:
${
className
}
Class, meta: { isQuit: true, navigationBar: { titleText: "uni-app" } as PageNavigationBar } as PageMeta } as PageRoute`
`{ path: "
${
page
.
path
}
", component:
${
className
}
Class, meta: { isQuit: true } as PageMeta, style:
${
stringifyPageStyle
(
page
.
style
)}
} as PageRoute`
)
})
return
`
${
imports
.
map
((
p
)
=>
`import('./
${
p
}
.uvue')`
).
join
(
'
\n
'
)}
...
...
@@ -56,14 +60,23 @@ export default 'pages.json'`
${
imports
.
map
((
p
)
=>
{
const
className
=
genClassName
(
p
)
return
`import
{
${
className
}
Class }
from './
${
p
}
.uvue?type=page'`
return
`import
${
className
}
Class
from './
${
p
}
.uvue?type=page'`
})
.
join
(
'
\n
'
)}
function definePageRoutes() {
${
routes
.
map
((
route
)
=>
`__uniRoutes.push(
${
route
}
)`
).
join
(
'
\n
'
)}
}
function defineAppConfig(){
__uniConfig.entryPagePath = '/
${
imports
[
0
]}
'
}
`
}
},
}
}
function
stringifyPageStyle
(
pageStyle
:
UniApp
.
PagesJsonPageStyle
)
{
delete
pageStyle
.
isNVue
delete
pageStyle
.
isSubNVue
return
stringifyMap
(
pageStyle
)
}
packages/uni-app-uts/src/plugins/utils.ts
浏览文件 @
9b34d37e
...
...
@@ -29,3 +29,35 @@ export function genClassName(fileName: string) {
export
function
isVue
(
filename
:
string
)
{
return
filename
.
endsWith
(
'
.vue
'
)
||
filename
.
endsWith
(
'
.uvue
'
)
}
export
function
stringifyMap
(
obj
:
unknown
)
{
return
mapToInitString
(
objToMap
(
obj
as
Record
<
string
,
unknown
>
),
true
)
}
function
mapToInitString
(
map
:
Map
<
string
,
unknown
>
,
ts
:
boolean
=
false
):
string
{
let
entries
=
[]
for
(
let
[
key
,
value
]
of
map
)
{
if
(
value
instanceof
Map
)
{
entries
.
push
(
`["
${
key
}
",
${
mapToInitString
(
value
,
ts
)}
]`
)
}
else
{
entries
.
push
(
`["
${
key
}
",
${
JSON
.
stringify
(
value
)}
]`
)
}
}
return
`new Map
${
ts
?
'
<string, any>
'
:
''
}
([
${
entries
.
join
(
'
,
'
)}
])`
}
function
objToMap
(
obj
:
Record
<
string
,
unknown
>
)
{
const
map
=
new
Map
()
for
(
const
key
in
obj
)
{
const
value
=
obj
[
key
]
if
(
typeof
value
===
'
object
'
)
{
map
.
set
(
key
,
objToMap
(
value
as
Record
<
string
,
unknown
>
))
}
else
{
map
.
set
(
key
,
value
)
}
}
return
map
}
packages/uni-app-uts/src/plugins/uvue/code/script.ts
浏览文件 @
9b34d37e
...
...
@@ -2,18 +2,16 @@ import { SFCDescriptor } from '@vue/compiler-sfc'
export
function
genScript
(
{
script
}:
SFCDescriptor
,
{
filename
}
:
{
filename
:
string
}
_options
:
{
filename
:
string
}
)
{
if
(
!
script
)
{
return
`
export default {}
export const
${
filename
}
Class = UTSAndroid.getKotlinClass(
${
filename
}
)
`
}
return
(
'
\n
'
.
repeat
(
script
.
loc
.
start
.
line
-
1
)
+
`
${
script
.
content
}
export const
${
filename
}
Class = UTSAndroid.getKotlinClass(
${
filename
}
)
`
)
}
packages/uni-components/dist/components.js
浏览文件 @
9b34d37e
...
...
@@ -3237,19 +3237,11 @@ const Switch = /* @__PURE__ */ defineComponent({
watch
(()
=>
props2
.
checked
,
(
val
)
=>
{
switchChecked
.
value
=
val
;
});
const
listeners
=
{
onChange
(
e2
)
{
switchChecked
.
value
=
e2
.
detail
.
value
;
trigger
(
"
change
"
,
{
value
:
switchChecked
.
value
});
}
};
const
_onClick
=
(
$event
,
isLabelClick
)
=>
{
if
(
props2
.
disabled
)
{
return
;
}
switchChecked
.
value
=
!
switchChecked
.
value
;
switchChecked
.
value
=
$event
.
detail
?
$event
.
detail
.
value
:
!
switchChecked
.
value
;
trigger
(
"
change
"
,
{
value
:
switchChecked
.
value
});
...
...
@@ -3273,7 +3265,9 @@ const Switch = /* @__PURE__ */ defineComponent({
"
ref
"
:
rootRef
},
[
type
===
SwitchType
.
switch
?
createVNode
(
"
dc-switch
"
,
mergeProps
({
dataUncType
:
"
uni-switch
"
},
listeners
,
{
},
{
"
onChange
"
:
_onClick
},
{
checked
:
switchChecked
.
value
,
color
,
disabled
...
...
@@ -3284,8 +3278,11 @@ const Switch = /* @__PURE__ */ defineComponent({
color
}
},
{
checked
:
switchChecked
.
value
},
listeners
),
null
)
:
null
]);
checked
:
switchChecked
.
value
,
disabled
},
{
"
onClick
"
:
_onClick
}),
null
)
:
null
]);
};
}
});
...
...
packages/uni-uts-v1/__tests__/compiler.spec.ts
浏览文件 @
9b34d37e
...
...
@@ -23,6 +23,7 @@ describe('compiler', () => {
inputDir
,
outputDir
,
sourceMap
:
false
,
isPlugin
:
true
,
components
:
{},
})
expect
(
existsSync
(
kotlinFile
)).
toBeTruthy
()
...
...
@@ -37,6 +38,7 @@ describe('compiler', () => {
inputDir
,
outputDir
,
sourceMap
:
false
,
isPlugin
:
true
,
components
:
{},
})
expect
(
existsSync
(
swiftFile
)).
toBeTruthy
()
...
...
packages/uni-uts-v1/src/index.ts
浏览文件 @
9b34d37e
...
...
@@ -95,8 +95,13 @@ function createResult(
}
}
interface
CompilerOptions
{
isPlugin
:
boolean
}
export
async
function
compile
(
pluginDir
:
string
pluginDir
:
string
,
{
isPlugin
}:
CompilerOptions
=
{
isPlugin
:
true
}
):
Promise
<
CompileResult
|
void
>
{
const
pkg
=
resolvePackage
(
pluginDir
)
if
(
!
pkg
)
{
...
...
@@ -158,7 +163,11 @@ export async function compile(
filename
=
resolvePlatformIndexFilename
(
'
app-android
'
,
pluginDir
,
pkg
)
}
if
(
filename
)
{
await
getCompiler
(
'
kotlin
'
).
runProd
(
filename
,
androidComponents
)
await
getCompiler
(
'
kotlin
'
).
runProd
(
filename
,
androidComponents
,
isPlugin
)
if
(
cacheDir
)
{
// 存储 sourcemap
storeSourceMap
(
...
...
@@ -186,7 +195,7 @@ export async function compile(
filename
=
resolvePlatformIndexFilename
(
'
app-ios
'
,
pluginDir
,
pkg
)
}
if
(
filename
)
{
await
getCompiler
(
'
swift
'
).
runProd
(
filename
,
iosComponents
)
await
getCompiler
(
'
swift
'
).
runProd
(
filename
,
iosComponents
,
isPlugin
)
if
(
cacheDir
)
{
storeSourceMap
(
'
app-ios
'
,
...
...
@@ -311,7 +320,11 @@ export async function compile(
inputDir
,
outputDir
)
const
res
=
await
getCompiler
(
compilerType
).
runDev
(
filename
,
components
)
const
res
=
await
getCompiler
(
compilerType
).
runDev
(
filename
,
components
,
isPlugin
)
if
(
res
)
{
if
(
isArray
(
res
.
deps
)
&&
res
.
deps
.
length
)
{
// 添加其他文件的依赖
...
...
packages/uni-uts-v1/src/kotlin.ts
浏览文件 @
9b34d37e
...
...
@@ -62,7 +62,8 @@ function parseKotlinPackage(filename: string) {
export
async
function
runKotlinProd
(
filename
:
string
,
components
:
Record
<
string
,
string
>
components
:
Record
<
string
,
string
>
,
isPlugin
=
true
)
{
// 文件有可能是 app-ios 里边的,因为编译到 android 时,为了保证不报错,可能会去读取 ios 下的 uts
if
(
filename
.
includes
(
'
app-ios
'
))
{
...
...
@@ -75,6 +76,7 @@ export async function runKotlinProd(
outputDir
,
sourceMap
:
true
,
components
,
isPlugin
,
})
if
(
!
result
)
{
return
...
...
@@ -99,7 +101,8 @@ export type RunKotlinDevResult = UTSResult & {
export
async
function
runKotlinDev
(
filename
:
string
,
components
:
Record
<
string
,
string
>
components
:
Record
<
string
,
string
>
,
isPlugin
=
true
):
Promise
<
RunKotlinDevResult
|
undefined
>
{
// 文件有可能是 app-ios 里边的,因为编译到 android 时,为了保证不报错,可能会去读取 ios 下的 uts
if
(
filename
.
includes
(
'
app-ios
'
))
{
...
...
@@ -112,6 +115,7 @@ export async function runKotlinDev(
outputDir
,
sourceMap
:
true
,
components
,
isPlugin
,
}))
as
RunKotlinDevResult
if
(
!
result
)
{
return
...
...
@@ -305,7 +309,7 @@ const DEFAULT_IMPORTS = [
export
async
function
compile
(
filename
:
string
,
{
inputDir
,
outputDir
,
sourceMap
,
components
}:
ToKotlinOptions
{
inputDir
,
outputDir
,
sourceMap
,
components
,
isPlugin
}:
ToKotlinOptions
)
{
const
{
bundle
,
UTSTarget
}
=
getUTSCompiler
()
// let time = Date.now()
...
...
@@ -340,7 +344,7 @@ export async function compile(
const
result
=
await
bundle
(
UTSTarget
.
KOTLIN
,
{
input
,
output
:
{
isPlugin
:
true
,
isPlugin
,
outDir
:
outputDir
,
package
:
pluginPackage
,
sourceMap
:
sourceMap
?
resolveUTSSourceMapPath
()
:
false
,
...
...
packages/uni-uts-v1/src/swift.ts
浏览文件 @
9b34d37e
...
...
@@ -35,7 +35,8 @@ function parseSwiftPackage(filename: string) {
export
async
function
runSwiftProd
(
filename
:
string
,
components
:
Record
<
string
,
string
>
components
:
Record
<
string
,
string
>
,
isPlugin
=
true
)
{
// 文件有可能是 app-android 里边的,因为编译到 ios 时,为了保证不报错,可能会去读取 android 下的 uts
if
(
filename
.
includes
(
'
app-android
'
))
{
...
...
@@ -48,6 +49,7 @@ export async function runSwiftProd(
outputDir
,
sourceMap
:
true
,
components
,
isPlugin
,
})
if
(
!
result
)
{
return
...
...
@@ -75,7 +77,8 @@ export type RunSwiftDevResult = UTSResult & {
let
isEnvReady
=
true
export
async
function
runSwiftDev
(
filename
:
string
,
components
:
Record
<
string
,
string
>
components
:
Record
<
string
,
string
>
,
isPlugin
=
true
)
{
// 文件有可能是 app-android 里边的,因为编译到 ios 时,为了保证不报错,可能会去读取 android 下的 uts
if
(
filename
.
includes
(
'
app-android
'
))
{
...
...
@@ -106,6 +109,7 @@ export async function runSwiftDev(
outputDir
,
sourceMap
:
true
,
components
,
isPlugin
,
}))
as
RunSwiftDevResult
if
(
!
result
)
{
...
...
@@ -165,7 +169,7 @@ function isCliProject(projectPath: string) {
export
async
function
compile
(
filename
:
string
,
{
inputDir
,
outputDir
,
sourceMap
,
components
}:
ToSwiftOptions
{
inputDir
,
outputDir
,
sourceMap
,
components
,
isPlugin
}:
ToSwiftOptions
)
{
const
{
bundle
,
UTSTarget
}
=
getUTSCompiler
()
// let time = Date.now()
...
...
@@ -194,7 +198,7 @@ export async function compile(
const
result
=
await
bundle
(
UTSTarget
.
SWIFT
,
{
input
,
output
:
{
isPlugin
:
true
,
isPlugin
,
outDir
:
outputDir
,
package
:
namespace
,
sourceMap
:
sourceMap
?
resolveUTSSourceMapPath
()
:
false
,
...
...
packages/uni-uts-v1/src/utils.ts
浏览文件 @
9b34d37e
...
...
@@ -18,6 +18,7 @@ interface ToOptions {
outputDir
:
string
sourceMap
:
boolean
components
:
Record
<
string
,
string
>
isPlugin
:
boolean
}
export
type
ToKotlinOptions
=
ToOptions
export
type
ToSwiftOptions
=
ToOptions
...
...
packages/uni-uts-v1/src/uvue/index.ts
浏览文件 @
9b34d37e
...
...
@@ -22,12 +22,7 @@ const DEFAULT_IMPORTS = [
'
io.dcloud.uts.vue.*
'
,
'
io.dcloud.uts.vue.shared.*
'
,
'
io.dcloud.uts.vue.reactivity.*
'
,
'
io.dcloud.uniapp.appframe.*
'
,
'
io.dcloud.uniapp.interfaces.*
'
,
'
io.dcloud.uniapp.interfaces.htmlex.*
'
,
'
io.dcloud.uniapp.interfaces.htmlex.event.*
'
,
'
io.dcloud.uniapp.dom.*
'
,
'
io.dcloud.uniapp.dom.node.*
'
,
'
io.dcloud.uniapp.runtime.*
'
,
]
export
interface
CompileAppOptions
{
...
...
packages/uts-darwin-arm64/uts.darwin-arm64.node
浏览文件 @
9b34d37e
无法预览此类型文件
packages/uts-darwin-x64/uts.darwin-x64.node
浏览文件 @
9b34d37e
无法预览此类型文件
packages/uts-linux-x64-gnu/uts.linux-x64-gnu.node
浏览文件 @
9b34d37e
无法预览此类型文件
packages/uts-linux-x64-musl/uts.linux-x64-musl.node
浏览文件 @
9b34d37e
无法预览此类型文件
packages/uts-win32-ia32-msvc/uts.win32-ia32-msvc.node
浏览文件 @
9b34d37e
无法预览此类型文件
packages/uts-win32-x64-msvc/uts.win32-x64-msvc.node
浏览文件 @
9b34d37e
无法预览此类型文件
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录