@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
@@ -5,121 +5,70 @@ const path = require('path');
5
5
  const fs = require('fs');
6
6
 
7
7
  const {
8
- parseProperties
9
- } = require('../utils/propertiesParser'); // Improved caching with proper cleanup
10
-
11
-
12
- class ConfigCache {
13
- constructor() {
14
- this.i18nDataCache = new Map();
15
- this.maxCacheSize = 10; // Limit cache size
16
- }
17
-
18
- getI18nData(filePath) {
19
- return this.i18nDataCache.get(filePath);
20
- }
21
-
22
- setI18nData(filePath, data) {
23
- if (this.i18nDataCache.size >= this.maxCacheSize) {
24
- // Clear oldest entries
25
- const firstKey = this.i18nDataCache.keys().next().value;
26
- this.i18nDataCache.delete(firstKey);
27
- }
28
-
29
- this.i18nDataCache.set(filePath, data);
30
- }
31
-
32
- clear() {
33
- this.i18nDataCache.clear();
34
- }
35
-
36
- }
37
-
38
- const configCache = new ConfigCache();
39
-
40
- function loadJSResourcesOnce(options, webpackContext) {
41
- if (!options.i18nIndexing || !options.i18nIndexing.enable) {
42
- throw new Error('i18nIdReplaceLoader requires i18nIndexing to be enabled');
43
- }
44
-
45
- if (!options.i18nIndexing.jsResourcePath) {
46
- throw new Error('Missing required jsResourcePath in i18nIndexing options');
47
- } // Use webpack context instead of process.cwd() for better reliability
48
-
49
-
50
- const contextPath = webpackContext || process.cwd();
51
- const propertiesFilePath = path.isAbsolute(options.i18nIndexing.jsResourcePath) ? options.i18nIndexing.jsResourcePath : path.resolve(contextPath, options.i18nIndexing.jsResourcePath); // Check cache first
52
-
53
- const cached = configCache.getI18nData(propertiesFilePath);
54
-
55
- if (cached) {
56
- return cached;
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');
57
20
  }
58
21
 
59
- if (!fs.existsSync(propertiesFilePath)) {
60
- throw new Error(`JSResource file not found at: ${propertiesFilePath}`);
22
+ if (!jsResourcePath) {
23
+ throw new Error('Missing required jsResourcePath in i18n options');
61
24
  }
62
25
 
63
26
  try {
64
- const data = fs.readFileSync(propertiesFilePath, {
65
- encoding: 'utf-8'
66
- });
67
- const i18nData = parseProperties(data);
27
+ const i18nData = getPropertiesAsJSON(jsResourcePath);
68
28
 
69
29
  if (Object.keys(i18nData).length === 0) {
70
- throw new Error(`No i18n data found in JSResource file: ${propertiesFilePath}`);
71
- } // Cache the result
72
-
30
+ console.warn(`[i18nIdReplaceLoaderConfig] Warning: No i18n data found in JSResource file: ${jsResourcePath}`);
31
+ return {};
32
+ }
73
33
 
74
- configCache.setI18nData(propertiesFilePath, i18nData);
75
34
  return i18nData;
76
35
  } catch (err) {
77
- throw new Error(`Error reading JSResource file ${propertiesFilePath}: ${err.message}`);
36
+ throw new Error(`Error reading JSResource file ${jsResourcePath}: ${err.message}`);
78
37
  }
79
38
  }
80
39
 
