diff --git a/gulpfile.mjs b/gulpfile.mjs index 4efed955d..154b6ec3d 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -27,6 +27,7 @@ import { mkdirp } from "mkdirp"; import path from "path"; import postcss from "gulp-postcss"; import postcssDirPseudoClass from "postcss-dir-pseudo-class"; +import postcssDiscardComments from "postcss-discard-comments"; import postcssNesting from "postcss-nesting"; import { preprocessPDFJSCode } from "./external/builder/preprocessor2.mjs"; import rename from "gulp-rename"; @@ -934,17 +935,26 @@ gulp.task("cmaps", async function () { function preprocessCSS(source, defines) { const outName = getTempFile("~preprocess", ".css"); builder.preprocess(source, outName, defines); - let out = fs.readFileSync(outName).toString(); + const out = fs.readFileSync(outName).toString(); fs.unlinkSync(outName); - // Strip out all license headers in the middle. - const reg = /\n\/\* Copyright(.|\n)*?Mozilla Foundation(.|\n)*?\*\//g; - out = out.replaceAll(reg, ""); - const i = source.lastIndexOf("/"); return createStringSource(source.substr(i + 1), out); } +function discardCommentsCSS() { + let copyrightNum = 0; + + function remove(comment) { + // Remove all comments, except the *first* license header. + if (comment.startsWith("Copyright") && copyrightNum++ === 0) { + return false; + } + return true; + } + return postcssDiscardComments({ remove }); +} + function preprocessHTML(source, defines) { const outName = getTempFile("~preprocess", ".html"); builder.preprocess(source, outName, defines); @@ -982,6 +992,7 @@ function buildGeneric(defines, dir) { .pipe( postcss([ postcssDirPseudoClass(), + discardCommentsCSS(), postcssNesting(), autoprefixer(AUTOPREFIXER_CONFIG), ]) @@ -1069,6 +1080,7 @@ function buildComponents(defines, dir) { .pipe( postcss([ postcssDirPseudoClass(), + discardCommentsCSS(), postcssNesting(), autoprefixer(AUTOPREFIXER_CONFIG), ]) @@ -1165,6 +1177,7 @@ function buildMinified(defines, dir) { .pipe( postcss([ postcssDirPseudoClass(), + discardCommentsCSS(), postcssNesting(), autoprefixer(AUTOPREFIXER_CONFIG), ]) @@ -1411,12 +1424,22 @@ gulp.task( ), preprocessCSS("web/viewer.css", defines) - .pipe(postcss([autoprefixer(MOZCENTRAL_AUTOPREFIXER_CONFIG)])) + .pipe( + postcss([ + discardCommentsCSS(), + autoprefixer(MOZCENTRAL_AUTOPREFIXER_CONFIG), + ]) + ) .pipe(replaceMozcentralCSS()) .pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")), preprocessCSS("web/viewer-geckoview.css", gvDefines) - .pipe(postcss([autoprefixer(MOZCENTRAL_AUTOPREFIXER_CONFIG)])) + .pipe( + postcss([ + discardCommentsCSS(), + autoprefixer(MOZCENTRAL_AUTOPREFIXER_CONFIG), + ]) + ) .pipe(replaceMozcentralCSS()) .pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")), @@ -1509,6 +1532,7 @@ gulp.task( .pipe( postcss([ postcssDirPseudoClass(), + discardCommentsCSS(), postcssNesting(), autoprefixer(AUTOPREFIXER_CONFIG), ]) diff --git a/package-lock.json b/package-lock.json index a581871f7..b00ca1596 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,6 +48,7 @@ "pngjs": "^7.0.0", "postcss": "^8.4.30", "postcss-dir-pseudo-class": "^8.0.0", + "postcss-discard-comments": "^6.0.0", "postcss-nesting": "^12.0.1", "prettier": "^3.0.3", "puppeteer": "^21.2.1", @@ -16768,6 +16769,18 @@ "postcss": "^8.4" } }, + "node_modules/postcss-discard-comments": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/postcss-discard-comments/-/postcss-discard-comments-6.0.0.tgz", + "integrity": "sha512-p2skSGqzPMZkEQvJsgnkBhCn8gI7NzRH2683EEjrIkoMiwRELx68yoUJ3q3DGSGuQ8Ug9Gsn+OuDr46yfO+eFw==", + "dev": true, + "engines": { + "node": "^14 || ^16 || >=18.0" + }, + "peerDependencies": { + "postcss": "^8.2.15" + } + }, "node_modules/postcss-load-config": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/postcss-load-config/-/postcss-load-config-3.1.0.tgz", diff --git a/package.json b/package.json index 47c942aef..cedaccd20 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "pngjs": "^7.0.0", "postcss": "^8.4.30", "postcss-dir-pseudo-class": "^8.0.0", + "postcss-discard-comments": "^6.0.0", "postcss-nesting": "^12.0.1", "prettier": "^3.0.3", "puppeteer": "^21.2.1",