Skip to content

Commit

Permalink
Merge pull request #5 from rambler-digital-solutions/exclude
Browse files Browse the repository at this point in the history
feat: support option to exclude licenses by the list
  • Loading branch information
andrepolischuk authored Mar 1, 2023
2 parents 3c1f94a + 1707652 commit 3126b0a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ licenselint --help
--summary Output a summary of the license usage
--deny Fail on an occurrence of the licenses of the deny list
--allow Fail on an occurrence of the licenses not in the allow list
--exclude Exclude modules which licenses are in the list
--extends Use custom configuration file

Examples
Expand Down
6 changes: 6 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const cli = meow<any>(
--summary Output a summary of the license usage
--deny Fail on an occurrence of the licenses of the deny list
--allow Fail on an occurrence of the licenses not in the allow list
--exclude Exclude modules which licenses are in the list
--extends Use custom configuration file
Examples
Expand Down Expand Up @@ -54,6 +55,11 @@ const cli = meow<any>(
type: 'string',
default: defaultArray,
isMultiple: true
},
exclude: {
type: 'string',
default: defaultArray,
isMultiple: true
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ test('lint licenses with allow list', async () => {
expect(errors.map((result) => result.licenses)).not.toContain('MIT')
expect(errors.map((result) => result.licenses)).not.toContain('ISC')
})

test('lint licenses with exclude list', async () => {
const options = {
production: true,
exclude: ['Apache-2.0']
}
const results = await lint(entry, options)
expect(results.map((result) => result.licenses)).not.toContain('Apache-2.0')
})
12 changes: 10 additions & 2 deletions src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ export const lint = (
options: Options
): Promise<LicenseResult[]> =>
new Promise<LicenseResult[]>((resolve, reject) => {
const {production, development, deny = [], allow = []} = options
const {
production,
development,
deny = [],
allow = [],
exclude = []
} = options

const checkerOptions: InitOpts = {
start: entry,
production,
development
development,
// NOTE fix wrong `exclude` type
exclude: exclude.toString() as unknown as string[]
}

licenseChecker.init(checkerOptions, (error: Error, modulesInfo) => {
Expand Down
4 changes: 3 additions & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ export interface Options {
summary?: boolean
deny?: string[]
allow?: string[]
exclude?: string[]
}

export const defaultOptions: Partial<Options> = {
production: false,
development: false,
summary: false,
deny: [],
allow: []
allow: [],
exclude: []
}

const defaultOptionsFileName = '.licenserc.json'
Expand Down

0 comments on commit 3126b0a

Please sign in to comment.