Feat/lightningcss (#6427)

* Added lightning css for minification of css

* Added esbuild for minification

* Upgraded to Node 22

* Fixed.

* Temporary change branch

* Rebased changes.
This commit is contained in:
SamTV12345 2024-06-03 22:32:06 +02:00 committed by GitHub
parent b376688f75
commit 426174d491
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 5329 additions and 3946 deletions

View file

@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [18, 20, 21]
node: [18, 20, 22]
steps:
-
name: Checkout repository
@ -81,7 +81,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [18, 20, 21]
node: [18, 20, 22]
steps:
-
name: Checkout repository
@ -211,7 +211,7 @@ jobs:
-
uses: actions/setup-node@v4
with:
node-version: 21
node-version: 22
- uses: pnpm/action-setup@v4
name: Install pnpm
with:

View file

@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [20, 21]
node: [20, 22]
steps:
-

View file

@ -26,7 +26,7 @@ jobs:
-
uses: actions/setup-node@v4
with:
node-version: 21
node-version: 22
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
@ -92,7 +92,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 21
node-version: 22
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
@ -159,7 +159,7 @@ jobs:
-
uses: actions/setup-node@v4
with:
node-version: 21
node-version: 22
- uses: pnpm/action-setup@v4
name: Install pnpm
with:

View file

@ -24,13 +24,13 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [18, 20, 21]
node: [18, 20, 22]
steps:
-
name: Check out latest release
uses: actions/checkout@v4
with:
ref: master
ref: develop #FIXME change to master when doing release
-
uses: actions/setup-node@v4
with:

View file

@ -34,7 +34,7 @@ jobs:
-
uses: actions/setup-node@v4
with:
node-version: 21
node-version: 22
- uses: pnpm/action-setup@v4
name: Install pnpm
with:

File diff suppressed because it is too large Load diff

View file

@ -3,31 +3,45 @@
* Worker thread to minify JS & CSS files out of the main NodeJS thread
*/
const CleanCSS = require('clean-css');
const Terser = require('terser');
const fsp = require('fs').promises;
const path = require('path');
const Threads = require('threads');
import path from 'node:path'
import {expose} from 'threads'
import lightminify from 'lightningcss'
import {transform} from 'esbuild';
const compressJS = (content) => Terser.minify(content);
/*
* Minify JS content
* @param {string} content - JS content to minify
*/
const compressJS = async (content) => {
return await transform(content, {minify: true});
}
/*
* Minify CSS content
* @param {string} filename - name of the file
* @param {string} ROOT_DIR - the root dir of Etherpad
*/
const compressCSS = async (filename, ROOT_DIR) => {
const absPath = path.resolve(ROOT_DIR, filename);
try {
const basePath = path.dirname(absPath);
const output = await new CleanCSS({
rebase: true,
rebaseTo: basePath,
}).minify([absPath]);
return output.styles;
const file = await fsp.readFile(absPath, 'utf8');
let { code } = lightminify.transform({
errorRecovery: true,
filename: basePath,
minify: true,
code: Buffer.from(file, 'utf8')
});
return code.toString();
} catch (error) {
// on error, just yield the un-minified original, but write a log message
console.error(`Unexpected error minifying ${filename} (${absPath}): ${error}`);
console.error(`Unexpected error minifying ${filename} (${absPath}): ${JSON.stringify(error)}`);
return await fsp.readFile(absPath, 'utf8');
}
};
Threads.expose({
compressJS,
expose({
compressJS: compressJS,
compressCSS,
});

View file

@ -32,7 +32,6 @@
"dependencies": {
"async": "^3.2.5",
"axios": "^1.7.2",
"clean-css": "^5.3.3",
"cookie-parser": "^1.4.6",
"cross-spawn": "^7.0.3",
"ejs": "^3.1.10",
@ -51,9 +50,11 @@
"jsonminify": "0.4.2",
"jsonwebtoken": "^9.0.2",
"languages4translatewiki": "0.1.3",
"lightningcss": "^1.25.1",
"live-plugin-manager": "^1.0.0",
"lodash.clonedeep": "4.5.0",
"log4js": "^6.9.1",
"lru-cache": "^10.2.0",
"measured-core": "^2.0.0",
"mime-types": "^2.1.35",
"oidc-provider": "^8.4.5",
@ -68,15 +69,13 @@
"socket.io": "^4.7.5",
"socket.io-client": "^4.7.5",
"superagent": "^9.0.2",
"terser": "^5.30.3",
"threads": "^1.7.0",
"tinycon": "0.6.8",
"tsx": "^4.11.2",
"ueberdb2": "^4.2.63",
"underscore": "1.13.6",
"unorm": "1.6.0",
"wtfnode": "^0.9.2",
"lru-cache": "^10.2.0"
"wtfnode": "^0.9.2"
},
"bin": {
"etherpad-healthcheck": "../bin/etherpad-healthcheck",
@ -97,6 +96,7 @@
"@types/sinon": "^17.0.3",
"@types/supertest": "^6.0.2",
"@types/underscore": "^1.11.15",
"esbuild": "^0.21.4",
"eslint": "^9.2.0",
"eslint-config-etherpad": "^4.0.4",
"etherpad-cli-client": "^3.0.2",