@zohodesk/client_build_tool 0.0.14 → 0.0.15

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 (22) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +27 -0
  3. package/lib/schemas/defaultConfigValues.js +11 -1
  4. package/lib/shared/bundler/webpack/custom_plugins/ChunkHierarchyPlugin.js +64 -0
  5. package/lib/shared/bundler/webpack/custom_plugins/InjectChunkGraphPlugin.js +45 -0
  6. package/lib/shared/bundler/webpack/custom_plugins/ResourceHintsPlugin.js +39 -36
  7. package/lib/shared/bundler/webpack/pluginConfigs/configChunkHierarchyPlugin.js +21 -0
  8. package/lib/shared/bundler/webpack/pluginConfigs/configInjectChunkGraphPlugin.js +22 -0
  9. package/lib/shared/bundler/webpack/pluginConfigs/configResourceHintsPlugin.js +8 -4
  10. package/lib/shared/bundler/webpack/plugins.js +5 -1
  11. package/lib/shared/bundler/webpack/tsLoaders.js +0 -1
  12. package/package.json +3 -2
  13. package/lib/shared/bundler/webpack/common/i18nOptionsValidator.js +0 -121
  14. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +0 -199
  15. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +0 -110
  16. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +0 -478
  17. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +0 -115
  18. package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +0 -69
  19. package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +0 -126
  20. package/lib/shared/bundler/webpack/pluginConfigs/configI18nIndexingPlugin.js +0 -42
  21. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericHtmlInjector.js +0 -82
  22. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +0 -95
