npm package diff
Package: @forge/manifest
Versions: 7.7.0-next.8-experimental-c7a7d36 - 7.7.0-next.11
File: package/out/utils/i18n/module-i18n-helper.js
Index: package/out/utils/i18n/module-i18n-helper.js
===================================================================
--- package/out/utils/i18n/module-i18n-helper.js
+++ package/out/utils/i18n/module-i18n-helper.js
@@ -0,0 +1,96 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.extractInternalI18nPropertyKeysFromModules = exports.extractI18nKeysFromModules = exports.extractI18nPropertiesFromModules = void 0;
+const isObject = (value) => {
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
+};
+const isI18nValue = (value) => {
+ return typeof value?.i18n === 'string';
+};
+const getI18nKeysFromObject = (obj) => {
+ const visited = new Set();
+ const visit = (value, i18nPath) => {
+ if (!isObject(value) || visited.has(value)) {
+ return [];
+ }
+ visited.add(value);
+ return Object.entries(value).flatMap(([propKey, propValue]) => {
+ const currentPath = [...i18nPath, propKey];
+ if (isI18nValue(propValue)) {
+ return [{ propertyPath: currentPath, key: propValue.i18n }];
+ }
+ else if (Array.isArray(propValue)) {
+ return propValue.flatMap((item) => visit(item, currentPath));
+ }
+ return visit(propValue, currentPath);
+ });
+ };
+ return visit(obj, []);
+};
+const INTERNAL_I18N_PROPERTY_KEY_SUFFIX = '__i18n';
+const isInternalI18nPropertyKey = (key) => {
+ return key.length > INTERNAL_I18N_PROPERTY_KEY_SUFFIX.length && key.endsWith(INTERNAL_I18N_PROPERTY_KEY_SUFFIX);
+};
+const isI18nProperty = (key, value) => {
+ return isInternalI18nPropertyKey(key) && typeof value === 'string';
+};
+const getInternalI18nPropertyKeysFromObject = (obj) => {
+ const visited = new Set();
+ const visit = (value) => {
+ if (!isObject(value) || visited.has(value)) {
+ return [];
+ }
+ visited.add(value);
+ return Object.entries(value).flatMap(([propKey, propValue]) => {
+ if (isI18nProperty(propKey, propValue)) {
+ return [propKey];
+ }
+ else if (Array.isArray(propValue)) {
+ return propValue.flatMap((item) => visit(item));
+ }
+ return visit(propValue);
+ });
+ };
+ return visit(obj);
+};
+const getAllModuleEntries = (modules) => {
+ return Object.entries(modules).flatMap(([moduleKey, moduleEntries]) => {
+ if (moduleEntries && Array.isArray(moduleEntries) && moduleEntries.length > 0) {
+ return moduleEntries.map((moduleEntry) => [moduleEntry, moduleKey]);
+ }
+ return [];
+ });
+};
+const extractI18nPropertiesFromModules = (modules) => {
+ const moduleI18nProperties = [];
+ for (const moduleEntry of getAllModuleEntries(modules)) {
+ const i18nKeysForEntryValue = getI18nKeysFromObject(moduleEntry[0]);
+ for (const i18nObj of i18nKeysForEntryValue) {
+ moduleI18nProperties.push({ moduleName: moduleEntry[1], ...i18nObj });
+ }
+ }
+ return moduleI18nProperties;
+};
+exports.extractI18nPropertiesFromModules = extractI18nPropertiesFromModules;
+const extractI18nKeysFromModules = (modules) => {
+ const i18nKeys = new Set();
+ for (const moduleEntry of getAllModuleEntries(modules)) {
+ const i18nKeysForEntryValue = getI18nKeysFromObject(moduleEntry[0]);
+ for (const { key } of i18nKeysForEntryValue) {
+ i18nKeys.add(key);
+ }
+ }
+ return i18nKeys.size > 0 ? Array.from(i18nKeys) : [];
+};
+exports.extractI18nKeysFromModules = extractI18nKeysFromModules;
+const extractInternalI18nPropertyKeysFromModules = (modules) => {
+ const i18nKeys = new Set();
+ for (const [moduleEntryObject, moduleKey] of getAllModuleEntries(modules)) {
+ const i18nKeysForEntryValue = getInternalI18nPropertyKeysFromObject(moduleEntryObject);
+ for (const key of i18nKeysForEntryValue) {
+ i18nKeys.add(`${key},${moduleKey}`);
+ }
+ }
+ return i18nKeys.size > 0 ? Array.from(i18nKeys).map((key) => key.split(',')) : [];
+};
+exports.extractInternalI18nPropertyKeysFromModules = extractInternalI18nPropertyKeysFromModules;