diff --git a/package.json b/package.json index 2ebb28f24d515..acd1dc9dbc638 100644 --- a/package.json +++ b/package.json @@ -1246,7 +1246,6 @@ "@types/chromedriver": "^81.0.1", "@types/classnames": "^2.2.9", "@types/color": "^3.0.3", - "@types/compression-webpack-plugin": "^2.0.2", "@types/cytoscape": "^3.14.0", "@types/d3": "^3.5.43", "@types/d3-array": "^2.12.1", @@ -1274,7 +1273,6 @@ "@types/geojson": "^7946.0.10", "@types/getos": "^3.0.0", "@types/gulp": "^4.0.6", - "@types/gulp-zip": "^4.0.1", "@types/hapi__cookie": "^10.1.3", "@types/hapi__h2o2": "^8.3.3", "@types/hapi__hapi": "^20.0.9", @@ -1408,7 +1406,6 @@ "chromedriver": "^116.0.0", "clean-webpack-plugin": "^3.0.0", "cli-table3": "^0.6.1", - "compression-webpack-plugin": "^4.0.0", "copy-webpack-plugin": "^6.0.2", "cpy": "^8.1.1", "css-loader": "^3.4.2", @@ -1461,7 +1458,6 @@ "gulp-postcss": "^9.0.1", "gulp-sourcemaps": "2.6.5", "gulp-terser": "^2.1.0", - "gulp-zip": "^5.0.2", "has-ansi": "^3.0.0", "hdr-histogram-js": "^1.2.0", "html": "1.0.0", diff --git a/packages/kbn-optimizer/src/worker/webpack.config.ts b/packages/kbn-optimizer/src/worker/webpack.config.ts index 986ec051637e4..189ca29072afe 100644 --- a/packages/kbn-optimizer/src/worker/webpack.config.ts +++ b/packages/kbn-optimizer/src/worker/webpack.config.ts @@ -15,7 +15,6 @@ import webpack from 'webpack'; import TerserPlugin from 'terser-webpack-plugin'; import webpackMerge from 'webpack-merge'; import { CleanWebpackPlugin } from 'clean-webpack-plugin'; -import CompressionPlugin from 'compression-webpack-plugin'; import UiSharedDepsNpm from '@kbn/ui-shared-deps-npm'; import * as UiSharedDepsSrc from '@kbn/ui-shared-deps-src'; @@ -271,15 +270,6 @@ export function getWebpackConfig( IS_KIBANA_DISTRIBUTABLE: `"true"`, }, }), - new CompressionPlugin({ - algorithm: 'brotliCompress', - filename: '[path].br', - test: /\.(js|css)$/, - cache: false, - compressionOptions: { - level: 11, - }, - }), ], optimization: { diff --git a/packages/kbn-plugin-helpers/src/cli.ts b/packages/kbn-plugin-helpers/src/cli.ts index 96da79f75d6c8..21f183dea5e4a 100644 --- a/packages/kbn-plugin-helpers/src/cli.ts +++ b/packages/kbn-plugin-helpers/src/cli.ts @@ -87,6 +87,7 @@ export function runCli() { await Tasks.initTargets(context); await Tasks.buildBazelPackages(context); await Tasks.optimize(context); + await Tasks.brotliCompressBundles(context); await Tasks.writePublicAssets(context); await Tasks.writeServerFiles(context); await Tasks.yarnInstall(context); diff --git a/packages/kbn-plugin-helpers/src/integration_tests/build.test.ts b/packages/kbn-plugin-helpers/src/integration_tests/build.test.ts index 6a88c40ce8f8b..420f8d3bb7c8f 100644 --- a/packages/kbn-plugin-helpers/src/integration_tests/build.test.ts +++ b/packages/kbn-plugin-helpers/src/integration_tests/build.test.ts @@ -81,6 +81,7 @@ it('builds a generated plugin into a viable archive', async () => { info running @kbn/optimizer │ succ browser bundle created at plugins/foo_test_plugin/build/kibana/fooTestPlugin/target/public │ info stopping @kbn/optimizer + info compressing js and css bundles found at plugins/foo_test_plugin/build/kibana/fooTestPlugin/target/public to brotli info copying assets from \`public/assets\` to build info copying server source into the build and converting with babel info running yarn to install dependencies diff --git a/packages/kbn-plugin-helpers/src/tasks/brotli_compress_bundles.ts b/packages/kbn-plugin-helpers/src/tasks/brotli_compress_bundles.ts new file mode 100644 index 0000000000000..f04d707b279e9 --- /dev/null +++ b/packages/kbn-plugin-helpers/src/tasks/brotli_compress_bundles.ts @@ -0,0 +1,44 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import Path from 'path'; +import { pipeline } from 'stream'; +import { promisify } from 'util'; + +import vfs from 'vinyl-fs'; +import del from 'del'; +import gulpBrotli from 'gulp-brotli'; +import zlib from 'zlib'; +import { REPO_ROOT } from '@kbn/repo-info'; + +import { TaskContext } from '../task_context'; + +const asyncPipeline = promisify(pipeline); + +export async function brotliCompressBundles({ buildDir, log }: TaskContext) { + const compressDir = Path.resolve(buildDir, 'target/public'); + + log.info( + `compressing js and css bundles found at ${Path.relative(REPO_ROOT, compressDir)} to brotli` + ); + + try { + await del(['**/*.br'], { cwd: compressDir }); + await asyncPipeline( + vfs.src(['**/*.{js,css}'], { cwd: compressDir }), + gulpBrotli({ + params: { + [zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY, + }, + }), + vfs.dest(compressDir) + ); + } catch (e) { + log.error(e); + } +} diff --git a/packages/kbn-plugin-helpers/src/tasks/create_archive.ts b/packages/kbn-plugin-helpers/src/tasks/create_archive.ts index 5f2339d2a4ce1..999bb559c6dbe 100644 --- a/packages/kbn-plugin-helpers/src/tasks/create_archive.ts +++ b/packages/kbn-plugin-helpers/src/tasks/create_archive.ts @@ -7,17 +7,13 @@ */ import Path from 'path'; -import { pipeline } from 'stream'; -import { promisify } from 'util'; +import Fs from 'fs'; +import archiver from 'archiver'; import del from 'del'; -import vfs from 'vinyl-fs'; -import zip from 'gulp-zip'; import { TaskContext } from '../task_context'; -const asyncPipeline = promisify(pipeline); - export async function createArchive({ kibanaVersion, plugin, log }: TaskContext) { const { manifest: { id }, @@ -30,15 +26,14 @@ export async function createArchive({ kibanaVersion, plugin, log }: TaskContext) const buildDir = Path.resolve(directory, 'build'); // zip up the build files - await asyncPipeline( - vfs.src([`kibana/${id}/**/*`], { - cwd: buildDir, - base: buildDir, - dot: true, - }), - zip(zipName), - vfs.dest(buildDir) - ); + const output = Fs.createWriteStream(Path.resolve(buildDir, zipName)); + const archive = archiver('zip', { zlib: { level: 9 } }); + archive.pipe(output); + + const directoryToAdd = Path.resolve(buildDir, 'kibana'); + const directoryNameOnZip = Path.basename(directoryToAdd); + + await archive.directory(directoryToAdd, directoryNameOnZip).finalize(); // delete the files that were zipped await del(Path.resolve(buildDir, 'kibana')); diff --git a/packages/kbn-plugin-helpers/src/tasks/index.ts b/packages/kbn-plugin-helpers/src/tasks/index.ts index ab23a501ca14c..cc788a4ccfa35 100644 --- a/packages/kbn-plugin-helpers/src/tasks/index.ts +++ b/packages/kbn-plugin-helpers/src/tasks/index.ts @@ -7,6 +7,7 @@ */ export * from './bazel_packages'; +export * from './brotli_compress_bundles'; export * from './clean'; export * from './create_archive'; export * from './optimize'; diff --git a/yarn.lock b/yarn.lock index e90a40d3ad2b0..33fa2571e664d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8553,13 +8553,6 @@ dependencies: "@types/color-convert" "*" -"@types/compression-webpack-plugin@^2.0.2": - version "2.0.2" - resolved "https://registry.yarnpkg.com/@types/compression-webpack-plugin/-/compression-webpack-plugin-2.0.2.tgz#9d8956a542ea974e018ab5dc2316480edbaf17fb" - integrity sha512-4GW0o21FHqRwP/HYC8o7ceiO9duBopo1v5MaTVZy8VqF6nnRRDoG/C6djGxAmC7uyXRBK8AdnB2IVQgkoRokXQ== - dependencies: - "@types/webpack" "*" - "@types/connect-history-api-fallback@^1.3.5": version "1.3.5" resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.3.5.tgz#d1f7a8a09d0ed5a57aee5ae9c18ab9b803205dae" @@ -8818,13 +8811,6 @@ dependencies: "@types/node" "*" -"@types/gulp-zip@^4.0.1": - version "4.0.1" - resolved "https://registry.yarnpkg.com/@types/gulp-zip/-/gulp-zip-4.0.1.tgz#96cd0b994219f9ae3bbbec7ec3baa043fba9d9ef" - integrity sha512-dYwGsHmwv4pnMD+jtyuIdZchJ0CIivnl8PIApHC+rYN7FMj01tJSAiQb+YN4T/pOn10pmmucBLEB9wXEhQX2Ug== - dependencies: - "@types/node" "*" - "@types/gulp@^4.0.6": version "4.0.6" resolved "https://registry.yarnpkg.com/@types/gulp/-/gulp-4.0.6.tgz#68fe0e1f0ff3657cfca46fb564806b744a1bf899" @@ -12153,7 +12139,7 @@ cacache@^12.0.2: unique-filename "^1.1.1" y18n "^4.0.0" -cacache@^15.0.3, cacache@^15.0.4, cacache@^15.0.5, cacache@^15.2.0: +cacache@^15.0.4, cacache@^15.0.5, cacache@^15.2.0: version "15.3.0" resolved "https://registry.yarnpkg.com/cacache/-/cacache-15.3.0.tgz#dc85380fb2f556fe3dda4c719bfa0ec875a7f1eb" integrity sha512-VVdYzXEn+cnbXpFgWs5hTT7OScegHVmLhJIR8Ufqk3iFD6A6j5iSX1KuBTfNEv4tdJWE2PzA6IVFtcLC7fN9wQ== @@ -13047,17 +13033,6 @@ compressible@~2.0.16: dependencies: mime-db ">= 1.40.0 < 2" -compression-webpack-plugin@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-4.0.0.tgz#7599f592050002a49cd3ad3ee18ae7371e266bca" - integrity sha512-DRoFQNTkQ8gadlk117Y2wxANU+MDY56b1FIZj/yJXucBOTViTHXjthM7G9ocnitksk4kLzt1N2RLF0gDjxI+hg== - dependencies: - cacache "^15.0.3" - find-cache-dir "^3.3.1" - schema-utils "^2.6.6" - serialize-javascript "^3.0.0" - webpack-sources "^1.4.3" - compression@^1.7.4: version "1.7.4" resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f" @@ -17690,17 +17665,6 @@ gulp-terser@^2.1.0: through2 "^4.0.2" vinyl-sourcemaps-apply "^0.2.1" -gulp-zip@^5.0.2: - version "5.0.2" - resolved "https://registry.yarnpkg.com/gulp-zip/-/gulp-zip-5.0.2.tgz#2edf797ec842e770f4dfde8bef97d139015b1972" - integrity sha512-rZd0Ppuc8Bf7J2/WzcdNaeb+lcEXf1R8mV/PJ9Kdu7PmnInWVeLSmiXIka/2QSe6uhAsGVFAMffWSaMzAPGTBg== - dependencies: - get-stream "^5.1.0" - plugin-error "^1.0.1" - through2 "^3.0.1" - vinyl "^2.1.0" - yazl "^2.5.1" - gzip-size@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-6.0.0.tgz#065367fd50c239c0671cbcbad5be3e2eeb10e462" @@ -26593,7 +26557,7 @@ scheduler@^0.20.2: loose-envify "^1.1.0" object-assign "^4.1.1" -schema-utils@2.7.0, schema-utils@^2.0.0, schema-utils@^2.0.1, schema-utils@^2.5.0, schema-utils@^2.6.5, schema-utils@^2.6.6, schema-utils@^2.7.0: +schema-utils@2.7.0, schema-utils@^2.0.0, schema-utils@^2.0.1, schema-utils@^2.5.0, schema-utils@^2.6.5, schema-utils@^2.7.0: version "2.7.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.0.tgz#17151f76d8eae67fbbf77960c33c676ad9f4efc7" integrity sha512-0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A== @@ -26750,7 +26714,7 @@ serialize-javascript@6.0.0, serialize-javascript@^6.0.0: dependencies: randombytes "^2.1.0" -serialize-javascript@^3.0.0, serialize-javascript@^3.1.0: +serialize-javascript@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-3.1.0.tgz#8bf3a9170712664ef2561b44b691eafe399214ea" integrity sha512-JIJT1DGiWmIKhzRsG91aS6Ze4sFUrYbltlkg2onR5OrnNM02Kl/hnY/T4FN2omvyeBbQmMJv+K4cPOpGzOTFBg== @@ -30111,7 +30075,7 @@ vinyl-sourcemaps-apply@^0.2.1: dependencies: source-map "^0.5.1" -vinyl@^2.1.0, vinyl@^2.2.0: +vinyl@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-2.2.0.tgz#d85b07da96e458d25b2ffe19fece9f2caa13ed86" integrity sha512-MBH+yP0kC/GQ5GwBqrTPTzEfiiLjta7hTtvQtbxBgTeSXsmKQRQecjibMbxIXzVT3Y9KJK+drOz1/k+vsu8Nkg==