Skip to content

Commit 11ab19f

Browse files
committed
[INTERNAL] Log warning + prevent duplicate messages
1 parent bf8c34e commit 11ab19f

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

lib/processors/manifestEnhancer.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ class ManifestEnhancer {
170170

171171
this.isModified = false;
172172
this.runInvoked = false;
173+
174+
this.supportedLocalesCache = new Map();
173175
}
174176

175177
markModified() {
@@ -189,7 +191,14 @@ class ManifestEnhancer {
189191
}
190192
}
191193

192-
async findSupportedLocales(i18nBundleUrl) {
194+
findSupportedLocales(i18nBundleUrl) {
195+
if (!this.supportedLocalesCache.has(i18nBundleUrl)) {
196+
this.supportedLocalesCache.set(i18nBundleUrl, this._findSupportedLocales(i18nBundleUrl));
197+
}
198+
return this.supportedLocalesCache.get(i18nBundleUrl);
199+
}
200+
201+
async _findSupportedLocales(i18nBundleUrl) {
193202
const i18nBundleName = path.basename(i18nBundleUrl, ".properties");
194203
const i18nBundlePrefix = `${i18nBundleName}_`;
195204
const i18nBundleDir = path.dirname(i18nBundleUrl);
@@ -207,7 +216,7 @@ class ManifestEnhancer {
207216
if (isValidPropertiesFilenameLocale(locale)) {
208217
supportedLocales.push(locale);
209218
} else {
210-
log.verbose(`Skipping invalid locale '${locale}' for bundle '${i18nBundleUrl}'`);
219+
log.warn(`Skipping invalid file '${fileName}' for bundle '${i18nBundleUrl}'`);
211220
}
212221
}
213222
});

test/lib/processors/manifestEnhancer.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,8 @@ test("manifestEnhancer#getSupportedLocales", async (t) => {
30513051
"../../../../../../../../../../../../resources/sap/ui/demo/app/i18n/i18n.properties"
30523052
), expectedLocales);
30533053

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

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

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

3104-
t.is(t.context.logVerboseSpy.callCount, 5);
3105-
t.is(t.context.logVerboseSpy.getCall(0).args[0],
3106-
"Skipping invalid locale 'en-US' for bundle 'i18n/i18n.properties'");
3107-
t.is(t.context.logVerboseSpy.getCall(1).args[0],
3108-
"Skipping invalid locale 'zh_CN_' for bundle 'i18n/i18n.properties'");
3109-
t.is(t.context.logVerboseSpy.getCall(2).args[0],
3110-
"Skipping invalid locale 'sr_Latn_RS_variant_f_11' for bundle 'i18n/i18n.properties'");
3111-
t.is(t.context.logVerboseSpy.getCall(3).args[0],
3112-
"Skipping invalid locale 'sr_Latn_RS_variant_x_private' for bundle 'i18n/i18n.properties'");
3113-
t.is(t.context.logVerboseSpy.getCall(4).args[0],
3114-
"Skipping invalid locale 'sr_Latn_RS_variant_f_11_x_private' for bundle 'i18n/i18n.properties'");
3115-
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
3105+
t.is(t.context.logWarnSpy.callCount, 5);
3106+
t.is(t.context.logWarnSpy.getCall(0).args[0],
3107+
"Skipping invalid file 'i18n_en-US.properties' for bundle 'i18n/i18n.properties'");
3108+
t.is(t.context.logWarnSpy.getCall(1).args[0],
3109+
"Skipping invalid file 'i18n_zh_CN_.properties' for bundle 'i18n/i18n.properties'");
3110+
t.is(t.context.logWarnSpy.getCall(2).args[0],
3111+
"Skipping invalid file 'i18n_sr_Latn_RS_variant_f_11.properties' for bundle 'i18n/i18n.properties'");
3112+
t.is(t.context.logWarnSpy.getCall(3).args[0],
3113+
"Skipping invalid file 'i18n_sr_Latn_RS_variant_x_private.properties' for bundle 'i18n/i18n.properties'");
3114+
t.is(t.context.logWarnSpy.getCall(4).args[0],
3115+
"Skipping invalid file 'i18n_sr_Latn_RS_variant_f_11_x_private.properties' for bundle 'i18n/i18n.properties'");
3116+
t.true(t.context.logVerboseSpy.notCalled, "No verbose messages should be logged");
31163117
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
31173118
});
31183119

0 commit comments

Comments
 (0)