From b21e4d9b9335573bcb3b699bb9e999ae0fa01191 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Fri, 27 May 2022 13:35:26 -0700 Subject: [PATCH 1/4] clients(psi): expose the swapLocale types --- build/build-report.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/build/build-report.js b/build/build-report.js index 2b16c5173de0..0eae4ef1b8e4 100644 --- a/build/build-report.js +++ b/build/build-report.js @@ -96,8 +96,32 @@ async function buildEsModulesBundle() { rollupPlugins.commonjs(), // Exclude this 30kb from the devtools bundle for now. rollupPlugins.shim({ - [`${LH_ROOT}/shared/localization/i18n-module.js`]: - 'export const swapLocale = _ => {}; export const format = _ => {};', + [`${LH_ROOT}/shared/localization/i18n-module.js`]: ` +/** + * Returns a new LHR with all strings changed to the new requestedLocale. + * @param {LH.Result} lhr + * @param {LH.Locale} requestedLocale + * @return {{lhr: LH.Result, missingIcuMessageIds: string[]}} + */ +export function swapLocale(lhr, requestedLocale) { + return { + lhr, + missingIcuMessageIds: [] + }; +}; + +/** + * Populate the i18n string lookup dict with locale data + * Used when the host environment selects the locale and serves lighthouse the intended locale file + * @see https://docs.google.com/document/d/1jnt3BqKB-4q3AE94UWFA0Gqspx8Sd_jivlB7gQMlmfk/edit + * @param {LH.Locale} locale + * @param {Record} lhlMessages + */ +function registerLocaleData(locale, lhlMessages) { + LOCALE_MESSAGES[locale] = lhlMessages; +} +export const format = {registerLocaleData}; + `, }), ], }); From 71fbefb783f821480ef7aaaafecef3b3e8b2df4c Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Fri, 27 May 2022 15:15:35 -0700 Subject: [PATCH 2/4] drop locale_messages --- build/build-report.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/build-report.js b/build/build-report.js index 0eae4ef1b8e4..5c4d6fb2f1c6 100644 --- a/build/build-report.js +++ b/build/build-report.js @@ -106,9 +106,9 @@ async function buildEsModulesBundle() { export function swapLocale(lhr, requestedLocale) { return { lhr, - missingIcuMessageIds: [] + missingIcuMessageIds: [], }; -}; +} /** * Populate the i18n string lookup dict with locale data @@ -118,7 +118,7 @@ export function swapLocale(lhr, requestedLocale) { * @param {Record} lhlMessages */ function registerLocaleData(locale, lhlMessages) { - LOCALE_MESSAGES[locale] = lhlMessages; + // ... } export const format = {registerLocaleData}; `, From 579ed92e4ba34315f8f6a7241b9e17ae077dbe1a Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Fri, 27 May 2022 15:17:49 -0700 Subject: [PATCH 3/4] connor feedback --- build/build-report.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/build-report.js b/build/build-report.js index 5c4d6fb2f1c6..73004edee8a2 100644 --- a/build/build-report.js +++ b/build/build-report.js @@ -95,6 +95,7 @@ async function buildEsModulesBundle() { plugins: [ rollupPlugins.commonjs(), // Exclude this 30kb from the devtools bundle for now. + // But include the type detail for bundle.esm.d.ts generation rollupPlugins.shim({ [`${LH_ROOT}/shared/localization/i18n-module.js`]: ` /** @@ -104,6 +105,7 @@ async function buildEsModulesBundle() { * @return {{lhr: LH.Result, missingIcuMessageIds: string[]}} */ export function swapLocale(lhr, requestedLocale) { + // Stub function only included for types return { lhr, missingIcuMessageIds: [], @@ -118,7 +120,7 @@ export function swapLocale(lhr, requestedLocale) { * @param {Record} lhlMessages */ function registerLocaleData(locale, lhlMessages) { - // ... + // Stub function only included for types } export const format = {registerLocaleData}; `, From a84674cb89f7ac2f14e1ddfecebf90dae9aeddc3 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Fri, 27 May 2022 15:25:49 -0700 Subject: [PATCH 4/4] extract to var. good call --- build/build-report.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/build/build-report.js b/build/build-report.js index 73004edee8a2..5f172b83b3c8 100644 --- a/build/build-report.js +++ b/build/build-report.js @@ -90,14 +90,8 @@ async function buildFlowReport() { } async function buildEsModulesBundle() { - const bundle = await rollup({ - input: 'report/clients/bundle.js', - plugins: [ - rollupPlugins.commonjs(), - // Exclude this 30kb from the devtools bundle for now. - // But include the type detail for bundle.esm.d.ts generation - rollupPlugins.shim({ - [`${LH_ROOT}/shared/localization/i18n-module.js`]: ` + // Include the type detail for bundle.esm.d.ts generation + const i18nModuleShim = ` /** * Returns a new LHR with all strings changed to the new requestedLocale. * @param {LH.Result} lhr @@ -123,7 +117,15 @@ function registerLocaleData(locale, lhlMessages) { // Stub function only included for types } export const format = {registerLocaleData}; - `, +`; + + const bundle = await rollup({ + input: 'report/clients/bundle.js', + plugins: [ + rollupPlugins.commonjs(), + // Exclude this 30kb from the devtools bundle for now. + rollupPlugins.shim({ + [`${LH_ROOT}/shared/localization/i18n-module.js`]: i18nModuleShim, }), ], });