Skip to content

Commit 8266929

Browse files
sapphi-redmoonlitusun
authored andcommitted
refactor!: remove deprecated hook-level enforce/transform from transformIndexHtml hook (vitejs#19349)
1 parent fe58a64 commit 8266929

File tree

2 files changed

+3
-43
lines changed

2 files changed

+3
-43
lines changed

packages/vite/src/node/plugins/html.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import type { ResolvedConfig } from '../config'
3131
import { checkPublicFile } from '../publicDir'
3232
import { toOutputFilePathInHtml } from '../build'
3333
import { resolveEnvPrefix } from '../env'
34-
import type { Logger } from '../logger'
3534
import { cleanUrl } from '../../shared/utils'
3635
import { perEnvironmentState } from '../environment'
3736
import { getNodeAssetAttributes } from '../assetSource'
@@ -332,7 +331,6 @@ function handleParseError(
332331
export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
333332
const [preHooks, normalHooks, postHooks] = resolveHtmlTransforms(
334333
config.plugins,
335-
config.logger,
336334
)
337335
preHooks.unshift(injectCspNonceMetaTagHook(config))
338336
preHooks.unshift(preImportMapHook(config))
@@ -1123,21 +1121,6 @@ export type IndexHtmlTransform =
11231121
| IndexHtmlTransformHook
11241122
| {
11251123
order?: 'pre' | 'post' | null
1126-
/**
1127-
* @deprecated renamed to `order`
1128-
*/
1129-
enforce?: 'pre' | 'post'
1130-
/**
1131-
* @deprecated renamed to `handler`
1132-
*/
1133-
transform: IndexHtmlTransformHook
1134-
}
1135-
| {
1136-
order?: 'pre' | 'post' | null
1137-
/**
1138-
* @deprecated renamed to `order`
1139-
*/
1140-
enforce?: 'pre' | 'post'
11411124
handler: IndexHtmlTransformHook
11421125
}
11431126

@@ -1306,7 +1289,6 @@ export function injectNonceAttributeTagHook(
13061289

13071290
export function resolveHtmlTransforms(
13081291
plugins: readonly Plugin[],
1309-
logger: Logger,
13101292
): [
13111293
IndexHtmlTransformHook[],
13121294
IndexHtmlTransformHook[],
@@ -1323,31 +1305,10 @@ export function resolveHtmlTransforms(
13231305
if (typeof hook === 'function') {
13241306
normalHooks.push(hook)
13251307
} else {
1326-
if (!('order' in hook) && 'enforce' in hook) {
1327-
logger.warnOnce(
1328-
colors.yellow(
1329-
`plugin '${plugin.name}' uses deprecated 'enforce' option. Use 'order' option instead.`,
1330-
),
1331-
)
1332-
}
1333-
if (!('handler' in hook) && 'transform' in hook) {
1334-
logger.warnOnce(
1335-
colors.yellow(
1336-
`plugin '${plugin.name}' uses deprecated 'transform' option. Use 'handler' option instead.`,
1337-
),
1338-
)
1339-
}
1340-
1341-
// `enforce` had only two possible values for the `transformIndexHtml` hook
1342-
// `'pre'` and `'post'` (the default). `order` now works with three values
1343-
// to align with other hooks (`'pre'`, normal, and `'post'`). We map
1344-
// both `enforce: 'post'` to `order: undefined` to avoid a breaking change
1345-
const order = hook.order ?? (hook.enforce === 'pre' ? 'pre' : undefined)
1346-
// @ts-expect-error union type
1347-
const handler = hook.handler ?? hook.transform
1348-
if (order === 'pre') {
1308+
const handler = hook.handler
1309+
if (hook.order === 'pre') {
13491310
preHooks.push(handler)
1350-
} else if (order === 'post') {
1311+
} else if (hook.order === 'post') {
13511312
postHooks.push(handler)
13521313
} else {
13531314
normalHooks.push(handler)

packages/vite/src/node/server/middlewares/indexHtml.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export function createDevHtmlTransformFn(
6767
) => Promise<string> {
6868
const [preHooks, normalHooks, postHooks] = resolveHtmlTransforms(
6969
config.plugins,
70-
config.logger,
7170
)
7271
const transformHooks = [
7372
preImportMapHook(config),

0 commit comments

Comments
 (0)