Skip to content

Commit

Permalink
fix: broken nitro types
Browse files Browse the repository at this point in the history
Fixes #93
  • Loading branch information
harlan-zw committed May 22, 2024
1 parent 1008a1a commit 018210a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/util/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ export async function getNuxtModuleOptions(module: string | NuxtModule, nuxt: Nu
export function extendTypes(module: string, template: (options: { typesPath: string }) => MaybePromise<string>) {
const nuxt = useNuxt()
const { resolve } = createResolver(import.meta.url)
const fileName = `${module.replace('/', '-')}.d.ts`
// paths.d.ts
addTemplate({
filename: `module/${module}.d.ts`,
filename: `module/${fileName}`,
getContents: async () => {
const typesPath = relative(resolve(nuxt!.options.rootDir, nuxt!.options.buildDir, 'module'), resolve('runtime/types'))
const typesPath = relative(resolve(nuxt!.options.rootDir, nuxt!.options.buildDir, 'module'), resolve('../runtime/types'))
const s = await template({ typesPath })
return `// Generated by ${module}
${s}
Expand All @@ -55,14 +56,14 @@ export {}
})

nuxt.hooks.hook('prepare:types', ({ references }) => {
references.push({ path: resolve(nuxt.options.buildDir, `module/${module}.d.ts`) })
references.push({ path: resolve(nuxt.options.buildDir, `module/${fileName}`) })
})

nuxt.hooks.hook('nitro:config', (config) => {
config.typescript = config.typescript || {}
config.typescript.tsConfig = config.typescript.tsConfig || {}
config.typescript.tsConfig.include = config.typescript.tsConfig.include || []
config.typescript.tsConfig.include.push(`./module/${module}.d.ts`)
config.typescript.tsConfig.include.push(`./module/${fileName}`)
})
}

Expand Down

0 comments on commit 018210a

Please sign in to comment.