Skip to content

Commit

Permalink
refactor: remove deprecated api for 3.0 (#5868)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydcjeff committed May 5, 2022
1 parent eeac2d2 commit b5c3709
Show file tree
Hide file tree
Showing 15 changed files with 9 additions and 309 deletions.
1 change: 0 additions & 1 deletion docs/config/index.md
Expand Up @@ -1022,7 +1022,6 @@ export default defineConfig({

- `external` is also omitted, use Vite's `optimizeDeps.exclude` option
- `plugins` are merged with Vite's dep plugin
- `keepNames` takes precedence over the deprecated `optimizeDeps.keepNames`

## SSR Options

Expand Down
7 changes: 1 addition & 6 deletions packages/plugin-react/src/index.ts
Expand Up @@ -38,15 +38,10 @@ export interface Options {
* @default true
*/
jsxPure?: boolean

/**
* Babel configuration applied in both dev and prod.
*/
babel?: BabelOptions
/**
* @deprecated Use `babel.parserOpts.plugins` instead
*/
parserPlugins?: ParserOptions['plugins']
}

export type BabelOptions = Omit<
Expand Down Expand Up @@ -104,7 +99,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
babelOptions.presets ||= []
babelOptions.overrides ||= []
babelOptions.parserOpts ||= {} as any
babelOptions.parserOpts.plugins ||= opts.parserPlugins || []
babelOptions.parserOpts.plugins ||= []

// Support patterns like:
// - import * as React from 'react';
Expand Down
7 changes: 0 additions & 7 deletions packages/vite/src/client/client.ts
Expand Up @@ -433,13 +433,6 @@ export function createHotContext(ownerPath: string): ViteHotContext {
}
},

acceptDeps() {
throw new Error(
`hot.acceptDeps() is deprecated. ` +
`Use hot.accept() with the same signature instead.`
)
},

dispose(cb) {
disposeMap.set(ownerPath, cb)
},
Expand Down
46 changes: 0 additions & 46 deletions packages/vite/src/node/__tests__/config.spec.ts
Expand Up @@ -183,52 +183,6 @@ describe('mergeConfig', () => {
})
})

describe('resolveConfig', () => {
beforeAll(() => {
// silence deprecation warning
jest.spyOn(console, 'warn').mockImplementation(() => {})
})

afterAll(() => {
jest.clearAllMocks()
})

test('copies optimizeDeps.keepNames to esbuildOptions.keepNames', async () => {
const config: InlineConfig = {
optimizeDeps: {
keepNames: false
}
}

expect(await resolveConfig(config, 'serve')).toMatchObject({
optimizeDeps: {
esbuildOptions: {
keepNames: false
}
}
})
})

test('uses esbuildOptions.keepNames if set', async () => {
const config: InlineConfig = {
optimizeDeps: {
keepNames: true,
esbuildOptions: {
keepNames: false
}
}
}

expect(await resolveConfig(config, 'serve')).toMatchObject({
optimizeDeps: {
esbuildOptions: {
keepNames: false
}
}
})
})
})

