Skip to content

Commit

Permalink
[INTERNAL] Log warning + prevent duplicate messages
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Sep 11, 2024
1 parent fd64eaa commit eb9d5d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
13 changes: 11 additions & 2 deletions lib/processors/manifestEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class ManifestEnhancer {

this.isModified = false;
this.runInvoked = false;

this.supportedLocalesCache = new Map();
}

markModified() {
Expand All @@ -189,7 +191,14 @@ class ManifestEnhancer {
}
}

async findSupportedLocales(i18nBundleUrl) {
findSupportedLocales(i18nBundleUrl) {
if (!this.supportedLocalesCache.has(i18nBundleUrl)) {
this.supportedLocalesCache.set(i18nBundleUrl, this._findSupportedLocales(i18nBundleUrl));
}
return this.supportedLocalesCache.get(i18nBundleUrl);
}

async _findSupportedLocales(i18nBundleUrl) {
const i18nBundleName = path.basename(i18nBundleUrl, ".properties");
const i18nBundlePrefix = `${i18nBundleName}_`;
const i18nBundleDir = path.dirname(i18nBundleUrl);
Expand All @@ -207,7 +216,7 @@ class ManifestEnhancer {
if (isValidPropertiesFilenameLocale(locale)) {
supportedLocales.push(locale);
} else {
log.verbose(`Skipping invalid locale '${locale}' for bundle '${i18nBundleUrl}'`);
log.warn(`Skipping invalid file '${fileName}' for bundle '${i18nBundleUrl}'`);
}
}
});
Expand Down
27 changes: 14 additions & 13 deletions test/lib/processors/manifestEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3051,7 +3051,8 @@ test("manifestEnhancer#getSupportedLocales", async (t) => {
"../../../../../../../../../../../../resources/sap/ui/demo/app/i18n/i18n.properties"
), expectedLocales);

t.is(fs.readdir.callCount, 4);
// findSupportedLocales caches requests, so for the same bundle readdir is only called once
t.is(fs.readdir.callCount, 1);

t.true(t.context.logVerboseSpy.notCalled, "No verbose messages should be logged");
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
Expand Down Expand Up @@ -3101,18 +3102,18 @@ test("manifestEnhancer#getSupportedLocales (invalid locales)", async (t) => {

t.is(fs.readdir.callCount, 1);

t.is(t.context.logVerboseSpy.callCount, 5);
t.is(t.context.logVerboseSpy.getCall(0).args[0],
"Skipping invalid locale 'en-US' for bundle 'i18n/i18n.properties'");
t.is(t.context.logVerboseSpy.getCall(1).args[0],
"Skipping invalid locale 'zh_CN_' for bundle 'i18n/i18n.properties'");
t.is(t.context.logVerboseSpy.getCall(2).args[0],
"Skipping invalid locale 'sr_Latn_RS_variant_f_11' for bundle 'i18n/i18n.properties'");
t.is(t.context.logVerboseSpy.getCall(3).args[0],
"Skipping invalid locale 'sr_Latn_RS_variant_x_private' for bundle 'i18n/i18n.properties'");
t.is(t.context.logVerboseSpy.getCall(4).args[0],
"Skipping invalid locale 'sr_Latn_RS_variant_f_11_x_private' for bundle 'i18n/i18n.properties'");
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
t.is(t.context.logWarnSpy.callCount, 5);
t.is(t.context.logWarnSpy.getCall(0).args[0],
"Skipping invalid file 'i18n_en-US.properties' for bundle 'i18n/i18n.properties'");
t.is(t.context.logWarnSpy.getCall(1).args[0],
"Skipping invalid file 'i18n_zh_CN_.properties' for bundle 'i18n/i18n.properties'");
t.is(t.context.logWarnSpy.getCall(2).args[0],
"Skipping invalid file 'i18n_sr_Latn_RS_variant_f_11.properties' for bundle 'i18n/i18n.properties'");
t.is(t.context.logWarnSpy.getCall(3).args[0],
"Skipping invalid file 'i18n_sr_Latn_RS_variant_x_private.properties' for bundle 'i18n/i18n.properties'");
t.is(t.context.logWarnSpy.getCall(4).args[0],
"Skipping invalid file 'i18n_sr_Latn_RS_variant_f_11_x_private.properties' for bundle 'i18n/i18n.properties'");
t.true(t.context.logVerboseSpy.notCalled, "No verbose messages should be logged");
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
});

Expand Down

0 comments on commit eb9d5d2

Please sign in to comment.