Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default tseslint.config(
'less',
'sass',
'sass-embedded',
'terser',
'lightningcss',
'vitest',
'unbuild',
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export type { Connect } from 'dep-types/connect'
export type { WebSocket, WebSocketAlias } from 'dep-types/ws'
export type { HttpProxy } from 'dep-types/http-proxy'
export type { FSWatcher, WatchOptions } from 'dep-types/chokidar'
export type { Terser } from 'dep-types/terser'
export type { Terser } from 'types/internal/terserOptions'
export type { RollupCommonJSOptions } from 'dep-types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
export type { Matcher, AnymatchPattern, AnymatchFn } from 'dep-types/anymatch'
Expand Down
11 changes: 7 additions & 4 deletions packages/vite/src/node/plugins/terser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { Terser } from 'dep-types/terser'
import type {
TerserMinifyOptions,
TerserMinifyOutput,
} from 'types/internal/terserOptions'
import { WorkerWithFallback } from 'artichokie'
import type { Plugin } from '../plugin'
import type { ResolvedConfig } from '..'
import { requireResolveFromRootWithFallback } from '../utils'

export interface TerserOptions extends Terser.MinifyOptions {
export interface TerserOptions extends TerserMinifyOptions {
/**
* Vite-specific option to specify the max number of workers to spawn
* when minifying files with terser.
Expand Down Expand Up @@ -42,12 +45,12 @@ export function terserPlugin(config: ResolvedConfig): Plugin {
async (
terserPath: string,
code: string,
options: Terser.MinifyOptions,
options: TerserMinifyOptions,
) => {
// test fails when using `import`. maybe related: https://github.com/nodejs/node/issues/43205
// eslint-disable-next-line no-restricted-globals -- this function runs inside cjs
const terser = require(terserPath)
return terser.minify(code, options) as Terser.MinifyOutput
return terser.minify(code, options) as TerserMinifyOutput
},
{
shouldUseFake(_terserPath, _code, options) {
Expand Down
255 changes: 0 additions & 255 deletions packages/vite/src/types/terser.d.ts

This file was deleted.

11 changes: 11 additions & 0 deletions packages/vite/types/internal/terserOptions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

// @ts-ignore `terser` may not be installed
export type * as Terser from 'terser'
// @ts-ignore `terser` may not be installed
import type * as Terser from 'terser'

/* eslint-enable @typescript-eslint/ban-ts-comment */

export type TerserMinifyOptions = Terser.MinifyOptions
export type TerserMinifyOutput = Terser.MinifyOutput
Comment on lines +10 to +11
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to re-export the type instead of other modules importing Terser directly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to avoid Terser to be renamed to Terser$1 in the output dts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see 👍