Postponed as this warning doesn't exist until #3261163: Update to PostCSS 8

Problem/Motivation

As of #3261163: Update to PostCSS 8 there's a deprecation warning during yarn build

remove-unwanted-comments-from-variables: postcss.plugin was deprecated. Migration guide:
https://evilmartians.com/chronicles/postcss-8-plugin-migration

The link in the warning on how to address the deprecation seems to explain it pretty well

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

bnjmnm created an issue. See original summary.

bnjmnm’s picture

Status: Postponed (maintainer needs more info) » Postponed
longwave’s picture

Status: Postponed » Active

#3261163: Update to PostCSS 8 landed so this can be addressed now.

spokje’s picture

StatusFileSize
new2.82 KB

Whilst looking to upgrade our custom plugin, I found out nothing changes if I remove the plugin on my local after running a yarn build.

Let's see if TestBot sees it the same way.

spokje’s picture

StatusFileSize
new322.23 KB
spokje’s picture

Hmm, looks like the plugin does actually does things on 9.x and doesn't (need to) on 10.x

spokje’s picture

StatusFileSize
new4.41 KB

So let's try an upgrade attempt on 9.5.x where the custom plugin actually does something.

The goal here is to have:

- No CSS changes
- No deprecation message in the build log

spokje’s picture

Issue tags: +Needs manual testing

Since yarn build doesn't seem to be part of the drupal CI, we need manual testing for this one:

- Checkout dev branch
- Apply patch
- cd core/
- yarn install
- node ./scripts/css/postcss-build.js (This is the acual sub-command in yarn build that triggers the deprecation message.

After the above commands are fully finished, for a successful test, there should be:
- NO changes in any of the CSS files.
- NO occurrence of the deprecation message remove-unwanted-comments-from-variables: postcss.plugin was deprecated. Migration guide: https://evilmartians.com/chronicles/postcss-8-plugin-migration anywhere in the output of the above commands.

spokje’s picture

Version: 10.0.x-dev » 10.1.x-dev
StatusFileSize
new4.26 KB
spokje’s picture

Status: Active » Needs review
longwave’s picture

Status: Needs review » Needs work
Issue tags: -Needs manual testing
  1. +++ b/core/package.json
    @@ -97,6 +97,9 @@
    +  "peerDependencies": {
    +    "postcss": "^8"
    +  },
    

    Is this required? We already have an actual dependency on postcss, not sure we need a peer dependency as well.

  2. +++ b/core/scripts/css/remove-unwanted-comments-from-variables.js
    @@ -0,0 +1,18 @@
    +      if (css.source.input.file.indexOf('variables.pcss.css') !== -1) {
    

    In 10.x if we replace variables.pcss.css with media-queries.pcss.css then some cruft is removed from the built CSS. Maybe we should also just rename the plugin to remove-unwanted-comments?

spokje’s picture

Assigned: Unassigned » spokje
spokje’s picture

StatusFileSize
new4.19 KB
new1.81 KB
new58.63 KB
new46.6 KB

https://www.drupal.org/project/drupal/issues/3308872#comment-14814010.1

Is this required? We already have an actual dependency on postcss, not sure we need a peer dependency as well.

The way I understand this: https://evilmartians.com/chronicles/postcss-8-plugin-migration : Step 1: Move postcss to peerDependencies:

This will keep the size of the end-user’s node_modules directory under control: now, all plugins will use the same version of postcss as a dependency.

it isn't (really?) necessary, but will make all postcss-plugins use the same postcss version, which seems like a good thing to me.

https://www.drupal.org/project/drupal/issues/3308872#comment-14814010.2

In 10.x if we replace variables.pcss.css with media-queries.pcss.css then some cruft is removed from the built CSS. Maybe we should also just rename the plugin to remove-unwanted-comments?

Nice!
Booh to cruft!

spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review
longwave’s picture

Re peerDependencies, I might be wrong here but I think that statement only applies when you are distributing the plugin as a separate npm package. Here we are just shipping it along with core so the devDependencies entry is enough.

spokje’s picture

StatusFileSize
new324 bytes
new58.4 KB
new327 bytes
new3.79 KB

Well, you're the native speaker...:)

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Oh, nice that we can remove the filename check entirely, and the output is still sensible, and even cleaner than before!

This all looks good to me now.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Given that this includes an API addition, it should probably be 10.1.x only. (Also, 9.5.x does not seem to have the unwanted comments anyway, so no need to backport the API there?)

+++ b/core/scripts/css/compile.js
@@ -48,22 +36,22 @@ module.exports = (filePath, callback) => {
-          propList: [
-            '*',
-            '!background-position',
-            '!border',
-            '!border-width',
-            '!box-shadow',
-            '!border-top*',
-            '!border-right*',
-            '!border-bottom*',
-            '!border-left*',
-            '!border-start*',
-            '!border-end*',
-            '!outline*',
-          ],
-          mediaQuery: true,
-          minPixelValue: 3,
+        propList: [
+          '*',
+          '!background-position',
+          '!border',
+          '!border-width',
+          '!box-shadow',
+          '!border-top*',
+          '!border-right*',
+          '!border-bottom*',
+          '!border-left*',
+          '!border-start*',
+          '!border-end*',
+          '!outline*',
+        ],
+        mediaQuery: true,
+        minPixelValue: 3,
       }),

@@ -74,19 +62,19 @@ module.exports = (filePath, callback) => {
-    .process(css, { from: filePath })
-    .then(result => {
+      .process(css, {from: filePath})
+      .then(result => {
         return stylelint.lint({
           code: result.css,
           fix: true
         });
-    })
-    .then(result => {
-      callback(result.output);
-    })
-    .catch(error => {
-      log(error);
-      process.exitCode = 1;
-    });
+      })
+      .then(result => {
+        callback(result.output);
+      })
+      .catch(error => {
+        log(error);
+        process.exitCode = 1;
+      });

As far as I can see, these hunks are just having their whitespace changed. Out of scope? I confirmed locally that these changes don't show up with git diff -w

Aside from that, I confirmed that if I simply apply these three hunks:

diff --git a/core/package.json b/core/package.json
index e06958b4ce..5aa7f6025b 100644
--- a/core/package.json
+++ b/core/package.json
@@ -107,6 +107,5 @@
     "last 1 ChromeAndroid version",
     "last 1 Samsung version",
     "Firefox ESR"
-  ],
-  "dependencies": {}
+  ]
 }
