1.0.1 • Published 11 months ago

@transmission-dynamics/esbuild-plugin-license v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

@transmission-dynamics/esbuild-plugin-license

npm (tag) npm

License generation tool similar to https://github.com/mjeanroy/rollup-plugin-license

Contributors

Usage

npm i -D @transmission-dynamics/esbuild-plugin-license
import * as esbuild from 'esbuild'
import esbuildPluginLicense from 'esbuild-plugin-license';

esbuild.build({
  entryPoints: ['index.ts'],
  outdir: 'dist',
  plugins: [esbuildPluginLicense()],
  bundle: true,
  platform: 'node'
})

Config

The available options are:

NameDescription
additionalFilesDefault: {}. An object that defines additional files to be generated by the plugin based on its default output (e.g., an HTML representation of the licenses in addition to the generated JSON). The keys represent filenames, while the values are functions invoked with the packages array and return the content to be written to the additional file. These functions can return a string or a Promise<string>.
excludedPackageTestA function used to exclude specific packages from the process. It is invoked with the packageName (string) of each package and should return true to exclude the package from the output.
fileDefault: oss-licenses.json. Specifies the path to the output file that will be generated. The path is relative to the bundle output directory.
unacceptableLicenseTestA function that defines unacceptable license identifiers. It is invoked with the license (string) of each package and should return true when the license is considered unacceptable, causing the build to fail.
includePrivateA boolean that determines whether private packages should be included in the output.
templateA function that customizes the generated file content. It accepts the packages array as an argument and should return the generated file content as a string.
bannerA string banner inserted at the beginning of the bundled file. Supports Lodash template format for dynamic content generation.

Example of default config

export const defaultOptions: DeepRequired<Options> = {
  banner: `/*! <%= pkg.name %> v<%= pkg.version %> | <%= pkg.license %> */`,
  thirdParty: {
    includePrivate: false,
    excludedPackageTest: (packageName) => false,
    additionalFiles: {},
    unacceptableLicenseTest: (license) => false,
    output: {
      file: 'oss-licenses.json',
      // Template function that can be defined to customize report output
      template(dependencies) {
        // Default template function
      },
    }
  }
} as const

How to run this project

  1. Install newest pnpm with major version 7:
  npm install -g pnpm@7
  1. Install dependencies without lock file changes:
  pnpm install --frozen-lockfile
  1. Check if all commands work and tests pass:
  pnpm run build
  pnpm run dev
  pnpm run test
1.0.1

11 months ago

1.0.0

11 months ago