@umijs/bundler-webpack 4.0.0-beta.8 → 4.0.0-canary-20240513.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 (297) hide show
  1. package/client/client/client.js +255 -167
  2. package/client/constants.d.ts +15 -0
  3. package/client/constants.js +30 -12
  4. package/client/utils/formatWebpackMessages.d.ts +12 -0
  5. package/client/utils/formatWebpackMessages.js +87 -86
  6. package/compiled/autoprefixer/browserslist/index.d.ts +33 -7
  7. package/compiled/autoprefixer/index.js +3 -3
  8. package/compiled/autoprefixer/package.json +1 -1
  9. package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
  10. package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
  11. package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
  12. package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
  13. package/compiled/autoprefixer/postcss/lib/declaration.d.ts +2 -2
  14. package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
  15. package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
  16. package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
  17. package/compiled/autoprefixer/postcss/lib/node.d.ts +38 -4
  18. package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
  19. package/compiled/autoprefixer/postcss/lib/processor.d.ts +6 -5
  20. package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
  21. package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
  22. package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
  23. package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
  24. package/compiled/babel-loader/index.js +8 -2
  25. package/compiled/babel-loader/package.json +1 -1
  26. package/compiled/copy-webpack-plugin/939.index.js +1171 -0
  27. package/compiled/copy-webpack-plugin/index.js +16 -10
  28. package/compiled/copy-webpack-plugin/package.json +1 -1
  29. package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
  30. package/compiled/css-minimizer-webpack-plugin/minify.js +23 -22
  31. package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
  32. package/compiled/css-minimizer-webpack-plugin/utils.js +305 -54
  33. package/compiled/cssnano/index.js +12 -11
  34. package/compiled/cssnano/package.json +1 -1
  35. package/compiled/express.d.ts +2 -0
  36. package/compiled/file-loader/index.js +3 -0
  37. package/compiled/file-loader/package.json +1 -0
  38. package/compiled/less-loader/index.js +1 -1
  39. package/compiled/less-loader/package.json +1 -1
  40. package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -46
  41. package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +10 -6
  42. package/compiled/mini-css-extract-plugin/index.js +10669 -10348
  43. package/compiled/mini-css-extract-plugin/loader.js +159 -100
  44. package/compiled/mini-css-extract-plugin/package.json +1 -1
  45. package/compiled/mini-css-extract-plugin/utils.js +88 -44
  46. package/compiled/postcss-loader/index.js +1 -1
  47. package/compiled/postcss-loader/package.json +1 -1
  48. package/compiled/sass-loader/index.js +1 -1
  49. package/compiled/sass-loader/package.json +1 -1
  50. package/compiled/sass-loader/sass.default.dart.js +4 -0
  51. package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
  52. package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
  53. package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
  54. package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
  55. package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
  56. package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
  57. package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
  58. package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
  59. package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
  60. package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
  61. package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
  62. package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
  63. package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
  64. package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
  65. package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
  66. package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
  67. package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
  68. package/compiled/schema-utils/declarations/validate.d.ts +4 -4
  69. package/compiled/schema-utils/index.js +8 -2
  70. package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
  71. package/compiled/style-loader/index.js +1 -1
  72. package/compiled/stylus-loader/LICENSE +20 -0
  73. package/compiled/stylus-loader/index.js +44 -0
  74. package/compiled/stylus-loader/package.json +1 -0
  75. package/compiled/terser/@jridgewell/gen-mapping/dist/types/gen-mapping.d.ts +90 -0
  76. package/compiled/terser/@jridgewell/gen-mapping/dist/types/sourcemap-segment.d.ts +12 -0
  77. package/compiled/terser/@jridgewell/gen-mapping/dist/types/types.d.ts +35 -0
  78. package/compiled/terser/@jridgewell/source-map/dist/types/source-map.d.ts +25 -0
  79. package/compiled/terser/@jridgewell/trace-mapping/dist/types/sourcemap-segment.d.ts +16 -0
  80. package/compiled/terser/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts +74 -0
  81. package/compiled/terser/@jridgewell/trace-mapping/dist/types/types.d.ts +92 -0
  82. package/compiled/terser/index.js +1 -1
  83. package/compiled/terser/package.json +1 -1
  84. package/compiled/terser/tools/terser.d.ts +6 -3
  85. package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/sourcemap-segment.d.ts +16 -0
  86. package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts +74 -0
  87. package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/types.d.ts +92 -0
  88. package/compiled/terser-webpack-plugin/index.js +1390 -3693
  89. package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
  90. package/compiled/terser-webpack-plugin/minify.js +10 -3
  91. package/compiled/terser-webpack-plugin/package.json +1 -1
  92. package/compiled/terser-webpack-plugin/types/index.d.ts +186 -152
  93. package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
  94. package/compiled/terser-webpack-plugin/types/utils.d.ts +20 -24
  95. package/compiled/terser-webpack-plugin/utils.js +153 -34
  96. package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
  97. package/compiled/webpack/BasicEvaluatedExpression.js +1 -0
  98. package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
  99. package/compiled/webpack/ExternalsPlugin.js +1 -0
  100. package/compiled/webpack/FetchCompileAsyncWasmPlugin.js +1 -0
  101. package/compiled/webpack/FetchCompileWasmPlugin.js +1 -0
  102. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  103. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  104. package/compiled/webpack/LimitChunkCountPlugin.js +1 -0
  105. package/compiled/webpack/NodeTargetPlugin.js +1 -0
  106. package/compiled/webpack/NodeTemplatePlugin.js +1 -0
  107. package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
  108. package/compiled/webpack/RuleSetCompiler.js +1 -0
  109. package/compiled/webpack/StringXor.js +1 -0
  110. package/compiled/webpack/UseEffectRulePlugin.js +1 -0
  111. package/compiled/webpack/WebWorkerTemplatePlugin.js +1 -0
  112. package/compiled/webpack/deepImports.json +15 -1
  113. package/compiled/webpack/index.js +26404 -10329
  114. package/compiled/webpack/json-schema/index.d.ts +8 -1
  115. package/compiled/webpack/lazy-compilation-node.js +10 -0
  116. package/compiled/webpack/lazy-compilation-web.js +9 -0
  117. package/compiled/webpack/types.d.ts +823 -287
  118. package/compiled/webpack-5-chain/index.js +1 -1
  119. package/compiled/webpack-5-chain/package.json +1 -1
  120. package/compiled/webpack-5-chain/types/index.d.ts +76 -20
  121. package/compiled/webpack-bundle-analyzer/index.js +7 -6
  122. package/compiled/webpack-bundle-analyzer/package.json +1 -1
  123. package/compiled/webpack-bundle-analyzer/public/viewer.js +2 -2
  124. package/compiled/webpack-bundle-analyzer/public/viewer.js.map +1 -1
  125. package/compiled/webpack-dev-middleware/index.js +12 -5
  126. package/compiled/webpack-dev-middleware/package.json +1 -1
  127. package/compiled/{tapable → webpack-manifest-plugin}/LICENSE +2 -2
  128. package/compiled/webpack-manifest-plugin/index.js +1 -0
  129. package/compiled/webpack-manifest-plugin/package.json +1 -0
  130. package/compiled/webpack-sources/index.js +1 -1
  131. package/compiled/{express → webpackbar}/LICENSE +1 -5
  132. package/compiled/webpackbar/dist/index.d.ts +121 -0
  133. package/compiled/webpackbar/index.js +7 -0
  134. package/compiled/webpackbar/package.json +1 -0
  135. package/compiled/ws/LICENSE +13 -12
  136. package/compiled/ws/index.d.ts +74 -35
  137. package/compiled/ws/index.js +1 -1
  138. package/compiled/ws/package.json +1 -1
  139. package/dist/build.d.ts +8 -3
  140. package/dist/build.js +147 -68
  141. package/dist/cli.d.ts +0 -1
  142. package/dist/cli.js +84 -81
  143. package/dist/config/_sampleFeature.js +33 -20
  144. package/dist/config/assetRules.js +46 -55
  145. package/dist/config/bundleAnalyzerPlugin.js +41 -28
  146. package/dist/config/compressPlugin.js +125 -74
  147. package/dist/config/config.d.ts +11 -2
  148. package/dist/config/config.js +235 -172
  149. package/dist/config/copyPlugin.js +61 -47
  150. package/dist/config/cssRules.js +162 -95
  151. package/dist/config/definePlugin.d.ts +2 -0
  152. package/dist/config/definePlugin.js +59 -39
  153. package/dist/config/detectCssModulesInDependence.d.ts +10 -0
  154. package/dist/config/detectCssModulesInDependence.js +151 -0
  155. package/dist/config/detectDeadCode.d.ts +12 -0
  156. package/dist/config/detectDeadCode.js +191 -0
  157. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  158. package/dist/config/detectDeadCodePlugin.js +82 -0
  159. package/dist/config/fastRefreshPlugin.js +46 -31
  160. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  161. package/dist/config/forkTSCheckerPlugin.js +49 -0
  162. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  163. package/dist/config/harmonyLinkingErrorPlugin.js +53 -0
  164. package/dist/config/ignorePlugin.js +38 -25
  165. package/dist/config/javaScriptRules.d.ts +2 -0
  166. package/dist/config/javaScriptRules.js +186 -150
  167. package/dist/config/manifestPlugin.d.ts +11 -0
  168. package/dist/config/manifestPlugin.js +40 -0
  169. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  170. package/dist/config/miniCSSExtractPlugin.js +52 -31
  171. package/dist/config/nodePolyfill.js +49 -32
  172. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  173. package/dist/config/nodePrefixPlugin.js +38 -0
  174. package/dist/config/progressPlugin.js +50 -24
  175. package/dist/config/purgecssWebpackPlugin.js +41 -30
  176. package/dist/config/speedMeasureWebpackPlugin.js +56 -31
  177. package/dist/config/ssrPlugin.d.ts +11 -0
  178. package/dist/config/ssrPlugin.js +98 -0
  179. package/dist/config/svgRules.d.ts +1 -0
  180. package/dist/config/svgRules.js +68 -54
  181. package/dist/constants.d.ts +4 -0
  182. package/dist/constants.js +59 -15
  183. package/dist/dev.d.ts +23 -3
  184. package/dist/dev.js +198 -81
  185. package/dist/index.d.ts +6 -2
  186. package/dist/index.js +31 -15
  187. package/dist/loader/svgr.d.ts +4 -0
  188. package/dist/loader/svgr.js +84 -0
  189. package/dist/loader/swc.d.ts +4 -0
  190. package/dist/loader/swc.js +149 -0
  191. package/dist/parcelCSS.d.ts +2 -0
  192. package/dist/parcelCSS.js +39 -0
  193. package/dist/plugins/EsbuildMinifyFix.d.ts +8 -0
  194. package/dist/plugins/EsbuildMinifyFix.js +136 -0
  195. package/dist/plugins/ProgressPlugin.js +68 -43
  196. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  197. package/dist/plugins/RuntimePublicPathPlugin.js +45 -0
  198. package/dist/plugins/_SamplePlugin.d.ts +1 -1
  199. package/dist/plugins/_SamplePlugin.js +37 -14
  200. package/dist/requireHook.js +44 -27
  201. package/dist/schema.d.ts +4 -3
  202. package/dist/schema.js +175 -69
  203. package/dist/server/server.d.ts +4 -3
  204. package/dist/server/server.js +219 -154
  205. package/dist/server/ws.d.ts +8 -3
  206. package/dist/server/ws.js +72 -38
  207. package/dist/swcPlugins/autoCSSModules.d.ts +11 -2
  208. package/dist/swcPlugins/autoCSSModules.js +60 -32
  209. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  210. package/dist/swcPlugins/changeImportFromString.js +32 -0
  211. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  212. package/dist/swcPlugins/lockCoreJS.js +56 -0
  213. package/dist/types.d.ts +53 -9
  214. package/dist/types.js +61 -29
  215. package/dist/utils/browsersList.js +31 -8
  216. package/dist/utils/depMatch.js +65 -39
  217. package/dist/utils/formatWebpackMessages.js +119 -91
  218. package/dist/utils/getEsBuildTarget.d.ts +7 -0
  219. package/dist/utils/getEsBuildTarget.js +46 -0
  220. package/dist/utils/pkgUpContainsName.d.ts +1 -0
  221. package/dist/utils/pkgUpContainsName.js +50 -0
  222. package/package.json +89 -81
  223. package/compiled/@svgr/webpack/.svgo.yml +0 -75
  224. package/compiled/@svgr/webpack/LICENSE +0 -7
  225. package/compiled/@svgr/webpack/index.js +0 -343
  226. package/compiled/@svgr/webpack/package.json +0 -1
  227. package/compiled/css-loader/api.js +0 -102
  228. package/compiled/css-loader/getUrl.js +0 -29
  229. package/compiled/css-loader/index.js +0 -2
  230. package/compiled/css-loader/noSourceMaps.js +0 -5
  231. package/compiled/css-loader/package.json +0 -1
  232. package/compiled/css-loader/sourceMaps.js +0 -22
  233. package/compiled/express/body-parser/index.d.ts +0 -104
  234. package/compiled/express/connect/index.d.ts +0 -93
  235. package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
  236. package/compiled/express/index.d.ts +0 -133
  237. package/compiled/express/index.js +0 -338
  238. package/compiled/express/mime/index.d.ts +0 -35
  239. package/compiled/express/package.json +0 -1
  240. package/compiled/express/qs/index.d.ts +0 -62
  241. package/compiled/express/range-parser/index.d.ts +0 -35
  242. package/compiled/express/serve-static/index.d.ts +0 -108
  243. package/compiled/http-proxy-middleware/LICENSE +0 -22
  244. package/compiled/http-proxy-middleware/dist/index.d.ts +0 -4
  245. package/compiled/http-proxy-middleware/dist/types.d.ts +0 -54
  246. package/compiled/http-proxy-middleware/http-proxy/index.d.ts +0 -226
  247. package/compiled/http-proxy-middleware/index.js +0 -66
  248. package/compiled/http-proxy-middleware/package.json +0 -1
  249. package/compiled/less/index.js +0 -31
  250. package/compiled/less/package.json +0 -1
  251. package/compiled/react-refresh/index.js +0 -19
  252. package/compiled/swc-loader/LICENSE +0 -25
  253. package/compiled/swc-loader/index.js +0 -1
  254. package/compiled/swc-loader/package.json +0 -1
  255. package/compiled/tapable/index.js +0 -1
  256. package/compiled/tapable/package.json +0 -1
  257. package/compiled/tapable/tapable.d.ts +0 -116
  258. package/dist/build.d.ts.map +0 -1
  259. package/dist/cli.d.ts.map +0 -1
  260. package/dist/client/client.d.ts.map +0 -1
  261. package/dist/client/client.js +0 -239
  262. package/dist/config/_sampleFeature.d.ts.map +0 -1
  263. package/dist/config/assetRules.d.ts.map +0 -1
  264. package/dist/config/bundleAnalyzerPlugin.d.ts.map +0 -1
  265. package/dist/config/compressPlugin.d.ts.map +0 -1
  266. package/dist/config/config.d.ts.map +0 -1
  267. package/dist/config/copyPlugin.d.ts.map +0 -1
  268. package/dist/config/cssRules.d.ts.map +0 -1
  269. package/dist/config/definePlugin.d.ts.map +0 -1
  270. package/dist/config/fastRefreshPlugin.d.ts.map +0 -1
  271. package/dist/config/ignorePlugin.d.ts.map +0 -1
  272. package/dist/config/javaScriptRules.d.ts.map +0 -1
  273. package/dist/config/miniCSSExtractPlugin.d.ts.map +0 -1
  274. package/dist/config/nodePolyfill.d.ts.map +0 -1
  275. package/dist/config/progressPlugin.d.ts.map +0 -1
  276. package/dist/config/purgecssWebpackPlugin.d.ts.map +0 -1
  277. package/dist/config/speedMeasureWebpackPlugin.d.ts.map +0 -1
  278. package/dist/config/svgRules.d.ts.map +0 -1
  279. package/dist/constants.d.ts.map +0 -1
  280. package/dist/dev.d.ts.map +0 -1
  281. package/dist/index.d.ts.map +0 -1
  282. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
  283. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts.map +0 -1
  284. package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -65
  285. package/dist/plugins/ProgressPlugin.d.ts.map +0 -1
  286. package/dist/plugins/_SamplePlugin.d.ts.map +0 -1
  287. package/dist/requireHook.d.ts.map +0 -1
  288. package/dist/schema.d.ts.map +0 -1
  289. package/dist/server/server.d.ts.map +0 -1
  290. package/dist/server/ws.d.ts.map +0 -1
  291. package/dist/swcPlugins/autoCSSModules.d.ts.map +0 -1
  292. package/dist/types.d.ts.map +0 -1
  293. package/dist/utils/browsersList.d.ts.map +0 -1
  294. package/dist/utils/depMatch.d.ts.map +0 -1
  295. package/dist/utils/formatWebpackMessages.d.ts.map +0 -1
  296. /package/{dist → client}/client/client.d.ts +0 -0
  297. /package/compiled/{css-loader → file-loader}/LICENSE +0 -0
