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.
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.
We probably can remove this file and ensure that Mobile loads the package directly.
@hypest any thoughts?
| 'wp-blocks', | ||
| 'wp-components', | ||
| 'wp-compose', | ||
| 'wp-data', |
| "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", |
|
|
||
| const { | ||
| WP_BASE_URL = 'http://localhost:8889', | ||
| WP_BASE_URL = 'http://localhost:8888', |
| import * as verse from './verse'; | ||
| import * as video from './video'; | ||
|
|
||
| export const registerCoreBlocks = () => { |
There was a problem hiding this comment.
So we have it duplicated in here but without two problematic blocks. Interesting.
| registerBlockType( name, settings ); | ||
| } ); | ||
|
|
||
| setDefaultBlockName( paragraph.name ); |
There was a problem hiding this comment.
We don't call setUnknownTypeHandlerName. Will it cause some issues?
There was a problem hiding this comment.
Ironically, we can't set it to both HTML and Freeform :(
| }, | ||
| "main": "build/index.js", | ||
| "module": "build-module/index.js", | ||
| "dependencies": { |
There was a problem hiding this comment.
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 🤷♂️ |
bin/build-plugin-zip.sh
Outdated
| gutenberg.php \ | ||
| lib/*.php \ | ||
| core-blocks/*/*.php \ | ||
| packages/core-blocks/src/*/*.php \ |
There was a problem hiding this comment.
I think we agreed to rename this stuff to blocks-library or something along those lines. /cc @mtias
| @@ -0,0 +1,21 @@ | |||
| # Core Blocks | |||
|
|
|||
| Core Blocks for the WordPress editor. | |||
There was a problem hiding this comment.
This would become:
Blocks library for the WordPress editor.
| export const registerCoreBlocks = () => { | ||
| [ | ||
| code, | ||
| more, |
There was a problem hiding this comment.
I think, it needs rebase. Paragraph was exposed recently.
| @import './text-columns/style.scss'; | ||
| @import './video/style.scss'; | ||
|
|
||
| .has-pale-pink-background-color { |
There was a problem hiding this comment.
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
|
|
||
| // Build entire package scss. | ||
| buildPackageScss( packagePath ); | ||
| const scssFiles = glob.sync( `${ srcDir }/*.scss` ); |
There was a problem hiding this comment.
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.
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.scssone 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 |
gziolo
left a comment
There was a problem hiding this comment.
In my testing, everything works like before. All changes I can think of were applied. We have deprecation in place.
Let's 🚢
Great work🏅
tofumatt
left a comment
There was a problem hiding this comment.
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.
| - [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.
While we're updating the name, calling these "built-in" or "default" blocks might be nicer than "core blocks". Thoughts?
| # **core/editor**: The Editor’s Data | ||
|
|
||
| ## Selectors | ||
| ## Selectors |
There was a problem hiding this comment.
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.
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.
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.
Ah, okay, gotcha! That makes sense, I'll ignore it then. 👍
tofumatt
left a comment
There was a problem hiding this comment.
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.
@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.
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.
|
|
||
| const { | ||
| WP_BASE_URL = 'http://localhost:8889', | ||
| WP_BASE_URL = 'http://localhost:8888', |
There was a problem hiding this comment.
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.
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.
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?
This PR tries to extract the core blocks package partially to the npm packages folder.
It lives these two blocks out:
CodeEditorcomponent which is not available in thenpmcomponents 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