@zohodesk/client_build_tool 0.0.1-0.exp.0.0.8 → 0.0.1-0.exp.1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/CHANGELOG.md +0 -10
  2. package/README.md +0 -10
  3. package/lib/schemas/defaultConfigValues.js +14 -63
  4. package/lib/schemas/defaultConfigValuesOnly.js +6 -10
  5. package/lib/shared/babel/getBabelPlugin.js +4 -9
  6. package/lib/shared/babel/runBabelForTsFile.js +1 -1
  7. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +14 -12
  8. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +90 -426
  9. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin_simplified.js +129 -0
  10. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/i18nDataLoader.js +134 -0
  11. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +113 -0
  12. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nFilesEmitPlugin.js +5 -66
  13. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +0 -3
  14. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectAstKeys.js +4 -6
  15. package/lib/shared/bundler/webpack/custom_plugins/getInitialI18nAssetsArrayStr.js +1 -6
  16. package/lib/shared/bundler/webpack/jsLoaders.js +12 -7
  17. package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +37 -88
  18. package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +67 -191
  19. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +27 -99
  20. package/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +1 -4
  21. package/lib/shared/bundler/webpack/plugins.js +3 -20
  22. package/lib/shared/bundler/webpack/utils/i18n/collectAstKeys.js +96 -0
  23. package/lib/shared/bundler/webpack/utils/propertiesParser.js +1 -1
  24. package/lib/shared/server/mockApiHandler.js +0 -7
  25. package/npm-shrinkwrap.json +32 -8225
  26. package/package.json +5 -6
  27. package/lib/shared/bundler/webpack/common/hashUtils.js +0 -20
  28. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/CLAUDE.md +0 -0
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ const {
4
+ walk
5
+ } = require('estree-walker');
6
+
7
+ const PREFIX_I18N_COMMENT = 'I18N';
8
+ const PREFIX_I18N_COMMENT_DYNAMIC = 'dynamic-i18n-key';
9
+
10
+ function getI18nKeysFromSingleComment(commentNode, validKeysSet) {
11
+ const foundKeysInComment = [];
12
+
13
+ if (!commentNode || typeof commentNode.value !== 'string') {
14
+ return foundKeysInComment;
15
+ }
16
+
17
+ const commentString = commentNode.value.trim();
18
+ let i18nKeyStr;
19
+
20
+ if (commentString.startsWith(PREFIX_I18N_COMMENT)) {
21
+ i18nKeyStr = commentString.slice(PREFIX_I18N_COMMENT.length).trim();
22
+ } else if (commentString.startsWith(PREFIX_I18N_COMMENT_DYNAMIC)) {
23
+ i18nKeyStr = commentString.slice(PREFIX_I18N_COMMENT_DYNAMIC.length).trim();
24
+ }
25
+
26
+ if (!i18nKeyStr) {
27
+ return foundKeysInComment;
28
+ }
29
+
30
+ const potentialKeys = i18nKeyStr.split(',').map(key => key.trim()).filter(key => key);
31
+ potentialKeys.forEach(key => {
32
+ if (validKeysSet.has(key)) {
33
+ foundKeysInComment.push(key);
34
+ }
35
+ });
36
+ return foundKeysInComment;
37
+ }
38
+ /**
39
+ * Traverses an AST and its comments to collect and categorize i18n keys.
40
+ *
41
+ * @param {object} astProgramNode - The Program node of the AST.
42
+ * @param {object[]} commentsArray - An array of comment nodes from the AST.
43
+ * @param {object} allI18nKeysMasterMap - Object map of all valid i18n keys (from JSResources).
44
+ * @param {boolean} [isDebug=false] - Flag for verbose logging.
45
+ * @returns {{literalKeys: Set<string>, commentKeys: Set<string>}}
46
+ * literalKeys: Set of valid i18n keys found as string literals.
47
+ * commentKeys: Set of valid i18n keys found in comments.
48
+ */
49
+
50
+
51
+ function collectAndCategorizeUsedI18nKeys(astProgramNode, commentsArray, allI18nKeysMasterMap, isDebug = false) {
52
+ const foundLiteralKeys = new Set();
53
+ const foundCommentKeys = new Set();
54
+ const validKeysSet = new Set(Object.keys(allI18nKeysMasterMap || {}));
55
+
56
+ if (validKeysSet.size === 0 && isDebug) {
57
+ console.warn('[collectAndCategorizeUsedI18nKeys] allI18nKeysMasterMap is empty. No keys can be collected.');
58
+ } // 1. Collect keys from AST string literals
59
+
60
+
61
+ if (astProgramNode) {
62
+ try {
63
+ walk(astProgramNode, {
64
+ enter(node) {
65
+ if ((node.type === 'Literal' || node.type === 'StringLiteral') && typeof node.value === 'string') {
66
+ if (validKeysSet.has(node.value)) {
67
+ foundLiteralKeys.add(node.value);
68
+ }
69
+ }
70
+ }
71
+
72
+ });
73
+ } catch (error) {
74
+ console.error('[collectAndCategorizeUsedI18nKeys] Error during AST walk:', error);
75
+ }
76
+ } // 2. Collect keys from comments
77
+
78
+
79
+ if (commentsArray && Array.isArray(commentsArray)) {
80
+ commentsArray.forEach(commentNode => {
81
+ const keysFromComment = getI18nKeysFromSingleComment(commentNode, validKeysSet);
82
+ keysFromComment.forEach(key => {
83
+ foundCommentKeys.add(key);
84
+ });
85
+ });
86
+ }
87
+
88
+ return {
89
+ literalKeys: foundLiteralKeys,
90
+ commentKeys: foundCommentKeys
91
+ };
92
+ }
93
+
94
+ module.exports = {
95
+ collectAndCategorizeUsedI18nKeys: collectAndCategorizeUsedI18nKeys
96
+ };
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
+
2
3
  /**
3
4
  * Shared properties file parsing utility
4
5
  * Handles consistent parsing across all i18n tools
5
6
  */
6
7
  // Decode Unicode escape sequences (for values only)
7
-
8
8
  function decodeUnicodeEscapes(str) {
9
9
  if (typeof str !== 'string') {
10
10
  return str;
@@ -44,13 +44,6 @@ function handleMockApi(mockEntryFile, app) {
44
44
  const entryFilePath = (0, _constants.joinWithAppPath)(mockEntryFile); // eslint-disable-next-line no-use-before-define
45
45
 
46
46
  const mockFunc = safeRequire(entryFilePath);
47
-
48
- if (typeof mockFunc === 'function') {
49
- // eslint-disable-next-line no-use-before-define
50
- mockFunc(app);
51
- return;
52
- }
53
-
54
47
  mockFunc?.mockApi?.(app);
55
48
  } // function handleMockApi(params) {
56
49
  // }