@zohodesk/client_build_tool 0.0.11-exp.9 → 0.0.12-exp.1

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 (26) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +132 -0
  3. package/README_backup.md +102 -0
  4. package/lib/schemas/defaultConfigValues.js +8 -18
  5. package/lib/schemas/defaultConfigValuesOnly.js +4 -19
  6. package/lib/shared/babel/getBabelPlugin.js +3 -4
  7. package/lib/shared/babel/runBabelForTsFile.js +1 -1
  8. package/lib/shared/bundler/webpack/common/decidePublicPath.js +2 -2
  9. package/lib/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/index.js +10 -0
  10. package/lib/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +14 -2
  11. package/lib/shared/bundler/webpack/jsLoaders.js +2 -20
  12. package/lib/shared/bundler/webpack/pluginConfigs/configCopyPublicFolders.js +3 -2
  13. package/lib/shared/bundler/webpack/plugins.js +1 -3
  14. package/lib/shared/postcss/custom_postcss_plugins/VariableModificationPlugin/index.js +1 -1
  15. package/lib/shared/server/mockApiHandler.js +7 -0
  16. package/lib/shared/server/urlConcat.js +13 -1
  17. package/npm-shrinkwrap.json +354 -38
  18. package/package.json +6 -5
  19. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +0 -49
  20. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +0 -174
  21. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +0 -108
  22. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectAstKeys.js +0 -96
  23. package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +0 -74
  24. package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +0 -105
  25. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +0 -79
  26. package/lib/shared/bundler/webpack/utils/propertiesParser.js +0 -103