describe('resolveEnvPrefix', () => {
test(`use 'VITE_' as default value`, () => {
const config: UserConfig = {}
Expand Down
40 changes: 1 addition & 39 deletions packages/vite/src/node/build.ts
Expand Up @@ -42,11 +42,6 @@ import { watchPackageDataPlugin } from './packages'
import { ensureWatchPlugin } from './plugins/ensureWatch'

export interface BuildOptions {
/**
* Base public path when served in production.
* @deprecated `base` is now a root-level config option.
*/
base?: string
/**
* Compatibility transform target. The transform is performed with esbuild
* and the lowest supported target is es2015/es6. Note this only handles
Expand All @@ -70,13 +65,6 @@ export interface BuildOptions {
* @default true
*/
polyfillModulePreload?: boolean
/**
* whether to inject dynamic import polyfill.
* Note: does not apply to library mode.
* @default false
* @deprecated use plugin-legacy for browsers that don't support dynamic import
*/
polyfillDynamicImport?: boolean
/**
* Directory relative from `root` where build output will be placed. If the
* directory exists, it will be removed before the build.
Expand Down Expand Up @@ -130,10 +118,6 @@ export interface BuildOptions {
* https://terser.org/docs/api-reference#minify-options
*/
terserOptions?: Terser.MinifyOptions
/**
* @deprecated Vite now uses esbuild for CSS minification.
*/
cleanCssOptions?: any
/**
* Will be merged with internal rollup options.
* https://rollupjs.org/guide/en/#big-list-of-options
Expand Down Expand Up @@ -198,12 +182,6 @@ export interface BuildOptions {
* Can slightly improve build speed.
*/
reportCompressedSize?: boolean
/**
* Set to false to disable brotli compressed size reporting for build.
* Can slightly improve build speed.
* @deprecated use `build.reportCompressedSize` instead.
*/
brotliSize?: boolean
/**
* Adjust chunk size warning limit (in kbs).
* @default 500
Expand All @@ -225,13 +203,7 @@ export interface LibraryOptions {

export type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife'

export type ResolvedBuildOptions = Required<
Omit<
BuildOptions,
// make deprecated options optional
'base' | 'cleanCssOptions' | 'polyfillDynamicImport' | 'brotliSize'
>
>
export type ResolvedBuildOptions = Required<BuildOptions>

export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
const resolved: ResolvedBuildOptions = {
Expand All @@ -253,7 +225,6 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
ssr: false,
ssrManifest: false,
reportCompressedSize: true,
// brotliSize: true,
chunkSizeWarningLimit: 500,
watch: null,
...raw,
Expand Down Expand Up @@ -451,15 +422,6 @@ async function doBuild(

try {
const buildOutputOptions = (output: OutputOptions = {}): OutputOptions => {
// @ts-ignore
if (output.output) {
config.logger.warn(
`You've set "rollupOptions.output.output" in your config. ` +
`This is deprecated and will override all Vite.js default output options. ` +
`Please use "rollupOptions.output" instead.`
)
}

return {
dir: outDir,
format: ssr ? 'cjs' : 'es',
Expand Down
133 changes: 3 additions & 130 deletions packages/vite/src/node/config.ts
Expand Up @@ -176,17 +176,6 @@ export interface UserConfig {
* @default 'VITE_'
*/
envPrefix?: string | string[]
/**
* Import aliases
* @deprecated use `resolve.alias` instead
*/
alias?: AliasOptions
/**
* Force Vite to always resolve listed dependencies to the same copy (from
* project root).
* @deprecated use `resolve.dedupe` instead
*/
dedupe?: string[]
/**
* Worker bundle options
*/
Expand Down Expand Up @@ -235,10 +224,7 @@ export interface InlineConfig extends UserConfig {
}

export type ResolvedConfig = Readonly<
Omit<
UserConfig,
'plugins' | 'alias' | 'dedupe' | 'assetsInclude' | 'optimizeDeps' | 'worker'
> & {
Omit<UserConfig, 'plugins' | 'assetsInclude' | 'optimizeDeps' | 'worker'> & {
configFile: string | undefined
configFileDependencies: string[]
inlineConfig: InlineConfig
Expand All @@ -261,7 +247,7 @@ export type ResolvedConfig = Readonly<
assetsInclude: (file: string) => boolean
logger: Logger
createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn
optimizeDeps: Omit<DepOptimizationOptions, 'keepNames'>
optimizeDeps: DepOptimizationOptions
/** @internal */
packageCache: PackageCache
worker: ResolveWorkerOptions
Expand Down Expand Up @@ -370,12 +356,11 @@ export async function resolveConfig(
// @ts-ignore because @rollup/plugin-alias' type doesn't allow function
// replacement, but its implementation does work with function values.
clientAlias,
config.resolve?.alias || config.alias || []
config.resolve?.alias || []
)
)

const resolveOptions: ResolvedConfig['resolve'] = {
dedupe: config.dedupe,
...config.resolve,
alias: resolvedAlias
}
Expand Down Expand Up @@ -501,7 +486,6 @@ export async function resolveConfig(
optimizeDeps: {
...optimizeDeps,
esbuildOptions: {
keepNames: optimizeDeps.keepNames,
preserveSymlinks: config.resolve?.preserveSymlinks,
...optimizeDeps.esbuildOptions
}
Expand Down Expand Up @@ -540,117 +524,6 @@ export async function resolveConfig(
})
}

// TODO Deprecation warnings - remove when out of beta

const logDeprecationWarning = (
deprecatedOption: string,
hint: string,
error?: Error
) => {
logger.warn(
colors.yellow(
colors.bold(
`(!) "${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() {
logDeprecationWarning(
'build.base',
'"base" is now a root-level config option.',
new Error()
)
return resolved.base
}
})

if (config.alias) {
logDeprecationWarning('alias', 'Use "resolve.alias" instead.')
}
Object.defineProperty(resolved, 'alias', {
enumerable: false,
get() {
logDeprecationWarning(
'alias',
'Use "resolve.alias" instead.',
new Error()
)
return resolved.resolve.alias
}
})

if (config.dedupe) {
logDeprecationWarning('dedupe', 'Use "resolve.dedupe" instead.')
}
Object.defineProperty(resolved, 'dedupe', {
enumerable: false,
get() {
logDeprecationWarning(
'dedupe',
'Use "resolve.dedupe" instead.',
new Error()
)
return resolved.resolve.dedupe
}
})

if (optimizeDeps.keepNames) {
logDeprecationWarning(
'optimizeDeps.keepNames',
'Use "optimizeDeps.esbuildOptions.keepNames" instead.'
)
}
Object.defineProperty(resolved.optimizeDeps, 'keepNames', {
enumerable: false,
get() {
logDeprecationWarning(
'optimizeDeps.keepNames',
'Use "optimizeDeps.esbuildOptions.keepNames" instead.',
new Error()
)
return resolved.optimizeDeps.esbuildOptions?.keepNames
}
})

if (config.build?.polyfillDynamicImport) {
logDeprecationWarning(
'build.polyfillDynamicImport',
'"polyfillDynamicImport" has been removed. Please use @vitejs/plugin-legacy if your target browsers do not support dynamic imports.'
)
}

Object.defineProperty(resolvedBuildOptions, 'polyfillDynamicImport', {
enumerable: false,
get() {
logDeprecationWarning(
'build.polyfillDynamicImport',
'"polyfillDynamicImport" has been removed. Please use @vitejs/plugin-legacy if your target browsers do not support dynamic imports.',
new Error()
)
return false
}
})

if (config.build?.cleanCssOptions) {
logDeprecationWarning(
'build.cleanCssOptions',
'Vite now uses esbuild for CSS minification.'
)
}

if (config.build?.terserOptions && config.build.minify !== 'terser') {
logger.warn(
colors.yellow(
Expand Down

0 comments on commit b5c3709

Please sign in to comment.