import * as fs from 'fs' ; import type { SFCDescriptor } from 'vue/compiler-sfc' ; import { parse } from 'vue/compiler-sfc' ; const cache = new Map < string , SFCDescriptor > ( ) ; export function setDescriptor ( filename , entry ) { cache . set ( cleanQuery ( filename ) , entry ) ; } export function getDescriptor ( filename ) { filename = cleanQuery ( filename ) ; if ( cache . has ( filename ) ) { return cache . get ( filename ) ! ; } const source = fs . readFileSync ( filename , 'utf-8' ) ; const { descriptor } = parse ( source , { filename , sourceMap : true , } ) ; cache . set ( filename , descriptor ) ; return descriptor ; } function cleanQuery ( str ) { const i = str . indexOf ( '?' ) ; return i > 0 ? str . slice ( 0 , i ) : str ; }