Skip to content

Commit b5c3709

Browse files
authored
refactor: remove deprecated api for 3.0 (#5868)
1 parent eeac2d2 commit b5c3709

File tree

15 files changed

+9
-309
lines changed

15 files changed

+9
-309
lines changed

docs/config/index.md

-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,6 @@ export default defineConfig({
10221022

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

10271026
## SSR Options
10281027

packages/plugin-react/src/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ export interface Options {
3838
* @default true
3939
*/
4040
jsxPure?: boolean
41-
4241
/**
4342
* Babel configuration applied in both dev and prod.
4443
*/
4544
babel?: BabelOptions
46-
/**
47-
* @deprecated Use `babel.parserOpts.plugins` instead
48-
*/
49-
parserPlugins?: ParserOptions['plugins']
5045
}
5146

5247
export type BabelOptions = Omit<
@@ -104,7 +99,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
10499
babelOptions.presets ||= []
105100
babelOptions.overrides ||= []
106101
babelOptions.parserOpts ||= {} as any
107-
babelOptions.parserOpts.plugins ||= opts.parserPlugins || []
102+
babelOptions.parserOpts.plugins ||= []
108103

109104
// Support patterns like:
110105
// - import * as React from 'react';

packages/vite/src/client/client.ts

-7
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,6 @@ export function createHotContext(ownerPath: string): ViteHotContext {
433433
}
434434
},
435435

436-
acceptDeps() {
437-
throw new Error(
438-
`hot.acceptDeps() is deprecated. ` +
439-
`Use hot.accept() with the same signature instead.`
440-
)
441-
},
442-
443436
dispose(cb) {
444437
disposeMap.set(ownerPath, cb)
445438
},

packages/vite/src/node/__tests__/config.spec.ts

-46
Original file line numberDiff line numberDiff line change
@@ -183,52 +183,6 @@ describe('mergeConfig', () => {
183183
})
184184
})
185185

