@umijs/bundler-webpack 4.0.0-beta.9 → 4.0.0-rc.3

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.
Files changed (135) hide show
  1. package/compiled/autoprefixer/browserslist/index.d.ts +11 -7
  2. package/compiled/autoprefixer/index.js +3 -3
  3. package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
  4. package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
  5. package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
  6. package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
  7. package/compiled/autoprefixer/postcss/lib/declaration.d.ts +1 -1
  8. package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
  9. package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
  10. package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
  11. package/compiled/autoprefixer/postcss/lib/node.d.ts +36 -2
  12. package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
  13. package/compiled/autoprefixer/postcss/lib/processor.d.ts +5 -4
  14. package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
  15. package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
  16. package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
  17. package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
  18. package/compiled/babel-loader/index.js +2 -2
  19. package/compiled/copy-webpack-plugin/576.index.js +1171 -0
  20. package/compiled/copy-webpack-plugin/index.js +16 -10
  21. package/compiled/copy-webpack-plugin/package.json +1 -1
  22. package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
  23. package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
  24. package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
  25. package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
  26. package/compiled/cssnano/index.js +12 -11
  27. package/compiled/express/index.js +57 -74
  28. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
  29. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  30. package/compiled/fork-ts-checker-webpack-plugin/index.js +48 -0
  31. package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
  32. package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
  33. package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
  34. package/compiled/http-proxy-middleware/index.js +10 -10
  35. package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
  36. package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
  37. package/compiled/mini-css-extract-plugin/index.js +8103 -7617
  38. package/compiled/mini-css-extract-plugin/loader.js +177 -54
  39. package/compiled/mini-css-extract-plugin/package.json +1 -1
  40. package/compiled/mini-css-extract-plugin/utils.js +83 -24
  41. package/compiled/postcss-loader/index.js +1 -1
  42. package/compiled/react-refresh/index.js +3 -3
  43. package/compiled/sass-loader/index.js +1 -1
  44. package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
  45. package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
  46. package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
  47. package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
  48. package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
  49. package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
  50. package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
  51. package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
  52. package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
  53. package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
  54. package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
  55. package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
  56. package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
  57. package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
  58. package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
  59. package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
  60. package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
  61. package/compiled/schema-utils/declarations/validate.d.ts +4 -4
  62. package/compiled/schema-utils/index.js +8 -2
  63. package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
  64. package/compiled/style-loader/index.js +1 -1
  65. package/compiled/terser/index.js +1 -1
  66. package/compiled/terser-webpack-plugin/index.js +393 -517
  67. package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
  68. package/compiled/terser-webpack-plugin/minify.js +10 -3
  69. package/compiled/terser-webpack-plugin/package.json +1 -1
  70. package/compiled/terser-webpack-plugin/types/index.d.ts +183 -149
  71. package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
  72. package/compiled/terser-webpack-plugin/types/utils.d.ts +10 -15
  73. package/compiled/terser-webpack-plugin/utils.js +118 -25
  74. package/compiled/webpack/index.js +10464 -5286
  75. package/compiled/webpack-dev-middleware/index.js +11 -5
  76. package/compiled/webpack-dev-middleware/package.json +1 -1
  77. package/compiled/webpack-manifest-plugin/LICENSE +21 -0
  78. package/compiled/webpack-manifest-plugin/index.js +1 -0
  79. package/compiled/webpack-manifest-plugin/package.json +1 -0
  80. package/compiled/webpack-sources/index.js +1 -1
  81. package/compiled/ws/index.d.ts +1 -2
  82. package/compiled/ws/index.js +1 -1
  83. package/dist/build.d.ts +5 -3
  84. package/dist/build.js +2 -1
  85. package/dist/cli.js +4 -7
  86. package/dist/config/assetRules.js +6 -14
  87. package/dist/config/compressPlugin.js +6 -0
  88. package/dist/config/config.d.ts +7 -2
  89. package/dist/config/config.js +49 -7
  90. package/dist/config/cssRules.js +1 -1
  91. package/dist/config/detectDeadCode.d.ts +12 -0
  92. package/dist/config/detectDeadCode.js +120 -0
  93. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  94. package/dist/config/detectDeadCodePlugin.js +71 -0
  95. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  96. package/dist/config/forkTSCheckerPlugin.js +34 -0
  97. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  98. package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
  99. package/dist/config/javaScriptRules.d.ts +1 -0
  100. package/dist/config/javaScriptRules.js +31 -20
  101. package/dist/config/manifestPlugin.d.ts +11 -0
  102. package/dist/config/manifestPlugin.js +25 -0
  103. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  104. package/dist/config/miniCSSExtractPlugin.js +2 -3
  105. package/dist/config/svgRules.d.ts +1 -0
  106. package/dist/config/svgRules.js +17 -3
  107. package/dist/constants.d.ts +3 -0
  108. package/dist/constants.js +4 -1
  109. package/dist/dev.d.ts +4 -2
  110. package/dist/dev.js +31 -5
  111. package/dist/loader/svgr.d.ts +4 -0
  112. package/dist/loader/svgr.js +67 -0
  113. package/dist/loader/swc.d.ts +4 -0
  114. package/dist/loader/swc.js +79 -0
  115. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
  116. package/dist/plugins/ParcelCSSMinifyPlugin.js +74 -0
  117. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  118. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  119. package/dist/requireHook.js +1 -1
  120. package/dist/schema.js +14 -6
  121. package/dist/server/server.js +20 -1
  122. package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
  123. package/dist/swcPlugins/autoCSSModules.js +13 -16
  124. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  125. package/dist/swcPlugins/lockCoreJS.js +23 -0
  126. package/dist/types.d.ts +16 -0
  127. package/dist/types.js +1 -0
  128. package/dist/utils/depMatch.js +1 -1
  129. package/package.json +45 -39
  130. package/compiled/@svgr/webpack/LICENSE +0 -7
  131. package/compiled/@svgr/webpack/index.js +0 -266
  132. package/compiled/@svgr/webpack/package.json +0 -1
  133. package/compiled/swc-loader/LICENSE +0 -25
  134. package/compiled/swc-loader/index.js +0 -1
  135. package/compiled/swc-loader/package.json +0 -1
