@zohodesk/react-cli 1.1.17 → 1.1.18-exp.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. package/README.md +13 -0
  2. package/lib/babel/babel-option-utils/babel-preset-react-option.js +22 -0
  3. package/lib/babel/cmjs-plugins-presets.js +7 -1
  4. package/lib/babel/es-plugins-presets.js +7 -1
  5. package/lib/configs/webpack.dev.config.js +7 -2
  6. package/lib/configs/webpack.prod.config.js +9 -2
  7. package/lib/loaderUtils/getDevJsLoaders.js +5 -1
  8. package/lib/schemas/index.js +4 -0
  9. package/npm-shrinkwrap.json +31 -5
  10. package/package.json +1 -1
  11. package/packages/client_build_tool/lib/allCommandsConfigs.js +23 -0
  12. package/packages/client_build_tool/lib/buildToolLoggers.js +32 -0
  13. package/packages/client_build_tool/lib/commands/build/commandExecutor.js +21 -0
  14. package/packages/client_build_tool/lib/commands/build/config.js +12 -0
  15. package/packages/client_build_tool/lib/commands/build/errorHander.js +10 -0
  16. package/packages/client_build_tool/lib/commands/build/index.js +35 -0
  17. package/packages/client_build_tool/lib/commands/build/optionsProcesser.js +40 -0
  18. package/packages/client_build_tool/lib/commands/buildEs/commandExecutor.js +17 -0
  19. package/packages/client_build_tool/lib/commands/buildEs/config.js +12 -0
  20. package/packages/client_build_tool/lib/commands/buildLib/commandExecutor.js +17 -0
  21. package/packages/client_build_tool/lib/commands/buildLib/config.js +12 -0
  22. package/packages/client_build_tool/lib/commands/start/commandExecutor.js +13 -0
  23. package/packages/client_build_tool/lib/commands/start/config.js +12 -0
  24. package/packages/client_build_tool/lib/commands/start/deprecationHandler.js +10 -0
  25. package/packages/client_build_tool/lib/commands/start/errorHander.js +10 -0
  26. package/packages/client_build_tool/lib/commands/start/optionsProcesser.js +36 -0
  27. package/packages/client_build_tool/lib/commands/start/postProcesser.js +10 -0
  28. package/packages/client_build_tool/lib/commands/start/preProcesser.js +10 -0
  29. package/packages/client_build_tool/lib/commandsRouter.js +71 -0
  30. package/packages/client_build_tool/lib/shared/bundler/webpack/common/decidePublicPath.js +44 -0
  31. package/packages/client_build_tool/lib/shared/bundler/webpack/common/libAlias.js +31 -0
  32. package/packages/client_build_tool/lib/shared/bundler/webpack/common/nameTemplates.js +51 -0
  33. package/packages/client_build_tool/lib/shared/bundler/webpack/common/resourceBasedPublicPath.js +21 -0
  34. package/packages/client_build_tool/lib/shared/bundler/webpack/cssLoaders.js +16 -0
  35. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin.js +111 -0
  36. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/EFCPlugin.js +1 -0
  37. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ContributionGuide.md +11 -0
  38. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +136 -0
  39. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nSplit.md +95 -0
  40. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/README.md +25 -0
  41. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +29 -0
  42. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +24 -0
  43. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nDependency.js +99 -0
  44. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +81 -0
  45. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nModule.js +201 -0
  46. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +401 -0
  47. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +67 -0
  48. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +23 -0
  49. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +29 -0
  50. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +49 -0
  51. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +77 -0
  52. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +63 -0
  53. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +19 -0
  54. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +31 -0
  55. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +127 -0
  56. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RTLSplitPlugin.js +1 -0
  57. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +63 -0
  58. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +89 -0
  59. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtrSplit.md +34 -0
  60. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +15 -0
  61. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +155 -0
  62. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin.js +49 -0
  63. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_postcss_loaders/ExcludePlugin.js +58 -0
  64. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_postcss_loaders/RTLSplitPlugin.js +139 -0
  65. package/packages/client_build_tool/lib/shared/bundler/webpack/devServerConfig.js +34 -0
  66. package/packages/client_build_tool/lib/shared/bundler/webpack/getCSSLoaders.js +30 -0
  67. package/packages/client_build_tool/lib/shared/bundler/webpack/jsLoaders.js +17 -0
  68. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/assetLoaders.js +14 -0
  69. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +24 -0
  70. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +18 -0
  71. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +21 -0
  72. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +138 -0
  73. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +83 -0
  74. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +23 -0
  75. package/packages/client_build_tool/lib/shared/bundler/webpack/loaders/workerLoader.js +133 -0
  76. package/packages/client_build_tool/lib/shared/bundler/webpack/optimizationConfig.js +39 -0
  77. package/packages/client_build_tool/lib/shared/bundler/webpack/outputConfig.js +28 -0
  78. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +18 -0
  79. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configCopyThirdpartyFile.js +38 -0
  80. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +24 -0
  81. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +28 -0
  82. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +35 -0
  83. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +16 -0
  84. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +23 -0
  85. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +19 -0
  86. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +27 -0
  87. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +18 -0
  88. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configUglifyCSSPlugin.js +15 -0
  89. package/packages/client_build_tool/lib/shared/bundler/webpack/plugins.js +39 -0
  90. package/packages/client_build_tool/lib/shared/bundler/webpack/postcssPlugins.js +36 -0
  91. package/packages/client_build_tool/lib/shared/bundler/webpack/resolvers.js +42 -0
  92. package/packages/client_build_tool/lib/shared/bundler/webpack/splitChunksConfig.js +12 -0
  93. package/packages/client_build_tool/lib/shared/bundler/webpack/webpack.dev.config.js +17 -0
  94. package/packages/client_build_tool/lib/shared/bundler/webpack/webpackBuild.js +24 -0
  95. package/packages/client_build_tool/lib/shared/bundler/webpack/webpackConfig.js +50 -0
  96. package/packages/client_build_tool/lib/shared/commands-utlis/doBasicRequiermentCheck.js +16 -0
  97. package/packages/client_build_tool/lib/shared/commands-utlis/getCliPath.js +38 -0
  98. package/packages/client_build_tool/lib/shared/commands-utlis/index.js +29 -0
  99. package/packages/client_build_tool/lib/shared/commands-utlis/log.js +13 -0
  100. package/packages/client_build_tool/lib/shared/commands-utlis/readArgsFormCommandLine.js +11 -0
  101. package/packages/client_build_tool/lib/shared/commands-utlis/readOptionFormCommandLine.js +11 -0
  102. package/packages/client_build_tool/lib/shared/commands-utlis/spanSync.js +35 -0
  103. package/packages/client_build_tool/lib/shared/constants.js +33 -0
  104. package/packages/client_build_tool/lib/shared/schemas/applyValuesToShema.js +37 -0
  105. package/packages/client_build_tool/lib/shared/schemas/cliArgsToObject.js +37 -0
  106. package/packages/client_build_tool/lib/shared/schemas/defaultConfigValues.js +119 -0
  107. package/packages/client_build_tool/lib/shared/schemas/deprecatedOptionsHandler.js +65 -0
  108. package/packages/client_build_tool/lib/shared/schemas/getCWD.js +23 -0
  109. package/packages/client_build_tool/lib/shared/schemas/getNpmVersion.js +21 -0
  110. package/packages/client_build_tool/lib/shared/schemas/npmConfigToObject.js +32 -0
  111. package/packages/client_build_tool/lib/shared/schemas/oldDefaultConfigValues.js +480 -0
  112. package/packages/client_build_tool/lib/shared/schemas/readOptions.js +55 -0
  113. package/packages/client_build_tool/lib/shared/schemas/readOptionsForPackageJson.js +26 -0
  114. package/packages/client_build_tool/lib/shared/schemas/readOptionsOld.js +152 -0
  115. package/packages/client_build_tool/lib/shared/server/cert/Tsicsezwild-22-23.crt +37 -0
  116. package/packages/client_build_tool/lib/shared/server/cert/Tsicsezwild-22-23.key +27 -0
  117. package/packages/client_build_tool/lib/shared/server/configWebpackDevMiddleware.js +40 -0
  118. package/packages/client_build_tool/lib/shared/server/corsHandleing.js +28 -0
  119. package/packages/client_build_tool/lib/shared/server/getIp.js +30 -0
  120. package/packages/client_build_tool/lib/shared/server/getServerURL.js +29 -0
  121. package/packages/client_build_tool/lib/shared/server/httpsOptions.js +53 -0
  122. package/packages/client_build_tool/lib/shared/server/initExpressApp.js +19 -0
  123. package/packages/client_build_tool/lib/shared/server/initialHTMLHandling.js +66 -0
  124. package/packages/client_build_tool/lib/shared/server/serveContextFiles.js +24 -0
  125. package/packages/client_build_tool/lib/shared/server/serverBywebpackDevMiddleware.js +40 -0
  126. package/packages/client_build_tool/lib/shared/server/startHttpServer.js +26 -0
  127. package/packages/client_build_tool/lib/shared/server/startHttpsServer.js +34 -0
  128. package/packages/client_build_tool/lib/shared/server/unwanted/addHttp2Server.js +41 -0
  129. package/packages/client_build_tool/lib/shared/server/unwanted/configWebpackDevMiddleware.js +44 -0
  130. package/packages/client_build_tool/lib/shared/server/unwanted/devServerUtlis.js +1 -0
  131. package/packages/client_build_tool/lib/shared/server/unwanted/mockApiSupport.js +19 -0
  132. package/packages/client_build_tool/lib/shared/server/unwanted/webpackConfig.js +32 -0
  133. package/packages/client_build_tool/lib/shared/server/unwanted/websocketMockSetup.js +48 -0
  134. package/packages/client_build_tool/lib/shared/server/urlConcat.js +25 -0
  135. package/packages/client_build_tool/lib/shared/utils/utils.js +1 -0
