@zohodesk/react-cli 0.0.1-beta.98 → 0.0.1-betaa.138.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +149 -0
  3. package/bin/cli.js +34 -29
  4. package/files/eslintrc.js +57 -0
  5. package/files/prettierrc.js +3 -0
  6. package/lib/babel/cmjs-plugins-presets.js +16 -9
  7. package/lib/babel/es-plugins-presets.js +26 -14
  8. package/lib/common/getEntries.js +31 -22
  9. package/lib/common/getPublicPathConfig.js +27 -13
  10. package/lib/common/index.js +21 -25
  11. package/lib/common/splitChunks.js +62 -53
  12. package/lib/common/templateParameters.js +10 -8
  13. package/lib/configs/jest.config.js +15 -25
  14. package/lib/configs/webpack.component.umd.config.js +31 -37
  15. package/lib/configs/webpack.css.umd.config.js +44 -47
  16. package/lib/configs/webpack.dev.config.js +70 -52
  17. package/lib/configs/webpack.docs.config.js +106 -106
  18. package/lib/configs/webpack.prod.config.js +95 -75
  19. package/lib/hooks/docsProptypeHook.js +32 -38
  20. package/lib/jest/commitedFilesResult.js +103 -74
  21. package/lib/jest/coverageCollector.js +41 -21
  22. package/lib/jest/jsonMaker.js +15 -16
  23. package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
  24. package/lib/jest/preProcessors/jsPreprocessor.js +3 -5
  25. package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
  26. package/lib/jest/result.js +90 -45
  27. package/lib/jest/run.js +43 -43
  28. package/lib/jest/setup.js +102 -95
  29. package/lib/loaderUtils/getCSSLoaders.js +21 -22
  30. package/lib/loaderUtils/getDevJsLoaders.js +25 -23
  31. package/lib/loaderUtils/index.js +11 -13
  32. package/lib/loaders/docsLoader.js +15 -15
  33. package/lib/loaders/docsPropsLoader.js +14 -17
  34. package/lib/loaders/fileLoader.js +33 -35
  35. package/lib/loaders/scriptInstrumentLoader.js +21 -20
  36. package/lib/loaders/workerLoader.js +136 -0
  37. package/lib/middlewares/HMRMiddleware.js +54 -45
  38. package/lib/middlewares/SSTMiddleware.js +8 -5
  39. package/lib/pluginUtils/getDevPlugins.js +114 -52
  40. package/lib/pluginUtils/getDocsPlugins.js +25 -29
  41. package/lib/pluginUtils/getLibraryPlugins.js +8 -10
  42. package/lib/pluginUtils/getProdPlugins.js +163 -74
  43. package/lib/pluginUtils/getServerPlugins.js +8 -11
  44. package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
  45. package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
  46. package/lib/pluginUtils/index.js +36 -43
  47. package/lib/plugins/CdnChangePlugin.js +63 -0
  48. package/lib/plugins/CleanupStatsPlugin.js +18 -32
  49. package/lib/plugins/CustomAttributePlugin.js +79 -0
  50. package/lib/plugins/CustomAttributePlugin.md +35 -0
  51. package/lib/plugins/EFCPlugin.js +185 -0
  52. package/lib/plugins/I18NInjectIntoIndexPlugin.js +118 -52
  53. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
  54. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
  55. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
  56. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
  57. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
  58. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
  59. package/lib/plugins/I18nSplitPlugin/README.md +25 -0
  60. package/lib/plugins/I18nSplitPlugin/index.js +185 -0
  61. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
  62. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
  63. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
  64. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
  65. package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
  66. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
  67. package/lib/plugins/ManifestPlugin.js +52 -63
  68. package/lib/plugins/ModuleStatsPlugin.js +83 -173
  69. package/lib/plugins/OptimizeJSPlugin.js +24 -41
  70. package/lib/plugins/PublicPathCallbackPlugin.js +42 -116
  71. package/lib/plugins/PublicPathChangePlugin.js +175 -284
  72. package/lib/plugins/ReportGeneratePlugin.js +150 -151
  73. package/lib/plugins/ResourceHintsPlugin.js +53 -35
  74. package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
  75. package/lib/plugins/ServiceWorkerPlugin.js +81 -57
  76. package/lib/plugins/ShadowDOMSupportPlugin.js +153 -234
  77. package/lib/plugins/SourceMapHookPlugin.js +21 -33
  78. package/lib/plugins/TPHashMappingPlugin.js +67 -0
  79. package/lib/plugins/UglifyCSSPlugin.js +23 -30
  80. package/lib/plugins/UnusedFilesFindPlugin.js +137 -152
  81. package/lib/plugins/index.js +100 -91
  82. package/lib/plugins/webpackwatchrunplugin.js +18 -30
  83. package/lib/postcss-plugins/ExcludeRTLPlugin.js +14 -17
  84. package/lib/schemas/index.js +336 -81
  85. package/lib/servers/clusterHubServer.js +22 -26
  86. package/lib/servers/docsServer.js +3 -5
  87. package/lib/servers/docsServerCore.js +84 -91
  88. package/lib/servers/helpServer.js +19 -21
  89. package/lib/servers/impactServer.js +99 -92
  90. package/lib/servers/mockserver.js +24 -24
  91. package/lib/servers/scrServer.js +78 -98
  92. package/lib/servers/server.js +101 -122
  93. package/lib/servers/ssServer.js +63 -61
  94. package/lib/sh/reportPublish.sh +1 -2
  95. package/lib/templates/CoverageScriptTemplate.js +45 -18
  96. package/lib/templates/WMSTemplate.js +17 -18
  97. package/lib/templates/linterConstant.js +6 -4
  98. package/lib/utils/babelPresets.js +12 -5
  99. package/lib/utils/clean.js +12 -11
  100. package/lib/utils/copy.js +12 -34
  101. package/lib/utils/copyTimezones.js +9 -16
  102. package/lib/utils/createEventStream.js +24 -19
  103. package/lib/utils/cssClassNameGenerate.js +44 -73
  104. package/lib/utils/cssURLReplacer.js +62 -56
  105. package/lib/utils/dependencyPostPublish.js +20 -19
  106. package/lib/utils/fileUtils.js +66 -54
  107. package/lib/utils/folderIterator.js +20 -21
  108. package/lib/utils/getComponents.js +70 -27
  109. package/lib/utils/getCurrentBranch.js +11 -17
  110. package/lib/utils/getDependenciesImpactList.js +114 -187
  111. package/lib/utils/getHash.js +9 -13
  112. package/lib/utils/getIp.js +9 -9
  113. package/lib/utils/getOptions.js +26 -29
  114. package/lib/utils/getServerURL.js +19 -10
  115. package/lib/utils/index.js +147 -126
  116. package/lib/utils/init.js +2 -2
  117. package/lib/utils/initPreCommitHook.js +40 -32
  118. package/lib/utils/jsonHelper.js +37 -21
  119. package/lib/utils/lint/addScripts.js +27 -0
  120. package/lib/utils/lint/checkExistingConfig.js +67 -0
  121. package/lib/utils/lint/copyConfigs.js +24 -0
  122. package/lib/utils/lint/index.js +54 -0
  123. package/lib/utils/lint/lintScripts.js +11 -0
  124. package/lib/utils/lint/lintSetup.js +31 -0
  125. package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
  126. package/lib/utils/lint/question.js +30 -0
  127. package/lib/utils/lintReporter.js +70 -56
  128. package/lib/utils/mailSender.js +12 -27
  129. package/lib/utils/pullOrigin.js +21 -18
  130. package/lib/utils/reinstallDependencies.js +76 -85
  131. package/lib/utils/removeAttributes.js +25 -23
  132. package/lib/utils/repoClone.js +47 -45
  133. package/lib/utils/request.js +64 -77
  134. package/lib/utils/rtl.js +22 -29
  135. package/lib/utils/setEnvVariables.js +5 -6
  136. package/lib/utils/ssTestHack.js +21 -19
  137. package/lib/utils/switchBranch.js +21 -20
  138. package/lib/utils/urlConcat.js +22 -0
  139. package/package.json +72 -67
