Feature : Add support for building blocks in theme updates#624
Merged
sagarjadhav merged 7 commits intofeature/support-for-building-blocks-in-themefrom Mar 13, 2026
Conversation
073fec6
into
feature/support-for-building-blocks-in-theme
8 checks passed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Improves block development tooling by adding stricter CLI validation, fixing block registration edge cases, introducing cross-platform block build scripts, and updating block development documentation.
Technical Details
bin/create-block.js— RewrittenexecSyncwithspawnSyncto pass arguments as an array, avoiding shell interpolation and making argument handling safer and more predictableparseUserInputArgsstring-building approach with a stricterparseArgs()helper that uses aSetto track seen keys and aMapfor defaults, preventing duplicate flags/^[a-z0-9][a-z0-9-]*[a-z0-9]$/)printUsage()helper shown on validation errorsspawnSyncexits due to a signal (result.status === null), reporting the signal name instead of a misleading exit code--title,--category,--icon,--keywords, and--short-descriptionsince these values should be explicitly defined per blockclass-blocks.php— Bug fixes_-prefixed blocks were not excluded correctly. Because the path contained a leading/,strpos()returned1instead of0, causing the prefix check to fail. The fix usesbasename()to reliably extract the block directory nameis_dir()guard before filesystem operations, preventing errors on fresh clones before a build has runfunction_exists( 'wp_register_block_metadata_collection' )guard — this function was introduced in WordPress 6.7; without the guard it would fatal on older versionsglob()failures are handled safely by falling back to an empty array when it returnsfalseuntrailingslashit()wrapper —get_template_directory()already returns a path without a trailing slashsetup_hooks()visibility frompublictoprivate— it is only called from__constructpackage.json— Updatedbuild:blocks— replaced directwp-scriptscall withnode ./bin/build-blocks.jsbuild:block-manifest— replaced Unix-only shell command withnode ./bin/build-block-manifest.js(the previous command relied onfind,grep, andrm -fwhich do not work on Windows)start:blocks— replaced directwp-scriptscall withnode ./bin/start-blocks.jslint:css:fix— removed duplicate./assets/srcargument (path already included vianpm run lint:css)lint:js:fix— removed duplicate./assets/srcargument (same issue)@wordpress/interactivity— moved fromdependenciestodevDependenciessince it is bundled during build and not required at runtimeminimatchoverride — changed from pinned3.1.3to^3.1.3for consistency with other override entriesbin/build-blocks.js— New filePrevents webpack from running when no block sources exist. Checks for at least one non-
_-prefixed directory inassets/src/blocks/before invoking webpack. If none found, exits silently with code0— preventing an emptyassets/build/blocks/directory from being created on a fresh clone.bin/build-block-manifest.js— New fileWraps
wp-scripts build-blocks-manifest. Checks for at least one compiledblock.jsoninsideassets/build/blocks/before running. If none found, exits silently with code0— preventingbuild:prodfrom failing on fresh clones or CI environments.bin/start-blocks.js— New fileSame guard as
build-blocks.jsbut for watch mode. Skipswp-scripts startif no buildable block sources exist.docs/blocks-guide.md— Rewritten--npm argument separator--variantand--namespaceare pre-configured defaults, only need to be passed to override--titleas (Recommended) instead of just optionalcommonwithtextnpm run startwatch modeedit.js,save.js,.scss)build:blocksskips and creates no empty folder when no blocks existChecklist
_prefix exclusion bug fixed in block registrationwp_register_block_metadata_collection()assets/build/blocks/folder on fresh clonebuild:block-manifestworks on Windowslint:css:fixandlint:js:fixduplicate path arguments fixedScreenshots
N/A — CLI tooling and PHP registration only, no UI changes.
To-do
spawnSynctospawninstart-blocks.jsif non-blocking watch behavior is needed.