Skip to content

Commit 36e23da

Browse files
committedJul 13, 2024·
fix: stub in mock composables when module disabled
1 parent b425fc5 commit 36e23da

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
 

Diff for: ‎src/module.ts

+15
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ export default defineNuxtModule<ModuleOptions>({
173173
logger.level = (config.debug || nuxt.options.debug) ? 4 : 3
174174
if (config.enabled === false) {
175175
logger.debug('The module is disabled, skipping setup.')
176+
// need to mock the composables to allow module still to work when disabled
177+
;['defineRobotMeta', 'useRobotsRule']
178+
.forEach((name) => {
179+
addImports({ name, from: resolve(`./runtime/nuxt/composables/mock`) })
180+
})
181+
nuxt.options.nitro = nuxt.options.nitro || {}
182+
nuxt.options.nitro.imports = nuxt.options.nitro.imports || {}
183+
nuxt.options.nitro.imports.presets = nuxt.options.nitro.imports.presets || []
184+
nuxt.options.nitro.imports.presets.push({
185+
from: resolve('./runtime/nitro/composables/mock'),
186+
imports: [
187+
'getPathRobotConfig',
188+
'getSiteRobotConfig',
189+
],
190+
})
176191
return
177192
}
178193

Diff for: ‎src/runtime/nitro/composables/mock.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { H3Event } from 'h3'
2+
3+
// eslint-disable-next-line unused-imports/no-unused-vars
4+
export function getPathRobotConfig(e: H3Event, options?: { skipSiteIndexable?: boolean, path?: string }) {
5+
return {
6+
indexable: true,
7+
rule: '',
8+
}
9+
}
10+
11+
// eslint-disable-next-line unused-imports/no-unused-vars
12+
export function getSiteRobotConfig(e: H3Event): { indexable: boolean, hints: string[] } {
13+
return {
14+
indexable: true,
15+
hints: [],
16+
}
17+
}

Diff for: ‎src/runtime/nuxt/composables/mock.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { MaybeRef } from 'vue'
2+
import { ref } from '#imports'
3+
4+
// eslint-disable-next-line unused-imports/no-unused-vars
5+
export function defineRobotMeta(component?: boolean) {}
6+
7+
// eslint-disable-next-line unused-imports/no-unused-vars
8+
export function useRobotsRule(rule?: MaybeRef<boolean | string>) {
9+
return ref('')
10+
}

0 commit comments

Comments
 (0)
Please sign in to comment.