fix(compat): handle and warn config.optionMergeStrategies

This commit is contained in:
Evan You
2021-05-08 16:47:38 -04:00
parent ed6c5fe903
commit 94e69fd389
5 changed files with 48 additions and 9 deletions

View File

@@ -26,6 +26,7 @@ export const enum DeprecationTypes {
CONFIG_PRODUCTION_TIP = 'CONFIG_PRODUCTION_TIP',
CONFIG_IGNORED_ELEMENTS = 'CONFIG_IGNORED_ELEMENTS',
CONFIG_WHITESPACE = 'CONFIG_WHITESPACE',
CONFIG_OPTION_MERGE_STRATS = 'CONFIG_OPTION_MERGE_STRATS',
INSTANCE_SET = 'INSTANCE_SET',
INSTANCE_DELETE = 'INSTANCE_DELETE',
@@ -174,6 +175,12 @@ export const deprecationData: Record<DeprecationTypes, DeprecationData> = {
`\`config.compilerOptions.whitespace\`.`
},
[DeprecationTypes.CONFIG_OPTION_MERGE_STRATS]: {
message:
`config.optionMergeStrategies no longer exposes internal strategies. ` +
`Use custom merge functions instead.`
},
[DeprecationTypes.INSTANCE_SET]: {
message:
`vm.$set() has been removed as it is no longer needed in Vue 3. ` +

View File

@@ -41,7 +41,8 @@ import { Directive } from '../directives'
import { nextTick } from '../scheduler'
import { version } from '..'
import {
installLegacyConfigProperties,
installLegacyConfigWarnings,
installLegacyOptionMergeStrats,
LegacyConfig,
legacyOptionMergeStrats
} from './globalConfig'
@@ -327,6 +328,7 @@ export function installAppCompatProperties(
render: RootRenderFunction
) {
installFilterMethod(app, context)
installLegacyOptionMergeStrats(app.config)
if (!singletonApp) {
// this is the call of creating the singleton itself so the rest is
@@ -337,7 +339,7 @@ export function installAppCompatProperties(
installCompatMount(app, context, render)
installLegacyAPIs(app)
applySingletonAppMutations(app)
if (__DEV__) installLegacyConfigProperties(app.config)
if (__DEV__) installLegacyConfigWarnings(app.config)
}
function installFilterMethod(app: App, context: AppContext) {

View File

@@ -1,7 +1,11 @@
import { extend, isArray } from '@vue/shared'
import { AppConfig } from '../apiCreateApp'
import { mergeDataOption } from './data'
import { DeprecationTypes, warnDeprecation } from './compatConfig'
import {
DeprecationTypes,
softAssertCompatEnabled,
warnDeprecation
} from './compatConfig'
import { isCopyingConfig } from './global'
// legacy config warnings
@@ -33,7 +37,7 @@ export type LegacyConfig = {
}
// dev only
export function installLegacyConfigProperties(config: AppConfig) {
export function installLegacyConfigWarnings(config: AppConfig) {
const legacyConfigOptions: Record<string, DeprecationTypes> = {
silent: DeprecationTypes.CONFIG_SILENT,
devtools: DeprecationTypes.CONFIG_DEVTOOLS,
@@ -57,11 +61,27 @@ export function installLegacyConfigProperties(config: AppConfig) {
}
})
})
}
// Internal merge strats which are no longer needed in v3, but we need to
// expose them because some v2 plugins will reuse these internal strats to
// merge their custom options.
extend(config.optionMergeStrategies, legacyOptionMergeStrats)
export function installLegacyOptionMergeStrats(config: AppConfig) {
config.optionMergeStrategies = new Proxy({} as any, {
get(target, key) {
if (key in target) {
return target[key]
}
if (
key in legacyOptionMergeStrats &&
softAssertCompatEnabled(
DeprecationTypes.CONFIG_OPTION_MERGE_STRATS,
null
)
) {
return legacyOptionMergeStrats[
key as keyof typeof legacyOptionMergeStrats
]
}
}
})
}
export const legacyOptionMergeStrats = {