From 00320d887ffdcec5802796e2dbf7f52c6d641c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=28Greg=29=20Zi=C3=B3=C5=82kowski?= Date: Sun, 27 May 2018 15:16:43 +0200 Subject: [PATCH] Deprecated: Introduce new module with depreaction util (#6914) * Devtools: Introduce new module with depreacted util * Deprecated: Remove devtools to deprecated --- .eslintrc.js | 20 +++++++------ blocks/api/registration.js | 2 +- core-blocks/index.js | 2 +- data/persist.js | 2 +- data/test/index.js | 4 --- docs/reference/deprecated.md | 3 +- editor/components/image-placeholder/index.js | 2 +- editor/components/rich-text/index.js | 2 +- editor/deprecated.js | 2 +- lib/client-assets.php | 15 ++++++++-- packages/deprecated/.npmrc | 1 + packages/deprecated/README.md | 28 +++++++++++++++++++ packages/deprecated/package.json | 23 +++++++++++++++ .../deprecated/src/index.js | 2 +- .../deprecated/src/test/index.js | 2 +- test/unit/jest.config.json | 2 +- utils/deprecated.js | 22 +++++++++------ utils/index.js | 1 - webpack.config.js | 3 +- 19 files changed, 103 insertions(+), 35 deletions(-) create mode 100644 packages/deprecated/.npmrc create mode 100644 packages/deprecated/README.md create mode 100644 packages/deprecated/package.json rename utils/deprecation.js => packages/deprecated/src/index.js (92%) rename utils/test/deprecation.js => packages/deprecated/src/test/index.js (97%) diff --git a/.eslintrc.js b/.eslintrc.js index a4884fbb7fde5..77c4e0eaa7003 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -46,25 +46,29 @@ module.exports = { selector: 'ImportDeclaration[source.value=/^components$/]', message: 'Use @wordpress/components as import path instead.', }, + { + selector: 'ImportDeclaration[source.value=/^data$/]', + message: 'Use @wordpress/data as import path instead.', + }, { selector: 'ImportDeclaration[source.value=/^date$/]', message: 'Use @wordpress/date as import path instead.', }, { - selector: 'ImportDeclaration[source.value=/^editor$/]', - message: 'Use @wordpress/editor as import path instead.', + selector: 'ImportDeclaration[source.value=/^deprecated/]', + message: 'Use @wordpress/deprecated as import path instead.', }, { - selector: 'ImportDeclaration[source.value=/^element$/]', - message: 'Use @wordpress/element as import path instead.', + selector: 'ImportDeclaration[source.value=/^dom$/]', + message: 'Use @wordpress/dom as import path instead.', }, { - selector: 'ImportDeclaration[source.value=/^data$/]', - message: 'Use @wordpress/data as import path instead.', + selector: 'ImportDeclaration[source.value=/^editor$/]', + message: 'Use @wordpress/editor as import path instead.', }, { - selector: 'ImportDeclaration[source.value=/^dom$/]', - message: 'Use @wordpress/dom as import path instead.', + selector: 'ImportDeclaration[source.value=/^element$/]', + message: 'Use @wordpress/element as import path instead.', }, { selector: 'ImportDeclaration[source.value=/^utils$/]', diff --git a/blocks/api/registration.js b/blocks/api/registration.js index 1ce6fb13ac1ae..b8aecb72dd9a9 100644 --- a/blocks/api/registration.js +++ b/blocks/api/registration.js @@ -10,7 +10,7 @@ import { get, set, isFunction, some } from 'lodash'; */ import { applyFilters } from '@wordpress/hooks'; import { select, dispatch } from '@wordpress/data'; -import { deprecated } from '@wordpress/utils'; +import deprecated from '@wordpress/deprecated'; /** * Defined behavior of a block type. diff --git a/core-blocks/index.js b/core-blocks/index.js index a6c83b08da036..75f6b509eed70 100644 --- a/core-blocks/index.js +++ b/core-blocks/index.js @@ -6,7 +6,7 @@ import { setDefaultBlockName, setUnknownTypeHandlerName, } from '@wordpress/blocks'; -import { deprecated } from '@wordpress/utils'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies diff --git a/data/persist.js b/data/persist.js index 0a76097173377..63d800f4ee1c1 100644 --- a/data/persist.js +++ b/data/persist.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { deprecated } from '@wordpress/utils'; +import deprecated from '@wordpress/deprecated'; /** * External dependencies diff --git a/data/test/index.js b/data/test/index.js index 7042011e9b006..d437e81dd790a 100644 --- a/data/test/index.js +++ b/data/test/index.js @@ -29,10 +29,6 @@ import { toAsyncIterable, } from '../'; -jest.mock( '@wordpress/utils', () => ( { - deprecated: jest.fn(), -} ) ); - // Mock data store to prevent self-initialization, as it needs to be reset // between tests of `registerResolvers` by replacement (new `registerStore`). jest.mock( '../store', () => () => {} ); diff --git a/docs/reference/deprecated.md b/docs/reference/deprecated.md index 5422e71ce22fd..db44a598613ee 100644 --- a/docs/reference/deprecated.md +++ b/docs/reference/deprecated.md @@ -4,6 +4,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo - `wp.data.withRehydratation` has been renamed to `wp.data.withRehydration`. - The `wp.editor.ImagePlaceholder` component is removed. Please use `wp.editor.MediaPlaceholder` instead. + - `wp.utils.deprecated` function removed. Please use `wp.deprecated` instead. ## 3.1.0 @@ -11,7 +12,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo - `wp.blocks.withEditorSettings` is removed. Please use the data module to access the editor settings `wp.data.select( "core/editor" ).getEditorSettings()`. - All DOM utils in `wp.utils.*` are removed. Please use `wp.dom.*` instead. - `isPrivate: true` has been removed from the Block API. Please use `supports.inserter: false` instead. - - `wp.utils.isExtraSmall` function removed. Please use `wp.viewport.*` instead. + - `wp.utils.isExtraSmall` function removed. Please use `wp.viewport.isExtraSmall` instead. ## 3.0.0 diff --git a/editor/components/image-placeholder/index.js b/editor/components/image-placeholder/index.js index 335f4c21bbe28..1edf4adf09417 100644 --- a/editor/components/image-placeholder/index.js +++ b/editor/components/image-placeholder/index.js @@ -3,7 +3,7 @@ */ import { Component } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; -import { deprecated } from '@wordpress/utils'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies diff --git a/editor/components/rich-text/index.js b/editor/components/rich-text/index.js index b65eb2eabe27f..238dae578486b 100644 --- a/editor/components/rich-text/index.js +++ b/editor/components/rich-text/index.js @@ -24,10 +24,10 @@ import { getRectangleFromRange, getScrollContainer, } from '@wordpress/dom'; +import deprecated from '@wordpress/deprecated'; import { keycodes, createBlobURL, - deprecated, } from '@wordpress/utils'; import { withInstanceId, withSafeTimeout, Slot } from '@wordpress/components'; import { withSelect } from '@wordpress/data'; diff --git a/editor/deprecated.js b/editor/deprecated.js index f1e130c825cbd..0135f7c71a66c 100644 --- a/editor/deprecated.js +++ b/editor/deprecated.js @@ -7,7 +7,7 @@ import { forEach } from 'lodash'; * WordPress dependencies */ import { Component } from '@wordpress/element'; -import { deprecated } from '@wordpress/utils'; +import deprecated from '@wordpress/deprecated'; import { withSelect } from '@wordpress/data'; import { diff --git a/lib/client-assets.php b/lib/client-assets.php index bcb5cebb9f290..789fe04c211fb 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -115,10 +115,17 @@ function gutenberg_register_scripts_and_styles() { ); // Editor Scripts. + wp_register_script( + 'wp-deprecated', + gutenberg_url( 'build/deprecated/index.js' ), + array(), + filemtime( gutenberg_dir_path() . 'build/deprecated/index.js' ), + true + ); wp_register_script( 'wp-data', gutenberg_url( 'build/data/index.js' ), - array( 'wp-element', 'wp-utils', 'wp-is-shallow-equal', 'lodash' ), + array( 'wp-deprecated', 'wp-element', 'wp-is-shallow-equal', 'lodash' ), filemtime( gutenberg_dir_path() . 'build/data/index.js' ), true ); @@ -139,7 +146,7 @@ function gutenberg_register_scripts_and_styles() { wp_register_script( 'wp-utils', gutenberg_url( 'build/utils/index.js' ), - array( 'lodash', 'wp-dom' ), + array( 'lodash', 'wp-deprecated', 'wp-dom' ), filemtime( gutenberg_dir_path() . 'build/utils/index.js' ), true ); @@ -206,7 +213,7 @@ function gutenberg_register_scripts_and_styles() { wp_register_script( 'wp-blocks', gutenberg_url( 'build/blocks/index.js' ), - array( 'wp-dom', 'wp-element', 'wp-utils', 'wp-hooks', 'wp-i18n', 'shortcode', 'wp-data', 'lodash' ), + array( 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-utils', 'wp-hooks', 'wp-i18n', 'shortcode', 'wp-data', 'lodash' ), filemtime( gutenberg_dir_path() . 'build/blocks/index.js' ), true ); @@ -234,6 +241,7 @@ function gutenberg_register_scripts_and_styles() { 'wp-blocks', 'wp-components', 'wp-core-data', + 'wp-deprecated', 'wp-element', 'wp-editor', 'wp-i18n', @@ -327,6 +335,7 @@ function gutenberg_register_scripts_and_styles() { 'wp-core-data', 'wp-data', 'wp-date', + 'wp-deprecated', 'wp-dom', 'wp-i18n', 'wp-element', diff --git a/packages/deprecated/.npmrc b/packages/deprecated/.npmrc new file mode 100644 index 0000000000000..43c97e719a5a8 --- /dev/null +++ b/packages/deprecated/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/deprecated/README.md b/packages/deprecated/README.md new file mode 100644 index 0000000000000..e00c1276a089a --- /dev/null +++ b/packages/deprecated/README.md @@ -0,0 +1,28 @@ +# @wordpress/deprecated + +Logs a message to notify developers about a deprecated feature. + +## Installation + +Install the module + +```bash +npm install @wordpress/deprecated@next --save +``` + +## Usage + +```js +import deprecated from '@wordpress/deprecated'; + +deprecated( 'Eating meat', { + version: 'the future', + alternative: 'vegetables', + plugin: 'the earth', + hint: 'You may find it beneficial to transition gradually.', +} ); + +// Logs: 'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead. Note: You may find it beneficial to transition gradually.' +``` + +

Code is Poetry.

diff --git a/packages/deprecated/package.json b/packages/deprecated/package.json new file mode 100644 index 0000000000000..3c6db41f30f12 --- /dev/null +++ b/packages/deprecated/package.json @@ -0,0 +1,23 @@ +{ + "name": "@wordpress/deprecated", + "version": "0.0.1", + "description": "Deprecation utility for WordPress", + "author": "WordPress", + "license": "GPL-2.0-or-later", + "keywords": [ + "wordpress", + "deprecated" + ], + "homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/deprecated/README.md", + "repository": { + "type": "git", + "url": "https://github.com/WordPress/gutenberg.git" + }, + "bugs": { + "url": "https://github.com/WordPress/gutenberg/issues" + }, + "main": "src/index.js", + "publishConfig": { + "access": "public" + } +} diff --git a/utils/deprecation.js b/packages/deprecated/src/index.js similarity index 92% rename from utils/deprecation.js rename to packages/deprecated/src/index.js index 89d9b15ebf397..e9c5fba2c461a 100644 --- a/utils/deprecation.js +++ b/packages/deprecated/src/index.js @@ -9,7 +9,7 @@ * @param {?string} options.link Link to documentation * @param {?string} options.hint Additional message to help transition away from the deprecated feature. */ -export function deprecated( feature, { version, alternative, plugin, link, hint } = {} ) { +export default function deprecated( feature, { version, alternative, plugin, link, hint } = {} ) { const pluginMessage = plugin ? ` from ${ plugin }` : ''; const versionMessage = version ? `${ pluginMessage } in ${ version }` : ''; const useInsteadMessage = alternative ? ` Please use ${ alternative } instead.` : ''; diff --git a/utils/test/deprecation.js b/packages/deprecated/src/test/index.js similarity index 97% rename from utils/test/deprecation.js rename to packages/deprecated/src/test/index.js index 56c6f925d7634..24c3a0550e072 100644 --- a/utils/test/deprecation.js +++ b/packages/deprecated/src/test/index.js @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { deprecated } from '../deprecation'; +import deprecated from '../'; describe( 'deprecated', () => { it( 'should show a deprecation warning', () => { diff --git a/test/unit/jest.config.json b/test/unit/jest.config.json index 01c3d24d6ec60..c4dd16ffc48f0 100644 --- a/test/unit/jest.config.json +++ b/test/unit/jest.config.json @@ -6,7 +6,7 @@ ], "moduleNameMapper": { "@wordpress\\/(blocks|components|editor|data|utils|edit-post|viewport|plugins|core-data|core-blocks)$": "$1", - "@wordpress\\/(date|dom|element)$": "packages/$1/src" + "@wordpress\\/(date|dom|deprecated|element)$": "packages/$1/src" }, "preset": "@wordpress/jest-preset-default", "setupFiles": [ diff --git a/utils/deprecated.js b/utils/deprecated.js index 7b4b5d3ff9d5c..cdc66c5b44eb9 100644 --- a/utils/deprecated.js +++ b/utils/deprecated.js @@ -2,14 +2,10 @@ * WordPress dependencies */ import * as dom from '@wordpress/dom'; - -/** - * Internal dependencies - */ -import { deprecated } from './deprecation'; +import originalDeprecated from '@wordpress/deprecated'; const wrapFunction = ( functionName, source = dom ) => ( ...args ) => { - deprecated( 'wp.utils.' + functionName, { + originalDeprecated( 'wp.utils.' + functionName, { version: '3.1', alternative: 'wp.dom.' + functionName, plugin: 'Gutenberg', @@ -41,10 +37,20 @@ export const replace = wrapFunction( 'replace' ); export const replaceTag = wrapFunction( 'replaceTag' ); export const unwrap = wrapFunction( 'unwrap' ); +export function deprecated( ...params ) { + originalDeprecated( 'wp.utils.deprecated', { + version: '3.2', + alternative: 'wp.deprecated', + plugin: 'Gutenberg', + } ); + + return originalDeprecated( ...params ); +} + export function isExtraSmall() { - deprecated( 'wp.utils.isExtraSmall', { + originalDeprecated( 'wp.utils.isExtraSmall', { version: '3.1', - alternative: 'wp.viewport.*', + alternative: 'wp.viewport.isExtraSmall', plugin: 'Gutenberg', } ); diff --git a/utils/index.js b/utils/index.js index 368c296ee3009..5a46909a6fbf6 100644 --- a/utils/index.js +++ b/utils/index.js @@ -8,7 +8,6 @@ export { decodeEntities }; export { keycodes }; export * from './blob-cache'; -export * from './deprecation'; export * from './mediaupload'; export * from './terms'; diff --git a/webpack.config.js b/webpack.config.js index ea455672100dc..ec34191362963 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -137,6 +137,7 @@ const entryPointNames = [ const gutenbergPackages = [ 'date', + 'deprecated', 'dom', 'element', ]; @@ -275,7 +276,7 @@ const config = { return path; }, } ), - new LibraryExportDefaultPlugin( [ 'dom-ready' ].map( camelCaseDash ) ), + new LibraryExportDefaultPlugin( [ 'deprecated', 'dom-ready' ].map( camelCaseDash ) ), ], stats: { children: false,