Skip to content

Commit 9c24a46

Browse files
authoredMar 14, 2024··
Convert SASS-style inline comments to CSS-style multiline comments. (#11733)
Following on from [the conversion of SASS -> CSS](#11677), this PR converts the SASS style inline comments to CSS style multiline comments. Since this was the only reason we were using `postcss-scss` parser, it too has been removed. --- I used this script to achieve the conversion: ```sh #!/bin/bash # Write a temporary postcss config for postcss to work cat <<EOF > postcss.config.js const spaceAtEndRegex = /\s$/; const postCssInlineToMultilineComment = { postcssPlugin: 'postcss-inline-to-multiline-comment', Comment(node) { if (node.raws.inline && (!node.raws.right || !spaceAtEndRegex.test(node.raws.right))) { if (!node.raws.right) { node.raws.right = ''; } node.raws.right += ' '; } }, } module.exports = { // Need to understand SCSS inline comment syntax parser: 'postcss-scss', plugins: [ postCssInlineToMultilineComment, ], }; EOF npx postcss-cli --yes postcss-cli -r --no-map --config="`pwd`" polaris-react/**/*.css rm -f postcss.config.js # Clean up temporary files ``` Then I confirmed it was successful with this script: ```sh if [ -z "$1" ]; then echo "A filename is required:\n> $0 ./no-inline.css"; exit 1; fi; # Write a temporary postcss config for cssnano to work cat <<EOF > postcss.config.js module.exports = { plugins: [ require('cssnano')({ preset: 'lite', }), ], }; EOF yarn workspace @shopify/polaris add cssnano-preset-lite yarn yarn build --filter="@shopify/polaris" cp polaris-react/build/esm/styles.css "$1" # Move out of ignored directories yarn prettier -w "$1" # Pre-format to normalize whitespace npx postcss-cli --yes postcss-cli -r --no-map --config="`pwd`" "$1" # cssnano removes more whitespace prettier doesn't yarn prettier -w "$1" # Format again to get back into un-minified version rm postcss.config.js # Clean up temporary files yarn workspace @shopify/polaris remove cssnano-preset-lite ``` Run like this: ```sh git checkout multiline-comments ./go.sh ./no-inline.css git checkout main ./go.sh ./inline.css git checkout - git diff --histogram --no-index inline.css no-inline.css # Should be an empty diff ```
1 parent 2f0cbca commit 9c24a46

File tree

102 files changed

+1256
-1232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1256
-1232
lines changed
 

‎.changeset/brown-penguins-walk.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Convert SASS-style inline comments to CSS-style multiline comments.

‎polaris-react/config/rollup/plugin-styles.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const path = require('path');
22

33
const {createFilter} = require('@rollup/pluginutils');
44
const postcss = require('postcss');
5-
const postcssScss = require('postcss-scss');
65
const cssModules = require('postcss-modules');
76

87
module.exports.styles = function styles({
@@ -145,7 +144,7 @@ module.exports.styles = function styles({
145144
}
146145

147146
const postCssOutput = await styleProcessor
148-
.process(source, {parser: postcssScss, from: id})
147+
.process(source, {from: id})
149148
.then((result) => ({
150149
css: result.css,
151150
tokens: result.messages.find(({plugin, type}) => {

0 commit comments

Comments
 (0)
Please sign in to comment.