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 <lauris@nix.lv>
This commit is contained in:
silverwind 2020-06-12 13:26:37 +02:00 committed by GitHub
parent 2b573f49cf
commit bc4f7ba69b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 142 additions and 138 deletions

View File

@ -33,8 +33,6 @@ func TestLinksNoLogin(t *testing.T) {
"/user/forgot_password", "/user/forgot_password",
"/api/swagger", "/api/swagger",
"/api/v1/swagger", "/api/v1/swagger",
// TODO: follow this page and test every link
"/vendor/librejs.html",
} }
for _, link := range links { for _, link := range links {

View File

@ -20,6 +20,7 @@ user_profile_and_more = Profile and Settings…
signed_in_as = Signed in as signed_in_as = Signed in as
enable_javascript = This website works better with JavaScript. enable_javascript = This website works better with JavaScript.
toc = Table of Contents toc = Table of Contents
licenses = Licenses
username = Username username = Username
email = Email Address email = Email Address

113
package-lock.json generated
View File

@ -1158,8 +1158,7 @@
"@types/color-name": { "@types/color-name": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
"integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ=="
"dev": true
}, },
"@types/json-schema": { "@types/json-schema": {
"version": "7.0.5", "version": "7.0.5",
@ -1209,12 +1208,34 @@
"csstype": "^2.2.0" "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": { "@types/unist": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz",
"integrity": "sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==", "integrity": "sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==",
"dev": true "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": { "@vue/component-compiler-utils": {
"version": "3.1.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/@vue/component-compiler-utils/-/component-compiler-utils-3.1.2.tgz", "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", "string-width": "^1.0.1",
"strip-ansi": "^3.0.1", "strip-ansi": "^3.0.1",
"wrap-ansi": "^2.0.0" "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": { "clone": {
@ -7993,6 +8025,15 @@
"type-check": "~0.4.0" "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": { "liftoff": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/liftoff/-/liftoff-3.1.0.tgz", "resolved": "https://registry.npmjs.org/liftoff/-/liftoff-3.1.0.tgz",
@ -15287,12 +15328,70 @@
} }
}, },
"wrap-ansi": { "wrap-ansi": {
"version": "2.1.0", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
"integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
"requires": { "requires": {
"string-width": "^1.0.1", "ansi-styles": "^4.0.0",
"strip-ansi": "^3.0.1" "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": { "wrappy": {

View File

@ -25,6 +25,7 @@
"jquery": "3.5.1", "jquery": "3.5.1",
"jquery.are-you-sure": "1.9.0", "jquery.are-you-sure": "1.9.0",
"less-loader": "6.1.0", "less-loader": "6.1.0",
"license-webpack-plugin": "2.2.0",
"mini-css-extract-plugin": "0.9.0", "mini-css-extract-plugin": "0.9.0",
"monaco-editor": "0.20.0", "monaco-editor": "0.20.0",
"monaco-editor-webpack-plugin": "1.9.0", "monaco-editor-webpack-plugin": "1.9.0",
@ -48,7 +49,8 @@
"webpack-fix-style-only-entries": "0.5.0", "webpack-fix-style-only-entries": "0.5.0",
"workbox-routing": "5.1.3", "workbox-routing": "5.1.3",
"workbox-strategies": "5.1.3", "workbox-strategies": "5.1.3",
"worker-loader": "2.0.0" "worker-loader": "2.0.0",
"wrap-ansi": "7.0.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "7.2.0", "eslint": "7.2.0",

View File

@ -1,126 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript and plugin license information</title>
</head>
<body>
<table id="jslicense-labels1">
<thead>
<tr><th>Script</th><th>License</th><th>Source</th></tr>
</thead>
<tbody>
<tr>
<td><a href="../js/index.js">jquery.are-you-sure.js</a></td>
<td><a href="http://www.freebsd.org/copyright/freebsd-license.html">Expat</a></td>
<td><a href="https://github.com/codedance/jquery.AreYouSure/archive/1.9.0.tar.gz">jquery.areyousure-1.9.0.tar.gz</a></td>
</tr>
<tr>
<td><a href="../js/jquery.js">jQuery</a></td>
<td><a href="https://jquery.org/license/">MIT</a></td>
<td><a href="https://code.jquery.com/jquery-3.5.0.min.js">jquery-3.5.0.min.js</a></td>
</tr>
<tr>
<td><a href="../fomantic/semantic.min.js">semantic.min.js</a></td>
<td><a href="https://github.com/fomantic/Fomantic-UI/blob/master/LICENSE.md">Expat</a></td>
<td><a href="https://github.com/fomantic/Fomantic-UI/archive/2.8.2.tar.gz">Fomantic-UI-2.8.2.tar.gz</a></td>
</tr>
<tr>
<td><a href="../js/index.js">semantic.dropdown</a></td>
<td><a href="https://semantic-ui.mit-license.org/">Expat</a></td>
<td><a href="https://github.com/go-gitea/gitea/tree/master/web_src/vendor/semantic.dropdown">semantic.dropdown.custom.js</a></td>
</tr>
<tr>
<td><a href="../js/index.js">index.js</a></td>
<td><a href="https://github.com/go-gitea/gitea/blob/master/LICENSE">Expat</a></td>
<td><a href="https://github.com/go-gitea/gitea/tree/master/web_src/js">*.js</a></td>
</tr>
<tr>
<td><a href="../js/clipboard.js">clipboard.js</a></td>
<td><a href="http://www.freebsd.org/copyright/freebsd-license.html">Expat</a></td>
<td><a href="https://github.com/zenorocha/clipboard.js/archive/v2.0.4.tar.gz">clipboard-2.0.4.tar.gz</a></td>
</tr>
<tr>
<td><a href="../js/gitgraph.js">gitgraph.js</a></td>
<td><a href="https://github.com/bluef/gitgraph.js/blob/master/LICENSE">BSD 3-Clause</a></td>
<td><a href="https://github.com/bluef/gitgraph.js">gitgraph.js-latest</a></td>
</tr>
<tr>
<td><a href="../js/index.js">vue</a></td>
<td><a href="https://github.com/vuejs/vue/blob/dev/LICENSE">Expat</a></td>
<td><a href="https://github.com/vuejs/vue/archive/v2.6.11.tar.gz">vue.js-v2.6.11.tar.gz</a></td>
</tr>
<tr>
<td><a href="../js/dropzone.js">dropzone.js</a></td>
<td><a href="https://github.com/enyo/dropzone/blob/master/LICENSE">MIT</a></td>
<td><a href="https://github.com/enyo/dropzone/archive/master.tar.gz">dropzone-master.tar.gz</a></td>
</tr>
<tr>
<td><a href="../js/highlight.js">highlight.js</a></td>
<td><a href="https://github.com/highlightjs/highlight.js/blob/master/LICENSE">BSD 3-Clause</a></td>
<td><a href="https://github.com/highlightjs/highlight.js/archive/9.18.0.tar.gz">highlight.js.tar.gz</a></td>
</tr>
<tr>
<td><a href="./plugins/jquery.minicolors/jquery.minicolors.min.js">jquery.minicolors.min.js</a></td>
<td><a href="https://github.com/claviska/jquery-minicolors/blob/master/LICENSE.md">Expat</a></td>
<td><a href="https://github.com/claviska/jquery-minicolors/archive/2.2.3.tar.gz">jquery.minicolors-2.2.3.tar.gz</a></td>
</tr>
<tr>
<td><a href="./plugins/codemirror/addon/mode/loadmode.js">loadmode.js</a></td>
<td><a href="https://github.com/codemirror/CodeMirror/blob/master/LICENSE">Expat</a></td>
<td><a href="https://github.com/codemirror/CodeMirror/archive/5.49.0.tar.gz">codemirror-5.49.0.tar.gz</a></td>
</tr>
<tr>
<td><a href="./plugins/codemirror/mode/meta.js">meta.js</a></td>
<td><a href="https://github.com/codemirror/CodeMirror/blob/master/LICENSE">Expat</a></td>
<td><a href="https://github.com/codemirror/CodeMirror/archive/5.49.0.tar.gz">codemirror-5.49.0.tar.gz</a></td>
</tr>
<tr>
<td><a href="./plugins/simplemde/simplemde.min.js">simplemde.min.js</a></td>
<td><a href="https://github.com/sparksuite/simplemde-markdown-editor/blob/master/LICENSE">Expat</a></td>
<td><a href="https://github.com/NextStepWebs/simplemde-markdown-editor/archive/1.10.1.tar.gz">simplemde-markdown-editor-1.10.1.tar.gz</a></td>
</tr>
<tr>
<td><a href="./plugins/pdfjs/">pdf.js</a></td>
<td><a href="https://github.com/mozilla/pdf.js/blob/master/LICENSE">Apache-2.0-only</a></td>
<td><a href="https://github.com/mozilla/pdf.js/archive/v2.1.266.tar.gz">pdf.js-v2.1.266.tar.gz</a></td>
</tr>
<tr>
<td><a href="./plugins/u2f/">u2f-api</a></td>
<td><a href="https://github.com/go-gitea/u2f-api/blob/master/LICENSE">Expat</a></td>
<td><a href="https://github.com/go-gitea/u2f-api/archive/v1.0.8.zip">u2f-api-1.0.8.zip</a></td>
</tr>
<tr>
<td><a href="./assets/font-awesome/fonts/">font-awesome - fonts</a></td>
<td><a href="http://fontawesome.io/license/">OFL</a></td>
<td><a href="http://fontawesome.io/assets/font-awesome-4.6.0.zip">font-awesome-4.6.0.zip</a></td>
</tr>
<tr>
<td><a href="./assets/roboto-fonts/">roboto-fonts</a></td>
<td><a href="https://github.com/google/roboto/blob/master/LICENSE">Apache-2.0</a></td>
<td><a href="https://google-webfonts-helper.herokuapp.com/api/fonts/roboto?download=zip&subsets=latin-ext,cyrillic-ext,latin,greek,vietnamese,cyrillic,greek-ext&variants=700,regular,italic,700italic">roboto-v20-latin-ext_cyrillic-ext_latin_greek_vietnamese_cyrillic_greek-ext.zip</a></td>
</tr>
<tr>
<td><a href="./assets/font-awesome/css/">font-awesome - code</a></td>
<td><a href="http://fontawesome.io/license/">Expat</a></td>
<td><a href="http://fontawesome.io/assets/font-awesome-4.6.0.zip">font-awesome-4.6.0.zip</a></td>
</tr>
<tr>
<td><a href="./assets/octicons/">octicons</a></td>
<td><a href="https://github.com/primer/octicons/blob/master/LICENSE">Expat</a></td>
<td><a href="https://github.com/primer/octicons/archive/v4.3.0.tar.gz">octicons-v4.3.0.tar.gz</a></td>
</tr>
<tr>
<td><a href="./assets/swagger-ui/">swagger-ui</a></td>
<td><a href="https://github.com/swagger-api/swagger-ui/blob/master/LICENSE">Apache-2.0</a></td>
<td><a href="https://github.com/swagger-api/swagger-ui/archive/v3.22.1.tar.gz">swagger-ui-v3.22.1.tar.gz</a></td>
</tr>
<tr>
<td><a href="../js/index.js">vue-calendar-heatmap</a></td>
<td><a href="https://github.com/WildCodeSchool/vue-calendar-heatmap/blob/master/README.md">MIT</a></td>
<td><a href="https://github.com/WildCodeSchool/vue-calendar-heatmap/archive/master.zip">master.zip</a></td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -16,7 +16,7 @@
{{end}} {{end}}
</div> </div>
</div> </div>
<a href="{{StaticUrlPrefix}}/vendor/librejs.html" data-jslicense="1">JavaScript licenses</a> <a href="{{StaticUrlPrefix}}/js/licenses.txt">{{.i18n.Tr "licenses"}}</a>
{{if .EnableSwagger}}<a href="{{AppSubUrl}}/api/swagger">API</a>{{end}} {{if .EnableSwagger}}<a href="{{AppSubUrl}}/api/swagger">API</a>{{end}}
<a target="_blank" rel="noopener noreferrer" href="https://gitea.io">{{.i18n.Tr "website"}}</a> <a target="_blank" rel="noopener noreferrer" href="https://gitea.io">{{.i18n.Tr "website"}}</a>
{{template "custom/extra_links_footer" .}} {{template "custom/extra_links_footer" .}}

View File

@ -52,7 +52,7 @@
THE SOFTWARE. THE SOFTWARE.
--- ---
Licensing information for additional javascript libraries can be found at: 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 @licend The above is the entire license notice
for the JavaScript code in this page. for the JavaScript code in this page.

View File

@ -1,5 +1,6 @@
const cssnano = require('cssnano'); const cssnano = require('cssnano');
const fastGlob = require('fast-glob'); const fastGlob = require('fast-glob');
const wrapAnsi = require('wrap-ansi');
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries'); const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-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 VueLoaderPlugin = require('vue-loader/lib/plugin');
const {statSync} = require('fs'); const {statSync} = require('fs');
const {resolve, parse} = require('path'); const {resolve, parse} = require('path');
const {LicenseWebpackPlugin} = require('license-webpack-plugin');
const {SourceMapDevToolPlugin} = require('webpack'); const {SourceMapDevToolPlugin} = require('webpack');
const glob = (pattern) => fastGlob.sync(pattern, {cwd: __dirname, absolute: true}); const glob = (pattern) => fastGlob.sync(pattern, {cwd: __dirname, absolute: true});
@ -241,6 +243,34 @@ module.exports = {
new MonacoWebpackPlugin({ new MonacoWebpackPlugin({
filename: 'js/monaco-[name].worker.js', 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: { performance: {
hints: false, hints: false,