@@ -1,126 +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(); // Early exit if i18n indexing is not enabled
24
-
25
- if (!options.i18nIndexingEnabled) {
26
- return callback(null, source, map);
27
- }
28
-
29
- if (options.excludePaths && Array.isArray(options.excludePaths)) {
30
- const shouldExclude = options.excludePaths.some(excludePath => typeof excludePath === 'string' && resourcePath.includes(excludePath));
31
-
32
- if (shouldExclude) {
33
- return callback(null, source, map);
34
- }
35
- }
36
-
37
- if (options.includePaths && Array.isArray(options.includePaths) && options.includePaths.length > 0) {
38
- const shouldInclude = options.includePaths.some(includePath => typeof includePath === 'string' && resourcePath.includes(includePath));
39
-
40
- if (!shouldInclude) {
41
- return callback(null, source, map);
42
- }
43
- }
44
-
45
- if (!options.allI18nData || Object.keys(options.allI18nData).length === 0) {
46
- return callback(new Error(`i18nIdReplaceLoader: 'allI18nData' option is missing or empty`));
47
- }
48
-
49
- let numericIdMap = options.numericIdMap;
50
-
51
- if (!numericIdMap && options.numericMapPath) {
52
- try {
53
- const mapPath = path.isAbsolute(options.numericMapPath) ? options.numericMapPath : path.resolve(this.rootContext || this.context || process.cwd(), options.numericMapPath);
54
- this.addDependency(mapPath);
55
-
56
- if (fs.existsSync(mapPath)) {
57
- const mapContent = fs.readFileSync(mapPath, 'utf-8');
58
- const parsed = JSON.parse(mapContent);
59
- numericIdMap = parsed.originalKeyToNumericId || parsed;
60
- }
61
- } catch (e) {
62
- return callback(new Error(`i18nIdReplaceLoader: Failed to load numeric map from ${options.numericMapPath}: ${e.message}`));
63
- }
64
- }
65
-
66
- if (!numericIdMap) {
67
- return callback(null, source, map);
68
- } // Pre-filter: Skip files without valid i18n keys from numericIdMap
69
-
70
-
71
- function hasValidI18nKeys(source, numericIdMap) {
72
- const keyPattern = /['"`]([\w-_]+(?:\.[\w-_]+){2,})['"`]/g;
73
- let match;
74
-
75
- while ((match = keyPattern.exec(source)) !== null) {
76
- if (numericIdMap.hasOwnProperty(match[1])) {
77
- return true;
78
- }
79
- }
80
-
81
- return false;
82
- }
83
-
84
- if (!hasValidI18nKeys(source, numericIdMap)) {
85
- return callback(null, source, map);
86
- }
87
-
88
- try {
89
- const ast = parser.parse(source, {
90
- sourceType: 'module',
91
- plugins: ['jsx', 'typescript', 'nullishCoalescingOperator'],
92
- sourceFilename: resourcePath
93
- });
94
- let hasTransformations = false;
95
- let transformationCount = 0;
96
- traverse(ast, {
97
- StringLiteral(path) {
98
- const {
99
- node
100
- } = path;
101
-
102
- if (options.allI18nData.hasOwnProperty(node.value) && numericIdMap.hasOwnProperty(node.value)) {
103
- const numericId = String(numericIdMap[node.value]);
104
- path.replaceWith(t.stringLiteral(numericId));
105
- hasTransformations = true;
106
- transformationCount++;
107
- }
108
- }
109
-
110
- });
111
-
112
- if (hasTransformations) {
113
- const output = generator(ast, {
114
- sourceMaps: !!options.sourceMaps,
115
- sourceFileName: resourcePath,
116
- retainLines: false,
117
- comments: true
118
- }, source);
119
- callback(null, output.code, output.map);
120
- } else {
121
- callback(null, source, map);
122
- }
123
- } catch (err) {
124
- callback(new Error(`i18nIdReplaceLoader: Failed to process ${resourcePath}: ${err.message}`));
125
- }
126
- };
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = configI18nIndexingPlugin;
7
-
8
- var _I18nNumericIndexPlugin = _interopRequireDefault(require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin"));
9
-
10
- var _resourceBasedPublicPath = require("../common/resourceBasedPublicPath");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function configI18nIndexingPlugin(config) {
15
- const {
16
- i18nIndexing,
17
- cdnMapping
18
- } = config;
19
-
20
- if (!i18nIndexing || !i18nIndexing.enable) {
21
- return null;
22
- } // Get the public path for i18n resources
23
-
24
-
25
- const i18nPublicPath = (0, _resourceBasedPublicPath.resourceBasedPublicPath)('i18n', config); // Get the CDN template for i18n resources if CDN is enabled
26
-
27
- const i18nCdnTemplate = cdnMapping && cdnMapping.isCdnEnabled ? cdnMapping.i18nTemplate || cdnMapping.jsTemplate : '';
28
- const options = {
29
- jsResourcePath: i18nIndexing.jsResourcePath,
30
- propertiesFolderPath: i18nIndexing.propertiesFolderPath,
31
- numericMapPath: i18nIndexing.numericMapPath,
32
- numericFilenameTemplate: i18nIndexing.numericFilenameTemplate || 'i18n-chunk/[locale]/numeric.i18n.js',
33
- dynamicFilenameTemplate: i18nIndexing.dynamicFilenameTemplate || 'i18n-chunk/[locale]/dynamic.i18n.js',
34
- jsonpFunc: i18nIndexing.jsonpFunc || 'window.loadI18nChunk',
35
- htmlTemplateLabel: i18nIndexing.htmlTemplateLabel || '{{--user-locale}}',
36
- localeVarName: i18nIndexing.localeVarName || 'window.userLangCode',
37
- customGroups: i18nIndexing.customGroups || {},
38
- publicPath: i18nPublicPath || '',
39
- i18nCdnTemplate
40
- };
41
- return new _I18nNumericIndexPlugin.default(options);
42
- }
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = configI18nNumericHtmlInjector;
7
-
8
- var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- const pluginName = 'I18nNumericHtmlInjectorPlugin';
13
-
14
- class I18nNumericHtmlInjectorPlugin {
15
- constructor(options) {
16
- this.options = options;
17
- }
18
-
19
- apply(compiler) {
20
- compiler.hooks.thisCompilation.tap(pluginName, compilation => {
21
- _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tap(pluginName, hookData => {
22
- const {
23
- assets
24
- } = hookData;
25
- const {
26
- numericFilenameTemplate,
27
- dynamicFilenameTemplate,
28
- htmlTemplateLabel,
29
- customGroups
30
- } = this.options;
31
- const newI18nAssets = [];
32
-
33
- if (numericFilenameTemplate) {
34
- const numericFilename = numericFilenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel).replace(/%5Blocale%5D/g, htmlTemplateLabel);
35
- newI18nAssets.push(numericFilename);
36
- }
37
-
38
- if (dynamicFilenameTemplate) {
39
- const dynamicFilename = dynamicFilenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel).replace(/%5Blocale%5D/g, htmlTemplateLabel);
40
- newI18nAssets.push(dynamicFilename);
41
- }
42
-
43
- if (customGroups) {
44
- Object.entries(customGroups).forEach(([groupName, groupConfig]) => {
45
- if (groupConfig.preload && groupConfig.filenameTemplate) {
46
- const groupFilename = groupConfig.filenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel).replace(/%5Blocale%5D/g, htmlTemplateLabel);
47
- newI18nAssets.push(groupFilename);
48
- }
49
- });
50
- }
51
-
52
- if (newI18nAssets.length > 0) {
53
- assets.js = [...newI18nAssets, ...assets.js];
54
- }
55
-
56
- return hookData;
57
- });
58
- });
59
- }
60
-
61
- }
62
-
63
- function configI18nNumericHtmlInjector(config) {
64
- const {
65
- i18nIndexing,
66
- cdnMapping
67
- } = config;
68
-
69
- if (!i18nIndexing || !i18nIndexing.enable) {
70
- return null;
71
- }
72
-
73
- const i18nCdnTemplate = cdnMapping && cdnMapping.isCdnEnabled ? cdnMapping.i18nTemplate || cdnMapping.jsTemplate : '';
74
- const options = {
75
- numericFilenameTemplate: i18nIndexing.numericFilenameTemplate || 'i18n-chunk/[locale]/numeric.i18n.js',
76
- dynamicFilenameTemplate: i18nIndexing.dynamicFilenameTemplate || 'i18n-chunk/[locale]/dynamic.i18n.js',
77
- htmlTemplateLabel: i18nIndexing.htmlTemplateLabel || '{{--user-locale}}',
78
- customGroups: i18nIndexing.customGroups || {},
79
- i18nCdnTemplate
80
- };
81
- return new I18nNumericHtmlInjectorPlugin(options);
82
- }
@@ -1,95 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.configI18nNumericIndexPlugin = configI18nNumericIndexPlugin;
7
-
8
- var _I18nNumericIndexPlugin = _interopRequireDefault(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
- var _i18nOptionsValidator = require("../common/i18nOptionsValidator.js");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function configI18nNumericIndexPlugin(options) {
19
- if (!options.i18nIndexing) {
20
- return null;
21
- }
22
-
23
- const i18nOpts = options.i18nIndexing;
24
- const groupPublicPathPrefix = i18nOpts.groupPublicPathPrefix || '';
25
- const groupPublicPathRuntimeExpression = i18nOpts.groupPublicPathRuntimeExpression !== undefined ? i18nOpts.groupPublicPathRuntimeExpression : 'window.__SMAP_PATH__';
26
-
27
- try {
28
- const result = (0, _i18nOptionsValidator.validateI18nIndexingOptions)(i18nOpts);
29
-
30
- if (result.skipValidation) {
31
- return null;
32
- }
33
- } catch (error) {
34
- throw new Error(`[I18nNumericIndexPlugin] ${error.message}`);
35
- }
36
-
37
- const emitFiles = i18nOpts.emitFiles !== undefined ? i18nOpts.emitFiles : true;
38
- const injectHtml = i18nOpts.injectI18nUrlInIndex !== undefined ? i18nOpts.injectI18nUrlInIndex : true;
39
- const hasCustomGroups = !!(i18nOpts.customGroups && Object.keys(i18nOpts.customGroups || {}).length);
40
-
41
- if (!emitFiles && !injectHtml && !hasCustomGroups) {
42
- return [];
43
- }
44
-
45
- let i18nData;
46
-
47
- try {
48
- i18nData = (0, _readI18nValues.readI18nValues)({
49
- jsResource: i18nOpts.jsResourcePath,
50
- propertiesFolder: i18nOpts.propertiesFolderPath,
51
- disableDefault: false
52
- });
53
- } catch (error) {
54
- throw new Error(`[I18nNumericIndexPlugin] Failed to read i18n data: ${error.message}`);
55
- }
56
-
57
- const {
58
- locales,
59
- allI18nObject
60
- } = i18nData;
61
- const numericTemplate = i18nOpts.numericFilenameTemplate || '[locale]/numeric.i18n.js';
62
- const dynamicTemplate = i18nOpts.dynamicFilenameTemplate || '[locale]/dynamic.i18n.js';
63
- const sharedOptions = {
64
- outputFolder: i18nOpts.outputFolder || 'i18n-chunk',
65
- numericFilenameTemplate: numericTemplate,
66
- dynamicFilenameTemplate: dynamicTemplate,
67
- singleFileTemplate: i18nOpts.singleFileTemplate,
68
- singleFile: i18nOpts.singleFile || false,
69
- includeContentHash: i18nOpts.includeContentHash || false
70
- };
71
- const numericIndexPluginOptions = { ...sharedOptions,
72
- enable: i18nOpts.enable,
73
- jsResourcePath: i18nOpts.jsResourcePath,
74
- propertiesFolderPath: i18nOpts.propertiesFolderPath,
75
- numericMapPath: i18nOpts.numericMapPath,
76
- locales,
77
- allI18nObject,
78
- jsonpFunc: i18nOpts.jsonpFunc,
79
- localeVarName: i18nOpts.localeVarName,
80
- restrictToBaseKeys: i18nOpts.restrictToBaseKeys || false,
81
- generateManifest: i18nOpts.generateManifest || false,
82
- manifestPath: i18nOpts.manifestPath || null,
83
- customGroups: i18nOpts.customGroups || null,
84
- chunkToGroupMapping: i18nOpts.chunkToGroupMapping || {},
85
- emitFiles,
86
- groupPublicPathPrefix,
87
- groupPublicPathRuntimeExpression
88
- };
89
- const htmlInjectorOptions = { ...sharedOptions,
90
- htmlTemplateLabel: i18nOpts.htmlTemplateLabel,
91
- i18nAssetsPublicPathPrefix: '',
92
- injectI18nUrlInIndex: injectHtml
93
- };
94
- return [new _I18nNumericIndexPlugin.default(numericIndexPluginOptions), new _I18nNumericIndexHtmlInjectorPlugin.I18nNumericIndexHtmlInjectorPlugin(htmlInjectorOptions)];
95
- }