Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
5b14e4bb
U
uni-app
项目概览
DCloud
/
uni-app
2 个月 前同步成功
通知
717
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,发现更多精彩内容 >>
提交
5b14e4bb
编写于
6月 23, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore(test): easycom
上级
7d4f3fd6
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
49 addition
and
101 deletion
+49
-101
packages/shims-uni-app.d.ts
packages/shims-uni-app.d.ts
+2
-2
packages/uni-cli-shared/__tests__/easycom.spec.ts
packages/uni-cli-shared/__tests__/easycom.spec.ts
+2
-2
packages/uni-cli-shared/__tests__/examples/easycom/components/test/test.vue
...hared/__tests__/examples/easycom/components/test/test.vue
+0
-0
packages/uni-cli-shared/__tests__/examples/easycom/components/test1/test1.vue
...red/__tests__/examples/easycom/components/test1/test1.vue
+0
-0
packages/uni-cli-shared/__tests__/examples/easycom/pages.json
...ages/uni-cli-shared/__tests__/examples/easycom/pages.json
+0
-0
packages/uni-cli-shared/__tests__/examples/easycom/uni_modules/plugin/components/test/test.vue
...mples/easycom/uni_modules/plugin/components/test/test.vue
+0
-0
packages/uni-cli-shared/__tests__/examples/easycom/uni_modules/plugin/components/test2/test2.vue
...les/easycom/uni_modules/plugin/components/test2/test2.vue
+0
-0
packages/uni-cli-shared/src/json/app/pages.ts
packages/uni-cli-shared/src/json/app/pages.ts
+3
-19
packages/uni-cli-shared/src/json/pages.ts
packages/uni-cli-shared/src/json/pages.ts
+35
-0
packages/uni-h5-vite/dist/plugins/pagesJson.js
packages/uni-h5-vite/dist/plugins/pagesJson.js
+3
-32
packages/uni-h5-vite/src/plugins/pagesJson.ts
packages/uni-h5-vite/src/plugins/pagesJson.ts
+4
-46
未找到文件。
packages/shims-uni-app.d.ts
浏览文件 @
5b14e4bb
...
...
@@ -62,7 +62,7 @@ declare namespace UniApp {
alias
?:
string
meta
:
PageRouteMeta
component
?:
any
loader
:
()
=>
Promise
<
any
>
loader
?
:
()
=>
Promise
<
any
>
}
type
UniRoutes
=
UniRoute
[]
...
...
@@ -150,7 +150,7 @@ declare namespace UniApp {
onReachBottomDistance
?:
number
}
interface
PageRouteMeta
extends
PagesJsonPageStyle
{
id
:
number
id
?
:
number
route
:
string
isNVue
?:
boolean
isQuit
?:
boolean
...
...
packages/
vite-plugin-uni
/__tests__/easycom.spec.ts
→
packages/
uni-cli-shared
/__tests__/easycom.spec.ts
浏览文件 @
5b14e4bb
import
path
from
'
path
'
import
{
initEasycoms
,
matchEasycom
}
from
'
../src/
utils
'
import
{
initEasycoms
,
matchEasycom
}
from
'
../src/
easycom
'
const
rootDir
=
path
.
resolve
(
__dirname
,
'
example
'
)
const
rootDir
=
path
.
resolve
(
__dirname
,
'
example
s/easycom
'
)
describe
(
'
easycom
'
,
()
=>
{
test
(
'
initEasycom with dirs
'
,
()
=>
{
...
...
packages/
vite-plugin-uni/__tests__/example
/components/test/test.vue
→
packages/
uni-cli-shared/__tests__/examples/easycom
/components/test/test.vue
浏览文件 @
5b14e4bb
文件已移动
packages/
vite-plugin-uni/__tests__/example
/components/test1/test1.vue
→
packages/
uni-cli-shared/__tests__/examples/easycom
/components/test1/test1.vue
浏览文件 @
5b14e4bb
文件已移动
packages/
vite-plugin-uni/__tests__/example
/pages.json
→
packages/
uni-cli-shared/__tests__/examples/easycom
/pages.json
浏览文件 @
5b14e4bb
文件已移动
packages/
vite-plugin-uni/__tests__/example
/uni_modules/plugin/components/test/test.vue
→
packages/
uni-cli-shared/__tests__/examples/easycom
/uni_modules/plugin/components/test/test.vue
浏览文件 @
5b14e4bb
文件已移动
packages/
vite-plugin-uni/__tests__/example
/uni_modules/plugin/components/test2/test2.vue
→
packages/
uni-cli-shared/__tests__/examples/easycom
/uni_modules/plugin/components/test2/test2.vue
浏览文件 @
5b14e4bb
文件已移动
packages/uni-cli-shared/src/json/app/pages.ts
浏览文件 @
5b14e4bb
import
{
normalizeIdentifier
}
from
'
../../utils
'
import
{
normalizePagesRoute
}
from
'
../pages
'
export
function
normalizeAppPagesJson
(
pagesJson
:
Record
<
string
,
any
>
)
{
return
polyfillCode
+
restoreGlobalCode
+
definePageCode
(
pagesJson
)
...
...
@@ -40,7 +41,7 @@ if(uni.restoreGlobal){
export
function
normalizeAppConfigService
(
pagesJson
:
UniApp
.
PagesJson
)
{
return
`
;(function(){
const u=void 0
;
isReady=false,onReadyCallbacks=[],isServiceReady=false,onServiceReadyCallbacks=[];
const u=void 0
,
isReady=false,onReadyCallbacks=[],isServiceReady=false,onServiceReadyCallbacks=[];
const __uniConfig =
${
normalizeAppUniConfig
(
pagesJson
)}
;
const __uniRoutes =
${
normalizeAppUniRoutes
(
pagesJson
)}
;
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
...
...
@@ -56,24 +57,7 @@ function normalizeAppUniConfig(pagesJson: UniApp.PagesJson) {
return
JSON
.
stringify
(
pagesJson
.
globalStyle
)
}
function
normalizeAppUniRoutes
(
pagesJson
:
UniApp
.
PagesJson
)
{
const
uniRoutes
:
{
path
:
string
meta
:
Partial
<
UniApp
.
PageRouteMeta
>
style
:
UniApp
.
PagesJsonPageStyle
}[]
=
[]
pagesJson
.
pages
.
forEach
((
page
)
=>
{
uniRoutes
.
push
(
normalizeAppUniRoute
(
page
))
})
return
JSON
.
stringify
(
pagesJson
)
}
function
normalizeAppUniRoute
(
page
:
UniApp
.
PagesJsonPageOptions
)
{
const
pageMeta
:
Partial
<
UniApp
.
PageRouteMeta
>
=
{}
return
{
path
:
page
.
path
,
meta
:
pageMeta
,
style
:
page
.
style
,
}
return
JSON
.
stringify
(
normalizePagesRoute
(
pagesJson
))
}
function
normalizeGlobalStatement
(
globals
:
string
[])
{
...
...
packages/uni-cli-shared/src/json/pages.ts
浏览文件 @
5b14e4bb
...
...
@@ -281,3 +281,38 @@ function removePlatformStyle(pageStyle: UniApp.PagesJsonPageStyle) {
})
return
pageStyle
}
export
function
normalizePagesRoute
(
pagesJson
:
UniApp
.
PagesJson
):
UniApp
.
UniRoute
[]
{
const
firstPagePath
=
pagesJson
.
pages
[
0
].
path
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[]
return
pagesJson
.
pages
.
map
((
pageOptions
)
=>
{
const
pagePath
=
pageOptions
.
path
const
isEntry
=
firstPagePath
===
pagePath
?
true
:
undefined
const
tabBarIndex
=
tabBarList
.
findIndex
(
(
tabBarPage
:
{
pagePath
:
string
})
=>
tabBarPage
.
pagePath
===
pagePath
)
const
isTabBar
=
tabBarIndex
!==
-
1
?
true
:
undefined
const
isNVue
=
fs
.
existsSync
(
path
.
join
(
process
.
env
.
UNI_INPUT_DIR
,
pagePath
+
'
.nvue
'
)
)
let
windowTop
=
0
const
meta
=
extend
(
{
route
:
pageOptions
.
path
,
isNVue
:
isNVue
?
true
:
undefined
,
isQuit
:
isEntry
||
isTabBar
?
true
:
undefined
,
isEntry
,
isTabBar
,
tabBarIndex
,
windowTop
,
},
pageOptions
.
style
)
return
{
path
:
pageOptions
.
path
,
meta
,
}
})
}
packages/uni-h5-vite/dist/plugins/pagesJson.js
浏览文件 @
5b14e4bb
...
...
@@ -4,10 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
uniPagesJsonPlugin
=
void
0
;
const
fs_1
=
__importDefault
(
require
(
"
fs
"
));
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
slash_1
=
__importDefault
(
require
(
"
slash
"
));
const
shared_1
=
require
(
"
@vue/shared
"
);
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
pkg
=
require
(
'
@dcloudio/vite-plugin-uni/package.json
'
);
function
uniPagesJsonPlugin
()
{
...
...
@@ -152,39 +150,12 @@ function generatePagesDefineCode(pagesJson, _config) {
}
`
+
pages
.
map
((
pageOptions
)
=>
generatePageDefineCode
(
pageOptions
)).
join
(
'
\n
'
));
}
function
normalizePagesRoute
(
pagesJson
)
{
const
firstPagePath
=
pagesJson
.
pages
[
0
].
path
;
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[];
return
pagesJson
.
pages
.
map
((
pageOptions
)
=>
{
const
pagePath
=
pageOptions
.
path
;
const
name
=
uni_cli_shared_1
.
normalizeIdentifier
(
pagePath
);
const
isEntry
=
firstPagePath
===
pagePath
?
true
:
undefined
;
const
tabBarIndex
=
tabBarList
.
findIndex
((
tabBarPage
)
=>
tabBarPage
.
pagePath
===
pagePath
);
const
isTabBar
=
tabBarIndex
!==
-
1
?
true
:
undefined
;
const
isNVue
=
fs_1
.
default
.
existsSync
(
path_1
.
default
.
join
(
process
.
env
.
UNI_INPUT_DIR
,
pagePath
+
'
.nvue
'
));
let
windowTop
=
0
;
const
meta
=
shared_1
.
extend
({
route
:
pageOptions
.
path
,
isNVue
:
isNVue
?
true
:
undefined
,
isQuit
:
isEntry
||
isTabBar
?
true
:
undefined
,
isEntry
,
isTabBar
,
tabBarIndex
,
windowTop
,
},
pageOptions
.
style
);
return
{
name
,
path
:
pageOptions
.
path
,
meta
,
};
});
}
function
generatePageRoute
({
name
,
path
,
meta
},
config
)
{
function
generatePageRoute
({
path
,
meta
},
config
)
{
const
{
isEntry
}
=
meta
;
const
alias
=
isEntry
?
`\n alias:'/
${
path
}
',`
:
''
;
return
`{
path:'/
${
isEntry
?
''
:
path
}
',
${
alias
}
component:{setup(){return ()=>renderPage(
${
name
}
)}},
component:{setup(){return ()=>renderPage(
${
uni_cli_shared_1
.
normalizeIdentifier
(
path
)
}
)}},
loader:
${
uni_cli_shared_1
.
normalizeIdentifier
(
path
)}
Loader,
meta:
${
JSON
.
stringify
(
meta
)}
}`
;
...
...
@@ -198,7 +169,7 @@ function renderPage(component){
return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(component, { ref: "page" }, null, 512 /* NEED_PATCH */)]), _: 1 /* STABLE */}))
}
${
globalName
}
.__uniRoutes=[
${[
...
generatePagesRoute
(
normalizePagesRoute
(
pagesJson
),
config
),
...
generatePagesRoute
(
uni_cli_shared_1
.
normalizePagesRoute
(
pagesJson
),
config
),
].
join
(
'
,
'
)}
]`
;
}
function
generateConfig
(
globalName
,
pagesJson
,
config
)
{
...
...
packages/uni-h5-vite/src/plugins/pagesJson.ts
浏览文件 @
5b14e4bb
import
fs
from
'
fs
'
import
path
from
'
path
'
import
slash
from
'
slash
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
extend
}
from
'
@vue/shared
'
import
{
API_DEPS_CSS
,
FEATURE_DEFINES
,
...
...
@@ -11,6 +9,7 @@ import {
normalizeIdentifier
,
normalizePagesJson
,
defineUniPagesJsonPlugin
,
normalizePagesRoute
,
}
from
'
@dcloudio/uni-cli-shared
'
const
pkg
=
require
(
'
@dcloudio/vite-plugin-uni/package.json
'
)
...
...
@@ -37,12 +36,6 @@ export function uniPagesJsonPlugin(): Plugin {
})
}
interface
PageRouteOptions
{
name
:
string
path
:
string
meta
:
Partial
<
UniApp
.
PageRouteMeta
>
}
function
generatePagesJsonCode
(
ssr
:
boolean
|
undefined
,
jsonStr
:
string
,
...
...
@@ -190,57 +183,22 @@ function generatePagesDefineCode(
)
}
function
normalizePagesRoute
(
pagesJson
:
UniApp
.
PagesJson
):
PageRouteOptions
[]
{
const
firstPagePath
=
pagesJson
.
pages
[
0
].
path
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[]
return
pagesJson
.
pages
.
map
((
pageOptions
)
=>
{
const
pagePath
=
pageOptions
.
path
const
name
=
normalizeIdentifier
(
pagePath
)
const
isEntry
=
firstPagePath
===
pagePath
?
true
:
undefined
const
tabBarIndex
=
tabBarList
.
findIndex
(
(
tabBarPage
:
{
pagePath
:
string
})
=>
tabBarPage
.
pagePath
===
pagePath
)
const
isTabBar
=
tabBarIndex
!==
-
1
?
true
:
undefined
const
isNVue
=
fs
.
existsSync
(
path
.
join
(
process
.
env
.
UNI_INPUT_DIR
,
pagePath
+
'
.nvue
'
)
)
let
windowTop
=
0
const
meta
=
extend
(
{
route
:
pageOptions
.
path
,
isNVue
:
isNVue
?
true
:
undefined
,
isQuit
:
isEntry
||
isTabBar
?
true
:
undefined
,
isEntry
,
isTabBar
,
tabBarIndex
,
windowTop
,
},
pageOptions
.
style
)
return
{
name
,
path
:
pageOptions
.
path
,
meta
,
}
})
}
function
generatePageRoute
(
{
name
,
path
,
meta
}:
PageRouteOptions
,
{
path
,
meta
}:
UniApp
.
UniRoute
,
config
:
ResolvedConfig
)
{
const
{
isEntry
}
=
meta
const
alias
=
isEntry
?
`\n alias:'/
${
path
}
',`
:
''
return
`{
path:'/
${
isEntry
?
''
:
path
}
',
${
alias
}
component:{setup(){return ()=>renderPage(
${
n
ame
}
)}},
component:{setup(){return ()=>renderPage(
${
n
ormalizeIdentifier
(
path
)
}
)}},
loader:
${
normalizeIdentifier
(
path
)}
Loader,
meta:
${
JSON
.
stringify
(
meta
)}
}`
}
function
generatePagesRoute
(
pagesRouteOptions
:
PageRouteOptions
[],
pagesRouteOptions
:
UniApp
.
UniRoute
[],
config
:
ResolvedConfig
)
{
return
pagesRouteOptions
.
map
((
pageOptions
)
=>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录