Commands: Update to modern Sass module system#70252
Commands: Update to modern Sass module system#70252m1r0 wants to merge 2 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @m1r0! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
|
Thanks for the PR! Just to be sure, in order to update the The Personally, I'd like to see the whole Gutenberg project migrate to Dart Sass in the future. That way, we can update the old Sass version to the latest version. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
Thanks for the quick response @t-hamano!
I'm getting an error from this package only, so I'm guessing it's the only one that needs an update. 🙂🤞
|
t-hamano
left a comment
There was a problem hiding this comment.
so I'm guessing it's the only one that needs an update.
I see, it's only this one place, so there's no need to update other packages. As for other packages, it seems that they mainly refer to pre-built CSS (Example).
| @use "../../../base-styles/mixins"; | ||
| @use "../../../base-styles/variables"; |
There was a problem hiding this comment.
I'm not sure whether it's ok to reference SCSS files from other packages or not.
Should we add @wordpress/base-styles as a dependency of the @wordpress/commands package? Otherwise, consumers who only use the @wordpress/commands package and do not have the @wordpress/base-styles package installed may encounter a fatal error.
Any feedback would be appreciated.
There was a problem hiding this comment.
Good question. 🤔 Waiting for feedback as well.
There was a problem hiding this comment.
Adding a dependency makes sense to me.
There was a problem hiding this comment.
At least as a devDependency since in prod it's bundled in the CSS file.
There was a problem hiding this comment.
@m1r0 Can you add the dev dependencies [here](https://github.com/WordPress/gutenberg/blob/trunk/packages/commands/package.json)?
There was a problem hiding this comment.
I've tried adding it as a dev dependency, but the build started failing with Error: Can't find stylesheet to import. Any ideas? 🤔
I've tried using a version instead of a local path to include the package, but the result was the same.
Diff:
diff --git a/package-lock.json b/package-lock.json
index 950dd68787..b699f630ff 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -50179,6 +50179,9 @@
"clsx": "^2.1.1",
"cmdk": "^1.0.0"
},
+ "devDependencies": {
+ "@wordpress/base-styles": "file:../base-styles"
+ },
"engines": {
"node": ">=18.12.0",
"npm": ">=8.19.2"
diff --git a/packages/commands/package.json b/packages/commands/package.json
index 4fab2eb874..80cb8bb528 100644
--- a/packages/commands/package.json
+++ b/packages/commands/package.json
@@ -39,6 +39,9 @@
"clsx": "^2.1.1",
"cmdk": "^1.0.0"
},
+ "devDependencies": {
+ "@wordpress/base-styles": "file:../base-styles"
+ },
"peerDependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
diff --git a/packages/commands/src/components/style.scss b/packages/commands/src/components/style.scss
index b57b12baa0..11b96141e8 100644
--- a/packages/commands/src/components/style.scss
+++ b/packages/commands/src/components/style.scss
@@ -1,6 +1,6 @@
-@use "../../../base-styles/colors";
-@use "../../../base-styles/mixins";
-@use "../../../base-styles/variables";
+@use "@wordpress/base-styles/colors";
+@use "@wordpress/base-styles/mixins";
+@use "@wordpress/base-styles/variables";
// dirty hack to clean up modal
.commands-command-menu {There was a problem hiding this comment.
@use "@wordpress/base-styles/colors";
@use "@wordpress/base-styles/mixins";
@use "@wordpress/base-styles/variables";I don't think this syntax works with the Sass build process in Gutgenberg, so I think it's fine to leave the path as a relative path.
There was a problem hiding this comment.
Does the Sass compilation include node_modules as a lookup path, or should it?
Alternatively, in the spirit of modern Sass, we could look at incorporating NodePackageImporter and exposing entrypoints for Sass, so that it can be used directly from the package like this.
There was a problem hiding this comment.
Does the Sass compilation include
node_modulesas a lookup path, or should it?
I thought this part would handle the lookup paths nicely, but apparently not:
gutenberg/bin/packages/build-worker.js
Line 125 in a5e3592
After some experimentation, I found that the following approach works well:
Diff
diff --git a/bin/packages/build-worker.js b/bin/packages/build-worker.js
index 06e30efc6c..db6c7584a0 100644
--- a/bin/packages/build-worker.js
+++ b/bin/packages/build-worker.js
@@ -122,7 +122,10 @@ async function buildCSS( file ) {
const builtSass = await renderSass( {
file,
- includePaths: [ path.join( PACKAGES_DIR, 'base-styles' ) ],
+ includePaths: [
+ path.join( PACKAGES_DIR, 'base-styles' ),
+ path.join( __dirname, '../../node_modules' ),
+ ],
data: ''.concat( '@use "sass:math";', importLists, contents ),
} );
diff --git a/packages/commands/src/components/style.scss b/packages/commands/src/components/style.scss
index b57b12baa0..11b96141e8 100644
--- a/packages/commands/src/components/style.scss
+++ b/packages/commands/src/components/style.scss
@@ -1,6 +1,6 @@
-@use "../../../base-styles/colors";
-@use "../../../base-styles/mixins";
-@use "../../../base-styles/variables";
+@use "@wordpress/base-styles/colors";
+@use "@wordpress/base-styles/mixins";
+@use "@wordpress/base-styles/variables";
// dirty hack to clean up modal
.commands-command-menu {You can find a discussion about the includePath field here: #17883 (comment)
It seems like this field was added for the playground, but I don't understand why it doesn't work in the Gutenberg build 🤔
|
@m1r0 @mirka I saw that you solved the issue by importing built CSS (Automattic/wp-calypso#103652 (comment)). I want to confirm if we should move forward with this PR now. |
|
@t-hamano I can confirm that this is no longer a blocker for Calypso. Feel free to close/deprioritize this PR. |
|
It may be a good idea to close this PR for now. In the future, if plans arise to migrate the entire Gutenberg to a modern Sass system, it would be good to create a new issue based on the discussion held in this PR. |

What?
Relates to #37044 and Automattic/wp-calypso#103652
Why?
The PR makes the Commands package compatible with the new Sass module system (https://sass-lang.com/blog/the-module-system-is-launched/).
This is a blocker for updating the
@wordpresspackages in thewp-calypsorepo.How?
I used the
npx sass-migrator module division --verbose --migrate-deps packages/commands/src/components/style.scsscommand to migrate the code.Testing Instructions
Build the Commands package and ensure there are no errors. There should be no visual changes.