@zohodesk/react-cli 0.0.1-beta.99 → 0.0.1-betaa.138.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 +183 -183
- package/CHANGELOG.md +5 -0
- package/README.md +636 -491
- package/bin/cli.js +372 -367
- package/files/eslintrc.js +57 -0
- package/files/prettierrc.js +3 -0
- package/lib/babel/cmjs-plugins-presets.js +16 -9
- package/lib/babel/es-plugins-presets.js +26 -14
- package/lib/common/getEntries.js +31 -22
- package/lib/common/getPublicPathConfig.js +27 -13
- package/lib/common/index.js +21 -25
- package/lib/common/splitChunks.js +62 -53
- package/lib/common/templateParameters.js +10 -8
- package/lib/configs/jest.config.js +15 -25
- package/lib/configs/webpack.component.umd.config.js +31 -37
- package/lib/configs/webpack.css.umd.config.js +44 -47
- package/lib/configs/webpack.dev.config.js +70 -52
- package/lib/configs/webpack.docs.config.js +106 -106
- package/lib/configs/webpack.prod.config.js +95 -75
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +103 -74
- package/lib/jest/coverageCollector.js +41 -21
- package/lib/jest/jsonMaker.js +15 -16
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
- package/lib/jest/preProcessors/jsPreprocessor.js +3 -5
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
- package/lib/jest/result.js +90 -45
- package/lib/jest/run.js +43 -43
- package/lib/jest/setup.js +102 -95
- package/lib/loaderUtils/getCSSLoaders.js +21 -22
- package/lib/loaderUtils/getDevJsLoaders.js +25 -23
- package/lib/loaderUtils/index.js +11 -13
- package/lib/loaders/docsLoader.js +15 -15
- package/lib/loaders/docsPropsLoader.js +14 -17
- package/lib/loaders/fileLoader.js +33 -35
- package/lib/loaders/scriptInstrumentLoader.js +21 -20
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +54 -45
- package/lib/middlewares/SSTMiddleware.js +8 -5
- package/lib/pluginUtils/getDevPlugins.js +114 -52
- package/lib/pluginUtils/getDocsPlugins.js +25 -29
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +163 -74
- package/lib/pluginUtils/getServerPlugins.js +8 -11
- package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
- package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
- package/lib/pluginUtils/index.js +36 -43
- package/lib/plugins/CdnChangePlugin.js +63 -0
- package/lib/plugins/CleanupStatsPlugin.js +18 -32
- package/lib/plugins/CustomAttributePlugin.js +79 -0
- package/lib/plugins/CustomAttributePlugin.md +35 -0
- package/lib/plugins/EFCPlugin.js +185 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +118 -52
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
- package/lib/plugins/I18nSplitPlugin/README.md +25 -0
- package/lib/plugins/I18nSplitPlugin/index.js +185 -0
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
- package/lib/plugins/ManifestPlugin.js +52 -63
- package/lib/plugins/ModuleStatsPlugin.js +83 -173
- package/lib/plugins/OptimizeJSPlugin.js +24 -41
- package/lib/plugins/PublicPathCallbackPlugin.js +42 -116
- package/lib/plugins/PublicPathChangePlugin.js +175 -284
- package/lib/plugins/ReportGeneratePlugin.js +150 -151
- package/lib/plugins/ResourceHintsPlugin.js +53 -35
- package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
- package/lib/plugins/ServiceWorkerPlugin.js +81 -57
- package/lib/plugins/ShadowDOMSupportPlugin.js +153 -234
- package/lib/plugins/SourceMapHookPlugin.js +21 -33
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +23 -30
- package/lib/plugins/UnusedFilesFindPlugin.js +137 -152
- package/lib/plugins/index.js +100 -91
- package/lib/plugins/webpackwatchrunplugin.js +18 -30
- package/lib/postcss-plugins/ExcludeRTLPlugin.js +14 -17
- package/lib/schemas/index.js +336 -81
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +84 -91
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/impactServer.js +99 -92
- package/lib/servers/mockserver.js +24 -24
- package/lib/servers/scrServer.js +78 -98
- package/lib/servers/server.js +101 -122
- package/lib/servers/ssServer.js +63 -61
- package/lib/sh/pre-commit.sh +34 -34
- package/lib/sh/reportPublish.sh +45 -46
- package/lib/templates/CoverageScriptTemplate.js +45 -18
- package/lib/templates/WMSTemplate.js +17 -18
- package/lib/templates/linterConstant.js +6 -4
- package/lib/utils/babelPresets.js +12 -5
- package/lib/utils/buildstats.html +148 -148
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +12 -34
- package/lib/utils/copyTimezones.js +9 -16
- package/lib/utils/createEventStream.js +24 -19
- package/lib/utils/cssClassNameGenerate.js +44 -73
- package/lib/utils/cssURLReplacer.js +60 -54
- package/lib/utils/dependencyPostPublish.js +20 -19
- package/lib/utils/fileUtils.js +66 -54
- package/lib/utils/folderIterator.js +20 -21
- package/lib/utils/getComponents.js +70 -27
- package/lib/utils/getCurrentBranch.js +11 -17
- package/lib/utils/getDependenciesImpactList.js +114 -187
- package/lib/utils/getHash.js +9 -13
- package/lib/utils/getIp.js +9 -9
- package/lib/utils/getOptions.js +26 -29
- package/lib/utils/getServerURL.js +19 -10
- package/lib/utils/index.js +147 -126
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +40 -32
- package/lib/utils/jsonHelper.js +37 -21
- package/lib/utils/lint/addScripts.js +27 -0
- package/lib/utils/lint/checkExistingConfig.js +67 -0
- package/lib/utils/lint/copyConfigs.js +24 -0
- package/lib/utils/lint/index.js +54 -0
- package/lib/utils/lint/lintScripts.js +11 -0
- package/lib/utils/lint/lintSetup.js +31 -0
- package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
- package/lib/utils/lint/question.js +30 -0
- package/lib/utils/lintReporter.js +70 -56
- package/lib/utils/mailSender.js +12 -27
- package/lib/utils/pullOrigin.js +21 -18
- package/lib/utils/reinstallDependencies.js +76 -85
- package/lib/utils/removeAttributes.js +25 -23
- package/lib/utils/repoClone.js +47 -45
- package/lib/utils/request.js +64 -77
- package/lib/utils/resultSchema.json +73 -73
- package/lib/utils/rtl.js +22 -29
- package/lib/utils/setEnvVariables.js +5 -6
- package/lib/utils/ssTestHack.js +21 -19
- package/lib/utils/switchBranch.js +21 -20
- package/lib/utils/urlConcat.js +22 -0
- package/package.json +141 -136
- 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/index.html +1493 -1493
- 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
|
@@ -1,75 +1,141 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var
|
|
8
|
+
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _utils = require("../utils");
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _urlConcat = require("../utils/urlConcat");
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
15
|
|
|
15
|
-
var _webpackSources = require(
|
|
16
|
+
var _webpackSources = require("webpack-sources");
|
|
17
|
+
|
|
18
|
+
var _hashUtils = require("./I18nSplitPlugin/utils/hashUtils");
|
|
19
|
+
|
|
20
|
+
var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
|
|
16
21
|
|
|
17
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
let i18nObj = null;
|
|
25
|
+
let options = (0, _utils.getOptions)();
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
function newAssign(target, data) {
|
|
28
|
+
return Object.assign({}, target, data);
|
|
29
|
+
}
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
const {
|
|
32
|
+
i18n
|
|
33
|
+
} = options;
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
class I18NInjectIntoIndexPlugin {
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.isDevelopment = options.isDevelopment;
|
|
38
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate;
|
|
28
39
|
this.publicPath = options.publicPath;
|
|
40
|
+
this.templateLabel = options.templateLabel || '{{--user-locale}}';
|
|
41
|
+
this.i18nManifestFileName = options.i18nManifestFileName;
|
|
42
|
+
this.entryPointName = options.mainChunkName;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getI18nFileUrlPath(chunk, compilation) {
|
|
46
|
+
let urlpath = (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, this.templateLabel);
|
|
47
|
+
return (0, _urlConcat.urlConcat)(this.publicPath, urlpath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getI18nManifest(compilation) {
|
|
51
|
+
const i18nManifestFile = compilation.assets[this.i18nManifestFileName];
|
|
52
|
+
|
|
53
|
+
if (!i18nManifestFile) {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const manifest = JSON.parse(i18nManifestFile.source());
|
|
58
|
+
return manifest;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
injectI18nURLsToHTML(compilation) {
|
|
62
|
+
_htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
|
|
63
|
+
const {
|
|
64
|
+
assets
|
|
65
|
+
} = data; // Manipulate the content
|
|
66
|
+
|
|
67
|
+
const i18nManifest = this.getI18nManifest(compilation);
|
|
68
|
+
const entryPoint = compilation.entrypoints.get(this.entryPointName);
|
|
69
|
+
const i18nScriptURLs = entryPoint.chunks.filter(c => !!i18nManifest[c.id]).map(c => this.getI18nFileUrlPath(c, compilation)); // .map(url => getI18nScriptTagObj(url));
|
|
70
|
+
// .join('');
|
|
71
|
+
// Tell webpack to move on
|
|
72
|
+
|
|
73
|
+
cb(null, newAssign(data, {
|
|
74
|
+
assets: newAssign(assets, {
|
|
75
|
+
js: i18nScriptURLs.concat(assets.js)
|
|
76
|
+
})
|
|
77
|
+
}));
|
|
78
|
+
});
|
|
29
79
|
}
|
|
30
80
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} else {
|
|
49
|
-
res[splittedFileName[0]] = fileName;
|
|
50
|
-
}
|
|
51
|
-
return res;
|
|
52
|
-
}, {});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var _Object$keys$filter = Object.keys(compilation.assets).filter(function (filename) {
|
|
56
|
-
return (/\.html$/g.test(filename)
|
|
57
|
-
);
|
|
58
|
-
}),
|
|
59
|
-
_Object$keys$filter2 = _slicedToArray(_Object$keys$filter, 1),
|
|
60
|
-
indexFile = _Object$keys$filter2[0];
|
|
61
|
-
|
|
62
|
-
if (indexFile) {
|
|
63
|
-
var source = compilation.assets[indexFile].source();
|
|
64
|
-
compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), function (match, arg) {
|
|
65
|
-
return match.replace(arg, JSON.stringify(i18nObj));
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
81
|
+
withI18nSpitHandling(compiler) {
|
|
82
|
+
compiler.hooks.make.tap('I18NInjectIntoIndexPlugin', compilation => {
|
|
83
|
+
// let cdns = Object.keys(this.publicPaths);
|
|
84
|
+
// console.log('compilation.assets', Object.keys(compilation.assets).filter(a => a.includes('i18n')));
|
|
85
|
+
if (!(0, _hashUtils.hasContentHash)(this.i18nFileNameTemplate)) {
|
|
86
|
+
this.injectI18nURLsToHTML(compilation);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
_htmlWebpackPlugin.default.getHooks(compilation).beforeEmit.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
|
|
91
|
+
// Manipulate the content
|
|
92
|
+
const i18nManifest = this.getI18nManifest(compilation);
|
|
93
|
+
const entryPoint = compilation.entrypoints.get(this.entryPointName);
|
|
94
|
+
let i18nAssets = (0, _hashUtils.getShortI18nAssets)(entryPoint.chunks, i18nManifest, this.publicPath);
|
|
95
|
+
data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets))); // Tell webpack to move on
|
|
96
|
+
|
|
97
|
+
cb(null, data);
|
|
68
98
|
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
apply(compiler) {
|
|
103
|
+
if (i18n.chunkSplitEnable) {
|
|
104
|
+
this.withI18nSpitHandling(compiler);
|
|
105
|
+
} else {
|
|
106
|
+
this.withoutI18nSpitHandling(compiler);
|
|
69
107
|
}
|
|
70
|
-
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
withoutI18nSpitHandling(compiler) {
|
|
111
|
+
compiler.hooks.emit.tap('I18NInjectIntoIndexPlugin', compilation => {
|
|
112
|
+
// let cdns = Object.keys(this.publicPaths);
|
|
113
|
+
if (i18nObj === null) {
|
|
114
|
+
let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
|
115
|
+
|
|
116
|
+
i18nObj = i18nFiles.reduce((res, next) => {
|
|
117
|
+
let fileName = next.replace(`i18n${_path.default.sep}`, '');
|
|
118
|
+
let splittedFileName = fileName.split('.');
|
|
119
|
+
/* if (this.isDevelopment) {
|
|
120
|
+
res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
|
|
121
|
+
} else {
|
|
122
|
+
res[splittedFileName[0]] = fileName;
|
|
123
|
+
} */
|
|
124
|
+
|
|
125
|
+
res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
|
|
126
|
+
return res;
|
|
127
|
+
}, {});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let [indexFile] = Object.keys(compilation.assets).filter(filename => /\.html$/g.test(filename));
|
|
131
|
+
|
|
132
|
+
if (indexFile) {
|
|
133
|
+
let source = compilation.assets[indexFile].source();
|
|
134
|
+
compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nObj))));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
71
138
|
|
|
72
|
-
|
|
73
|
-
}();
|
|
139
|
+
}
|
|
74
140
|
|
|
75
141
|
exports.default = I18NInjectIntoIndexPlugin;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
|
|
10
|
+
const pluginName = 'I18nDebugPlugin'; // this plugin only for debug related purpose
|
|
11
|
+
|
|
12
|
+
class I18nDebugPlugin {
|
|
13
|
+
constructor(jsResourceI18nKeys) {
|
|
14
|
+
this.jsResourceI18nKeys = jsResourceI18nKeys;
|
|
15
|
+
this.warnings = [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply(compiler) {
|
|
19
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation, compilationParams) => {
|
|
20
|
+
// TEMP : only for debugging purpose
|
|
21
|
+
this.compilation1 = compilation;
|
|
22
|
+
this.compilationParams = compilationParams.normalModuleFactory;
|
|
23
|
+
});
|
|
24
|
+
compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
|
|
25
|
+
if (!this.compilationParams || this.compilationParams.normalModuleFactory === factory) {
|
|
26
|
+
return;
|
|
27
|
+
} // console.log('skiped');
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
let handler = parser => {
|
|
31
|
+
parser.hooks.program.tap(pluginName, (ast, commmets) => {
|
|
32
|
+
const {
|
|
33
|
+
module
|
|
34
|
+
} = parser.state; //
|
|
35
|
+
|
|
36
|
+
if (!(module && /\.jsx?$/.test(module.resource))) {
|
|
37
|
+
return;
|
|
38
|
+
} // i18n grep proper contract regex
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
|
|
42
|
+
i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
|
|
43
|
+
(0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
|
|
44
|
+
i18nKeys.length && this.warnings.push({
|
|
45
|
+
message: 'skiped i18n keys',
|
|
46
|
+
reason: 'may be some child compiler',
|
|
47
|
+
fileName: module.resource,
|
|
48
|
+
i18nKeys
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
|
|
54
|
+
factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler); // factory.hooks.parser.for('javascript/esm').tap(pluginName, handler);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.default = I18nDebugPlugin;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.I18nDependencyTemplate = exports.I18nDependency = void 0;
|
|
7
|
+
|
|
8
|
+
var _webpack = require("webpack");
|
|
9
|
+
|
|
10
|
+
// const webpack = require('webpack');
|
|
11
|
+
class I18nDependency extends _webpack.Dependency {
|
|
12
|
+
constructor({
|
|
13
|
+
identifier,
|
|
14
|
+
i18nKeys
|
|
15
|
+
}, context, identifierIndex) {
|
|
16
|
+
super();
|
|
17
|
+
this.identifier = identifier;
|
|
18
|
+
this.identifierIndex = identifierIndex;
|
|
19
|
+
this.i18nKeys = i18nKeys;
|
|
20
|
+
this.context = context;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getResourceIdentifier() {
|
|
24
|
+
return `i18n-module-${this.identifier}-${this.identifierIndex}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.I18nDependency = I18nDependency;
|
|
30
|
+
|
|
31
|
+
class I18nDependencyTemplate {
|
|
32
|
+
//eslint-disable-next-line no-empty-function
|
|
33
|
+
apply() {} // apply(dep, source) {
|
|
34
|
+
// if (typeof dep.range === "number") {
|
|
35
|
+
// source.insert(0, `/* comment by I18nSplitPlugin , i18n keys = ${JSON.stringify(dep.i18nKeys)} */`);
|
|
36
|
+
// return;
|
|
37
|
+
// }
|
|
38
|
+
// source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
|
|
39
|
+
// }
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
exports.I18nDependencyTemplate = I18nDependencyTemplate;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _webpack = require("webpack");
|
|
9
|
+
|
|
10
|
+
var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nKeysIdentifer"));
|
|
11
|
+
|
|
12
|
+
var _hashUtils = require("./utils/hashUtils");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
+
*/
|
|
34
|
+
// import { REGEXP_HASH, REGEXP_CHUNKHASH } from './utils/hashUtils';
|
|
35
|
+
const pluginName = 'DownloadLogicOfI18n'; // const pluginName = 'i18n-plugin';
|
|
36
|
+
|
|
37
|
+
const MODULE_TYPE = 'json/i18n';
|
|
38
|
+
|
|
39
|
+
const ltype = locale => `${MODULE_TYPE}/${locale}`;
|
|
40
|
+
|
|
41
|
+
function hashesWithLength(hashes, length) {
|
|
42
|
+
const shortChunkHashMap = {};
|
|
43
|
+
|
|
44
|
+
for (let key of Object.keys(hashes)) {
|
|
45
|
+
if (typeof hashes[key] === 'string') {
|
|
46
|
+
shortChunkHashMap[key] = hashes.slice(0, length);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return shortChunkHashMap;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getContentHashMaxLength(filenameTemplate) {
|
|
54
|
+
let length = 0;
|
|
55
|
+
let matches = filenameTemplate.match(_hashUtils.REGEXP_CONTENTHASH);
|
|
56
|
+
|
|
57
|
+
for (let match of matches) {
|
|
58
|
+
let tem = match.match(/\d+/);
|
|
59
|
+
|
|
60
|
+
if (tem) {
|
|
61
|
+
length = Math.max(parseInt(tem[0]), length);
|
|
62
|
+
} else {
|
|
63
|
+
length = 0;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return length;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class I18nDownlodLogic {
|
|
72
|
+
constructor({
|
|
73
|
+
filenameTemplate,
|
|
74
|
+
publicPath,
|
|
75
|
+
localeVarName = 'document.documentElement.lang',
|
|
76
|
+
locales
|
|
77
|
+
}) {
|
|
78
|
+
this.locales = locales;
|
|
79
|
+
this.publicPath = publicPath;
|
|
80
|
+
this.options = {
|
|
81
|
+
filenameTemplate,
|
|
82
|
+
localeVarName
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getShortContentHashes(chunk, hashLength) {
|
|
87
|
+
let allContenHashes = {};
|
|
88
|
+
const chunkMaps = chunk.getChunkMaps();
|
|
89
|
+
this.locales.forEach(locale => {
|
|
90
|
+
allContenHashes[locale] = chunkMaps.contentHash[ltype(locale)];
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (!length) {
|
|
94
|
+
return allContenHashes;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let shortContentHashMap = {};
|
|
98
|
+
|
|
99
|
+
for (const locale of this.locales) {
|
|
100
|
+
shortContentHashMap[locale] = hashesWithLength(allContenHashes[locale], hashLength);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return shortContentHashMap;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
getI18nChunkObject(mainChunk) {
|
|
107
|
+
const obj = {};
|
|
108
|
+
|
|
109
|
+
for (const chunk of mainChunk.getAllAsyncChunks()) {
|
|
110
|
+
if (_I18nKeysIdentifer.default.isChunkHasI18n(chunk)) {
|
|
111
|
+
obj[chunk.id] = 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return obj;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
addDownloadLogicOfI18nInMainTemplate(mainTemplate) {
|
|
119
|
+
mainTemplate.hooks.localVars.tap(pluginName, (source, mainChunk) => {
|
|
120
|
+
const chunkMap = this.getI18nChunkObject(mainChunk);
|
|
121
|
+
|
|
122
|
+
if (!Object.keys(chunkMap).length) {
|
|
123
|
+
return source;
|
|
124
|
+
}
|
|
125
|
+
|
|
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')), '};']);
|
|
127
|
+
});
|
|
128
|
+
mainTemplate.hooks.requireEnsure.tap(pluginName, (source, mainChunk, hash) => {
|
|
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,
|
|
133
|
+
*/
|
|
134
|
+
const chunkMap = this.getI18nChunkObject(mainChunk);
|
|
135
|
+
|
|
136
|
+
if (!Object.keys(chunkMap).length) {
|
|
137
|
+
return source;
|
|
138
|
+
}
|
|
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 ]
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
const chunkMaps = mainChunk.getChunkMaps();
|
|
147
|
+
const {
|
|
148
|
+
crossOriginLoading
|
|
149
|
+
} = mainTemplate.outputOptions;
|
|
150
|
+
const {
|
|
151
|
+
filenameTemplate,
|
|
152
|
+
localeVarName = 'document.documentElement.lang'
|
|
153
|
+
} = this.options;
|
|
154
|
+
const i18nSrcPath = mainTemplate.getAssetPath(JSON.stringify(filenameTemplate).replace(/\[locale\]/gi, '"+ locale +"'), // "i18n-chunk/[locale]/[name].[chunkhash].js"
|
|
155
|
+
{
|
|
156
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
|
157
|
+
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
|
158
|
+
chunk: {
|
|
159
|
+
id: '" + chunkId + "',
|
|
160
|
+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
|
161
|
+
|
|
162
|
+
hashWithLength(length) {
|
|
163
|
+
const shortChunkHashMap = hashesWithLength(chunkMaps.hash, length);
|
|
164
|
+
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
// contentHash: contentHashMap,
|
|
168
|
+
// contentHashWithLength: contentHashLengthMap,
|
|
169
|
+
contentHash: {
|
|
170
|
+
[MODULE_TYPE]: '" + contentHash + "'
|
|
171
|
+
},
|
|
172
|
+
contentHashWithLength: {
|
|
173
|
+
[MODULE_TYPE]: length => `" + contentHash.slice(0,${length}) + "`
|
|
174
|
+
},
|
|
175
|
+
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
|
176
|
+
},
|
|
177
|
+
contentHashType: MODULE_TYPE
|
|
178
|
+
});
|
|
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
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
const buf = [];
|
|
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
|
+
}
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
if ((0, _hashUtils.hasContentHash)(filenameTemplate)) {
|
|
198
|
+
const hashLength = getContentHashMaxLength(filenameTemplate);
|
|
199
|
+
const contentHashes = this.getShortContentHashes(mainChunk, hashLength);
|
|
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;', '}']));
|
|
201
|
+
buf.push('var contentHash = i18nContentHashes[locale][chunkId]');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const hashUtils = _webpack.Template.asString(buf);
|
|
205
|
+
|
|
206
|
+
const publicPath = this.publicPath ? JSON.stringify(this.publicPath) : `${mainTemplate.requireFn}.p`;
|
|
207
|
+
return _webpack.Template.asString([source, `
|
|
208
|
+
(function() {
|
|
209
|
+
// ${pluginName} I18N loading
|
|
210
|
+
var i18nChunks = ${JSON.stringify(chunkMap)};
|
|
211
|
+
var locale = ${localeVarName};
|
|
212
|
+
// ${pluginName} I18N hasehes
|
|
213
|
+
${hashUtils}
|
|
214
|
+
if(installedI18nChunks[chunkId]) {
|
|
215
|
+
promises.push(installedI18nChunks[chunkId]);
|
|
216
|
+
} else if(installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {
|
|
217
|
+
promises.push(installedI18nChunks[chunkId] = new Promise(function(resolve, reject) {
|
|
218
|
+
var srcPath = (${i18nSrcPath});
|
|
219
|
+
${'' // TODO: I think this is the area for download chunk of i18n we can
|
|
220
|
+
// change mainTemplate.requireFn as our cdn server urls !!!
|
|
221
|
+
// and we can change the i18n download logic here
|
|
222
|
+
}
|
|
223
|
+
var fullsrcPath = ${publicPath} + srcPath;
|
|
224
|
+
var existingLinkTags = document.getElementsByTagName("script");
|
|
225
|
+
for(var i = 0; i < existingLinkTags.length; i++) {
|
|
226
|
+
var tag = existingLinkTags[i];
|
|
227
|
+
var dataSrc = tag.getAttribute("data-src") || tag.getAttribute("src");
|
|
228
|
+
if(dataSrc === srcPath || dataSrc === fullsrcPath){ return resolve();}
|
|
229
|
+
}
|
|
230
|
+
var scriptTag = document.createElement("script");
|
|
231
|
+
scriptTag.onload = resolve;
|
|
232
|
+
scriptTag.onerror = function(event) {
|
|
233
|
+
var request = event && event.target && event.target.src || fullsrcPath;
|
|
234
|
+
var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + request + ")");
|
|
235
|
+
err.code = "I18N_CHUNK_LOAD_FAILED";
|
|
236
|
+
err.request = request;
|
|
237
|
+
delete installedI18nChunks[chunkId];
|
|
238
|
+
scriptTag.parentNode.removeChild(scriptTag);
|
|
239
|
+
reject(err);
|
|
240
|
+
};
|
|
241
|
+
${mainTemplate.requireFn}.nc && scriptTag.setAttribute("nonce", ${mainTemplate.requireFn}.nc);
|
|
242
|
+
scriptTag.src = fullsrcPath;
|
|
243
|
+
${crossOriginLoading ? `if (scriptTag.src.indexOf(window.location.origin + '/') !== 0) {
|
|
244
|
+
scriptTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};
|
|
245
|
+
}` : ''}
|
|
246
|
+
document.body.appendChild(scriptTag);
|
|
247
|
+
}).then(function() {
|
|
248
|
+
installedI18nChunks[chunkId] = 0;
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
})()`]);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
apply(compiler) {
|
|
256
|
+
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
257
|
+
const {
|
|
258
|
+
mainTemplate
|
|
259
|
+
} = compilation;
|
|
260
|
+
this.addDownloadLogicOfI18nInMainTemplate(mainTemplate);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
exports.default = I18nDownlodLogic;
|