-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Framework: Adding a deprecation helper (#5069)
- Loading branch information
1 parent
7d2ee78
commit da8184a
Showing
12 changed files
with
129 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Logs a message to notify developpers about a deprecated feature. | ||
* | ||
* @param {string} feature Name of the deprecated feature. | ||
* @param {?Object} options Personalisation options | ||
* @param {?string} options.version Version in which the feature will be removed. | ||
* @param {?string} options.alternative Feature to use instead | ||
* @param {?string} options.plugin Plugin name if it's a plugin feature | ||
* @param {?string} options.link Link to documentation | ||
*/ | ||
export function deprecated( feature, { version, alternative, plugin, link } = {} ) { | ||
const pluginMessage = plugin ? ` from ${ plugin }` : ''; | ||
const versionMessage = version ? `${ pluginMessage } in ${ version }` : ''; | ||
const useInsteadMessage = alternative ? ` Please use ${ alternative } instead.` : ''; | ||
const linkMessage = link ? ` See: ${ link }` : ''; | ||
const message = `${ feature } is deprecated and will be removed${ versionMessage }.${ useInsteadMessage }${ linkMessage }`; | ||
|
||
// eslint-disable-next-line no-console | ||
console.warn( message ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { deprecated } from '../deprecation'; | ||
|
||
describe( 'deprecated', () => { | ||
it( 'should show a deprecation warning', () => { | ||
deprecated( 'Eating meat' ); | ||
|
||
expect( console ).toHaveWarnedWith( | ||
'Eating meat is deprecated and will be removed.' | ||
); | ||
} ); | ||
|
||
it( 'should show a deprecation warning with a version', () => { | ||
deprecated( 'Eating meat', { version: 'the future' } ); | ||
|
||
expect( console ).toHaveWarnedWith( | ||
'Eating meat is deprecated and will be removed in the future.' | ||
); | ||
} ); | ||
|
||
it( 'should show a deprecation warning with an alternative', () => { | ||
deprecated( 'Eating meat', { version: 'the future', alternative: 'vegetables' } ); | ||
|
||
expect( console ).toHaveWarnedWith( | ||
'Eating meat is deprecated and will be removed in the future. Please use vegetables instead.' | ||
); | ||
} ); | ||
|
||
it( 'should show a deprecation warning with an alternative specific to a plugin', () => { | ||
deprecated( 'Eating meat', { | ||
version: 'the future', | ||
alternative: 'vegetables', | ||
plugin: 'the earth', | ||
} ); | ||
|
||
expect( console ).toHaveWarnedWith( | ||
'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead.' | ||
); | ||
} ); | ||
|
||
it( 'should show a deprecation warning with a link', () => { | ||
deprecated( 'Eating meat', { | ||
version: 'the future', | ||
alternative: 'vegetables', | ||
plugin: 'the earth', | ||
link: 'https://en.wikipedia.org/wiki/Vegetarianism', | ||
} ); | ||
|
||
expect( console ).toHaveWarnedWith( | ||
'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead. See: https://en.wikipedia.org/wiki/Vegetarianism' | ||
); | ||
} ); | ||
} ); |