Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a runtime warning for the old object type transformIndexHtml hook #14791

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import type { ResolvedConfig } from '../config'
import { toOutputFilePathInHtml } from '../build'
import { resolveEnvPrefix } from '../env'
import type { Logger } from '../logger'
import {
assetUrlRE,
checkPublicFile,
Expand Down Expand Up @@ -287,6 +288,7 @@ function handleParseError(
export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
const [preHooks, normalHooks, postHooks] = resolveHtmlTransforms(
config.plugins,
config.logger,
)
preHooks.unshift(preImportMapHook(config))
preHooks.push(htmlEnvHook(config))
Expand Down Expand Up @@ -1066,6 +1068,7 @@ export function htmlEnvHook(config: ResolvedConfig): IndexHtmlTransformHook {

export function resolveHtmlTransforms(
plugins: readonly Plugin[],
logger: Logger,
): [
IndexHtmlTransformHook[],
IndexHtmlTransformHook[],
Expand All @@ -1082,6 +1085,21 @@ export function resolveHtmlTransforms(
if (typeof hook === 'function') {
normalHooks.push(hook)
} else {
if (!('order' in hook) && 'enforce' in hook) {
logger.warnOnce(
colors.yellow(
`plugin '${plugin.name}' uses deprecated 'enforce' option. Use 'order' option instead.`,
),
)
}
if (!('handler' in hook) && 'transform' in hook) {
logger.warnOnce(
colors.yellow(
`plugin '${plugin.name}' uses deprecated 'transform' option. Use 'handler' option instead.`,
),
)
}

// `enforce` had only two possible values for the `transformIndexHtml` hook
// `'pre'` and `'post'` (the default). `order` now works with three values
// to align with other hooks (`'pre'`, normal, and `'post'`). We map
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function createDevHtmlTransformFn(
): (url: string, html: string, originalUrl: string) => Promise<string> {
const [preHooks, normalHooks, postHooks] = resolveHtmlTransforms(
server.config.plugins,
server.config.logger,
)
return (url: string, html: string, originalUrl: string): Promise<string> => {
return applyHtmlTransforms(
Expand Down