Skip to content

Commit

Permalink
chore(deps): move Mousetrap to new client build workflow
Browse files Browse the repository at this point in the history
Changes include:
- Moved moustrap and moustrap-global-bind to  be managed in client/.
- Removed old bundles.
- Build the new bundle with moustrap and mousetrap-bind-global.
- Updated base.html to include the new bundles.
- Removed old license files and generated a new one.
- Added LLVM-exception.txt to licesne to stay reuse compliant with the new changes.
  • Loading branch information
meel-hd authored and nijel committed Nov 15, 2024
1 parent 90fc25f commit 41b6231
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 1,141 deletions.
15 changes: 15 additions & 0 deletions LICENSES/LLVM-exception.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---- LLVM Exceptions to the Apache 2.0 License ----

As an exception, if, as a result of your compiling your source code, portions
of this Software are embedded into an Object form of such source code, you
may redistribute such embedded portions in such Object form without complying
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.

In addition, if you combine or link compiled forms of this Software with
software that is licensed under the GPLv2 ("Combined Software") and if a
court of competent jurisdiction determines that the patent provision (Section
3), the indemnity provision (Section 9) or other Section of the License
conflicts with the conditions of the GPLv2, you may retroactively and
prospectively choose to deem waived or otherwise exclude such Section(s) of
the License, but only in their entirety and only with respect to the Combined
Software.
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"daterangepicker": "3.1.0",
"jquery": "3.7.1",
"moment": "2.30.1",
"mousetrap": "1.6.5",
"mousetrap-global-bind": "1.1.0",
"multi.js": "0.5.3",
"tributejs": "5.1.3"
},
Expand Down
8 changes: 8 additions & 0 deletions client/src/mousetrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright © Michal Čihař <[email protected]>
//
// SPDX-License-Identifier: GPL-3.0-or-later

import Mousetrap from "mousetrap";
import "mousetrap-global-bind";

