From bc4f7ba69b01c6f10f6ea26325bf61485adaa0ff Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 12 Jun 2020 13:26:37 +0200 Subject: Add automatic JS license generation (#11810) * Add automatic JS license generation Removed librejs file and replaced it with a plaintext file that is built from all JS dependencies that are included in the webpack build. It does not cover the few remaining statically vendored files and fomantic is added manually because it's not yet in the webpack build process. Fixes: https://github.com/go-gitea/gitea/issues/11630 * fix lint * remove jslicense, we're not librejs compatible any more * remove license.txt test as it depens on absent files * small optimization * trailing comma * localize and capitalize the word 'licenses' * reduce text to just 'Licenses' Co-authored-by: Lauris BH --- webpack.config.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'webpack.config.js') diff --git a/webpack.config.js b/webpack.config.js index 85a046892b..09caeb4029 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,6 @@ const cssnano = require('cssnano'); const fastGlob = require('fast-glob'); +const wrapAnsi = require('wrap-ansi'); const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); @@ -11,6 +12,7 @@ const TerserPlugin = require('terser-webpack-plugin'); const VueLoaderPlugin = require('vue-loader/lib/plugin'); const {statSync} = require('fs'); const {resolve, parse} = require('path'); +const {LicenseWebpackPlugin} = require('license-webpack-plugin'); const {SourceMapDevToolPlugin} = require('webpack'); const glob = (pattern) => fastGlob.sync(pattern, {cwd: __dirname, absolute: true}); @@ -241,6 +243,34 @@ module.exports = { new MonacoWebpackPlugin({ filename: 'js/monaco-[name].worker.js', }), + new LicenseWebpackPlugin({ + outputFilename: 'js/licenses.txt', + perChunkOutput: false, + addBanner: false, + skipChildCompilers: true, + modulesDirectories: [ + resolve(__dirname, 'node_modules'), + ], + additionalModules: [ + { + name: 'fomantic-ui', + directory: resolve(__dirname, 'node_modules/fomantic-ui'), + }, + ], + renderLicenses: (modules) => { + const line = '-'.repeat(80); + return modules.map((module) => { + const {name, version} = module.packageJson; + const {licenseId, licenseText} = module; + const body = wrapAnsi(licenseText || '', 80); + return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`; + }).join('\n'); + }, + stats: { + warnings: false, + errors: true, + }, + }), ], performance: { hints: false, -- cgit v1.2.3