Fix path to locales file in component-server
Bug: none
Change-Id: I7e47b1d8dc3ccafad980bcbae09d3083472a50a3
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3110432
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
diff --git a/scripts/component_server/server.js b/scripts/component_server/server.js
index 706f7b2..90aeeb5 100644
--- a/scripts/component_server/server.js
+++ b/scripts/component_server/server.js
@@ -292,10 +292,21 @@
} else {
// This means it's an asset like a JS file or an image.
let fullPath = path.join(componentDocsBaseFolder, filePath);
- if (fullPath.endsWith(path.join('locales', 'en-US.json'))) {
+ if (fullPath.endsWith(path.join('locales', 'en-US.json')) &&
+ !componentDocsBaseFolder.includes(sharedResourcesBase)) {
+ /**
+ * If the path is for locales/en-US.json we special case the loading of that to fix the path so it works properly in the server.
+ * We also make sure that we take into account the shared resources base;
+ * but if the base folder already contains the shared resources base, we don't
+ * add it to the path, because otherwise that would cause the shared resources
+ * base to be duplicated in the fullPath.
+ */
// Rewrite this path so we can load up the locale in the component-docs
- fullPath =
- path.join(componentDocsBaseFolder, sharedResourcesBase, 'front_end', 'core', 'i18n', 'locales', 'en-US.json');
+ let prefix = componentDocsBaseFolder;
+ if (sharedResourcesBase && !componentDocsBaseFolder.includes(sharedResourcesBase)) {
+ prefix = path.join(componentDocsBaseFolder, sharedResourcesBase);
+ }
+ fullPath = path.join(prefix, 'front_end', 'core', 'i18n', 'locales', 'en-US.json');
}
if (!fullPath.startsWith(devtoolsRootFolder) && !fileIsInTestFolder) {