From f5a4c56527960d3f199a699e4ae77fec57f63cad Mon Sep 17 00:00:00 2001
From: "a.kuzmenko"
Date: Tue, 20 Mar 2018 16:20:46 +0200
Subject: [PATCH 1/2] add cssoOptions and test
---
README.md | 1 +
src/run.js | 3 ++-
tests/examples/comments.css | 4 ++++
tests/examples/comments.html | 10 ++++++++++
tests/main.test.js | 10 ++++++++++
5 files changed, 27 insertions(+), 1 deletion(-)
create mode 100644 tests/examples/comments.css
create mode 100644 tests/examples/comments.html
diff --git a/README.md b/README.md
index f5c50910..148c812b 100644
--- a/README.md
+++ b/README.md
@@ -175,6 +175,7 @@ key is `urls`. Other optional options are:
* `viewport` - viewport object as specified in [page.setViewport](https://github.com/GoogleChrome/puppeteer/blob/v1.0.0/docs/api.md#pagesetviewportviewport)
* `puppeteerArgs` - Args sent to puppeteer when launching. [List
of strings for headless Chrome](https://peter.sh/experiments/chromium-command-line-switches/).
+* `cssoOptions` - CSSO compress function [options](https://github.com/css/csso#compressast-options)
## Warnings
diff --git a/src/run.js b/src/run.js
index 0524db39..b89ceedf 100644
--- a/src/run.js
+++ b/src/run.js
@@ -325,6 +325,7 @@ const processPage = ({
const minimalcss = async options => {
const { urls } = options;
const debug = options.debug || false;
+ const cssoOptions = options.cssoOptions || {};
const puppeteerArgs = options.puppeteerArgs || [];
const browser =
options.browser ||
@@ -502,7 +503,7 @@ const minimalcss = async options => {
// When ultimately, what was need is `p { color: blue; font-weight: bold}`.
// The csso.minify() function will solve this, *and* whitespace minify
// it too.
- csso.compress(allCombinedAst);
+ csso.compress(allCombinedAst, cssoOptions);
postProcessOptimize(allCombinedAst);
const returned = {
diff --git a/tests/examples/comments.css b/tests/examples/comments.css
new file mode 100644
index 00000000..d516f400
--- /dev/null
+++ b/tests/examples/comments.css
@@ -0,0 +1,4 @@
+/*! test css comment */
+p {
+ color: red;
+}
diff --git a/tests/examples/comments.html b/tests/examples/comments.html
new file mode 100644
index 00000000..9e0db9c0
--- /dev/null
+++ b/tests/examples/comments.html
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+ Only a P tag in this document. And images too.
+
+
diff --git a/tests/main.test.js b/tests/main.test.js
index c326c5dc..4d6bd512 100644
--- a/tests/main.test.js
+++ b/tests/main.test.js
@@ -206,3 +206,13 @@ test('avoids link tags that is css data', async () => {
// See https://github.com/peterbe/minimalcss/issues/158
expect(finalCss).toMatch('');
});
+
+test('accept CSSO options', async () => {
+ const cssoOptions = {};
+ let { finalCss } = await runMinimalcss('comments', { cssoOptions });
+ expect(finalCss).toMatch('test css comment');
+
+ cssoOptions.comments = false;
+ ({ finalCss } = await runMinimalcss('comments', { cssoOptions }));
+ expect(finalCss).not.toMatch('test css comment');
+});
From 3fe3c8b0535016f0f4903f2430e029add9211f41 Mon Sep 17 00:00:00 2001
From: "a.kuzmenko"
Date: Wed, 21 Mar 2018 10:24:07 +0200
Subject: [PATCH 2/2] master | fix TypeScript notation
Signed-off-by: a.kuzmenko
---
src/run.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/run.js b/src/run.js
index b89ceedf..af8d143b 100644
--- a/src/run.js
+++ b/src/run.js
@@ -319,7 +319,7 @@ const processPage = ({
/**
*
- * @param {{ urls: Array, debug: boolean, loadimages: boolean, skippable: function, browser: any, userAgent: string, withoutjavascript: boolean, viewport: any, puppeteerArgs: Array }} options
+ * @param {{ urls: Array, debug: boolean, loadimages: boolean, skippable: function, browser: any, userAgent: string, withoutjavascript: boolean, viewport: any, puppeteerArgs: Array, cssoOptions: Object }} options
* @return Promise<{ finalCss: string, stylesheetContents: { [key: string]: string } }>
*/
const minimalcss = async options => {