-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(i18n): support descriptions #5718
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is totally rad. I like it.
const content = fs.readFileSync(fullPath, 'utf8'); | ||
if (!UISTRINGS_REGEX.test(content)) continue; | ||
const exportVars = require(fullPath); | ||
if (!exportVars.UIStrings) throw new Error('UIStrings not exported'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UIStrings defined but not exported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
|
||
// @ts-ignore regex just matched | ||
const justUIStrings = content.match(UISTRINGS_REGEX)[0]; | ||
// just parse the UIStrings substring to avoid ES version issues, save time, etc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 i like this approach.
@@ -10,8 +10,17 @@ | |||
|
|||
const fs = require('fs'); | |||
const path = require('path'); | |||
// @ts-ignore - TODO: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/25410 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like that landed?
DefinitelyTyped/DefinitelyTyped#25410
32ca3e5
to
9931884
Compare
@brendankenny you gellin'? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
general approach looks good!
failureTitle: 'Shown to users as the title of the audit when it is in a failing state.', | ||
}; | ||
|
||
// @ts-ignore - waiting for esprima types, see above TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more ts-ignore? or annoying to type even with types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the comment, @types/esprima doesn't actually come with typedefs for any of this
@@ -23,16 +23,13 @@ | |||
"build-viewer": "cd ./lighthouse-viewer && yarn build", | |||
"clean": "rimraf *.report.html *.report.dom.html *.report.json *.screenshots.html *.screenshots.json *.devtoolslog.json *.trace.json || true", | |||
"lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .", | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert these or do we just want to give up on them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally for giving up, but I can revert if we're still trying to keep the dream alive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -119,7 +115,7 @@ | |||
"chrome-launcher": "^0.10.2", | |||
"configstore": "^3.1.1", | |||
"devtools-timeline-model": "1.1.6", | |||
"esprima": "^4.0.0", | |||
"esprima": "^4.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to fix on a specific version since it's a (possibly) finicky extraction task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh 🤷♀️ we've got yarn.lock for the script and the other usage isn't that sensitive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've got yarn.lock for the script
ha, well I feel like that's a reason to just drop the ^
since we don't honor it anyways, but
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree :)
This approach makes sure our usage is locked in for our script but when others install lighthouse we accept any version of esprima 4 when it doesn't matter as much in the audit
// @ts-ignore regex just matched | ||
const justUIStrings = 'const ' + content.match(UISTRINGS_REGEX)[0]; | ||
// just parse the UIStrings substring to avoid ES version issues, save time, etc | ||
// @ts-ignore - esprima's type definition is supremely lacking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it's pretty terrible as I recall
const content = fs.readFileSync(fullPath, 'utf8'); | ||
if (!UISTRINGS_REGEX.test(content)) continue; | ||
const exportVars = require(fullPath); | ||
if (!exportVars.UIStrings) throw new Error('UIStrings defined but not exported'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably also do the opposite test too, UIStrings
exported but failing the regex just in case one of them ends up weird in one file or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
*/ | ||
function writeStringsToLocaleFormat(locale, strings) { | ||
const fullPath = path.join(LH_ROOT, `lighthouse-core/lib/locales/${locale}.json`); | ||
const output = {}; | ||
for (const [key, message] of Object.entries(strings)) { | ||
output[key] = {message}; | ||
for (const [key, object] of Object.entries(strings)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: above defn
is used...might be better than object
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
// @ts-ignore - waiting for esprima types, see above TODO | ||
function computeDescription(ast, property, startRange) { | ||
const endRange = property.range[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to prepend [ICU Syntax]
here if it is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulirish was against that since it only applies to ones that have the template and there are only ~5, I was persuaded as well :)
const UISTRINGS_REGEX = /UIStrings = (.|\s)*?\};\n/gim; | ||
|
||
/** | ||
* @typedef ICUMessage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ICUMessage.message
is a little unfortunate (e.g. destructuring like const [key, msg] of Object.entries(strings)
below would be weird because then you'd need to say msg.message
) , but I don't have anything better. ICUMessageDefn
:) Not sure if there are any other terms of art
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*Defn
it is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -119,7 +115,7 @@ | |||
"chrome-launcher": "^0.10.2", | |||
"configstore": "^3.1.1", | |||
"devtools-timeline-model": "1.1.6", | |||
"esprima": "^4.0.0", | |||
"esprima": "^4.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've got yarn.lock for the script
ha, well I feel like that's a reason to just drop the ^
since we don't honor it anyways, but
@@ -23,16 +23,13 @@ | |||
"build-viewer": "cd ./lighthouse-viewer && yarn build", | |||
"clean": "rimraf *.report.html *.report.dom.html *.report.json *.screenshots.html *.screenshots.json *.devtoolslog.json *.trace.json || true", | |||
"lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .", | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -3,7 +3,8 @@ | |||
"message": "JavaScript boot-up time" | |||
}, | |||
"lighthouse-core/audits/bootup-time.js | failureTitle": { | |||
"message": "JavaScript boot-up time is too high" | |||
"message": "JavaScript boot-up time is too high", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file might need to be regenerated now
Adds support for string descriptions and defaulting all failureTitles to one for example
Related Issues/PRs
blocked on #5716