@@ -1,13 +1,5 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.terserMinify = terserMinify;
7
- exports.uglifyJsMinify = uglifyJsMinify;
8
- exports.swcMinify = swcMinify;
9
- exports.esbuildMinify = esbuildMinify;
10
-
11
3
  /** @typedef {import("source-map").RawSourceMap} RawSourceMap */
12
4
 
13
5
  /** @typedef {import("terser").FormatOptions} TerserFormatOptions */
@@ -28,14 +20,68 @@ exports.esbuildMinify = esbuildMinify;
28
20
 
29
21
  /** @typedef {import("./index.js").PredefinedOptions} PredefinedOptions */
30
22
 
23
+ /** @typedef {import("./index.js").CustomOptions} CustomOptions */
24
+
25
+ /**
26
+ * @typedef {Array<string>} ExtractedComments
27
+ */
28
+ const notSettled = Symbol(`not-settled`);
31
29
  /**
32
- * @typedef {{ [key: string]: any }} CustomOptions
30
+ * @template T
31
+ * @typedef {() => Promise<T>} Task
33
32
  */
34
33
 
35
34
  /**
36
- * @typedef {Array<string>} ExtractedComments
35
+ * Run tasks with limited concurency.
36
+ * @template T
37
+ * @param {number} limit - Limit of tasks that run at once.
38
+ * @param {Task<T>[]} tasks - List of tasks to run.
39
+ * @returns {Promise<T[]>} A promise that fulfills to an array of the results
37
40
  */
38
41
 
42
+ function throttleAll(limit, tasks) {
43
+ if (!Number.isInteger(limit) || limit < 1) {
44
+ throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`);
45
+ }
46
+
47
+ if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
48
+ throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`);
49
+ }
50
+
51
+ return new Promise((resolve, reject) => {
52
+ const result = Array(tasks.length).fill(notSettled);
53
+ const entries = tasks.entries();
54
+
55
+ const next = () => {
56
+ const {
57
+ done,
58
+ value
59
+ } = entries.next();
60
+
61
+ if (done) {
62
+ const isLast = !result.includes(notSettled);
63
+ if (isLast) resolve(
64
+ /** @type{T[]} **/
65
+ result);
66
+ return;
67
+ }
68
+
69
+ const [index, task] = value;
70
+ /**
71
+ * @param {T} x
72
+ */
73
+
74
+ const onFulfilled = x => {
75
+ result[index] = x;
76
+ next();
77
+ };
78
+
79
+ task().then(onFulfilled, reject);
80
+ };
81
+
82
+ Array(limit).fill(0).forEach(next);
83
+ });
84
+ }
39
85
  /* istanbul ignore next */
40
86
 
41
87
  /**
@@ -45,6 +91,8 @@ exports.esbuildMinify = esbuildMinify;
45
91
  * @param {ExtractCommentsOptions | undefined} extractComments
46
92
  * @return {Promise<MinimizedResult>}
47
93
  */
