diff --git a/src/core/context.ts b/src/core/context.ts index 897d2a9da..2364967a3 100644 --- a/src/core/context.ts +++ b/src/core/context.ts @@ -105,10 +105,11 @@ export function createRoutesContext(options: ResolvedOptions) { const content = await fs.readFile(filePath, 'utf8') // TODO: cache the result of parsing the SFC so the transform can reuse the parsing node.hasDefinePage ||= content.includes('definePage') - const [definedPageNameAndPath, routeBlock] = await Promise.all([ - extractDefinePageNameAndPath(content, filePath), - getRouteBlock(filePath, options), - ]) + const definedPageNameAndPath = extractDefinePageNameAndPath( + content, + filePath + ) + const routeBlock = getRouteBlock(filePath, content, options) // TODO: should warn if hasDefinePage and customRouteBlock // if (routeBlock) logger.log(routeBlock) node.setCustomRouteBlock(filePath, { diff --git a/src/core/customBlock.ts b/src/core/customBlock.ts index 37b60e448..b8c8f5da4 100644 --- a/src/core/customBlock.ts +++ b/src/core/customBlock.ts @@ -1,15 +1,16 @@ import { SFCBlock, parse } from '@vue/compiler-sfc' -import fs from 'node:fs/promises' import { ResolvedOptions } from '../options' import JSON5 from 'json5' import { parse as YAMLParser } from 'yaml' import { RouteRecordRaw } from 'vue-router' import { warn } from './utils' -export async function getRouteBlock(path: string, options: ResolvedOptions) { - const content = await fs.readFile(path, 'utf8') - - const parsedSFC = await parse(content, { pad: 'space' }).descriptor +export function getRouteBlock( + path: string, + content: string, + options: ResolvedOptions +) { + const parsedSFC = parse(content, { pad: 'space' }).descriptor const blockStr = parsedSFC?.customBlocks.find((b) => b.type === 'route') if (!blockStr) return