From 1814054edd4e4768bb497cd6ff5c3a2d496e72d4 Mon Sep 17 00:00:00 2001 From: Daniel Perez Alvarez Date: Mon, 11 Dec 2017 20:45:15 -0800 Subject: [PATCH] Update types for license-checker to 15.0 --- types/license-checker/index.d.ts | 159 +++++++++++------- .../license-checker/license-checker-tests.ts | 36 +++- 2 files changed, 122 insertions(+), 73 deletions(-) diff --git a/types/license-checker/index.d.ts b/types/license-checker/index.d.ts index d0286a05af..4ae2995ea0 100644 --- a/types/license-checker/index.d.ts +++ b/types/license-checker/index.d.ts @@ -1,86 +1,117 @@ -// Type definitions for license-checker 11.0 +// Type definitions for license-checker 15.0 // Project: https://github.com/davglass/license-checker -// Definitions by: Rogier Schouten +// Definitions by: Rogier Schouten , Daniel Perez Alvarez // Definitions: https://github.com/borisyankov/DefinitelyTyped /** * Options struct for the init() function */ export interface InitOpts { - /** - * Path to start checking dependencies from - */ - start: string; - /** - * only show production dependencies - */ - production?: boolean; - /** - * only show development dependencies - */ - development?: boolean; - /** - * report guessed licenses as unknown licenses - */ - unknown?: boolean; - /** - * only list packages with unknown or guessed licenses - */ - onlyunknown?: boolean; - /** - * to add a custom Format file in JSON - */ - customPath?: string; - /** - * exclude modules which licenses are in the comma-separated list from the output - */ - exclude?: string[]; - /** - * Use chalk to colorize the licenses member of each returned module info. Unknown licenses become red. - */ - color?: boolean; - /** - * output the location of the license files as relative paths - */ - relativeLicensePath?: boolean; + /** + * Path to start checking dependencies from + */ + start: string; + /** + * Only show production dependencies + */ + production?: boolean; + /** + * Only show development dependencies + */ + development?: boolean; + /** + * Report guessed licenses as unknown licenses + */ + unknown?: boolean; + /** + * Only list packages with unknown or guessed licenses + */ + onlyunknown?: boolean; + /** + * to add a custom Format file in JSON + */ + customPath?: string | ModuleInfo; + /** + * Exclude modules which licenses are in the comma-separated list from the output + */ + exclude?: string[]; + /** + * Output the location of the license files as relative paths + */ + relativeLicensePath?: boolean; + /** + * Output a summary of the license usage + */ + summary?: boolean; + /** + * Fail (exit with code 1) on the first occurrence of the licenses of the comma-separated list + */ + failOn?: string[]; + /** + * Use chalk to colorize the licenses member of each returned module info. Unknown licenses become red. + */ + color?: boolean; } /** * Information about one dependency */ export interface ModuleInfo { - /** - * licenses, either one string or an array of multiple licenses - */ - licenses: string | string[]; - /** - * Repository URL - */ - repository: string; - /** - * Publisher name - */ - publisher?: string; - /** - * Publisher e-mail - */ - email?: string; - /** - * Publisher URL - */ - url?: string; - /** - * Path to license file, if available - */ - licenseFile?: string; + /** + * Module name + */ + name?: string; + /** + * Module version + */ + version?: string; + /** + * Module description + */ + description?: string; + /** + * Repository URL + */ + repository?: string; + /** + * Publisher name + */ + publisher?: string; + /** + * Publisher e-mail + */ + email?: string; + /** + * Publisher URL + */ + url?: string; + /** + * Array of licenses + */ + licenses?: string | string[]; + /** + * Path to license file, if available + */ + licenseFile?: string; + /** + * Contents of the license + */ + licenseText?: string; + /** + * Whether the license is modified + */ + licenseModified?: string; } export interface ModuleInfos { - [packageName: string]: ModuleInfo; + [packageName: string]: ModuleInfo; } /** * Run the license check * @param opts specifies the path to the module to check dependencies of */ -export function init(opts: InitOpts, callback: (err: Error, ret: ModuleInfos) => void): void; +export function init( + opts: InitOpts, + callback: (err: Error, ret: ModuleInfos) => void +): void; diff --git a/types/license-checker/license-checker-tests.ts b/types/license-checker/license-checker-tests.ts index 0caf98a373..ab9039837f 100644 --- a/types/license-checker/license-checker-tests.ts +++ b/types/license-checker/license-checker-tests.ts @@ -1,13 +1,31 @@ // From README.md: -import * as checker from 'license-checker'; +import * as checker from "license-checker"; -checker.init({ - start: '/path/to/start/looking' -}, (err: Error, json: checker.ModuleInfos): void => { - if (err) { - // Handle error - } else { - // The sorted json data +checker.init( + { + start: "/path/to/start/looking", + production: true, + customPath: { + licenseText: "" + } + }, + (err: Error, json: checker.ModuleInfos): void => { + if (err) { + throw err; + } else { + const licenses = Object.keys(json).reduce( + (memo, key) => { + const license = json[key]; + const { name, version, repository, licenseText } = license; + if (licenseText == null) { + return memo; + } + memo.push(license); + return memo; + }, + [] as checker.ModuleInfo[] + ); + } } -}); +);