Skip to content

Commit

Permalink
Fix test builds
Browse files Browse the repository at this point in the history
  • Loading branch information
KTibow committed Oct 12, 2023
1 parent d818085 commit 6a37e22
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions build-scripts/lightningcss.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ function wrapCSS(text, type) {
return text;
}
function unwrapCSS(text, type) {
if (type === "inline") return text.match(/^#a\{([\s\S]*)\}$/)[1];
if (type === "media") return text.match(/^@media ?([\s\S]*?) ?{[\s\S]*}$/)[1];
if (type === "inline") return text.match(/^#a ?\{([\s\S]*)\}$/m)[1];
if (type === "media")
return text.match(/^@media ?([\s\S]*?) ?{[\s\S]*}$/m)[1];
return text;
}

Expand All @@ -28,36 +29,39 @@ module.exports.getMinifyCSS = ({ latestBuild, isProdBuild }) => {
return (text, type) => {
if (!text) return text;
const input = wrapCSS(text, type);
if (text.includes("babel-plugin-template-html-minifier")) {
const { styles: ccss, errors, warnings: w1 } = cleanCSS.minify(input);
if (!text.includes("babel-plugin-template-html-minifier")) {
const { code, warnings: w1 } = lightningcss.transform({
filename: "style.css",
code: Buffer.from(input),
minify: isProdBuild,
targets: cssTargets,
});
if (w1.length > 0) {
console.warn("[LCSS] Warnings while transforming CSS:", ...w1);
}
const lcss = decoder.decode(code);
try {
return unwrapCSS(lcss, type);
} catch (e) {
console.error("[LCSS] Invalid output", { text, type, output: lcss, e });
return text;
}
}
if (isProdBuild) {
const { styles: ccss, errors, warnings: w2 } = cleanCSS.minify(input);
if (errors.length > 0) {
console.error("[CCSS] Errors while transforming CSS:", ...errors);
}
if (w1.length > 0) {
console.warn("[CCSS] Warnings while transforming CSS:", ...w1);
if (w2.length > 0) {
console.warn("[CCSS] Warnings while transforming CSS:", ...w2);
}
try {
return unwrapCSS(ccss, type);
} catch (e) {
console.error("[CCSS] Invalid output", { text, type, output: ccss });
console.error("[CCSS] Invalid output", { text, type, output: ccss, e });
return text;
}
}
const { code, warnings: w2 } = lightningcss.transform({
filename: "style.css",
code: Buffer.from(input),
minify: isProdBuild,
targets: cssTargets,
});
if (w2.length > 0) {
console.warn("[LCSS] Warnings while transforming CSS:", ...w2);
}
const lcss = decoder.decode(code);
try {
return unwrapCSS(lcss, type);
} catch (e) {
console.error("[LCSS] Invalid output", { text, type, output: lcss });
return text;
}
return text;
};
};

0 comments on commit 6a37e22

Please sign in to comment.