Skip to content

Commit

Permalink
fix(i18n): resolve inline @nuxtjs/i18n options
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Nov 22, 2023
1 parent be47d00 commit 08141d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/runtime/sitemap/urlset/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export async function fetchDataSource(input: SitemapSourceBase | SitemapSourceRe
}
catch (_err) {
const error = (_err as FetchError)
if (error.message.includes('This operation was aborted')) {
if (error.message.includes('This operation was aborted'))
context.tips.push('The request has taken too long. Make sure app sources respond within 5 seconds or adjust the timeout fetch option.')
} else {
else
context.tips.push(`Response returned a status of ${error.response?.status || 'unknown'}.`)
}

console.error('[nuxt-simple-sitemap] Failed to fetch source.', { url, error })
return {
...input,
Expand Down
30 changes: 16 additions & 14 deletions src/util/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ import type { MaybePromise } from '../runtime/types'
export async function getNuxtModuleOptions(module: string | NuxtModule, nuxt: Nuxt = useNuxt()) {
const moduleMeta = (typeof module === 'string' ? { name: module } : await module.getMeta?.()) || {}
const { nuxtModule } = (await loadNuxtModuleInstance(module, nuxt))
const inlineOptions = (
await Promise.all(
nuxt.options.modules
.filter(async (m) => {
if (!Array.isArray(m))
return false
const _module = m[0]
return typeof module === 'object'
? (await (_module as any as NuxtModule).getMeta?.() === moduleMeta.name)
: _module === moduleMeta.name
})
.map(m => m?.[1 as keyof typeof m]),
)
)[0] || {}

let moduleEntry: [string | NuxtModule, Record<string, any>] | undefined
for (const m of nuxt.options.modules) {
if (Array.isArray(m) && m.length >= 2) {
const _module = m[0]
const _moduleEntryName = typeof _module === 'string'
? _module
: (await (_module as any as NuxtModule).getMeta?.())?.name || ''
if (_moduleEntryName === moduleMeta.name)
moduleEntry = m as [string | NuxtModule, Record<string, any>]
}
}

let inlineOptions = {}
if (moduleEntry)
inlineOptions = moduleEntry[1]
if (nuxtModule.getOptions)
return nuxtModule.getOptions(inlineOptions, nuxt)
return inlineOptions
Expand Down

0 comments on commit 08141d7

Please sign in to comment.