From 8234bdc3709b402b8f71ce42433e6e63a6d2ab4a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 7 Jun 2021 05:47:20 -0500 Subject: [PATCH 01/10] Update postcss --- packages/core/integration-tests/package.json | 2 +- packages/optimizers/cssnano/package.json | 2 +- packages/packagers/css/package.json | 2 +- packages/transformers/css/package.json | 2 +- packages/transformers/postcss/package.json | 2 +- packages/transformers/sugarss/package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/integration-tests/package.json b/packages/core/integration-tests/package.json index b612936add4..f1cd8a076cb 100644 --- a/packages/core/integration-tests/package.json +++ b/packages/core/integration-tests/package.json @@ -40,7 +40,7 @@ "nib": "^1.1.2", "node-elm-compiler": "^5.0.5", "parcel": "2.0.0-beta.3.1", - "postcss": "^8.2.1", + "postcss": "^8.3.0", "postcss-custom-properties": "^11.0.0", "postcss-import": "^14.0.2", "posthtml-include": "^1.5.0", diff --git a/packages/optimizers/cssnano/package.json b/packages/optimizers/cssnano/package.json index fd16edcf2bf..6e179c524b2 100644 --- a/packages/optimizers/cssnano/package.json +++ b/packages/optimizers/cssnano/package.json @@ -23,6 +23,6 @@ "@parcel/plugin": "2.0.0-beta.3.1", "@parcel/source-map": "2.0.0-rc.4", "cssnano": "^5.0.3", - "postcss": "^8.0.5" + "postcss": "^8.3.0" } } diff --git a/packages/packagers/css/package.json b/packages/packagers/css/package.json index 95544ea0a4c..5bc9410731b 100644 --- a/packages/packagers/css/package.json +++ b/packages/packagers/css/package.json @@ -24,6 +24,6 @@ "@parcel/source-map": "2.0.0-rc.4", "@parcel/utils": "2.0.0-beta.3.1", "nullthrows": "^1.1.1", - "postcss": "^8.2.1" + "postcss": "^8.3.0" } } diff --git a/packages/transformers/css/package.json b/packages/transformers/css/package.json index 2b1839cf91b..0aa6b29c88a 100644 --- a/packages/transformers/css/package.json +++ b/packages/transformers/css/package.json @@ -24,7 +24,7 @@ "@parcel/source-map": "2.0.0-rc.4", "@parcel/utils": "2.0.0-beta.3.1", "nullthrows": "^1.1.1", - "postcss": "^8.2.1", + "postcss": "^8.3.0", "postcss-value-parser": "^4.1.0", "semver": "^5.4.1" } diff --git a/packages/transformers/postcss/package.json b/packages/transformers/postcss/package.json index fed090e0980..7d5098cfc64 100644 --- a/packages/transformers/postcss/package.json +++ b/packages/transformers/postcss/package.json @@ -31,6 +31,6 @@ "semver": "^5.4.1" }, "devDependencies": { - "postcss": "^8.2.1" + "postcss": "^8.3.0" } } diff --git a/packages/transformers/sugarss/package.json b/packages/transformers/sugarss/package.json index e2f5faa22cd..bf76aa8cfd8 100644 --- a/packages/transformers/sugarss/package.json +++ b/packages/transformers/sugarss/package.json @@ -21,7 +21,7 @@ }, "dependencies": { "@parcel/plugin": "2.0.0-beta.3.1", - "postcss": "^8.0.5", + "postcss": "^8.3.0", "sugarss": "^3.0.3" } } From 2b097e185718600079f8902ced5f75b0206960fe Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 7 Jun 2021 05:49:16 -0500 Subject: [PATCH 02/10] Update cssnano --- packages/optimizers/cssnano/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/optimizers/cssnano/package.json b/packages/optimizers/cssnano/package.json index 6e179c524b2..44a02c47c84 100644 --- a/packages/optimizers/cssnano/package.json +++ b/packages/optimizers/cssnano/package.json @@ -22,7 +22,7 @@ "dependencies": { "@parcel/plugin": "2.0.0-beta.3.1", "@parcel/source-map": "2.0.0-rc.4", - "cssnano": "^5.0.3", + "cssnano": "^5.0.5", "postcss": "^8.3.0" } } From fdaa817a7f0bb6e1e92d74f65a700e000aa455cf Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 7 Jun 2021 05:49:41 -0500 Subject: [PATCH 03/10] Update lockfile --- yarn.lock | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 1c5b2cda3a1..f5bca24212a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3290,7 +3290,7 @@ browserify-zlib@^0.2.0: dependencies: pako "~1.0.5" -browserslist@^4.0.0, browserslist@^4.14.5, browserslist@^4.16.0, browserslist@^4.16.3, browserslist@^4.6.6: +browserslist@^4.0.0, browserslist@^4.14.5, browserslist@^4.16.0, browserslist@^4.16.3, browserslist@^4.16.6, browserslist@^4.6.6: version "4.16.6" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.16.6.tgz#d7901277a5a88e554ed305b183ec9b0c08f66fa2" integrity sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ== @@ -3857,6 +3857,11 @@ colord@^1.7.0: resolved "https://registry.yarnpkg.com/colord/-/colord-1.7.2.tgz#474f0e46333cb5c7a191dbd571edeee19a5f97b6" integrity sha512-/sQCxy6PEhZbrAn1+NVRRefy3k4jkWQGxk7mo2o0CoNA24jq4ujDc2jXzJ5uXphm/TwfdGOP0w8U+H+9ys4Peg== +colord@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/colord/-/colord-2.0.1.tgz#1e7fb1f9fa1cf74f42c58cb9c20320bab8435aa0" + integrity sha512-vm5YpaWamD0Ov6TSG0GGmUIwstrWcfKQV/h2CmbR7PbNu41+qdB5PW9lpzhjedrpm08uuYvcXi0Oel1RLZIJuA== + colorette@^1.2.2: version "1.2.2" resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.2.tgz#cbcc79d5e99caea2dbf10eb3a26fd8b3e6acfa94" @@ -4420,12 +4425,47 @@ cssnano-preset-default@^5.1.0: postcss-svgo "^5.0.1" postcss-unique-selectors "^5.0.1" +cssnano-preset-default@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/cssnano-preset-default/-/cssnano-preset-default-5.1.2.tgz#5d4877a91769823c5da6bcebd54996ecdf8aca12" + integrity sha512-spilp8LRw0sacuxiN9A/dyyPr6G/WISKMBKcBD4NMoPV0ENx4DeuWvIIrSx9PII2nJIDCO3kywkqTPreECBVOg== + dependencies: + css-declaration-sorter "^6.0.3" + cssnano-utils "^2.0.1" + postcss-calc "^8.0.0" + postcss-colormin "^5.2.0" + postcss-convert-values "^5.0.1" + postcss-discard-comments "^5.0.1" + postcss-discard-duplicates "^5.0.1" + postcss-discard-empty "^5.0.1" + postcss-discard-overridden "^5.0.1" + postcss-merge-longhand "^5.0.2" + postcss-merge-rules "^5.0.2" + postcss-minify-font-values "^5.0.1" + postcss-minify-gradients "^5.0.1" + postcss-minify-params "^5.0.1" + postcss-minify-selectors "^5.1.0" + postcss-normalize-charset "^5.0.1" + postcss-normalize-display-values "^5.0.1" + postcss-normalize-positions "^5.0.1" + postcss-normalize-repeat-style "^5.0.1" + postcss-normalize-string "^5.0.1" + postcss-normalize-timing-functions "^5.0.1" + postcss-normalize-unicode "^5.0.1" + postcss-normalize-url "^5.0.1" + postcss-normalize-whitespace "^5.0.1" + postcss-ordered-values "^5.0.1" + postcss-reduce-initial "^5.0.1" + postcss-reduce-transforms "^5.0.1" + postcss-svgo "^5.0.2" + postcss-unique-selectors "^5.0.1" + cssnano-utils@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/cssnano-utils/-/cssnano-utils-2.0.1.tgz#8660aa2b37ed869d2e2f22918196a9a8b6498ce2" integrity sha512-i8vLRZTnEH9ubIyfdZCAdIdgnHAUeQeByEeQ2I7oTilvP9oHO6RScpeq3GsFUVqeB8uZgOQ9pw8utofNn32hhQ== -cssnano@^5.0.0, cssnano@^5.0.3: +cssnano@^5.0.0: version "5.0.3" resolved "https://registry.yarnpkg.com/cssnano/-/cssnano-5.0.3.tgz#3ae26411a176168e7a0ef425f4691579e1aed12a" integrity sha512-Ga/a+IA6U0F9+MNmqrXgwn1A3btY5jFkla2iurL7i9PTmQmMu2Kc99W9a8KSxT8iLV0aoI+Q5Q9i3SpVAVNnrQ== @@ -4434,6 +4474,15 @@ cssnano@^5.0.0, cssnano@^5.0.3: cssnano-preset-default "^5.1.0" is-resolvable "^1.1.0" +cssnano@^5.0.5: + version "5.0.5" + resolved "https://registry.yarnpkg.com/cssnano/-/cssnano-5.0.5.tgz#6b8787123bf4cd5a220a2fa6cb5bc036b0854b48" + integrity sha512-L2VtPXnq6rmcMC9vkBOP131sZu3ccRQI27ejKZdmQiPDpUlFkUbpXHgKN+cibeO1U4PItxVZp1zTIn5dHsXoyg== + dependencies: + cosmiconfig "^7.0.0" + cssnano-preset-default "^5.1.2" + is-resolvable "^1.1.0" + csso@^4.0.2, csso@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/csso/-/csso-4.2.0.tgz#ea3a561346e8dc9f546d6febedd50187cf389529" @@ -9987,6 +10036,16 @@ postcss-colormin@^5.1.0: colord "^1.7.0" postcss-value-parser "^4.1.0" +postcss-colormin@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/postcss-colormin/-/postcss-colormin-5.2.0.tgz#2b620b88c0ff19683f3349f4cf9e24ebdafb2c88" + integrity sha512-+HC6GfWU3upe5/mqmxuqYZ9B2Wl4lcoUUNkoaX59nEWV4EtADCMiBqui111Bu8R8IvaZTmqmxrqOAqjbHIwXPw== + dependencies: + browserslist "^4.16.6" + caniuse-api "^3.0.0" + colord "^2.0.1" + postcss-value-parser "^4.1.0" + postcss-convert-values@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/postcss-convert-values/-/postcss-convert-values-5.0.1.tgz#4ec19d6016534e30e3102fdf414e753398645232" @@ -10050,6 +10109,17 @@ postcss-merge-rules@^5.0.1: postcss-selector-parser "^6.0.5" vendors "^1.0.3" +postcss-merge-rules@^5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/postcss-merge-rules/-/postcss-merge-rules-5.0.2.tgz#d6e4d65018badbdb7dcc789c4f39b941305d410a" + integrity sha512-5K+Md7S3GwBewfB4rjDeol6V/RZ8S+v4B66Zk2gChRqLTCC8yjnHQ601omj9TKftS19OPGqZ/XzoqpzNQQLwbg== + dependencies: + browserslist "^4.16.6" + caniuse-api "^3.0.0" + cssnano-utils "^2.0.1" + postcss-selector-parser "^6.0.5" + vendors "^1.0.3" + postcss-minify-font-values@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/postcss-minify-font-values/-/postcss-minify-font-values-5.0.1.tgz#a90cefbfdaa075bd3dbaa1b33588bb4dc268addf" @@ -10280,6 +10350,14 @@ postcss-svgo@^5.0.1: postcss-value-parser "^4.1.0" svgo "^2.3.0" +postcss-svgo@^5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/postcss-svgo/-/postcss-svgo-5.0.2.tgz#bc73c4ea4c5a80fbd4b45e29042c34ceffb9257f" + integrity sha512-YzQuFLZu3U3aheizD+B1joQ94vzPfE6BNUcSYuceNxlVnKKsOtdo6hL9/zyC168Q8EwfLSgaDSalsUGa9f2C0A== + dependencies: + postcss-value-parser "^4.1.0" + svgo "^2.3.0" + postcss-unique-selectors@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/postcss-unique-selectors/-/postcss-unique-selectors-5.0.1.tgz#3be5c1d7363352eff838bd62b0b07a0abad43bfc" @@ -10330,7 +10408,7 @@ postcss@^7.0.14, postcss@^7.0.17, postcss@^7.0.32, postcss@^7.0.5, postcss@^7.0. source-map "^0.6.1" supports-color "^6.1.0" -postcss@^8.0.5, postcss@^8.1.6, postcss@^8.2.1, postcss@^8.2.9: +postcss@^8.1.6, postcss@^8.2.1, postcss@^8.2.9: version "8.2.15" resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.15.tgz#9e66ccf07292817d226fc315cbbf9bc148fbca65" integrity sha512-2zO3b26eJD/8rb106Qu2o7Qgg52ND5HPjcyQiK2B98O388h43A448LCslC0dI2P97wCAQRJsFvwTRcXxTKds+Q== @@ -10339,6 +10417,15 @@ postcss@^8.0.5, postcss@^8.1.6, postcss@^8.2.1, postcss@^8.2.9: nanoid "^3.1.23" source-map "^0.6.1" +postcss@^8.3.0: + version "8.3.0" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.3.0.tgz#b1a713f6172ca427e3f05ef1303de8b65683325f" + integrity sha512-+ogXpdAjWGa+fdYY5BQ96V/6tAo+TdSSIMP5huJBIygdWwKtVoB5JWZ7yUd4xZ8r+8Kvvx4nyg/PQ071H4UtcQ== + dependencies: + colorette "^1.2.2" + nanoid "^3.1.23" + source-map-js "^0.6.2" + posthtml-expressions@^1.6.0: version "1.7.1" resolved "https://registry.yarnpkg.com/posthtml-expressions/-/posthtml-expressions-1.7.1.tgz#b62b47a9c2cc8216cbbb07d2e9e7b293f3c1f5bc" @@ -11872,6 +11959,11 @@ sort-keys@^2.0.0: dependencies: is-plain-obj "^1.0.0" +source-map-js@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-0.6.2.tgz#0bb5de631b41cfbda6cfba8bd05a80efdfd2385e" + integrity sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug== + source-map-resolve@^0.5.0, source-map-resolve@^0.5.2: version "0.5.3" resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a" From a96e7f6e96dc9e195bf3425d91ec435c718fa2ca Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 7 Jun 2021 06:01:53 -0500 Subject: [PATCH 04/10] Allow configuring cssnano --- packages/optimizers/cssnano/package.json | 1 + packages/optimizers/cssnano/src/CSSNanoOptimizer.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/optimizers/cssnano/package.json b/packages/optimizers/cssnano/package.json index 44a02c47c84..597fe8cbf82 100644 --- a/packages/optimizers/cssnano/package.json +++ b/packages/optimizers/cssnano/package.json @@ -22,6 +22,7 @@ "dependencies": { "@parcel/plugin": "2.0.0-beta.3.1", "@parcel/source-map": "2.0.0-rc.4", + "@parcel/utils": "2.0.0-beta.3.1", "cssnano": "^5.0.5", "postcss": "^8.3.0" } diff --git a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js index d67aa3aefdc..74126b3244d 100644 --- a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js +++ b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js @@ -4,6 +4,8 @@ import SourceMap from '@parcel/source-map'; import {Optimizer} from '@parcel/plugin'; import postcss from 'postcss'; import cssnano from 'cssnano'; +import {loadConfig} from '@parcel/utils'; +import path from 'path'; export default (new Optimizer({ async optimize({ @@ -23,7 +25,14 @@ export default (new Optimizer({ ); } - const result = await postcss([cssnano]).process(prevContents, { + const userConfig = await loadConfig( + options.inputFS, + path.join(options.entryRoot, 'index.css'), + ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'], + options.projectRoot, + ); + + const result = await postcss([cssnano(userConfig)]).process(prevContents, { // Suppress postcss's warning about a missing `from` property. In this // case, the input map contains all of the sources. from: undefined, From e5448512fbe3ed314852283b860a321561f72d57 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 7 Jun 2021 06:45:50 -0500 Subject: [PATCH 05/10] Default to {} in cssnano config --- packages/optimizers/cssnano/src/CSSNanoOptimizer.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js index 74126b3244d..aab4bdab40d 100644 --- a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js +++ b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js @@ -25,12 +25,13 @@ export default (new Optimizer({ ); } - const userConfig = await loadConfig( - options.inputFS, - path.join(options.entryRoot, 'index.css'), - ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'], - options.projectRoot, - ); + const userConfig = + (await loadConfig( + options.inputFS, + path.join(options.entryRoot, 'index.css'), + ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'], + options.projectRoot, + )) ?? {}; const result = await postcss([cssnano(userConfig)]).process(prevContents, { // Suppress postcss's warning about a missing `from` property. In this From e841f6021f8e5b0ed274f13e9cbe36f8695db2ff Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 10 Jun 2021 03:27:52 -0500 Subject: [PATCH 06/10] Add type annotation for CSSNanoOptions --- .../optimizers/cssnano/src/CSSNanoOptimizer.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js index aab4bdab40d..bb96edebbe4 100644 --- a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js +++ b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js @@ -4,6 +4,7 @@ import SourceMap from '@parcel/source-map'; import {Optimizer} from '@parcel/plugin'; import postcss from 'postcss'; import cssnano from 'cssnano'; +import type {CSSNanoOptions} from 'cssnano'; // TODO the type is based on cssnano 4 import {loadConfig} from '@parcel/utils'; import path from 'path'; @@ -25,13 +26,12 @@ export default (new Optimizer({ ); } - const userConfig = - (await loadConfig( - options.inputFS, - path.join(options.entryRoot, 'index.css'), - ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'], - options.projectRoot, - )) ?? {}; + const userConfig = ((await loadConfig( + options.inputFS, + path.join(options.entryRoot, 'index.css'), + ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'], + options.projectRoot, + )) ?? {}: CSSNanoOptions); const result = await postcss([cssnano(userConfig)]).process(prevContents, { // Suppress postcss's warning about a missing `from` property. In this From 588983b19424af249892c686e797bfaf012d85e8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 10 Jun 2021 04:12:02 -0500 Subject: [PATCH 07/10] Use config.getConfigFrom --- packages/optimizers/cssnano/package.json | 1 - .../cssnano/src/CSSNanoOptimizer.js | 21 +++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/optimizers/cssnano/package.json b/packages/optimizers/cssnano/package.json index 597fe8cbf82..44a02c47c84 100644 --- a/packages/optimizers/cssnano/package.json +++ b/packages/optimizers/cssnano/package.json @@ -22,7 +22,6 @@ "dependencies": { "@parcel/plugin": "2.0.0-beta.3.1", "@parcel/source-map": "2.0.0-rc.4", - "@parcel/utils": "2.0.0-beta.3.1", "cssnano": "^5.0.5", "postcss": "^8.3.0" } diff --git a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js index bb96edebbe4..2d998aa5ccc 100644 --- a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js +++ b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js @@ -5,15 +5,25 @@ import {Optimizer} from '@parcel/plugin'; import postcss from 'postcss'; import cssnano from 'cssnano'; import type {CSSNanoOptions} from 'cssnano'; // TODO the type is based on cssnano 4 -import {loadConfig} from '@parcel/utils'; import path from 'path'; export default (new Optimizer({ + async loadConfig({config, options}) { + return ( + (await config.getConfigFrom(path.join(options.entryRoot, 'index.css'), [ + '.cssnanorc', + 'cssnano.config.json', + 'cssnano.config.js', + ])) ?? {} + ); + }, + async optimize({ bundle, contents: prevContents, getSourceMapReference, map: prevMap, + config, options, }) { if (!bundle.env.shouldOptimize) { @@ -26,14 +36,7 @@ export default (new Optimizer({ ); } - const userConfig = ((await loadConfig( - options.inputFS, - path.join(options.entryRoot, 'index.css'), - ['.cssnanorc ', 'cssnano.config.json', 'cssnano.config.js'], - options.projectRoot, - )) ?? {}: CSSNanoOptions); - - const result = await postcss([cssnano(userConfig)]).process(prevContents, { + const result = await postcss([cssnano(config)]).process(prevContents, { // Suppress postcss's warning about a missing `from` property. In this // case, the input map contains all of the sources. from: undefined, From bf02014741cf556263ead18d32f21b32bcc5a9b3 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 10 Jun 2021 08:11:55 -0500 Subject: [PATCH 08/10] Use getConfig and setResult --- .../cssnano/src/CSSNanoOptimizer.js | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js index 2d998aa5ccc..36417037fb9 100644 --- a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js +++ b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js @@ -8,14 +8,29 @@ import type {CSSNanoOptions} from 'cssnano'; // TODO the type is based on cssnan import path from 'path'; export default (new Optimizer({ - async loadConfig({config, options}) { - return ( - (await config.getConfigFrom(path.join(options.entryRoot, 'index.css'), [ - '.cssnanorc', - 'cssnano.config.json', - 'cssnano.config.js', - ])) ?? {} + async loadConfig({config}) { + const configFile = await config.getConfig( + ['.cssnanorc', 'cssnano.config.json', 'cssnano.config.js'], + { + packageKey: 'cssnano', + }, ); + // TODO copied from stylus package. make this a utility function + if (configFile) { + let isJavascript = path.extname(configFile.filePath) === '.js'; + if (isJavascript) { + config.shouldInvalidateOnStartup(); + } + + // Resolve relative paths from config file + if (configFile.contents.paths) { + configFile.contents.paths = configFile.contents.paths.map(p => + path.resolve(path.dirname(configFile.filePath), p), + ); + } + + config.setResult(configFile.contents); + } }, async optimize({ @@ -36,7 +51,9 @@ export default (new Optimizer({ ); } - const result = await postcss([cssnano(config)]).process(prevContents, { + const result = await postcss([ + cssnano((config ?? {}: CSSNanoOptions)), + ]).process(prevContents, { // Suppress postcss's warning about a missing `from` property. In this // case, the input map contains all of the sources. from: undefined, From e6dd84026f98306deba88f4756e24ab79e528496 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 10 Jun 2021 08:24:37 -0500 Subject: [PATCH 09/10] Update cssnano types --- flow-libs/cssnano.js.flow | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flow-libs/cssnano.js.flow b/flow-libs/cssnano.js.flow index c34447cac8a..fbb923090d0 100644 --- a/flow-libs/cssnano.js.flow +++ b/flow-libs/cssnano.js.flow @@ -1,13 +1,14 @@ // @flow strict-local -// Derived from the source of cssnano located at +// Modified from the source of cssnano located at // https://github.com/cssnano/cssnano and its types at // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/cssnano/index.d.ts declare module 'cssnano' { + import type { Plugin } from "postcss" declare interface CSSNanoOptions { configFile?: string; preset?: [string, mixed] | string; } - declare module.exports: (?CSSNanoOptions) => void; + declare module.exports: (?CSSNanoOptions) => Plugin; } From 1dfccab35cb91c3b55e646628dfb429330364e92 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 12 Jun 2021 10:18:16 -0500 Subject: [PATCH 10/10] Remove path resolving in the config file --- packages/optimizers/cssnano/src/CSSNanoOptimizer.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js index 36417037fb9..468a2be2e57 100644 --- a/packages/optimizers/cssnano/src/CSSNanoOptimizer.js +++ b/packages/optimizers/cssnano/src/CSSNanoOptimizer.js @@ -15,20 +15,11 @@ export default (new Optimizer({ packageKey: 'cssnano', }, ); - // TODO copied from stylus package. make this a utility function if (configFile) { let isJavascript = path.extname(configFile.filePath) === '.js'; if (isJavascript) { config.shouldInvalidateOnStartup(); } - - // Resolve relative paths from config file - if (configFile.contents.paths) { - configFile.contents.paths = configFile.contents.paths.map(p => - path.resolve(path.dirname(configFile.filePath), p), - ); - } - config.setResult(configFile.contents); } },