@zohodesk/client_build_tool 0.0.10 → 0.0.11-exp.7

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.
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ const fs = require('fs');
4
+
5
+ const path = require('path');
6
+
7
+ const parser = require('@babel/parser');
8
+
9
+ const traverse = require('@babel/traverse').default;
10
+
11
+ const generator = require('@babel/generator').default;
12
+
13
+ const t = require('@babel/types');
14
+
15
+ const {
16
+ getOptions
17
+ } = require('loader-utils');
18
+
19
+ module.exports = function i18nIdReplaceLoader(source, map) {
20
+ const resourcePath = this.resourcePath;
21
+ this.cacheable && this.cacheable();
22
+ const options = getOptions(this) || {};
23
+ const callback = this.async();
24
+
25
+ if (options.excludePaths) {
26
+ const shouldExclude = options.excludePaths.some(excludePath => resourcePath.includes(excludePath));
27
+
28
+ if (shouldExclude) {
29
+ return callback(null, source, map);
30
+ }
31
+ }
32
+
33
+ if (options.includePaths && options.includePaths.length > 0) {
34
+ const shouldInclude = options.includePaths.some(includePath => resourcePath.includes(includePath));
35
+
36
+ if (!shouldInclude) {
37
+ return callback(null, source, map);
38
+ }
39
+ }
40
+
41
+ if (!options.allI18nData || Object.keys(options.allI18nData).length === 0) {
42
+ return callback(new Error(`i18nIdReplaceLoader: 'allI18nData' option is missing or empty`));
43
+ }
44
+
45
+ let numericIdMap = null;
46
+
47
+ if (options.numericMapPath) {
48
+ try {
49
+ if (fs.existsSync(options.numericMapPath)) {
50
+ const fileContent = fs.readFileSync(options.numericMapPath, 'utf-8');
51
+ const parsedData = JSON.parse(fileContent);
52
+
53
+ if (parsedData && parsedData.originalKeyToNumericId) {
54
+ numericIdMap = parsedData.originalKeyToNumericId;
55
+ }
56
+ }
57
+ } catch (err) {// ignore - optional file
58
+ }
59
+ }
60
+
61
+ if (!numericIdMap) {
62
+ return callback(null, source, map);
63
+ }
64
+
65
+ try {
66
+ const ast = parser.parse(source, {
67
+ sourceType: 'module',
68
+ plugins: ['jsx', 'typescript', 'classProperties', 'optionalChaining', 'nullishCoalescingOperator'],
69
+ sourceFilename: resourcePath
70
+ });
71
+ let hasTransformations = false;
72
+ traverse(ast, {
73
+ StringLiteral(path) {
74
+ const {
75
+ node
76
+ } = path;
77
+
78
+ if (!options.allI18nData.hasOwnProperty(node.value)) {
79
+ return;
80
+ }
81
+
82
+ if (numericIdMap.hasOwnProperty(node.value)) {
83
+ const numericId = String(numericIdMap[node.value]);
84
+ path.replaceWith(t.stringLiteral(numericId));
85
+ hasTransformations = true;
86
+ }
87
+ }
88
+
89
+ });
90
+
91
+ if (hasTransformations) {
92
+ const output = generator(ast, {
93
+ sourceMaps: !!options.sourceMaps,
94
+ sourceFileName: resourcePath,
95
+ retainLines: false,
96
+ comments: true
97
+ }, source);
98
+ callback(null, output.code, output.map);
99
+ } else {
100
+ callback(null, source, map);
101
+ }
102
+ } catch (err) {
103
+ callback(err);
104
+ }
105
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.configI18nNumericIndexPlugin = configI18nNumericIndexPlugin;
7
+
8
+ var _I18nNumericIndexPlugin = require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin");
9
+
10
+ var _I18nNumericIndexHtmlInjectorPlugin = require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin");
11
+
12
+ var _readI18nValues = require("../custom_plugins/I18nSplitPlugin/readI18nValues");
13
+
14
+ function configI18nNumericIndexPlugin(options) {
15
+ if (!(options.i18nIndexing && options.i18nIndexing.enable)) {
16
+ return null;
17
+ }
18
+
19
+ const i18nOpts = options.i18nIndexing;
20
+ const cdnConfig = options.cdnMapping || {};
21
+ const requiredOptions = ['jsResourcePath', 'propertiesFolderPath', 'numericMapPath', 'jsonpFunc', 'htmlTemplateLabel', 'localeVarName', 'numericFilenameTemplate', 'dynamicFilenameTemplate'];
22
+ const missingOptions = requiredOptions.filter(opt => !i18nOpts[opt]);
23
+
24
+ if (missingOptions.length > 0) {
25
+ return null;
26
+ }
27
+
28
+ const {
29
+ locales,
30
+ allI18nObject
31
+ } = (0, _readI18nValues.readI18nValues)({
32
+ jsResource: i18nOpts.jsResourcePath,
33
+ propertiesFolder: i18nOpts.propertiesFolderPath,
34
+ disableDefault: false
35
+ });
36
+
37
+ if (!i18nOpts.numericFilenameTemplate.includes('[locale]')) {
38
+ return null;
39
+ }
40
+
41
+ if (!i18nOpts.dynamicFilenameTemplate.includes('[locale]')) {
42
+ return null;
43
+ } // Empty prefix - HtmlWebpackPlugin handles publicPath
44
+
45
+
46
+ const i18nAssetsPublicPathPrefix = '';
47
+ const numericIndexPluginOptions = {
48
+ enable: i18nOpts.enable,
49
+ jsResourcePath: i18nOpts.jsResourcePath,
50
+ propertiesFolderPath: i18nOpts.propertiesFolderPath,
51
+ numericMapPath: i18nOpts.numericMapPath,
52
+ locales,
53
+ allI18nObject,
54
+ numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
55
+ dynamicFilenameTemplate: i18nOpts.dynamicFilenameTemplate,
56
+ jsonpFunc: i18nOpts.jsonpFunc,
57
+ singleFile: i18nOpts.singleFile || false,
58
+ includeContentHash: i18nOpts.includeContentHash || false,
59
+ generateManifest: i18nOpts.generateManifest || false
60
+ };
61
+ const htmlInjectorOptions = {
62
+ numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
63
+ dynamicFilenameTemplate: i18nOpts.dynamicFilenameTemplate,
64
+ htmlTemplateLabel: i18nOpts.htmlTemplateLabel,
65
+ i18nAssetsPublicPathPrefix
66
+ };
67
+ const i18nNumericPluginInstance = new _I18nNumericIndexPlugin.I18nNumericIndexPlugin(numericIndexPluginOptions);
68
+ const htmlInjectorPluginInstance = new _I18nNumericIndexHtmlInjectorPlugin.I18nNumericIndexHtmlInjectorPlugin(htmlInjectorOptions);
69
+ return [i18nNumericPluginInstance, htmlInjectorPluginInstance];
70
+ }
@@ -49,10 +49,12 @@ var _configRuntimeResourceCleanup = require("./pluginConfigs/configRuntimeResour
49
49
 
50
50
  var _configCustomScriptLoadingStrategyPlugin = require("./pluginConfigs/configCustomScriptLoadingStrategyPlugin");
51
51
 
52
+ var _configI18nNumericIndexPlugin = require("./pluginConfigs/configI18nNumericIndexPlugin");
53
+
52
54
  // import { IgnorePlugin } from 'webpack';
53
55
  function plugins(options) {
54
56
  const {
55
57
  webpackPlugins
56
58
  } = options;
57
- return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), (0, _configCustomScriptLoadingStrategyPlugin.configCustomScriptLoadingStrategyPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), ...webpackPlugins].filter(Boolean);
59
+ return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), ...((0, _configI18nNumericIndexPlugin.configI18nNumericIndexPlugin)(options) || []), (0, _configCustomScriptLoadingStrategyPlugin.configCustomScriptLoadingStrategyPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), ...webpackPlugins].filter(Boolean);
58
60
  }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Shared properties file parsing utility
