From 1abedb61ba4e5e37e313274b34a2e0a4204bb26d Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Tue, 7 Jun 2022 15:12:41 -0700 Subject: [PATCH] clients(psi): expose the swapLocale types (#14062) --- build/build-report.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/build/build-report.js b/build/build-report.js index 426619233d5f..e68af047230b 100644 --- a/build/build-report.js +++ b/build/build-report.js @@ -92,14 +92,42 @@ async function buildFlowReport() { } async function buildEsModulesBundle() { + // 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 + * @param {LH.Locale} requestedLocale + * @return {{lhr: LH.Result, missingIcuMessageIds: string[]}} + */ +export function swapLocale(lhr, requestedLocale) { + // Stub function only included for types + 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) { + // Stub function only included for types +} +export const format = {registerLocaleData}; +`; + const bundle = await rollup.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`]: - 'export const swapLocale = _ => {}; export const format = _ => {};', + [`${LH_ROOT}/shared/localization/i18n-module.js`]: i18nModuleShim, }), ], });