@@ -1,55 +1,53 @@
1
- 'use strict';
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 _miniCssExtractPlugin = require('mini-css-extract-plugin');
8
+ var _miniCssExtractPlugin = _interopRequireDefault(require("mini-css-extract-plugin"));
8
9
 
9
- var _miniCssExtractPlugin2 = _interopRequireDefault(_miniCssExtractPlugin);
10
-
11
- var _cssClassNameGenerate = require('../utils/cssClassNameGenerate');
12
-
13
- var _cssClassNameGenerate2 = _interopRequireDefault(_cssClassNameGenerate);
10
+ var _cssClassNameGenerate = _interopRequireDefault(require("../utils/cssClassNameGenerate"));
14
11
 
15
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
13
 
17
- var isWin = process.platform === 'win32';
14
+ let isWin = process.platform === 'win32';
18
15
 
19
- var getCSSLoaders = function getCSSLoaders(hasRTL, rtlExclude, classNameBlob, cssUniqueness, selectorReplace, cssHashSelectors, classNamePrefix) {
20
- var rtlExcludeLocal = isWin ? rtlExclude.map(function (r) {
21
- return r.replace(/\//g, '\\');
22
- }) : rtlExclude;
23
- var cssLoaderOptions = {
16
+ let getCSSLoaders = (hasRTL, rtlExclude, classNameBlob, cssUniqueness, selectorReplace, cssHashSelectors, classNamePrefix) => {
17
+ let rtlExcludeLocal = isWin ? rtlExclude.map(r => r.replace(/\//g, '\\')) : rtlExclude;
18
+ let cssLoaderOptions = {
24
19
  importLoaders: hasRTL ? 1 : 0,
25
- modules: true
20
+ modules: {}
26
21
  };
22
+
27
23
  if (classNameBlob) {
28
- cssLoaderOptions.localIdentName = classNameBlob;
24
+ cssLoaderOptions.modules.localIdentName = classNameBlob;
29
25
  } else {
30
- cssLoaderOptions.getLocalIdent = (0, _cssClassNameGenerate2.default)(cssUniqueness, cssHashSelectors, classNamePrefix);
26
+ cssLoaderOptions.modules.getLocalIdent = (0, _cssClassNameGenerate.default)(cssUniqueness, cssHashSelectors, classNamePrefix);
31
27
  }
28
+
32
29
  return [{
33
- loader: _miniCssExtractPlugin2.default.loader,
30
+ loader: _miniCssExtractPlugin.default.loader,
34
31
  options: {
35
32
  publicPath: '../'
36
33
  }
37
34
  }, {
38
35
  loader: 'css-loader',
39
36
  options: cssLoaderOptions
40
- }, hasRTL ? {
37
+ }, hasRTL || selectorReplace ? {
41
38
  loader: 'postcss-loader',
42
39
  options: {
43
40
  ident: 'postcss',
44
- plugins: function plugins() {
45
- return [selectorReplace && require('postcss-selector-replace')(selectorReplace), require('../postcss-plugins/ExcludeRTLPlugin')({
41
+ plugins: function () {
42
+ return [selectorReplace && require('postcss-selector-replace')(selectorReplace), hasRTL && require('../postcss-plugins/ExcludeRTLPlugin')({
46
43
  ignore: rtlExcludeLocal,
47
44
  plugins: [require('@zohodesk/postcss-rtl')({
48
45
  addPrefixToSelector: function addPrefixToSelector(selector, prefix) {
49
46
  if (prefix === '[dir]') {
50
47
  return selector;
51
48
  }
52
- return prefix + ' ' + selector; // Make selectors like [dir=rtl] > .selector
49
+
50
+ return `${prefix} ${selector}`; // Make selectors like [dir=rtl] > .selector
53
51
  }
54
52
  })]
55
53
  })].filter(Boolean);
@@ -58,4 +56,5 @@ var getCSSLoaders = function getCSSLoaders(hasRTL, rtlExclude, classNameBlob, cs
58
56
  } : null].filter(Boolean);
59
57
  };
60
58
 
61
- exports.default = getCSSLoaders;
59
+ var _default = getCSSLoaders;
60
+ exports.default = _default;
@@ -1,22 +1,25 @@
1
- 'use strict';
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 _path = require('path');
8
-
9
- var _path2 = _interopRequireDefault(_path);
8
+ var _path = _interopRequireDefault(require("path"));
10
9
 
11
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
11
 
13
- var getDevJsLoaders = function getDevJsLoaders(options) {
14
- var _options$app = options.app,
15
- disableES5Transpile = _options$app.disableES5Transpile,
16
- instrumentScript = _options$app.instrumentScript,
17
- enableEslint = options.esLint.enable;
18
-
19
- var loaders = [];
12
+ let getDevJsLoaders = options => {
13
+ let {
14
+ app: {
15
+ disableES5Transpile,
16
+ instrumentScript
17
+ },
18
+ esLint: {
19
+ enable: enableEslint
20
+ }
21
+ } = options;
22
+ let loaders = [];
20
23
 
21
24
  if (instrumentScript) {
22
25
  loaders.push({
@@ -27,19 +30,17 @@ var getDevJsLoaders = function getDevJsLoaders(options) {
27
30
  loaders.push({
28
31
  loader: 'babel-loader',
29
32
  options: {
30
- presets: [[require.resolve('babel-preset-env'), disableES5Transpile ? {
33
+ presets: [[require.resolve('@babel/preset-env'), disableES5Transpile ? {
31
34
  modules: false,
32
- useBuiltIns: true,
35
+ useBuiltIns: 'usage',
36
+ corejs: 3,
33
37
  targets: {
34
- browsers: ['Chrome >= 60', 'Safari >= 10.1', 'iOS >= 10.3', 'Firefox >= 54', 'Edge >= 15']
38
+ browsers: ['last 3 Chrome versions', 'last 3 Firefox versions', 'last 3 Edge versions']
35
39
  }
36
- } : { modules: false }], require.resolve('babel-preset-react')],
37
- plugins: disableES5Transpile ? [require.resolve('babel-plugin-syntax-dynamic-import'), require.resolve('babel-plugin-lodash'), require.resolve('babel-plugin-syntax-object-rest-spread')] : [[require.resolve('babel-plugin-transform-runtime'), {
38
- helpers: true,
39
- polyfill: true,
40
- regenerator: false,
41
- moduleName: 'babel-runtime'
42
- }], require.resolve('babel-plugin-syntax-dynamic-import'), require.resolve('babel-plugin-lodash'), require.resolve('babel-plugin-syntax-object-rest-spread')],
40
+ } : {
41
+ modules: false
42
+ }], require.resolve('@babel/preset-react')],
43
+ plugins: disableES5Transpile ? [require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('babel-plugin-lodash'), require.resolve('@babel/plugin-proposal-object-rest-spread')] : [require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('babel-plugin-lodash'), require.resolve('@babel/plugin-proposal-object-rest-spread')],
43
44
  cacheDirectory: true
44
45
  }
45
46
  });
@@ -50,7 +51,7 @@ var getDevJsLoaders = function getDevJsLoaders(options) {
50
51
  options: {
51
52
  emitError: true,
52
53
  emitWarning: true,
53
- configFile: _path2.default.join(__dirname, '..', '..', '.eslintrc.js')
54
+ configFile: _path.default.join(__dirname, '..', '..', '.eslintrc.js')
54
55
  }
55
56
  });
56
57
  }
@@ -58,4 +59,5 @@ var getDevJsLoaders = function getDevJsLoaders(options) {
58
59
  return loaders;
59
60
  };
60
61
 
61
- exports.default = getDevJsLoaders;
62
+ var _default = getDevJsLoaders;
63
+ exports.default = _default;
@@ -1,25 +1,23 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
- var _getDevJsLoaders = require('./getDevJsLoaders');
8
-
9
- Object.defineProperty(exports, 'getDevJsLoaders', {
6
+ Object.defineProperty(exports, "getCSSLoaders", {
10
7
  enumerable: true,
11
- get: function get() {
12
- return _interopRequireDefault(_getDevJsLoaders).default;
8
+ get: function () {
9
+ return _getCSSLoaders.default;
13
10
  }
14
11
  });
15
-
16
- var _getCSSLoaders = require('./getCSSLoaders');
17
-
18
- Object.defineProperty(exports, 'getCSSLoaders', {
12
+ Object.defineProperty(exports, "getDevJsLoaders", {
19
13
  enumerable: true,
20
- get: function get() {
21
- return _interopRequireDefault(_getCSSLoaders).default;
14
+ get: function () {
15
+ return _getDevJsLoaders.default;
22
16
  }
23
17
  });
24
18
 
19
+ var _getDevJsLoaders = _interopRequireDefault(require("./getDevJsLoaders"));
20
+
21
+ var _getCSSLoaders = _interopRequireDefault(require("./getCSSLoaders"));
22
+
25
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -1,22 +1,22 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _fs = require('fs');
3
+ var _fs = _interopRequireDefault(require("fs"));
4
4
 
5
- var _fs2 = _interopRequireDefault(_fs);
6
-
7
- var _path = require('path');
8
-
9
- var _path2 = _interopRequireDefault(_path);
5
+ var _path = _interopRequireDefault(require("path"));
10
6
 
11
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
8
 
13
9
  module.exports = function (source) {
14
- var comNameAry = this.resourcePath.split(_path2.default.sep);
15
- var filePath = this.resourcePath;
16
- var appPath = _fs2.default.realpathSync(process.cwd());
17
- var changePath = filePath.replace('/lib/', '/src/');
18
- var comName = comNameAry[comNameAry.length - 1];
19
- var name = comName.substring(0, comName.lastIndexOf('.'));
20
- var src = _fs2.default.readFileSync(filePath.startsWith(appPath) ? filePath : changePath).toString();
21
- return source + ';' + name + '.source=' + JSON.stringify(src) + ';' + name + '.filePath=' + JSON.stringify(filePath);
10
+ let comNameAry = this.resourcePath.split(_path.default.sep);
11
+ let filePath = this.resourcePath;
12
+
13
+ let appPath = _fs.default.realpathSync(process.cwd());
14
+
15
+ let changePath = filePath.replace('/lib/', '/src/');
16
+ let comName = comNameAry[comNameAry.length - 1];
17
+ let name = comName.substring(0, comName.lastIndexOf('.'));
18
+
19
+ let src = _fs.default.readFileSync(filePath.startsWith(appPath) ? filePath : changePath).toString();
20
+
21
+ return `${source};${name}.source=${JSON.stringify(src)};${name}.filePath=${JSON.stringify(filePath)}`;
22
22
  };
@@ -1,30 +1,27 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _reactDocgen = require('react-docgen');
3
+ var _reactDocgen = _interopRequireDefault(require("react-docgen"));
4
4
 
5
- var _reactDocgen2 = _interopRequireDefault(_reactDocgen);
5
+ var _path = _interopRequireDefault(require("path"));
6
6
 
7
- var _path = require('path');
8
-
9
- var _path2 = _interopRequireDefault(_path);
10
-
11
- var _utils = require('../utils');
7
+ var _utils = require("../utils");
12
8
 
13
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
10
 
15
11
  // import loaderUtils from 'loader-utils';
16
- module.exports = function (source) {
17
- undefined.cacheable && undefined.cacheable();
18
- // let query = loaderUtils.parseQuery(this.query);
12
+ module.exports = source => {
13
+ (void 0).cacheable && (void 0).cacheable(); // let query = loaderUtils.parseQuery(this.query);
14
+
15
+ let value = {};
19
16
 
20
- var value = {};
21
17
  try {
22
- value = _reactDocgen2.default.parse(source);
18
+ value = _reactDocgen.default.parse(source);
23
19
  } catch (e) {
24
20
  (0, _utils.log)('ERROR in docgen-loader', e);
25
21
  }
26
- var comNameAry = undefined.resourcePath.split(_path2.default.sep);
27
- var comName = comNameAry[comNameAry.length - 1];
28
- var name = comName.substring(0, comName.lastIndexOf('.'));
29
- return source + ';' + name + '.propsObj=' + JSON.stringify(value);
22
+
23
+ let comNameAry = (void 0).resourcePath.split(_path.default.sep);
24
+ let comName = comNameAry[comNameAry.length - 1];
25
+ let name = comName.substring(0, comName.lastIndexOf('.'));
26
+ return `${source};${name}.propsObj=${JSON.stringify(value)}`;
30
27
  };
@@ -1,66 +1,64 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _path = require('path');
3
+ var _path = _interopRequireDefault(require("path"));
4
4
 
5
- var _path2 = _interopRequireDefault(_path);
5
+ var _loaderUtils = _interopRequireDefault(require("loader-utils"));
6
6
 
7
- var _loaderUtils = require('loader-utils');
8
-
9
- var _loaderUtils2 = _interopRequireDefault(_loaderUtils);
10
-
11
- var _common = require('../common');
7
+ var _common = require("../common");
12
8
 
13
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
10
 
15
11
  module.exports = function (content) {
16
- var userRequest = this._module.issuer.userRequest;
17
-
12
+ let {
13
+ userRequest
14
+ } = this._module.issuer;
18
15
  this.cacheable && this.cacheable();
16
+
19
17
  if (!this.emitFile) {
20
18
  throw new Error('emitFile is required from module system');
21
19
  }
22
20
 
23
- var options = _loaderUtils2.default.getOptions(this) || {};
24
- var query = this.resourceQuery ? _loaderUtils2.default.parseQuery(this.resourceQuery) : {};
25
-
26
- // let configKey = query.config || 'fileLoader';
21
+ let options = _loaderUtils.default.getOptions(this) || {};
22
+ let query = this.resourceQuery ? _loaderUtils.default.parseQuery(this.resourceQuery) : {}; // let configKey = query.config || 'fileLoader';
27
23
 
28
- var config = {
24
+ let config = {
29
25
  // publicPath: false,
30
26
  useRelativePath: false,
31
- name: '[hash].[ext]'
32
- // publicPathStrigify: true
33
- };
27
+ name: '[hash].[ext]' // publicPathStrigify: true
28
+
29
+ }; // options takes precedence over config
34
30
 
35
- // options takes precedence over config
36
- Object.keys(options).forEach(function (attr) {
31
+ Object.keys(options).forEach(attr => {
37
32
  config[attr] = options[attr];
38
- });
33
+ }); // query takes precedence over config and options
39
34
 
40
- // query takes precedence over config and options
41
- Object.keys(query).forEach(function (attr) {
35
+ Object.keys(query).forEach(attr => {
42
36
  config[attr] = query[attr];
43
37
  });
38
+ let context = config.context || options.context;
44
39
 
45
- var context = config.context || options.context;
46
- var url = _loaderUtils2.default.interpolateName(this, config.name, {
40
+ let url = _loaderUtils.default.interpolateName(this, config.name, {
47
41
  context: context,
48
42
  content: content,
49
43
  regExp: config.regExp
50
44
  });
51
45
 
52
- var outputPath = '';
46
+ let outputPath = '';
47
+ let filePath = this.resourcePath;
53
48
 
54
- var filePath = this.resourcePath;
55
49
  if (config.useRelativePath) {
56
- var issuerContext = this._module && this._module.issuer && this._module.issuer.context || context;
57
- var relativeUrl = issuerContext && _path2.default.relative(issuerContext, filePath).split(_path2.default.sep).join('/');
58
- var relativePath = relativeUrl && _path2.default.dirname(relativeUrl) + '/';
50
+ let issuerContext = this._module && this._module.issuer && this._module.issuer.context || context;
51
+
52
+ let relativeUrl = issuerContext && _path.default.relative(issuerContext, filePath).split(_path.default.sep).join('/');
53
+
54
+ let relativePath = relativeUrl && `${_path.default.dirname(relativeUrl)}/`;
55
+
59
56
  if (~relativePath.indexOf('../')) {
60
- outputPath = _path2.default.posix.join(outputPath, relativePath, url);
57
+ outputPath = _path.default.posix.join(outputPath, relativePath, url);
61
58
  } else {
62
59
  outputPath = relativePath + url;
63
60
  }
61
+
64
62
  url = relativePath + url;
65
63
  } else if (config.outputPath) {
66
64
  // support functions as outputPath to generate them dynamically
@@ -70,9 +68,8 @@ module.exports = function (content) {
70
68
  outputPath = url;
71
69
  }
72
70
 
73
- var requestFromJS = /\.js$/.test(userRequest);
74
- var publicPath = requestFromJS ? (0, _common.getPublicPathConfig)(url) : '__webpack_public_path__ + ' + JSON.stringify(url);
75
- // if (config.publicPath !== false) {
71
+ let requestFromJS = /\.js$/.test(userRequest);
72
+ let publicPath = requestFromJS ? (0, _common.getPublicPathConfig)(url) : `__webpack_public_path__ + ${JSON.stringify(url)}`; // if (config.publicPath !== false) {
76
73
  // // support functions as publicPath to generate them dynamically
77
74
  // if (config.publicPathStringify) {
78
75
  // publicPath = JSON.Stringify(
@@ -91,7 +88,8 @@ module.exports = function (content) {
91
88
  if (query.emitFile === undefined || query.emitFile) {
92
89
  this.emitFile(outputPath, content);
93
90
  }
94
- return 'module.exports = ' + publicPath + ';';
91
+
92
+ return `module.exports = ${publicPath};`;
95
93
  };
96
94
 
97
95
  module.exports.raw = true;
@@ -1,18 +1,16 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _esprima = require('esprima');
3
+ var esprima = _interopRequireWildcard(require("esprima"));
4
4
 
5
- var esprima = _interopRequireWildcard(_esprima);
6
-
7
- var _escodegen = require('escodegen');
8
-
9
- var _escodegen2 = _interopRequireDefault(_escodegen);
5
+ var _escodegen = _interopRequireDefault(require("escodegen"));
10
6
 
11
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
8
 
13
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
10
 
15
- var start = {
11
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
+
13
+ let start = {
16
14
  type: 'ExpressionStatement',
17
15
  expression: {
18
16
  type: 'CallExpression',
@@ -56,22 +54,28 @@ var start = {
56
54
  }
57
55
  };
58
56
 
59
- var scriptInstrumentLoader = function scriptInstrumentLoader(source) {
60
- var parsed = esprima.parseModule(source, { jsx: true });
61
- for (var i in parsed.body) {
57
+ let scriptInstrumentLoader = function (source) {
58
+ let parsed = esprima.parseModule(source, {
59
+ jsx: true
60
+ });
61
+
62
+ for (let i in parsed.body) {
62
63
  if (parsed.body[i].type === 'FunctionDeclaration' || parsed.body[i].type === 'ExportDefaultDeclaration' || parsed.body[i].type === 'ExportNamedDeclaration') {
63
- var ParsedTemp = void 0;
64
+ let ParsedTemp;
65
+
64
66
  if (parsed.body[i].type === 'FunctionDeclaration') {
65
67
  ParsedTemp = parsed.body[i];
66
68
  } else {
67
69
  ParsedTemp = parsed.body[i].declaration;
68
70
  }
71
+
69
72
  if (ParsedTemp) {
70
73
  if (ParsedTemp.id) {
71
- var funcname = ParsedTemp.id.name;
74
+ let funcname = ParsedTemp.id.name;
75
+
72
76
  if (funcname !== 'mapStateToProps') {
73
77
  if (!funcname.includes('_')) {
74
- var startFunc = JSON.parse(JSON.stringify(start));
78
+ let startFunc = JSON.parse(JSON.stringify(start));
75
79
  startFunc.expression.arguments[0].value = this.resourcePath;
76
80
  startFunc.expression.arguments[0].raw = this.resourcePath;
77
81
  startFunc.expression.arguments[1].value = funcname;
@@ -84,8 +88,7 @@ var scriptInstrumentLoader = function scriptInstrumentLoader(source) {
84
88
  }
85
89
  }
86
90
 
87
- return _escodegen2.default.generate(parsed);
88
- // function removeDuplicates(arr) {
91
+ return _escodegen.default.generate(parsed); // function removeDuplicates(arr) {
89
92
  // let uniqueArray = [];
90
93
  // for (let i = 0; i < arr.length; i++) {
91
94
  // if (uniqueArray.indexOf(arr[i]) == -1) {
@@ -97,9 +100,7 @@ var scriptInstrumentLoader = function scriptInstrumentLoader(source) {
97
100
  // funcArray = removeDuplicates(funcArray);
98
101
  };
99
102
 
100
- module.exports = scriptInstrumentLoader;
101
-
102
- // let start = {
103
+ module.exports = scriptInstrumentLoader; // let start = {
103
104
  // type: 'ExpressionStatement',
104
105
  // expression: {
105
106
  // type: 'CallExpression',
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = loader;
7
+ exports.pitch = pitch;
8
+
9
+ var _path = _interopRequireDefault(require("path"));
10
+
11
+ var _loaderUtils = require("loader-utils");
12
+
13
+ var _schemaUtils = _interopRequireDefault(require("schema-utils"));
14
+
15
+ var _SingleEntryPlugin = _interopRequireDefault(require("webpack/lib/SingleEntryPlugin"));
16
+
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+
19
+ /* import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin';
20
+ import ExternalsPlugin from 'webpack/lib/ExternalsPlugin'; */
21
+ const schema = {
22
+ 'type': 'object',
23
+ 'properties': {
24
+ 'publicPath': {
25
+ 'anyOf': [{
26
+ 'type': 'string'
27
+ }, {
28
+ 'instanceof': 'Function'
29
+ }]
30
+ },
31
+ 'filename': {
32
+ 'anyOf': [{
33
+ 'type': 'string',
34
+ 'minLength': 1
35
+ }, {
36
+ 'instanceof': 'Function'
37
+ }]
38
+ },
39
+ 'chunkFilename': {
40
+ 'type': 'string',
41
+ 'minLength': 1
42
+ },
43
+ 'esModule': {
44
+ 'type': 'boolean'
45
+ }
46
+ },
47
+ 'additionalProperties': false
48
+ }; // eslint-disable-next-line
49
+
50
+ function loader() {}
51
+
52
+ function getDefaultFilename(filename) {
53
+ if (typeof filename === 'function') {
54
+ return filename;
55
+ }
56
+
57
+ return filename.replace(/\.([a-z]+)(\?.+)?$/i, '.worker.$1$2');
58
+ }
59
+
60
+ function getDefaultChunkFilename(chunkFilename) {
61
+ return chunkFilename.replace(/\.([a-z]+)(\?.+)?$/i, '.worker.$1$2');
62
+ }
63
+
64
+ function pitch(request) {
65
+ this.cacheable(false);
66
+ const options = (0, _loaderUtils.getOptions)(this);
67
+ (0, _schemaUtils.default)(schema, options, {
68
+ name: 'Worker Loader',
69
+ baseDataPath: 'options'
70
+ });
71
+ const workerContext = {};
72
+ const compilerOptions = this._compiler.options || {};
73
+ const filename = options.filename ? options.filename : getDefaultFilename(compilerOptions.output.filename);
74
+ const chunkFilename = options.chunkFilename ? options.chunkFilename : getDefaultChunkFilename(compilerOptions.output.chunkFilename);
75
+ const publicPath = options.publicPath ? options.publicPath : compilerOptions.output.publicPath;
76
+ workerContext.options = {
77
+ filename,
78
+ chunkFilename,
79
+ publicPath,
80
+ globalObject: 'self'
81
+ };
82
+ workerContext.compiler = this._compilation.createChildCompiler(`worker-loader ${request}`, workerContext.options);
83
+ /*
84
+ new WebWorkerTemplatePlugin().apply(workerContext.compiler);
85
+
86
+ if (compilerOptions.externals) {
87
+ new ExternalsPlugin(
88
+ getExternalsType(compilerOptions),
89
+ compilerOptions.externals
90
+ ).apply(workerContext.compiler);
91
+ } */
92
+
93
+ new _SingleEntryPlugin.default(this.context, `!!${request}`, _path.default.parse(this.resourcePath).name).apply(workerContext.compiler);
94
+ workerContext.request = request;
95
+ const cb = this.async();
96
+ workerContext.compiler.runAsChild((errorArg, entries, compilation) => {
97
+ let error = errorArg;
98
+
99
+ if (!error && compilation.errors && compilation.errors.length) {
100
+ // eslint-disable-next-line
101
+ error = compilation.errors[0];
102
+ }
103
+
104
+ const entry = entries && entries[0] && entries[0].files.values().next().value;
105
+
106
+ if (!error && !entry) {
107
+ error = Error(`WorkerPlugin: no entry for ${request}`);
108
+ }
109
+
110
+ if (error) {
111
+ return cb(error);
112
+ }
113
+
114
+ function workerCode() {
115
+ let blob;
116
+
117
+ try {
118
+ blob = new Blob([`importScripts('${this.workerUrl}');`], {
119
+ 'type': 'application/javascript'
120
+ });
121
+ } catch (e1) {
122
+ throw new Error(e1);
123
+ }
124
+
125
+ let url = window.URL || window.webkitURL;
126
+ let blobUrl = url.createObjectURL(blob);
127
+ let worker = new Worker(blobUrl);
128
+ return worker;
129
+ }
130
+
131
+ return cb(null, `${options.esModule ? 'export default' : 'module.exports ='} {\n
132
+ workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
133
+ getInstance: ${workerCode} \n
134
+ }`);
135
+ });
136
+ }