Skip to content

Commit

Permalink
refactor: default to warning
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Sep 1, 2024
1 parent 00a0a50 commit e287e9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/core/options.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import type { FilterPattern } from '@rollup/pluginutils'

export interface Options {
enable?: boolean
root?: string
include?: FilterPattern
exclude?: FilterPattern
/**
* @default 'warning'
*/
level?: 'warning' | 'error'
}

type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U

export type OptionsResolved = Overwrite<
Required<Options>,
Pick<Options, 'enable' | 'root'>
Pick<Options, 'root'>
>

export function resolveOptions(options: Options): OptionsResolved {
return {
include: options.include || [/\.([cm]?[jt]sx?|vue)$/],
exclude: options.exclude || [/node_modules/],
level: options.level || 'warning',
}
}
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ const plugin: UnpluginInstance<Options | undefined, false> = createUnplugin(

buildEnd() {
if (deps.size) {
throw new Error(
const error = new Error(
`Unused dependencies found: ${Array.from(deps).join(', ')}`,
)
if (options.level === 'error') {
throw error
} else {
console.warn(error)
}
}
},

vite: {
configResolved(config) {
options.enable ??= config.command === 'build'
options.root ||= config.root
},
},
Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export default defineConfig({
cjsInterop: true,
clean: true,
dts: true,
esbuildPlugins: [Unused()],
esbuildPlugins: [Unused({ level: 'error' })],
})

0 comments on commit e287e9a

Please sign in to comment.