From 2945a7b70163f7f6aaef4019edaff721548a9ee9 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 2 Jan 2025 16:54:35 +0100 Subject: [PATCH] Add back zopfli compression (#23555) --- build-scripts/gulp/compress.js | 61 +++++++++++++++++++++++------- package.json | 1 + yarn.lock | 69 +++++++++++++++++++++++++++++++--- 3 files changed, 112 insertions(+), 19 deletions(-) diff --git a/build-scripts/gulp/compress.js b/build-scripts/gulp/compress.js index e1fff793a60a..81e1c87abed4 100644 --- a/build-scripts/gulp/compress.js +++ b/build-scripts/gulp/compress.js @@ -3,6 +3,7 @@ import { constants } from "node:zlib"; import gulp from "gulp"; import brotli from "gulp-brotli"; +import zopfli from "gulp-zopfli-green"; import paths from "../paths.cjs"; const filesGlob = "*.{js,json,css,svg,xml}"; @@ -12,17 +13,18 @@ const brotliOptions = { [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY, }, }; +const zopfliOptions = { threshold: 150 }; -const compressModern = (rootDir, modernDir) => +const compressModern = (rootDir, modernDir, compress) => gulp .src([`${modernDir}/**/${filesGlob}`, `${rootDir}/sw-modern.js`], { base: rootDir, allowEmpty: true, }) - .pipe(brotli(brotliOptions)) + .pipe(compress === "zopfli" ? zopfli(zopfliOptions) : brotli(brotliOptions)) .pipe(gulp.dest(rootDir)); -const compressOther = (rootDir, modernDir) => +const compressOther = (rootDir, modernDir, compress) => gulp .src( [ @@ -33,21 +35,52 @@ const compressOther = (rootDir, modernDir) => ], { base: rootDir, allowEmpty: true } ) - .pipe(brotli(brotliOptions)) + .pipe(compress === "zopfli" ? zopfli(zopfliOptions) : brotli(brotliOptions)) .pipe(gulp.dest(rootDir)); -const compressAppModern = () => - compressModern(paths.app_output_root, paths.app_output_latest); -const compressHassioModern = () => - compressModern(paths.hassio_output_root, paths.hassio_output_latest); +const compressAppModernBrotli = () => + compressModern(paths.app_output_root, paths.app_output_latest, "brotli"); +const compressAppModernZopfli = () => + compressModern(paths.app_output_root, paths.app_output_latest, "zopfli"); -const compressAppOther = () => - compressOther(paths.app_output_root, paths.app_output_latest); -const compressHassioOther = () => - compressOther(paths.hassio_output_root, paths.hassio_output_latest); +const compressHassioModernBrotli = () => + compressModern( + paths.hassio_output_root, + paths.hassio_output_latest, + "brotli" + ); +const compressHassioModernZopfli = () => + compressModern( + paths.hassio_output_root, + paths.hassio_output_latest, + "zopfli" + ); -gulp.task("compress-app", gulp.parallel(compressAppModern, compressAppOther)); +const compressAppOtherBrotli = () => + compressOther(paths.app_output_root, paths.app_output_latest, "brotli"); +const compressAppOtherZopfli = () => + compressOther(paths.app_output_root, paths.app_output_latest, "zopfli"); + +const compressHassioOtherBrotli = () => + compressOther(paths.hassio_output_root, paths.hassio_output_latest, "brotli"); +const compressHassioOtherZopfli = () => + compressOther(paths.hassio_output_root, paths.hassio_output_latest, "zopfli"); + +gulp.task( + "compress-app", + gulp.parallel( + compressAppModernBrotli, + compressAppOtherBrotli, + compressAppModernZopfli, + compressAppOtherZopfli + ) +); gulp.task( "compress-hassio", - gulp.parallel(compressHassioModern, compressHassioOther) + gulp.parallel( + compressHassioModernBrotli, + compressHassioOtherBrotli, + compressHassioModernZopfli, + compressHassioOtherZopfli + ) ); diff --git a/package.json b/package.json index 2cc7051a390b..fa7f97f838ab 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,7 @@ "element-internals-polyfill": "1.3.12", "fuse.js": "7.0.0", "google-timezones-json": "1.2.0", + "gulp-zopfli-green": "6.0.2", "hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch", "home-assistant-js-websocket": "9.4.0", "idb-keyval": "6.2.1", diff --git a/yarn.lock b/yarn.lock index a16777c70a44..d86b9c8915c2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1801,6 +1801,15 @@ __metadata: languageName: node linkType: hard +"@gfx/zopfli@npm:^1.0.15": + version: 1.0.15 + resolution: "@gfx/zopfli@npm:1.0.15" + dependencies: + base64-js: "npm:^1.3.0" + checksum: 10/2721ad8c0cbbdac7d5ca9e01ad05f232b4e3cdcecf88f9b0ef9a2bdc7d05e1ca54ea68905430cf36338ef1077acec178aa7b258c67baa7a4c2b6d74067605723 + languageName: node + linkType: hard + "@gulpjs/messages@npm:^1.1.0": version: 1.1.0 resolution: "@gulpjs/messages@npm:1.1.0" @@ -5684,6 +5693,13 @@ __metadata: languageName: node linkType: hard +"any-promise@npm:^1.1.0": + version: 1.3.0 + resolution: "any-promise@npm:1.3.0" + checksum: 10/6737469ba353b5becf29e4dc3680736b9caa06d300bda6548812a8fee63ae7d336d756f88572fa6b5219aed36698d808fa55f62af3e7e6845c7a1dc77d240edb + languageName: node + linkType: hard + "anymatch@npm:^3.1.3, anymatch@npm:~3.1.2": version: 3.1.3 resolution: "anymatch@npm:3.1.3" @@ -6030,7 +6046,7 @@ __metadata: languageName: node linkType: hard -"base64-js@npm:^1.3.1": +"base64-js@npm:^1.3.0, base64-js@npm:^1.3.1": version: 1.5.1 resolution: "base64-js@npm:1.5.1" checksum: 10/669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005 @@ -6237,7 +6253,7 @@ __metadata: languageName: node linkType: hard -"bytes@npm:3.1.2": +"bytes@npm:3.1.2, bytes@npm:^3.1.2": version: 3.1.2 resolution: "bytes@npm:3.1.2" checksum: 10/a10abf2ba70c784471d6b4f58778c0beeb2b5d405148e66affa91f23a9f13d07603d0a0354667310ae1d6dc141474ffd44e2a074be0f6e2254edb8fc21445388 @@ -7070,7 +7086,7 @@ __metadata: languageName: node linkType: hard -"defaults@npm:^1.0.3": +"defaults@npm:^1.0.3, defaults@npm:^1.0.4": version: 1.0.4 resolution: "defaults@npm:1.0.4" dependencies: @@ -8180,7 +8196,7 @@ __metadata: languageName: node linkType: hard -"fancy-log@npm:2.0.0": +"fancy-log@npm:2.0.0, fancy-log@npm:^2.0.0": version: 2.0.0 resolution: "fancy-log@npm:2.0.0" dependencies: @@ -8973,6 +8989,21 @@ __metadata: languageName: node linkType: hard +"gulp-zopfli-green@npm:6.0.2": + version: 6.0.2 + resolution: "gulp-zopfli-green@npm:6.0.2" + dependencies: + "@gfx/zopfli": "npm:^1.0.15" + bytes: "npm:^3.1.2" + defaults: "npm:^1.0.4" + fancy-log: "npm:^2.0.0" + plugin-error: "npm:^2.0.1" + stream-to-array: "npm:^2.3.0" + through2: "npm:^4.0.2" + checksum: 10/52e899dfb86777ff8f97a23af99c59e203ea485fbf04d0a8f4f1cfbd4d4c496808a3593ae8dac16584fc4b4d81cf127b2eda5355a61bcc213875c95cc86d41da + languageName: node + linkType: hard + "gulp@npm:5.0.0": version: 5.0.0 resolution: "gulp@npm:5.0.0" @@ -9254,6 +9285,7 @@ __metadata: gulp-brotli: "npm:3.0.0" gulp-json-transform: "npm:0.5.0" gulp-rename: "npm:2.0.0" + gulp-zopfli-green: "npm:6.0.2" hls.js: "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch" home-assistant-js-websocket: "npm:9.4.0" html-minifier-terser: "npm:7.2.0" @@ -12161,6 +12193,15 @@ __metadata: languageName: node linkType: hard +"plugin-error@npm:^2.0.1": + version: 2.0.1 + resolution: "plugin-error@npm:2.0.1" + dependencies: + ansi-colors: "npm:^1.0.1" + checksum: 10/9a4f91461cd24cce401112098969991d7aa6b4c94f78e0381234280c07da779570a8b21ab143292b534ec0117c09705a67e5d756c1c303d4706fdd7f861bf5bc + languageName: node + linkType: hard + "pngjs@npm:^3.0.0, pngjs@npm:^3.3.3": version: 3.4.0 resolution: "pngjs@npm:3.4.0" @@ -12383,7 +12424,7 @@ __metadata: languageName: node linkType: hard -"readable-stream@npm:2 || 3, readable-stream@npm:^3.0.6, readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.0": +"readable-stream@npm:2 || 3, readable-stream@npm:3, readable-stream@npm:^3.0.6, readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.0": version: 3.6.2 resolution: "readable-stream@npm:3.6.2" dependencies: @@ -13566,6 +13607,15 @@ __metadata: languageName: node linkType: hard +"stream-to-array@npm:^2.3.0": + version: 2.3.0 + resolution: "stream-to-array@npm:2.3.0" + dependencies: + any-promise: "npm:^1.1.0" + checksum: 10/7feaf63b38399b850615e6ffcaa951e96e4c8f46745dbce4b553a94c5dc43966933813747014935a3ff97793e7f30a65270bde19f82b2932871a1879229a77cf + languageName: node + linkType: hard + "streamx@npm:^2.12.0, streamx@npm:^2.12.5, streamx@npm:^2.13.2, streamx@npm:^2.14.0": version: 2.21.1 resolution: "streamx@npm:2.21.1" @@ -13993,6 +14043,15 @@ __metadata: languageName: node linkType: hard +"through2@npm:^4.0.2": + version: 4.0.2 + resolution: "through2@npm:4.0.2" + dependencies: + readable-stream: "npm:3" + checksum: 10/72c246233d9a989bbebeb6b698ef0b7b9064cb1c47930f79b25d87b6c867e075432811f69b7b2ac8da00ca308191c507bdab913944be8019ac43b036ce88f6ba + languageName: node + linkType: hard + "thunky@npm:^1.0.2": version: 1.1.0 resolution: "thunky@npm:1.1.0"