From 9b01bfd53cb1fdfba7c16975fe54c1f02ad01899 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 10 Feb 2021 12:46:44 +0100 Subject: [PATCH] Revert removal of apiVersion for JS code We miss the mapping layer during registration that would transform kyes from PHP to JS. --- .wp-env.json | 7 +++++-- .../templates/src/index.js.mustache | 5 +++++ packages/create-block/lib/init-block-json.js | 4 ++-- .../lib/templates/esnext/src/index.js.mustache | 5 +++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.wp-env.json b/.wp-env.json index 4d67d71c82fb55..40323126730c36 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,9 +1,12 @@ { "core": "WordPress/WordPress", "plugins": [ - "." + ".", + "./esnext-exampl" + ], + "themes": [ + "WordPress/theme-experiments/tt1-blocks#tt1-blocks@0.4.3" ], - "themes": [ "WordPress/theme-experiments/tt1-blocks#tt1-blocks@0.4.3" ], "env": { "tests": { "mappings": { diff --git a/packages/create-block-tutorial-template/templates/src/index.js.mustache b/packages/create-block-tutorial-template/templates/src/index.js.mustache index ad697a563786b5..8fa6ae10231969 100644 --- a/packages/create-block-tutorial-template/templates/src/index.js.mustache +++ b/packages/create-block-tutorial-template/templates/src/index.js.mustache @@ -28,6 +28,11 @@ import save from './save'; * @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block */ registerBlockType( '{{namespace}}/{{slug}}', { + /** + * @see https://make.wordpress.org/core/2020/11/18/block-api-version-2/ + */ + apiVersion: {{apiVersion}}, + /** * Used to construct a preview for the block to be shown in the block inserter. */ diff --git a/packages/create-block/lib/init-block-json.js b/packages/create-block/lib/init-block-json.js index 81f177290372b8..900767145dd0cc 100644 --- a/packages/create-block/lib/init-block-json.js +++ b/packages/create-block/lib/init-block-json.js @@ -1,7 +1,7 @@ /** * External dependencies */ -const { isEmpty, omitBy } = require( 'lodash' ); +const { omitBy } = require( 'lodash' ); const { join } = require( 'path' ); const { writeFile } = require( 'fs' ).promises; @@ -46,7 +46,7 @@ module.exports = async ( { editorStyle, style, }, - isEmpty + ( value ) => ! value ), null, '\t' diff --git a/packages/create-block/lib/templates/esnext/src/index.js.mustache b/packages/create-block/lib/templates/esnext/src/index.js.mustache index 6b258d5b390c5f..6eb0e76b75e9f9 100644 --- a/packages/create-block/lib/templates/esnext/src/index.js.mustache +++ b/packages/create-block/lib/templates/esnext/src/index.js.mustache @@ -26,6 +26,11 @@ import save from './save'; * @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block */ registerBlockType( '{{namespace}}/{{slug}}', { + /** + * @see https://make.wordpress.org/core/2020/11/18/block-api-version-2/ + */ + apiVersion: {{apiVersion}}, + /** * @see ./edit.js */