From 256168aba8cbb2a9adc048b3dfc81179d09b21ae Mon Sep 17 00:00:00 2001 From: Mickael Jeanroy Date: Mon, 15 Mar 2021 09:13:38 +0100 Subject: [PATCH] chore: put typings in dist directory --- index.d.ts | 210 ----------------------------------------- package.json | 3 +- scripts/build/index.js | 24 ++++- src/index.d.ts | 208 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 216 deletions(-) delete mode 100644 index.d.ts create mode 100644 src/index.d.ts diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 64750cc9..00000000 --- a/index.d.ts +++ /dev/null @@ -1,210 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2016-2020 Mickael Jeanroy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import type { Plugin } from "rollup"; - -export interface Person { - readonly name: string, - readonly email: string | null, - readonly url: string | null, - - /** - * Turns the person into a formatted string - * @returns formatted person info - */ - text: ()=> string, -} - -export type CommentStyle = "regular" | "ignored" | "slash"; - -export type Banner = string | { - - /** - * @see {@link https://github.com/mjeanroy/rollup-plugin-license#comment-style} - */ - commentStyle?: CommentStyle, - content: string | (()=> string) | { - - /** - * File to get banner content from - */ - file: string, - - /** - * @default utf-8 - */ - encoding?: string, - }, - data?: {[key: string]: string} | (()=> {[key: string]: string}), -}; - -/** - * Dependency information is derived from the package.json file - */ -export interface Dependency { - readonly name: string, - readonly maintainers: string[], - readonly version: string, - readonly description: string, - readonly repository: { - readonly url: string, - readonly type: string, - }, - readonly homepage: string, - - /** - * If dependency is private - */ - readonly private: boolean, - - /** - * SPDX License short ID - */ - readonly license: string, - - /** - * Full License file text - */ - readonly licenseText: string, - - /** - * Author information - */ - readonly author: Person, - readonly contributors: Person[], - - /** - * Turns the dependency into a formatted string - * @returns formatted dependency license info - */ - text: ()=> string, -} - -export type ThirdPartyOutput = string | ((dependencies: Dependency[])=> void) | { - - /** - * Name of file to write licenses to - */ - file: string, - - /** - * @default utf-8 - */ - encoding?: string, - - /** - * @example - * // Template function that can be defined to customize report output - * template(dependencies) { - * return dependencies.map((dependency) => ( - * `${dependency.name}:${dependency.version} -- ${dependency.license}`).join('\n') - * ); - * }, - * - * // Lodash template that can be defined to customize report output - * template: ` - * <% _.forEach(dependencies, function (dependency) { %> - * <%= dependency.name %>:<%= dependency.version%> -- <%= dependency.license %> - * <% }) %> - * ` - */ - template?: ((dependencies: Dependency[])=> string) | string, -}; - -export type ThirdParty = ((dependencies: Dependency[])=> void) | { - - /** - * If private dependencies should be allowed (`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: - * @example - * {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, - }, - - /** - * Output file for - */ - output: ThirdPartyOutput | ThirdPartyOutput[], -}; - -export type Options = { - sourcemap?: boolean | string, - - /** - * Debug mode - * @default false - */ - debug?: boolean, - - /** - * Current Working Directory - * @default process.cwd() - */ - cwd?: string, - - /** - * License banner to place at the top of your bundle - */ - banner?: Banner, - - /** - * For third party dependencies. - * Creates a file containing a summary of all dependencies can be generated - * automatically - */ - thirdParty?: ThirdParty, -} - -declare function rollupPluginLicense(options: Options): Plugin; - -export default rollupPluginLicense diff --git a/package.json b/package.json index 300fc25b..85dce6d4 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "2.3.0", "description": "Rollup plugin to add license banner to the final bundle and output third party licenses", "main": "dist/index.js", - "types": "index.d.ts", + "types": "dist/index.d.ts", + "typings": "dist/index.d.ts", "scripts": { "lint": "gulp lint", "clean": "gulp clean", diff --git a/scripts/build/index.js b/scripts/build/index.js index d858fa08..12031291 100644 --- a/scripts/build/index.js +++ b/scripts/build/index.js @@ -22,13 +22,27 @@ * SOFTWARE. */ +const path = require('path'); +const gulp = require('gulp'); const rollup = require('rollup'); -const config = require('./rollup.config'); +const rollupConfig = require('./rollup.config'); +const config = require('../config'); -module.exports = function build() { - return rollup.rollup(config).then((bundle) => ( - Promise.all(config.output.map((output) => ( +module.exports = gulp.series( + buildOutput, + copyTypings +); + +// eslint-disable-next-line require-jsdoc +function buildOutput() { + return rollup.rollup(rollupConfig).then((bundle) => ( + Promise.all(rollupConfig.output.map((output) => ( bundle.write(output) ))) )); -}; +} + +// eslint-disable-next-line require-jsdoc +function copyTypings() { + return gulp.src(path.join(config.src, 'index.d.ts')).pipe(gulp.dest(config.dist)); +} diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 00000000..5a0e2b1e --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,208 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016-2020 Mickael Jeanroy + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import type { Plugin } from "rollup"; + +export interface Person { + readonly name: string, + readonly email: string | null, + readonly url: string | null, + + /** + * Turns the person into a formatted string + * @returns formatted person info + */ + text: ()=> string, +} + +export type CommentStyle = "regular" | "ignored" | "slash"; + +export type Banner = string | { + /** + * @see {@link https://github.com/mjeanroy/rollup-plugin-license#comment-style} + */ + commentStyle?: CommentStyle, + content: string | (()=> string) | { + + /** + * File to get banner content from + */ + file: string, + + /** + * @default utf-8 + */ + encoding?: string, + }, + data?: {[key: string]: string} | (()=> {[key: string]: string}), +}; + +/** + * Dependency information is derived from the package.json file + */ +export interface Dependency { + readonly name: string, + readonly maintainers: string[], + readonly version: string, + readonly description: string, + readonly repository: { + readonly url: string, + readonly type: string, + }, + readonly homepage: string, + + /** + * If dependency is private + */ + readonly private: boolean, + + /** + * SPDX License short ID + */ + readonly license: string, + + /** + * Full License file text + */ + readonly licenseText: string, + + /** + * Author information + */ + readonly author: Person, + readonly contributors: Person[], + + /** + * Turns the dependency into a formatted string + * @returns formatted dependency license info + */ + text: ()=> string, +} + +export type ThirdPartyOutput = string | ((dependencies: Dependency[])=> void) | { + + /** + * Name of file to write licenses to + */ + file: string, + + /** + * @default utf-8 + */ + encoding?: string, + + /** + * @example + * // Template function that can be defined to customize report output + * template(dependencies) { + * return dependencies.map((dependency) => ( + * `${dependency.name}:${dependency.version} -- ${dependency.license}`).join('\n') + * ); + * }, + * + * // Lodash template that can be defined to customize report output + * template: ` + * <% _.forEach(dependencies, function (dependency) { %> + * <%= dependency.name %>:<%= dependency.version%> -- <%= dependency.license %> + * <% }) %> + * ` + */ + template?: ((dependencies: Dependency[])=> string) | string, +}; + +export type ThirdParty = ((dependencies: Dependency[])=> void) | { + /** + * If private dependencies should be allowed (`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: + * @example + * {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, + }, + + /** + * Output file for + */ + output: ThirdPartyOutput | ThirdPartyOutput[], +}; + +export type Options = { + sourcemap?: boolean | string, + + /** + * Debug mode + * @default false + */ + debug?: boolean, + + /** + * Current Working Directory + * @default process.cwd() + */ + cwd?: string, + + /** + * License banner to place at the top of your bundle + */ + banner?: Banner, + + /** + * For third party dependencies. + * Creates a file containing a summary of all dependencies can be generated + * automatically + */ + thirdParty?: ThirdParty, +} + +declare function rollupPluginLicense(options: Options): Plugin; + +export default rollupPluginLicense