@zohodesk/client_build_tool 0.0.11-exp.16.0 → 0.0.11-exp.17.0
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 +102 -0
- package/README_backup.md +102 -0
- package/lib/allCommandsConfigs.js +7 -2
- package/lib/commands/build/commandExecutor.js +5 -1
- package/lib/commands/build/config.js +3 -2
- package/lib/commands/build/optionsProcessor.js +5 -2
- package/lib/commands/build/preProcessor.js +2 -0
- package/lib/commands/buildEs/commandExecutor.js +5 -0
- package/lib/commands/buildEs/config.js +3 -2
- package/lib/commands/buildEs/preProcessor.js +2 -0
- package/lib/commands/buildLib/commandExecutor.js +5 -0
- package/lib/commands/buildLib/config.js +3 -2
- package/lib/commands/buildLib/preProcessor.js +2 -0
- package/lib/commands/mockserver/commandExecutor.js +9 -2
- package/lib/commands/mockserver/config.js +3 -2
- package/lib/commands/pre_process/commandExecutor.js +2 -0
- package/lib/commands/pre_process/config.js +3 -2
- package/lib/commands/start/commandExecutor.js +2 -0
- package/lib/commands/start/config.js +3 -2
- package/lib/commands/start/optionsProcessor.js +4 -2
- package/lib/commands/start/preProcessor.js +2 -0
- package/lib/commands/template/commandExecutor.js +7 -0
- package/lib/commands/template/config.js +3 -2
- package/lib/commands/version/commandExecutor.js +3 -0
- package/lib/commands/version/config.js +3 -2
- package/lib/commandsRouter.js +21 -5
- package/lib/index.js +2 -0
- package/lib/logger.js +5 -0
- package/lib/schemas/applyValuesToSchema/index.js +8 -0
- package/lib/schemas/applyValuesToSchema/isObject.js +1 -0
- package/lib/schemas/applyValuesToSchema/isValid.js +2 -0
- package/lib/schemas/cliArgsToObject.js +6 -2
- package/lib/schemas/defaultConfigValues.js +17 -4
- package/lib/schemas/defaultConfigValuesOnly.js +33 -4
- package/lib/schemas/deprecatedOptionsHandler.js +16 -7
- package/lib/schemas/getNpmVersion.js +5 -0
- package/lib/schemas/giveDefaultValue.js +3 -0
- package/lib/schemas/npmConfigToObject.js +5 -2
- package/lib/schemas/readOptions.js +30 -10
- package/lib/schemas/readOptionsForConfigFile.js +12 -2
- package/lib/shared/babel/addDefaultPlugins.js +2 -0
- package/lib/shared/babel/babelWebConfig.js +10 -1
- package/lib/shared/babel/babel_plugins/removeAttributesPlugin.js +4 -0
- package/lib/shared/babel/getBabelPlugin.js +7 -2
- package/lib/shared/babel/runBabelForJSFile.js +4 -1
- package/lib/shared/babel/runBabelForTsFile.js +5 -1
- package/lib/shared/bundler/webpack/common/decidePublicPath.js +5 -0
- package/lib/shared/bundler/webpack/common/libAlias.js +3 -3
- package/lib/shared/bundler/webpack/common/modeUtils.js +5 -0
- package/lib/shared/bundler/webpack/common/nameTemplates.js +18 -11
- package/lib/shared/bundler/webpack/common/resourceBasedPublicPath.js +3 -2
- package/lib/shared/bundler/webpack/configCustomLoaders.js +1 -0
- package/lib/shared/bundler/webpack/cssLoaders.js +2 -0
- package/lib/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/index.js +20 -1
- package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/index.js +25 -20
- package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/webpackCustomJsUrlLoader.js +9 -4
- package/lib/shared/bundler/webpack/custom_plugins/CustomScriptLoadingPlugin.js +23 -3
- package/lib/shared/bundler/webpack/custom_plugins/EFCTemplatePlugin.js +19 -8
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +61 -37
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +33 -15
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +108 -60
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +26 -20
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nFilesEmitPlugin.js +26 -5
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +16 -13
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nRuntimeDealerPlugin.js +53 -19
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/LocaleChunkAssetsStore.js +17 -2
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ModulesI18nKeysStore.js +13 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +21 -11
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +4 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +14 -4
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +13 -3
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/iterateModulesInChunk.js +12 -3
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +7 -2
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +2 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +3 -2
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +4 -2
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +13 -8
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +14 -2
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/getChunkModules.js +1 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +3 -1
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +4 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +25 -5
- package/lib/shared/bundler/webpack/custom_plugins/InitialHtmlPlugin.js +10 -3
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/addFilesNamesToManifestJson.js +6 -1
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createInitialEntries.js +6 -1
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createManifestJson.js +6 -0
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/findInitialFileNames.js +1 -0
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/index.js +7 -0
- package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/removeHashFromFileName.js +1 -0
- package/lib/shared/bundler/webpack/custom_plugins/ResourceHintsPlugin.js +17 -13
- package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +15 -6
- package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +13 -4
- package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +6 -4
- package/lib/shared/bundler/webpack/custom_plugins/RuntimeResourceCleanup/index.js +10 -0
- package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/classHandling.js +3 -0
- package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/index.js +20 -4
- package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/selectorWeightPrefixAdder.js +12 -10
- package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/windowsModification.js +3 -2
- package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +20 -7
- package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPluginUtils.js +1 -0
- package/lib/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +10 -7
- package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/addHashToFilePath.js +6 -1
- package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/index.js +16 -1
- package/lib/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin/index.js.js +11 -4
- package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/ErrorHandler.js +10 -3
- package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/index.js +62 -27
- package/lib/shared/bundler/webpack/custom_plugins/custom_attribute_plugin/index.js +15 -3
- package/lib/shared/bundler/webpack/custom_plugins/emitAsset.js +1 -0
- package/lib/shared/bundler/webpack/custom_plugins/getInitialAssetsFuncTemplate.js +12 -2
- package/lib/shared/bundler/webpack/custom_plugins/getInitialI18nAssetsArrayStr.js +7 -2
- package/lib/shared/bundler/webpack/defaultVendorPatternList.js +6 -2
- package/lib/shared/bundler/webpack/devtoolConfig.js +1 -0
- package/lib/shared/bundler/webpack/entryConfig.js +4 -0
- package/lib/shared/bundler/webpack/externals.js +1 -0
- package/lib/shared/bundler/webpack/getCSSLoaders.js +6 -1
- package/lib/shared/bundler/webpack/getFilenameFromModule.js +5 -1
- package/lib/shared/bundler/webpack/jsLoaders.js +10 -6
- package/lib/shared/bundler/webpack/loaderConfigs/assetLoaders.js +2 -0
- package/lib/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +3 -2
- package/lib/shared/bundler/webpack/loaderConfigs/checkIsPatternsMatchFilename.js +12 -3
- package/lib/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +1 -0
- package/lib/shared/bundler/webpack/loaderConfigs/configPostCssLoader.js +10 -2
- package/lib/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +2 -0
- package/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +12 -0
- package/lib/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +15 -1
- package/lib/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +4 -1
- package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +16 -8
- package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +29 -22
- package/lib/shared/bundler/webpack/loaders/miniCssFallBackLoader.js +2 -2
- package/lib/shared/bundler/webpack/loaders/workerLoader.js +19 -8
- package/lib/shared/bundler/webpack/optimizationConfig.js +13 -5
- package/lib/shared/bundler/webpack/outputConfig.js +9 -1
- package/lib/shared/bundler/webpack/pluginConfigs/configBundleAnalyzer.js +9 -5
- package/lib/shared/bundler/webpack/pluginConfigs/configBundleIntegrityReport.js +5 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configCSSMinifierPlugin.js +9 -4
- package/lib/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +8 -3
- package/lib/shared/bundler/webpack/pluginConfigs/configCopyPublicFolders.js +16 -1
- package/lib/shared/bundler/webpack/pluginConfigs/configCustomAttributesPlugin.js +4 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configCustomScriptLoadingStrategyPlugin.js +16 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configEFCTemplatePlugin.js +5 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +5 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +8 -2
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nIndexingPlugin.js +9 -5
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericHtmlInjector.js +25 -19
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +26 -12
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +9 -3
- package/lib/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +2 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configManifestJsonPlugin.js +7 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +7 -3
- package/lib/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +5 -1
- package/lib/shared/bundler/webpack/pluginConfigs/configResourceHintsPlugin.js +4 -1
- package/lib/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +4 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configRuntimeResourceCleanup.js +8 -3
- package/lib/shared/bundler/webpack/pluginConfigs/configSelectorWeightPlugin.js +6 -1
- package/lib/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +8 -3
- package/lib/shared/bundler/webpack/pluginConfigs/configSourceMapPlugin.js +4 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configTPHashMappingPlugin.js +8 -1
- package/lib/shared/bundler/webpack/pluginConfigs/configVariableConversionPlugin.js +6 -1
- package/lib/shared/bundler/webpack/plugins.js +24 -1
- package/lib/shared/bundler/webpack/resolvers.js +17 -3
- package/lib/shared/bundler/webpack/splitChunksConfig.js +15 -2
- package/lib/shared/bundler/webpack/statsConfig.js +5 -2
- package/lib/shared/bundler/webpack/tsLoaders.js +4 -2
- package/lib/shared/bundler/webpack/utils/index.js +12 -1
- package/lib/shared/bundler/webpack/utils/object-manipulation.js +16 -2
- package/lib/shared/bundler/webpack/utils/updateArrayWithDefault.js +7 -0
- package/lib/shared/bundler/webpack/webpackBuild.js +8 -1
- package/lib/shared/bundler/webpack/webpackConfig.js +17 -0
- package/lib/shared/commands-utils/doBasicRequirementCheck.js +3 -0
- package/lib/shared/commands-utils/getCliPath.js +9 -5
- package/lib/shared/commands-utils/index.js +3 -0
- package/lib/shared/commands-utils/log.js +2 -0
- package/lib/shared/commands-utils/readArgsFormCommandLine.js +1 -0
- package/lib/shared/commands-utils/readOptionFormCommandLine.js +1 -0
- package/lib/shared/commands-utils/spawnSyncIO.js +13 -5
- package/lib/shared/constants.js +29 -9
- package/lib/shared/fileUtils/copyFile.js +8 -1
- package/lib/shared/fileUtils/directoryIterator.js +4 -0
- package/lib/shared/fileUtils/watchRun.js +24 -3
- package/lib/shared/postcss/custom_postcss_plugins/EmptyPlugin.js +6 -1
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/constants.js +3 -2
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/handleIgnores.js +13 -6
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/index.js +26 -6
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/insertBefore.js +9 -6
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/isPreviouslyProcessed.js +3 -0
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/replaceUtils.js +7 -2
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/separateHoveredSelectorAndNormalSelector.js +2 -0
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/specialCases.js +9 -4
- package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/typeCheckUtils.js +10 -0
- package/lib/shared/postcss/custom_postcss_plugins/RTLSplitPlugin.js +29 -16
- package/lib/shared/postcss/custom_postcss_plugins/SelectorReplace.js +17 -0
- package/lib/shared/postcss/custom_postcss_plugins/ValueReplacer.js +9 -4
- package/lib/shared/postcss/custom_postcss_plugins/VariableModificationPlugin/index.js +63 -27
- package/lib/shared/postcss/filterPluginsAllowedForSpecficFile.js +13 -5
- package/lib/shared/postcss/getAllowedPostCssPlugins.js +3 -0
- package/lib/shared/postcss/getSpecificPostCssPlugin.js +17 -7
- package/lib/shared/postcss/runPostCssForCssFile.js +9 -1
- package/lib/shared/pre_process/runPreProcess.js +11 -0
- package/lib/shared/server/configWebpackDevMiddleware.js +8 -1
- package/lib/shared/server/corsHandling.js +6 -2
- package/lib/shared/server/getIp.js +7 -1
- package/lib/shared/server/getServerURL.js +6 -0
- package/lib/shared/server/httpsOptions.js +11 -0
- package/lib/shared/server/initExpressApp.js +4 -1
- package/lib/shared/server/initialHTMLHandling.js +16 -7
- package/lib/shared/server/mockApiHandler.js +16 -8
- package/lib/shared/server/mockServer.js +7 -0
- package/lib/shared/server/serveContextFiles.js +5 -1
- package/lib/shared/server/serverBywebpackDevMiddleware.js +9 -4
- package/lib/shared/server/startHttpServer.js +3 -0
- package/lib/shared/server/startHttpsServer.js +9 -1
- package/lib/shared/server/unwanted/addHttp2Server.js +7 -2
- package/lib/shared/server/unwanted/configWebpackDevMiddleware.js +8 -1
- package/lib/shared/server/unwanted/mockApiSupport.js +2 -0
- package/lib/shared/server/unwanted/websocketMockSetup.js +7 -1
- package/lib/shared/server/urlConcat.js +8 -3
- package/lib/shared/utils/requireLocalOrGlobal.js +25 -10
- package/lib/shared/utils/versionPrint.js +6 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js
CHANGED
|
@@ -4,46 +4,64 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
7
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
8
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
9
12
|
var _webpack = require("webpack");
|
|
13
|
+
|
|
10
14
|
var _propertiesUtils = require("../I18nSplitPlugin/utils/propertiesUtils");
|
|
15
|
+
|
|
11
16
|
var _I18nGroupRuntimeModule = require("./I18nGroupRuntimeModule");
|
|
17
|
+
|
|
12
18
|
var _i18nDataLoader = require("./utils/i18nDataLoader");
|
|
13
|
-
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
14
22
|
const {
|
|
15
23
|
RawSource
|
|
16
24
|
} = _webpack.sources;
|
|
17
25
|
const pluginName = 'I18nNumericIndexPlugin';
|
|
26
|
+
|
|
18
27
|
class I18nNumericIndexPlugin {
|
|
19
28
|
constructor(options) {
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
console.log('[I18nNumericIndexPlugin] Plugin initialized with options:', JSON.stringify(options, null, 2));
|
|
30
|
+
this.options = { ...options,
|
|
22
31
|
singleFile: options.singleFile || false,
|
|
23
32
|
singleFileTemplate: options.singleFileTemplate || '[locale].js',
|
|
24
33
|
includeContentHash: options.includeContentHash || false,
|
|
25
34
|
generateManifest: options.generateManifest || false,
|
|
26
35
|
outputFolder: options.outputFolder || 'i18n-chunk',
|
|
27
|
-
manifestPath: options.manifestPath || null
|
|
36
|
+
manifestPath: options.manifestPath || null,
|
|
37
|
+
emitFiles: options.emitFiles !== undefined ? options.emitFiles : true // Default to true for backward compatibility
|
|
38
|
+
|
|
28
39
|
};
|
|
29
40
|
this.numericMap = {};
|
|
30
41
|
this.customGroups = {};
|
|
31
42
|
this.manifest = {};
|
|
32
43
|
}
|
|
44
|
+
|
|
33
45
|
apply(compiler) {
|
|
34
46
|
// Detect webpackI18nGroup comments in code
|
|
35
47
|
this.detectI18nGroupComments(compiler);
|
|
36
48
|
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
37
49
|
// Add runtime module for group-based loading
|
|
38
50
|
if (this.options.customGroups) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
// Add runtime module unconditionally to ensure it's always available
|
|
52
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(pluginName, (chunk, set) => {
|
|
53
|
+
// Only add to the main/entry chunk to avoid duplication
|
|
54
|
+
if (chunk.name === 'main' || chunk.hasRuntime()) {
|
|
55
|
+
console.log('[I18nNumericIndexPlugin] Adding I18nGroupRuntimeModule to chunk:', chunk.name || chunk.id);
|
|
56
|
+
compilation.addRuntimeModule(chunk, new _I18nGroupRuntimeModule.I18nGroupRuntimeModule({
|
|
57
|
+
customGroups: this.options.customGroups,
|
|
58
|
+
localeVarName: this.options.localeVarName,
|
|
59
|
+
jsonpFunc: this.options.jsonpFunc
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
45
62
|
});
|
|
46
63
|
}
|
|
64
|
+
|
|
47
65
|
compilation.hooks.processAssets.tap({
|
|
48
66
|
name: pluginName,
|
|
49
67
|
stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
|
|
@@ -52,6 +70,7 @@ class I18nNumericIndexPlugin {
|
|
|
52
70
|
});
|
|
53
71
|
});
|
|
54
72
|
}
|
|
73
|
+
|
|
55
74
|
detectI18nGroupComments(compiler) {
|
|
56
75
|
compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
|
|
57
76
|
factory.hooks.parser.for('javascript/auto').tap(pluginName, parser => {
|
|
@@ -61,14 +80,17 @@ class I18nNumericIndexPlugin {
|
|
|
61
80
|
comments.forEach(comment => {
|
|
62
81
|
if (comment.value && comment.value.includes('webpackI18nGroup')) {
|
|
63
82
|
const match = comment.value.match(/webpackI18nGroup:\s*["']([^"']+)["']/);
|
|
83
|
+
|
|
64
84
|
if (match) {
|
|
65
|
-
const groupName = match[1];
|
|
66
|
-
|
|
85
|
+
const groupName = match[1]; // Store this information for later use
|
|
86
|
+
|
|
67
87
|
if (!this.detectedGroups) {
|
|
68
88
|
this.detectedGroups = {};
|
|
69
|
-
}
|
|
70
|
-
|
|
89
|
+
} // Extract chunk name from webpackChunkName comment
|
|
90
|
+
|
|
91
|
+
|
|
71
92
|
const chunkNameMatch = comment.value.match(/webpackChunkName:\s*["']([^"']+)["']/);
|
|
93
|
+
|
|
72
94
|
if (chunkNameMatch) {
|
|
73
95
|
const chunkName = chunkNameMatch[1];
|
|
74
96
|
this.detectedGroups[chunkName] = groupName;
|
|
@@ -80,7 +102,9 @@ class I18nNumericIndexPlugin {
|
|
|
80
102
|
});
|
|
81
103
|
});
|
|
82
104
|
}
|
|
105
|
+
|
|
83
106
|
processI18nFiles(compilation) {
|
|
107
|
+
console.log('[I18nNumericIndexPlugin] Starting to process i18n files - plugin is active');
|
|
84
108
|
const {
|
|
85
109
|
jsResourcePath,
|
|
86
110
|
propertiesFolderPath,
|
|
@@ -90,13 +114,16 @@ class I18nNumericIndexPlugin {
|
|
|
90
114
|
numericFilenameTemplate,
|
|
91
115
|
dynamicFilenameTemplate
|
|
92
116
|
} = this.options;
|
|
117
|
+
|
|
93
118
|
if (!jsResourcePath || !propertiesFolderPath) {
|
|
119
|
+
console.log('[I18nNumericIndexPlugin] Missing required paths - jsResourcePath:', jsResourcePath, 'propertiesFolderPath:', propertiesFolderPath);
|
|
94
120
|
return;
|
|
95
|
-
}
|
|
121
|
+
} // Load existing numeric map if available
|
|
122
|
+
|
|
96
123
|
|
|
97
|
-
// Load existing numeric map if available
|
|
98
124
|
if (numericMapPath) {
|
|
99
125
|
const mapData = (0, _i18nDataLoader.loadNumericMap)(numericMapPath, compilation);
|
|
126
|
+
|
|
100
127
|
if (mapData && mapData.sortedKeys) {
|
|
101
128
|
// Initialize numericMap from existing data
|
|
102
129
|
mapData.sortedKeys.forEach((key, id) => {
|
|
@@ -105,54 +132,49 @@ class I18nNumericIndexPlugin {
|
|
|
105
132
|
}
|
|
106
133
|
});
|
|
107
134
|
}
|
|
108
|
-
}
|
|
135
|
+
} // Read JSResources.properties
|
|
136
|
+
|
|
109
137
|
|
|
110
|
-
//
|
|
111
|
-
const jsResourceKeys = (0, _propertiesUtils.getPropertiesAsJSON)(jsResourcePath);
|
|
138
|
+
const jsResourceKeys = (0, _propertiesUtils.getPropertiesAsJSON)(jsResourcePath); // Parse custom groups from banner markers
|
|
112
139
|
|
|
113
|
-
// Parse custom groups from banner markers
|
|
114
140
|
if (customGroups) {
|
|
115
141
|
this.parseCustomGroups(jsResourcePath, customGroups);
|
|
116
|
-
}
|
|
142
|
+
} // Get all locale translations
|
|
143
|
+
|
|
117
144
|
|
|
118
|
-
// Get all locale translations
|
|
119
145
|
const allI18nObject = (0, _propertiesUtils.getAllI18n)({
|
|
120
146
|
folderPath: propertiesFolderPath,
|
|
121
147
|
disableDefault: false,
|
|
122
148
|
jsResourceI18nKeys: jsResourceKeys
|
|
123
|
-
});
|
|
149
|
+
}); // For en_US, use only JSResources (don't merge with ApplicationResources_en_US)
|
|
124
150
|
|
|
125
|
-
// For en_US, use only JSResources (don't merge with ApplicationResources_en_US)
|
|
126
151
|
if (allI18nObject['en_US']) {
|
|
127
152
|
allI18nObject['en_US'] = jsResourceKeys;
|
|
128
153
|
} else {
|
|
129
154
|
// If en_US doesn't exist in the folder, create it from JSResources
|
|
130
155
|
allI18nObject['en_US'] = jsResourceKeys;
|
|
131
156
|
}
|
|
132
|
-
const locales = Object.keys(allI18nObject);
|
|
133
157
|
|
|
134
|
-
// Process each locale
|
|
158
|
+
const locales = Object.keys(allI18nObject); // Process each locale
|
|
159
|
+
|
|
135
160
|
locales.forEach(locale => {
|
|
136
161
|
const localeData = allI18nObject[locale];
|
|
137
162
|
const numericData = {};
|
|
138
163
|
const dynamicData = {};
|
|
139
|
-
const groupData = {};
|
|
164
|
+
const groupData = {}; // Initialize custom groups
|
|
140
165
|
|
|
141
|
-
// Initialize custom groups
|
|
142
166
|
Object.keys(customGroups || {}).forEach(groupName => {
|
|
143
167
|
groupData[groupName] = {};
|
|
144
|
-
});
|
|
168
|
+
}); // Process each key
|
|
145
169
|
|
|
146
|
-
// Process each key
|
|
147
170
|
Object.keys(localeData).forEach(key => {
|
|
148
|
-
const value = localeData[key];
|
|
171
|
+
const value = localeData[key]; // Simple logic: if has numeric ID use it, otherwise it's dynamic
|
|
149
172
|
|
|
150
|
-
// Simple logic: if has numeric ID use it, otherwise it's dynamic
|
|
151
173
|
if (this.numericMap[key]) {
|
|
152
|
-
const numericKey = String(this.numericMap[key]);
|
|
174
|
+
const numericKey = String(this.numericMap[key]); // Check if belongs to a custom group
|
|
153
175
|
|
|
154
|
-
// Check if belongs to a custom group
|
|
155
176
|
const belongsToGroup = this.getKeyGroup(key);
|
|
177
|
+
|
|
156
178
|
if (belongsToGroup) {
|
|
157
179
|
groupData[belongsToGroup][numericKey] = value;
|
|
158
180
|
} else {
|
|
@@ -162,15 +184,14 @@ class I18nNumericIndexPlugin {
|
|
|
162
184
|
// No numeric ID = dynamic key (regardless of placeholders)
|
|
163
185
|
dynamicData[key] = value;
|
|
164
186
|
}
|
|
165
|
-
});
|
|
187
|
+
}); // Handle single-file mode or separate files
|
|
166
188
|
|
|
167
|
-
// Handle single-file mode or separate files
|
|
168
189
|
if (this.options.singleFile) {
|
|
169
190
|
// Combine numeric and dynamic data into a single file
|
|
170
|
-
const combinedData = {
|
|
171
|
-
...numericData,
|
|
191
|
+
const combinedData = { ...numericData,
|
|
172
192
|
...dynamicData
|
|
173
193
|
};
|
|
194
|
+
|
|
174
195
|
if (Object.keys(combinedData).length > 0) {
|
|
175
196
|
// Use singleFileTemplate for combined file - no fileType suffix needed
|
|
176
197
|
const singleFileTemplate = this.options.singleFileTemplate || '[locale].js';
|
|
@@ -180,35 +201,37 @@ class I18nNumericIndexPlugin {
|
|
|
180
201
|
// Emit numeric chunk
|
|
181
202
|
if (Object.keys(numericData).length > 0) {
|
|
182
203
|
this.emitChunk(compilation, numericFilenameTemplate, locale, numericData, jsonpFunc, null, 'numeric');
|
|
183
|
-
}
|
|
204
|
+
} // Emit dynamic chunk
|
|
205
|
+
|
|
184
206
|
|
|
185
|
-
// Emit dynamic chunk
|
|
186
207
|
if (Object.keys(dynamicData).length > 0) {
|
|
187
208
|
this.emitChunk(compilation, dynamicFilenameTemplate, locale, dynamicData, jsonpFunc, null, 'dynamic');
|
|
188
209
|
}
|
|
189
|
-
}
|
|
210
|
+
} // Emit custom group chunks (always separate)
|
|
211
|
+
|
|
190
212
|
|
|
191
|
-
// Emit custom group chunks (always separate)
|
|
192
213
|
Object.entries(groupData).forEach(([groupName, data]) => {
|
|
193
214
|
const groupConfig = customGroups[groupName];
|
|
215
|
+
|
|
194
216
|
if (groupConfig && Object.keys(data).length > 0) {
|
|
195
217
|
const groupTemplate = groupConfig.filenameTemplate || `[locale]/${groupName}.i18n.js`;
|
|
196
218
|
this.emitChunk(compilation, groupTemplate, locale, data, jsonpFunc, groupName, `group-${groupName}`);
|
|
197
219
|
}
|
|
198
220
|
});
|
|
199
|
-
});
|
|
221
|
+
}); // Generate manifest file if enabled
|
|
200
222
|
|
|
201
|
-
// Generate manifest file if enabled
|
|
202
223
|
if (this.options.generateManifest && Object.keys(this.manifest).length > 0) {
|
|
203
224
|
const manifestPath = this.options.manifestPath || _path.default.join(this.options.outputFolder, 'manifest.json');
|
|
225
|
+
|
|
204
226
|
const manifestContent = JSON.stringify(this.manifest, null, 2);
|
|
205
227
|
compilation.emitAsset(manifestPath, new RawSource(manifestContent));
|
|
206
|
-
}
|
|
228
|
+
} // Don't save numeric map - it should only be generated by the external script
|
|
207
229
|
|
|
208
|
-
// Don't save numeric map - it should only be generated by the external script
|
|
209
230
|
}
|
|
231
|
+
|
|
210
232
|
parseCustomGroups(jsResourcePath, customGroups) {
|
|
211
233
|
const content = _fs.default.readFileSync(jsResourcePath, 'utf-8');
|
|
234
|
+
|
|
212
235
|
const lines = content.split('\n');
|
|
213
236
|
Object.entries(customGroups).forEach(([groupName, config]) => {
|
|
214
237
|
const {
|
|
@@ -224,6 +247,7 @@ class I18nNumericIndexPlugin {
|
|
|
224
247
|
inGroup = false;
|
|
225
248
|
} else if (inGroup && line.includes('=')) {
|
|
226
249
|
const key = line.split('=')[0].trim();
|
|
250
|
+
|
|
227
251
|
if (key && !key.startsWith('#')) {
|
|
228
252
|
groupKeys.push(key);
|
|
229
253
|
}
|
|
@@ -232,63 +256,72 @@ class I18nNumericIndexPlugin {
|
|
|
232
256
|
this.customGroups[groupName] = groupKeys;
|
|
233
257
|
});
|
|
234
258
|
}
|
|
259
|
+
|
|
235
260
|
getKeyGroup(key) {
|
|
236
261
|
for (const [groupName, keys] of Object.entries(this.customGroups)) {
|
|
237
262
|
if (keys.includes(key)) {
|
|
238
263
|
return groupName;
|
|
239
264
|
}
|
|
240
265
|
}
|
|
266
|
+
|
|
241
267
|
return null;
|
|
242
268
|
}
|
|
269
|
+
|
|
243
270
|
isDynamicKey(value) {
|
|
244
271
|
// Check if value contains placeholders like {0}, {1}, etc.
|
|
245
272
|
return /\{\d+\}/.test(value);
|
|
246
273
|
}
|
|
274
|
+
|
|
247
275
|
getNumericKey(key) {
|
|
248
276
|
// Return numeric ID if it exists, null otherwise
|
|
249
277
|
return this.numericMap[key] ? String(this.numericMap[key]) : null;
|
|
250
278
|
}
|
|
279
|
+
|
|
251
280
|
generateContentHash(content, compilation) {
|
|
252
281
|
const {
|
|
253
282
|
hashFunction,
|
|
254
283
|
hashDigest,
|
|
255
284
|
hashDigestLength
|
|
256
285
|
} = compilation.outputOptions;
|
|
286
|
+
|
|
257
287
|
const hash = _webpack.util.createHash(hashFunction || 'xxhash64');
|
|
288
|
+
|
|
258
289
|
hash.update(content);
|
|
259
290
|
return hash.digest(hashDigest || 'hex').substring(0, hashDigestLength || 8);
|
|
260
291
|
}
|
|
292
|
+
|
|
261
293
|
constructFilePath(template, locale) {
|
|
262
294
|
const {
|
|
263
295
|
outputFolder,
|
|
264
296
|
singleFile
|
|
265
|
-
} = this.options;
|
|
297
|
+
} = this.options; // Replace locale placeholder
|
|
266
298
|
|
|
267
|
-
|
|
268
|
-
let filePath = template.replace(/\[locale\]/g, locale);
|
|
299
|
+
let filePath = template.replace(/\[locale\]/g, locale); // If template already contains outputFolder or starts with a path separator, use as-is
|
|
269
300
|
|
|
270
|
-
// If template already contains outputFolder or starts with a path separator, use as-is
|
|
271
301
|
if (filePath.includes(outputFolder) || filePath.startsWith('/')) {
|
|
272
302
|
return filePath.replace(/\\/g, '/');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// For single-file mode with a simple template like '[locale].js',
|
|
303
|
+
} // For single-file mode with a simple template like '[locale].js',
|
|
276
304
|
// put it directly in outputFolder without subdirectories
|
|
305
|
+
|
|
306
|
+
|
|
277
307
|
if (singleFile && !filePath.includes('/')) {
|
|
278
308
|
return _path.default.join(outputFolder, filePath).replace(/\\/g, '/');
|
|
279
|
-
}
|
|
309
|
+
} // For other cases, if template contains subdirectories, preserve them
|
|
310
|
+
|
|
280
311
|
|
|
281
|
-
// For other cases, if template contains subdirectories, preserve them
|
|
282
312
|
return _path.default.join(outputFolder, filePath).replace(/\\/g, '/');
|
|
283
313
|
}
|
|
314
|
+
|
|
284
315
|
emitChunk(compilation, filenameTemplate, locale, data, jsonpFunc, groupName = null, fileType = null) {
|
|
285
316
|
if (!filenameTemplate || Object.keys(data).length === 0) {
|
|
286
317
|
return null;
|
|
287
318
|
}
|
|
319
|
+
|
|
320
|
+
console.log('[I18nNumericIndexPlugin] Processing chunk for locale:', locale, 'fileType:', fileType, 'dataKeys:', Object.keys(data).length, 'groupName:', groupName, 'emitFiles:', this.options.emitFiles); // Generate content regardless of emitFiles flag (needed for runtime)
|
|
321
|
+
|
|
288
322
|
const content = this.generateChunkContent(data, jsonpFunc, groupName);
|
|
289
|
-
let outputPath = this.constructFilePath(filenameTemplate, locale);
|
|
323
|
+
let outputPath = this.constructFilePath(filenameTemplate, locale); // Handle [contenthash] placeholder in template
|
|
290
324
|
|
|
291
|
-
// Handle [contenthash] placeholder in template
|
|
292
325
|
if (outputPath.includes('[contenthash]')) {
|
|
293
326
|
const contentHash = this.generateContentHash(content, compilation);
|
|
294
327
|
outputPath = outputPath.replace(/\[contenthash\]/g, contentHash);
|
|
@@ -296,12 +329,13 @@ class I18nNumericIndexPlugin {
|
|
|
296
329
|
// Legacy: Add content hash before .js extension if includeContentHash is true
|
|
297
330
|
const contentHash = this.generateContentHash(content, compilation);
|
|
298
331
|
outputPath = outputPath.replace(/\.js$/, `.${contentHash}.js`);
|
|
299
|
-
}
|
|
332
|
+
} // Track in manifest if enabled
|
|
333
|
+
|
|
300
334
|
|
|
301
|
-
// Track in manifest if enabled
|
|
302
335
|
if (this.options.generateManifest) {
|
|
303
336
|
// For single-file mode, use clean locale.js format
|
|
304
337
|
let manifestKey;
|
|
338
|
+
|
|
305
339
|
if (this.options.singleFile) {
|
|
306
340
|
// Just use locale.js without path or type suffix
|
|
307
341
|
manifestKey = `${locale}.js`;
|
|
@@ -310,19 +344,33 @@ class I18nNumericIndexPlugin {
|
|
|
310
344
|
const cleanName = this.constructFilePath(filenameTemplate, locale);
|
|
311
345
|
manifestKey = fileType ? cleanName.replace(/\.js$/, `.${fileType}.js`) : cleanName;
|
|
312
346
|
}
|
|
347
|
+
|
|
313
348
|
this.manifest[manifestKey] = _path.default.basename(outputPath);
|
|
349
|
+
} // Only emit the file if emitFiles is true
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
if (this.options.emitFiles) {
|
|
353
|
+
console.log('[I18nNumericIndexPlugin] Emitting file:', outputPath);
|
|
354
|
+
compilation.emitAsset(outputPath, new RawSource(content));
|
|
355
|
+
} else {
|
|
356
|
+
console.log('[I18nNumericIndexPlugin] Skipping file emission for:', outputPath, '(emitFiles is false)');
|
|
314
357
|
}
|
|
315
|
-
|
|
358
|
+
|
|
316
359
|
return outputPath;
|
|
317
360
|
}
|
|
361
|
+
|
|
318
362
|
generateChunkContent(data, jsonpFunc, groupName) {
|
|
319
363
|
// Decode Unicode escapes to convert \uXXXX to actual characters
|
|
320
364
|
const jsonString = (0, _propertiesUtils.decodeUnicodeEscapes)(JSON.stringify(data));
|
|
365
|
+
|
|
321
366
|
if (groupName) {
|
|
322
367
|
// Include group name for lazy loading identification
|
|
323
368
|
return `${jsonpFunc}(${jsonString}, "${groupName}");`;
|
|
324
369
|
}
|
|
370
|
+
|
|
325
371
|
return `${jsonpFunc}(${jsonString});`;
|
|
326
372
|
}
|
|
373
|
+
|
|
327
374
|
}
|
|
375
|
+
|
|
328
376
|
exports.default = I18nNumericIndexPlugin;
|
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
|
|
4
5
|
const path = require('path');
|
|
6
|
+
|
|
5
7
|
const {
|
|
6
8
|
getPropertiesAsJSON
|
|
7
9
|
} = require('../../I18nSplitPlugin/utils/propertiesUtils');
|
|
8
|
-
|
|
9
10
|
/**
|
|
10
11
|
* Load and parse a properties file
|
|
11
12
|
*/
|
|
13
|
+
|
|
14
|
+
|
|
12
15
|
function loadPropertiesFile(filePath, compilation, description) {
|
|
13
16
|
try {
|
|
14
17
|
const parsed = getPropertiesAsJSON(filePath);
|
|
@@ -17,21 +20,22 @@ function loadPropertiesFile(filePath, compilation, description) {
|
|
|
17
20
|
if (compilation) {
|
|
18
21
|
compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading ${description}: ${err.message}`));
|
|
19
22
|
}
|
|
23
|
+
|
|
20
24
|
return {};
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
|
-
|
|
24
27
|
/**
|
|
25
28
|
* Load numeric mapping from JSON file
|
|
26
29
|
*/
|
|
30
|
+
|
|
31
|
+
|
|
27
32
|
function loadNumericMap(numericMapPath, compilation) {
|
|
28
33
|
try {
|
|
29
34
|
const fileContent = fs.readFileSync(numericMapPath, 'utf-8');
|
|
30
35
|
const parsedData = JSON.parse(fileContent);
|
|
31
36
|
let numericMap;
|
|
32
|
-
let totalKeys;
|
|
37
|
+
let totalKeys; // Handle both wrapped and flat formats
|
|
33
38
|
|
|
34
|
-
// Handle both wrapped and flat formats
|
|
35
39
|
if (parsedData.originalKeyToNumericId) {
|
|
36
40
|
// New format with metadata
|
|
37
41
|
numericMap = parsedData.originalKeyToNumericId;
|
|
@@ -40,9 +44,9 @@ function loadNumericMap(numericMapPath, compilation) {
|
|
|
40
44
|
// Flat format - use directly
|
|
41
45
|
numericMap = parsedData;
|
|
42
46
|
totalKeys = Object.keys(numericMap).length;
|
|
43
|
-
}
|
|
47
|
+
} // Create sorted array for numeric ID lookups
|
|
48
|
+
|
|
44
49
|
|
|
45
|
-
// Create sorted array for numeric ID lookups
|
|
46
50
|
const maxId = Math.max(...Object.values(numericMap));
|
|
47
51
|
const sortedKeys = new Array(maxId + 1);
|
|
48
52
|
Object.entries(numericMap).forEach(([key, id]) => {
|
|
@@ -56,40 +60,41 @@ function loadNumericMap(numericMapPath, compilation) {
|
|
|
56
60
|
if (compilation) {
|
|
57
61
|
compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading numeric map: ${err.message}`));
|
|
58
62
|
}
|
|
63
|
+
|
|
59
64
|
return {
|
|
60
65
|
sortedKeys: [],
|
|
61
66
|
totalKeys: 0
|
|
62
67
|
};
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
|
-
|
|
66
70
|
/**
|
|
67
71
|
* Load all locale files from properties directory
|
|
68
72
|
*/
|
|
73
|
+
|
|
74
|
+
|
|
69
75
|
function loadAllLocaleFiles(propertiesPath, compilation, jsResourceBase) {
|
|
70
76
|
const allI18n = {};
|
|
71
|
-
const locales = [];
|
|
77
|
+
const locales = []; // Start with English base
|
|
72
78
|
|
|
73
|
-
// Start with English base
|
|
74
79
|
allI18n['en_US'] = jsResourceBase;
|
|
75
80
|
locales.push('en_US');
|
|
81
|
+
|
|
76
82
|
try {
|
|
77
83
|
const files = fs.readdirSync(propertiesPath);
|
|
78
84
|
files.forEach(file => {
|
|
79
|
-
if (!file.endsWith('.properties')) return;
|
|
85
|
+
if (!file.endsWith('.properties')) return; // Match locale-specific property files
|
|
80
86
|
|
|
81
|
-
// Match locale-specific property files
|
|
82
87
|
const match = file.match(/^ApplicationResources_([a-z]{2}_[A-Z]{2})\.properties$/);
|
|
88
|
+
|
|
83
89
|
if (match) {
|
|
84
90
|
const locale = match[1];
|
|
85
91
|
const filePath = path.join(propertiesPath, file);
|
|
86
|
-
const localeData = loadPropertiesFile(filePath, compilation, `locale ${locale}`);
|
|
92
|
+
const localeData = loadPropertiesFile(filePath, compilation, `locale ${locale}`); // Merge with base resources
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
allI18n[locale] = {
|
|
90
|
-
...jsResourceBase,
|
|
94
|
+
allI18n[locale] = { ...jsResourceBase,
|
|
91
95
|
...localeData
|
|
92
96
|
};
|
|
97
|
+
|
|
93
98
|
if (!locales.includes(locale)) {
|
|
94
99
|
locales.push(locale);
|
|
95
100
|
}
|
|
@@ -100,23 +105,23 @@ function loadAllLocaleFiles(propertiesPath, compilation, jsResourceBase) {
|
|
|
100
105
|
compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error reading properties folder: ${err.message}`));
|
|
101
106
|
}
|
|
102
107
|
}
|
|
108
|
+
|
|
103
109
|
return {
|
|
104
110
|
allI18n,
|
|
105
111
|
locales
|
|
106
112
|
};
|
|
107
113
|
}
|
|
108
|
-
|
|
109
114
|
/**
|
|
110
115
|
* Main loader function for i18n data
|
|
111
116
|
*/
|
|
117
|
+
|
|
118
|
+
|
|
112
119
|
function loadI18nData(options, compilation) {
|
|
113
120
|
const jsResourcePath = path.resolve(compilation.compiler.context, options.jsResourcePath);
|
|
114
|
-
const propertiesPath = path.resolve(compilation.compiler.context, options.propertiesFolderPath);
|
|
121
|
+
const propertiesPath = path.resolve(compilation.compiler.context, options.propertiesFolderPath); // Load base JS resources
|
|
115
122
|
|
|
116
|
-
// Load
|
|
117
|
-
const jsResourceBase = loadPropertiesFile(jsResourcePath, compilation, 'JS resources');
|
|
123
|
+
const jsResourceBase = loadPropertiesFile(jsResourcePath, compilation, 'JS resources'); // Load all locale files
|
|
118
124
|
|
|
119
|
-
// Load all locale files
|
|
120
125
|
const {
|
|
121
126
|
allI18n,
|
|
122
127
|
locales
|
|
@@ -127,6 +132,7 @@ function loadI18nData(options, compilation) {
|
|
|
127
132
|
locales
|
|
128
133
|
};
|
|
129
134
|
}
|
|
135
|
+
|
|
130
136
|
module.exports = {
|
|
131
137
|
loadPropertiesFile,
|
|
132
138
|
loadNumericMap,
|
|
@@ -4,21 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.I18nFilesEmitPlugin = void 0;
|
|
7
|
+
|
|
7
8
|
var _webpack = require("webpack");
|
|
9
|
+
|
|
8
10
|
var _createHash = require("./createHash");
|
|
11
|
+
|
|
9
12
|
var _pathCreator = require("./pathCreator");
|
|
13
|
+
|
|
10
14
|
var _propertiesUtils = require("./utils/propertiesUtils");
|
|
15
|
+
|
|
11
16
|
var _LocaleChunkAssetsStore = require("./LocaleChunkAssetsStore");
|
|
12
|
-
/* eslint-disable no-restricted-syntax */
|
|
13
17
|
|
|
18
|
+
/* eslint-disable no-restricted-syntax */
|
|
14
19
|
const pluginName = 'I18nFilesEmitPlugin';
|
|
15
20
|
const {
|
|
16
21
|
RawSource
|
|
17
22
|
} = _webpack.sources;
|
|
23
|
+
|
|
18
24
|
class I18nFilesEmitPlugin {
|
|
19
25
|
constructor(options) {
|
|
20
|
-
this.options = options;
|
|
21
|
-
// this.options = {
|
|
26
|
+
this.options = options; // this.options = {
|
|
22
27
|
// locales: options.locales,
|
|
23
28
|
// chunkFilename: options.chunkFilename,
|
|
24
29
|
// filename: options.filename,
|
|
@@ -26,6 +31,7 @@ class I18nFilesEmitPlugin {
|
|
|
26
31
|
// jsonpFunc: options.jsonpFunc
|
|
27
32
|
// };
|
|
28
33
|
}
|
|
34
|
+
|
|
29
35
|
apply(compiler) {
|
|
30
36
|
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
31
37
|
// Get store for cache
|
|
@@ -42,10 +48,12 @@ class I18nFilesEmitPlugin {
|
|
|
42
48
|
if (!i18nStore.isChunkHasI18n(chunk.id)) {
|
|
43
49
|
return;
|
|
44
50
|
}
|
|
51
|
+
|
|
45
52
|
this.emitI18nFileForEveryLocale(chunk, compilation);
|
|
46
53
|
});
|
|
47
54
|
});
|
|
48
55
|
}
|
|
56
|
+
|
|
49
57
|
createAndStoreFileContentForEveryChunkAndLocale(compilation) {
|
|
50
58
|
const {
|
|
51
59
|
chunks
|
|
@@ -54,12 +62,15 @@ class I18nFilesEmitPlugin {
|
|
|
54
62
|
locales
|
|
55
63
|
} = this.options;
|
|
56
64
|
const i18nStore = this.store;
|
|
65
|
+
|
|
57
66
|
for (const chunk of chunks) {
|
|
58
67
|
const i18nKeys = i18nStore.getI18nKeysForChunk(chunk);
|
|
68
|
+
|
|
59
69
|
if (!i18nKeys.length) {
|
|
60
70
|
// eslint-disable-next-line no-continue
|
|
61
71
|
continue;
|
|
62
72
|
}
|
|
73
|
+
|
|
63
74
|
for (const locale of locales) {
|
|
64
75
|
const content = this.getI18nChunkFileContent(i18nKeys, locale);
|
|
65
76
|
i18nStore.storeData(chunk.id, locale, {
|
|
@@ -68,11 +79,13 @@ class I18nFilesEmitPlugin {
|
|
|
68
79
|
}
|
|
69
80
|
}
|
|
70
81
|
}
|
|
82
|
+
|
|
71
83
|
updateChunkHashForEveryLocale(chunk, hash) {
|
|
72
84
|
const {
|
|
73
85
|
locales
|
|
74
86
|
} = this.options;
|
|
75
87
|
const i18nStore = this.store;
|
|
88
|
+
|
|
76
89
|
if (i18nStore.isChunkHasI18n(chunk.id)) {
|
|
77
90
|
for (const loc of locales) {
|
|
78
91
|
const content = i18nStore.getContent(chunk.id, loc);
|
|
@@ -80,6 +93,7 @@ class I18nFilesEmitPlugin {
|
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
}
|
|
96
|
+
|
|
83
97
|
emitI18nFileForEveryLocale(chunk, compilation) {
|
|
84
98
|
const i18nStore = this.store;
|
|
85
99
|
const {
|
|
@@ -87,8 +101,8 @@ class I18nFilesEmitPlugin {
|
|
|
87
101
|
chunkFilename,
|
|
88
102
|
filename
|
|
89
103
|
} = this.options;
|
|
90
|
-
const fileNameTemplate = chunk.canBeInitial() ? filename : chunkFilename;
|
|
91
|
-
|
|
104
|
+
const fileNameTemplate = chunk.canBeInitial() ? filename : chunkFilename; // const { chunks } = compilation;
|
|
105
|
+
|
|
92
106
|
for (const locale of locales) {
|
|
93
107
|
const content = i18nStore.getContent(chunk.id, locale);
|
|
94
108
|
const contentHash = (0, _createHash.createHash)({
|
|
@@ -111,6 +125,7 @@ class I18nFilesEmitPlugin {
|
|
|
111
125
|
compilation.emitAsset(filename, new RawSource(content));
|
|
112
126
|
}
|
|
113
127
|
}
|
|
128
|
+
|
|
114
129
|
static createFilenameWithHash({
|
|
115
130
|
compilation,
|
|
116
131
|
fileNameTemplate,
|
|
@@ -132,16 +147,20 @@ class I18nFilesEmitPlugin {
|
|
|
132
147
|
filename
|
|
133
148
|
};
|
|
134
149
|
}
|
|
150
|
+
|
|
135
151
|
getI18nContentForkeys(i18nKeys, locale) {
|
|
136
152
|
const {
|
|
137
153
|
allI18nObject
|
|
138
154
|
} = this.options;
|
|
139
155
|
const data = {};
|
|
156
|
+
|
|
140
157
|
for (const key of i18nKeys) {
|
|
141
158
|
data[key] = allI18nObject[locale][key];
|
|
142
159
|
}
|
|
160
|
+
|
|
143
161
|
return data;
|
|
144
162
|
}
|
|
163
|
+
|
|
145
164
|
getI18nChunkFileContent(i18nKeys, loc) {
|
|
146
165
|
const {
|
|
147
166
|
jsonpFunc
|
|
@@ -149,5 +168,7 @@ class I18nFilesEmitPlugin {
|
|
|
149
168
|
const data = this.getI18nContentForkeys(i18nKeys, loc);
|
|
150
169
|
return `${jsonpFunc}(${(0, _propertiesUtils.jsonToString)(data)})`;
|
|
151
170
|
}
|
|
171
|
+
|
|
152
172
|
}
|
|
173
|
+
|
|
153
174
|
exports.I18nFilesEmitPlugin = I18nFilesEmitPlugin;
|