License generation tool similar to https://github.com/mjeanroy/rollup-plugin-license
- Yiming Li - Original Author
- Chris
- td-michal-kepka - Fork Author
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'
})
The available options are:
Name | Description |
---|---|
additionalFiles |
Default: {} . 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> . |
excludedPackageTest |
A 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. |
file |
Default: oss-licenses.json . Specifies the path to the output file that will be generated. The path is relative to the bundle output directory. |
unacceptableLicenseTest |
A 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. |
includePrivate |
A boolean that determines whether private packages should be included in the output. |
template |
A 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 . |
banner |
A 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
- Install newest
pnpm
with major version 7:
npm install -g pnpm@7
- Install dependencies without lock file changes:
pnpm install --frozen-lockfile
- Check if all commands work and tests pass:
pnpm run build
pnpm run dev
pnpm run test