@umijs/bundler-webpack 4.0.0-beta.9 → 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.
- package/client/client/client.js +255 -167
- package/client/constants.d.ts +15 -0
- package/client/constants.js +30 -12
- package/client/utils/formatWebpackMessages.d.ts +12 -0
- package/client/utils/formatWebpackMessages.js +87 -86
- package/compiled/autoprefixer/browserslist/index.d.ts +33 -7
- package/compiled/autoprefixer/index.js +3 -3
- package/compiled/autoprefixer/package.json +1 -1
- package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
- package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
- package/compiled/autoprefixer/postcss/lib/declaration.d.ts +2 -2
- package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
- package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
- package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
- package/compiled/autoprefixer/postcss/lib/node.d.ts +38 -4
- package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
- package/compiled/autoprefixer/postcss/lib/processor.d.ts +6 -5
- package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
- package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
- package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
- package/compiled/babel-loader/index.js +8 -2
- package/compiled/babel-loader/package.json +1 -1
- package/compiled/copy-webpack-plugin/939.index.js +1171 -0
- package/compiled/copy-webpack-plugin/index.js +16 -10
- package/compiled/copy-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
- package/compiled/css-minimizer-webpack-plugin/minify.js +23 -22
- package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/utils.js +305 -54
- package/compiled/cssnano/index.js +12 -11
- package/compiled/cssnano/package.json +1 -1
- package/compiled/express.d.ts +2 -0
- package/compiled/file-loader/index.js +3 -0
- package/compiled/file-loader/package.json +1 -0
- package/compiled/less-loader/index.js +1 -1
- package/compiled/less-loader/package.json +1 -1
- package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -46
- package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +10 -6
- package/compiled/mini-css-extract-plugin/index.js +10669 -10348
- package/compiled/mini-css-extract-plugin/loader.js +159 -100
- package/compiled/mini-css-extract-plugin/package.json +1 -1
- package/compiled/mini-css-extract-plugin/utils.js +88 -44
- package/compiled/postcss-loader/index.js +1 -1
- package/compiled/postcss-loader/package.json +1 -1
- package/compiled/sass-loader/index.js +1 -1
- package/compiled/sass-loader/package.json +1 -1
- package/compiled/sass-loader/sass.default.dart.js +4 -0
- package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
- package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
- package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
- package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
- package/compiled/schema-utils/declarations/validate.d.ts +4 -4
- package/compiled/schema-utils/index.js +8 -2
- package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/style-loader/index.js +1 -1
- package/compiled/stylus-loader/LICENSE +20 -0
- package/compiled/stylus-loader/index.js +44 -0
- package/compiled/stylus-loader/package.json +1 -0
- package/compiled/terser/@jridgewell/gen-mapping/dist/types/gen-mapping.d.ts +90 -0
- package/compiled/terser/@jridgewell/gen-mapping/dist/types/sourcemap-segment.d.ts +12 -0
- package/compiled/terser/@jridgewell/gen-mapping/dist/types/types.d.ts +35 -0
- package/compiled/terser/@jridgewell/source-map/dist/types/source-map.d.ts +25 -0
- package/compiled/terser/@jridgewell/trace-mapping/dist/types/sourcemap-segment.d.ts +16 -0
- package/compiled/terser/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts +74 -0
- package/compiled/terser/@jridgewell/trace-mapping/dist/types/types.d.ts +92 -0
- package/compiled/terser/index.js +1 -1
- package/compiled/terser/package.json +1 -1
- package/compiled/terser/tools/terser.d.ts +6 -3
- package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/sourcemap-segment.d.ts +16 -0
- package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts +74 -0
- package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/types.d.ts +92 -0
- package/compiled/terser-webpack-plugin/index.js +1390 -3693
- package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
- package/compiled/terser-webpack-plugin/minify.js +10 -3
- package/compiled/terser-webpack-plugin/package.json +1 -1
- package/compiled/terser-webpack-plugin/types/index.d.ts +186 -152
- package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
- package/compiled/terser-webpack-plugin/types/utils.d.ts +20 -24
- package/compiled/terser-webpack-plugin/utils.js +153 -34
- package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
- package/compiled/webpack/BasicEvaluatedExpression.js +1 -0
- package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
- package/compiled/webpack/ExternalsPlugin.js +1 -0
- package/compiled/webpack/FetchCompileAsyncWasmPlugin.js +1 -0
- package/compiled/webpack/FetchCompileWasmPlugin.js +1 -0
- package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
- package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/compiled/webpack/LimitChunkCountPlugin.js +1 -0
- package/compiled/webpack/NodeTargetPlugin.js +1 -0
- package/compiled/webpack/NodeTemplatePlugin.js +1 -0
- package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
- package/compiled/webpack/RuleSetCompiler.js +1 -0
- package/compiled/webpack/StringXor.js +1 -0
- package/compiled/webpack/UseEffectRulePlugin.js +1 -0
- package/compiled/webpack/WebWorkerTemplatePlugin.js +1 -0
- package/compiled/webpack/deepImports.json +15 -1
- package/compiled/webpack/index.js +26404 -10329
- package/compiled/webpack/json-schema/index.d.ts +8 -1
- package/compiled/webpack/lazy-compilation-node.js +10 -0
- package/compiled/webpack/lazy-compilation-web.js +9 -0
- package/compiled/webpack/types.d.ts +823 -287
- package/compiled/webpack-5-chain/index.js +1 -1
- package/compiled/webpack-5-chain/package.json +1 -1
- package/compiled/webpack-5-chain/types/index.d.ts +76 -20
- package/compiled/webpack-bundle-analyzer/index.js +7 -6
- package/compiled/webpack-bundle-analyzer/package.json +1 -1
- package/compiled/webpack-bundle-analyzer/public/viewer.js +2 -2
- package/compiled/webpack-bundle-analyzer/public/viewer.js.map +1 -1
- package/compiled/webpack-dev-middleware/index.js +12 -5
- package/compiled/webpack-dev-middleware/package.json +1 -1
- package/compiled/{tapable → webpack-manifest-plugin}/LICENSE +2 -2
- package/compiled/webpack-manifest-plugin/index.js +1 -0
- package/compiled/webpack-manifest-plugin/package.json +1 -0
- package/compiled/webpack-sources/index.js +1 -1
- package/compiled/{express → webpackbar}/LICENSE +1 -5
- package/compiled/webpackbar/dist/index.d.ts +121 -0
- package/compiled/webpackbar/index.js +7 -0
- package/compiled/webpackbar/package.json +1 -0
- package/compiled/ws/LICENSE +13 -12
- package/compiled/ws/index.d.ts +74 -35
- package/compiled/ws/index.js +1 -1
- package/compiled/ws/package.json +1 -1
- package/dist/build.d.ts +8 -3
- package/dist/build.js +147 -68
- package/dist/cli.js +84 -81
- package/dist/config/_sampleFeature.js +33 -20
- package/dist/config/assetRules.js +46 -67
- package/dist/config/bundleAnalyzerPlugin.js +41 -28
- package/dist/config/compressPlugin.js +125 -74
- package/dist/config/config.d.ts +11 -2
- package/dist/config/config.js +235 -172
- package/dist/config/copyPlugin.js +61 -47
- package/dist/config/cssRules.js +162 -95
- package/dist/config/definePlugin.d.ts +2 -0
- package/dist/config/definePlugin.js +59 -39
- package/dist/config/detectCssModulesInDependence.d.ts +10 -0
- package/dist/config/detectCssModulesInDependence.js +151 -0
- package/dist/config/detectDeadCode.d.ts +12 -0
- package/dist/config/detectDeadCode.js +191 -0
- package/dist/config/detectDeadCodePlugin.d.ts +9 -0
- package/dist/config/detectDeadCodePlugin.js +82 -0
- package/dist/config/fastRefreshPlugin.js +46 -31
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +49 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +53 -0
- package/dist/config/ignorePlugin.js +38 -25
- package/dist/config/javaScriptRules.d.ts +2 -0
- package/dist/config/javaScriptRules.js +186 -150
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +40 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
- package/dist/config/miniCSSExtractPlugin.js +52 -31
- package/dist/config/nodePolyfill.js +49 -32
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +38 -0
- package/dist/config/progressPlugin.js +50 -24
- package/dist/config/purgecssWebpackPlugin.js +41 -30
- package/dist/config/speedMeasureWebpackPlugin.js +56 -31
- package/dist/config/ssrPlugin.d.ts +11 -0
- package/dist/config/ssrPlugin.js +98 -0
- package/dist/config/svgRules.d.ts +1 -0
- package/dist/config/svgRules.js +68 -41
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +59 -15
- package/dist/dev.d.ts +23 -2
- package/dist/dev.js +198 -81
- package/dist/index.d.ts +6 -1
- package/dist/index.js +31 -15
- package/dist/loader/svgr.d.ts +4 -0
- package/dist/loader/svgr.js +84 -0
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +149 -0
- package/dist/parcelCSS.d.ts +2 -0
- package/dist/parcelCSS.js +39 -0
- package/dist/plugins/EsbuildMinifyFix.d.ts +8 -0
- package/dist/plugins/EsbuildMinifyFix.js +136 -0
- package/dist/plugins/ProgressPlugin.js +68 -43
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
- package/dist/plugins/RuntimePublicPathPlugin.js +45 -0
- package/dist/plugins/_SamplePlugin.d.ts +1 -1
- package/dist/plugins/_SamplePlugin.js +37 -14
- package/dist/requireHook.js +44 -27
- package/dist/schema.d.ts +4 -3
- package/dist/schema.js +175 -69
- package/dist/server/server.d.ts +4 -3
- package/dist/server/server.js +219 -154
- package/dist/server/ws.d.ts +8 -3
- package/dist/server/ws.js +72 -38
- package/dist/swcPlugins/autoCSSModules.d.ts +11 -2
- package/dist/swcPlugins/autoCSSModules.js +60 -32
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +32 -0
- package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
- package/dist/swcPlugins/lockCoreJS.js +56 -0
- package/dist/types.d.ts +53 -9
- package/dist/types.js +61 -29
- package/dist/utils/browsersList.js +31 -8
- package/dist/utils/depMatch.js +65 -39
- package/dist/utils/formatWebpackMessages.js +119 -91
- package/dist/utils/getEsBuildTarget.d.ts +7 -0
- package/dist/utils/getEsBuildTarget.js +46 -0
- package/dist/utils/pkgUpContainsName.d.ts +1 -0
- package/dist/utils/pkgUpContainsName.js +50 -0
- package/package.json +76 -68
- package/compiled/@svgr/webpack/LICENSE +0 -7
- package/compiled/@svgr/webpack/index.js +0 -266
- package/compiled/@svgr/webpack/package.json +0 -1
- package/compiled/css-loader/api.js +0 -102
- package/compiled/css-loader/getUrl.js +0 -29
- package/compiled/css-loader/index.js +0 -2
- package/compiled/css-loader/noSourceMaps.js +0 -5
- package/compiled/css-loader/package.json +0 -1
- package/compiled/css-loader/sourceMaps.js +0 -22
- package/compiled/express/body-parser/index.d.ts +0 -104
- package/compiled/express/connect/index.d.ts +0 -93
- package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
- package/compiled/express/index.d.ts +0 -133
- package/compiled/express/index.js +0 -338
- package/compiled/express/mime/index.d.ts +0 -35
- package/compiled/express/package.json +0 -1
- package/compiled/express/qs/index.d.ts +0 -62
- package/compiled/express/range-parser/index.d.ts +0 -35
- package/compiled/express/serve-static/index.d.ts +0 -108
- package/compiled/http-proxy-middleware/LICENSE +0 -22
- package/compiled/http-proxy-middleware/dist/index.d.ts +0 -4
- package/compiled/http-proxy-middleware/dist/types.d.ts +0 -54
- package/compiled/http-proxy-middleware/http-proxy/index.d.ts +0 -226
- package/compiled/http-proxy-middleware/index.js +0 -66
- package/compiled/http-proxy-middleware/package.json +0 -1
- package/compiled/less/index.js +0 -31
- package/compiled/less/package.json +0 -1
- package/compiled/react-refresh/index.js +0 -19
- package/compiled/swc-loader/LICENSE +0 -25
- package/compiled/swc-loader/index.js +0 -1
- package/compiled/swc-loader/package.json +0 -1
- package/compiled/tapable/index.js +0 -1
- package/compiled/tapable/package.json +0 -1
- package/compiled/tapable/tapable.d.ts +0 -116
- package/dist/client/client.js +0 -239
- package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -65
- /package/{dist → client}/client/client.d.ts +0 -0
- /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 =
|
|
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.
|
|
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;
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
if (result.error) {
|
|
65
|
-
throw result.error;
|
|
66
|
-
} else {
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
68
|
+
return minify(evaluatedOptions);
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
164
|
+
sourceMap: Boolean(sourceMap),
|
|
102
165
|
...minimizerOptions
|
|
103
166
|
});
|
|
104
167
|
return {
|
|
105
168
|
code: result.css,
|
|
106
|
-
map: result.map
|
|
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
|
-
|
|
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(
|
|
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:
|
|
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
|
-
};
|
|
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
|
-
|
|
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 =>
|
|
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
|
+
};
|