Skip to content

Commit

Permalink
Deprecated: Output an informational message for deprecation when no v…
Browse files Browse the repository at this point in the history
…ersion provided

When there is no `options.version` param provided `deprecated` method outputs an informational message to the Web Console rather than warns as previously.
  • Loading branch information
gziolo committed Jul 26, 2019
1 parent c402014 commit 2d304fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/deprecated/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Master

### Breaking Change

- When there is no `options.version` param provided `deprecated` method outputs an informational message to the Web Console rather than warns as previously.

## 2.0.4 (2019-01-03)

## 2.0.0 (2018-09-05)
Expand Down
13 changes: 9 additions & 4 deletions packages/deprecated/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export default function deprecated( feature, options = {} ) {
} = options;

const pluginMessage = plugin ? ` from ${ plugin }` : '';
const versionMessage = version ? `${ pluginMessage } in ${ version }` : '';
const versionMessage = version ? ` and will be removed${ pluginMessage } in ${ version }` : '';
const useInsteadMessage = alternative ? ` Please use ${ alternative } instead.` : '';
const linkMessage = link ? ` See: ${ link }` : '';
const hintMessage = hint ? ` Note: ${ hint }` : '';
const message = `${ feature } is deprecated and will be removed${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;
const message = `${ feature } is deprecated${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;

// Skip if already logged.
if ( message in logged ) {
Expand All @@ -71,8 +71,13 @@ export default function deprecated( feature, options = {} ) {
*/
doAction( 'deprecated', feature, options, message );

// eslint-disable-next-line no-console
console.warn( message );
if ( version ) {
// eslint-disable-next-line no-console
console.warn( message );
} else {
// eslint-disable-next-line no-console
console.info( message );
}

logged[ message ] = true;
}
10 changes: 5 additions & 5 deletions packages/deprecated/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe( 'deprecated', () => {
it( 'should show a deprecation warning', () => {
deprecated( 'Eating meat' );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed.'
expect( console ).toHaveInformedWith(
'Eating meat is deprecated.'
);
} );

Expand Down Expand Up @@ -81,15 +81,15 @@ describe( 'deprecated', () => {
deprecated( 'Eating meat' );
deprecated( 'Eating meat' );

expect( console ).toHaveWarned();
expect( console ).toHaveInformed();
// eslint-disable-next-line no-console
expect( console.warn ).toHaveBeenCalledTimes( 1 );
expect( console.info ).toHaveBeenCalledTimes( 1 );
} );

it( 'should do an action', () => {
deprecated( 'turkey', { alternative: 'tofurky' } );

expect( console ).toHaveWarned();
expect( console ).toHaveInformed();
expect( didAction( 'deprecated' ) ).toBeTruthy();
} );
} );

0 comments on commit 2d304fc

Please sign in to comment.