81
40
  function i18nIdReplaceLoaderConfig(options, webpackContext) {
82
- // Validate required options
83
- if (!options.i18nIndexing || !options.i18nIndexing.enable) {
84
- throw new Error('i18nIdReplaceLoader requires i18nIndexing to be enabled');
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');
85
49
  }
86
50
 
87
- if (!options.i18nIndexing.numericMapPath) {
88
- throw new Error('Missing required numericMapPath in i18nIndexing options');
89
- } // Load i18n data with proper context
90
-
91
-
92
- const allI18nData = loadJSResourcesOnce(options, webpackContext);
51
+ if (!numericMapPath) {
52
+ throw new Error('numericMapPath is required in i18nIndexing or i18nChunkSplit config');
53
+ }
93
54
 
94
- const i18nKeyReplaceLoaderPath = require.resolve('../loaders/i18nIdReplaceLoader.js'); // Enhanced loader options with better defaults
55
+ const allI18nData = loadJSResourcesOnce(options);
95
56
 
57
+ const i18nKeyReplaceLoaderPath = require.resolve('../loaders/i18nIdReplaceLoader.js');
96
58
 
97
59
  const loaderOptions = {
98
60
  allI18nData: allI18nData,
99
- sourceMaps: !!(options.devtool && options.devtool.includes('source-map')),
100
- isDebug: options.mode === 'development',
101
- useNumericIndexing: true,
102
- numericMapPath: options.i18nIndexing.numericMapPath,
103
- // Additional configurable options
104
- retainLines: options.i18nIndexing.retainLines || false,
105
- preserveComments: options.i18nIndexing.preserveComments !== false,
106
- compact: options.mode === 'production',
107
- minified: options.mode === 'production',
108
- // Allow custom babel plugins
109
- babelPlugins: options.i18nIndexing.babelPlugins || undefined
61
+ sourceMaps: false,
62
+ numericMapPath: numericMapPath,
63
+ includePaths: options.i18nIndexing?.loaderOptions?.includePaths || [],
64
+ excludePaths: options.i18nIndexing?.loaderOptions?.excludePaths || ['node_modules', 'tests']
110
65
  };
111
66
  return {
112
67
  loader: i18nKeyReplaceLoaderPath,
113
68
  options: loaderOptions
114
69
  };
115
- } // Export cache for potential cleanup
116
-
117
-
118
- function clearCache() {
119
- configCache.clear();
120
70
  }
121
71
 
122
72
  module.exports = {
123
- i18nIdReplaceLoaderConfig,
124
- clearCache
73
+ i18nIdReplaceLoaderConfig
125
74
  };
@@ -1,229 +1,105 @@
1
1
  "use strict";
2
2
 
3
- const fs = require('fs').promises;
4
-
5
- const fsSync = require('fs');
3
+ const fs = require('fs');
6
4
 
7
5
  const path = require('path');
8
6
 
9
7
  const parser = require('@babel/parser');
10
8
 
9
+ const traverse = require('@babel/traverse').default;
10
+
11
11
  const generator = require('@babel/generator').default;
12
12
 
13
- const {
14
- walk
15
- } = require('estree-walker');
13
+ const t = require('@babel/types');
16
14
 
17
15
  const {
18
16
  getOptions
19
17
  } = require('loader-utils');
20
18
 