186-
describe('resolveConfig', () => {
187-
beforeAll(() => {
188-
// silence deprecation warning
189-
jest.spyOn(console, 'warn').mockImplementation(() => {})
190-
})
191-
192-
afterAll(() => {
193-
jest.clearAllMocks()
194-
})
195-
196-
test('copies optimizeDeps.keepNames to esbuildOptions.keepNames', async () => {
197-
const config: InlineConfig = {
198-
optimizeDeps: {
199-
keepNames: false
200-
}
201-
}
202-
203-
expect(await resolveConfig(config, 'serve')).toMatchObject({
204-
optimizeDeps: {
205-
esbuildOptions: {
206-
keepNames: false
207-
}
208-
}
209-
})
210-
})
211-
212-
test('uses esbuildOptions.keepNames if set', async () => {
213-
const config: InlineConfig = {
214-
optimizeDeps: {
215-
keepNames: true,
216-
esbuildOptions: {
217-
keepNames: false
218-
}
219-
}
220-
}
221-
222-
expect(await resolveConfig(config, 'serve')).toMatchObject({
223-
optimizeDeps: {
224-
esbuildOptions: {
225-
keepNames: false
226-
}
227-
}
228-
})
229-
})
230-
})
231-
232186
describe('resolveEnvPrefix', () => {
233187
test(`use 'VITE_' as default value`, () => {
234188
const config: UserConfig = {}

packages/vite/src/node/build.ts

+1-39
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ import { watchPackageDataPlugin } from './packages'
4242
import { ensureWatchPlugin } from './plugins/ensureWatch'
4343

4444
export interface BuildOptions {
45-
/**
46-
* Base public path when served in production.
47-
* @deprecated `base` is now a root-level config option.
48-
*/
49-
base?: string
5045
/**
5146
* Compatibility transform target. The transform is performed with esbuild
5247
* and the lowest supported target is es2015/es6. Note this only handles
@@ -70,13 +65,6 @@ export interface BuildOptions {
7065
* @default true
7166
*/
7267
polyfillModulePreload?: boolean
73-
/**
74-
* whether to inject dynamic import polyfill.
75-
* Note: does not apply to library mode.
76-
* @default false
77-
* @deprecated use plugin-legacy for browsers that don't support dynamic import
78-
*/
79-
polyfillDynamicImport?: boolean
8068
/**
8169
* Directory relative from `root` where build output will be placed. If the
8270
* directory exists, it will be removed before the build.
@@ -130,10 +118,6 @@ export interface BuildOptions {
130118
* https://terser.org/docs/api-reference#minify-options
131119
*/
132120
terserOptions?: Terser.MinifyOptions
133-
/**
134-
* @deprecated Vite now uses esbuild for CSS minification.
135-
*/
136-
cleanCssOptions?: any
137121
/**
138122
* Will be merged with internal rollup options.
139123
* https://rollupjs.org/guide/en/#big-list-of-options
@@ -198,12 +182,6 @@ export interface BuildOptions {
198182
* Can slightly improve build speed.
199183
*/
200184
reportCompressedSize?: boolean
201-
/**
202-
* Set to false to disable brotli compressed size reporting for build.
203-
* Can slightly improve build speed.
204-
* @deprecated use `build.reportCompressedSize` instead.
205-
*/
206-
brotliSize?: boolean
207185
/**
208186
* Adjust chunk size warning limit (in kbs).
209187
* @default 500
@@ -225,13 +203,7 @@ export interface LibraryOptions {
225203

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

228-
export type ResolvedBuildOptions = Required<
229-
Omit<
230-
BuildOptions,
231-
// make deprecated options optional
232-
'base' | 'cleanCssOptions' | 'polyfillDynamicImport' | 'brotliSize'
233-
>
234-
>
206+
export type ResolvedBuildOptions = Required<BuildOptions>
235207

236208
export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
237209
const resolved: ResolvedBuildOptions = {
@@ -253,7 +225,6 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
253225
ssr: false,
254226
ssrManifest: false,
255227
reportCompressedSize: true,
256-
// brotliSize: true,
257228
chunkSizeWarningLimit: 500,
258229
watch: null,
259230
...raw,
@@ -451,15 +422,6 @@ async function doBuild(
451422

452423
try {
453424
const buildOutputOptions = (output: OutputOptions = {}): OutputOptions => {
454-
// @ts-ignore
455-
if (output.output) {
456-
config.logger.warn(
457-
`You've set "rollupOptions.output.output" in your config. ` +
458-
`This is deprecated and will override all Vite.js default output options. ` +
459-
`Please use "rollupOptions.output" instead.`
460-
)
461-
}
462-
463425
return {
464426
dir: outDir,
465427
format: ssr ? 'cjs' : 'es',

packages/vite/src/node/config.ts

+3-130
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,6 @@ export interface UserConfig {
176176
* @default 'VITE_'
177177
*/
178178
envPrefix?: string | string[]
179-
/**
180-
* Import aliases
181-
* @deprecated use `resolve.alias` instead
182-
*/
183-
alias?: AliasOptions
184-
/**
185-
* Force Vite to always resolve listed dependencies to the same copy (from
186-
* project root).
187-
* @deprecated use `resolve.dedupe` instead
188-
*/
189-
dedupe?: string[]
190179
/**
191180
* Worker bundle options
192181
*/
@@ -235,10 +224,7 @@ export interface InlineConfig extends UserConfig {
235224
}
236225

237226
export type ResolvedConfig = Readonly<
238-
Omit<
239-
UserConfig,
240-
'plugins' | 'alias' | 'dedupe' | 'assetsInclude' | 'optimizeDeps' | 'worker'
241-
> & {
227+
Omit<UserConfig, 'plugins' | 'assetsInclude' | 'optimizeDeps' | 'worker'> & {
242228
configFile: string | undefined
243229
configFileDependencies: string[]
244230
inlineConfig: InlineConfig
@@ -261,7 +247,7 @@ export type ResolvedConfig = Readonly<
261247
assetsInclude: (file: string) => boolean
262248
logger: Logger
263249
createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn
264-
optimizeDeps: Omit<DepOptimizationOptions, 'keepNames'>
250+
optimizeDeps: DepOptimizationOptions
265251
/** @internal */
266252
packageCache: PackageCache
267253
worker: ResolveWorkerOptions
@@ -370,12 +356,11 @@ export async function resolveConfig(
370356
// @ts-ignore because @rollup/plugin-alias' type doesn't allow function
371357
// replacement, but its implementation does work with function values.
372358
clientAlias,
373-
config.resolve?.alias || config.alias || []
359+
config.resolve?.alias || []
374360
)
375361
)
376362

377363
const resolveOptions: ResolvedConfig['resolve'] = {
378-
dedupe: config.dedupe,
379364
...config.resolve,
380365
alias: resolvedAlias
381366
}
@@ -501,7 +486,6 @@ export async function resolveConfig(
501486
optimizeDeps: {
502487
...optimizeDeps,
503488
esbuildOptions: {
504-
keepNames: optimizeDeps.keepNames,
505489
preserveSymlinks: config.resolve?.preserveSymlinks,
506490
...optimizeDeps.esbuildOptions
507491
}
@@ -540,117 +524,6 @@ export async function resolveConfig(
540524
})
541525
}
542526

543-
// TODO Deprecation warnings - remove when out of beta
544-
545-
const logDeprecationWarning = (
546-
deprecatedOption: string,
547-
hint: string,
548-
error?: Error
549-
) => {
550-
logger.warn(
551-
colors.yellow(
552-
colors.bold(
553-
`(!) "${deprecatedOption}" option is deprecated. ${hint}${
554-
error ? `\n${error.stack}` : ''
555-
}`
556-
)
557-
)
558-
)
559-
}
560-
561-
if (config.build?.base) {
562-
logDeprecationWarning(
563-
'build.base',
564-
'"base" is now a root-level config option.'
565-
)
566-
config.base = config.build.base
567-
}
568-
Object.defineProperty(resolvedBuildOptions, 'base', {
569-
enumerable: false,
570-
get() {
571-
logDeprecationWarning(
572-
'build.base',
573-
'"base" is now a root-level config option.',
574-
new Error()
575-
)
576-
return resolved.base
577-
}
578-
})
579-
580-
if (config.alias) {
581-
logDeprecationWarning('alias', 'Use "resolve.alias" instead.')
582-
}
583-
Object.defineProperty(resolved, 'alias', {
584-
enumerable: false,
585-
get() {
586-
logDeprecationWarning(
587-
'alias',
588-
'Use "resolve.alias" instead.',
589-
new Error()
590-
)
591-
return resolved.resolve.alias
592-
}
593-
})
594-
595-
if (config.dedupe) {
596-
logDeprecationWarning('dedupe', 'Use "resolve.dedupe" instead.')
597-
}
598-
Object.defineProperty(resolved, 'dedupe', {
599-
enumerable: false,
600-
get() {
601-
logDeprecationWarning(
602-
'dedupe',
603-
'Use "resolve.dedupe" instead.',
604-
new Error()
605-
)
606-
return resolved.resolve.dedupe
607-
}
608-
})
609-
610-
if (optimizeDeps.keepNames) {
611-
logDeprecationWarning(
612-
'optimizeDeps.keepNames',
613-
'Use "optimizeDeps.esbuildOptions.keepNames" instead.'
614-
)
615-
}
616-
Object.defineProperty(resolved.optimizeDeps, 'keepNames', {
617-
enumerable: false,
618-
get() {
619-
logDeprecationWarning(
620-
'optimizeDeps.keepNames',
621-
'Use "optimizeDeps.esbuildOptions.keepNames" instead.',
622-
new Error()
623-
)
624-
return resolved.optimizeDeps.esbuildOptions?.keepNames
625-
}
626-
})
627-
628-
if (config.build?.polyfillDynamicImport) {
629-
logDeprecationWarning(
630-
'build.polyfillDynamicImport',
631-
'"polyfillDynamicImport" has been removed. Please use @vitejs/plugin-legacy if your target browsers do not support dynamic imports.'
632-
)
633-
}
634-
635-
Object.defineProperty(resolvedBuildOptions, 'polyfillDynamicImport', {
636-
enumerable: false,
637-
get() {
638-
logDeprecationWarning(
639-
'build.polyfillDynamicImport',
640-
'"polyfillDynamicImport" has been removed. Please use @vitejs/plugin-legacy if your target browsers do not support dynamic imports.',
641-
new Error()
642-
)
643-
return false
644-
}
645-
})
646-
647-
if (config.build?.cleanCssOptions) {
648-
logDeprecationWarning(
649-
'build.cleanCssOptions',
650-
'Vite now uses esbuild for CSS minification.'
651-
)
652-
}
653-
654527
if (config.build?.terserOptions && config.build.minify !== 'terser') {
655528
logger.warn(
656529
colors.yellow(

0 commit comments

Comments
 (0)