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

misc: exit collect-strings script with error code on failure #12971

Merged
merged 4 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
7 changes: 5 additions & 2 deletions build/build-treemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function buildStrings() {
const locales = require('../lighthouse-core/lib/i18n/locales.js');
// TODO(esmodules): use dynamic import when build/ is esm.
const utilCode = fs.readFileSync(LH_ROOT + '/lighthouse-treemap/app/src/util.js', 'utf-8');
const {UIStrings} = eval(utilCode.replace('export ', '') + '\nmodule.exports = TreemapUtil;');
const {UIStrings} = eval(utilCode.replace(/export /g, '') + '\nmodule.exports = TreemapUtil;');
Copy link
Collaborator

Choose a reason for hiding this comment

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

heh, I guess this technically works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a different solution you had in mind?

const strings = /** @type {Record<LH.Locale, string>} */ ({});

for (const [locale, lhlMessages] of Object.entries(locales)) {
Expand Down Expand Up @@ -76,4 +76,7 @@ async function run() {
}
}

run();
run().catch(err => {
console.error(err);
process.exit(1);
});
5 changes: 4 additions & 1 deletion lighthouse-core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,10 @@ async function main() {

// Test if called from the CLI or as a module.
if (require.main === module) {
main();
main().catch(err => {
console.error(err.stack);
process.exit(1);
});
}

module.exports = {
Expand Down
38 changes: 20 additions & 18 deletions lighthouse-treemap/app/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@
/** @template {string} T @typedef {import('typed-query-selector/parser').ParseSelector<T, Element>} ParseSelector */
/** @template T @typedef {import('../../../report/renderer/i18n').I18n<T>} I18n */

export const UIStrings = {
/** Label for a button that alternates between showing or hiding a table. */
toggleTableButtonLabel: 'Toggle Table',
/** Text for an option in a dropdown menu. When selected, the app shows information for all scripts that were found in a web page. */
allScriptsDropdownLabel: 'All Scripts',
/** Label for a table column where the values are URLs, JS module names, or arbitrary identifiers. For simplicity, just 'name' is used. */
tableColumnName: 'Name',
/** Label for column giving the size of a file in bytes. */
resourceBytesLabel: 'Resource Bytes',
/** Label for a value associated with how many bytes of a script are not executed. */
unusedBytesLabel: 'Unused Bytes',
/** Label for a column where the values represent how much of a file is used bytes vs unused bytes (coverage). */
coverageColumnName: 'Coverage',
/** Label for a button that shows everything (or rather, does not highlight any specific mode such as: unused bytes, duplicate bytes, etc). */
allLabel: 'All',
/** Label for a button that highlights information about duplicate modules (aka: files, javascript resources that were included twice by a web page). */
duplicateModulesLabel: 'Duplicate Modules',
};

export class TreemapUtil {
/** @type {I18n<typeof TreemapUtil['UIStrings']>} */
// @ts-expect-error: Is set in main.
static i18n = null;

static UIStrings = {
/** Label for a button that alternates between showing or hiding a table. */
toggleTableButtonLabel: 'Toggle Table',
/** Text for an option in a dropdown menu. When selected, the app shows information for all scripts that were found in a web page. */
allScriptsDropdownLabel: 'All Scripts',
/** Label for a table column where the values are URLs, JS module names, or arbitrary identifiers. For simplicity, just 'name' is used. */
tableColumnName: 'Name',
/** Label for column giving the size of a file in bytes. */
resourceBytesLabel: 'Resource Bytes',
/** Label for a value associated with how many bytes of a script are not executed. */
unusedBytesLabel: 'Unused Bytes',
/** Label for a column where the values represent how much of a file is used bytes vs unused bytes (coverage). */
coverageColumnName: 'Coverage',
/** Label for a button that shows everything (or rather, does not highlight any specific mode such as: unused bytes, duplicate bytes, etc). */
allLabel: 'All',
/** Label for a button that highlights information about duplicate modules (aka: files, javascript resources that were included twice by a web page). */
duplicateModulesLabel: 'Duplicate Modules',
};
static UIStrings = UIStrings;

/**
* @param {LH.Treemap.Node} node
Expand Down