-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: types for nuxt runtime hook
schema-org:meta
Fixes #33
- Loading branch information
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { addTemplate, createResolver, useNuxt } from '@nuxt/kit' | ||
import { relative } from 'pathe' | ||
|
||
export function extendTypes(module: string, template: (options: { typesPath: string }) => string | Promise<string>) { | ||
const nuxt = useNuxt() | ||
const { resolve } = createResolver(import.meta.url) | ||
// paths.d.ts | ||
addTemplate({ | ||
filename: `module/${module}.d.ts`, | ||
getContents: async () => { | ||
const typesPath = relative(resolve(nuxt!.options.rootDir, nuxt!.options.buildDir, 'module'), resolve('runtime/types')) | ||
const s = await template({ typesPath }) | ||
return `// Generated by ${module} | ||
${s} | ||
export {} | ||
` | ||
}, | ||
}) | ||
|
||
nuxt.hooks.hook('prepare:types', ({ references }) => { | ||
references.push({ path: resolve(nuxt.options.buildDir, `module/${module}.d.ts`) }) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import type { ModuleOptions } from '../module' | ||
import type { MetaInput } from '@unhead/schema-org' | ||
|
||
export type ModuleRuntimeConfig = Pick<ModuleOptions, 'scriptAttributes' | 'reactive' | 'minify'> & { version: string } | ||
|
||
export type { MetaInput } |