wip: better experimental feature warnings

This commit is contained in:
Evan You
2020-11-19 20:36:15 -05:00
parent 9db42889e6
commit 62830f8fa4
3 changed files with 33 additions and 20 deletions

View File

@@ -1,12 +1,27 @@
const hasWarned: Record<string, boolean> = {}
export function warnOnce(msg: string) {
if (!hasWarned[msg]) {
const isNodeProd =
typeof process !== 'undefined' && process.env.NODE_ENV === 'production'
if (!isNodeProd && !__TEST__ && !hasWarned[msg]) {
hasWarned[msg] = true
warn(msg)
}
}
export function warn(msg: string) {
console.warn(`\x1b[33m[@vue/compiler-sfc] ${msg}\x1b[0m\n`)
console.warn(
`\x1b[1m\x1b[33m[@vue/compiler-sfc]\x1b[0m\x1b[33m ${msg}\x1b[0m\n`
)
}
export function warnExperimental(feature: string, rfcId: number) {
warnOnce(
`${feature} is still an experimental proposal.\n` +
`Follow its status at https://github.com/vuejs/rfcs/pull/${rfcId}.`
)
warnOnce(
`When using experimental features,\n` +
`it is recommended to pin your vue dependencies to exact versions to avoid breakage.`
)
}