@@ -1,49 +0,0 @@
1
- "use strict";
2
-
3
- const HtmlWebpackPlugin = require('html-webpack-plugin');
4
-
5
- const pluginName = 'I18nNumericIndexHtmlInjectorPlugin';
6
-
7
- class I18nNumericIndexHtmlInjectorPlugin {
8
- constructor(options) {
9
- this.options = options;
10
- }
11
-
12
- apply(compiler) {
13
- compiler.hooks.thisCompilation.tap(pluginName, compilation => {
14
- HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync(pluginName, (hookData, cb) => {
15
- const {
16
- assets
17
- } = hookData;
18
- const {
19
- numericFilenameTemplate,
20
- dynamicFilenameTemplate,
21
- htmlTemplateLabel,
22
- i18nAssetsPublicPathPrefix = ''
23
- } = this.options;
24
- const newI18nAssetUrlsToAdd = [];
25
-
26
- if (numericFilenameTemplate) {
27
- const numericFilename = numericFilenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel);
28
- newI18nAssetUrlsToAdd.push(numericFilename);
29
- }
30
-
31
- if (dynamicFilenameTemplate) {
32
- const dynamicFilename = dynamicFilenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel);
33
- newI18nAssetUrlsToAdd.push(dynamicFilename);
34
- }
35
-
36
- if (newI18nAssetUrlsToAdd.length > 0) {
37
- assets.js = [...assets.js, ...newI18nAssetUrlsToAdd];
38
- }
39
-
40
- cb(null, hookData);
41
- });
42
- });
43
- }
44
-
45
- }
46
-
47
- module.exports = {
48
- I18nNumericIndexHtmlInjectorPlugin
49
- };
@@ -1,174 +0,0 @@
1
- "use strict";
2
-
3
- const path = require('path');
4
-
5
- const {
6
- sources,
7
- Compilation,
8
- util
9
- } = require('webpack');
10
-
11
- const {
12
- decodeUnicodeEscapes
13
- } = require('../../utils/propertiesParser');
14
-
15
- const {
16
- loadNumericMap,
17
- loadI18nData
18
- } = require('./utils/i18nDataLoader');
19
-
20
- const {
21
- RawSource
22
- } = sources;
23
- const pluginName = 'I18nNumericIndexPlugin';
24
-
25
- class I18nNumericIndexPlugin {
26
- constructor(options = {}) {
27
- this.options = { ...options,
28
- singleFile: options.singleFile || false,
29
- singleFileTemplate: options.singleFileTemplate,
30
- includeContentHash: options.includeContentHash || false,
31
- generateManifest: options.generateManifest || false
32
- };
33
- this.numericMap = null;
34
- this.i18nData = null;
35
- this.manifest = {};
36
- }
37
-
38
- getNumericMap(compilation) {
39
- if (!this.numericMap) {
40
- const mapPath = path.resolve(compilation.compiler.context, this.options.numericMapPath);
41
- this.numericMap = loadNumericMap(mapPath, compilation);
42
- }
43
-
44
- return this.numericMap;
45
- }
46
-
47
- getI18nData(compilation) {
48
- if (!this.i18nData) {
49
- this.i18nData = loadI18nData(this.options, compilation);
50
- }
51
-
52
- return this.i18nData;
53
- }
54
-
55
- generateContentHash(content, compilation) {
56
- const {
57
- hashFunction,
58
- hashDigest,
59
- hashDigestLength
60
- } = compilation.outputOptions;
61
- const hash = util.createHash(hashFunction || 'xxhash64');
62
- hash.update(content);
63
- return hash.digest(hashDigest || 'hex').substring(0, hashDigestLength || 20);
64
- }
65
-
66
- emitChunk(compilation, filename, locale, data, fileType = null) {
67
- const content = decodeUnicodeEscapes(JSON.stringify(data));
68
- const fileContent = `${this.options.jsonpFunc}(${content});`;
69
- let outputPath = filename.replace(/\[locale\]/g, locale); // Check if template contains [contenthash] placeholder or use legacy includeContentHash flag
70
-
71
- const hasContentHashPlaceholder = filename.includes('[contenthash]');
72
- const shouldIncludeHash = hasContentHashPlaceholder || this.options.includeContentHash;
73
-
74
- if (shouldIncludeHash) {
75
- const contentHash = this.generateContentHash(fileContent, compilation);
76
-
77
- if (hasContentHashPlaceholder) {
78
- // Replace [contenthash] placeholder with actual hash
79
- outputPath = outputPath.replace(/\[contenthash\]/g, contentHash);
80
- } else {
81
- // Legacy behavior: append hash before .js extension
82
- outputPath = outputPath.replace(/\.js$/, `.${contentHash}.js`);
83
- }
84
- }
85
-
86
- if (this.options.generateManifest) {
87
- const cleanName = filename.replace(/\[locale\]/g, locale).replace(/\.js$/, '.js');
88
- const cleanNameWithType = fileType ? cleanName.replace(/\.js$/, `.${fileType}.js`) : cleanName;
89
- const manifestKey = cleanNameWithType.split('/').pop(); // Extract just the filename for the key
90
-
91
- this.manifest[manifestKey] = outputPath.split('/').pop();
92
- }
93
-
94
- compilation.emitAsset(outputPath, new RawSource(fileContent));
95
- return outputPath;
96
- }
97
-
98
- apply(compiler) {
99
- compiler.hooks.thisCompilation.tap(pluginName, compilation => {
100
- compilation.hooks.processAssets.tapAsync({
101
- name: pluginName,
102
- stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
103
- }, (assets, callback) => {
104
- if (!this.options.enable) {
105
- return callback();
106
- }
107
-
108
- const {
109
- sortedKeys,
110
- totalKeys
111
- } = this.getNumericMap(compilation);
112
- const {
113
- jsResourceBase,
114
- allI18n,
115
- locales
116
- } = this.getI18nData(compilation);
117
- if (!locales.length) return callback();
118
- const numericKeysSet = new Set(sortedKeys);
119
- const englishData = allI18n.en_US || jsResourceBase;
120
- locales.forEach(locale => {
121
- const localeData = allI18n[locale] || {};
122
- const numericData = {};
123
-
124
- for (let i = 0; i < totalKeys; i++) {
125
- const key = sortedKeys[i];
126
-
127
- if (key && jsResourceBase[key] !== undefined) {
128
- numericData[i] = localeData[key] ?? englishData[key];
129
- }
130
- }
131
-
132
- const dynamicData = {};
133
- Object.keys(jsResourceBase).forEach(key => {
134
- if (!numericKeysSet.has(key)) {
135
- dynamicData[key] = localeData[key] ?? englishData[key];
136
- }
137
- });
138
-
139
- if (this.options.singleFile) {
140
- const combinedData = { ...numericData,
141
- ...dynamicData
142
- };
143
-
144
- if (Object.keys(combinedData).length > 0) {
145
- const filename = this.options.singleFileTemplate || this.options.numericFilenameTemplate || this.options.dynamicFilenameTemplate;
146
- this.emitChunk(compilation, filename, locale, combinedData);
147
- }
148
- } else {
149
- if (Object.keys(numericData).length > 0) {
150
- this.emitChunk(compilation, this.options.numericFilenameTemplate, locale, numericData, 'numeric');
151
- }
152
-
153
- if (Object.keys(dynamicData).length > 0) {
154
- this.emitChunk(compilation, this.options.dynamicFilenameTemplate, locale, dynamicData, 'dynamic');
155
- }
156
- }
157
- });
158
-
159
- if (this.options.generateManifest && Object.keys(this.manifest).length > 0) {
160
- const manifestPath = path.dirname(this.options.numericFilenameTemplate) + '/manifest.json';
161
- const manifestContent = JSON.stringify(this.manifest, null, 2);
162
- compilation.emitAsset(manifestPath, new RawSource(manifestContent));
163
- }
164
-
165
- callback();
166
- });
167
- });
168
- }
169
-
170
- }
171
-
172
- module.exports = {
173
- I18nNumericIndexPlugin
174
- };
@@ -1,108 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require('fs');
4
-
5
- const path = require('path');
6
-
7
- const {
8
- parseProperties
9
- } = require('../../../utils/propertiesParser');
10
-
11
- function loadPropertiesFile(filePath, compilation, description) {
12
- try {
13
- const content = fs.readFileSync(filePath, 'utf-8');
14
- const parsed = parseProperties(content);
15
- return parsed;
16
- } catch (err) {
17
- if (compilation) {
18
- compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading ${description}: ${err.message}`));
19
- }
20
-
21
- return {};
22
- }
23
- }
24
-
25
- function loadNumericMap(numericMapPath, compilation) {
26
- try {
27
- const fileContent = fs.readFileSync(numericMapPath, 'utf-8');
28
- const parsedData = JSON.parse(fileContent);
29
- const sortedKeys = new Array(parsedData.totalKeysInMap);
30
- Object.entries(parsedData.originalKeyToNumericId).forEach(([key, id]) => {
31
- sortedKeys[id] = key;
32
- });
33
- return {
34
- sortedKeys,
35
- totalKeys: parsedData.totalKeysInMap
36
- };
37
- } catch (err) {
38
- if (compilation) {
39
- compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading numeric map: ${err.message}`));
40
- }
41
-
42
- return {
43
- sortedKeys: [],
44
- totalKeys: 0
45
- };
46
- }
47
- }
48
-
49
- function loadAllLocaleFiles(propertiesPath, baseFileName, compilation, jsResourceBase) {
50
- const allI18n = {};
51
- const locales = []; // Always use the jsResourceBase as en_US base
52
-
53
- allI18n['en_US'] = jsResourceBase;
54
- locales.push('en_US');
55
-
56
- try {
57
- const files = fs.readdirSync(propertiesPath);
58
- files.forEach(file => {
59
- if (!file.endsWith('.properties')) return;
60
- const match = file.match(/^ApplicationResources_([a-z]{2}_[A-Z]{2})\.properties$/);
61
-
62
- if (match) {
63
- const locale = match[1];
64
- const filePath = path.join(propertiesPath, file);
65
- const localeData = loadPropertiesFile(filePath, compilation, `locale ${locale}`);
66
- allI18n[locale] = { ...jsResourceBase,
67
- ...localeData
68
- };
69
-
70
- if (!locales.includes(locale)) {
71
- locales.push(locale);
72
- }
73
- }
74
- });
75
- } catch (err) {
76
- if (compilation) {
77
- compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error reading properties folder: ${err.message}`));
78
- }
79
- }
80
-
81
- return {
82
- allI18n,
83
- locales
84
- };
85
- }
86
-
87
- function loadI18nData(options, compilation) {
88
- const jsResourcePath = path.resolve(compilation.compiler.context, options.jsResourcePath);
89
- const propertiesPath = path.resolve(compilation.compiler.context, options.propertiesFolderPath);
90
- const baseFileName = path.basename(options.jsResourcePath, '.properties');
91
- const jsResourceBase = loadPropertiesFile(jsResourcePath, compilation, 'JS resources');
92
- const {
93
- allI18n,
94
- locales
95
- } = loadAllLocaleFiles(propertiesPath, baseFileName, compilation, jsResourceBase);
96
- return {
97
- jsResourceBase,
98
- allI18n,
99
- locales
100
- };
101
- }
102
-
103
- module.exports = {
104
- loadPropertiesFile,
105
- loadNumericMap,
106
- loadAllLocaleFiles,
107
- loadI18nData
108
- };
@@ -1,96 +0,0 @@
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,74 +0,0 @@
1
- "use strict";
2
-
3
- const path = require('path');
4
-
5
- const fs = require('fs');
6
-
7
- const {
8
- getPropertiesAsJSON
9
- } = require('../custom_plugins/I18nSplitPlugin/utils/propertiesUtils');
10
-
11
- function loadJSResourcesOnce(options) {
12
- let jsResourcePath;
13
-
14
- if (options.i18nIndexing && options.i18nIndexing.enable) {
15
- jsResourcePath = options.i18nIndexing.jsResourcePath;
16
- } else if (options.i18nChunkSplit && options.i18nChunkSplit.chunkSplitEnable && options.i18nChunkSplit.useNumericIndexing) {
17
- jsResourcePath = options.i18nChunkSplit.jsResource;
18
- } else {
19
- throw new Error('i18nIdReplaceLoader requires either i18nIndexing to be enabled or i18nChunkSplit with useNumericIndexing');
20
- }
21
-
22
- if (!jsResourcePath) {
23
- throw new Error('Missing required jsResourcePath in i18n options');
24
- }
25
-
26
- try {
27
- const i18nData = getPropertiesAsJSON(jsResourcePath);
28
-
29
- if (Object.keys(i18nData).length === 0) {
30
- console.warn(`[i18nIdReplaceLoaderConfig] Warning: No i18n data found in JSResource file: ${jsResourcePath}`);
31
- return {};
32
- }
33
-
34
- return i18nData;
35
- } catch (err) {
36
- throw new Error(`Error reading JSResource file ${jsResourcePath}: ${err.message}`);
37
- }
38
- }
39
-
40
- function i18nIdReplaceLoaderConfig(options, webpackContext) {
41
- let numericMapPath;
42
-
43
- if (options.i18nIndexing && options.i18nIndexing.enable) {
44
- numericMapPath = options.i18nIndexing.numericMapPath;
45
- } else if (options.i18nChunkSplit && options.i18nChunkSplit.chunkSplitEnable && options.i18nChunkSplit.useNumericIndexing) {
46
- numericMapPath = options.i18nChunkSplit.numericMapPath;
47
- } else {
48
- throw new Error('i18nIdReplaceLoader requires either i18nIndexing to be enabled or i18nChunkSplit with useNumericIndexing');
49
- }
50
-
51
- if (!numericMapPath) {
52
- throw new Error('numericMapPath is required in i18nIndexing or i18nChunkSplit config');
53
- }
54
-
55
- const allI18nData = loadJSResourcesOnce(options);
56
-
57
- const i18nKeyReplaceLoaderPath = require.resolve('../loaders/i18nIdReplaceLoader.js');
58
-
59
- const loaderOptions = {
60
- allI18nData: allI18nData,
61
- sourceMaps: false,
62
- numericMapPath: numericMapPath,
63
- includePaths: options.i18nIndexing?.loaderOptions?.includePaths || [],
64
- excludePaths: options.i18nIndexing?.loaderOptions?.excludePaths || ['node_modules', 'tests']
65
- };
66
- return {
67
- loader: i18nKeyReplaceLoaderPath,
68
- options: loaderOptions
69
- };
70
- }
71
-
72
- module.exports = {
73
- i18nIdReplaceLoaderConfig
74
- };
@@ -1,105 +0,0 @@
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
- };
@@ -1,79 +0,0 @@
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 = ''; // Smart contenthash detection based on template content
47
-
48
- const hasContentHashInNumeric = i18nOpts.numericFilenameTemplate.includes('[contenthash]');
49
- const hasContentHashInDynamic = i18nOpts.dynamicFilenameTemplate.includes('[contenthash]');
50
- const hasContentHashInSingle = i18nOpts.singleFileTemplate?.includes('[contenthash]'); // Determine if hashing should be enabled based on template content
51
-
52
- const shouldIncludeContentHash = i18nOpts.singleFile ? hasContentHashInSingle : hasContentHashInNumeric || hasContentHashInDynamic; // Use explicit includeContentHash if provided, otherwise use smart detection
53
-
54
- const finalIncludeContentHash = i18nOpts.includeContentHash !== undefined ? i18nOpts.includeContentHash : shouldIncludeContentHash;
55
- const numericIndexPluginOptions = {
56
- enable: i18nOpts.enable,
57
- jsResourcePath: i18nOpts.jsResourcePath,
58
- propertiesFolderPath: i18nOpts.propertiesFolderPath,
59
- numericMapPath: i18nOpts.numericMapPath,
60
- locales,
61
- allI18nObject,
62
- numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
63
- dynamicFilenameTemplate: i18nOpts.dynamicFilenameTemplate,
64
- singleFileTemplate: i18nOpts.singleFileTemplate,
65
- jsonpFunc: i18nOpts.jsonpFunc,
66
- singleFile: i18nOpts.singleFile || false,
67
- includeContentHash: finalIncludeContentHash,
68
- generateManifest: i18nOpts.generateManifest || false
69
- };
70
- const htmlInjectorOptions = {
71
- numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
72
- dynamicFilenameTemplate: i18nOpts.dynamicFilenameTemplate,
73
- htmlTemplateLabel: i18nOpts.htmlTemplateLabel,
74
- i18nAssetsPublicPathPrefix
75
- };
76
- const i18nNumericPluginInstance = new _I18nNumericIndexPlugin.I18nNumericIndexPlugin(numericIndexPluginOptions);
77
- const htmlInjectorPluginInstance = new _I18nNumericIndexHtmlInjectorPlugin.I18nNumericIndexHtmlInjectorPlugin(htmlInjectorOptions);
78
- return [i18nNumericPluginInstance, htmlInjectorPluginInstance];
79
- }