-
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
Extract Core Blocks to the npm packages folder #8287
Conversation
57a6414
to
ca40fba
Compare
core-blocks/index.js
Outdated
import * as verse from '../packages/core-blocks/src/verse'; | ||
import * as video from '../packages/core-blocks/src/video'; | ||
|
||
// The freeform block can't be moved to the "npm" packages folder because it requires the wp.oldEditor global. |
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's hope that order of imports doesn't matter anymore :)
core-blocks/index.native.js
Outdated
registerBlockType( name, settings ); | ||
} ); | ||
}; | ||
import '../packages/core-blocks/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.
We probably can remove this file and ensure that Mobile loads the package directly.
@hypest any thoughts?
'wp-blob', | ||
'wp-blocks', | ||
'wp-components', | ||
'wp-compose', | ||
'wp-data', |
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.
How it even worked before? 😅
"fixtures:clean": "rimraf \"core-blocks/test/fixtures/*.+(json|serialized.html)\"", | ||
"fixtures:server-registered": "docker-compose run -w /var/www/html/wp-content/plugins/gutenberg --rm wordpress ./bin/get-server-blocks.php > core-blocks/test/server-registered.json", | ||
"fixtures:clean": "rimraf \"test/integration/full-content/fixtures/*.+(json|serialized.html)\"", | ||
"fixtures:server-registered": "docker-compose run -w /var/www/html/wp-content/plugins/gutenberg --rm wordpress ./bin/get-server-blocks.php > test/integration/full-content/server-registered.json", |
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.
Good one 👍
test/e2e/support/utils.js
Outdated
@@ -10,7 +10,7 @@ import { URL } from 'url'; | |||
import { times } from 'lodash'; | |||
|
|||
const { | |||
WP_BASE_URL = 'http://localhost:8889', | |||
WP_BASE_URL = 'http://localhost:8888', |
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 that intended change?
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.
no :P
packages/core-blocks/src/index.js
Outdated
import * as verse from './verse'; | ||
import * as video from './video'; | ||
|
||
export const registerCoreBlocks = () => { |
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.
So we have it duplicated in here but without two problematic blocks. Interesting.
packages/core-blocks/src/index.js
Outdated
registerBlockType( name, settings ); | ||
} ); | ||
|
||
setDefaultBlockName( paragraph.name ); |
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 don't call setUnknownTypeHandlerName
. Will it cause some issues?
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.
Ironically, we can't set it to both HTML
and Freeform
:(
packages/core-blocks/package.json
Outdated
}, | ||
"main": "build/index.js", | ||
"module": "build-module/index.js", | ||
"dependencies": { |
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 need also an entry point for React Native:
"react-native": "src/index",
Would it be fair to say that the component could be used if the global (or some appropriately-named alternative) is available? Or some way to provide the implementation at runtime? |
Yes, that's true (I prefer avoiding the global though, a setter at runtime possible) but I kind of hope all WP JS scripts become packages at some point 🤷♂️ |
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 PR needs rebase.
bin/build-plugin-zip.sh
Outdated
@@ -121,6 +121,7 @@ zip -r gutenberg.zip \ | |||
gutenberg.php \ | |||
lib/*.php \ | |||
core-blocks/*/*.php \ | |||
packages/core-blocks/src/*/*.php \ |
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 we agreed to rename this stuff to blocks-library
or something along those lines. /cc @mtias
packages/core-blocks/README.md
Outdated
@@ -0,0 +1,21 @@ | |||
# Core Blocks | |||
|
|||
Core Blocks for the WordPress editor. |
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 would become:
Blocks library for the WordPress editor.
export const registerCoreBlocks = () => { | ||
[ | ||
code, | ||
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.
I think, it needs rebase. Paragraph was exposed recently.
packages/core-blocks/src/style.scss
Outdated
@import './text-columns/style.scss'; | ||
@import './video/style.scss'; | ||
|
||
.has-pale-pink-background-color { |
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 put colors in its own file? I'm also not quite sure why they are located in this package?
Another way of tackling it is to use the same approach we did for |
Let's tackle this one separately and focus on exposing blocks to npm so people could start experimenting. |
ca40fba
to
c72500b
Compare
I rebased with master and tested it locally. So far everything looks good 👍 |
I feel this is important for npm people to be able to show the block styles properly |
c72500b
to
8362a83
Compare
8362a83 tries to solve the issue with the styles prepared for npm publish. It might not fully work, but in general creates files properly :) |
bin/packages/build.js
Outdated
@@ -203,8 +207,10 @@ function buildPackage( packagePath ) { | |||
// Build js files individually. | |||
jsFiles.forEach( ( file ) => buildJsFile( file, true ) ); | |||
|
|||
// Build entire package scss. | |||
buildPackageScss( packagePath ); | |||
const scssFiles = glob.sync( `${ srcDir }/*.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.
So if I understand properly, this considers all root level files in as entry points. I personally don't like this convention because in some packages a src/style.scss
may import and src/something.scss
and we'd still have a unique entry point.
I think I'd prefer having the current behavior: the src/style.scss
file convention as a fallback and explicit entry points (maybe a custom property in the package.json
in case there are multiple)
That said, I can be ok with the current behavior temporarily, I'd like if we document it somewhere though.
Last thing, I think this breaks "watching" sass files, we probably have to rebuild all the files and not only the style.scss
one if a sass file changes.
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.
Personally, I would go further and glob for all scss
files, the same way we do it for JS files. The next step would be a bit different. Instead of transpiling all of them as it happens for JS, we would group them based on the file name and produce one .css
, e.g. all style.scss
files from one package would get merged into build-style/style.css
.
// Exclude deceitful source-like files, such as editor swap files.
const isSourceFile = ( filename ) => {
return /.\.(js|scss)$/.test( filename );
};
Last thing, I think this breaks "watching" sass files, we probably have to rebuild all the files and not only the
style.scss
one if a sass file changes.
execSync( `${ BUILD_CMD } ${ files.join( ' ' ) }`, { stdio: [ 0, 1, 2 ] } );
Yes, correct. We need to improve this one somehow. It probably would make sense to implement the grouping I described which would ultimately solve the latter.
2606854
to
4e11e6d
Compare
a83d982
to
1717c65
Compare
I think we need to provide deprecation strategy 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.
In my testing, everything works like before. All changes I can think of were applied. We have deprecation in place.
Let's 🚢
Great work🏅
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 have a few tweaks but I'll make them myself. Only question is do we have an issue for that 3.8 deprecation? I know we'll probably remember it, but an issue in the milestone might be nice as it doesn't look like our linter will catch it.
@@ -5,7 +5,7 @@ It turns out that writing the simplest possible block which contains only static | |||
- [zgordon/gutenberg-course](https://github.com/zgordon/gutenberg-course) - a repository for Zac Gordon's Gutenberg Development Course | |||
- [ahmadawais/create-guten-block](https://github.com/ahmadawais/create-guten-block) - A zero-configuration developer toolkit for building WordPress Gutenberg block plugins | |||
|
|||
It might be also a good idea to browse the folder with [all core blocks](https://github.com/WordPress/gutenberg/tree/master/core-blocks) to see how they are implemented. | |||
It might be also a good idea to browse the folder with [all core blocks](https://github.com/WordPress/gutenberg/tree/master/packages/block-library/src) to see how they are implemented. |
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.
While we're updating the name, calling these "built-in" or "default" blocks might be nicer than "core blocks". Thoughts?
@@ -1,6 +1,6 @@ | |||
# **core/editor**: The Editor’s Data | |||
|
|||
## Selectors | |||
## Selectors |
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.
Trailing whitespace! 😱
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 is generated, we might have an issue in the build tool
filemtime( gutenberg_dir_path() . 'build/block-library/index.js' ), | ||
true | ||
); | ||
// Remove it with 3.8.0 release. |
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 tag this so it's findable or have an issue for it referenced here? Anything so this doesn't get lost.
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 it's fine, I think we don't need the comment at all because the deprecated call on the frontend will be caught and when we remove it, the module will be empty.
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.
Ah, okay, gotcha! That makes sense, I'll ignore it then. 👍
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.
Looks like my comments have been addressed and this doesn't actually need any modification then.
@@ -16,11 +16,7 @@ import { | |||
unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase | |||
} from '@wordpress/blocks'; | |||
import { parse as grammarParse } from '@wordpress/block-serialization-spec-parser'; | |||
|
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.
@youknowriad I think this file no longer runs as part of npm run test-unit
? Is that intentional? Additionally require( '../../packages/editor/src/hooks' );
won't work if forced to run.
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.
Good catch, It was not intentional, I just moved it to the integration tests folder but apparently this folder needs a .spec
in the file name to run tests.
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 should be fixed in #8923
@@ -10,7 +10,7 @@ import { URL } from 'url'; | |||
import { times, castArray } from 'lodash'; | |||
|
|||
const { | |||
WP_BASE_URL = 'http://localhost:8889', | |||
WP_BASE_URL = 'http://localhost:8888', |
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 this huge diff I missed this change, but we shouldn't be doing this. We have a separate test environment for a reason 😄
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.
Sorry that was a debug change :), I would have expected the tests to fail because of this change :P
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.
Yeah, I'm a bit surprised they didn't, but actually the point is to have a fresh state that's always reset for the tests… it might be that because the tests on Travis are fresh no matter what it worked. I'll see about adding a check for this that at least warns us in my fix?
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.
Good catch.
This PR tries to extract the core blocks package partially to the npm packages folder.
It lives these two blocks out:
CodeEditor
component which is not available in thenpm
components package (due to lazy loading issues, related Tips: status should be user-based not browser-based #8052 Babel Plugin Async Load: Lazy load react components when necessary #8017)wp.oldEditor
. The only way to do so would be to make sure the old editor is also available as an npm package. Not sure if possible cc @iseuldeTesting instructionss