deprecations.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { isRuntimeOnly } from '../component'
  2. export const enum DeprecationTypes {
  3. CONFIG_SILENT,
  4. CONFIG_DEVTOOLS,
  5. CONFIG_KEY_CODES,
  6. CONFIG_PRODUCTION_TIP,
  7. CONFIG_IGNORED_ELEMENTS,
  8. GLOBAL_PROTOTYPE,
  9. GLOBAL_SET,
  10. GLOBAL_DELETE,
  11. GLOBAL_OBSERVABLE,
  12. GLOBAL_DOM_TEMPLATE_MOUNT,
  13. INSTANCE_SET,
  14. INSTANCE_DELETE,
  15. INSTANCE_MOUNT,
  16. INSTANCE_DESTROY
  17. }
  18. type DeprecationData = {
  19. message: string | (() => string)
  20. link?: string
  21. }
  22. const deprecations: Record<DeprecationTypes, DeprecationData> = {
  23. [DeprecationTypes.CONFIG_SILENT]: {
  24. message:
  25. `config.silent has been removed because it is not good practice to ` +
  26. `intentionally suppress warnings. You can use your browser console's ` +
  27. `filter features to focus on relevant messages.`
  28. },
  29. [DeprecationTypes.CONFIG_DEVTOOLS]: {
  30. message:
  31. `config.devtools has been removed. To enable devtools for ` +
  32. `production, configure the __VUE_PROD_DEVTOOLS__ compile-time flag.`,
  33. link: `https://github.com/vuejs/vue-next/tree/master/packages/vue#bundler-build-feature-flags`
  34. },
  35. [DeprecationTypes.CONFIG_KEY_CODES]: {
  36. message:
  37. `config.keyCodes has been removed. ` +
  38. `In Vue 3, you can directly use the kebab-case key names as v-on modifiers.`,
  39. link: `https://v3.vuejs.org/guide/migration/keycode-modifiers.html`
  40. },
  41. [DeprecationTypes.CONFIG_PRODUCTION_TIP]: {
  42. message: `config.productionTip has been removed.`,
  43. link: `https://v3.vuejs.org/guide/migration/global-api.html#config-productiontip-removed`
  44. },
  45. [DeprecationTypes.CONFIG_IGNORED_ELEMENTS]: {
  46. message: () => {
  47. let msg = `config.ignoredElements has been removed.`
  48. if (isRuntimeOnly()) {
  49. msg += ` Pass the "isCustomElement" option to @vue/compiler-dom instead.`
  50. } else {
  51. msg += ` Use config.isCustomElement instead.`
  52. }
  53. return msg
  54. },
  55. link: `https://v3.vuejs.org/guide/migration/global-api.html#config-ignoredelements-is-now-config-iscustomelement`
  56. },
  57. [DeprecationTypes.GLOBAL_PROTOTYPE]: {
  58. message:
  59. `Vue.prototype is no longer available in Vue 3. ` +
  60. `Use config.globalProperties instead.`,
  61. link: `https://v3.vuejs.org/guide/migration/global-api.html#vue-prototype-replaced-by-config-globalproperties`
  62. },
  63. [DeprecationTypes.GLOBAL_SET]: {
  64. message:
  65. `Vue.set() has been removed as it is no longer needed in Vue 3. ` +
  66. `Simply use native JavaScript mutations.`
  67. },
  68. [DeprecationTypes.GLOBAL_DELETE]: {
  69. message:
  70. `Vue.delete() has been removed as it is no longer needed in Vue 3. ` +
  71. `Simply use native JavaScript mutations.`
  72. },
  73. [DeprecationTypes.GLOBAL_OBSERVABLE]: {
  74. message:
  75. `Vue.observable() has been removed. ` +
  76. `Use \`import { reactive } from "vue"\` from Composition API instead.`,
  77. link: `https://v3.vuejs.org/api/basic-reactivity.html`
  78. },
  79. [DeprecationTypes.GLOBAL_DOM_TEMPLATE_MOUNT]: {
  80. message:
  81. `Vue detected directives on the mount container. ` +
  82. `In Vue 3, the container is no longer considered part of the template ` +
  83. `and will not be processed/replaced.`,
  84. link: `https://v3.vuejs.org/guide/migration/mount-changes.html`
  85. },
  86. [DeprecationTypes.INSTANCE_SET]: {
  87. message:
  88. `vm.$set() has been removed as it is no longer needed in Vue 3. ` +
  89. `Simply use native JavaScript mutations.`
  90. },
  91. [DeprecationTypes.INSTANCE_DELETE]: {
  92. message:
  93. `vm.$delete() has been removed as it is no longer needed in Vue 3. ` +
  94. `Simply use native JavaScript mutations.`
  95. },
  96. [DeprecationTypes.INSTANCE_MOUNT]: {
  97. message:
  98. `The global app boostrapping API has changed: vm.$mount() and the "el" ` +
  99. `option have been removed. Use createApp(RootComponent).mount() instead.`,
  100. link: `https://v3.vuejs.org/guide/migration/global-api.html#mounting-app-instance`
  101. },
  102. [DeprecationTypes.INSTANCE_DESTROY]: {
  103. message: `vm.$destroy() has been removed. Use app.unmount() instead.`,
  104. link: `https://v3.vuejs.org/api/application-api.html#unmount`
  105. }
  106. }
  107. export function warnDeprecation(key: DeprecationTypes) {
  108. if (!__COMPAT__ || !__DEV__) {
  109. return
  110. }
  111. const { message, link } = deprecations[key]
  112. console.warn(
  113. `[Vue Deprecation]: ${typeof message === 'function' ? message() : message}${
  114. link ? `\nFor more details, see ${link}` : ``
  115. }`
  116. )
  117. }