Skip to content

Commit bc4f7ba

Browse files
silverwindlafriks
andauthored
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: #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 <[email protected]>
1 parent 2b573f4 commit bc4f7ba

File tree

8 files changed

+142
-138
lines changed

8 files changed

+142
-138
lines changed

integrations/links_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ func TestLinksNoLogin(t *testing.T) {
3333
"/user/forgot_password",
3434
"/api/swagger",
3535
"/api/v1/swagger",
36-
// TODO: follow this page and test every link
37-
"/vendor/librejs.html",
3836
}
3937

4038
for _, link := range links {

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ user_profile_and_more = Profile and Settings…
2020
signed_in_as = Signed in as
2121
enable_javascript = This website works better with JavaScript.
2222
toc = Table of Contents
23+
licenses = Licenses
2324

2425
username = Username
2526
email = Email Address

package-lock.json

Lines changed: 106 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"jquery": "3.5.1",
2626
"jquery.are-you-sure": "1.9.0",
2727
"less-loader": "6.1.0",
28+
"license-webpack-plugin": "2.2.0",
2829
"mini-css-extract-plugin": "0.9.0",
2930
"monaco-editor": "0.20.0",
3031
"monaco-editor-webpack-plugin": "1.9.0",
@@ -48,7 +49,8 @@
4849
"webpack-fix-style-only-entries": "0.5.0",
4950
"workbox-routing": "5.1.3",
5051
"workbox-strategies": "5.1.3",
51-
"worker-loader": "2.0.0"
52+
"worker-loader": "2.0.0",
53+
"wrap-ansi": "7.0.0"
5254
},
5355
"devDependencies": {
5456
"eslint": "7.2.0",

public/vendor/librejs.html

Lines changed: 0 additions & 126 deletions
This file was deleted.

templates/base/footer_content.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{{end}}
1717
</div>
1818
</div>
19-
<a href="{{StaticUrlPrefix}}/vendor/librejs.html" data-jslicense="1">JavaScript licenses</a>
19+
<a href="{{StaticUrlPrefix}}/js/licenses.txt">{{.i18n.Tr "licenses"}}</a>
2020
{{if .EnableSwagger}}<a href="{{AppSubUrl}}/api/swagger">API</a>{{end}}
2121
<a target="_blank" rel="noopener noreferrer" href="https://gitea.io">{{.i18n.Tr "website"}}</a>
2222
{{template "custom/extra_links_footer" .}}

templates/base/head.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
THE SOFTWARE.
5353
---
5454
Licensing information for additional javascript libraries can be found at:
55-
{{StaticUrlPrefix}}/vendor/librejs.html
55+
{{StaticUrlPrefix}}/js/licenses.txt
5656

5757
@licend The above is the entire license notice
5858
for the JavaScript code in this page.

webpack.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const cssnano = require('cssnano');
22
const fastGlob = require('fast-glob');
3+
const wrapAnsi = require('wrap-ansi');
34
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
45
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
56
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
@@ -11,6 +12,7 @@ const TerserPlugin = require('terser-webpack-plugin');
1112
const VueLoaderPlugin = require('vue-loader/lib/plugin');
1213
const {statSync} = require('fs');
1314
const {resolve, parse} = require('path');
15+
const {LicenseWebpackPlugin} = require('license-webpack-plugin');
1416
const {SourceMapDevToolPlugin} = require('webpack');
1517

1618
const glob = (pattern) => fastGlob.sync(pattern, {cwd: __dirname, absolute: true});
@@ -241,6 +243,34 @@ module.exports = {
241243
new MonacoWebpackPlugin({
242244
filename: 'js/monaco-[name].worker.js',
243245
}),
246+
new LicenseWebpackPlugin({
247+
outputFilename: 'js/licenses.txt',
248+
perChunkOutput: false,
249+
addBanner: false,
250+
skipChildCompilers: true,
251+
modulesDirectories: [
252+
resolve(__dirname, 'node_modules'),
253+
],
254+
additionalModules: [
255+
{
256+
name: 'fomantic-ui',
257+
directory: resolve(__dirname, 'node_modules/fomantic-ui'),
258+
},
259+
],
260+
renderLicenses: (modules) => {
261+
const line = '-'.repeat(80);
262+
return modules.map((module) => {
263+
const {name, version} = module.packageJson;
264+
const {licenseId, licenseText} = module;
265+
const body = wrapAnsi(licenseText || '', 80);
266+
return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`;
267+
}).join('\n');
268+
},
269+
stats: {
270+
warnings: false,
271+
errors: true,
272+
},
273+
}),
244274
],
245275
performance: {
246276
hints: false,

0 commit comments

Comments
 (0)