@@ -0,0 +1,95 @@
1
+ # I18n Split As Chunks Plugin
2
+
3
+ generaly we have manage our all I18n keys and values as language specific i18n files and then we download all i18n in initial page load.
4
+
5
+ ### what is the problem with this?.
6
+
7
+ the problem is i18n file keep get's grown it will affect the the inital page load and critial rendering path.
8
+ So, We have decide to create a plugin for split i18n per chunk's of js vise.
9
+
10
+ ### what is i18n split?
11
+
12
+ it is like code split for i18n.
13
+ we will collect i18n from js chunk and we will create separate i18n chunk per js chunk,
14
+ with this we already load Js chunks are on demand and now we also download i18n also ondemand with this the initial and forthere actions.
15
+ when js download's we will download i18n with it.
16
+
17
+ ### How to we going to i18n split?
18
+
19
+ we will read the js chunk and collect I18n keys form it,
20
+ then we will create i18n chunk files with these used keys.
21
+
22
+ ### how do you collect i18n keys from js files?
23
+
24
+ we will traverse the js file's AST (static analysis) and find i18 keys,
25
+ we will concider all string which is in jsResource file as i18n keys.
26
+ and you can tell dynamic i18n key by js comments,
27
+ Like Below:-
28
+
29
+ ```js
30
+ fetch('tickets?view=view1').then(data => {
31
+ // I18n support.ticketsEmpty
32
+ // I18n support.viewNotFount
33
+ // I18n support.permissionDenied
34
+ let text = getI18nValue(data.i18nkey);
35
+ });
36
+ ```
37
+
38
+ ### is there any posiblity for unwanted keys in some chunk?
39
+
40
+ Yes, there is two posiblity
41
+
42
+ 1. js comment , if you write js comment but it is not needed then it will be add into i18n chunk
43
+ `To Resolve` we currently do not have perfect idea for this, But we can check this by chunk size limit.
44
+ `idea's will be welcome`
45
+ 2. like we said "we will concider all string which is in jsResource file as i18n keys",
46
+ So if you use string not for i18n but it was in jsResource then it will be add into i18n chunk.
47
+ `To Resolve` this problem we can use some kinda prefix or something.
48
+
49
+ ### how do we downlowd and give to app?
50
+
51
+ we have over write defualt webpack requireEnsure (every dynamic chunk requests are done by that function) function.
52
+ and we parlarly dowload i18n files. and we ask jsonFunction, to our plugin.
53
+ So we send i18nkeys , when it was download,
54
+ you must store all i18n keys, we give asycrnsly by that function download in that patticular.
55
+ so you must store and update (like append or assign) everytime that function call.
56
+
57
+ ### how to use this feature?
58
+
59
+ to use this feature use have give the below oprtions
60
+ `package.json`
61
+
62
+ ```json
63
+ {
64
+ /// ...some things
65
+ "react-cli": {
66
+ // ...some things
67
+ "i18n": {
68
+ "chunkSplitEnable": true,
69
+ "jsResource": "./deskapp/properties/JSResources.properties",
70
+ "localeVarName": "window.userInfo.langCode",
71
+ "jsonpFunc": "window.loadI18nChunk",
72
+ "templateLabel": "{{--user-locale}}", // this is for html template i18n file path locate template
73
+ "propertiesFolder": "./deskapp/properties"
74
+ }
75
+ // ...some things
76
+ }
77
+ }
78
+ ```
79
+
80
+ <!-- not need below -->
81
+ <!--we have added new feature for css to write logic to how hover related css work in hoverhover and a
82
+
83
+ ### is there any problems with static analysis?
84
+ Yes,
85
+
86
+ ### how do we use dynamic i18n key?
87
+
88
+ and we will download i18n file with
89
+
90
+ and when js chunk download's then we will download i18n as need.
91
+ we all know in our app we loading i18n as one single big file for each locale(language).
92
+ we are going to split i18n as per js chunk, and when js chunk download's then we will download i18n as need.
93
+
94
+
95
+ -->
@@ -0,0 +1,25 @@
1
+ # I18n Split As Chunks Plugin
2
+
3
+ generaly we have manage our all I18n keys and values as language specific i18n files and then we download all i18n in initial page load.
4
+
5
+ Ok, what is the problem with this?.
6
+ the problem is i18n file keep get's grown it will affect the the inital page load and critial rendering path.
7
+ So, We have decide to create a plugin for split i18n per chunk's of js vise, Which mean we diside to create for each js chunk has its own i18n chunks, with this we already load Js chunks are on demand and now we also download i18n also ondemand with this the initial and forthere actions.
8
+
9
+ Ok, How to you do this thing?
10
+ we have read the js chunk and collect I18n keys what are used in that chunk and we will create i18n chunk files with only used key.
11
+
12
+ Ok, How do you collect that keys?
13
+ we now have two experimental stage to collect I18n keys.
14
+
15
+ 1. we read jsResource.properties (or all keys I18n file) then we walk this AST of js and we collect all string which is jsResource.properties.
16
+ 2. for dynamic we discide to use comment some thing like
17
+ `// I18n support.tickekt.email.notvalid`
18
+
19
+ ok, how do you downlowd and give to app?
20
+ we have over write defualt webpack require ensure function.
21
+ So every dynamic chunk requset are done by that function.
22
+ So we parlarly dowload i18n files. and we ask jsonFunction, to our plugin.
23
+ So we send i18nkeys , when it was download,
24
+ you must store all i18n keys, we give asycrnsly by that function download in that patticular.
25
+ so you must store and update (like append or assign) everytime that function call.
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TYPES = exports.SINGLE_DOT_PATH_SEGMENT = exports.MODULE_TYPE = exports.I18N_CHUNK_NAME_GENERATION_SEGMENT = exports.DEFAULT_FILENAME = exports.DEFAULT_CHUNK_FILENAME = exports.CODE_GENERATION_RESULT = exports.BASE_URI = exports.AUTO_PUBLIC_PATH = exports.ABSOLUTE_PUBLIC_PATH = void 0;
7
+ const MODULE_TYPE = 'i18n/mini-extract';
8
+ exports.MODULE_TYPE = MODULE_TYPE;
9
+ const AUTO_PUBLIC_PATH = '__mini_i18n_extract_plugin_public_path_auto__';
10
+ exports.AUTO_PUBLIC_PATH = AUTO_PUBLIC_PATH;
11
+ const ABSOLUTE_PUBLIC_PATH = 'webpack:///mini-i18n-extract-plugin/';
12
+ exports.ABSOLUTE_PUBLIC_PATH = ABSOLUTE_PUBLIC_PATH;
13
+ const BASE_URI = 'webpack://';
14
+ exports.BASE_URI = BASE_URI;
15
+ const SINGLE_DOT_PATH_SEGMENT = '__mini_i18n_extract_plugin_single_dot_path_segment__';
16
+ exports.SINGLE_DOT_PATH_SEGMENT = SINGLE_DOT_PATH_SEGMENT;
17
+ const I18N_CHUNK_NAME_GENERATION_SEGMENT = '__mini_i18n_extract_plugin_i18n_chunk_name_generation_segment__';
18
+ exports.I18N_CHUNK_NAME_GENERATION_SEGMENT = I18N_CHUNK_NAME_GENERATION_SEGMENT;
19
+ const DEFAULT_FILENAME = 'i18n-chunks/[locale]/[name].[contenthash].i18n.js';
20
+ exports.DEFAULT_FILENAME = DEFAULT_FILENAME;
21
+ const DEFAULT_CHUNK_FILENAME = 'i18n-chunks/[locale]/[id].[contenthash].i18n.js';
22
+ exports.DEFAULT_CHUNK_FILENAME = DEFAULT_CHUNK_FILENAME;
23
+ const TYPES = new Set([MODULE_TYPE]);
24
+ exports.TYPES = TYPES;
25
+ const CODE_GENERATION_RESULT = {
26
+ sources: new Map(),
27
+ runtimeRequirements: new Set()
28
+ };
29
+ exports.CODE_GENERATION_RESULT = CODE_GENERATION_RESULT;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createHash = createHash;
7
+
8
+ function createHash({
9
+ compiler,
10
+ outputOptions,
11
+ content
12
+ }) {
13
+ const {
14
+ hashFunction,
15
+ hashDigest,
16
+ hashDigestLength
17
+ } = outputOptions;
18
+ const {
19
+ createHash
20
+ } = compiler.webpack.util;
21
+ const hash = createHash(hashFunction);
22
+ hash.update(content);
23
+ return hash.digest(hashDigest).substring(0, hashDigestLength);
24
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getI18nDependency = getI18nDependency;
7
+ exports.i18nDependencyCache = void 0;
8
+
9
+ var _path = _interopRequireDefault(require("path"));
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ /* eslint-disable class-methods-use-this */
14
+ const i18nDependencyCache = new WeakMap();
15
+ exports.i18nDependencyCache = i18nDependencyCache;
16
+
17
+ function getI18nDependency(webpack) {
18
+ if (i18nDependencyCache.has(webpack)) {
19
+ return i18nDependencyCache.get(webpack);
20
+ }
21
+
22
+ class I18nDependency extends webpack.Dependency {
23
+ constructor({
24
+ identifier,
25
+ content
26
+ }, context, identifierIndex) {
27
+ super();
28
+ this.identifier = identifier;
29
+ this.identifierIndex = identifierIndex;
30
+ this.content = content; // ## this.layer = layer;
31
+ // ## this.supports = supports;
32
+ // ## this.media = media;
33
+ // ## this.sourceMap = sourceMap;
34
+
35
+ this.context = context;
36
+ this.assets = undefined;
37
+ this.assetsInfo = undefined;
38
+ }
39
+
40
+ getResourceIdentifier() {
41
+ return `i18n-module-${this.identifier}-${this.identifierIndex}`;
42
+ }
43
+
44
+ getModuleEvaluationSideEffectsState() {
45
+ return webpack.ModuleGraphConnection.TRANSITIVE_ONLY;
46
+ }
47
+
48
+ serialize(context) {
49
+ const {
50
+ write
51
+ } = context;
52
+ write(this.identifier);
53
+ write(this.content); // ## write(this.layer);
54
+ // ## write(this.supports);
55
+ // ## write(this.media);
56
+ // ## write(this.sourceMap);
57
+
58
+ write(this.context);
59
+ write(this.identifierIndex);
60
+ write(this.assets);
61
+ write(this.assetsInfo);
62
+ super.serialize(context);
63
+ }
64
+
65
+ deserialize(context) {
66
+ super.deserialize(context);
67
+ }
68
+
69
+ }
70
+
71
+ i18nDependencyCache.set(webpack, I18nDependency);
72
+ webpack.util.serialization.register(I18nDependency, _path.default.resolve(__dirname, 'I18nDependency-new'), null, {
73
+ serialize(instance, context) {
74
+ instance.serialize(context);
75
+ },
76
+
77
+ deserialize(context) {
78
+ const {
79
+ read
80
+ } = context;
81
+ const dep = new I18nDependency({
82
+ identifier: read(),
83
+ content: read() // ## layer: read(),
84
+ // ## supports: read(),
85
+ // ## media: read(),
86
+ // ## sourceMap: read()
87
+
88
+ }, read(), read());
89
+ const assets = read();
90
+ const assetsInfo = read();
91
+ dep.assets = assets;
92
+ dep.assetsInfo = assetsInfo;
93
+ dep.deserialize(context);
94
+ return dep;
95
+ }
96
+
97
+ });
98
+ return I18nDependency;
99
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getI18nLoadingRuntimeModule = getI18nLoadingRuntimeModule;
7
+
8
+ /* eslint-disable no-restricted-syntax */
9
+ const getChunksMapObject = i18nChunks => {
10
+ const obj = {};
11
+
12
+ for (const chunk of i18nChunks) {
13
+ obj[chunk.id] = 1;
14
+ }
15
+
16
+ return obj;
17
+ };
18
+
19
+ function getI18nLoadingRuntimeModule({
20
+ webpack,
21
+ getI18nChunks
22
+ }) {
23
+ const {
24
+ Template,
25
+ RuntimeGlobals,
26
+ RuntimeModule
27
+ } = webpack;
28
+
29
+ class I18nLoadingRuntimeModule extends RuntimeModule {
30
+ constructor(runtimeRequirements, {
31
+ runtimeOptions,
32
+ prefixFunc
33
+ }) {
34
+ super('i18n loading', 10);
35
+ this.runtimeRequirements = runtimeRequirements;
36
+ this.prefixFunc = prefixFunc;
37
+ this.runtimeOptions = runtimeOptions;
38
+ }
39
+
40
+ generate() {
41
+ const {
42
+ chunk,
43
+ runtimeRequirements,
44
+ prefixFunc,
45
+ compilation
46
+ } = this;
47
+ const {
48
+ runtimeTemplate,
49
+ outputOptions: {
50
+ crossOriginLoading
51
+ }
52
+ } = compilation; // const i18nChunks = getI18nChunks(chunk, compilation);
53
+ // REASON: we do it in here is in dev mode thing may change
54
+ // const i18nChunks = getI18nChunks(entryRuntimeChunk);
55
+
56
+ const i18nChunks = getI18nChunks(chunk);
57
+ const withLoading = runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) && i18nChunks.length > 0;
58
+
59
+ if (!withLoading) {
60
+ return '';
61
+ }
62
+
63
+ const chunkMap = getChunksMapObject(i18nChunks);
64
+ const {
65
+ attributes,
66
+ scriptType,
67
+ insert: insertRoot
68
+ } = this.runtimeOptions;
69
+ const insertPlace = typeof insertRoot === 'function' ? `(${insertRoot.toString()})(scriptTag)` : Template.asString([`var target = document.querySelector("${insertRoot}");`, 'target.parentNode.insertBefore(scriptTag, target.nextSibling);']);
70
+ return Template.asString([`${prefixFunc(i18nChunks)}`, `var createI18nScriptTag = ${runtimeTemplate.basicFunction('chunkId, fullsrc, resolve, reject', ['var scriptTag = document.createElement("script");', attributes ? Template.asString(Object.entries(attributes).map(entry => {
71
+ const [key, value] = entry;
72
+ return `scriptTag.setAttribute(${JSON.stringify(key)}, ${JSON.stringify(value)});`;
73
+ })) : '', scriptType ? `scriptTag.type = ${JSON.stringify(scriptType)};` : '', `var onScriptComplete = ${runtimeTemplate.basicFunction('event', ['// avoid mem leaks.', 'scriptTag.onerror = scriptTag.onload = null;', 'if (event.type === \'load\') {', Template.indent(['resolve();']), '} else {', Template.indent(['var errorType = event && (event.type === \'load\' ? \'missing\' : event.type);', 'var realSrc = event && event.target && event.target.src || fullsrc;', 'var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + realSrc + ")");', 'err.code = "I18N_CHUNK_LOAD_FAILED";', 'err.type = errorType;', 'err.request = realSrc;', 'scriptTag.parentNode.removeChild(scriptTag)', 'reject(err);']), '}'])}`, 'scriptTag.onerror = scriptTag.onload = onScriptComplete;', 'scriptTag.src = fullsrc;', crossOriginLoading ? Template.asString(['if (scriptTag.src.indexOf(window.location.origin + \'/\') !== 0) {', Template.indent(`scriptTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '', insertRoot && insertPlace || Template.asString(['document.head.appendChild(scriptTag);']), 'return scriptTag;'])};`, `var findI18nScriptTag = ${runtimeTemplate.basicFunction('src, fullsrc', ['var existingScriptTags = document.getElementsByTagName("script");', 'for(var i = 0; i < existingScriptTags.length; i++) {', Template.indent(['var tag = existingScriptTags[i];', 'var dataSrc = tag.getAttribute("data-src") || tag.getAttribute("src");', 'if((dataSrc === src || dataSrc === fullsrc)) return tag;']), '}', 'var existingStyleTags = document.getElementsByTagName("style");', 'for(var i = 0; i < existingStyleTags.length; i++) {', Template.indent(['var tag = existingStyleTags[i];', 'var dataSrc = tag.getAttribute("data-src");', 'if(dataSrc === src || dataSrc === fullsrc) return tag;']), '}'])};`, `var loadI18nScriptTag = ${runtimeTemplate.basicFunction('chunkId', `return new Promise(${runtimeTemplate.basicFunction('resolve, reject', [`var src = ${RuntimeGlobals.require}.miniI18nF(chunkId);`, `var fullsrc = ${RuntimeGlobals.publicPath} + src;`, 'if(findI18nScriptTag(src, fullsrc)) return resolve();', 'createI18nScriptTag(chunkId, fullsrc, resolve, reject);'])});`)}`, withLoading ? Template.asString(['// object to store loaded I18N chunks', 'var installedI18nChunks = {', Template.indent(
74
+ /** @type {string[]} */
75
+ chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};', '', `${RuntimeGlobals.ensureChunkHandlers}.miniI18n = ${runtimeTemplate.basicFunction('chunkId, promises', [`var i18nChunks = ${JSON.stringify(chunkMap)};`, 'if(installedI18nChunks[chunkId]) promises.push(installedI18nChunks[chunkId]);', 'else if(installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {', Template.indent([`promises.push(installedI18nChunks[chunkId] = loadI18nScriptTag(chunkId).then(${runtimeTemplate.basicFunction('', 'installedI18nChunks[chunkId] = 0;')}, ${runtimeTemplate.basicFunction('e', ['delete installedI18nChunks[chunkId];', 'throw e;'])}));`]), '}'])};`]) : '// no chunk loading', '']);
76
+ }
77
+
78
+ }
79
+
80
+ return I18nLoadingRuntimeModule;
81
+ }
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getI18nModule = getI18nModule;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _constants = require("./constants");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ /* eslint-disable no-underscore-dangle */
15
+ const i18nModuleCache = new WeakMap();
16
+
17
+ function getI18nModule(webpack) {
18
+ if (i18nModuleCache.has(webpack)) {
19
+ return i18nModuleCache.get(webpack);
20
+ }
21
+
22
+ class I18nModule extends webpack.Module {
23
+ constructor({
24
+ context,
25
+ identifier,
26
+ identifierIndex,
27
+ content,
28
+ // ## layer,
29
+ // ## supports,
30
+ // ## media,
31
+ // ## sourceMap,
32
+ assets,
33
+ assetsInfo
34
+ }) {
35
+ super(_constants.MODULE_TYPE, context);
36
+ this.id = '';
37
+ this._context = context;
38
+ this._identifier = identifier;
39
+ this._identifierIndex = identifierIndex;
40
+ this.content = content; // ## this.layer = layer;
41
+ // ## this.supports = supports;
42
+ // ## this.media = media;
43
+ // ## this.sourceMap = sourceMap;
44
+
45
+ this.assets = assets;
46
+ this.assetsInfo = assetsInfo;
47
+ this._needBuild = true;
48
+ }
49
+
50
+ size() {
51
+ return this.content.length;
52
+ }
53
+
54
+ identifier() {
55
+ return `i18n|${this._identifier}|${this._identifierIndex}`;
56
+ }
57
+
58
+ readableIdentifier(requestShortener) {
59
+ return `i18n ${requestShortener.shorten(this._identifier)}${this._identifierIndex ? ` (${this._identifierIndex})` : ''}`;
60
+ } // eslint-disable-next-line class-methods-use-this
61
+
62
+
63
+ getSourceTypes() {
64
+ return _constants.TYPES;
65
+ } // eslint-disable-next-line class-methods-use-this
66
+
67
+
68
+ codeGeneration() {
69
+ return _constants.CODE_GENERATION_RESULT;
70
+ }
71
+
72
+ nameForCondition() {
73
+ const resource = this._identifier.split('!').pop();
74
+
75
+ const idx = resource.indexOf('?');
76
+
77
+ if (idx >= 0) {
78
+ return resource.substring(0, idx);
79
+ }
80
+
81
+ return resource;
82
+ }
83
+
84
+ updateCacheModule(module) {
85
+ if (this.content !== module.content || // ## this.layer !== module.layer ||
86
+ // ## this.supports !== module.supports ||
87
+ // ## this.media !== module.media ||
88
+ // ## this.sourceMap !== module.sourceMap ||
89
+ this.assets !== module.assets || this.assetsInfo !== module.assetsInfo) {
90
+ this._needBuild = true;
91
+ this.content = module.content; // ## this.layer = module.layer;
92
+ // ## this.supports = module.supports;
93
+ // ## this.media = module.media;
94
+ // ## this.sourceMap = module.sourceMap;
95
+
96
+ this.assets = module.assets;
97
+ this.assetsInfo = module.assetsInfo;
98
+ }
99
+ }
100
+
101
+ needRebuild() {
102
+ return this._needBuild;
103
+ }
104
+
105
+ needBuild(context, callback) {
106
+ callback(undefined, this._needBuild);
107
+ }
108
+
109
+ build(options, compilation, resolver, fileSystem, callback) {
110
+ this.buildInfo = {
111
+ assets: this.assets,
112
+ assetsInfo: this.assetsInfo,
113
+ cacheable: true,
114
+ hash: this._computeHash(compilation.outputOptions.hashFunction)
115
+ };
116
+ this.buildMeta = {};
117
+ this._needBuild = false;
118
+ callback();
119
+ }
120
+
121
+ _computeHash(hashFunction) {
122
+ const hash = webpack.util.createHash(hashFunction);
123
+ hash.update(this.content); // ## if (this.layer) {
124
+ // ## hash.update(this.layer);
125
+ // ## }
126
+ // ## hash.update(this.supports || '');
127
+ // ## hash.update(this.media || '');
128
+ // ## hash.update(this.sourceMap || '');
129
+
130
+ return hash.digest('hex');
131
+ }
132
+
133
+ updateHash(hash, context) {
134
+ super.updateHash(hash, context);
135
+ hash.update(this.buildInfo.hash);
136
+ }
137
+
138
+ serialize(context) {
139
+ const {
140
+ write
141
+ } = context;
142
+ write(this._context);
143
+ write(this._identifier);
144
+ write(this._identifierIndex);
145
+ write(this.content); // ## write(this.layer);
146
+ // ## write(this.supports);
147
+ // ## write(this.media);
148
+ // ## write(this.sourceMap);
149
+
150
+ write(this.assets);
151
+ write(this.assetsInfo);
152
+ write(this._needBuild);
153
+ super.serialize(context);
154
+ }
155
+
156
+ deserialize(context) {
157
+ this._needBuild = context.read();
158
+ super.deserialize(context);
159
+ }
160
+
161
+ }
162
+
163
+ i18nModuleCache.set(webpack, I18nModule);
164
+ webpack.util.serialization.register(I18nModule, _path.default.resolve(__dirname, 'I18nModule-new'), null, {
165
+ serialize(instance, context) {
166
+ instance.serialize(context);
167
+ },
168
+
169
+ deserialize(context) {
170
+ const {
171
+ read
172
+ } = context;
173
+ const contextModule = read();
174
+ const identifier = read();
175
+ const identifierIndex = read();
176
+ const content = read(); // ## const layer = read();
177
+ // ## const supports = read();
178
+ // ## const media = read();
179
+ // ## const sourceMap = read();
180
+
181
+ const assets = read();
182
+ const assetsInfo = read();
183
+ const dep = new I18nModule({
184
+ context: contextModule,
185
+ identifier,
186
+ identifierIndex,
187
+ content,
188
+ // ## layer,
189
+ // ## supports,
190
+ // ## media,
191
+ // ## sourceMap,
192
+ assets,
193
+ assetsInfo
194
+ });
195
+ dep.deserialize(context);
196
+ return dep;
197
+ }
198
+
199
+ });
200
+ return I18nModule;
201
+ }