Skip to content

Commit f4f5284

Browse files
authored
fix: fix error of empty subPackage in the applet devtools (#167)
1 parent d97a8af commit f4f5284

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/core/src/context.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ export class PageContext {
255255
subPageMaps[root] = pages || []
256256
}
257257

258-
const subPageMetaData = Object.keys(subPageMaps).map(root => ({ root, pages: subPageMaps[root] }))
258+
const subPageMetaData = Object.keys(subPageMaps)
259+
.map(root => ({ root, pages: subPageMaps[root] }))
260+
.filter(meta => meta.pages.length > 0)
259261

260262
this.subPageMetaData = subPageMetaData
261263
debug.subPages(this.subPageMetaData)

test/generate.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,34 @@ describe('generate routes', () => {
214214
]"
215215
`)
216216
})
217+
218+
it('check pages is exist', async () => {
219+
const ctx = new PageContext({
220+
subPackages: [
221+
'packages/playground/src/pages-sub-empty',
222+
'packages/playground/src/pages-sub-pages/sub-main',
223+
],
224+
})
225+
await ctx.scanSubPages()
226+
await ctx.mergeSubPageMetaData()
227+
const routes = ctx.resolveSubRoutes()
228+
229+
expect(routes).toMatchInlineSnapshot(`
230+
"[
231+
{
232+
"root": "../packages/playground/src/pages-sub-pages/sub-main",
233+
"pages": [
234+
{
235+
"path": "pages/about/index",
236+
"type": "page"
237+
},
238+
{
239+
"path": "pages/home/index",
240+
"type": "page"
241+
}
242+
]
243+
}
244+
]"
245+
`)
246+
})
217247
})

0 commit comments

Comments
 (0)