Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clients(psi): expose the swapLocale types #14062

Merged
merged 7 commits into from
Jun 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions build/build-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`]: `
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ridiculous but I can't think of a better way to do accomplish this. Better to be ridiculous than to overengineer it :)

For readability, would this string be better in a variable than inline? Alternatively should we make a build/shims/ directory and rollupPlugins.alias() i18n-module.js to point there? I'm assuming that would work but it may not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a shims/i18nmodule.js sg. then it's at least lintable

Copy link
Member Author

@paulirish paulirish May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried a shim file and it's terrible. ends up creating more cruft. so.. leaving as is.

(extracted to a var actually)

/**
* 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: []
};
};

paulirish marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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<string, {message: string}>} lhlMessages
*/
function registerLocaleData(locale, lhlMessages) {
LOCALE_MESSAGES[locale] = lhlMessages;
paulirish marked this conversation as resolved.
Show resolved Hide resolved
}
export const format = {registerLocaleData};
`,
}),
],
});
Expand Down