Skip to content

Commit 13da14e

Browse files
committed
chore(ts): improve thirdParty.allow typings
1 parent fae72a8 commit 13da14e

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

src/index.d.ts

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -216,42 +216,60 @@ export type ThirdPartyOutput = string | ((dependencies: Dependency[]) => void) |
216216
template?: ((dependencies: Dependency[]) => string) | string,
217217
};
218218

219+
/**
220+
* SPDX Licence Identifier.
221+
*/
222+
type SpdxId = string;
223+
224+
/**
225+
* Function checking dependency license validity.
226+
*/
227+
type ThirdPartyDependencyValidatorFn = (Dependency: Dependency) => boolean;
228+
229+
type ThirdPartyValidator = SpdxId | ThirdPartyDependencyValidatorFn;
230+
231+
interface ThirdPartyAllowOptions {
232+
/**
233+
* Testing if the license if valid
234+
*/
235+
test: ThirdPartyValidator;
236+
237+
/**
238+
* Fail if a dependency does not specify any licenses
239+
* @default false
240+
*/
241+
failOnUnlicensed?: boolean;
242+
243+
/**
244+
* Fail if a dependency specify a license that does not match given requirement
245+
* @default false
246+
*/
247+
failOnViolation?: boolean;
248+
}
249+
219250
export type ThirdParty = ((dependencies: Dependency[]) => void) | {
220251
/**
221-
* If private dependencies should be allowed (`private: true` in package.json)
252+
* If private dependencies should be checked (`private: true` in package.json)
222253
* @default false
223254
*/
224255
includePrivate?: boolean,
225256

226257
/**
227258
* Ensures that dependencies does not violate any license restriction.
259+
*
228260
* For example, suppose you want to limit dependencies with MIT or Apache-2.0
229-
* licenses, simply define the restriction such as:
261+
* licenses, simply define the restriction:
262+
*
230263
* @example
231-
* {allow: '(MIT OR Apache-2.0)'}
264+
* {
265+
* allow: '(MIT OR Apache-2.0)'
266+
* }
232267
*
233-
* allow(dependency) {
234-
* return dependency.license === 'MIT';
235-
* }
236-
*/
237-
allow?: string | ((dependency: Dependency) => boolean) | {
238-
/**
239-
* Testing if the license if valid
240-
*/
241-
test: string | ((dependency: Dependency) => boolean),
242-
243-
/**
244-
* Fail if a dependency does not specify any licenses
245-
* @default false
246-
*/
247-
failOnUnlicensed?: boolean,
248-
249-
/**
250-
* Fail if a dependency specify a license that does not match given requirement
251-
* @default false
252-
*/
253-
failOnViolation?: boolean,
254-
},
268+
* allow(dependency) {
269+
* return dependency.license === 'MIT';
270+
* }
271+
*/
272+
allow?: ThirdPartyValidator | ThirdPartyAllowOptions,
255273

256274
/**
257275
* Output file for

0 commit comments

Comments
 (0)