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

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 (101) hide show
  1. package/compiled/autoprefixer/browserslist/index.d.ts +7 -7
  2. package/compiled/autoprefixer/index.js +3 -3
  3. package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
  4. package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
  5. package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
  6. package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
  7. package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
  8. package/compiled/autoprefixer/postcss/lib/node.d.ts +36 -2
  9. package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
  10. package/compiled/autoprefixer/postcss/lib/processor.d.ts +5 -4
  11. package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
  12. package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
  13. package/compiled/babel-loader/index.js +2 -2
  14. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
  15. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  16. package/compiled/fork-ts-checker-webpack-plugin/index.js +49 -0
  17. package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
  18. package/compiled/mini-css-extract-plugin/index.js +6769 -6731
  19. package/compiled/mini-css-extract-plugin/loader.js +1 -1
  20. package/compiled/mini-css-extract-plugin/utils.js +11 -6
  21. package/compiled/postcss-loader/index.js +1 -1
  22. package/compiled/react-refresh/index.js +3 -3
  23. package/compiled/sass-loader/index.js +1 -1
  24. package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
  25. package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
  26. package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
  27. package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
  28. package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
  29. package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
  30. package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
  31. package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
  32. package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
  33. package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
  34. package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
  35. package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
  36. package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
  37. package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
  38. package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
  39. package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
  40. package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
  41. package/compiled/schema-utils/declarations/validate.d.ts +4 -4
  42. package/compiled/schema-utils/index.js +8 -2
  43. package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
  44. package/compiled/style-loader/index.js +1 -1
  45. package/compiled/terser/index.js +1 -1
  46. package/compiled/terser-webpack-plugin/index.js +328 -451
  47. package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
  48. package/compiled/terser-webpack-plugin/minify.js +6 -1
  49. package/compiled/terser-webpack-plugin/types/index.d.ts +3 -3
  50. package/compiled/terser-webpack-plugin/types/utils.d.ts +9 -12
  51. package/compiled/terser-webpack-plugin/utils.js +113 -17
  52. package/compiled/webpack/index.js +4915 -4485
  53. package/compiled/webpack-dev-middleware/index.js +11 -5
  54. package/compiled/webpack-manifest-plugin/LICENSE +21 -0
  55. package/compiled/webpack-manifest-plugin/index.js +1 -0
  56. package/compiled/webpack-manifest-plugin/package.json +1 -0
  57. package/compiled/webpack-sources/index.js +1 -1
  58. package/dist/build.d.ts +3 -2
  59. package/dist/build.js +1 -0
  60. package/dist/cli.js +4 -7
  61. package/dist/config/assetRules.js +6 -14
  62. package/dist/config/config.d.ts +7 -2
  63. package/dist/config/config.js +45 -4
  64. package/dist/config/cssRules.js +1 -1
  65. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  66. package/dist/config/forkTSCheckerPlugin.js +34 -0
  67. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  68. package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
  69. package/dist/config/javaScriptRules.d.ts +1 -0
  70. package/dist/config/javaScriptRules.js +33 -19
  71. package/dist/config/manifestPlugin.d.ts +11 -0
  72. package/dist/config/manifestPlugin.js +25 -0
  73. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  74. package/dist/config/miniCSSExtractPlugin.js +2 -3
  75. package/dist/config/svgRules.d.ts +1 -0
  76. package/dist/config/svgRules.js +17 -3
  77. package/dist/dev.d.ts +3 -2
  78. package/dist/dev.js +29 -5
  79. package/dist/esbuildHandler/autoCssModules.d.ts +2 -0
  80. package/dist/esbuildHandler/autoCssModules.js +23 -0
  81. package/dist/loader/esbuild.d.ts +5 -0
  82. package/dist/loader/esbuild.js +53 -0
  83. package/dist/loader/svgr.d.ts +4 -0
  84. package/dist/loader/svgr.js +67 -0
  85. package/dist/loader/swc.d.ts +4 -0
  86. package/dist/loader/swc.js +83 -0
  87. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  88. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  89. package/dist/schema.js +11 -5
  90. package/dist/server/server.js +20 -1
  91. package/dist/swcPlugins/autoCSSModules.js +6 -4
  92. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  93. package/dist/swcPlugins/lockCoreJS.js +23 -0
  94. package/dist/types.d.ts +18 -0
  95. package/package.json +36 -31
  96. package/compiled/@svgr/webpack/LICENSE +0 -7
  97. package/compiled/@svgr/webpack/index.js +0 -266
  98. package/compiled/@svgr/webpack/package.json +0 -1
  99. package/compiled/swc-loader/LICENSE +0 -25
  100. package/compiled/swc-loader/index.js +0 -1
  101. package/compiled/swc-loader/package.json +0 -1