21
- let collectAndCategorizeUsedI18nKeys;
22
-
23
- try {
24
- collectAndCategorizeUsedI18nKeys = require('../custom_plugins/I18nSplitPlugin/utils/collectAstKeys').collectAndCategorizeUsedI18nKeys;
25
- } catch (e) {
26
- throw new Error('[i18nIdReplaceLoader] Required dependency not found: ' + e.message);
27
- }
28
-
29
- const LOADER_PREFIX = '[i18nIdReplaceLoader]'; // Improved caching with proper cleanup
30
-
31
- class LoaderCache {
32
- constructor() {
33
- this.numericMapCache = new Map();
34
- this.astCache = new Map();
35
- this.maxCacheSize = 100; // Prevent memory leaks
36
- }
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();
37
24
 
38
- getNumericMap(mapPath) {
39
- return this.numericMapCache.get(mapPath);
40
- }
25
+ if (options.excludePaths) {
26
+ const shouldExclude = options.excludePaths.some(excludePath => resourcePath.includes(excludePath));
41
27
 
42
- setNumericMap(mapPath, data) {
43
- if (this.numericMapCache.size >= this.maxCacheSize) {
44
- // Clear oldest entries
45
- const firstKey = this.numericMapCache.keys().next().value;
46
- this.numericMapCache.delete(firstKey);
28
+ if (shouldExclude) {
29
+ return callback(null, source, map);
47
30
  }
48
-
49
- this.numericMapCache.set(mapPath, data);
50
31
  }
51
32
 
52
- clear() {
53
- this.numericMapCache.clear();
54
- this.astCache.clear();
55
- }
56
-
57
- }
33
+ if (options.includePaths && options.includePaths.length > 0) {
34
+ const shouldInclude = options.includePaths.some(includePath => resourcePath.includes(includePath));
58
35
 
59
- const loaderCache = new LoaderCache();
60
-
61
- async function loadNumericIdMap(loaderContext, mapPath) {
62
- if (!mapPath) {
63
- throw new Error(`${LOADER_PREFIX} Numeric map path not provided in loader options.`);
36
+ if (!shouldInclude) {
37
+ return callback(null, source, map);
38
+ }
64
39
  }
65
40
 
66
- const absoluteMapPath = path.isAbsolute(mapPath) ? mapPath : path.resolve(loaderContext.rootContext || process.cwd(), mapPath); // Check cache first
67
-
68
- const cached = loaderCache.getNumericMap(absoluteMapPath);
69
-
70
- if (cached) {
71
- return cached;
41
+ if (!options.allI18nData || Object.keys(options.allI18nData).length === 0) {
42
+ return callback(new Error(`i18nIdReplaceLoader: 'allI18nData' option is missing or empty`));
72
43
  }
73
44
 
74
- try {
75
- // Check if file exists
76
- if (!fsSync.existsSync(absoluteMapPath)) {
77
- throw new Error(`Pre-generated i18n numeric map file NOT FOUND at: ${absoluteMapPath}`);
78
- } // Read file asynchronously for better performance
45
+ let numericIdMap = null;
79
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);
80
52
 
81
- const fileContent = await fs.readFile(absoluteMapPath, 'utf-8');
82
- const parsedData = JSON.parse(fileContent); // Validate map structure
83
-
84
- if (!parsedData || !parsedData.originalKeyToNumericId || typeof parsedData.originalKeyToNumericId !== 'object') {
85
- throw new Error(`Pre-generated map file (${absoluteMapPath}) is invalid or does not contain 'originalKeyToNumericId'`);
53
+ if (parsedData && parsedData.originalKeyToNumericId) {
54
+ numericIdMap = parsedData.originalKeyToNumericId;
55
+ }
56
+ }
57
+ } catch (err) {// ignore - optional file
86
58
  }
87
-
88
- const numericIdMap = parsedData.originalKeyToNumericId; // Cache the result
89
-
90
- loaderCache.setNumericMap(absoluteMapPath, numericIdMap);
91
- return numericIdMap;
92
- } catch (err) {
93
- throw new Error(`${LOADER_PREFIX} Error loading or parsing pre-generated i18n map from ${absoluteMapPath}: ${err.message}`);
94
59
  }
95
- }
96
60
 
97
- module.exports = function i18nIdReplaceLoader(source, map, meta) {
98
- const resourcePath = this.resourcePath;
99
- this.cacheable && this.cacheable();
100
- const options = getOptions(this) || {};
101
- const callback = this.async();
102
- const loaderContext = this; // Validate required options
103
-
104
- if (!options.allI18nData || typeof options.allI18nData !== 'object' || Object.keys(options.allI18nData).length === 0) {
105
- return callback(new Error(`${LOADER_PREFIX} [${resourcePath}] 'allI18nData' option is missing or empty.`));
61
+ if (!numericIdMap) {
62
+ return callback(null, source, map);
106
63
  }
107
64
 
108
- if (!options.useNumericIndexing) {
109
- return callback(new Error(`${LOADER_PREFIX} [${resourcePath}] 'useNumericIndexing' must be enabled.`));
110
- } // Load numeric map asynchronously
111
-
112
-
113
- loadNumericIdMap(this, options.numericMapPath).then(numericIdMap => {
114
- try {
115
- // Configure parser with better defaults and configurability
116
- const parserOptions = {
117
- sourceType: 'module',
118
- plugins: options.babelPlugins || ['jsx', 'typescript', 'classProperties', 'optionalChaining', 'nullishCoalescingOperator', 'objectRestSpread', 'dynamicImport', 'decorators-legacy', 'asyncGenerators', 'bigInt', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'functionBind', 'importMeta', 'numericSeparator', 'optionalCatchBinding', 'throwExpressions', 'topLevelAwait'],
119
- attachComment: true,
120
- sourceFilename: resourcePath,
121
- allowImportExportEverywhere: true,
122
- allowAwaitOutsideFunction: true,
123
- allowReturnOutsideFunction: true,
124
- ranges: false,
125
- tokens: false
126
- };
127
- const astFile = parser.parse(source, parserOptions);
128
- const astProgram = astFile.program;
129
- const comments = astFile.comments || [];
130
- const {
131
- literalKeys,
132
- commentKeys
133
- } = collectAndCategorizeUsedI18nKeys(astProgram, comments, options.allI18nData, options.isDebug); // Store keys in module build info for plugin consumption
134
-
135
- if (this._module) {
136
- if (!this._module.buildInfo) {
137
- this._module.buildInfo = {};
138
- }
139
-
140
- if (literalKeys.size > 0) {
141
- this._module.buildInfo.loaderIdentifiedLiteralI18nKeys = Array.from(literalKeys);
142
- }
143
-
144
- if (commentKeys.size > 0) {
145
- this._module.buildInfo.loaderIdentifiedCommentI18nKeys = Array.from(commentKeys);
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;
146
80
  }
147
- } // Early return if no replacements needed
148
-
149
-
150
- if (literalKeys.size === 0) {
151
- return callback(null, source, map);
152
- }
153
81
 
154
- let replacementMade = false;
155
- let replacementCount = 0; // Process AST and replace string literals with numeric IDs
156
-
157
- walk(astProgram, {
158
- enter: function (node, parent, prop, index) {
159
- const walkerControl = this;
160
-
161
- if ((node.type === 'Literal' || node.type === 'StringLiteral') && typeof node.value === 'string') {
162
- const originalValue = node.value;
163
-
164
- if (literalKeys.has(originalValue)) {
165
- const numericId = numericIdMap[originalValue];
166
-
167
- if (numericId !== undefined) {
168
- const numericLiteralNode = {
169
- type: 'NumericLiteral',
170
- value: numericId,
171
- raw: String(numericId)
172
- };
173
- let replacementNode = numericLiteralNode; // Handle JSX attributes specially
174
-
175
- if (parent && parent.type === 'JSXAttribute' && parent.value === node) {
176
- replacementNode = {
177
- type: 'JSXExpressionContainer',
178
- expression: numericLiteralNode
179
- };
180
- }
181
-
182
- walkerControl.replace(replacementNode);
183
- replacementMade = true;
184
- replacementCount++;
185
- }
186
- }
187
- }
188
- }
189
- }); // Generate output only if replacements were made
190
-
191
- if (replacementMade) {
192
- const generateOptions = {
193
- sourceMaps: !!options.sourceMaps,
194
- sourceFileName: resourcePath,
195
- retainLines: options.retainLines || false,
196
- comments: options.preserveComments !== false,
197
- compact: options.compact || false,
198
- minified: options.minified || false
199
- };
200
- const output = generator(astFile, generateOptions, source); // Debug logging if enabled
201
-
202
- if (options.isDebug) {
203
- console.log(`${LOADER_PREFIX} [${resourcePath}] Replaced ${replacementCount} i18n keys with numeric IDs`);
82
+ if (numericIdMap.hasOwnProperty(node.value)) {
83
+ const numericId = String(numericIdMap[node.value]);
84
+ path.replaceWith(t.stringLiteral(numericId));
85
+ hasTransformations = true;
204
86
  }
205
-
206
- callback(null, output.code, options.sourceMaps && output.map ? output.map : map);
207
- } else {
208
- callback(null, source, map);
209
87
  }
210
- } catch (err) {
211
- // Enhanced error handling with better context
212
- const detailedError = new Error(`${LOADER_PREFIX} [${resourcePath}] AST Processing Error: ${err.message}`);
213
88
 
214
- if (err.loc && err.loc.line) {
215
- detailedError.message += ` at line ${err.loc.line}, column ${err.loc.column}`;
216
- } // Add stack trace in debug mode
217
-
218
-
219
- if (options.isDebug && err.stack) {
220
- detailedError.message += `\nStack: ${err.stack}`;
221
- }
222
-
223
- callback(detailedError);
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);
224
101
  }
225
- }).catch(err => {
226
- // Handle async errors from map loading
227
- callback(new Error(`${LOADER_PREFIX} [${resourcePath}] Failed to load numeric map: ${err.message}`));
228
- });
102
+ } catch (err) {
103
+ callback(err);
104
+ }
229
105
  };
@@ -5,43 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.configI18nNumericIndexPlugin = configI18nNumericIndexPlugin;
7
7
 
8
- var {
9
- I18nNumericIndexPlugin
10
- } = require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin");
8
+ var _I18nNumericIndexPlugin = require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin");
11
9
 
12
- var {
13
- I18nNumericIndexHtmlInjectorPlugin
14
- } = require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin");
10
+ var _I18nNumericIndexHtmlInjectorPlugin = require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin");
15
11
 
16
- var {
17
- readI18nValues
18
- } = require('../custom_plugins/I18nSplitPlugin/readI18nValues');
19
-
20
- const path = require('path');
21
-
22
- function urlConcat(strPath) {
23
- if (strPath && typeof strPath === 'string' && !strPath.endsWith('/')) {
24
- return strPath + '/';
25
- }
26
-
27
- return strPath;
28
- }
29
-
30
- function urlJoin(...args) {
31
- return args.map(part => typeof part === 'string' ? part.replace(/(^\/+|\/+$)/g, '') : '').filter(part => part !== '').join('/');
32
- }
33
-
34
- function validateAndGetFilenameTemplate(template, chunkType) {
35
- if (!template || typeof template !== 'string') {
36
- throw new Error(`Missing required ${chunkType} filename template in i18nIndexing options`);
37
- }
38
-
39
- if (!template.includes('[locale]')) {
40
- throw new Error(`${chunkType} filename template must include '[locale]' placeholder: ${template}`);
41
- }
42
-
43
- return template;
44
- }
12
+ var _readI18nValues = require("../custom_plugins/I18nSplitPlugin/readI18nValues");
45
13
 
46
14
  function configI18nNumericIndexPlugin(options) {
47
15
  if (!(options.i18nIndexing && options.i18nIndexing.enable)) {
@@ -50,67 +18,32 @@ function configI18nNumericIndexPlugin(options) {
50
18
 
51
19
  const i18nOpts = options.i18nIndexing;
52
20
  const cdnConfig = options.cdnMapping || {};
21
+ const requiredOptions = ['jsResourcePath', 'propertiesFolderPath', 'numericMapPath', 'jsonpFunc', 'htmlTemplateLabel', 'localeVarName', 'numericFilenameTemplate', 'dynamicFilenameTemplate'];
22
+ const missingOptions = requiredOptions.filter(opt => !i18nOpts[opt]);
53
23
 
54
- if (!i18nOpts.jsResourcePath) {
55
- throw new Error('Missing required jsResourcePath in i18nIndexing options');
56
- }
57
-
58
- if (!i18nOpts.propertiesFolderPath) {
59
- throw new Error('Missing required propertiesFolderPath in i18nIndexing options');
60
- }
61
-
62
- if (!i18nOpts.numericMapPath) {
63
- throw new Error('Missing required numericMapPath in i18nIndexing options');
64
- }
65
-
66
- if (!i18nOpts.jsonpFunc) {
67
- throw new Error('Missing required jsonpFunc in i18nIndexing options');
68
- }
69
-
70
- if (!i18nOpts.htmlTemplateLabel) {
71
- throw new Error('Missing required htmlTemplateLabel in i18nIndexing options');
72
- }
73
-
74
- if (!i18nOpts.localeVarName) {
75
- throw new Error('Missing required localeVarName in i18nIndexing options');
24
+ if (missingOptions.length > 0) {
25
+ return null;
76
26
  }
77
27
 
78
- console.log('I18n Indexing Options:', {
79
- enable: i18nOpts.enable,
80
- jsResourcePath: i18nOpts.jsResourcePath,
81
- propertiesFolderPath: i18nOpts.propertiesFolderPath,
82
- numericMapPath: i18nOpts.numericMapPath,
83
- numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
84
- dynamicFilenameTemplate: i18nOpts.dynamicFilenameTemplate,
85
- jsonpFunc: i18nOpts.jsonpFunc,
86
- htmlTemplateLabel: i18nOpts.htmlTemplateLabel,
87
- localeVarName: i18nOpts.localeVarName
88
- });
89
28
  const {
90
29
  locales,
91
30
  allI18nObject
92
- } = readI18nValues({
31
+ } = (0, _readI18nValues.readI18nValues)({
93
32
  jsResource: i18nOpts.jsResourcePath,
94
33
  propertiesFolder: i18nOpts.propertiesFolderPath,
95
34
  disableDefault: false
96
35
  });
97
- const numericFilenameTemplate = validateAndGetFilenameTemplate(i18nOpts.numericFilenameTemplate, 'numericFilenameTemplate');
98
- const dynamicFilenameTemplate = validateAndGetFilenameTemplate(i18nOpts.dynamicFilenameTemplate, 'dynamicFilenameTemplate');
99
- let i18nAssetsPublicPathPrefix = '';
100
36
 
101
- if (cdnConfig.isCdnEnabled) {
102
- if (cdnConfig.i18nTemplate) {
103
- i18nAssetsPublicPathPrefix = urlConcat(cdnConfig.i18nTemplate);
104
- } else if (cdnConfig.jsTemplate) {
105
- i18nAssetsPublicPathPrefix = urlConcat(cdnConfig.jsTemplate);
106
- } else {
107
- const defaultCdnDomainPlaceholder = '//{{--js-static-domain}}';
108
- i18nAssetsPublicPathPrefix = urlConcat(urlJoin(defaultCdnDomainPlaceholder, options.publicPath === undefined ? '' : options.publicPath));
109
- }
110
- } else {
111
- i18nAssetsPublicPathPrefix = urlConcat(options.publicPath === undefined ? '' : options.publicPath);
37
+ if (!i18nOpts.numericFilenameTemplate.includes('[locale]')) {
38
+ return null;
112
39
  }
113
40
 
41
+ if (!i18nOpts.dynamicFilenameTemplate.includes('[locale]')) {
42
+ return null;
43
+ } // Empty prefix - HtmlWebpackPlugin handles publicPath
44
+
45
+
46
+ const i18nAssetsPublicPathPrefix = '';
114
47
  const numericIndexPluginOptions = {
115
48
  enable: i18nOpts.enable,
116
49
  jsResourcePath: i18nOpts.jsResourcePath,
@@ -118,25 +51,20 @@ function configI18nNumericIndexPlugin(options) {
118
51
  numericMapPath: i18nOpts.numericMapPath,
119
52
  locales,
120
53
  allI18nObject,
121
- numericFilenameTemplate: numericFilenameTemplate,
122
- dynamicFilenameTemplate: dynamicFilenameTemplate,
123
- numericJsonpFunction: i18nOpts.jsonpFunc,
124
- dynamicJsonpFunction: i18nOpts.jsonpFunc,
125
- moduleType: 'i18n/mini-extract'
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
126
60
  };
127
61
  const htmlInjectorOptions = {
128
- locales,
129
- numericFilenameTemplate: numericFilenameTemplate,
130
- numericJsonpFunc: i18nOpts.jsonpFunc,
131
- dynamicFilenameTemplate: dynamicFilenameTemplate,
132
- dynamicJsonpFunc: i18nOpts.jsonpFunc,
133
- mainChunkName: options.i18nChunkSplit && options.i18nChunkSplit.mainChunkName || 'main',
62
+ numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
63
+ dynamicFilenameTemplate: i18nOpts.dynamicFilenameTemplate,
134
64
  htmlTemplateLabel: i18nOpts.htmlTemplateLabel,
135
- localeVarName: i18nOpts.localeVarName,
136
- i18nAssetsPublicPathPrefix: i18nAssetsPublicPathPrefix,
137
- cspNoncePlaceholder: i18nOpts.cspNoncePlaceholder || '{{--CSP-nonce}}'
65
+ i18nAssetsPublicPathPrefix
138
66
  };
139
- const i18nNumericPluginInstance = new I18nNumericIndexPlugin(numericIndexPluginOptions);
140
- const htmlInjectorPluginInstance = new I18nNumericIndexHtmlInjectorPlugin(htmlInjectorOptions);
67
+ const i18nNumericPluginInstance = new _I18nNumericIndexPlugin.I18nNumericIndexPlugin(numericIndexPluginOptions);
68
+ const htmlInjectorPluginInstance = new _I18nNumericIndexHtmlInjectorPlugin.I18nNumericIndexHtmlInjectorPlugin(htmlInjectorOptions);
141
69
  return [i18nNumericPluginInstance, htmlInjectorPluginInstance];
142
70
  }
@@ -36,9 +36,6 @@ function configI18nSplitPlugin(options) {
36
36
  publicPath: i18nPublicPath,
37
37
  i18nManifestFileName: (0, _nameTemplates.nameTemplates)('i18nmanifest', options),
38
38
  // template: (object, locale) => `window.loadI18n(${JSON.stringify(object)}, ${JSON.stringify(locale)})`,
39
- propertiesFolder: i18nChunkSplit.propertiesFolder,
40
- // NEW OPTIONS FOR NUMERIC INDEXING
41
- useNumericIndexing: i18nChunkSplit.useNumericIndexing,
42
- numericMapPath: i18nChunkSplit.numericMapPath
39
+ propertiesFolder: i18nChunkSplit.propertiesFolder
43
40
  });
44
41
  }
@@ -49,29 +49,12 @@ var _configRuntimeResourceCleanup = require("./pluginConfigs/configRuntimeResour
49
49
 
50
50
  var _configCustomScriptLoadingStrategyPlugin = require("./pluginConfigs/configCustomScriptLoadingStrategyPlugin");
51
51
 
52
- var {
53
- configI18nNumericIndexPlugin
54
- } = require("./pluginConfigs/configI18nNumericIndexPlugin");
52
+ var _configI18nNumericIndexPlugin = require("./pluginConfigs/configI18nNumericIndexPlugin");
55
53
 
54
+ // import { IgnorePlugin } from 'webpack';
56
55
  function plugins(options) {
57
56
  const {
58
57
  webpackPlugins
59
58
  } = options;
60
- const pluginConfigurations = [(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, _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)];
61
-
62
- if (options.i18nIndexing && options.i18nIndexing.enable) {
63
- const newI18nPlugins = configI18nNumericIndexPlugin(options);
64
-
65
- if (newI18nPlugins) {
66
- pluginConfigurations.push(...newI18nPlugins);
67
- }
68
- } else {
69
- const configI18nSplitPlugin = (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options);
70
-
71
- if (configI18nSplitPlugin) {
72
- pluginConfigurations.push(configI18nSplitPlugin);
73
- }
74
- }
75
-
76
- return [...pluginConfigurations, ...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);
77
60
  }