Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: dedupe deprecation warning code #3232

Merged
merged 2 commits into from
May 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,64 +402,65 @@ export async function resolveConfig(
}

// TODO Deprecation warnings - remove when out of beta
if (config.build?.base) {

const logDeprecationWarning = (
deprecatedOption: string,
hint: string,
error?: Error
) => {
logger.warn(
chalk.yellow.bold(
`(!) "build.base" config option is deprecated. ` +
`"base" is now a root-level config option.`
`(!) "${deprecatedOption}" option is deprecated. ${hint}${
error ? `\n${error.stack}` : ''
}`
)
)
}

if (config.build?.base) {
logDeprecationWarning(
'build.base',
'"base" is now a root-level config option.'
)
config.base = config.build.base
}
Object.defineProperty(resolvedBuildOptions, 'base', {
enumerable: false,
get() {
logger.warn(
chalk.yellow.bold(
`(!) "build.base" config option is deprecated. ` +
`"base" is now a root-level config option.\n` +
new Error().stack
)
logDeprecationWarning(
'build.base',
'"base" is now a root-level config option.',
new Error()
)
return resolved.base
}
})

if (config.alias) {
logger.warn(
chalk.bold.yellow(
'(!) "alias" option is deprecated. Use "resolve.alias" instead.'
)
)
logDeprecationWarning('alias', 'Use "resolve.alias" instead.')
}
Object.defineProperty(resolved, 'alias', {
enumerable: false,
get() {
logger.warn(
chalk.yellow.bold(
`(!) "alias" config option is deprecated. Use "resolve.alias" instead.\n` +
new Error().stack
)
logDeprecationWarning(
'alias',
'Use "resolve.alias" instead.',
new Error()
)
return resolved.resolve.alias
}
})

if (config.dedupe) {
logger.warn(
chalk.bold.yellow(
'(!) "dedupe" option is deprecated. Use "resolve.dedupe" instead.'
)
)
logDeprecationWarning('dedupe', 'Use "resolve.dedupe" instead.')
}
Object.defineProperty(resolved, 'dedupe', {
enumerable: false,
get() {
logger.warn(
chalk.yellow.bold(
`(!) "dedupe" config option is deprecated. Use "resolve.dedupe" instead.\n` +
new Error().stack
)
logDeprecationWarning(
'dedupe',
'Use "resolve.dedupe" instead.',
new Error()
)
return resolved.resolve.dedupe
}
Expand Down