|
|
@ -14,11 +14,13 @@ import { resolveRewrites } from './rewritesPlugin'
|
|
|
|
|
|
|
|
|
|
|
|
export const dynamicRouteRE = /\[(\w+?)\]/g
|
|
|
|
export const dynamicRouteRE = /\[(\w+?)\]/g
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let fileToModulesMap: Record<string, Set<string>> = {}
|
|
|
|
|
|
|
|
|
|
|
|
export async function resolvePages(
|
|
|
|
export async function resolvePages(
|
|
|
|
srcDir: string,
|
|
|
|
srcDir: string,
|
|
|
|
userConfig: UserConfig,
|
|
|
|
userConfig: UserConfig,
|
|
|
|
logger: Logger
|
|
|
|
logger: Logger
|
|
|
|
) {
|
|
|
|
): Promise<Pick<SiteConfig, 'pages' | 'dynamicRoutes' | 'rewrites'>> {
|
|
|
|
// Important: tinyglobby doesn't guarantee order of the returned files.
|
|
|
|
// Important: tinyglobby doesn't guarantee order of the returned files.
|
|
|
|
// We must sort the pages so the input list to rollup is stable across
|
|
|
|
// We must sort the pages so the input list to rollup is stable across
|
|
|
|
// builds - otherwise different input order could result in different exports
|
|
|
|
// builds - otherwise different input order could result in different exports
|
|
|
@ -45,19 +47,19 @@ export async function resolvePages(
|
|
|
|
;(dynamicRouteRE.test(file) ? dynamicRouteFiles : pages).push(file)
|
|
|
|
;(dynamicRouteRE.test(file) ? dynamicRouteFiles : pages).push(file)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const dynamicRoutes = await resolveDynamicRoutes(
|
|
|
|
const { routes, fileToModulesMap: fileToModulesMap_ } =
|
|
|
|
srcDir,
|
|
|
|
await resolveDynamicRoutes(srcDir, dynamicRouteFiles, logger)
|
|
|
|
dynamicRouteFiles,
|
|
|
|
|
|
|
|
logger
|
|
|
|
pages.push(...routes.map((r) => r.path))
|
|
|
|
)
|
|
|
|
fileToModulesMap = fileToModulesMap_
|
|
|
|
pages.push(...dynamicRoutes.routes.map((r) => r.path))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rewrites = resolveRewrites(pages, userConfig.rewrites)
|
|
|
|
const rewrites = resolveRewrites(pages, userConfig.rewrites)
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
pages,
|
|
|
|
pages,
|
|
|
|
dynamicRoutes,
|
|
|
|
dynamicRoutes: { routes },
|
|
|
|
rewrites,
|
|
|
|
rewrites,
|
|
|
|
|
|
|
|
// @ts-expect-error internal flag to reload resolution cache in ../markdownToVue.ts
|
|
|
|
__dirty: true
|
|
|
|
__dirty: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -97,8 +99,6 @@ export type ResolvedRouteConfig = UserRouteConfig & {
|
|
|
|
fullPath: string
|
|
|
|
fullPath: string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fileToModulesMap: Record<string, Set<string>> = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const dynamicRoutesPlugin = async (
|
|
|
|
export const dynamicRoutesPlugin = async (
|
|
|
|
config: SiteConfig
|
|
|
|
config: SiteConfig
|
|
|
|
): Promise<Plugin> => {
|
|
|
|
): Promise<Plugin> => {
|
|
|
|