diff --git a/src/module.ts b/src/module.ts index 80de09c..2e406a5 100644 --- a/src/module.ts +++ b/src/module.ts @@ -52,6 +52,13 @@ export default defineNuxtModule({ // @ts-ignore const head = (nuxt.options.app.head || nuxt.options.head) as NuxtAppHead + // disable module when head is a function + if (typeof head === 'function') { + logger.warn('This module does not work with `head` as function.') + + return + } + // merge fonts from valid head link fontsParsed.push(...head.link .filter(link => isValidURL(String(link.href))) diff --git a/test/disable.test.ts b/test/disable.test.ts new file mode 100644 index 0000000..2c43dc7 --- /dev/null +++ b/test/disable.test.ts @@ -0,0 +1,30 @@ +import { describe, test, expect, vi, afterAll } from 'vitest' +import { setup } from '@nuxt/test-utils' + +describe('disable', async () => { + const spyStderr = vi.spyOn(process.stderr, 'write').mockImplementation(() => undefined!) + + afterAll(() => { + spyStderr.mockRestore() + }) + + await setup({ + nuxtConfig: { + app: { + // @ts-ignore + head: () => {} + }, + googleFonts: { + families: { + Roboto: true + } + } + } + }) + + test('should warn if head as function', () => { + expect(spyStderr).toBeCalledTimes(1) + const output = spyStderr.mock.calls[0][0].toString() + expect(output).contains('[warn] [nuxt:google-fonts] This module does not work with `head` as function.') + }) +})