5
+ * Handles consistent parsing across all i18n tools
6
+ */
7
+ // Decode Unicode escape sequences (for values only)
8
+ function decodeUnicodeEscapes(str) {
9
+ if (typeof str !== 'string') {
10
+ return str;
11
+ }
12
+
13
+ return str.replace(/\\u([0-9a-fA-F]{4})/g, (match, hex) => {
14
+ return String.fromCharCode(parseInt(hex, 16));
15
+ });
16
+ }
17
+ /**
18
+ * Parse properties file content into key-value pairs
19
+ * @param {string} content - Properties file content
20
+ * @returns {Object} Parsed key-value pairs
21
+ */
22
+
23
+
24
+ function parseProperties(content) {
25
+ const lines = content.split(/\r?\n/);
26
+ const data = {};
27
+ lines.forEach(line => {
28
+ const trimmedLine = line.trim();
29
+
30
+ if (trimmedLine.startsWith('#') || trimmedLine.startsWith('!') || trimmedLine === '') {
31
+ return;
32
+ } // Find unescaped separator (= or :)
33
+
34
+
35
+ let separatorIndex = -1;
36
+
37
+ for (let i = 0; i < trimmedLine.length; i++) {
38
+ if ((trimmedLine[i] === '=' || trimmedLine[i] === ':') && (i === 0 || trimmedLine[i - 1] !== '\\')) {
39
+ separatorIndex = i;
40
+ break;
41
+ }
42
+ }
43
+
44
+ if (separatorIndex > 0) {
45
+ let key = trimmedLine.substring(0, separatorIndex).trim();
46
+ let value = trimmedLine.substring(separatorIndex + 1).trim();
47
+
48
+ if (key) {
49
+ // Handle escaped spaces in keys only
50
+ key = key.replace(/\\ /g, ' '); // Decode Unicode escape sequences ONLY in values, not keys
51
+
52
+ value = decodeUnicodeEscapes(value);
53
+ data[key] = value;
54
+ }
55
+ }
56
+ });
57
+ return data;
58
+ }
59
+ /**
60
+ * Parse properties file content into a Set of keys only
61
+ * @param {string} content - Properties file content
62
+ * @returns {Set<string>} Set of keys
63
+ */
64
+
65
+
66
+ function parsePropertiesToKeySet(content) {
67
+ const lines = content.split(/\r?\n/);
68
+ const keys = new Set();
69
+ lines.forEach(line => {
70
+ const trimmedLine = line.trim();
71
+
72
+ if (trimmedLine.startsWith('#') || trimmedLine.startsWith('!') || trimmedLine === '') {
73
+ return;
74
+ } // Find unescaped separator (= or :)
75
+
76
+
77
+ let separatorIndex = -1;
78
+
79
+ for (let i = 0; i < trimmedLine.length; i++) {
80
+ if ((trimmedLine[i] === '=' || trimmedLine[i] === ':') && (i === 0 || trimmedLine[i - 1] !== '\\')) {
81
+ separatorIndex = i;
82
+ break;
83
+ }
84
+ }
85
+
86
+ if (separatorIndex > 0) {
87
+ let key = trimmedLine.substring(0, separatorIndex).trim();
88
+
89
+ if (key) {
90
+ // Handle escaped spaces in keys only
91
+ key = key.replace(/\\ /g, ' ');
92
+ keys.add(key);
93
+ }
94
+ }
95
+ });
96
+ return keys;
97
+ }
98
+
99
+ module.exports = {
100
+ parseProperties,
101
+ parsePropertiesToKeySet,
102
+ decodeUnicodeEscapes
103
+ };
@@ -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
  // }
@@ -20,7 +20,7 @@ function urlConcat(url, path) {
20
20
  return path;
21
21
  }
22
22
 
23
- return `${slashRemovedUrl}/${slashRemovedPath}`;
23
+ return `${slashRemovedUrl}/${slashRemovedPath}/`;
24
24
  }
25
25
 
26
26
  function removeLastSlash(url) {