@@ -86,6 +86,7 @@ export declare type WorkerOptions = {
86
86
  setupArgs: Array<unknown>;
87
87
  maxRetries: number;
88
88
  workerId: number;
89
+ workerData?: unknown;
89
90
  workerPath: string;
90
91
  };
91
92
  export declare type MessagePort = typeof EventEmitter & {
@@ -34,7 +34,12 @@ async function transform(options) {
34
34
  // 'use strict' => this === undefined (Clean Scope)
35
35
  // Safer for possible security issues, albeit not critical at all here
36
36
  // eslint-disable-next-line no-param-reassign
37
- const evaluatedOptions = // eslint-disable-next-line no-new-func
37
+ const evaluatedOptions =
38
+ /**
39
+ * @template T
40
+ * @type {import("./index.js").InternalOptions<T>}
41
+ * */
42
+ // eslint-disable-next-line no-new-func
38
43
  new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
39
44
  return minify(evaluatedOptions);
40
45
  }
@@ -222,16 +222,16 @@ declare class TerserPlugin<T = TerserOptions> {
222
222
  * @private
223
223
  * @param {Error | string} warning
224
224
  * @param {string} file
225
- * @returns {WebpackError}
225
+ * @returns {Error}
226
226
  */
227
227
  private static buildWarning;
228
228
  /**
229
229
  * @private
230
230
  * @param {any} error
231
231
  * @param {string} file
232
- * @param {Compilation["requestShortener"]} [requestShortener]
233
232
  * @param {SourceMapConsumer} [sourceMap]
234
- * @returns {WebpackError}
233
+ * @param {Compilation["requestShortener"]} [requestShortener]
234
+ * @returns {Error}
235
235
  */
236
236
  private static buildError;
237
237
  /**
@@ -1,3 +1,4 @@
1
+ export type Task<T> = () => Promise<T>;
1
2
  export type RawSourceMap = import('../source-map').RawSourceMap;
2
3
  export type TerserFormatOptions = import('../../terser').FormatOptions;
3
4
  export type TerserOptions = import('../../terser').MinifyOptions;
@@ -15,22 +16,18 @@ export type CustomOptions = {
15
16
  [key: string]: any;
16
17
  };
17
18
  export type ExtractedComments = Array<string>;
18
- /** @typedef {import('../source-map').RawSourceMap} RawSourceMap */
19
- /** @typedef {import('../../terser').FormatOptions} TerserFormatOptions */
20
- /** @typedef {import('../../terser').MinifyOptions} TerserOptions */
21
- /** @typedef {import('../../terser').ECMA} TerserECMA */
22
- /** @typedef {import('./index').ExtractCommentsOptions} ExtractCommentsOptions */
23
- /** @typedef {import('./index').ExtractCommentsFunction} ExtractCommentsFunction */
24
- /** @typedef {import('./index').ExtractCommentsCondition} ExtractCommentsCondition */
25
- /** @typedef {import('./index').Input} Input */
26
- /** @typedef {import('./index').MinimizedResult} MinimizedResult */
27
- /** @typedef {import('./index').PredefinedOptions} PredefinedOptions */
28
19
  /**
29
- * @typedef {{ [key: string]: any }} CustomOptions
20
+ * @template T
21
+ * @typedef {() => Promise<T>} Task
30
22
  */
31
23
  /**
32
- * @typedef {Array<string>} ExtractedComments
24
+ * Run tasks with limited concurency.
25
+ * @template T
26
+ * @param {number} limit - Limit of tasks that run at once.
27
+ * @param {Task<T>[]} tasks - List of tasks to run.
28
+ * @returns {Promise<T[]>} A promise that fulfills to an array of the results
33
29
  */
30
+ export function throttleAll<T>(limit: number, tasks: Task<T>[]): Promise<T[]>;
34
31
  /**
35
32
  * @param {Input} input
36
33
  * @param {RawSourceMap | undefined} sourceMap
@@ -3,10 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.esbuildMinify = esbuildMinify;
7
+ exports.swcMinify = swcMinify;
6
8
  exports.terserMinify = terserMinify;
9
+ exports.throttleAll = throttleAll;
7
10
  exports.uglifyJsMinify = uglifyJsMinify;
8
- exports.swcMinify = swcMinify;
9
- exports.esbuildMinify = esbuildMinify;
10
11
 
11
12
  /** @typedef {import("source-map").RawSourceMap} RawSourceMap */
12
13
 
@@ -35,7 +36,63 @@ exports.esbuildMinify = esbuildMinify;
35
36
  /**
36
37
  * @typedef {Array<string>} ExtractedComments
37
38
  */
39
+ const notSettled = Symbol(`not-settled`);
40
+ /**
41
+ * @template T
42
+ * @typedef {() => Promise<T>} Task
43
+ */
44
+
45
+ /**
46
+ * Run tasks with limited concurency.
47
+ * @template T
48
+ * @param {number} limit - Limit of tasks that run at once.
49
+ * @param {Task<T>[]} tasks - List of tasks to run.
50
+ * @returns {Promise<T[]>} A promise that fulfills to an array of the results
51
+ */
52
+
53
+ function throttleAll(limit, tasks) {
54
+ if (!Number.isInteger(limit) || limit < 1) {
55
+ throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`);
56
+ }
57
+
58
+ if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
59
+ throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`);
60
+ }
38
61
 
62
+ return new Promise((resolve, reject) => {
63
+ const result = Array(tasks.length).fill(notSettled);
64
+ const entries = tasks.entries();
65
+
66
+ const next = () => {
67
+ const {
68
+ done,
69
+ value
70
+ } = entries.next();
71
+
72
+ if (done) {
73
+ const isLast = !result.includes(notSettled);
74
+ if (isLast) resolve(
75
+ /** @type{T[]} **/
76
+ result);
77
+ return;
78
+ }
79
+
80
+ const [index, task] = value;
81
+ /**
82
+ * @param {T} x
83
+ */
84
+
85
+ const onFulfilled = x => {
86
+ result[index] = x;
87
+ next();
88
+ };
89
+
90
+ task().then(onFulfilled, reject);
91
+ };
92
+
93
+ Array(limit).fill(0).forEach(next);
94
+ });
95
+ }
39
96
  /* istanbul ignore next */
40
97
 
41
98
  /**
@@ -45,6 +102,8 @@ exports.esbuildMinify = esbuildMinify;
45
102
  * @param {ExtractCommentsOptions | undefined} extractComments
46
103
  * @return {Promise<MinimizedResult>}
47
104
  */
105
+
106
+
48
107
  async function terserMinify(input, sourceMap, minimizerOptions, extractComments) {
49
108
  /**
50
109
  * @param {any} value
@@ -117,21 +176,33 @@ async function terserMinify(input, sourceMap, minimizerOptions, extractComments)
117
176
  }
118
177
 
119
178
  if (condition[key] === "some") {
120
- condition[key] = (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
179
+ condition[key] =
180
+ /** @type {ExtractCommentsFunction} */
181
+ (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
121
182
 
122
183
  break;
123
184
  }
124
185
 
125
- regexStr = condition[key];
186
+ regexStr =
187
+ /** @type {string} */
188
+ condition[key];
126
189
 
127
- condition[key] = (astNode, comment) => new RegExp(regexStr).test(comment.value);
190
+ condition[key] =
191
+ /** @type {ExtractCommentsFunction} */
192
+ (astNode, comment) => new RegExp(
193
+ /** @type {string} */
194
+ regexStr).test(comment.value);
128
195
 
129
196
  break;
130
197
 
131
198
  default:
132
- regex = condition[key];
199
+ regex =
200
+ /** @type {RegExp} */
201
+ condition[key];
133
202
 
134
- condition[key] = (astNode, comment) =>
203
+ condition[key] =
204
+ /** @type {ExtractCommentsFunction} */
205
+ (astNode, comment) =>
135
206
  /** @type {RegExp} */
136
207
  regex.test(comment.value);
137
208
 
@@ -227,10 +298,14 @@ async function terserMinify(input, sourceMap, minimizerOptions, extractComments)
227
298
  [filename]: code
228
299
  }, terserOptions);