diff --git a/core/scripts/css/compile.js b/core/scripts/css/compile.js
index fe52555a77..1d984f05cd 100644
--- a/core/scripts/css/compile.js
+++ b/core/scripts/css/compile.js
@@ -8,28 +8,16 @@ const postcssPresetEnv = require('postcss-preset-env');
 // cspell:ignore pxtorem
 const postcssPixelsToRem = require('postcss-pxtorem');
 const stylelint = require('stylelint');
+const removeUnwantedComments = require('./remove-unwanted-comments');
 
 module.exports = (filePath, callback) => {
   // Transform the file.
   fs.readFile(filePath, (err, css) => {
     postcss([
       postcssImport({
-       plugins: [
-         // On import, remove the comments from variables.pcss.css so they don't
-         // appear as useless comments at the top files that import these
-         // variables.
-         postcss.plugin('remove-unwanted-comments-from-variables', (options) => {
-           return css => {
-             if (css.source.input.file.indexOf('variables.pcss.css') !== -1) {
-               css.walk(node => {
-                 if (node.type === 'comment') {
-                   node.remove();
-                 }
-               });
-             }
-           };
-         }),
-       ],
+        plugins: [
+          removeUnwantedComments,
+        ],
       }),
       postcssPresetEnv({
         stage: 1,
diff --git a/core/scripts/css/remove-unwanted-comments.js b/core/scripts/css/remove-unwanted-comments.js
new file mode 100644
index 0000000000..bedbb34797
--- /dev/null
+++ b/core/scripts/css/remove-unwanted-comments.js
@@ -0,0 +1,14 @@
+// On import, remove the comments, so they don't appear as useless comments at the top of the autogenerated css files.
+module.exports = opts => {
+  return {
+    postcssPlugin: 'remove-unwanted-comments',
+    Once(css) {
+      css.walk(node => {
+        if (node.type === 'comment') {
+          node.remove();
+        }
+      })
+    }
+  }
+}
+module.exports.postcss = true

...and then rerun yarn build, it results in the comments being removed from the Olivero files.

NW to remove the out-of-scope whitespace changes. Thanks!

spokje’s picture

Status: Needs work » Needs review
StatusFileSize
new56.62 KB
new1.8 KB

Removed whitespaces, now 10.1.x only.

xjm’s picture

StatusFileSize
new2.17 KB

Partial patch for build testing purposes.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

#19 looks good to me.

  • xjm committed 83f1d40d on 10.1.x
    Issue #3308872 by Spokje, xjm, longwave, bnjmnm: Address "postcss.plugin...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.