-
Notifications
You must be signed in to change notification settings - Fork 22
Feature: Add WordPress Block Metadata Collections Support #469
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
Open
fabiankaegy
wants to merge
10
commits into
develop
Choose a base branch
from
feature/block-manifest-generation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d92bdb2
feat(toolkit): add json2php dependency
fabiankaegy f1caee0
feat(toolkit): add build blocks manifest webpack plugin
fabiankaegy d28a27e
feat(toolkit): add useBlockManifest config option
fabiankaegy 5ee13e2
feat(toolkit): integrate build blocks manifest plugin
fabiankaegy b08fb3b
docs(toolkit): add changeset for block manifest feature
fabiankaegy 7875299
docs(toolkit): document block metadata collections
fabiankaegy 6875d72
test(toolkit): add tests for block manifest feature
fabiankaegy b8eac73
test(toolkit): add integration test for block manifest
fabiankaegy d5c2d6c
docs(toolkit): improve WordPress integration examples
fabiankaegy 4727a2f
docs(toolkit): clarify asset path transformation attribution
fabiankaegy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| "10up-toolkit": minor | ||
| --- | ||
|
|
||
| Add WordPress Block Metadata Collections API support | ||
|
|
||
| Integrate automatic generation of block metadata manifest files to improve block registration performance in WordPress 6.7+. When enabled, toolkit generates a PHP file (`blocks-manifest.php`) containing all block metadata from a single source, eliminating the need to read multiple `block.json` files at runtime. | ||
|
|
||
| **New Features:** | ||
| - Add `useBlockManifest` configuration option (boolean, default: `false`) | ||
| - Add `--block-manifest` CLI flag for one-time manifest generation | ||
| - Add `BuildBlocksManifestPlugin` webpack plugin that hooks into build completion | ||
| - Automatic manifest regeneration in watch mode when blocks change | ||
|
|
||
| **Configuration:** | ||
|
|
||
| Enable via package.json: | ||
| ```json | ||
| { | ||
| "10up-toolkit": { | ||
| "useBlockAssets": true, | ||
| "useBlockManifest": true | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Or via CLI flag: | ||
| ```bash | ||
| 10up-toolkit build --block-manifest | ||
| 10up-toolkit start --block-manifest | ||
| 10up-toolkit watch --block-manifest | ||
| ``` | ||
|
|
||
| **WordPress Integration:** | ||
|
|
||
| Register the collection and automatically register all blocks: | ||
| ```php | ||
| $blocks_dir = get_template_directory() . '/dist/blocks'; | ||
| $manifest_path = get_template_directory() . '/dist/blocks-manifest.php'; | ||
|
|
||
| wp_register_block_metadata_collection( $blocks_dir, $manifest_path ); | ||
|
|
||
| // Automatically register all blocks from the manifest | ||
| $manifest = require $manifest_path; | ||
| foreach ( array_keys( $manifest ) as $block_dir ) { | ||
| register_block_type_from_metadata( $blocks_dir . '/' . $block_dir ); | ||
| } | ||
| ``` | ||
|
|
||
| **Benefits:** | ||
| - Improved performance for projects with many blocks (50+) | ||
| - Reduced filesystem I/O operations | ||
| - Better opcode caching for block metadata | ||
| - Preserves transformed asset paths from the build process (TS→JS, SCSS→CSS) | ||
|
|
||
| The manifest is generated in `dist/blocks-manifest.php` and works seamlessly with the existing `useBlockAssets` workflow. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/toolkit/__tests__/build-project-block-manifest/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| dist |
20 changes: 20 additions & 0 deletions
20
..._tests__/build-project-block-manifest/__fixtures__/includes/blocks/example-one/block.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "title": "Example Block One", | ||
| "description": "First example block", | ||
| "textdomain": "test-blocks", | ||
| "name": "test/example-one", | ||
| "icon": "feedback", | ||
| "category": "test-blocks", | ||
| "attributes": { | ||
| "content": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "supports": { | ||
| "align": false, | ||
| "html": false | ||
| }, | ||
| "editorScript": "file:./index.js", | ||
| "editorStyle": "file:./editor.css", | ||
| "style": "file:./style.css" | ||
| } |
3 changes: 3 additions & 0 deletions
3
..._tests__/build-project-block-manifest/__fixtures__/includes/blocks/example-one/editor.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .wp-block-test-example-one { | ||
| color: blue; | ||
| } |
7 changes: 7 additions & 0 deletions
7
.../__tests__/build-project-block-manifest/__fixtures__/includes/blocks/example-one/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* eslint-disable import/no-unresolved */ | ||
| import { registerBlockType } from '@wordpress/blocks'; | ||
|
|
||
| registerBlockType('test/example-one', { | ||
| edit: () => 'Example One', | ||
| save: () => 'Example One', | ||
| }); |
3 changes: 3 additions & 0 deletions
3
...__tests__/build-project-block-manifest/__fixtures__/includes/blocks/example-one/style.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .wp-block-test-example-one { | ||
| margin: 1em; | ||
| } |
10 changes: 10 additions & 0 deletions
10
...ests__/build-project-block-manifest/__fixtures__/includes/blocks/example-three/block.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "title": "Example Block Three", | ||
| "description": "Third example block with TypeScript", | ||
| "textdomain": "test-blocks", | ||
| "name": "test/example-three", | ||
| "icon": "admin-tools", | ||
| "category": "test-blocks", | ||
| "editorScript": "file:./index.ts", | ||
| "style": "file:./style.scss" | ||
| } |
7 changes: 7 additions & 0 deletions
7
..._tests__/build-project-block-manifest/__fixtures__/includes/blocks/example-three/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* eslint-disable import/no-unresolved */ | ||
| import { registerBlockType } from '@wordpress/blocks'; | ||
|
|
||
| registerBlockType('test/example-three', { | ||
| edit: () => 'Example Three', | ||
| save: () => 'Example Three', | ||
| }); |
4 changes: 4 additions & 0 deletions
4
...ests__/build-project-block-manifest/__fixtures__/includes/blocks/example-three/style.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .wp-block-test-example-three { | ||
| $spacing: 2em; | ||
| padding: $spacing; | ||
| } |
20 changes: 20 additions & 0 deletions
20
..._tests__/build-project-block-manifest/__fixtures__/includes/blocks/example-two/block.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "title": "Example Block Two", | ||
| "description": "Second example block", | ||
| "textdomain": "test-blocks", | ||
| "name": "test/example-two", | ||
| "icon": "star-filled", | ||
| "category": "test-blocks", | ||
| "attributes": { | ||
| "message": { | ||
| "type": "string", | ||
| "default": "Hello" | ||
| } | ||
| }, | ||
| "supports": { | ||
| "align": true, | ||
| "html": false | ||
| }, | ||
| "editorScript": "file:./index.js", | ||
| "viewScript": "file:./view.js" | ||
| } |
7 changes: 7 additions & 0 deletions
7
.../__tests__/build-project-block-manifest/__fixtures__/includes/blocks/example-two/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* eslint-disable import/no-unresolved */ | ||
| import { registerBlockType } from '@wordpress/blocks'; | ||
|
|
||
| registerBlockType('test/example-two', { | ||
| edit: () => 'Example Two', | ||
| save: () => 'Example Two', | ||
| }); |
1 change: 1 addition & 0 deletions
1
...t/__tests__/build-project-block-manifest/__fixtures__/includes/blocks/example-two/view.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log('Example Two view script'); |
10 changes: 10 additions & 0 deletions
10
packages/toolkit/__tests__/build-project-block-manifest/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "test-build-project-block-manifest", | ||
| "10up-toolkit": { | ||
| "useBlockAssets": true, | ||
| "useBlockManifest": true, | ||
| "paths": { | ||
| "blocksDir": "./__fixtures__/includes/blocks" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.