Skip to content

Commit 1ec9f96

Browse files
committed
refactor!: drop support for nuxt v2
1 parent 82791c2 commit 1ec9f96

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/module.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { normalize } from 'pathe'
44
import { isWindows } from 'std-env'
55
import { genArrayFromRaw, genObjectFromRawEntries } from 'knitwork'
66

7-
import { createResolver, defineNuxtModule, isNuxt2, logger, resolvePath } from '@nuxt/kit'
7+
import { createResolver, defineNuxtModule, logger, resolvePath } from '@nuxt/kit'
88
import { DEFAULTS, NuxtRedirectHtmlRegex } from './config'
99
import type { ModuleOptions } from './config'
1010

@@ -15,7 +15,7 @@ export default defineNuxtModule<ModuleOptions>({
1515
name: '@nuxtjs/html-validator',
1616
configKey: 'htmlValidator',
1717
compatibility: {
18-
nuxt: '^2.0.0 || >=3.0.0-rc.7',
18+
nuxt: '>=3.0.0-rc.7',
1919
},
2020
},
2121
defaults: nuxt => ({
@@ -30,10 +30,9 @@ export default defineNuxtModule<ModuleOptions>({
3030
logger.info(`Using ${colors.bold('html-validate')} to validate server-rendered HTML`)
3131

3232
const { usePrettier, failOnError, options, logLevel } = moduleOptions as Required<ModuleOptions>
33-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34-
if ((nuxt.options as any).htmlValidator?.options?.extends) {
35-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
36-
options.extends = (nuxt.options as any).htmlValidator.options.extends
33+
34+
if (nuxt.options.htmlValidator?.options?.extends) {
35+
options.extends = nuxt.options.htmlValidator.options.extends
3736
}
3837

3938
const { resolve } = createResolver(import.meta.url)
@@ -63,7 +62,7 @@ export default defineNuxtModule<ModuleOptions>({
6362
})
6463
}
6564

66-
if (!nuxt.options.dev || isNuxt2()) {
65+
if (!nuxt.options.dev) {
6766
const validatorPath = await resolvePath(fileURLToPath(new URL('./runtime/validator', import.meta.url)))
6867
const { useChecker, getValidator } = await import(isWindows ? pathToFileURL(validatorPath).href : validatorPath)
6968
const validator = getValidator(options)
@@ -75,13 +74,10 @@ export default defineNuxtModule<ModuleOptions>({
7574
throw new Error('html-validator found errors')
7675
}
7776
}
78-
79-
// @ts-expect-error TODO: use @nuxt/bridge-schema
80-
nuxt.hook('generate:done', errorIfNeeded)
8177
nuxt.hook('close', errorIfNeeded)
8278
}
8379

84-
// Nuxt 3/Nuxt Bridge prerendering
80+
// Prerendering
8581

8682
nuxt.hook('nitro:init', (nitro) => {
8783
nitro.hooks.hook('prerender:generate', (route) => {
@@ -94,15 +90,6 @@ export default defineNuxtModule<ModuleOptions>({
9490
checkHTML(route.route, route.contents)
9591
})
9692
})
97-
98-
// Nuxt 2
99-
100-
if (isNuxt2()) {
101-
// @ts-expect-error TODO: use @nuxt/bridge-schema
102-
nuxt.hook('render:route', (url: string, result: { html: string }) => checkHTML(url, result.html))
103-
// @ts-expect-error TODO: use @nuxt/bridge-schema
104-
nuxt.hook('generate:page', ({ path, html }: { path: string, html: string }) => checkHTML(path, html))
105-
}
10693
}
10794
},
10895
})

0 commit comments

Comments
 (0)