Skip to content

Commit a5799fa

Browse files
authored
feat(types): use terser types from terser package (#20274)
1 parent 535d4fe commit a5799fa

File tree

5 files changed

+20
-260
lines changed

5 files changed

+20
-260
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export default tseslint.config(
100100
'less',
101101
'sass',
102102
'sass-embedded',
103+
'terser',
103104
'lightningcss',
104105
'vitest',
105106
'unbuild',

packages/vite/src/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export type { Connect } from 'dep-types/connect'
252252
export type { WebSocket, WebSocketAlias } from 'dep-types/ws'
253253
export type { HttpProxy } from 'dep-types/http-proxy'
254254
export type { FSWatcher, WatchOptions } from 'dep-types/chokidar'
255-
export type { Terser } from 'dep-types/terser'
255+
export type { Terser } from 'types/internal/terserOptions'
256256
export type { RollupCommonJSOptions } from 'dep-types/commonjs'
257257
export type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
258258
export type { Matcher, AnymatchPattern, AnymatchFn } from 'dep-types/anymatch'

packages/vite/src/node/plugins/terser.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import type { Terser } from 'dep-types/terser'
1+
import type {
2+
TerserMinifyOptions,
3+
TerserMinifyOutput,
4+
} from 'types/internal/terserOptions'
25
import { WorkerWithFallback } from 'artichokie'
36
import type { Plugin } from '../plugin'
47
import type { ResolvedConfig } from '..'
58
import { requireResolveFromRootWithFallback } from '../utils'
69

7-
export interface TerserOptions extends Terser.MinifyOptions {
10+
export interface TerserOptions extends TerserMinifyOptions {
811
/**
912
* Vite-specific option to specify the max number of workers to spawn
1013
* when minifying files with terser.
@@ -42,12 +45,12 @@ export function terserPlugin(config: ResolvedConfig): Plugin {
4245
async (
4346
terserPath: string,
4447
code: string,
45-
options: Terser.MinifyOptions,
48+
options: TerserMinifyOptions,
4649
) => {
4750
// test fails when using `import`. maybe related: https://github.com/nodejs/node/issues/43205
4851
// eslint-disable-next-line no-restricted-globals -- this function runs inside cjs
4952
const terser = require(terserPath)
50-
return terser.minify(code, options) as Terser.MinifyOutput
53+
return terser.minify(code, options) as TerserMinifyOutput
5154
},
5255
{
5356
shouldUseFake(_terserPath, _code, options) {

packages/vite/src/types/terser.d.ts

Lines changed: 0 additions & 255 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
2+
3+
// @ts-ignore `terser` may not be installed
4+
export type * as Terser from 'terser'
5+
// @ts-ignore `terser` may not be installed
6+
import type * as Terser from 'terser'
7+
8+
/* eslint-enable @typescript-eslint/ban-ts-comment */
9+
10+
export type TerserMinifyOptions = Terser.MinifyOptions
11+
export type TerserMinifyOutput = Terser.MinifyOutput

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy