Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export function formatPagePath(root: string, path: string) {
export function loadPagesJson(path: string, rootPath: string): string[] {
const pagesJsonRaw = readFileSync(path, 'utf-8')

const { pages = [], subPackages = [] } = jsonParse(pagesJsonRaw)
const pagesJson = jsonParse(pagesJsonRaw)
const { pages = [] } = pagesJson
const subPackages = pagesJson.subPackages ?? pagesJson.subpackages ?? []

return [
...pages
Expand Down
34 changes: 34 additions & 0 deletions test/transform.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'

import { afterEach, describe, expect, it } from 'vitest'

import { loadPagesJson } from '../src/utils'

const tempDirectories: string[] = []

afterEach(() => {
tempDirectories.splice(0).forEach(directory => rmSync(directory, { recursive: true, force: true }))
})

describe('loadPagesJson', () => {
it.each(['subPackages', 'subpackages'])('loads pages from %s', (subPackagesKey) => {
const directory = mkdtempSync(join(tmpdir(), 'uni-ku-root-'))
const pagesJsonPath = join(directory, 'pages.json')
tempDirectories.push(directory)

writeFileSync(pagesJsonPath, JSON.stringify({
pages: [{ path: 'pages/index' }],
[subPackagesKey]: [{
root: 'packages/example',
pages: [{ path: 'pages/detail' }],
}],
}))

expect(loadPagesJson(pagesJsonPath, '/project/src')).toEqual([
'/project/src/pages/index.vue',
'/project/src/packages/example/pages/detail.vue',
])
})
})