@zohodesk/react-cli 0.0.1-exp.175.1 → 0.0.1-exp.176.2
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/.eslintignore +7 -7
- package/.eslintrc.js +180 -180
- package/.prettierrc +6 -6
- package/README.md +1025 -1028
- package/bin/cli.js +482 -482
- package/cert/Tsicsezwild-22-23.crt +37 -37
- package/cert/Tsicsezwild-22-23.key +27 -27
- package/docs/CustomChunks.md +26 -26
- package/docs/DevStart.md +18 -18
- package/docs/HoverActive.md +12 -12
- package/docs/InstallNode.md +28 -28
- package/docs/SelectorWeight.md +6 -0
- package/docs/TODOS.md +10 -10
- package/docs/ValueReplacer.md +60 -60
- package/docs/VariableConversion.md +719 -678
- package/docs/warnings_while_install.txt +35 -35
- package/files/eslintrc.js +62 -62
- package/files/prettierrc.js +3 -3
- package/lib/babel/cmjs-plugins-presets.js +4 -0
- package/lib/babel/es-plugins-presets.js +4 -0
- package/lib/common/getEntries.js +10 -0
- package/lib/common/getPublicPathConfig.js +6 -0
- package/lib/common/index.js +5 -0
- package/lib/common/splitChunks.js +13 -2
- package/lib/common/sslcertUpdater.js +17 -6
- package/lib/common/templateParameters.js +2 -0
- package/lib/common/testPattern.js +21 -10
- package/lib/common/valueReplacer.js +15 -0
- package/lib/configs/jest.config.js +9 -0
- package/lib/configs/libAlias.js +2 -4
- package/lib/configs/webpack.component.umd.config.js +5 -0
- package/lib/configs/webpack.css.umd.config.js +13 -5
- package/lib/configs/webpack.dev.config.js +36 -2
- package/lib/configs/webpack.docs.config.js +21 -1
- package/lib/configs/webpack.impact.config.js +19 -1
- package/lib/configs/webpack.prod.config.js +37 -3
- package/lib/hooks/docsProptypeHook.js +7 -3
- package/lib/jest/commitedFilesResult.js +45 -3
- package/lib/jest/coverageCollector.js +11 -0
- package/lib/jest/jsonMaker.js +6 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +8 -0
- package/lib/jest/preProcessors/jsPreprocessor.js +2 -0
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +3 -0
- package/lib/jest/result.js +22 -0
- package/lib/jest/run.js +17 -6
- package/lib/jest/setup.js +57 -5
- package/lib/loaderUtils/configsAssetsLoaders.js +44 -34
- package/lib/loaderUtils/getCSSLoaders.js +35 -20
- package/lib/loaderUtils/getDevJsLoaders.js +8 -0
- package/lib/loaderUtils/index.js +3 -0
- package/lib/loaderUtils/windowsModification.js +11 -0
- package/lib/loaders/docsLoader.js +7 -0
- package/lib/loaders/docsPropsLoader.js +7 -3
- package/lib/loaders/fileBountryLoader.js +2 -0
- package/lib/loaders/fileLoader.js +22 -11
- package/lib/loaders/scriptInstrumentLoader.js +13 -5
- package/lib/loaders/selectorMappingLoader.js +25 -7
- package/lib/loaders/workerLoader.js +29 -13
- package/lib/middlewares/HMRMiddleware.js +26 -13
- package/lib/middlewares/SSTMiddleware.js +3 -0
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +9 -3
- package/lib/pluginUtils/getDevPlugins.js +68 -22
- package/lib/pluginUtils/getDocsPlugins.js +10 -1
- package/lib/pluginUtils/getLibraryImactPlugins.js +5 -4
- package/lib/pluginUtils/getLibraryPlugins.js +5 -0
- package/lib/pluginUtils/getProdPlugins.js +77 -28
- package/lib/pluginUtils/getServerPlugins.js +5 -0
- package/lib/pluginUtils/getUMDCSSPlugins.js +7 -0
- package/lib/pluginUtils/getUMDComponentPlugins.js +7 -0
- package/lib/pluginUtils/index.js +8 -0
- package/lib/plugins/CdnChangePlugin.js +14 -0
- package/lib/plugins/CleanupStatsPlugin.js +5 -0
- package/lib/plugins/EFCPlugin.js +34 -23
- package/lib/plugins/EFCPlugin.md +6 -6
- package/lib/plugins/EFCTemplatePlugin.js +32 -23
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +38 -12
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +17 -12
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +10 -4
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +77 -46
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +59 -44
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +30 -21
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +95 -95
- package/lib/plugins/I18nSplitPlugin/README.md +25 -25
- package/lib/plugins/I18nSplitPlugin/index.js +80 -70
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +12 -2
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +1 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +5 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +6 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +4 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +20 -2
- package/lib/plugins/ManifestPlugin.js +17 -0
- package/lib/plugins/ModuleStatsPlugin.js +23 -0
- package/lib/plugins/OptimizeJSPlugin.js +7 -0
- package/lib/plugins/PublicPathCallbackPlugin.js +10 -0
- package/lib/plugins/PublicPathChangePlugin.js +36 -4
- package/lib/plugins/ReportGeneratePlugin.js +30 -4
- package/lib/plugins/RequireVariablePublicPlugin.js +6 -0
- package/lib/plugins/ResourceHintsPlugin.js +27 -20
- package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +17 -12
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +22 -15
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -30
- package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +5 -2
- package/lib/plugins/ScriptInstrumentPlugin.js +7 -0
- package/lib/plugins/SelectorPlugin.js +97 -0
- package/lib/plugins/ServiceWorkerPlugin.js +29 -13
- package/lib/plugins/ShadowDOMSupportPlugin.js +40 -3
- package/lib/plugins/SourceMapHookPlugin.js +9 -0
- package/lib/plugins/TPHashMappingPlugin.js +19 -5
- package/lib/plugins/UglifyCSSPlugin.js +9 -0
- package/lib/plugins/UnusedFilesFindPlugin.js +35 -2
- package/lib/plugins/VariableConversionCollector.js +322 -0
- package/lib/plugins/composeCommonPlugin.js +30 -0
- package/lib/plugins/index.js +19 -0
- package/lib/plugins/libraryImpactPlugin.js +32 -0
- package/lib/plugins/webpackwatchrunplugin.js +5 -0
- package/lib/postcss-plugins/ExcludePlugin.js +4 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +37 -24
- package/lib/postcss-plugins/ValueReplacer.js +6 -9
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +3 -0
- package/lib/postcss-plugins/__test__/test1Input.css +38 -38
- package/lib/postcss-plugins/__test__/test1Output.css +38 -38
- package/lib/postcss-plugins/hoverActivePlugin.js +69 -33
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +42 -13
- package/lib/postcss-plugins/variableModificationPlugin/index.js +216 -141
- package/lib/postcss-plugins/variableModifier.js +20 -13
- package/lib/schemas/index.js +23 -4
- package/lib/servers/clusterHubServer.js +10 -0
- package/lib/servers/devBuild.js +24 -13
- package/lib/servers/docsServer.js +2 -0
- package/lib/servers/docsServerCore.js +21 -0
- package/lib/servers/getCliPath.js +9 -0
- package/lib/servers/helpServer.js +5 -0
- package/lib/servers/httpsOptions.js +4 -0
- package/lib/servers/impactServer.js +34 -2
- package/lib/servers/mockserver.js +9 -0
- package/lib/servers/nowatchserver.js +34 -12
- package/lib/servers/scrServer.js +20 -13
- package/lib/servers/server.js +35 -7
- package/lib/servers/ssServer.js +16 -0
- package/lib/sh/pre-commit.sh +34 -34
- package/lib/sh/reportPublish.sh +45 -45
- package/lib/templates/CoverageScriptTemplate.js +14 -0
- package/lib/templates/WMSTemplate.js +12 -6
- package/lib/utils/babelPresets.js +2 -0
- package/lib/utils/buildstats.html +148 -148
- package/lib/utils/clean.js +8 -2
- package/lib/utils/copy.js +6 -0
- package/lib/utils/copyTimezones.js +8 -0
- package/lib/utils/createEventStream.js +4 -0
- package/lib/utils/cssClassNameGenerate.js +19 -3
- package/lib/utils/cssURLReplacer.js +25 -0
- package/lib/utils/dependencyPostPublish.js +9 -0
- package/lib/utils/fileUtils.js +26 -0
- package/lib/utils/folderIterator.js +10 -0
- package/lib/utils/getComponents.js +21 -0
- package/lib/utils/getCurrentBranch.js +5 -0
- package/lib/utils/getDependenciesImpactList.js +21 -0
- package/lib/utils/getHash.js +7 -0
- package/lib/utils/getIp.js +2 -0
- package/lib/utils/getOptions.js +39 -14
- package/lib/utils/getServerURL.js +7 -0
- package/lib/utils/index.js +47 -2
- package/lib/utils/init.js +1 -0
- package/lib/utils/initPreCommitHook.js +29 -6
- package/lib/utils/jsonHelper.js +19 -2
- package/lib/utils/libraryImpactConfig.js +2 -0
- package/lib/utils/lint/addScripts.js +5 -2
- package/lib/utils/lint/checkExistingConfig.js +12 -3
- package/lib/utils/lint/copyConfigs.js +3 -0
- package/lib/utils/lint/index.js +9 -0
- package/lib/utils/lint/lintScripts.js +1 -0
- package/lib/utils/lint/lintSetup.js +4 -3
- package/lib/utils/lint/lintStagedPreCommitHook.js +1 -0
- package/lib/utils/lint/question.js +7 -0
- package/lib/utils/lintReporter.js +20 -0
- package/lib/utils/mailSender.js +7 -0
- package/lib/utils/pullOrigin.js +4 -0
- package/lib/utils/reinstallDependencies.js +28 -0
- package/lib/utils/removeAttributes.js +7 -0
- package/lib/utils/repoClone.js +27 -2
- package/lib/utils/request.js +12 -0
- package/lib/utils/resultSchema.json +73 -73
- package/lib/utils/rtl.js +16 -4
- package/lib/utils/setEnvVariables.js +2 -0
- package/lib/utils/ssTestHack.js +10 -0
- package/lib/utils/switchBranch.js +4 -0
- package/lib/utils/urlConcat.js +4 -0
- package/lib/utils/useExitCleanup.js +10 -9
- package/npm8.md +9 -9
- package/package.json +146 -146
- package/postpublish.js +6 -6
- package/templates/app/.eslintrc.js +140 -140
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -24
- package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
- package/templates/app/app/properties/i18nkeys.json +3 -3
- package/templates/app/docs/all.html +69 -69
- package/templates/app/mockapi/index.js +18 -18
- package/templates/app/package.json +37 -37
- package/templates/app/src/actions/SampleActions/index.js +37 -37
- package/templates/app/src/actions/index.js +65 -65
- package/templates/app/src/appUrls.js +19 -19
- package/templates/app/src/components/Alert/Alert.js +134 -134
- package/templates/app/src/components/Alert/Alert.module.css +79 -79
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -37
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -84
- package/templates/app/src/components/Sample/Sample.module.css +11 -11
- package/templates/app/src/components/Sample/SampleList.js +61 -61
- package/templates/app/src/components/Slider/Slider.css +41 -41
- package/templates/app/src/components/Slider/Slider.js +55 -55
- package/templates/app/src/containers/AlertContainer/index.js +15 -15
- package/templates/app/src/containers/AppContainer/index.js +96 -96
- package/templates/app/src/containers/AppContainer/index.module.css +27 -27
- package/templates/app/src/containers/CustomMatch/index.js +65 -65
- package/templates/app/src/containers/DevTools/index.js +10 -10
- package/templates/app/src/containers/Header/index.js +67 -67
- package/templates/app/src/containers/Header/index.module.css +43 -43
- package/templates/app/src/containers/Redirect/index.js +63 -63
- package/templates/app/src/containers/Redirector/index.js +47 -47
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -42
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -3
- package/templates/app/src/historyChange.js +5 -5
- package/templates/app/src/index.html +10 -10
- package/templates/app/src/index.js +24 -24
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -59
- package/templates/app/src/reducers/alertData.js +11 -11
- package/templates/app/src/reducers/index.js +6 -6
- package/templates/app/src/reducers/samples.js +19 -19
- package/templates/app/src/store/configureStore.dev.js +51 -51
- package/templates/app/src/store/configureStore.js +5 -5
- package/templates/app/src/store/configureStore.prod.js +26 -26
- package/templates/app/src/util/Common.js +5 -5
- package/templates/app/src/util/RequestAPI.js +132 -132
- package/templates/docs/all.html +249 -249
- package/templates/docs/component.html +178 -178
- package/templates/docs/components.html +221 -221
- package/templates/docs/css/b.min.css +6 -6
- package/templates/docs/css/component.css +42 -42
- package/templates/docs/css/componentTest.css +6 -6
- package/templates/docs/css/hopscotch.css +585 -585
- package/templates/docs/css/style.css +1022 -1022
- package/templates/docs/impactReportTemplate.html +154 -154
- package/templates/docs/index.html +1501 -1501
- package/templates/docs/js/active-line.js +72 -72
- package/templates/docs/js/b.min.js +7 -7
- package/templates/docs/js/codemirror.js +9680 -9680
- package/templates/docs/js/designTokens.js +334 -334
- package/templates/docs/js/j.min.js +4 -4
- package/templates/docs/js/javascript.js +874 -874
- package/templates/docs/js/matchbrackets.js +145 -145
|
@@ -4,49 +4,59 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
7
8
|
var _webpack = require("webpack");
|
|
9
|
+
|
|
8
10
|
var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nKeysIdentifer"));
|
|
11
|
+
|
|
9
12
|
var _hashUtils = require("./utils/hashUtils");
|
|
13
|
+
|
|
10
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
/**
|
|
12
|
-
* this plugin for the download i18n files
|
|
13
|
-
* So, if need to downoad i18n in browser this plugin handle that
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* this plugin works
|
|
17
|
-
* how it works?
|
|
18
|
-
* this plugin hook the requireEnsure method and we write logic for current compiled file download logic
|
|
19
|
-
*
|
|
20
|
-
* hinds:-
|
|
21
|
-
* requireEnsure method was loader for all js chunk's ,
|
|
22
|
-
* which means if we use dynamic import then this function will create script tag for that dynamic resource
|
|
23
|
-
* so every dynamic js chunk will load by this function,
|
|
24
|
-
* So we update this function with when dynamic jschunk call the nour code also execute
|
|
25
|
-
*
|
|
26
|
-
* some thing missing in this definetion
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
15
|
|
|
16
|
+
/**
|
|
17
|
+
* this plugin for the download i18n files
|
|
18
|
+
* So, if need to downoad i18n in browser this plugin handle that
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
* this plugin works
|
|
22
|
+
* how it works?
|
|
23
|
+
* this plugin hook the requireEnsure method and we write logic for current compiled file download logic
|
|
24
|
+
*
|
|
25
|
+
* hinds:-
|
|
26
|
+
* requireEnsure method was loader for all js chunk's ,
|
|
27
|
+
* which means if we use dynamic import then this function will create script tag for that dynamic resource
|
|
28
|
+
* so every dynamic js chunk will load by this function,
|
|
29
|
+
* So we update this function with when dynamic jschunk call the nour code also execute
|
|
30
|
+
*
|
|
31
|
+
* some thing missing in this definetion
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
30
34
|
// import { REGEXP_HASH, REGEXP_CHUNKHASH } from './utils/hashUtils';
|
|
35
|
+
const pluginName = 'DownloadLogicOfI18n'; // const pluginName = 'i18n-plugin';
|
|
31
36
|
|
|
32
|
-
const pluginName = 'DownloadLogicOfI18n';
|
|
33
|
-
// const pluginName = 'i18n-plugin';
|
|
34
37
|
const MODULE_TYPE = 'json/i18n';
|
|
38
|
+
|
|
35
39
|
const ltype = locale => `${MODULE_TYPE}/${locale}`;
|
|
40
|
+
|
|
36
41
|
function hashesWithLength(hashes, length) {
|
|
37
42
|
const shortChunkHashMap = {};
|
|
43
|
+
|
|
38
44
|
for (let key of Object.keys(hashes)) {
|
|
39
45
|
if (typeof hashes[key] === 'string') {
|
|
40
46
|
shortChunkHashMap[key] = hashes.slice(0, length);
|
|
41
47
|
}
|
|
42
48
|
}
|
|
49
|
+
|
|
43
50
|
return shortChunkHashMap;
|
|
44
51
|
}
|
|
52
|
+
|
|
45
53
|
function getContentHashMaxLength(filenameTemplate) {
|
|
46
54
|
let length = 0;
|
|
47
55
|
let matches = filenameTemplate.match(_hashUtils.REGEXP_CONTENTHASH);
|
|
56
|
+
|
|
48
57
|
for (let match of matches) {
|
|
49
58
|
let tem = match.match(/\d+/);
|
|
59
|
+
|
|
50
60
|
if (tem) {
|
|
51
61
|
length = Math.max(parseInt(tem[0]), length);
|
|
52
62
|
} else {
|
|
@@ -54,8 +64,10 @@ function getContentHashMaxLength(filenameTemplate) {
|
|
|
54
64
|
break;
|
|
55
65
|
}
|
|
56
66
|
}
|
|
67
|
+
|
|
57
68
|
return length;
|
|
58
69
|
}
|
|
70
|
+
|
|
59
71
|
class I18nDownlodLogic {
|
|
60
72
|
constructor({
|
|
61
73
|
filenameTemplate,
|
|
@@ -70,53 +82,67 @@ class I18nDownlodLogic {
|
|
|
70
82
|
localeVarName
|
|
71
83
|
};
|
|
72
84
|
}
|
|
85
|
+
|
|
73
86
|
getShortContentHashes(chunk, hashLength) {
|
|
74
87
|
let allContenHashes = {};
|
|
75
88
|
const chunkMaps = chunk.getChunkMaps();
|
|
76
89
|
this.locales.forEach(locale => {
|
|
77
90
|
allContenHashes[locale] = chunkMaps.contentHash[ltype(locale)];
|
|
78
91
|
});
|
|
92
|
+
|
|
79
93
|
if (!length) {
|
|
80
94
|
return allContenHashes;
|
|
81
95
|
}
|
|
96
|
+
|
|
82
97
|
let shortContentHashMap = {};
|
|
98
|
+
|
|
83
99
|
for (const locale of this.locales) {
|
|
84
100
|
shortContentHashMap[locale] = hashesWithLength(allContenHashes[locale], hashLength);
|
|
85
101
|
}
|
|
102
|
+
|
|
86
103
|
return shortContentHashMap;
|
|
87
104
|
}
|
|
105
|
+
|
|
88
106
|
getI18nChunkObject(mainChunk) {
|
|
89
107
|
const obj = {};
|
|
108
|
+
|
|
90
109
|
for (const chunk of mainChunk.getAllAsyncChunks()) {
|
|
91
110
|
if (_I18nKeysIdentifer.default.isChunkHasI18n(chunk)) {
|
|
92
111
|
obj[chunk.id] = 1;
|
|
93
112
|
}
|
|
94
113
|
}
|
|
114
|
+
|
|
95
115
|
return obj;
|
|
96
116
|
}
|
|
117
|
+
|
|
97
118
|
addDownloadLogicOfI18nInMainTemplate(mainTemplate) {
|
|
98
119
|
mainTemplate.hooks.localVars.tap(pluginName, (source, mainChunk) => {
|
|
99
120
|
const chunkMap = this.getI18nChunkObject(mainChunk);
|
|
121
|
+
|
|
100
122
|
if (!Object.keys(chunkMap).length) {
|
|
101
123
|
return source;
|
|
102
124
|
}
|
|
125
|
+
|
|
103
126
|
return _webpack.Template.asString([source, '', '// object to store loaded I18N chunks', 'var installedI18nChunks = {', _webpack.Template.indent(mainChunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};']);
|
|
104
127
|
});
|
|
105
128
|
mainTemplate.hooks.requireEnsure.tap(pluginName, (source, mainChunk, hash) => {
|
|
106
|
-
/**
|
|
107
|
-
* for Information this is tapped in mainTemplate ,
|
|
108
|
-
* So this hooks argument chunk is main chunk means entry chunk mostly.
|
|
109
|
-
* if any chunk has i18n then we must write our download i18n logic,
|
|
129
|
+
/**
|
|
130
|
+
* for Information this is tapped in mainTemplate ,
|
|
131
|
+
* So this hooks argument chunk is main chunk means entry chunk mostly.
|
|
132
|
+
* if any chunk has i18n then we must write our download i18n logic,
|
|
110
133
|
*/
|
|
111
134
|
const chunkMap = this.getI18nChunkObject(mainChunk);
|
|
135
|
+
|
|
112
136
|
if (!Object.keys(chunkMap).length) {
|
|
113
137
|
return source;
|
|
114
138
|
}
|
|
115
|
-
/**
|
|
116
|
-
* chunkMaps has
|
|
117
|
-
* @property {Object} hash [it has key as chunk id and value as chunkHash ]
|
|
118
|
-
* @property {Object} name [it has key as chunk id and value as chunk name ]
|
|
139
|
+
/**
|
|
140
|
+
* chunkMaps has
|
|
141
|
+
* @property {Object} hash [it has key as chunk id and value as chunkHash ]
|
|
142
|
+
* @property {Object} name [it has key as chunk id and value as chunk name ]
|
|
119
143
|
*/
|
|
144
|
+
|
|
145
|
+
|
|
120
146
|
const chunkMaps = mainChunk.getChunkMaps();
|
|
121
147
|
const {
|
|
122
148
|
crossOriginLoading
|
|
@@ -125,18 +151,19 @@ class I18nDownlodLogic {
|
|
|
125
151
|
filenameTemplate,
|
|
126
152
|
localeVarName = 'document.documentElement.lang'
|
|
127
153
|
} = this.options;
|
|
128
|
-
const i18nSrcPath = mainTemplate.getAssetPath(JSON.stringify(filenameTemplate).replace(/\[locale\]/gi, '"+ locale +"'),
|
|
129
|
-
// "i18n-chunk/[locale]/[name].[chunkhash].js"
|
|
154
|
+
const i18nSrcPath = mainTemplate.getAssetPath(JSON.stringify(filenameTemplate).replace(/\[locale\]/gi, '"+ locale +"'), // "i18n-chunk/[locale]/[name].[chunkhash].js"
|
|
130
155
|
{
|
|
131
156
|
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
|
132
157
|
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
|
133
158
|
chunk: {
|
|
134
159
|
id: '" + chunkId + "',
|
|
135
160
|
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
|
161
|
+
|
|
136
162
|
hashWithLength(length) {
|
|
137
163
|
const shortChunkHashMap = hashesWithLength(chunkMaps.hash, length);
|
|
138
164
|
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
|
139
165
|
},
|
|
166
|
+
|
|
140
167
|
// contentHash: contentHashMap,
|
|
141
168
|
// contentHashWithLength: contentHashLengthMap,
|
|
142
169
|
contentHash: {
|
|
@@ -149,31 +176,33 @@ class I18nDownlodLogic {
|
|
|
149
176
|
},
|
|
150
177
|
contentHashType: MODULE_TYPE
|
|
151
178
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* my suggestion is make ajax or fetch request
|
|
179
|
+
/** IDEA:
|
|
180
|
+
* as my suggestion ignore this `jsop` approch,
|
|
181
|
+
* Because json parse is faster then js parse.
|
|
182
|
+
* my suggestion is make ajax or fetch request
|
|
157
183
|
*/
|
|
158
184
|
|
|
159
185
|
const buf = [];
|
|
160
|
-
/*
|
|
161
|
-
if (REGEXP_HASH.test(filenameTemplate)) {
|
|
162
|
-
buf.push(
|
|
163
|
-
`var hash = ${mainTemplate.renderCurrentHashCode(hash)};`
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
if (REGEXP_CHUNKHASH.test(filenameTemplate)) {
|
|
167
|
-
buf.push(`var chunkHashes = ${JSON.stringify(chunkMaps.hash)};`);
|
|
168
|
-
}
|
|
186
|
+
/*
|
|
187
|
+
if (REGEXP_HASH.test(filenameTemplate)) {
|
|
188
|
+
buf.push(
|
|
189
|
+
`var hash = ${mainTemplate.renderCurrentHashCode(hash)};`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
if (REGEXP_CHUNKHASH.test(filenameTemplate)) {
|
|
193
|
+
buf.push(`var chunkHashes = ${JSON.stringify(chunkMaps.hash)};`);
|
|
194
|
+
}
|
|
169
195
|
*/
|
|
196
|
+
|
|
170
197
|
if ((0, _hashUtils.hasContentHash)(filenameTemplate)) {
|
|
171
198
|
const hashLength = getContentHashMaxLength(filenameTemplate);
|
|
172
199
|
const contentHashes = this.getShortContentHashes(mainChunk, hashLength);
|
|
173
200
|
buf.push(_webpack.Template.asString(['// all i18n files contentHash ', `var i18nContentHashes = ${JSON.stringify(contentHashes)};`, '', 'if (!i18nContentHashes[locale]) {', ' console.warn("this locale is "+locale + " not has support")', ' return;', '}', 'if (!i18nContentHashes[locale][chunkId]) {', ' console.warn("this chunkId is " + chunkId + " does not have \'"+locale+"\' locale chunk")', ' return;', '}']));
|
|
174
201
|
buf.push('var contentHash = i18nContentHashes[locale][chunkId]');
|
|
175
202
|
}
|
|
203
|
+
|
|
176
204
|
const hashUtils = _webpack.Template.asString(buf);
|
|
205
|
+
|
|
177
206
|
const publicPath = this.publicPath ? JSON.stringify(this.publicPath) : `${mainTemplate.requireFn}.p`;
|
|
178
207
|
return _webpack.Template.asString([source, `
|
|
179
208
|
(function() {
|
|
@@ -187,8 +216,7 @@ class I18nDownlodLogic {
|
|
|
187
216
|
} else if(installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {
|
|
188
217
|
promises.push(installedI18nChunks[chunkId] = new Promise(function(resolve, reject) {
|
|
189
218
|
var srcPath = (${i18nSrcPath});
|
|
190
|
-
${''
|
|
191
|
-
// TODO: I think this is the area for download chunk of i18n we can
|
|
219
|
+
${'' // TODO: I think this is the area for download chunk of i18n we can
|
|
192
220
|
// change mainTemplate.requireFn as our cdn server urls !!!
|
|
193
221
|
// and we can change the i18n download logic here
|
|
194
222
|
}
|
|
@@ -223,6 +251,7 @@ class I18nDownlodLogic {
|
|
|
223
251
|
})()`]);
|
|
224
252
|
});
|
|
225
253
|
}
|
|
254
|
+
|
|
226
255
|
apply(compiler) {
|
|
227
256
|
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
228
257
|
const {
|
|
@@ -231,5 +260,7 @@ class I18nDownlodLogic {
|
|
|
231
260
|
this.addDownloadLogicOfI18nInMainTemplate(mainTemplate);
|
|
232
261
|
});
|
|
233
262
|
}
|
|
263
|
+
|
|
234
264
|
}
|
|
265
|
+
|
|
235
266
|
exports.default = I18nDownlodLogic;
|
|
@@ -4,19 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
7
8
|
var _webpackSources = require("webpack-sources");
|
|
9
|
+
|
|
8
10
|
var _utils = require("./utils");
|
|
11
|
+
|
|
9
12
|
var _getI18nKeysFormModules = _interopRequireDefault(require("./utils/getI18nKeysFormModules"));
|
|
13
|
+
|
|
10
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
/**
|
|
12
|
-
* this plugin was creating the chunk specific i18n chunk's.
|
|
13
|
-
*/
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* this plugin was creating the chunk specific i18n chunk's.
|
|
18
|
+
*/
|
|
15
19
|
// this plugin's kick starter is apply method
|
|
16
|
-
|
|
17
20
|
const pluginName = 'I18nFilesEmitter';
|
|
18
21
|
const MODULE_TYPE = 'json/i18n';
|
|
22
|
+
|
|
19
23
|
const i18ntype = locale => `${MODULE_TYPE}/${locale}`;
|
|
24
|
+
|
|
20
25
|
class I18nFilesEmitter {
|
|
21
26
|
constructor({
|
|
22
27
|
allI18nObject,
|
|
@@ -27,12 +32,13 @@ class I18nFilesEmitter {
|
|
|
27
32
|
}) {
|
|
28
33
|
this.locales = locales;
|
|
29
34
|
this.allI18nObject = allI18nObject;
|
|
30
|
-
this.filenameTemplate = filenameTemplate;
|
|
31
|
-
|
|
35
|
+
this.filenameTemplate = filenameTemplate; // this.filenameTemplate = "i18n-chunk/[locale]/[name].js"
|
|
36
|
+
|
|
32
37
|
this.jsonpFunc = jsonpFunc;
|
|
33
38
|
this.prevHashes = {};
|
|
34
39
|
this.i18nManifestFileName = i18nManifestFileName;
|
|
35
40
|
}
|
|
41
|
+
|
|
36
42
|
emitAsset(compilation, filename, source, info) {
|
|
37
43
|
// NOTE: info support available since webpack v4.40.0 https://webpack.js.org/api/stats/#asset-objects
|
|
38
44
|
if (!compilation.emitAsset) {
|
|
@@ -40,9 +46,9 @@ class I18nFilesEmitter {
|
|
|
40
46
|
} else {
|
|
41
47
|
compilation.emitAsset(filename, source, info);
|
|
42
48
|
}
|
|
43
|
-
}
|
|
49
|
+
} // this method for create object and assign value for i18nkeys
|
|
50
|
+
|
|
44
51
|
|
|
45
|
-
// this method for create object and assign value for i18nkeys
|
|
46
52
|
getI18nObjectByLocale(i18nKeys, locale) {
|
|
47
53
|
const data = {};
|
|
48
54
|
i18nKeys.forEach(key => {
|
|
@@ -50,10 +56,10 @@ class I18nFilesEmitter {
|
|
|
50
56
|
});
|
|
51
57
|
return data;
|
|
52
58
|
}
|
|
59
|
+
|
|
53
60
|
getTemplateString(i18nKeys, locale) {
|
|
54
61
|
let i18nObject = this.getI18nObjectByLocale(i18nKeys, locale);
|
|
55
|
-
return `${this.jsonpFunc}(${(0, _utils.jsonToString)(i18nObject)});`;
|
|
56
|
-
// return `${this.jsonpFunc}(JSON.parse(${JSON.stringify(jsonToString(i18nObject))}));`;
|
|
62
|
+
return `${this.jsonpFunc}(${(0, _utils.jsonToString)(i18nObject)});`; // return `${this.jsonpFunc}(JSON.parse(${JSON.stringify(jsonToString(i18nObject))}));`;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
renderI18nLocaleChunk(chunk, locale, i18nKeys) {
|
|
@@ -71,6 +77,7 @@ class I18nFilesEmitter {
|
|
|
71
77
|
hash: chunk.contentHash[i18ntype(locale)]
|
|
72
78
|
};
|
|
73
79
|
}
|
|
80
|
+
|
|
74
81
|
emitI18nFilesForChunk(chunk, compilation) {
|
|
75
82
|
const i18nKeys = (0, _getI18nKeysFormModules.default)(chunk.modulesIterable);
|
|
76
83
|
const manifestForChunk = {
|
|
@@ -78,12 +85,14 @@ class I18nFilesEmitter {
|
|
|
78
85
|
hasI18n: false,
|
|
79
86
|
hasChanges: false
|
|
80
87
|
};
|
|
88
|
+
|
|
81
89
|
if (!i18nKeys.length) {
|
|
82
90
|
// why it is not checked as 0
|
|
83
91
|
return manifestForChunk;
|
|
84
92
|
}
|
|
85
|
-
|
|
86
|
-
// const locales = ['en_US'];
|
|
93
|
+
|
|
94
|
+
manifestForChunk.hasI18n = true; // const locales = ['en_US'];
|
|
95
|
+
|
|
87
96
|
this.locales.forEach(locale => {
|
|
88
97
|
const result = this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation);
|
|
89
98
|
const {
|
|
@@ -95,31 +104,34 @@ class I18nFilesEmitter {
|
|
|
95
104
|
} = result;
|
|
96
105
|
const filePath = compilation.getPath(filenameTemplate, pathOptions);
|
|
97
106
|
manifestForChunk.assets[locale] = filePath;
|
|
107
|
+
|
|
98
108
|
if (this.prevHashes[identifier] === hash) {
|
|
99
109
|
return;
|
|
100
110
|
}
|
|
111
|
+
|
|
101
112
|
manifestForChunk.hasChanges = true;
|
|
102
113
|
this.prevHashes[identifier] = hash;
|
|
103
114
|
this.emitAsset(compilation, filePath, render(), {
|
|
104
115
|
locale,
|
|
105
116
|
chunkId: chunk.id,
|
|
106
117
|
chunkName: chunk.name
|
|
107
|
-
});
|
|
108
|
-
// compilation.assets[filePath] = render();
|
|
118
|
+
}); // compilation.assets[filePath] = render();
|
|
109
119
|
});
|
|
110
|
-
|
|
111
120
|
return manifestForChunk;
|
|
112
121
|
}
|
|
122
|
+
|
|
113
123
|
emitI18nAssert(compilation) {
|
|
114
124
|
let manifest = {};
|
|
115
125
|
let needEmitManifest = false;
|
|
116
126
|
compilation.chunks.forEach(chunk => {
|
|
117
127
|
const manifestForChunk = this.emitI18nFilesForChunk(chunk, compilation);
|
|
128
|
+
|
|
118
129
|
if (manifestForChunk.hasI18n) {
|
|
119
130
|
manifest[chunk.id] = manifestForChunk.assets;
|
|
120
131
|
needEmitManifest = needEmitManifest || manifestForChunk.hasChanges;
|
|
121
132
|
}
|
|
122
133
|
});
|
|
134
|
+
|
|
123
135
|
if (needEmitManifest) {
|
|
124
136
|
const manifestSource = new _webpackSources.RawSource(JSON.stringify(manifest));
|
|
125
137
|
this.emitAsset(compilation, this.i18nManifestFileName, manifestSource, {
|
|
@@ -127,42 +139,45 @@ class I18nFilesEmitter {
|
|
|
127
139
|
});
|
|
128
140
|
}
|
|
129
141
|
}
|
|
142
|
+
|
|
130
143
|
apply(compiler) {
|
|
131
|
-
/*
|
|
132
|
-
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
133
|
-
compilation.mainTemplate.hooks.renderManifest.tap(
|
|
134
|
-
pluginName,
|
|
135
|
-
(result, { chunk }) => {
|
|
136
|
-
this.renderChunk(result, compilation, chunk);
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
pluginName,
|
|
141
|
-
(result, { chunk }) => {
|
|
142
|
-
this.renderChunk(result, compilation, chunk);
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
});
|
|
144
|
+
/*
|
|
145
|
+
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
146
|
+
compilation.mainTemplate.hooks.renderManifest.tap(
|
|
147
|
+
pluginName,
|
|
148
|
+
(result, { chunk }) => {
|
|
149
|
+
this.renderChunk(result, compilation, chunk);
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
compilation.chunkTemplate.hooks.renderManifest.tap(
|
|
153
|
+
pluginName,
|
|
154
|
+
(result, { chunk }) => {
|
|
155
|
+
this.renderChunk(result, compilation, chunk);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
});
|
|
146
159
|
*/
|
|
147
160
|
// this below hook was tapped for create asssets(file) for chunk specific i18nChunk Files
|
|
148
161
|
compiler.hooks.emit.tap(pluginName, compilation => {
|
|
149
162
|
this.emitI18nAssert(compilation);
|
|
150
163
|
});
|
|
151
164
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
165
|
+
/*
|
|
166
|
+
renderChunk(result, compilation, chunk) {
|
|
167
|
+
const i18nKeys = getI18nKeysFormModules(chunk.modulesIterable);
|
|
168
|
+
// TODO: need to discuss with vimal ji can we chose this place for add i18n locale files ????
|
|
169
|
+
// IDEA: we chose this place for add i18n locale files ????
|
|
170
|
+
if (i18nKeys.length > 0) {
|
|
171
|
+
Object.keys(this.allI18nObject).forEach(locale => {
|
|
172
|
+
result.push(
|
|
173
|
+
this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation)
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
166
178
|
*/
|
|
179
|
+
|
|
180
|
+
|
|
167
181
|
}
|
|
182
|
+
|
|
168
183
|
exports.default = I18nFilesEmitter;
|
|
@@ -4,37 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
7
8
|
var _utils = require("./utils");
|
|
9
|
+
|
|
8
10
|
var _I18nDependency = require("./I18nDependency");
|
|
11
|
+
|
|
9
12
|
var _NullFactory = _interopRequireDefault(require("webpack/lib/NullFactory"));
|
|
13
|
+
|
|
10
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
const pluginName = 'I18nKeysIdentifer';
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
16
|
+
const pluginName = 'I18nKeysIdentifer';
|
|
17
|
+
/**
|
|
18
|
+
* this plugin search the i18 keys and make it as I18nDependency.
|
|
19
|
+
* how it works?
|
|
20
|
+
* this plugin get jsResourceI18nKeys in constructor.
|
|
21
|
+
* we walk throught the js files AST
|
|
22
|
+
* if any string literal in that AST is in jsResourceI18nKeys then we consider that string as I18n key
|
|
23
|
+
* after the walk of AST we get some I18n keys
|
|
24
|
+
* then we make it as I18nDependency.
|
|
21
25
|
*/
|
|
26
|
+
|
|
22
27
|
class I18nKeysIdentifer {
|
|
23
28
|
constructor(jsResourceI18nKeys) {
|
|
24
29
|
this.jsResourceI18nKeys = jsResourceI18nKeys;
|
|
25
30
|
}
|
|
31
|
+
|
|
26
32
|
defineConfigarationForI18nDependency(compilation) {
|
|
27
33
|
compilation.dependencyFactories.set(_I18nDependency.I18nDependency, new _NullFactory.default());
|
|
28
34
|
compilation.dependencyTemplates.set(_I18nDependency.I18nDependency, new _I18nDependency.I18nDependencyTemplate());
|
|
29
35
|
}
|
|
36
|
+
|
|
30
37
|
addI18nDependency(module, i18nKeys) {
|
|
31
38
|
const identifier = `i18n ${module.resource}`;
|
|
32
39
|
const dep = new _I18nDependency.I18nDependency({
|
|
33
40
|
identifier,
|
|
34
41
|
i18nKeys
|
|
35
42
|
}, module.context, 0);
|
|
36
|
-
module.addDependency(dep);
|
|
37
|
-
// console.log('module', i18nKeys, identifier);
|
|
43
|
+
module.addDependency(dep); // console.log('module', i18nKeys, identifier);
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
apply(compiler) {
|
|
@@ -42,23 +48,23 @@ class I18nKeysIdentifer {
|
|
|
42
48
|
// this below hook was tapped for we use I18nDependency
|
|
43
49
|
// so we must define module factory for I18nDependency
|
|
44
50
|
// and we must define how it import statement look like I18nDependencyTemplate
|
|
45
|
-
this.defineConfigarationForI18nDependency(compilation);
|
|
51
|
+
this.defineConfigarationForI18nDependency(compilation); // handler for parser
|
|
46
52
|
|
|
47
|
-
// handler for parser
|
|
48
53
|
let handler = parser => {
|
|
49
54
|
parser.hooks.program.tap(pluginName, (ast, commmets) => {
|
|
50
55
|
const {
|
|
51
56
|
module
|
|
52
|
-
} = parser.state;
|
|
53
|
-
|
|
57
|
+
} = parser.state; //
|
|
58
|
+
|
|
54
59
|
if (!(module && /\.jsx?$/.test(module.resource))) {
|
|
55
60
|
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
61
|
+
} // i18n grep proper contract regex
|
|
62
|
+
|
|
63
|
+
|
|
58
64
|
let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
|
|
59
|
-
i18nKeys = i18nKeys.concat(
|
|
60
|
-
// i18n grep proper contract regex
|
|
65
|
+
i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
|
|
61
66
|
(0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
|
|
67
|
+
|
|
62
68
|
if (i18nKeys.length) {
|
|
63
69
|
// console.log(
|
|
64
70
|
// 'i18nKeys.length',
|
|
@@ -68,17 +74,19 @@ class I18nKeysIdentifer {
|
|
|
68
74
|
this.addI18nDependency(module, i18nKeys);
|
|
69
75
|
}
|
|
70
76
|
});
|
|
71
|
-
};
|
|
77
|
+
}; // this below hook was tapped for collect I18n Key from files and add as Deppenensy
|
|
72
78
|
|
|
73
|
-
// this below hook was tapped for collect I18n Key from files and add as Deppenensy
|
|
74
79
|
|
|
75
80
|
const factory = params.normalModuleFactory;
|
|
76
81
|
factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
|
|
77
82
|
factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
|
|
78
83
|
});
|
|
79
84
|
}
|
|
85
|
+
|
|
80
86
|
}
|
|
87
|
+
|
|
81
88
|
exports.default = I18nKeysIdentifer;
|
|
89
|
+
|
|
82
90
|
I18nKeysIdentifer.isChunkHasI18n = function (chunk) {
|
|
83
91
|
for (const module of chunk.modulesIterable) {
|
|
84
92
|
for (const dep of module.dependencies) {
|
|
@@ -87,5 +95,6 @@ I18nKeysIdentifer.isChunkHasI18n = function (chunk) {
|
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
}
|
|
98
|
+
|
|
90
99
|
return false;
|
|
91
100
|
};
|