Skip to content

Commit

Permalink
fix(quasar): replace require() by readFileSync() in QuasarResolver (#339
Browse files Browse the repository at this point in the history
)

Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
stefanvanherwijnen and antfu authored Mar 26, 2022
1 parent 13bf248 commit 5ab0251
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/core/resolvers/quasar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import { promises as fs } from 'fs'
import { resolveModule } from 'local-pkg'
import type { ComponentResolver } from '../../types'

/**
Expand All @@ -7,16 +9,15 @@ import type { ComponentResolver } from '../../types'
* @link https://github.com/quasarframework/quasar
*/
export function QuasarResolver(): ComponentResolver {
let components: unknown[] = []

return {
type: 'component',
resolve: (name: string) => {
let components = []

try {
/* eslint-disable @typescript-eslint/no-var-requires */
components = require('quasar/dist/transforms/api-list.json')
}
catch (e) {
resolve: async(name: string) => {
if (!components.length) {
const quasarApiListPath = resolveModule('quasar/dist/transforms/api-list.json')
if (quasarApiListPath)
components = JSON.parse(await fs.readFile(quasarApiListPath, 'utf-8'))
}

if (components.includes(name))
Expand Down

0 comments on commit 5ab0251

Please sign in to comment.