Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
b2ad3848
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
750
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看板
提交
b2ad3848
编写于
12月 18, 2023
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uvue): setup
上级
8a971170
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
104 addition
and
31 deletion
+104
-31
packages/uni-app-uts/src/plugins/android/uvue/sfc/compiler/script/context.ts
...s/src/plugins/android/uvue/sfc/compiler/script/context.ts
+1
-1
packages/uni-app-uts/src/plugins/android/uvue/sfc/main.ts
packages/uni-app-uts/src/plugins/android/uvue/sfc/main.ts
+77
-26
packages/uni-app-uts/src/plugins/utils.ts
packages/uni-app-uts/src/plugins/utils.ts
+12
-0
packages/uni-cli-shared/src/utils.ts
packages/uni-cli-shared/src/utils.ts
+11
-0
packages/uni-components/lib-x/unicloud-db/unicloud-db.vue
packages/uni-components/lib-x/unicloud-db/unicloud-db.vue
+0
-1
packages/vite-plugin-uni/src/vue/options.ts
packages/vite-plugin-uni/src/vue/options.ts
+3
-3
未找到文件。
packages/uni-app-uts/src/plugins/android/uvue/sfc/compiler/script/context.ts
浏览文件 @
b2ad3848
...
...
@@ -142,7 +142,7 @@ export function resolveParserPlugins(
}
plugins
.
push
([
'
typescript
'
,
{
dts
}])
if
(
!
userPlugins
||
!
userPlugins
.
includes
(
'
decorators
'
))
{
plugins
.
push
(
'
decorators
-legacy
'
)
plugins
.
push
(
'
decorators
'
)
}
if
(
userPlugins
)
{
plugins
.
push
(...
userPlugins
)
...
...
packages/uni-app-uts/src/plugins/android/uvue/sfc/main.ts
浏览文件 @
b2ad3848
import
fs
from
'
node:fs
'
import
path
from
'
node:path
'
import
type
{
SFCBlock
,
SFCDescriptor
}
from
'
@vue/compiler-sfc
'
import
type
{
...
...
@@ -22,14 +21,12 @@ import {
}
from
'
@dcloudio/uni-cli-shared
'
import
type
{
CompilerError
,
Position
}
from
'
@vue/compiler-core
'
import
type
{
ImportSpecifier
}
from
'
es-module-lexer
'
import
{
createDescriptor
,
getDescriptor
,
setSrcDescriptor
,
}
from
'
../descriptorCache
'
import
{
createDescriptor
,
setSrcDescriptor
}
from
'
../descriptorCache
'
import
{
resolveScript
,
scriptIdentifier
}
from
'
./script
'
import
type
{
ResolvedOptions
}
from
'
./index
'
import
{
addAutoImports
,
addExtApiComponents
,
createResolveError
,
genClassName
,
parseImports
,
...
...
@@ -39,22 +36,22 @@ import {
}
from
'
../../utils
'
import
{
genTemplateCode
}
from
'
../code/template
'
import
{
generateCodeFrameColumns
}
from
'
@dcloudio/uni-cli-shared
'
import
{
genComponentPublicInstanceImported
}
from
'
../compiler/utils
'
export
async
function
transformMain
(
code
:
string
,
filename
:
string
,
options
:
ResolvedOptions
,
pluginContext
:
TransformPluginContext
pluginContext
:
TransformPluginContext
,
isAppVue
:
boolean
=
false
)
{
if
(
!
options
.
compiler
)
{
options
.
compiler
=
require
(
'
@vue/compiler-sfc
'
)
}
const
relativeFileName
=
parseUTSRelativeFilename
(
filename
)
const
{
descriptor
,
errors
}
=
createDescriptor
(
filename
,
code
,
options
)
if
(
fs
.
existsSync
(
filename
))
{
// populate descriptor cache for HMR if it's not set yet
getDescriptor
(
filename
,
options
,
true
)
}
if
(
errors
.
length
)
{
errors
.
forEach
((
error
)
=>
pluginContext
.
error
(
createRollupError
(
''
,
filename
,
error
,
code
))
...
...
@@ -69,14 +66,20 @@ export async function transformMain(
)
const
className
=
genClassName
(
relativeFileName
)
const
inputRoot
=
normalizePath
(
options
.
root
)
const
templateStartLine
=
descriptor
.
template
?.
loc
.
start
.
line
??
0
// template
const
{
code
:
templateCode
,
map
:
templateMap
}
=
await
genTemplateCode
(
descriptor
,
{
let
templateCode
=
''
let
templateMap
=
undefined
let
templateImportsCode
=
''
let
templateImportEasyComponentsCode
=
''
let
templateImportUTSComponentsCode
=
''
if
(
!
isAppVue
)
{
// template
const
inputRoot
=
normalizePath
(
options
.
root
)
const
templateStartLine
=
descriptor
.
template
?.
loc
.
start
.
line
??
0
const
templateResult
=
await
genTemplateCode
(
descriptor
,
{
...
options
,
mode
:
'
function
'
,
rootDir
:
options
.
root
,
filename
:
relativeFileName
,
className
,
prefixIdentifiers
:
true
,
...
...
@@ -104,13 +107,50 @@ export async function transformMain(
onTemplateLog
(
'
error
'
,
error
,
code
,
relativeFileName
,
templateStartLine
)
},
parseUTSComponent
,
})
templateCode
=
templateResult
.
code
templateMap
=
templateResult
.
map
const
{
easyComponentAutoImports
,
elements
,
importEasyComponents
,
importUTSComponents
,
imports
,
}
=
templateResult
templateImportEasyComponentsCode
=
importEasyComponents
.
join
(
'
\n
'
)
templateImportUTSComponentsCode
=
importUTSComponents
.
join
(
'
\n
'
)
templateImportsCode
=
imports
.
join
(
'
\n
'
)
Object
.
keys
(
easyComponentAutoImports
).
forEach
((
source
)
=>
{
addAutoImports
(
source
,
easyComponentAutoImports
[
source
])
})
if
(
process
.
env
.
NODE_ENV
===
'
production
'
)
{
addExtApiComponents
(
elements
.
filter
((
element
)
=>
{
// 如果是UTS原生组件,则无需记录摇树
if
(
parseUTSComponent
(
element
,
'
kotlin
'
))
{
return
false
}
return
true
})
)
}
)
}
// styles
const
stylesCode
=
await
genStyleCode
(
descriptor
,
pluginContext
)
const
output
:
string
[]
=
[
scriptCode
,
templateCode
,
`/*
${
className
}
Styles*/`
]
const
utsOutput
:
string
[]
=
[
scriptCode
||
`
export default {}
`
,
templateCode
,
`/*
${
className
}
Styles*/`
,
]
let
resolvedMap
:
RawSourceMap
|
undefined
=
undefined
if
(
options
.
sourceMap
)
{
...
...
@@ -155,7 +195,7 @@ export async function transformMain(
}
// handle TS transpilation
let
resolvedCode
=
o
utput
.
join
(
'
\n
'
)
const
utsCode
=
utsO
utput
.
join
(
'
\n
'
)
if
(
resolvedMap
)
{
pluginContext
.
emitFile
({
...
...
@@ -165,11 +205,16 @@ export async function transformMain(
})
}
const
jsCodes
=
[]
if
(
resolvedCode
)
{
const
jsCodes
=
[
templateImportEasyComponentsCode
,
templateImportUTSComponentsCode
,
templateImportsCode
,
]
// 仅需要再解析script中的import,template上边已经加入了
if
(
scriptCode
)
{
jsCodes
.
push
(
await
parseImports
(
resolved
Code
,
script
Code
,
resolvedMap
?
createTryResolve
(
filename
,
pluginContext
.
resolve
,
resolvedMap
)
:
undefined
...
...
@@ -178,15 +223,21 @@ export async function transformMain(
pluginContext
.
emitFile
({
type
:
'
asset
'
,
fileName
:
relativeFileName
,
source
:
resolved
Code
,
source
:
uts
Code
,
})
}
if
(
stylesCode
)
{
jsCodes
.
push
(
stylesCode
)
}
jsCodes
.
push
(
`export default "
${
className
}
"
export const
${
genComponentPublicInstanceImported
(
options
.
root
,
relativeFileName
)}
= {}`
)
const
jsCode
=
jsCodes
.
filter
(
Boolean
).
join
(
'
\n
'
)
return
{
code
:
jsCode
s
.
join
(
'
\n
'
)
,
code
:
jsCode
,
map
:
{
mappings
:
''
,
}
as
SourceMapInput
,
...
...
packages/uni-app-uts/src/plugins/utils.ts
浏览文件 @
b2ad3848
import
path
from
'
node:path
'
import
{
MANIFEST_JSON_UTS
,
PAGES_JSON_UTS
,
...
...
@@ -5,6 +6,8 @@ import {
UniVitePlugin
,
initI18nOptions
,
injectAssetPlugin
,
normalizeNodeModules
,
normalizePath
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
compileI18nJsonStr
}
from
'
@dcloudio/uni-i18n
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
...
...
@@ -96,3 +99,12 @@ export function configResolved(config: ResolvedConfig, isAndroidX = false) {
config
.
build
.
assetsInlineLimit
=
0
injectAssetPlugin
(
config
,
{
isAndroidX
})
}
export
function
relativeInputDir
(
filename
:
string
)
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
filename
=
normalizeNodeModules
(
filename
)
if
(
filename
.
startsWith
(
inputDir
))
{
return
normalizePath
(
path
.
relative
(
inputDir
,
filename
))
}
return
filename
}
packages/uni-cli-shared/src/utils.ts
浏览文件 @
b2ad3848
...
...
@@ -20,6 +20,7 @@ import {
}
from
'
@vue/compiler-core
'
import
{
ParserPlugin
}
from
'
@babel/parser
'
import
{
getPlatformDir
}
from
'
./platform
'
import
{
isInHBuilderX
}
from
'
./hbx
'
export
const
version
=
require
(
'
../package.json
'
).
version
...
...
@@ -76,6 +77,16 @@ export function normalizeNodeModules(str: string) {
/.*
\/
plugins
\/
uniapp-cli-vite
\/
node
[
-_
]
modules/
,
'
node-modules
'
)
if
(
!
isInHBuilderX
())
{
// 内部测试
if
(
str
.
includes
(
'
uni-app-next/packages/
'
))
{
str
=
str
.
replace
(
/.*
\/
uni-app-next
\/
packages
\/
/
,
'
node-modules/@dcloudio/
'
)
}
}
if
(
process
.
env
.
UNI_PLATFORM
===
'
mp-alipay
'
)
{
str
=
str
.
replace
(
'
node-modules/@
'
,
'
node-modules/npm-scope-
'
)
}
...
...
packages/uni-components/lib-x/unicloud-db/unicloud-db.vue
浏览文件 @
b2ad3848
...
...
@@ -93,7 +93,6 @@
complete
?:
CompleteCallback
,
}
@
Suppress
(
"
UNCHECKED_CAST
"
)
function
cast_callback
<
T
>
(
options
:
any
|
null
)
:
T
|
null
{
return
options
as
T
|
null
}
...
...
packages/vite-plugin-uni/src/vue/options.ts
浏览文件 @
b2ad3848
...
...
@@ -173,9 +173,9 @@ export function initPluginVueOptions(
if
(
!
vueOptions
.
script
.
babelParserPlugins
.
includes
(
'
typescript
'
))
{
vueOptions
.
script
.
babelParserPlugins
.
push
(
'
typescript
'
)
}
//
TODO 是不是应该 decorators
if
(
!
vueOptions
.
script
.
babelParserPlugins
.
includes
(
'
decorators
-legacy
'
))
{
vueOptions
.
script
.
babelParserPlugins
.
push
(
'
decorators
-legacy
'
)
//
decorators or decorators-legacy
if
(
!
vueOptions
.
script
.
babelParserPlugins
.
includes
(
'
decorators
'
))
{
vueOptions
.
script
.
babelParserPlugins
.
push
(
'
decorators
'
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录