diff --git a/src/core/options.ts b/src/core/options.ts index bb84821..7c9ea92 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -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 = Pick> & U export type OptionsResolved = Overwrite< Required, - Pick + Pick > export function resolveOptions(options: Options): OptionsResolved { return { include: options.include || [/\.([cm]?[jt]sx?|vue)$/], exclude: options.exclude || [/node_modules/], + level: options.level || 'warning', } } diff --git a/src/index.ts b/src/index.ts index 628dd47..f079f29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,15 +47,19 @@ const plugin: UnpluginInstance = 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 }, }, diff --git a/tsup.config.ts b/tsup.config.ts index dd140fd..d4a11b4 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -9,5 +9,5 @@ export default defineConfig({ cjsInterop: true, clean: true, dts: true, - esbuildPlugins: [Unused()], + esbuildPlugins: [Unused({ level: 'error' })], })