window.Mousetrap = Mousetrap;
28 changes: 28 additions & 0 deletions client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ const TerserPlugin = require("terser-webpack-plugin");
const LicensePlugin = require("webpack-license-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

// Regular expression to match copyright lines
const copyrightRegex = /Copyright.*\n/;

// REUSE-IgnoreStart
// Function to extract copyright information from a package
function extractCopyright(pkg) {
if (pkg.licenseText !== null) {
const copyrights = pkg.licenseText.match(copyrightRegex);
Expand All @@ -21,6 +23,7 @@ function extractCopyright(pkg) {
return `Copyright ${pkg.author}\n`;
}

// Generic function to transform package information
function genericTransform(packages, filter) {
const mainPackages = packages.filter(filter);
const licenses = [...new Set(mainPackages.map((pkg) => pkg.license))]
Expand All @@ -35,32 +38,54 @@ SPDX-License-Identifier: ${licenses}
`;
}
// REUSE-IgnoreEnd
// License transform function for global packages used in main.js
function mainLicenseTransform(packages) {
const excludePrefixes = [
"@sentry",
"tributejs",
"@tarekraafat/autocomplete.js",
"autosize",
"multi.js",
"mousetrap",
];
return genericTransform(
packages,
(pkg) => !excludePrefixes.some((prefix) => pkg.name.startsWith(prefix)),
);
}

function sentryLicenseTransform(packages) {
return genericTransform(packages, (pkg) => pkg.name.startsWith("@sentry"));
}

function tributeLicenseTransform(packages) {
return genericTransform(packages, (pkg) => pkg.name.startsWith("tributejs"));
}

function autosizeLicenseTransform(packages) {
return genericTransform(packages, (pkg) => pkg.name.startsWith("autosize"));
}

function multiJsLicenseTransform(packages) {
return genericTransform(packages, (pkg) => pkg.name.startsWith("multi.js"));
}

// REUSE-IgnoreStart
function mousetrapLicenseTransform(packages) {
const pkg = packages.find((pkg) => pkg.name.startsWith("mousetrap"));
if (pkg) {
const author =
typeof pkg.author === "string"
? pkg.author
: pkg.author?.email
? `${pkg.author.name} <${pkg.author.email}>`
: pkg.author?.name
? pkg.author.name
: "";
return `SPDX-FileCopyrightText: ${author}\n\nSPDX-License-Identifier: ${pkg.license}`;
}
return "";
}
function autoCompleteLicenseTransform(packages) {
const pkg = packages.find((pkgsItem) =>
pkgsItem.name.startsWith("@tarekraafat/autocomplete.js"),
Expand All @@ -80,6 +105,7 @@ function autoCompleteLicenseTransform(packages) {
}
// REUSE-IgnoreEnd

// Webpack configuration
module.exports = {
entry: {
main: "./src/main.js",
Expand All @@ -88,6 +114,7 @@ module.exports = {
autoComplete: "./src/autoComplete.js",
autosize: "./src/autosize.js",
multi: "./src/multi.js",
mousetrap: "./src/mousetrap.js",
},
mode: "production",
optimization: {
Expand Down Expand Up @@ -121,6 +148,7 @@ module.exports = {
"autosize.js.license": autosizeLicenseTransform,
"multi.js.license": multiJsLicenseTransform,
"multi.css.license": multiJsLicenseTransform,
"mousetrap.js.license": mousetrapLicenseTransform,
},
}),
new MiniCssExtractPlugin({
Expand Down
10 changes: 10 additions & 0 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,16 @@ [email protected], moment@^2.9.0:
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==

[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mousetrap-global-bind/-/mousetrap-global-bind-1.1.0.tgz#cd7de9222bd0646fa2e010d54c84a74c26a88edd"
integrity sha512-AfxKB0OYc/wU66E2n2HXcZmKHrd5O/6mEdtSrZAt3tsMqcpcpYAolQdj602L0SgrP38ncm/6iOpxr9SIGgxOpQ==

[email protected]:
version "1.6.5"
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.5.tgz#8a766d8c272b08393d5f56074e0b5ec183485bf9"
integrity sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA==

[email protected]:
version "0.5.3"
resolved "https://registry.yarnpkg.com/multi.js/-/multi.js-0.5.3.tgz#544426bf2a12eb0c990401a75db52150869f2e2b"
Expand Down
6 changes: 0 additions & 6 deletions scripts/yarn-update
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ cd scripts/yarn/

yarn install --check-files

# Mousetrap
cp node_modules/mousetrap/mousetrap.js ../../weblate/static/vendor/

# Mousetrap global bind
cp node_modules/mousetrap-global-bind/mousetrap-global-bind.js ../../weblate/static/vendor/

# Prismjs
cp node_modules/prismjs/components/prism-core.js ../../weblate/static/vendor/prism/
cp node_modules/prismjs/components/prism-markup.js ../../weblate/static/vendor/prism/
Expand Down
2 changes: 0 additions & 2 deletions scripts/yarn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"main": "index.js",
"license": "GPL-3.0+",
"dependencies": {
"mousetrap": "1.6.5",
"mousetrap-global-bind": "1.1.0",
"prismjs": "1.29.0",
"slugify": "1.6.6",
"source-code-pro": "2.38.0",
Expand Down
10 changes: 0 additions & 10 deletions scripts/yarn/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
# yarn lockfile v1


[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mousetrap-global-bind/-/mousetrap-global-bind-1.1.0.tgz#cd7de9222bd0646fa2e010d54c84a74c26a88edd"
integrity sha512-AfxKB0OYc/wU66E2n2HXcZmKHrd5O/6mEdtSrZAt3tsMqcpcpYAolQdj602L0SgrP38ncm/6iOpxr9SIGgxOpQ==

[email protected]:
version "1.6.5"
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.5.tgz#8a766d8c272b08393d5f56074e0b5ec183485bf9"
integrity sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA==

[email protected]:
version "1.29.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.29.0.tgz#f113555a8fa9b57c35e637bba27509dcf802dd12"
Expand Down
1 change: 1 addition & 0 deletions weblate/static/js/vendor/mousetrap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions weblate/static/js/vendor/mousetrap.js.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Craig Campbell

SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
57 changes: 0 additions & 57 deletions weblate/static/vendor/mousetrap-global-bind.js

This file was deleted.

3 changes: 0 additions & 3 deletions weblate/static/vendor/mousetrap-global-bind.js.license

This file was deleted.

Loading

0 comments on commit 41b6231

Please sign in to comment.