94
+
95
+
48
96
  async function terserMinify(input, sourceMap, minimizerOptions, extractComments) {
49
97
  /**
50
98
  * @param {any} value
@@ -117,21 +165,33 @@ async function terserMinify(input, sourceMap, minimizerOptions, extractComments)
117
165
  }
118
166
 
119
167
  if (condition[key] === "some") {
120
- condition[key] = (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
168
+ condition[key] =
169
+ /** @type {ExtractCommentsFunction} */
170
+ (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
121
171
 
122
172
  break;
123
173
  }
124
174
 
125
- regexStr = condition[key];
175
+ regexStr =
176
+ /** @type {string} */
177
+ condition[key];
126
178
 
127
- condition[key] = (astNode, comment) => new RegExp(regexStr).test(comment.value);
179
+ condition[key] =
180
+ /** @type {ExtractCommentsFunction} */
181
+ (astNode, comment) => new RegExp(
182
+ /** @type {string} */
183
+ regexStr).test(comment.value);
128
184
 
129
185
  break;
130
186
 
131
187
  default:
132
- regex = condition[key];
188
+ regex =
189
+ /** @type {RegExp} */
190
+ condition[key];
133
191
 
134
- condition[key] = (astNode, comment) =>
192
+ condition[key] =
193
+ /** @type {ExtractCommentsFunction} */
194
+ (astNode, comment) =>
135
195
  /** @type {RegExp} */
136
196
  regex.test(comment.value);
137
197
 
@@ -227,10 +287,14 @@ async function terserMinify(input, sourceMap, minimizerOptions, extractComments)
227
287
  [filename]: code
228
288
  }, terserOptions);
229
289
  return {
230
- code: result.code,
290
+ code:
291
+ /** @type {string} **/
292
+ result.code,
231
293
  // @ts-ignore
232
294
  // eslint-disable-next-line no-undefined
233
- map: result.map ? result.map : undefined,
295
+ map: result.map ?
296
+ /** @type {RawSourceMap} **/
297
+ result.map : undefined,
234
298
  extractedComments
235
299
  };
236
300
  }
@@ -324,21 +388,33 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
324
388
  }
325
389
 
326
390
  if (condition[key] === "some") {
327
- condition[key] = (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
391
+ condition[key] =
392
+ /** @type {ExtractCommentsFunction} */
393
+ (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
328
394
 
329
395
  break;
330
396
  }
331
397
 
332
- regexStr = condition[key];
398
+ regexStr =
399
+ /** @type {string} */
400
+ condition[key];
333
401
 
334
- condition[key] = (astNode, comment) => new RegExp(regexStr).test(comment.value);
402
+ condition[key] =
403
+ /** @type {ExtractCommentsFunction} */
404
+ (astNode, comment) => new RegExp(
405
+ /** @type {string} */
406
+ regexStr).test(comment.value);
335
407
 
336
408
  break;
337
409
 
338
410
  default:
339
- regex = condition[key];
411
+ regex =
412
+ /** @type {RegExp} */
413
+ condition[key];
340
414
 
341
- condition[key] = (astNode, comment) =>
415
+ condition[key] =
416
+ /** @type {ExtractCommentsFunction} */
417
+ (astNode, comment) =>
342
418
  /** @type {RegExp} */
343
419
  regex.test(comment.value);
344
420
 
@@ -556,10 +632,10 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
556
632
  }; // eslint-disable-next-line import/no-extraneous-dependencies, global-require
557
633
 
558
634
 
559
- const esbuild = require('@umijs/bundler-utils/compiled/esbuild'); // Copy `swc` options
635
+ const esbuild = require('@umijs/bundler-utils/compiled/esbuild'); // Copy `esbuild` options
560
636
 
561
637
 
562
- const esbuildOptions = buildEsbuildOptions(minimizerOptions); // Let `swc` generate a SourceMap
638
+ const esbuildOptions = buildEsbuildOptions(minimizerOptions); // Let `esbuild` generate a SourceMap
563
639
 
564
640
  if (sourceMap) {
565
641
  esbuildOptions.sourcemap = true;
@@ -573,7 +649,16 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
573
649
  code: result.code,
574
650
  // eslint-disable-next-line no-undefined
575
651
  map: result.map ? JSON.parse(result.map) : undefined,
576
- warnings: result.warnings ? result.warnings.map(item => item.toString()) : []
652
+ warnings: result.warnings.length > 0 ? result.warnings.map(item => {
653
+ return {
654
+ name: "Warning",
655
+ source: item.location && item.location.file,
656
+ line: item.location && item.location.line,
657
+ column: item.location && item.location.column,
658
+ plugin: item.pluginName,
659
+ message: `${item.text}${item.detail ? `\nDetails:\n${item.detail}` : ""}${item.notes.length > 0 ? `\n\nNotes:\n${item.notes.map(note => `${note.location ? `[${note.location.file}:${note.location.line}:${note.location.column}] ` : ""}${note.text}${note.location ? `\nSuggestion: ${note.location.suggestion}` : ""}${note.location ? `\nLine text:\n${note.location.lineText}\n` : ""}`).join("\n")}` : ""}`
660
+ };
661
+ }) : []
577
662
  };
578
663
  }
579
664
  /**
@@ -591,4 +676,12 @@ esbuildMinify.getMinimizerVersion = () => {
591
676
  }
592
677
 
593
678
  return packageJson && packageJson.version;
679
+ };
680
+
681
+ module.exports = {
682
+ throttleAll,
683
+ terserMinify,
684
+ uglifyJsMinify,
685
+ swcMinify,
686
+ esbuildMinify
594
687
  };