Skip to content

Commit 5ab0251

Browse files
fix(quasar): replace require() by readFileSync() in QuasarResolver (#339)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 13bf248 commit 5ab0251

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/core/resolvers/quasar.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
import { promises as fs } from 'fs'
3+
import { resolveModule } from 'local-pkg'
24
import type { ComponentResolver } from '../../types'
35

46
/**
@@ -7,16 +9,15 @@ import type { ComponentResolver } from '../../types'
79
* @link https://github.com/quasarframework/quasar
810
*/
911
export function QuasarResolver(): ComponentResolver {
12+
let components: unknown[] = []
13+
1014
return {
1115
type: 'component',
12-
resolve: (name: string) => {
13-
let components = []
14-
15-
try {
16-
/* eslint-disable @typescript-eslint/no-var-requires */
17-
components = require('quasar/dist/transforms/api-list.json')
18-
}
19-
catch (e) {
16+
resolve: async(name: string) => {
17+
if (!components.length) {
18+
const quasarApiListPath = resolveModule('quasar/dist/transforms/api-list.json')
19+
if (quasarApiListPath)
20+
components = JSON.parse(await fs.readFile(quasarApiListPath, 'utf-8'))
2021
}
2122

2223
if (components.includes(name))

0 commit comments

Comments
 (0)