@@ -1,17 +1,26 @@
1
1
  "use strict";
2
2
 
3
+ /** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
4
+ /** @typedef {import("./index.js").InternalResult} InternalResult */
5
+
6
+ /**
7
+ * @template T
8
+ * @param {import("./index.js").InternalOptions<T>} options
9
+ * @returns {Promise<InternalResult>}
10
+ */
3
11
  const minify = async options => {
4
- const minifyFns = typeof options.minify === "function" ? [options.minify] : options.minify;
12
+ const minifyFns = Array.isArray(options.minimizer.implementation) ? options.minimizer.implementation : [options.minimizer.implementation];
13
+
14
+ /** @type {InternalResult} */
5
15
  const result = {
6
16
  outputs: [],
7
17
  warnings: [],
8
18
  errors: []
9
19
  };
10
20
  let needSourceMap = false;
11
-
12
21
  for (let i = 0; i <= minifyFns.length - 1; i++) {
13
22
  const minifyFn = minifyFns[i];
14
- const minifyOptions = Array.isArray(options.minifyOptions) ? options.minifyOptions[i] : options.minifyOptions;
23
+ const minifyOptions = Array.isArray(options.minimizer.options) ? options.minimizer.options[i] : options.minimizer.options;
15
24
  const prevResult = result.outputs.length > 0 ? result.outputs[result.outputs.length - 1] : {
16
25
  code: options.input,
17
26
  map: options.inputSourceMap
@@ -19,54 +28,46 @@ const minify = async options => {
19
28
  const {
20
29
  code,
21
30
  map
22
- } = prevResult; // eslint-disable-next-line no-await-in-loop
23
-
31
+ } = prevResult;
32
+ // eslint-disable-next-line no-await-in-loop
24
33
  const minifyResult = await minifyFn({
25
34
  [options.name]: code
26
35
  }, map, minifyOptions);
27
-
28
36
  if (typeof minifyResult.code !== "string") {
29
37
  throw new Error("minimizer function doesn't return the 'code' property or result is not a string value");
30
38
  }
31
-
32
39
  if (minifyResult.map) {
33
40
  needSourceMap = true;
34
41
  }
35
-
36
42
  if (minifyResult.errors) {
37
43
  result.errors = result.errors.concat(minifyResult.errors);
38
44
  }
39
-
40
45
  if (minifyResult.warnings) {
41
46
  result.warnings = result.warnings.concat(minifyResult.warnings);
42
47
  }
43
-
44
48
  result.outputs.push({
45
49
  code: minifyResult.code,
46
50
  map: minifyResult.map
47
51
  });
48
52
  }
49
-
50
53
  if (!needSourceMap) {
51
54
  result.outputs = [result.outputs[result.outputs.length - 1]];
52
55
  }
53
-
54
56
  return result;
55
57
  };
56
58
 
59
+ /**
60
+ * @param {string} options
61
+ * @returns {Promise<InternalResult>}
62
+ */
57
63
  async function transform(options) {
58
64
  // 'use strict' => this === undefined (Clean Scope)
59
65
  // Safer for possible security issues, albeit not critical at all here
60
66
  // eslint-disable-next-line no-new-func, no-param-reassign
61
67
  const evaluatedOptions = new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
62
- const result = await minify(evaluatedOptions);
63
-
64
- if (result.error) {
65
- throw result.error;
66
- } else {
67
- return result;
68
- }
68
+ return minify(evaluatedOptions);
69
69
  }
70
-
71
- module.exports.minify = minify;
72
- module.exports.transform = transform;
70
+ module.exports = {
71
+ minify,
72
+ transform
73
+ };
@@ -1 +1 @@
1
- {"name":"css-minimizer-webpack-plugin","author":"Loann Neveu","license":"MIT"}
1
+ {"name":"css-minimizer-webpack-plugin","version":"5.0.1","author":"Loann Neveu","license":"MIT","types":"types/index.d.ts"}
@@ -1,137 +1,231 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.cssnanoMinify = cssnanoMinify;
7
- exports.cssoMinify = cssoMinify;
8
- exports.cleanCssMinify = cleanCssMinify;
9
- exports.esbuildMinify = esbuildMinify;
3
+ /** @typedef {import("./index.js").Input} Input */
4
+ /** @typedef {import("@jridgewell/trace-mapping").EncodedSourceMap} RawSourceMap */
5
+ /** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
6
+ /** @typedef {import("./index.js").CustomOptions} CustomOptions */
7
+ /** @typedef {import("postcss").ProcessOptions} ProcessOptions */
8
+ /** @typedef {import("postcss").Postcss} Postcss */
9
+
10
+ const notSettled = Symbol(`not-settled`);
11
+
12
+ /**
13
+ * @template T
14
+ * @typedef {() => Promise<T>} Task
15
+ */
16
+
17
+ /**
18
+ * Run tasks with limited concurrency.
19
+ * @template T
20
+ * @param {number} limit - Limit of tasks that run at once.
21
+ * @param {Task<T>[]} tasks - List of tasks to run.
22
+ * @returns {Promise<T[]>} A promise that fulfills to an array of the results
23
+ */
24
+ function throttleAll(limit, tasks) {
25
+ if (!Number.isInteger(limit) || limit < 1) {
26
+ throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`);
27
+ }
28
+ if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
29
+ throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`);
30
+ }
31
+ return new Promise((resolve, reject) => {
32
+ const result = Array(tasks.length).fill(notSettled);
33
+ const entries = tasks.entries();
34
+ const next = () => {
35
+ const {
36
+ done,
37
+ value
38
+ } = entries.next();
39
+ if (done) {
40
+ const isLast = !result.includes(notSettled);
41
+ if (isLast) resolve(result);
42
+ return;
43
+ }
44
+ const [index, task] = value;
45
+
46
+ /**
47
+ * @param {T} x
48
+ */
49
+ const onFulfilled = x => {
50
+ result[index] = x;
51
+ next();
52
+ };
53
+ task().then(onFulfilled, reject);
54
+ };
55
+ Array(limit).fill(0).forEach(next);
56
+ });
57
+ }
10
58
 
