Skip to content

Commit

Permalink
feat: support ignore by kind
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Sep 6, 2024
1 parent d781872 commit 5d46f4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/core/options.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import type { FilterPattern } from '@rollup/pluginutils'

export type DepKind = 'dependencies' | 'devDependencies' | 'peerDependencies'

export interface Options {
root?: string
include?: FilterPattern
exclude?: FilterPattern
ignore?: string[]
ignore?: string[] | Record<DepKind, string[]>
/**
* @default 'warning'
*/
level?: 'warning' | 'error'
/**
* @default ['dependencies', 'peerDependencies']
*/
depKinds?: Array<'dependencies' | 'devDependencies' | 'peerDependencies'>
depKinds?: Array<DepKind>
}

type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ const plugin: UnpluginInstance<Options | undefined, false> = createUnplugin(
for (const kind of options.depKinds) {
const dependencies = Object.keys(pkg[kind] || {})
for (const dep of dependencies) {
if (options.ignore.includes(dep) || deps.has(dep)) continue
const ignore = Array.isArray(options.ignore)
? options.ignore
: options.ignore[kind]
if (ignore.includes(dep) || deps.has(dep)) continue
deps.add(dep)
depsRegex[dep] = new RegExp(`["']${escapeStringRegexp(dep)}['"\\/]`)
}
Expand Down

0 comments on commit 5d46f4e

Please sign in to comment.