Skip to content

Commit

Permalink
chore(ts): improve thirdParty.allow typings
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed May 31, 2021
1 parent fae72a8 commit 13da14e
Showing 1 changed file with 43 additions and 25 deletions.
68 changes: 43 additions & 25 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,42 +216,60 @@ export type ThirdPartyOutput = string | ((dependencies: Dependency[]) => void) |
template?: ((dependencies: Dependency[]) => string) | string,
};

/**
* SPDX Licence Identifier.
*/
type SpdxId = string;

/**
* Function checking dependency license validity.
*/
type ThirdPartyDependencyValidatorFn = (Dependency: Dependency) => boolean;

type ThirdPartyValidator = SpdxId | ThirdPartyDependencyValidatorFn;

interface ThirdPartyAllowOptions {
/**
* Testing if the license if valid
*/
test: ThirdPartyValidator;

/**
* Fail if a dependency does not specify any licenses
* @default false
*/
failOnUnlicensed?: boolean;

/**
* Fail if a dependency specify a license that does not match given requirement
* @default false
*/
failOnViolation?: boolean;
}

export type ThirdParty = ((dependencies: Dependency[]) => void) | {
/**
* If private dependencies should be allowed (`private: true` in package.json)
* If private dependencies should be checked (`private: true` in package.json)
* @default false
*/
includePrivate?: boolean,

/**
* Ensures that dependencies does not violate any license restriction.
*
* For example, suppose you want to limit dependencies with MIT or Apache-2.0
* licenses, simply define the restriction such as:
* licenses, simply define the restriction:
*
* @example
* {allow: '(MIT OR Apache-2.0)'}
* {
* allow: '(MIT OR Apache-2.0)'
* }
*
* allow(dependency) {
* return dependency.license === 'MIT';
* }
*/
allow?: string | ((dependency: Dependency) => boolean) | {
/**
* Testing if the license if valid
*/
test: string | ((dependency: Dependency) => boolean),

/**
* Fail if a dependency does not specify any licenses
* @default false
*/
failOnUnlicensed?: boolean,

/**
* Fail if a dependency specify a license that does not match given requirement
* @default false
*/
failOnViolation?: boolean,
},
* allow(dependency) {
* return dependency.license === 'MIT';
* }
*/
allow?: ThirdPartyValidator | ThirdPartyAllowOptions,

/**
* Output file for
Expand Down

0 comments on commit 13da14e

Please sign in to comment.