mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
lint: src/node/utils/MinifyWorker.js
This commit is contained in:
parent
b5e04d867e
commit
b11ba23208
1 changed files with 20 additions and 23 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* Worker thread to minify JS & CSS files out of the main NodeJS thread
|
* Worker thread to minify JS & CSS files out of the main NodeJS thread
|
||||||
*/
|
*/
|
||||||
|
@ -7,16 +8,13 @@ const Terser = require('terser');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Threads = require('threads');
|
const Threads = require('threads');
|
||||||
|
|
||||||
function compressJS(content) {
|
const compressJS = (content) => Terser.minify(content);
|
||||||
return Terser.minify(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function compressCSS(filename, ROOT_DIR) {
|
const compressCSS = (filename, ROOT_DIR) => new Promise((res, rej) => {
|
||||||
return new Promise((res, rej) => {
|
try {
|
||||||
try {
|
const absPath = path.join(ROOT_DIR, filename);
|
||||||
const absPath = path.join(ROOT_DIR, filename);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Changes done to migrate CleanCSS 3.x -> 4.x:
|
* Changes done to migrate CleanCSS 3.x -> 4.x:
|
||||||
*
|
*
|
||||||
* 1. Rework the rebase logic, because the API was simplified (but we have
|
* 1. Rework the rebase logic, because the API was simplified (but we have
|
||||||
|
@ -41,23 +39,22 @@ function compressCSS(filename, ROOT_DIR) {
|
||||||
* in an array and ask the library to read it by itself.
|
* in an array and ask the library to read it by itself.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const basePath = path.dirname(absPath);
|
const basePath = path.dirname(absPath);
|
||||||
|
|
||||||
new CleanCSS({
|
new CleanCSS({
|
||||||
rebase: true,
|
rebase: true,
|
||||||
rebaseTo: basePath,
|
rebaseTo: basePath,
|
||||||
}).minify([absPath], (errors, minified) => {
|
}).minify([absPath], (errors, minified) => {
|
||||||
if (errors) return rej(errors);
|
if (errors) return rej(errors);
|
||||||
|
|
||||||
return res(minified.styles);
|
return res(minified.styles);
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// on error, just yield the un-minified original, but write a log message
|
// 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}): ${error}`);
|
||||||
callback(null, content);
|
callback(null, content);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Threads.expose({
|
Threads.expose({
|
||||||
compressJS,
|
compressJS,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue