Skip to content

Commit d5a83df

Browse files
committed
fix(core): fix subPackage cannot match the second-level dir
1 parent c46d28e commit d5a83df

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

packages/core/src/context.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ export class PageContext {
241241
const subPackages = this.pagesGlobConfig?.subPackages || []
242242

243243
for (const [dir, pages] of Object.entries(this.subPagesPath)) {
244-
const root = path.basename(dir)
244+
const basePath = slash(path.join(this.options.root, this.options.outDir))
245+
const root = slash(path.relative(basePath, dir))
245246

246247
const globPackage = subPackages?.find(v => v.root === root)
247248
subPageMaps[root] = await this.parsePages(pages, 'sub', globPackage?.pages)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
this is subPackage second-level dir about
4+
</div>
5+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
this is subPackage second-level dir home
4+
</div>
5+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
this is subPackage second-level dir about
4+
</div>
5+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
this is subPackage second-level dir home
4+
</div>
5+
</template>

test/generate.spec.ts

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect } from 'vitest'
1+
import { describe, expect, it } from 'vitest'
22
import type { UserPagesConfig } from '../packages/core/src'
33
import { PageContext } from '../packages/core/src'
44

@@ -172,4 +172,46 @@ describe('generate routes', () => {
172172
]"
173173
`)
174174
})
175+
176+
it('fix subPackage cannot match the second-level dir', async () => {
177+
const ctx = new PageContext({
178+
subPackages: [
179+
'packages/playground/src/pages-sub-pages/sub-activity',
180+
'packages/playground/src/pages-sub-pages/sub-main',
181+
],
182+
})
183+
await ctx.scanSubPages()
184+
await ctx.mergeSubPageMetaData()
185+
const routes = ctx.resolveSubRoutes()
186+
expect(routes).toMatchInlineSnapshot(`
187+
"[
188+
{
189+
"root": "../packages/playground/src/pages-sub-pages/sub-activity",
190+
"pages": [
191+
{
192+
"path": "pages/about/index",
193+
"type": "page"
194+
},
195+
{
196+
"path": "pages/home/index",
197+
"type": "page"
198+
}
199+
]
200+
},
201+
{
202+
"root": "../packages/playground/src/pages-sub-pages/sub-main",
203+
"pages": [
204+
{
205+
"path": "pages/about/index",
206+
"type": "page"
207+
},
208+
{
209+
"path": "pages/home/index",
210+
"type": "page"
211+
}
212+
]
213+
}
214+
]"
215+
`)
216+
})
175217
})

0 commit comments

Comments
 (0)