From 211fe93394e39f694ad804df2e3003a8b3effddc Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 16 Aug 2021 20:05:58 -0500 Subject: [PATCH] misc(build): do not include locales in devtools bundle (#12921) --- build/build-bundle.js | 25 ++++++++++++++++++------- build/build-lightrider-bundles.js | 2 +- build/build-viewer.js | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/build/build-bundle.js b/build/build-bundle.js index c2937508128e..5156133c8818 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -13,6 +13,7 @@ const fs = require('fs'); const path = require('path'); const assert = require('assert').strict; +const stream = require('stream'); const mkdir = fs.promises.mkdir; const LighthouseRunner = require('../lighthouse-core/runner.js'); const exorcist = require('exorcist'); @@ -66,7 +67,23 @@ async function browserifyFile(entryPath, distPath) { }) // Transform the fs.readFile etc into inline strings. .transform('@wardpeet/brfs', { - readFileSyncTransform: minifyFileTransform, + /** @param {string} file */ + readFileTransform: (file) => { + // Don't include locales in DevTools. + if (isDevtools(entryPath) && locales.includes(file)) { + return new stream.Transform({ + transform(chunk, enc, next) { + next(); + }, + final(next) { + this.push('{}'); + next(); + }, + }); + } + + return minifyFileTransform(file); + }, global: true, parserOpts: {ecmaVersion: 12}, }) @@ -90,12 +107,6 @@ async function browserifyFile(entryPath, distPath) { bundle.ignore(require.resolve('../report/report-assets.js')); } - // Don't include locales in DevTools. - if (isDevtools(entryPath)) { - // @ts-expect-error bundle.ignore does accept an array of strings. - bundle.ignore(locales); - } - // Expose the audits, gatherers, and computed artifacts so they can be dynamically loaded. // Exposed path must be a relative path from lighthouse-core/config/config-helpers.js (where loading occurs). const corePath = './lighthouse-core/'; diff --git a/build/build-lightrider-bundles.js b/build/build-lightrider-bundles.js index 27970be7150d..6a570d3978e4 100644 --- a/build/build-lightrider-bundles.js +++ b/build/build-lightrider-bundles.js @@ -40,7 +40,7 @@ function buildReportGenerator() { browserify(generatorFilename, {standalone: 'ReportGenerator'}) // Transform the fs.readFile etc into inline strings. .transform('@wardpeet/brfs', { - readFileSyncTransform: minifyFileTransform, + readFileTransform: minifyFileTransform, global: true, parserOpts: {ecmaVersion: 12}, }) diff --git a/build/build-viewer.js b/build/build-viewer.js index 32afb9f24241..2794a458e699 100644 --- a/build/build-viewer.js +++ b/build/build-viewer.js @@ -20,7 +20,7 @@ async function run() { const generatorFilename = `${LH_ROOT}/report/report-generator.js`; const generatorBrowserify = browserify(generatorFilename, {standalone: 'ReportGenerator'}) .transform('@wardpeet/brfs', { - readFileSyncTransform: minifyFileTransform, + readFileTransform: minifyFileTransform, }); /** @type {Promise} */