Skip to content

Commit

Permalink
Devtools: Introduce new module with depreacted util
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed May 27, 2018
1 parent b084f8a commit d45bf7a
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 33 deletions.
20 changes: 12 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=/^devtools$/]',
message: 'Use @wordpress/devtools 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$/]',
Expand Down
2 changes: 1 addition & 1 deletion blocks/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/devtools';

/**
* Defined behavior of a block type.
Expand Down
2 changes: 1 addition & 1 deletion core-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
setDefaultBlockName,
setUnknownTypeHandlerName,
} from '@wordpress/blocks';
import { deprecated } from '@wordpress/utils';
import { deprecated } from '@wordpress/devtools';

/**
* Internal dependencies
Expand Down
2 changes: 1 addition & 1 deletion data/persist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { deprecated } from '@wordpress/utils';
import { deprecated } from '@wordpress/devtools';

/**
* External dependencies
Expand Down
4 changes: 0 additions & 4 deletions data/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => () => {} );
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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.devtools.deprecated` instead.

## 3.1.0

- All components in `wp.blocks.*` are removed. Please use `wp.editor.*` instead.
- `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

Expand Down
2 changes: 1 addition & 1 deletion editor/components/image-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { deprecated } from '@wordpress/utils';
import { deprecated } from '@wordpress/devtools';

/**
* Internal dependencies
Expand Down
2 changes: 1 addition & 1 deletion editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import {
getRectangleFromRange,
getScrollContainer,
} from '@wordpress/dom';
import { deprecated } from '@wordpress/devtools';
import {
keycodes,
createBlobURL,
deprecated,
} from '@wordpress/utils';
import { withInstanceId, withSafeTimeout, Slot } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
Expand Down
2 changes: 1 addition & 1 deletion editor/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { forEach } from 'lodash';
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { deprecated } from '@wordpress/utils';
import { deprecated } from '@wordpress/devtools';
import { withSelect } from '@wordpress/data';

import {
Expand Down
15 changes: 12 additions & 3 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,17 @@ function gutenberg_register_scripts_and_styles() {
);

// Editor Scripts.
wp_register_script(
'wp-devtools',
gutenberg_url( 'build/devtools/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'build/devtools/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-devtools', 'wp-element', 'wp-is-shallow-equal', 'lodash' ),
filemtime( gutenberg_dir_path() . 'build/data/index.js' ),
true
);
Expand All @@ -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-devtools', 'wp-dom' ),
filemtime( gutenberg_dir_path() . 'build/utils/index.js' ),
true
);
Expand Down Expand Up @@ -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-devtools', 'wp-dom', 'wp-element', 'wp-utils', 'wp-hooks', 'wp-i18n', 'shortcode', 'wp-data', 'lodash' ),
filemtime( gutenberg_dir_path() . 'build/blocks/index.js' ),
true
);
Expand Down Expand Up @@ -234,6 +241,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-blocks',
'wp-components',
'wp-core-data',
'wp-devtools',
'wp-element',
'wp-editor',
'wp-i18n',
Expand Down Expand Up @@ -327,6 +335,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-core-data',
'wp-data',
'wp-date',
'wp-devtools',
'wp-dom',
'wp-i18n',
'wp-element',
Expand Down
1 change: 1 addition & 0 deletions packages/devtools/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
13 changes: 13 additions & 0 deletions packages/devtools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @wordpress/devtools

Devtools module for WordPress.

## Installation

Install the module

```bash
npm install @wordpress/devtools@next --save
```

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
23 changes: 23 additions & 0 deletions packages/devtools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@wordpress/devtools",
"version": "0.0.1",
"description": "Devtools module for WordPress",
"author": "WordPress",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"devtools"
],
"homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/devtools/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"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import { deprecated } from '../deprecation';
import { deprecated } from '../';

describe( 'deprecated', () => {
it( 'should show a deprecation warning', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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|devtools|element)$": "packages/$1/src"
},
"preset": "@wordpress/jest-preset-default",
"setupFiles": [
Expand Down
22 changes: 14 additions & 8 deletions utils/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
* WordPress dependencies
*/
import * as dom from '@wordpress/dom';

/**
* Internal dependencies
*/
import { deprecated } from './deprecation';
import { deprecated as originalDeprecated } from '@wordpress/devtools';

const wrapFunction = ( functionName, source = dom ) => ( ...args ) => {
deprecated( 'wp.utils.' + functionName, {
originalDeprecated( 'wp.utils.' + functionName, {
version: '3.1',
alternative: 'wp.dom.' + functionName,
plugin: 'Gutenberg',
Expand Down Expand Up @@ -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.devtools.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',
} );

Expand Down
1 change: 0 additions & 1 deletion utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export { decodeEntities };
export { keycodes };

export * from './blob-cache';
export * from './deprecation';
export * from './mediaupload';
export * from './terms';

Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const entryPointNames = [

const gutenbergPackages = [
'date',
'devtools',
'dom',
'element',
];
Expand Down

0 comments on commit d45bf7a

Please sign in to comment.