From bc4f7ba69b01c6f10f6ea26325bf61485adaa0ff Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 12 Jun 2020 13:26:37 +0200 Subject: [PATCH] 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 --- integrations/links_test.go | 2 - options/locale/locale_en-US.ini | 1 + package-lock.json | 113 ++++++++++++++++++++++++-- package.json | 4 +- public/vendor/librejs.html | 126 ----------------------------- templates/base/footer_content.tmpl | 2 +- templates/base/head.tmpl | 2 +- webpack.config.js | 30 +++++++ 8 files changed, 142 insertions(+), 138 deletions(-) delete mode 100644 public/vendor/librejs.html diff --git a/integrations/links_test.go b/integrations/links_test.go index e69d9306edd..2db07e88144 100644 --- a/integrations/links_test.go +++ b/integrations/links_test.go @@ -33,8 +33,6 @@ func TestLinksNoLogin(t *testing.T) { "/user/forgot_password", "/api/swagger", "/api/v1/swagger", - // TODO: follow this page and test every link - "/vendor/librejs.html", } for _, link := range links { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 958b70131ed..662ea49acae 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -20,6 +20,7 @@ user_profile_and_more = Profile and Settingsā€¦ signed_in_as = Signed in as enable_javascript = This website works better with JavaScript. toc = Table of Contents +licenses = Licenses username = Username email = Email Address diff --git a/package-lock.json b/package-lock.json index df89e97e024..4ee0f0d6582 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1158,8 +1158,7 @@ "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", - "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", - "dev": true + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" }, "@types/json-schema": { "version": "7.0.5", @@ -1209,12 +1208,34 @@ "csstype": "^2.2.0" } }, + "@types/source-list-map": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz", + "integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==" + }, "@types/unist": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz", "integrity": "sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==", "dev": true }, + "@types/webpack-sources": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.8.tgz", + "integrity": "sha512-JHB2/xZlXOjzjBB6fMOpH1eQAfsrpqVVIbneE0Rok16WXwFaznaI5vfg75U5WgGJm7V9W1c4xeRQDjX/zwvghA==", + "requires": { + "@types/node": "*", + "@types/source-list-map": "*", + "source-map": "^0.6.1" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + } + } + }, "@vue/component-compiler-utils": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/@vue/component-compiler-utils/-/component-compiler-utils-3.1.2.tgz", @@ -2818,6 +2839,17 @@ "string-width": "^1.0.1", "strip-ansi": "^3.0.1", "wrap-ansi": "^2.0.0" + }, + "dependencies": { + "wrap-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "requires": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1" + } + } } }, "clone": { @@ -7993,6 +8025,15 @@ "type-check": "~0.4.0" } }, + "license-webpack-plugin": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/license-webpack-plugin/-/license-webpack-plugin-2.2.0.tgz", + "integrity": "sha512-XPsdL/0brSHf+7dXIlRqotnCQ58RX2au6otkOg4U3dm8uH+Ka/fW4iukEs95uXm+qKe/SBs+s1Ll/aQddKG+tg==", + "requires": { + "@types/webpack-sources": "^0.1.5", + "webpack-sources": "^1.2.0" + } + }, "liftoff": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/liftoff/-/liftoff-3.1.0.tgz", @@ -15287,12 +15328,70 @@ } }, "wrap-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", - "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "requires": { - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==" + }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "requires": { + "ansi-regex": "^5.0.0" + } + } } }, "wrappy": { diff --git a/package.json b/package.json index 7d82df3713a..2320a45f4f2 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "jquery": "3.5.1", "jquery.are-you-sure": "1.9.0", "less-loader": "6.1.0", + "license-webpack-plugin": "2.2.0", "mini-css-extract-plugin": "0.9.0", "monaco-editor": "0.20.0", "monaco-editor-webpack-plugin": "1.9.0", @@ -48,7 +49,8 @@ "webpack-fix-style-only-entries": "0.5.0", "workbox-routing": "5.1.3", "workbox-strategies": "5.1.3", - "worker-loader": "2.0.0" + "worker-loader": "2.0.0", + "wrap-ansi": "7.0.0" }, "devDependencies": { "eslint": "7.2.0", diff --git a/public/vendor/librejs.html b/public/vendor/librejs.html deleted file mode 100644 index 4397f8a644a..00000000000 --- a/public/vendor/librejs.html +++ /dev/null @@ -1,126 +0,0 @@ - - - - - JavaScript and plugin license information - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ScriptLicenseSource
jquery.are-you-sure.jsExpatjquery.areyousure-1.9.0.tar.gz
jQueryMITjquery-3.5.0.min.js
semantic.min.jsExpatFomantic-UI-2.8.2.tar.gz
semantic.dropdownExpatsemantic.dropdown.custom.js
index.jsExpat*.js
clipboard.jsExpatclipboard-2.0.4.tar.gz
gitgraph.jsBSD 3-Clausegitgraph.js-latest
vueExpatvue.js-v2.6.11.tar.gz
dropzone.jsMITdropzone-master.tar.gz
highlight.jsBSD 3-Clausehighlight.js.tar.gz
jquery.minicolors.min.jsExpatjquery.minicolors-2.2.3.tar.gz
loadmode.jsExpatcodemirror-5.49.0.tar.gz
meta.jsExpatcodemirror-5.49.0.tar.gz
simplemde.min.jsExpatsimplemde-markdown-editor-1.10.1.tar.gz
pdf.jsApache-2.0-onlypdf.js-v2.1.266.tar.gz
u2f-apiExpatu2f-api-1.0.8.zip
font-awesome - fontsOFLfont-awesome-4.6.0.zip
roboto-fontsApache-2.0roboto-v20-latin-ext_cyrillic-ext_latin_greek_vietnamese_cyrillic_greek-ext.zip
font-awesome - codeExpatfont-awesome-4.6.0.zip
octiconsExpatocticons-v4.3.0.tar.gz
swagger-uiApache-2.0swagger-ui-v3.22.1.tar.gz
vue-calendar-heatmapMITmaster.zip
- - diff --git a/templates/base/footer_content.tmpl b/templates/base/footer_content.tmpl index db4c19c156b..b99a0008948 100644 --- a/templates/base/footer_content.tmpl +++ b/templates/base/footer_content.tmpl @@ -16,7 +16,7 @@ {{end}} - JavaScript licenses + {{.i18n.Tr "licenses"}} {{if .EnableSwagger}}API{{end}} {{.i18n.Tr "website"}} {{template "custom/extra_links_footer" .}} diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 9ad7f8496c8..0f575233aa2 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -52,7 +52,7 @@ THE SOFTWARE. --- Licensing information for additional javascript libraries can be found at: - {{StaticUrlPrefix}}/vendor/librejs.html + {{StaticUrlPrefix}}/js/licenses.txt @licend The above is the entire license notice for the JavaScript code in this page. diff --git a/webpack.config.js b/webpack.config.js index 85a046892b3..09caeb40292 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,