-
Notifications
You must be signed in to change notification settings - Fork 4.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 the components module partially to the packages folder #7640
Conversation
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.
It doesn't use
@wordpress/utils
anymore. I copied the last remaining function (Sometimes copy pasting small function is better than figuring out a complex setup)
That's because @wordpress/utils
isn't published, right? Could you add a note about the duplicated function maybe? I agree with you about it not being worth a complex set up, but if it were a matter of just including another module dependancy available from NPM I'd say we should move to that once possible.
I have some questions about the change of style imports used but largely looks good.
@@ -14,12 +14,16 @@ const glob = require( 'glob' ); | |||
const babel = require( 'babel-core' ); | |||
const chalk = require( 'chalk' ); | |||
const mkdirp = require( 'mkdirp' ); | |||
const sass = require( 'node-sass' ); | |||
const postcss = require( 'postcss' ); | |||
const deasync = require( 'deasync' ); |
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 a tough one to read… might be nicer to import as deAsync
🤷♂️
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.
Even if it's nonsense, we should be strictly consistent in our camelcasing. If this were a module named de-async
, I'd agree deAsync
would be reasonable. Same reason we [should] use import classnames from 'classnames';
and not import classNames from 'classnames';
.
bin/packages/build.js
Outdated
const builtSass = sass.renderSync( { | ||
file: styleFile, | ||
includePaths: [ path.resolve( __dirname, '../../edit-post/assets/stylesheets' ) ], | ||
data: '@import "colors"; @import "breakpoints"; @import "variables"; @import "mixins"; @import "animations";@import "z-index";' + |
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.
Could this be… a multiline template string or something? To increase readability? If not it's fine and it's easy to grok after a second, but it's just a bit harsh 😄
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.
Could this be… a multiline template string or something?
Maybe just an array mapping (or reduce) result:
[
'colors',
'breakpoints',
'variables',
'mixins',
'animations',
'z-index',
].map( ( imported ) => `import "${ imported }";` ).join( '' );
bin/packages/build.js
Outdated
}; | ||
|
||
const result = deasync( postCSSSync )(); | ||
fs.writeFileSync( outputFile, result.css, () => 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.
What's the no-op return true function for?
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 don't know :) copy pasted from the docs of postcss :)
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.
Since this will be confusing to the hypothetical future maintainer, we should do one of:
- Explain why it exists in an inline comment
- Remove it
components/index.js
Outdated
export { default as Tooltip } from './tooltip'; | ||
export { default as TreeSelect } from './tree-select'; | ||
export { createSlotFill, Slot, Fill, Provider as SlotFillProvider } from './slot-fill'; | ||
export * from '../packages/components/src'; |
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.
Nice.
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.
Update: I see it's basically just moved, haha.
@@ -13,7 +13,6 @@ import { Component } from '@wordpress/element'; | |||
/** | |||
* Internal dependencies | |||
*/ | |||
import './style.scss'; |
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.
Why aren't these importing their local stylesheets anymore? Are they being magically loaded in from elsewhere?
@@ -14,7 +14,8 @@ $datepicker__muted-color: #ccc; | |||
$datepicker__navigation-disabled-color: lighten($datepicker__muted-color, 10%); | |||
$datepicker__border-color: $light-gray-500; | |||
|
|||
@import '~react-datepicker/src/stylesheets/datepicker'; | |||
// Lerna hoist packages, so can't reference with ~ |
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 these comments be "hoists packages"?
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.
We no longer use lerna bootstrap --hoist
, I'm wondering if it is still the case.
@@ -0,0 +1,34 @@ | |||
@import './autocomplete/style.scss'; |
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.
Oh, I see. So is every component's style loaded here now instead of in the component? That strikes me as less follow-able.
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.
can we generate this file using glob
?
Why is:
Needed? It makes it harder to look at a component's |
It is needed because we need a way to build a stylesheet per package for npm consumption and we don't use It's probably possible to use
I also do but in our case, I don't think it was good because we're not really using the imported value we just extract and concat all the stylesheets together. I think it can mislead people to think that the styles are scoped while in fact they are not. I think it's a good pattern to use with CSS modules or any CSS in JS solution but in our case, I think it's a bit misleading. |
Ah, that explanation helps a lot. Thanks. 👍 |
bin/packages/build.js
Outdated
const builtSass = sass.renderSync( { | ||
file: styleFile, | ||
includePaths: [ path.resolve( __dirname, '../../edit-post/assets/stylesheets' ) ], | ||
data: '@import "colors"; @import "breakpoints"; @import "variables"; @import "mixins"; @import "animations";@import "z-index";' + |
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.
Could this be… a multiline template string or something?
Maybe just an array mapping (or reduce) result:
[
'colors',
'breakpoints',
'variables',
'mixins',
'animations',
'z-index',
].map( ( imported ) => `import "${ imported }";` ).join( '' );
bin/packages/build.js
Outdated
}; | ||
|
||
const result = deasync( postCSSSync )(); | ||
fs.writeFileSync( outputFile, result.css, () => 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.
Since this will be confusing to the hypothetical future maintainer, we should do one of:
- Explain why it exists in an inline comment
- Remove it
const styleFile = path.resolve( packagePath, SRC_DIR, 'style.scss' ); | ||
const outputFile = path.resolve( packagePath, BUILD_DIR.style, 'style.css' ); | ||
mkdirp.sync( path.dirname( outputFile ) ); | ||
const builtSass = sass.renderSync( { |
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 know it's convenient for development, but a build script responsible for generating many distinct modules seems particularly write for an async implementation, not sync.
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.
yes, true. I think this could be handled separately as it has implications on the whole build
script and not only the styles build script.
bin/packages/post-css-config.js
Outdated
@@ -0,0 +1,64 @@ | |||
module.exports = [ | |||
require( '../../packages/postcss-themes/src/index.js' )( { |
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.
What if src/index.js
contains code not supported by Node native? We're assumed to be able to use modern features there, and this may subtly break in the future.
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.
We can use @wordpress/postcss-themes
since we started using local packages.
@@ -14,7 +14,8 @@ $datepicker__muted-color: #ccc; | |||
$datepicker__navigation-disabled-color: lighten($datepicker__muted-color, 10%); | |||
$datepicker__border-color: $light-gray-500; | |||
|
|||
@import '~react-datepicker/src/stylesheets/datepicker'; | |||
// Lerna hoist packages, so can't reference with ~ |
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.
We no longer use lerna bootstrap --hoist
, I'm wondering if it is still the case.
@@ -0,0 +1,34 @@ | |||
@import './autocomplete/style.scss'; |
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.
can we generate this file using glob
?
require( 'autoprefixer' ), | ||
require( 'postcss-color-function' ), | ||
], | ||
plugins: require( './bin/packages/post-css-config' ), |
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.
Is this related to components
package in any way? I'm wondering if this is something mandatory to be included in this PR. I'm not against, it's rather me trying to understand how it relates.
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 only because we're using the same config here and in the build script of the packages. It can be removed from webpack once all packages are moved to the lerna setup.
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.
Cool, it makes sense 👍
packages/components/package.json
Outdated
"@wordpress/keycodes": "^1.0.0-alpha.1", | ||
"@wordpress/i18n": "1.1.0", | ||
"@wordpress/is-shallow-equal": "1.0.2", | ||
"classnames": "2.2.5", |
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 bundle classnames
into element
or mark it as external dependency and convert it into its own WP module?
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 don't know if it's really an issue, it's 1kb unminified.
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.
Right, it probably would make more sense with other packages as noted here: #7640 (comment)
packages/components/package.json
Outdated
"main": "build/index.js", | ||
"module": "build-module/index.js", | ||
"dependencies": { | ||
"@wordpress/a11y": "1.0.6", |
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.
After we upgraded to Lerna 3.x, this should use local packages:
"@wordpress/a11y": "file:../a11y",
"@wordpress/api-request": "file:../api-request",
// etc.
packages/components/package.json
Outdated
"clipboard": "1.7.1", | ||
"dom-scroll-into-view": "1.2.1", | ||
"http-build-query": "0.7.0", | ||
"lodash": "4.17.5", |
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.
"lodash": "4.17.10"
- we now use a different version of lodash
.
packages/components/package.json
Outdated
"react-click-outside": "2.3.1", | ||
"react-color": "2.13.4", | ||
"react-datepicker": "1.4.1", | ||
"rememo": "3.0.0", |
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 noticed that not only classnames
is used in a few packages, but also:
memize
, rememo
or uuid
. We probably should create a vendor bundle and put them together there to optimize code send to the browser.
packages/components/README.md
Outdated
Components | ||
========== | ||
|
||
This packages includes a library of generic React components to be used for creating common UI elements shared between screens and features of the WordPress dashboard. |
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.
React components
- should we call them WordPress components instead?
We don't want to publish |
4d1e43d
to
f1c1efe
Compare
e3afd8f
to
6ec5b63
Compare
bin/packages/post-css-config.js
Outdated
@@ -0,0 +1,64 @@ | |||
module.exports = [ | |||
require( '../../packages/postcss-themes/src/index' )( { |
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'm wondering if we can use @wordpress/postcss-themes
instead?
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.
Let me give it a try :)
3b8babd
to
6e115e9
Compare
Doing sanity check for chunks sent to the browser using Before
After
|
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.
In my testing everything works great. Let's merge it and observe how it works.
Some further improvements we should look into:
- collect all the
.scss
files using script rather than maintain the list manually INCLUDE_PACKAGES
inbuld:packages
needs some rework. It would be nice to keep this list in the config or even build it based onpackage.json
file using whitelist fromdevDependencies
.
This PR makes the components module a generic npm ready package.
@wordpress/utils
anymore. I copied the last remaining function (Sometimes copy pasting small function is better than figuring out a complex setup)buildStyle
function to the build script of the packages to generate a CSS file per package if needed. The package should have asrc/style.scss
as an entry point.CodeEditor
component outside of the components npm package because it's not ready: It needs lazyloading (babel plugin) and a dependency towards@wordpress/code-editor
dashicon/index.js
file, I know @aduth planned to work on it, so we need to sync here.