@zohodesk/client_build_tool 0.0.10-exp.5 → 0.0.11-exp.6
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.
- package/README.md +148 -0
- package/README_backup.md +148 -0
- package/lib/schemas/defaultConfigValues.js +16 -1
- package/lib/schemas/defaultConfigValuesOnly.js +16 -1
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +49 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +161 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin_simplified.js +129 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/i18nDataLoader.js +134 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +113 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectAstKeys.js +96 -0
- package/lib/shared/bundler/webpack/jsLoaders.js +20 -2
- package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +74 -0
- package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +105 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +70 -0
- package/lib/shared/bundler/webpack/plugins.js +3 -1
- package/lib/shared/bundler/webpack/utils/i18n/collectAstKeys.js +96 -0
- package/lib/shared/bundler/webpack/utils/propertiesParser.js +103 -0
- package/lib/shared/postcss/custom_postcss_plugins/VariableModificationPlugin/index.js +1 -1
- package/lib/shared/server/urlConcat.js +1 -1
- package/package.json +1 -1
|
@@ -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,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
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -259,7 +259,7 @@ var _default = ({
|
|
|
259
259
|
if (range) {
|
|
260
260
|
// console.log('multiple :', decl.value)
|
|
261
261
|
let newVal = '';
|
|
262
|
-
decl.value.split(' ').
|
|
262
|
+
decl.value.split(' ').forEach(singleVal => {
|
|
263
263
|
newVal += `${singleConvertor(singleVal, settings.replacements.px, {
|
|
264
264
|
decl,
|
|
265
265
|
filename,
|