-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Packages: Move Custom CSS Properties to new calypso-css-custom-properties
package
#30933
Conversation
fc8b1e1
to
6120300
Compare
assets/stylesheets/shared/
to new calypso-shared-style
packageassets/stylesheets/shared/
to new calypso-shared-style
package
assets/stylesheets/shared/
to new calypso-shared-style
packagecalypso-css-custom-properties
package
I totally agree it's too rigid. I think we could move to using a |
44ec31e
to
583ce6a
Compare
Let's merge #30969 before this, rebase this PR, and apply this patch afterwards (background): (Edit: done) diff --git a/assets/stylesheets/directly.scss b/assets/stylesheets/directly.scss
index a82a2514a1..a6c71ca7b1 100644
--- a/assets/stylesheets/directly.scss
+++ b/assets/stylesheets/directly.scss
@@ -33,7 +33,7 @@
// QUIT AND RESTART YOUR BROWSER NORMALLY WHEN YOU'RE DONE MAKING LOCAL CSS CHANGES.
@import 'shared/mixins/mixins';
-@import '../../node_modules/@automattic/calypso-css-custom-properties/src/shared/colors';
+@import '~@automattic/calypso-css-custom-properties/src/shared/colors';
@import 'shared/extends-forms';
@import 'shared/forms';
@import 'shared/typography';
diff --git a/assets/stylesheets/editor.scss b/assets/stylesheets/editor.scss
index 36d5d6fda0..048b452af8 100644
--- a/assets/stylesheets/editor.scss
+++ b/assets/stylesheets/editor.scss
@@ -1,5 +1,5 @@
-@import '../../node_modules/@automattic/calypso-css-custom-properties/src/shared/colors';
-@import '../../node_modules/@automattic/calypso-css-custom-properties/src/shared/color-schemes';
+@import '~@automattic/calypso-css-custom-properties/src/shared/colors';
+@import '~@automattic/calypso-css-custom-properties/src/shared/color-schemes';
@import 'shared/typography';
@import 'shared/mixins/breakpoints';
diff --git a/assets/stylesheets/emergent-paywall.scss b/assets/stylesheets/emergent-paywall.scss
index bfd605c5cd..9c85ea5615 100644
--- a/assets/stylesheets/emergent-paywall.scss
+++ b/assets/stylesheets/emergent-paywall.scss
@@ -28,7 +28,7 @@
// QUIT AND RESTART YOUR BROWSER NORMALLY WHEN YOU'RE DONE MAKING LOCAL CSS CHANGES.
@import 'shared/mixins/mixins';
-@import '../../node_modules/@automattic/calypso-css-custom-properties/src/shared/colors';
+@import '~@automattic/calypso-css-custom-properties/src/shared/colors';
@import 'shared/extends-forms';
@import 'shared/forms';
@import 'shared/typography';
diff --git a/assets/stylesheets/shared/_utils.scss b/assets/stylesheets/shared/_utils.scss
index d4fabf9b6f..df14dbf1c8 100644
--- a/assets/stylesheets/shared/_utils.scss
+++ b/assets/stylesheets/shared/_utils.scss
@@ -1,6 +1,6 @@
@import '../shared/functions'; // functions that we've used from Compass, ported over
@import '../shared/functions/functions'; // sass functions for z-index, etc.
-@import '../../../node_modules/@automattic/calypso-css-custom-properties/src/shared/colors'; // import all of our wpcom colors
+@import '~@automattic/calypso-css-custom-properties/src/shared/colors'; // import all of our wpcom colors
@import '../shared/typography'; // all the typographic rules, variables, etc.
@import '../shared/variables'; // other variables
@import '../shared/mixins/mixins'; // sass mixins for gradients, bordius radii, etc.
diff --git a/assets/stylesheets/shared/functions/_functions.scss b/assets/stylesheets/shared/functions/_functions.scss
index 1703cff79e..24684c455e 100644
--- a/assets/stylesheets/shared/functions/_functions.scss
+++ b/assets/stylesheets/shared/functions/_functions.scss
@@ -1,3 +1,3 @@
-@import '../../../../node_modules/@automattic/calypso-css-custom-properties/src/shared/functions/_hex-to-rgb';
+@import '~@automattic/calypso-css-custom-properties/src/shared/functions/_hex-to-rgb';
@import 'overflow-gradient';
@import 'z-index';
diff --git a/assets/stylesheets/style.scss b/assets/stylesheets/style.scss
index 32095d14c1..7c2c17b2ab 100644
--- a/assets/stylesheets/style.scss
+++ b/assets/stylesheets/style.scss
@@ -4,7 +4,7 @@
// Shared
@import 'shared/reset'; // css reset before the rest of the styles are defined
@import 'shared/utils'; // utilities that are used by all CSS but don't produce any code
-@import '../../node_modules/@automattic/calypso-css-custom-properties/src/shared/color-schemes'; // import color schemes
+@import '~@automattic/calypso-css-custom-properties/src/shared/color-schemes'; // import color schemes
@import 'shared/animation'; // all UI animation
@import 'shared/forms'; // form styling
@import 'shared/welcome'; // welcome messages |
Ordering is even going to be interesting when packaging these things -- if this package wanted to provide a script that relies on a Thinking of breaking the vicious cycle by filing a PR to simply have each package provide a build script for now that doesn't rely on any TBD packages. |
d7a68d2
to
3d368cf
Compare
@@ -1,5 +1,5 @@ | |||
// The Muriel Color Palette | |||
@import '~color-studio/dist/color-variables'; | |||
@import '../../node_modules/color-studio/dist/color-variables'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I essentially reverted this change here. The reason is that node-sass-package-importer
isn't great at transitivity:
Calypso doesn't just import calypso-css-custom-properties
' main entry point (dist/custom-properties.css
), but continues to also import this file (shared/colors
) which in turn has the import of color-studio
's color-variables
file I'm modifying here.
Now if we used the node-sass-package-importer
-based import notation (@import '~color-studio/dist/color-variables'
), any consumer of that package would look for that path in its own node_modules/
directory -- rather than (transitively) in calypso-sdk-custom-properties
. It follows that:
- Any consumer of
calypso-sdk-custom-properties
(including Calypso!) will either have to installcolor-studio
itself (by adding it to its ownpackage.json
, or calypso-css-custom-properties
would need to add another build step to provide a file where thisimport
is resolved.
Or we just make the import
path explicit like I'm doing here, which seems like a lot less hassle 😄 it's calypso-css-custom-properties
's only import of an external SASS file anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have to use the tilde syntax here. The location of node_modules
relative to this file isn't guaranteed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, sure about that? (Or maybe I'm really getting my wires crossed here.)
This (i.e. the src/shared/_colors.scss
file in the calypso-css-custom-properties
package) is referring to that package's own node_modules/
directory here (whose relative location should thus be known and invariant).
The issue is with consuming projects that import this file: if they see a @import '~color-studio/dist/color-variables'
in it, they'll look for that file in their own node_modules/
rather than in calypso-css-custom-properties
's -- and they won't fit there (unless it's also installed there -- but requiring them to would kinda suck, see my previous comment).
(This is kinda backed up by my experiments with both notations 😬 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(My generalized takeaway would BTW be -- Don't use ~
SASS imports in npm modules (libraries) but only in apps that aren't published/imported by other projects (b/c of lack of transitivity))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (i.e. the
src/shared/_colors.scss
file in thecalypso-css-custom-properties
package) is referring to that package's ownnode_modules/
directory here (whose relative location should thus be known and invariant).
Try running npm dedupe
on this branch. color-studio
will get hoisted to the root node_modules
and the node_modules
under color-studio
will be removed. Yay for npm's non-determinism. Another way to get there would be to add color-studio
as a dependency to the root package.json, then run npm run update-deps
.
The issue is with consuming projects that import this file: if they see a
@import '~color-studio/dist/color-variables'
in it, they'll look for that file in their ownnode_modules/
rather than incalypso-css-custom-properties
's
Consuming projects should depend on the package, which depends on color-studio, so it should be present somewhere in the node_modules tree. If consuming projects are using this file on it's own without the supporting npm infrastructure ... I dunno.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (i.e. the
src/shared/_colors.scss
file in thecalypso-css-custom-properties
package) is referring to that package's ownnode_modules/
directory here (whose relative location should thus be known and invariant).Try running
npm dedupe
on this branch.color-studio
will get hoisted to the rootnode_modules
and thenode_modules
undercolor-studio
will be removed.
Okay, can repro -- that makes the build fail 🙁
Yay for npm's non-determinism. Another way to get there would be to add
color-studio
as a dependency to the root package.json, then runnpm run update-deps
.The issue is with consuming projects that import this file: if they see a
@import '~color-studio/dist/color-variables'
in it, they'll look for that file in their ownnode_modules/
rather than incalypso-css-custom-properties
'sConsuming projects should depend on the package, which depends on color-studio, so it should be present somewhere in the node_modules tree. If consuming projects are using this file on it's own without the supporting npm infrastructure ... I dunno.
So to recap: Starting from a clean slate (npm run distclean && npm ci
):
- With
@import '../../node_modules/color-studio/dist/color-variables';
: afternpm dedupe
,npm start
fails becausecolor-studio
has been hoisted to the top-levelnode_modules/
. (It works ifnpm dedupe
isn't called, though.) - With
@import '~color-studio/dist/color-variables';
:npm start
fails, because it's looking forcolor-studio
in the top-levelnode_modules/
(but it hasn't been installed explicitly there, nor hoisted.npm dedupe
makes it work).
So how do we get out of this mess? Just install color-studio
explicitly at the top level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
@import '~color-studio/dist/color-variables';
:npm start
fails, because it's looking forcolor-studio
in the top-levelnode_modules/
(but it hasn't been installed explicitly there, nor hoisted.npm dedupe
makes it work).
In this case, who's doing the import? Something in assets/stylesheets or something in calypso-css-custom-properties? If the former, yeah, we'd have to add a dependency on color-studio to the root for resolution to work. If the latter, ... I would expect that to work and would need to dig more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting observation. So, with the following directory structure:
node_modules/color-studio/index.scss
color-schemes/node_modules/color-studio/index.scss
color-schemes/index.scss
and contents of color-schemes/index.scss
:
@import '~color-studio';
the import gets resolved to node_modules/color-studio
instead of color-schemes/node_modules/color-studio
? That's not how the resolution algorithm should work and it's a bug in node-sass-package-importer
.
The node-sass
importer function gets the file path from where the import is performed as the second parameter and it should use it to resolve:
function importer( url, prev ) {
if ( ! url.startsWith( '~' ) ) {
return null; // not our business to resolve this path
}
return resolve.sync( url.slice( 1 ), { baseDir: dirname( prev ) } );
}
What node-sass-package-importer
does instead is that is passes process.cwd()
as baseDir
.
The other package that @blowery suggested in #30933 (comment), https://github.com/anarh/node-sass-import, doesn't have this bug. But it doesn't support the ~
prefix 🙁
Not a reason to block this PR, the __color-studio
solution is OK, but would be nice to file some issues and come back some time later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for digging into that @jsnajdr !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some experimenting with how npm handles lifecycle hooks with file refs. It looks like we could add a So root package.json would have One nice thing here is that |
0fbff62
to
2e575b0
Compare
1015c77
to
82ec0a7
Compare
This shrinkwrap has tabs at 1015c77 😱 There was another new conflict, I've rebased and cleaned up some of the messier tabs/spaces commits. A new shrinkwrap generated at the HEAD uses spaces. |
@@ -249,7 +247,7 @@ | |||
"clean": "npm run -s clean:build && npm run -s clean:devdocs && npm run -s clean:public && npm run -s clean:packages", | |||
"clean:build": "npx rimraf build server/bundler/*.json .babel-cache", | |||
"clean:devdocs": "npx rimraf server/devdocs/search-index.js server/devdocs/proptypes-index.json server/devdocs/components-usage-stats.json", | |||
"clean:packages": "npx rimraf packages/*/dist", | |||
"clean:packages": "npx lerna run clean", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we --stream
this like build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. it just changes the output format. i don't have a strong preference between standard and stream.
Tests are still passing after rebase, I'll smoke test and plan to land this if things look good. |
|
||
if ( ! existsSync( dirname( OUTPUT_FILE ) ) ) { | ||
mkdirSync( dirname( OUTPUT_FILE ), { recursive: true } ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add an exitsSync
check since my reading (and testing) of the recursive: true
arg was that it worked even if the path existed already 😬 (But I should've commented to that effect.)
Preparatory step to move Calypso's build system into an npm.
See #30772 (comment) (and conversation below) for background.
Questions/Notes
calypso-css-custom-properties
)? Yay? Nay?assets/stylesheets/shared/
folder (and was going to call the packagecalypso-shared-style
), but decided to keep the package as minimal as possible instead. Thoughts?Resolved, see Packages: Build individually #31112bin/build-packages
doesn't work for styling-only packages. I think it's too rigid (might also be for different kinds of packages) -- my suggestion would be to make the build process each package's individual concern for greater flexibility, i.e. havebin/build-packages
just run each package'snpm run build
. IIRC, lerna had a way to do that (but maybe only as part ofbootstrap
).Changes proposed in this Pull Request
calypso-css-custom-properties
packageTesting instructions
npm run distclean
npm start
Verify that Calypso runs as before, and that styling isn't broken.