Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dep: upgrade webpack css mini plugin and lightningcss #11877

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"use strict";

/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */

/** @typedef {import("source-map").RawSourceMap} RawSourceMap */

/** @typedef {import("./index.js").InternalResult} InternalResult */

/**
Expand All @@ -13,15 +10,14 @@
*/
const minify = async options => {
const minifyFns = Array.isArray(options.minimizer.implementation) ? options.minimizer.implementation : [options.minimizer.implementation];
/** @type {InternalResult} */

/** @type {InternalResult} */
const result = {
outputs: [],
warnings: [],
errors: []
};
let needSourceMap = false;

for (let i = 0; i <= minifyFns.length - 1; i++) {
const minifyFn = minifyFns[i];
const minifyOptions = Array.isArray(options.minimizer.options) ? options.minimizer.options[i] : options.minimizer.options;
Expand All @@ -32,54 +28,45 @@ const minify = async options => {
const {
code,
map
} = prevResult; // eslint-disable-next-line no-await-in-loop

} = prevResult;
// eslint-disable-next-line no-await-in-loop
const minifyResult = await minifyFn({
[options.name]: code
}, map, minifyOptions);

if (typeof minifyResult.code !== "string") {
throw new Error("minimizer function doesn't return the 'code' property or result is not a string value");
}

if (minifyResult.map) {
needSourceMap = true;
}

if (minifyResult.errors) {
result.errors = result.errors.concat(minifyResult.errors);
}

if (minifyResult.warnings) {
result.warnings = result.warnings.concat(minifyResult.warnings);
}

result.outputs.push({
code: minifyResult.code,
map: minifyResult.map
});
}

if (!needSourceMap) {
result.outputs = [result.outputs[result.outputs.length - 1]];
}

return result;
};

/**
* @param {string} options
* @returns {Promise<InternalResult>}
*/


async function transform(options) {
// 'use strict' => this === undefined (Clean Scope)
// Safer for possible security issues, albeit not critical at all here
// eslint-disable-next-line no-new-func, no-param-reassign
const evaluatedOptions = new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
return minify(evaluatedOptions);
}

module.exports = {
minify,
transform
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"css-minimizer-webpack-plugin","author":"Loann Neveu","license":"MIT","types":"types/index.d.ts"}
{"name":"css-minimizer-webpack-plugin","version":"5.0.1","author":"Loann Neveu","license":"MIT","types":"types/index.d.ts"}
Loading
Loading