11
59
  /* istanbul ignore next */
12
- async function cssnanoMinify(input, inputSourceMap, minimizerOptions = {
60
+ /**
61
+ * @param {Input} input
62
+ * @param {RawSourceMap | undefined} sourceMap
63
+ * @param {CustomOptions} minimizerOptions
64
+ * @return {Promise<MinimizedResult>}
65
+ */
66
+ async function cssnanoMinify(input, sourceMap, minimizerOptions = {
13
67
  preset: "default"
14
68
  }) {
69
+ /**
70
+ * @template T
71
+ * @param {string} module
72
+ * @returns {Promise<T>}
73
+ */
15
74
  const load = async module => {
16
75
  let exports;
17
-
18
76
  try {
19
77
  // eslint-disable-next-line import/no-dynamic-require, global-require
20
78
  exports = require(module);
21
79
  return exports;
22
80
  } catch (requireError) {
23
81
  let importESM;
24
-
25
82
  try {
26
83
  // eslint-disable-next-line no-new-func
27
84
  importESM = new Function("id", "return import(id);");
28
85
  } catch (e) {
29
86
  importESM = null;
30
87
  }
31
-
32
- if (requireError.code === "ERR_REQUIRE_ESM" && importESM) {
88
+ if ( /** @type {Error & {code: string}} */
89
+ requireError.code === "ERR_REQUIRE_ESM" && importESM) {
33
90
  exports = await importESM(module);
34
91
  return exports.default;
35
92
  }
36
-
37
93
  throw requireError;
38
94
  }
39
95
  };
40
-
41
96
  const [[name, code]] = Object.entries(input);
97
+ /** @type {ProcessOptions} */
42
98
  const postcssOptions = {
43
- to: name,
44
99
  from: name,
45
100
  ...minimizerOptions.processorOptions
46
101
  };
47
-
48
102
  if (typeof postcssOptions.parser === "string") {
49
103
  try {
50
104
  postcssOptions.parser = await load(postcssOptions.parser);
51
105
  } catch (error) {
52
- throw new Error(`Loading PostCSS "${postcssOptions.parser}" parser failed: ${error.message}\n\n(@${name})`);
106
+ throw new Error(`Loading PostCSS "${postcssOptions.parser}" parser failed: ${
107
+ /** @type {Error} */error.message}\n\n(@${name})`);
53
108
  }
54
109
  }
55
-
56
110
  if (typeof postcssOptions.stringifier === "string") {
57
111
  try {
58
112
  postcssOptions.stringifier = await load(postcssOptions.stringifier);
59
113
  } catch (error) {
60
- throw new Error(`Loading PostCSS "${postcssOptions.stringifier}" stringifier failed: ${error.message}\n\n(@${name})`);
114
+ throw new Error(`Loading PostCSS "${postcssOptions.stringifier}" stringifier failed: ${
115
+ /** @type {Error} */error.message}\n\n(@${name})`);
61
116
  }
62
117
  }
63
-
64
118
  if (typeof postcssOptions.syntax === "string") {
65
119
  try {
66
120
  postcssOptions.syntax = await load(postcssOptions.syntax);
67
121
  } catch (error) {
68
- throw new Error(`Loading PostCSS "${postcssOptions.syntax}" syntax failed: ${error.message}\n\n(@${name})`);
122
+ throw new Error(`Loading PostCSS "${postcssOptions.syntax}" syntax failed: ${
123
+ /** @type {Error} */error.message}\n\n(@${name})`);
69
124
  }
70
125
  }
71
-
72
- if (inputSourceMap) {
126
+ if (sourceMap) {
73
127
  postcssOptions.map = {
74
128
  annotation: false
75
129
  };
76
- } // eslint-disable-next-line global-require
77
-
78
-
79
- const postcss = require('postcss'); // eslint-disable-next-line global-require
80
-
130
+ }
81
131
 
132
+ /** @type {Postcss} */
133
+ // eslint-disable-next-line global-require
134
+ const postcss = require('postcss').default;
135
+ // @ts-ignore
136
+ // eslint-disable-next-line global-require
82
137
  const cssnano = require('@umijs/bundler-webpack/compiled/cssnano');
83
-
138
+ // @ts-ignore
139
+ // Types are broken
84
140
  const result = await postcss([cssnano(minimizerOptions)]).process(code, postcssOptions);
85
141
  return {
86
142
  code: result.css,
87
- map: result.map && result.map.toString(),
143
+ // @ts-ignore
144
+ map: result.map ? result.map.toJSON() :
145
+ // eslint-disable-next-line no-undefined
146
+ undefined,
88
147
  warnings: result.warnings().map(String)
89
148
  };
90
149
  }
91
- /* istanbul ignore next */
92
-
93
150
 
94
- async function cssoMinify(input, inputSourceMap, minimizerOptions) {
151
+ /* istanbul ignore next */
152
+ /**
153
+ * @param {Input} input
154
+ * @param {RawSourceMap | undefined} sourceMap
155
+ * @param {CustomOptions} minimizerOptions
156
+ * @return {Promise<MinimizedResult>}
157
+ */
158
+ async function cssoMinify(input, sourceMap, minimizerOptions) {
95
159
  // eslint-disable-next-line global-require,import/no-extraneous-dependencies
96
160
  const csso = require("csso");
97
-
98
161
  const [[filename, code]] = Object.entries(input);
99
162
  const result = csso.minify(code, {
100
163
  filename,
101
- sourceMap: Boolean(inputSourceMap),
164
+ sourceMap: Boolean(sourceMap),
102
165
  ...minimizerOptions
103
166
  });
104
167
  return {
105
168
  code: result.css,
106
- map: result.map && result.map.toJSON()
169
+ map: result.map ? /** @type {any & { toJSON(): RawSourceMap }} */
170
+ result.map.toJSON() :
171
+ // eslint-disable-next-line no-undefined
172
+ undefined
107
173
  };
108
174
  }
109
- /* istanbul ignore next */
110
-
111
175
 
112
- async function cleanCssMinify(input, inputSourceMap, minimizerOptions) {
176
+ /* istanbul ignore next */
177
+ /**
178
+ * @param {Input} input
179
+ * @param {RawSourceMap | undefined} sourceMap
180
+ * @param {CustomOptions} minimizerOptions
181
+ * @return {Promise<MinimizedResult>}
182
+ */
183
+ async function cleanCssMinify(input, sourceMap, minimizerOptions) {
113
184
  // eslint-disable-next-line global-require,import/no-extraneous-dependencies
114
185
  const CleanCSS = require("clean-css");
115
-
116
186
  const [[name, code]] = Object.entries(input);
117
187
  const result = await new CleanCSS({
118
- sourceMap: Boolean(inputSourceMap),
119
- ...minimizerOptions
188
+ sourceMap: Boolean(sourceMap),
189
+ ...minimizerOptions,
190
+ returnPromise: true
120
191
  }).minify({
121
192
  [name]: {
122
193
  styles: code
123
194
  }
124
195
  });
196
+ const generatedSourceMap = result.sourceMap && /** @type {any & { toJSON(): RawSourceMap }} */
197
+ result.sourceMap.toJSON();
198
+
199
+ // workaround for source maps on windows
200
+ if (generatedSourceMap) {
201
+ // eslint-disable-next-line global-require
202
+ const isWindowsPathSep = require("path").sep === "\\";
203
+ generatedSourceMap.sources = generatedSourceMap.sources.map(
204
+ /**
205
+ * @param {string} item
206
+ * @returns {string}
207
+ */
208
+ item => isWindowsPathSep ? item.replace(/\\/g, "/") : item);
209
+ }
125
210
  return {
126
211
  code: result.styles,
127
- map: result.sourceMap && result.sourceMap.toJSON(),
212
+ map: generatedSourceMap,
128
213
  warnings: result.warnings
129
214
  };
130
215
  }
131
- /* istanbul ignore next */
132
-
133
216
 
217
+ /* istanbul ignore next */
218
+ /**
219
+ * @param {Input} input
220
+ * @param {RawSourceMap | undefined} sourceMap
221
+ * @param {CustomOptions} minimizerOptions
222
+ * @return {Promise<MinimizedResult>}
223
+ */
134
224
  async function esbuildMinify(input, sourceMap, minimizerOptions) {
225
+ /**
226
+ * @param {import("esbuild").TransformOptions} [esbuildOptions={}]
227
+ * @returns {import("esbuild").TransformOptions}
228
+ */
135
229
  const buildEsbuildOptions = (esbuildOptions = {}) => {
136
230
  // Need deep copy objects to avoid https://github.com/terser/terser/issues/366
137
231
  return {
@@ -141,26 +235,183 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
141
235
  ...esbuildOptions,
142
236
  sourcemap: false
143
237
  };
144
- }; // eslint-disable-next-line import/no-extraneous-dependencies, global-require
145
-
146
-
147
- const esbuild = require('@umijs/bundler-utils/compiled/esbuild'); // Copy `esbuild` options
238
+ };
148
239
 
240
+ // eslint-disable-next-line import/no-extraneous-dependencies, global-require
241
+ const esbuild = require('@umijs/bundler-utils/compiled/esbuild');
149
242
 
150
- const esbuildOptions = buildEsbuildOptions(minimizerOptions); // Let `esbuild` generate a SourceMap
243
+ // Copy `esbuild` options
244
+ const esbuildOptions = buildEsbuildOptions(minimizerOptions);
151
245
 
246
+ // Let `esbuild` generate a SourceMap
152
247
  if (sourceMap) {
153
248
  esbuildOptions.sourcemap = true;
154
249
  esbuildOptions.sourcesContent = false;
155
250
  }
156
-
157
251
  const [[filename, code]] = Object.entries(input);
158
252
  esbuildOptions.sourcefile = filename;
159
253
  const result = await esbuild.transform(code, esbuildOptions);
160
254
  return {
161
255
  code: result.code,
162
256
  // eslint-disable-next-line no-undefined
163
- map: result.map ? result.map : undefined,
164
- warnings: result.warnings ? result.warnings.map(item => item.toString()) : []
257
+ map: result.map ? JSON.parse(result.map) : undefined,
258
+ warnings: result.warnings.length > 0 ? result.warnings.map(item => {
259
+ return {
260
+ source: item.location && item.location.file,
261
+ line: item.location && item.location.line ? item.location.line :
262
+ // eslint-disable-next-line no-undefined
263
+ undefined,
264
+ column: item.location && item.location.column ? item.location.column :
265
+ // eslint-disable-next-line no-undefined
266
+ undefined,
267
+ plugin: item.pluginName,
268
+ 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")}` : ""}`
269
+ };
270
+ }) : []
271
+ };
272
+ }
273
+
274
+ // TODO remove in the next major release
275
+ /* istanbul ignore next */
276
+ /**
277
+ * @param {Input} input
278
+ * @param {RawSourceMap | undefined} sourceMap
279
+ * @param {CustomOptions} minimizerOptions
280
+ * @return {Promise<MinimizedResult>}
281
+ */
282
+ async function parcelCssMinify(input, sourceMap, minimizerOptions) {
283
+ const [[filename, code]] = Object.entries(input);
284
+ /**
285
+ * @param {Partial<import("@parcel/css").TransformOptions<any>>} [parcelCssOptions={}]
286
+ * @returns {import("@parcel/css").TransformOptions<any>}
287
+ */
288
+ const buildParcelCssOptions = (parcelCssOptions = {}) => {
289
+ // Need deep copy objects to avoid https://github.com/terser/terser/issues/366
290
+ return {
291
+ minify: true,
292
+ ...parcelCssOptions,
293
+ sourceMap: false,
294
+ filename,
295
+ code: Buffer.from(code)
296
+ };
297
+ };
298
+
299
+ // eslint-disable-next-line import/no-extraneous-dependencies, global-require
300
+ const parcelCss = require("@parcel/css");
301
+
302
+ // Copy `parcel-css` options
303
+ const parcelCssOptions = buildParcelCssOptions(minimizerOptions);
304
+
305
+ // Let `esbuild` generate a SourceMap
306
+ if (sourceMap) {
307
+ parcelCssOptions.sourceMap = true;
308
+ }
309
+ const result = await parcelCss.transform(parcelCssOptions);
310
+ return {
311
+ code: result.code.toString(),
312
+ // eslint-disable-next-line no-undefined
313
+ map: result.map ? JSON.parse(result.map.toString()) : undefined
165
314
  };
166
- }
315
+ }
316
+
317
+ /* istanbul ignore next */
318
+ /**
319
+ * @param {Input} input
320
+ * @param {RawSourceMap | undefined} sourceMap
321
+ * @param {CustomOptions} minimizerOptions
322
+ * @return {Promise<MinimizedResult>}
323
+ */
324
+ async function lightningCssMinify(input, sourceMap, minimizerOptions) {
325
+ const [[filename, code]] = Object.entries(input);
326
+ /**
327
+ * @param {Partial<import("lightningcss").TransformOptions<any>>} [lightningCssOptions={}]
328
+ * @returns {import("lightningcss").TransformOptions<any>}
329
+ */
330
+ const buildLightningCssOptions = (lightningCssOptions = {}) => {
331
+ // Need deep copy objects to avoid https://github.com/terser/terser/issues/366
332
+ return {
333
+ minify: true,
334
+ ...lightningCssOptions,
335
+ sourceMap: false,
336
+ filename,
337
+ code: Buffer.from(code)
338
+ };
339
+ };
340
+
341
+ // eslint-disable-next-line import/no-extraneous-dependencies, global-require
342
+ const lightningCss = require("lightningcss");
343
+
344
+ // Copy `lightningCss` options
345
+ const lightningCssOptions = buildLightningCssOptions(minimizerOptions);
346
+
347
+ // Let `esbuild` generate a SourceMap
348
+ if (sourceMap) {
349
+ lightningCssOptions.sourceMap = true;
350
+ }
351
+ const result = await lightningCss.transform(lightningCssOptions);
352
+ return {
353
+ code: result.code.toString(),
354
+ // eslint-disable-next-line no-undefined
355
+ map: result.map ? JSON.parse(result.map.toString()) : undefined
356
+ };
357
+ }
358
+
359
+ /* istanbul ignore next */
360
+ /**
361
+ * @param {Input} input
362
+ * @param {RawSourceMap | undefined} sourceMap
363
+ * @param {CustomOptions} minimizerOptions
364
+ * @return {Promise<MinimizedResult>}
365
+ */
366
+ async function swcMinify(input, sourceMap, minimizerOptions) {
367
+ const [[filename, code]] = Object.entries(input);
368
+ /**
369
+ * @param {Partial<import("@swc/css").Options>} [swcOptions={}]
370
+ * @returns {import("@swc/css").Options}
371
+ */
372
+ const buildSwcOptions = (swcOptions = {}) => {
373
+ // Need deep copy objects to avoid https://github.com/terser/terser/issues/366
374
+ return {
375
+ ...swcOptions,
376
+ filename
377
+ };
378
+ };
379
+
380
+ // eslint-disable-next-line import/no-extraneous-dependencies, global-require
381
+ const swc = require("@swc/css");
382
+
383
+ // Copy `swc` options
384
+ const swcOptions = buildSwcOptions(minimizerOptions);
385
+
386
+ // Let `swc` generate a SourceMap
387
+ if (sourceMap) {
388
+ swcOptions.sourceMap = true;
389
+ }
390
+ const result = await swc.minify(Buffer.from(code), swcOptions);
391
+ return {
392
+ code: result.code.toString(),
393
+ // eslint-disable-next-line no-undefined
394
+ map: result.map ? JSON.parse(result.map.toString()) : undefined,
395
+ errors: result.errors ? result.errors.map(diagnostic => {
396
+ const error = new Error(diagnostic.message);
397
+
398
+ // @ts-ignore
399
+ error.span = diagnostic.span;
400
+ // @ts-ignore
401
+ error.level = diagnostic.level;
402
+ return error;
403
+ }) :
404
+ // eslint-disable-next-line no-undefined
405
+ undefined
406
+ };
407
+ }
408
+ module.exports = {
409
+ throttleAll,
410
+ cssnanoMinify,
411
+ cssoMinify,
412
+ cleanCssMinify,
413
+ esbuildMinify,
414
+ parcelCssMinify,
415
+ lightningCssMinify,
416
+ swcMinify
417
+ };