6
6
addServerHandler ,
7
7
addServerImportsDir ,
8
8
addServerPlugin ,
9
+ addTypeTemplate ,
9
10
createResolver ,
10
11
defineNuxtModule ,
11
12
hasNuxtModule ,
@@ -19,11 +20,13 @@ import { withoutTrailingSlash, withTrailingSlash } from 'ufo'
19
20
import { AiBots , NonHelpfulBots } from './const'
20
21
import { setupDevToolsUI } from './devtools'
21
22
import { resolveI18nConfig , splitPathForI18nLocales } from './i18n'
22
- import { extendTypes , isNuxtGenerate , resolveNitroPreset } from './kit'
23
+ import { isNuxtGenerate , resolveNitroPreset } from './kit'
23
24
import { logger } from './logger'
24
25
import {
25
- asArray ,
26
26
normaliseRobotsRouteRule ,
27
+ } from './runtime/server/nitro'
28
+ import {
29
+ asArray ,
27
30
normalizeGroup ,
28
31
parseRobotsTxt ,
29
32
validateRobots ,
@@ -461,8 +464,40 @@ export default defineNuxtModule<ModuleOptions>({
461
464
}
462
465
} )
463
466
464
- extendTypes ( 'nuxt-robots' , ( { typesPath } ) => {
465
- return `
467
+ addTypeTemplate ( {
468
+ filename : 'module/nuxt-robots.d.ts' ,
469
+ getContents : ( data ) => {
470
+ const typesPath = relative ( resolve ( data . nuxt ! . options . rootDir , data . nuxt ! . options . buildDir , 'module' ) , resolve ( 'runtime/types' ) )
471
+ return `// Generated by nuxt-robots
472
+
473
+ import type { RobotsContext } from '#robots/types'
474
+
475
+ declare module 'nitropack/types' {
476
+ interface NitroApp {
477
+ _robots: {
478
+ ctx: import('${ typesPath } ').HookRobotsConfigContext
479
+ nuxtContentUrls?: Set<string>
480
+ },
481
+ _robotsRuleMatcher: (url: string) => string
482
+ }
483
+ interface NitroRouteRules {
484
+ robots?: boolean | string | {
485
+ indexable: boolean
486
+ rule: string
487
+ }
488
+ }
489
+ interface NitroRouteConfig {
490
+ robots?: boolean | string | {
491
+ indexable: boolean
492
+ rule: string
493
+ }
494
+ }
495
+ interface NitroRuntimeHooks {
496
+ 'robots:config': (ctx: import('${ typesPath } ').HookRobotsConfigContext) => void | Promise<void>
497
+ 'robots:robots-txt': (ctx: import('${ typesPath } ').HookRobotsTxtContext) => void | Promise<void>
498
+ }
499
+ }
500
+
466
501
declare module 'nitropack' {
467
502
interface NitroApp {
468
503
_robots: {
@@ -488,13 +523,18 @@ declare module 'nitropack' {
488
523
'robots:robots-txt': (ctx: import('${ typesPath } ').HookRobotsTxtContext) => void | Promise<void>
489
524
}
490
525
}
526
+
491
527
declare module 'h3' {
492
- import type { RobotsContext } from '#robots/types'
493
528
interface H3EventContext {
494
529
robots: RobotsContext
495
530
}
496
531
}
532
+
533
+ export {}
497
534
`
535
+ } ,
536
+ } , {
537
+ nitro : true ,
498
538
} )
499
539
500
540
// only prerender for `nuxi generate`
0 commit comments