diff --git a/package-lock.json b/package-lock.json index a4389bf1610718..b2d55439574449 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17102,6 +17102,7 @@ "@wordpress/html-entities": "file:packages/html-entities", "@wordpress/i18n": "file:packages/i18n", "@wordpress/icons": "file:packages/icons", + "@wordpress/interface": "file:packages/interface", "@wordpress/is-shallow-equal": "file:packages/is-shallow-equal", "@wordpress/keyboard-shortcuts": "file:packages/keyboard-shortcuts", "@wordpress/keycodes": "file:packages/keycodes", diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index 261a33cc9e96c7..dc1fcfdb322e6d 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -48,6 +48,7 @@ "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", + "@wordpress/interface": "file:../interface", "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts", "@wordpress/keycodes": "file:../keycodes", diff --git a/packages/block-editor/src/index.js b/packages/block-editor/src/index.js index 594c78859b25c8..41ba6dab5bb871 100644 --- a/packages/block-editor/src/index.js +++ b/packages/block-editor/src/index.js @@ -1,3 +1,8 @@ +/** + * WordPress dependencies + */ +import { createExperiments } from '@wordpress/interface'; + /** * Internal dependencies */ @@ -17,3 +22,12 @@ export * from './elements'; export * from './utils'; export { storeConfig, store } from './store'; export { SETTINGS_DEFAULTS } from './store/defaults'; + +const __experiments = createExperiments( { + test( name ) { + // eslint-disable-next-line no-console + console.log( `Executed with "${ name }".` ); + }, +} ); + +export { __experiments }; diff --git a/packages/edit-post/src/index.js b/packages/edit-post/src/index.js index 68e3d4ba76bbd8..4acc4bb1e80b0d 100644 --- a/packages/edit-post/src/index.js +++ b/packages/edit-post/src/index.js @@ -6,6 +6,8 @@ import { registerCoreBlocks, __experimentalRegisterExperimentalCoreBlocks, } from '@wordpress/block-library'; +import { __experiments } from '@wordpress/block-editor'; +import { secretKey } from '@wordpress/interface'; import { render, unmountComponentAtNode } from '@wordpress/element'; import { dispatch, select } from '@wordpress/data'; import { addFilter } from '@wordpress/hooks'; @@ -80,6 +82,10 @@ export function initializeEditor( settings, initialEdits ) { + const test = __experiments( 'test', secretKey ); + + test( 'hello world' ); + // Prevent adding template part in the post editor. // Only add the filter when the post editor is initialized, not imported. addFilter( diff --git a/packages/interface/src/index.js b/packages/interface/src/index.js index 72531a0824c178..06b1f14471cd1e 100644 --- a/packages/interface/src/index.js +++ b/packages/interface/src/index.js @@ -1,2 +1,13 @@ export * from './components'; export { store } from './store'; + +export const secretKey = process.env.WP_SECRET_KEY; + +export function createExperiments( experiments ) { + return function ( name, key ) { + if ( secretKey !== key ) { + throw new Error( 'Experiments are not supported.' ); + } + return experiments[ name ]; + }; +} diff --git a/tools/webpack/shared.js b/tools/webpack/shared.js index 304da4ad03cc56..1be5c2bc66fbce 100644 --- a/tools/webpack/shared.js +++ b/tools/webpack/shared.js @@ -69,6 +69,7 @@ const plugins = [ // Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging. 'process.env.IS_GUTENBERG_PLUGIN': process.env.npm_package_config_IS_GUTENBERG_PLUGIN, + 'process.env.WP_SECRET_KEY': JSON.stringify( new Date() ), } ), mode === 'production' && new ReadableJsAssetsWebpackPlugin(), ];