Skip to content

Commit

Permalink
fix: use jiti to load custom font providers
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 20, 2024
1 parent 59e1189 commit a840e4d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"fontaine": "^0.4.1",
"globby": "^14.0.1",
"h3": "^1.10.2",
"jiti": "^1.21.0",
"magic-string": "^0.30.7",
"ofetch": "^1.3.3",
"ohash": "^1.1.3",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { addBuildPlugin, addTemplate, defineNuxtModule, resolveAlias, resolvePath, useLogger } from '@nuxt/kit'
import { addBuildPlugin, addTemplate, defineNuxtModule, resolveAlias, resolvePath, useLogger, useNuxt } from '@nuxt/kit'
import jiti from 'jiti'

import google from './providers/google'
import local from './providers/local'
Expand Down Expand Up @@ -140,14 +141,17 @@ export default defineNuxtModule<ModuleOptions>({
})

async function resolveProviders (_providers: ModuleOptions['providers'] = {}) {
const nuxt = useNuxt()
const _jiti = jiti(nuxt.options.rootDir, { interopDefault: true })

const providers = { ..._providers }
for (const key in providers) {
const value = providers[key]
if (value === false) {
delete providers[key]
}
if (typeof value === 'string') {
providers[key] = await import(await resolvePath(resolveAlias(value)))
providers[key] = await _jiti(await resolvePath(resolveAlias(value)))
}
}
return providers as Record<string, FontProvider>
Expand Down

0 comments on commit a840e4d

Please sign in to comment.