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

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented May 27, 2022

We're in a funny situation, so here's the backstory...

  1. we want the swapLocale functionality in PSI
  2. our PSI integration story uses the bundle.umd.js + a .d.ts declaration file
    • we use report/bundle.esm in devtools and report/bundle.umd in PSI. because reasons.
  3. the declaration file is created via node ./node_modules/.bin/tsc --allowJs --declaration --emitDeclarationOnly ./dist/report/bundle.esm.js <== the ESM version!
    • yes we generate types from the build that we don't use. we can't gen types from the umd one anyway
  4. the esm and umd report builds are slightly different and that hasn't mattered much until recently. i shimmed swaplocale/format with {} for devtools to save 30kb.
  5. however for the correct type generation we need those to look reasonable
  6. thus, this silly PR

A more reasonable solution is generating a ~lighthousereportrenderer.types.d.ts file the "right" way. tsc can generate quality .d.ts files - but its 1:1 against source files.

There are a few projects that can consume all of those and generate a single file. 1) dts-gen by microsoft is at the module level and doesnt really make sense for this usecase. (probably). 2) dts-generator isn't maintained and dun work. 3) dts-bundle is also dead. 4) dts-bundle-generator seems like the best one, but unfortunately it explicitly doesnt support composite projects. To me, situation is enough justification to justify our sed BS plus this unattractive solution. Ah well, I expect this situation will improve with the arch refactor + dts-bundle-generator adding support.

also there's https://api-extractor.com/pages/setup/invoking/ which does this.
an alternative is to only compile with TSC and do declaration emitting. and don't bundle into 1 file, but.. that may not be an option for this reportrenderer case.

@paulirish paulirish requested a review from a team as a code owner May 27, 2022 20:58
@paulirish paulirish requested review from adamraine and removed request for a team May 27, 2022 20:58
@@ -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)

build/build-report.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants