Skip to content

Commit

Permalink
feat: add a runtime warning for the old object type transformIndexHtm…
Browse files Browse the repository at this point in the history
…l hook (#14791)
  • Loading branch information
sapphi-red committed Oct 29, 2023
1 parent ac5d8a7 commit 17fb5ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit 17fb5ee

Please sign in to comment.