229
300
  return {
230
- code: result.code,
301
+ code:
302
+ /** @type {string} **/
303
+ result.code,
231
304
  // @ts-ignore
232
305
  // eslint-disable-next-line no-undefined
233
- map: result.map ? result.map : undefined,
306
+ map: result.map ?
307
+ /** @type {RawSourceMap} **/
308
+ result.map : undefined,
234
309
  extractedComments
235
310
  };
236
311
  }
@@ -324,21 +399,33 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
324
399
  }
325
400
 
326
401
  if (condition[key] === "some") {
327
- condition[key] = (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
402
+ condition[key] =
403
+ /** @type {ExtractCommentsFunction} */
404
+ (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
328
405
 
329
406
  break;
330
407
  }
331
408
 
332
- regexStr = condition[key];
409
+ regexStr =
410
+ /** @type {string} */
411
+ condition[key];
333
412
 
334
- condition[key] = (astNode, comment) => new RegExp(regexStr).test(comment.value);
413
+ condition[key] =
414
+ /** @type {ExtractCommentsFunction} */
415
+ (astNode, comment) => new RegExp(
416
+ /** @type {string} */
417
+ regexStr).test(comment.value);
335
418
 
336
419
  break;
337
420
 
338
421
  default:
339
- regex = condition[key];
422
+ regex =
423
+ /** @type {RegExp} */
424
+ condition[key];
340
425
 
341
- condition[key] = (astNode, comment) =>
426
+ condition[key] =
427
+ /** @type {ExtractCommentsFunction} */
428
+ (astNode, comment) =>
342
429
  /** @type {RegExp} */
343
430
  regex.test(comment.value);
344
431
 
@@ -556,10 +643,10 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
556
643
  }; // eslint-disable-next-line import/no-extraneous-dependencies, global-require
557
644
 
558
645
 
559
- const esbuild = require('@umijs/bundler-utils/compiled/esbuild'); // Copy `swc` options
646
+ const esbuild = require('@umijs/bundler-utils/compiled/esbuild'); // Copy `esbuild` options
560
647
 
561
648
 
562
- const esbuildOptions = buildEsbuildOptions(minimizerOptions); // Let `swc` generate a SourceMap
649
+ const esbuildOptions = buildEsbuildOptions(minimizerOptions); // Let `esbuild` generate a SourceMap
563
650
 
564
651
  if (sourceMap) {
565
652
  esbuildOptions.sourcemap = true;
@@ -573,7 +660,16 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
573
660
  code: result.code,
574
661
  // eslint-disable-next-line no-undefined
575
662
  map: result.map ? JSON.parse(result.map) : undefined,
576
- warnings: result.warnings ? result.warnings.map(item => item.toString()) : []
663
+ warnings: result.warnings.length > 0 ? result.warnings.map(item => {
664
+ return {
665
+ name: "Warning",
666
+ source: item.location && item.location.file,
667
+ line: item.location && item.location.line,
668
+ column: item.location && item.location.column,
669
+ plugin: item.pluginName,
670
+ 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")}` : ""}`
671
+ };
672
+ }) : []
577
673
  };
578
674
  }
579
675
  /**