You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@wordpress/deprecated

Package Overview
Dependencies
Maintainers
23
Versions
229
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/deprecated - npm Package Compare versions

Comparing version
4.25.0
to
4.26.0
+96
src/index.ts
/**
* WordPress dependencies
*/
import { doAction } from '@wordpress/hooks';
/**
* Object map tracking messages which have been logged, for use in ensuring a
* message is only logged once.
*/
export const logged: Record< string, true > = Object.create( null );
type DeprecatedOptions = {
/**
* Version in which the feature was deprecated.
*/
since?: string;
/**
* Version in which the feature will be removed.
*/
version?: string;
/**
* Feature to use instead.
*/
alternative?: string;
/**
* Plugin name if it's a plugin feature.
*/
plugin?: string;
/**
* Link to documentation.
*/
link?: string;
/**
* Additional message to help transition away from the deprecated feature.
*/
hint?: string;
};
/**
* Logs a message to notify developers about a deprecated feature.
*
* @param {string} feature Name of the deprecated feature.
* @param {DeprecatedOptions} [options] Personalisation options
*
* @example
* ```js
* import deprecated from '@wordpress/deprecated';
*
* deprecated( 'Eating meat', {
* since: '2019.01.01'
* version: '2020.01.01',
* alternative: 'vegetables',
* plugin: 'the earth',
* hint: 'You may find it beneficial to transition gradually.',
* } );
*
* // Logs: 'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
* ```
*/
export default function deprecated(
feature: string,
options: DeprecatedOptions = {}
) {
const { since, version, alternative, plugin, link, hint } = options;
const pluginMessage = plugin ? ` from ${ plugin }` : '';
const sinceMessage = since ? ` since version ${ since }` : '';
const versionMessage = version
? ` and will be removed${ pluginMessage } in version ${ version }`
: '';
const useInsteadMessage = alternative
? ` Please use ${ alternative } instead.`
: '';
const linkMessage = link ? ` See: ${ link }` : '';
const hintMessage = hint ? ` Note: ${ hint }` : '';
const message = `${ feature } is deprecated${ sinceMessage }${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;
// Skip if already logged.
if ( message in logged ) {
return;
}
/**
* Fires whenever a deprecated feature is encountered
*
* @param {string} feature Name of the deprecated feature.
* @param {DeprecatedOptions} options Personalisation options
* @param {string} message Message sent to console.warn
*/
doAction( 'deprecated', feature, options, message );
// eslint-disable-next-line no-console
console.warn( message );
logged[ message ] = true;
}
/**
* WordPress dependencies
*/
import { didAction } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import deprecated, { logged } from '..';
describe( 'deprecated', () => {
afterEach( () => {
for ( const key in logged ) {
delete logged[ key ];
}
} );
it( 'should show a deprecation warning', () => {
deprecated( 'Eating meat' );
expect( console ).toHaveWarnedWith( 'Eating meat is deprecated.' );
} );
it( 'should show a deprecation warning with a since', () => {
deprecated( 'Eating meat', { since: '2019.01.01' } );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated since version 2019.01.01.'
);
} );
it( 'should show a deprecation warning with a version', () => {
deprecated( 'Eating meat', { version: '2020.01.01' } );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed in version 2020.01.01.'
);
} );
it( 'should show a deprecation warning with an alternative', () => {
deprecated( 'Eating meat', {
since: '2019.01.01',
version: '2020.01.01',
alternative: 'vegetables',
} );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated since version 2019.01.01 and will be removed in version 2020.01.01. Please use vegetables instead.'
);
} );
it( 'should show a deprecation warning with an alternative specific to a plugin', () => {
deprecated( 'Eating meat', {
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
} );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed from the earth in version 2020.01.01. Please use vegetables instead.'
);
} );
it( 'should show a deprecation warning with a link', () => {
deprecated( 'Eating meat', {
version: '2020.01.01',
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 version 2020.01.01. Please use vegetables instead. See: https://en.wikipedia.org/wiki/Vegetarianism'
);
} );
it( 'should show a deprecation warning with a hint', () => {
deprecated( 'Eating meat', {
since: '2019.01.01',
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
hint: 'You may find it beneficial to transition gradually.',
} );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
);
} );
it( 'should show a message once', () => {
deprecated( 'Eating meat' );
deprecated( 'Eating meat' );
expect( console ).toHaveWarned();
// eslint-disable-next-line no-console
expect( console.warn ).toHaveBeenCalledTimes( 1 );
} );
it( 'should do an action', () => {
deprecated( 'turkey', { alternative: 'tofurky' } );
expect( console ).toHaveWarned();
expect( didAction( 'deprecated' ) ).toBeTruthy();
} );
} );
+5
-22

@@ -9,18 +9,9 @@ /**

* message is only logged once.
*
* @type {Record<string, true | undefined>}
*/
export const logged = Object.create(null);
/**
* Logs a message to notify developers about a deprecated feature.
*
* @param {string} feature Name of the deprecated feature.
* @param {Object} [options] Personalisation options
* @param {string} [options.since] Version in which the feature was deprecated.
* @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
* @param {string} [options.hint] Additional message to help transition away from the deprecated feature.
* @param {string} feature Name of the deprecated feature.
* @param {DeprecatedOptions} [options] Personalisation options
*

@@ -67,11 +58,5 @@ * @example

*
* @param {string} feature Name of the deprecated feature.
* @param {?Object} options Personalisation options
* @param {string} options.since Version in which the feature was deprecated.
* @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
* @param {?string} options.hint Additional message to help transition away from the deprecated feature.
* @param {?string} message Message sent to console.warn
* @param {string} feature Name of the deprecated feature.
* @param {DeprecatedOptions} options Personalisation options
* @param {string} message Message sent to console.warn
*/

@@ -84,4 +69,2 @@ doAction('deprecated', feature, options, message);

}
/** @typedef {import('utility-types').NonUndefined<Parameters<typeof deprecated>[1]>} DeprecatedOptions */
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"names":["doAction","logged","Object","create","deprecated","feature","options","since","version","alternative","plugin","link","hint","pluginMessage","sinceMessage","versionMessage","useInsteadMessage","linkMessage","hintMessage","message","console","warn"],"sources":["@wordpress/deprecated/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { doAction } from '@wordpress/hooks';\n\n/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n *\n * @type {Record<string, true | undefined>}\n */\nexport const logged = Object.create( null );\n\n/**\n * Logs a message to notify developers about a deprecated feature.\n *\n * @param {string} feature Name of the deprecated feature.\n * @param {Object} [options] Personalisation options\n * @param {string} [options.since] Version in which the feature was deprecated.\n * @param {string} [options.version] Version in which the feature will be removed.\n * @param {string} [options.alternative] Feature to use instead\n * @param {string} [options.plugin] Plugin name if it's a plugin feature\n * @param {string} [options.link] Link to documentation\n * @param {string} [options.hint] Additional message to help transition away from the deprecated feature.\n *\n * @example\n * ```js\n * import deprecated from '@wordpress/deprecated';\n *\n * deprecated( 'Eating meat', {\n * \tsince: '2019.01.01'\n * \tversion: '2020.01.01',\n * \talternative: 'vegetables',\n * \tplugin: 'the earth',\n * \thint: 'You may find it beneficial to transition gradually.',\n * } );\n *\n * // Logs: 'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'\n * ```\n */\nexport default function deprecated( feature, options = {} ) {\n\tconst { since, version, alternative, plugin, link, hint } = options;\n\n\tconst pluginMessage = plugin ? ` from ${ plugin }` : '';\n\tconst sinceMessage = since ? ` since version ${ since }` : '';\n\tconst versionMessage = version\n\t\t? ` and will be removed${ pluginMessage } in version ${ version }`\n\t\t: '';\n\tconst useInsteadMessage = alternative\n\t\t? ` Please use ${ alternative } instead.`\n\t\t: '';\n\tconst linkMessage = link ? ` See: ${ link }` : '';\n\tconst hintMessage = hint ? ` Note: ${ hint }` : '';\n\tconst message = `${ feature } is deprecated${ sinceMessage }${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;\n\n\t// Skip if already logged.\n\tif ( message in logged ) {\n\t\treturn;\n\t}\n\n\t/**\n\t * Fires whenever a deprecated feature is encountered\n\t *\n\t * @param {string} feature Name of the deprecated feature.\n\t * @param {?Object} options Personalisation options\n\t * @param {string} options.since Version in which the feature was deprecated.\n\t * @param {?string} options.version Version in which the feature will be removed.\n\t * @param {?string} options.alternative Feature to use instead\n\t * @param {?string} options.plugin Plugin name if it's a plugin feature\n\t * @param {?string} options.link Link to documentation\n\t * @param {?string} options.hint Additional message to help transition away from the deprecated feature.\n\t * @param {?string} message Message sent to console.warn\n\t */\n\tdoAction( 'deprecated', feature, options, message );\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\tlogged[ message ] = true;\n}\n\n/** @typedef {import('utility-types').NonUndefined<Parameters<typeof deprecated>[1]>} DeprecatedOptions */\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,kBAAkB;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,MAAM,GAAGC,MAAM,CAACC,MAAM,CAAE,IAAK,CAAC;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,UAAUA,CAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,EAAG;EAC3D,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC,WAAW;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAK,CAAC,GAAGN,OAAO;EAEnE,MAAMO,aAAa,GAAGH,MAAM,GAAG,SAAUA,MAAM,EAAG,GAAG,EAAE;EACvD,MAAMI,YAAY,GAAGP,KAAK,GAAG,kBAAmBA,KAAK,EAAG,GAAG,EAAE;EAC7D,MAAMQ,cAAc,GAAGP,OAAO,GAC3B,uBAAwBK,aAAa,eAAiBL,OAAO,EAAG,GAChE,EAAE;EACL,MAAMQ,iBAAiB,GAAGP,WAAW,GAClC,eAAgBA,WAAW,WAAY,GACvC,EAAE;EACL,MAAMQ,WAAW,GAAGN,IAAI,GAAG,SAAUA,IAAI,EAAG,GAAG,EAAE;EACjD,MAAMO,WAAW,GAAGN,IAAI,GAAG,UAAWA,IAAI,EAAG,GAAG,EAAE;EAClD,MAAMO,OAAO,GAAG,GAAId,OAAO,iBAAmBS,YAAY,GAAKC,cAAc,IAAMC,iBAAiB,GAAKC,WAAW,GAAKC,WAAW,EAAG;;EAEvI;EACA,IAAKC,OAAO,IAAIlB,MAAM,EAAG;IACxB;EACD;;EAEA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACCD,QAAQ,CAAE,YAAY,EAAEK,OAAO,EAAEC,OAAO,EAAEa,OAAQ,CAAC;;EAEnD;EACAC,OAAO,CAACC,IAAI,CAAEF,OAAQ,CAAC;EAEvBlB,MAAM,CAAEkB,OAAO,CAAE,GAAG,IAAI;AACzB;;AAEA","ignoreList":[]}
{"version":3,"names":["doAction","logged","Object","create","deprecated","feature","options","since","version","alternative","plugin","link","hint","pluginMessage","sinceMessage","versionMessage","useInsteadMessage","linkMessage","hintMessage","message","console","warn"],"sources":["@wordpress/deprecated/src/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { doAction } from '@wordpress/hooks';\n\n/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n */\nexport const logged: Record< string, true > = Object.create( null );\n\ntype DeprecatedOptions = {\n\t/**\n\t * Version in which the feature was deprecated.\n\t */\n\tsince?: string;\n\t/**\n\t * Version in which the feature will be removed.\n\t */\n\tversion?: string;\n\t/**\n\t * Feature to use instead.\n\t */\n\talternative?: string;\n\t/**\n\t * Plugin name if it's a plugin feature.\n\t */\n\tplugin?: string;\n\t/**\n\t * Link to documentation.\n\t */\n\tlink?: string;\n\t/**\n\t * Additional message to help transition away from the deprecated feature.\n\t */\n\thint?: string;\n};\n\n/**\n * Logs a message to notify developers about a deprecated feature.\n *\n * @param {string} feature Name of the deprecated feature.\n * @param {DeprecatedOptions} [options] Personalisation options\n *\n * @example\n * ```js\n * import deprecated from '@wordpress/deprecated';\n *\n * deprecated( 'Eating meat', {\n * \tsince: '2019.01.01'\n * \tversion: '2020.01.01',\n * \talternative: 'vegetables',\n * \tplugin: 'the earth',\n * \thint: 'You may find it beneficial to transition gradually.',\n * } );\n *\n * // Logs: 'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'\n * ```\n */\nexport default function deprecated(\n\tfeature: string,\n\toptions: DeprecatedOptions = {}\n) {\n\tconst { since, version, alternative, plugin, link, hint } = options;\n\n\tconst pluginMessage = plugin ? ` from ${ plugin }` : '';\n\tconst sinceMessage = since ? ` since version ${ since }` : '';\n\tconst versionMessage = version\n\t\t? ` and will be removed${ pluginMessage } in version ${ version }`\n\t\t: '';\n\tconst useInsteadMessage = alternative\n\t\t? ` Please use ${ alternative } instead.`\n\t\t: '';\n\tconst linkMessage = link ? ` See: ${ link }` : '';\n\tconst hintMessage = hint ? ` Note: ${ hint }` : '';\n\tconst message = `${ feature } is deprecated${ sinceMessage }${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;\n\n\t// Skip if already logged.\n\tif ( message in logged ) {\n\t\treturn;\n\t}\n\n\t/**\n\t * Fires whenever a deprecated feature is encountered\n\t *\n\t * @param {string} feature Name of the deprecated feature.\n\t * @param {DeprecatedOptions} options Personalisation options\n\t * @param {string} message Message sent to console.warn\n\t */\n\tdoAction( 'deprecated', feature, options, message );\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\tlogged[ message ] = true;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,kBAAkB;;AAE3C;AACA;AACA;AACA;AACA,OAAO,MAAMC,MAA8B,GAAGC,MAAM,CAACC,MAAM,CAAE,IAAK,CAAC;AA6BnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,UAAUA,CACjCC,OAAe,EACfC,OAA0B,GAAG,CAAC,CAAC,EAC9B;EACD,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC,WAAW;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAK,CAAC,GAAGN,OAAO;EAEnE,MAAMO,aAAa,GAAGH,MAAM,GAAG,SAAUA,MAAM,EAAG,GAAG,EAAE;EACvD,MAAMI,YAAY,GAAGP,KAAK,GAAG,kBAAmBA,KAAK,EAAG,GAAG,EAAE;EAC7D,MAAMQ,cAAc,GAAGP,OAAO,GAC3B,uBAAwBK,aAAa,eAAiBL,OAAO,EAAG,GAChE,EAAE;EACL,MAAMQ,iBAAiB,GAAGP,WAAW,GAClC,eAAgBA,WAAW,WAAY,GACvC,EAAE;EACL,MAAMQ,WAAW,GAAGN,IAAI,GAAG,SAAUA,IAAI,EAAG,GAAG,EAAE;EACjD,MAAMO,WAAW,GAAGN,IAAI,GAAG,UAAWA,IAAI,EAAG,GAAG,EAAE;EAClD,MAAMO,OAAO,GAAG,GAAId,OAAO,iBAAmBS,YAAY,GAAKC,cAAc,IAAMC,iBAAiB,GAAKC,WAAW,GAAKC,WAAW,EAAG;;EAEvI;EACA,IAAKC,OAAO,IAAIlB,MAAM,EAAG;IACxB;EACD;;EAEA;AACD;AACA;AACA;AACA;AACA;AACA;EACCD,QAAQ,CAAE,YAAY,EAAEK,OAAO,EAAEC,OAAO,EAAEa,OAAQ,CAAC;;EAEnD;EACAC,OAAO,CAACC,IAAI,CAAEF,OAAQ,CAAC;EAEvBlB,MAAM,CAAEkB,OAAO,CAAE,GAAG,IAAI;AACzB","ignoreList":[]}
/**
* Object map tracking messages which have been logged, for use in ensuring a
* message is only logged once.
*/
export declare const logged: Record<string, true>;
type DeprecatedOptions = {
/**
* Version in which the feature was deprecated.
*/
since?: string;
/**
* Version in which the feature will be removed.
*/
version?: string;
/**
* Feature to use instead.
*/
alternative?: string;
/**
* Plugin name if it's a plugin feature.
*/
plugin?: string;
/**
* Link to documentation.
*/
link?: string;
/**
* Additional message to help transition away from the deprecated feature.
*/
hint?: string;
};
/**
* Logs a message to notify developers about a deprecated feature.
*
* @param {string} feature Name of the deprecated feature.
* @param {Object} [options] Personalisation options
* @param {string} [options.since] Version in which the feature was deprecated.
* @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
* @param {string} [options.hint] Additional message to help transition away from the deprecated feature.
* @param {string} feature Name of the deprecated feature.
* @param {DeprecatedOptions} [options] Personalisation options
*

@@ -28,18 +53,4 @@ * @example

*/
export default function deprecated(feature: string, options?: {
since?: string | undefined;
version?: string | undefined;
alternative?: string | undefined;
plugin?: string | undefined;
link?: string | undefined;
hint?: string | undefined;
}): void;
/**
* Object map tracking messages which have been logged, for use in ensuring a
* message is only logged once.
*
* @type {Record<string, true | undefined>}
*/
export const logged: Record<string, true | undefined>;
export type DeprecatedOptions = import("utility-types").NonUndefined<Parameters<typeof deprecated>[1]>;
export default function deprecated(feature: string, options?: DeprecatedOptions): void;
export {};
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,4CAxBW,MAAM,YAEd;IAAyB,KAAK;IACL,OAAO;IACP,WAAW;IACX,MAAM;IACN,IAAI;IACJ,IAAI;CAE7B,QAsDF;AA1ED;;;;;GAKG;AACH,qBAFU,MAAM,CAAC,MAAM,EAAE,IAAI,GAAG,SAAS,CAAC,CAEE;gCAsE9B,OAAO,eAAe,EAAE,YAAY,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,CAAE,MAAM,EAAE,IAAI,CAA0B,CAAC;AAEpE,KAAK,iBAAiB,GAAG;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,iBAAsB,QAkC/B"}

@@ -16,18 +16,9 @@ "use strict";

* message is only logged once.
*
* @type {Record<string, true | undefined>}
*/
const logged = exports.logged = Object.create(null);
/**
* Logs a message to notify developers about a deprecated feature.
*
* @param {string} feature Name of the deprecated feature.
* @param {Object} [options] Personalisation options
* @param {string} [options.since] Version in which the feature was deprecated.
* @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
* @param {string} [options.hint] Additional message to help transition away from the deprecated feature.
* @param {string} feature Name of the deprecated feature.
* @param {DeprecatedOptions} [options] Personalisation options
*

@@ -74,11 +65,5 @@ * @example

*
* @param {string} feature Name of the deprecated feature.
* @param {?Object} options Personalisation options
* @param {string} options.since Version in which the feature was deprecated.
* @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
* @param {?string} options.hint Additional message to help transition away from the deprecated feature.
* @param {?string} message Message sent to console.warn
* @param {string} feature Name of the deprecated feature.
* @param {DeprecatedOptions} options Personalisation options
* @param {string} message Message sent to console.warn
*/

@@ -91,4 +76,2 @@ (0, _hooks.doAction)('deprecated', feature, options, message);

}
/** @typedef {import('utility-types').NonUndefined<Parameters<typeof deprecated>[1]>} DeprecatedOptions */
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"names":["_hooks","require","logged","exports","Object","create","deprecated","feature","options","since","version","alternative","plugin","link","hint","pluginMessage","sinceMessage","versionMessage","useInsteadMessage","linkMessage","hintMessage","message","doAction","console","warn"],"sources":["@wordpress/deprecated/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { doAction } from '@wordpress/hooks';\n\n/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n *\n * @type {Record<string, true | undefined>}\n */\nexport const logged = Object.create( null );\n\n/**\n * Logs a message to notify developers about a deprecated feature.\n *\n * @param {string} feature Name of the deprecated feature.\n * @param {Object} [options] Personalisation options\n * @param {string} [options.since] Version in which the feature was deprecated.\n * @param {string} [options.version] Version in which the feature will be removed.\n * @param {string} [options.alternative] Feature to use instead\n * @param {string} [options.plugin] Plugin name if it's a plugin feature\n * @param {string} [options.link] Link to documentation\n * @param {string} [options.hint] Additional message to help transition away from the deprecated feature.\n *\n * @example\n * ```js\n * import deprecated from '@wordpress/deprecated';\n *\n * deprecated( 'Eating meat', {\n * \tsince: '2019.01.01'\n * \tversion: '2020.01.01',\n * \talternative: 'vegetables',\n * \tplugin: 'the earth',\n * \thint: 'You may find it beneficial to transition gradually.',\n * } );\n *\n * // Logs: 'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'\n * ```\n */\nexport default function deprecated( feature, options = {} ) {\n\tconst { since, version, alternative, plugin, link, hint } = options;\n\n\tconst pluginMessage = plugin ? ` from ${ plugin }` : '';\n\tconst sinceMessage = since ? ` since version ${ since }` : '';\n\tconst versionMessage = version\n\t\t? ` and will be removed${ pluginMessage } in version ${ version }`\n\t\t: '';\n\tconst useInsteadMessage = alternative\n\t\t? ` Please use ${ alternative } instead.`\n\t\t: '';\n\tconst linkMessage = link ? ` See: ${ link }` : '';\n\tconst hintMessage = hint ? ` Note: ${ hint }` : '';\n\tconst message = `${ feature } is deprecated${ sinceMessage }${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;\n\n\t// Skip if already logged.\n\tif ( message in logged ) {\n\t\treturn;\n\t}\n\n\t/**\n\t * Fires whenever a deprecated feature is encountered\n\t *\n\t * @param {string} feature Name of the deprecated feature.\n\t * @param {?Object} options Personalisation options\n\t * @param {string} options.since Version in which the feature was deprecated.\n\t * @param {?string} options.version Version in which the feature will be removed.\n\t * @param {?string} options.alternative Feature to use instead\n\t * @param {?string} options.plugin Plugin name if it's a plugin feature\n\t * @param {?string} options.link Link to documentation\n\t * @param {?string} options.hint Additional message to help transition away from the deprecated feature.\n\t * @param {?string} message Message sent to console.warn\n\t */\n\tdoAction( 'deprecated', feature, options, message );\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\tlogged[ message ] = true;\n}\n\n/** @typedef {import('utility-types').NonUndefined<Parameters<typeof deprecated>[1]>} DeprecatedOptions */\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAGE,MAAM,CAACC,MAAM,CAAE,IAAK,CAAC;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,UAAUA,CAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,EAAG;EAC3D,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC,WAAW;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAK,CAAC,GAAGN,OAAO;EAEnE,MAAMO,aAAa,GAAGH,MAAM,GAAG,SAAUA,MAAM,EAAG,GAAG,EAAE;EACvD,MAAMI,YAAY,GAAGP,KAAK,GAAG,kBAAmBA,KAAK,EAAG,GAAG,EAAE;EAC7D,MAAMQ,cAAc,GAAGP,OAAO,GAC3B,uBAAwBK,aAAa,eAAiBL,OAAO,EAAG,GAChE,EAAE;EACL,MAAMQ,iBAAiB,GAAGP,WAAW,GAClC,eAAgBA,WAAW,WAAY,GACvC,EAAE;EACL,MAAMQ,WAAW,GAAGN,IAAI,GAAG,SAAUA,IAAI,EAAG,GAAG,EAAE;EACjD,MAAMO,WAAW,GAAGN,IAAI,GAAG,UAAWA,IAAI,EAAG,GAAG,EAAE;EAClD,MAAMO,OAAO,GAAG,GAAId,OAAO,iBAAmBS,YAAY,GAAKC,cAAc,IAAMC,iBAAiB,GAAKC,WAAW,GAAKC,WAAW,EAAG;;EAEvI;EACA,IAAKC,OAAO,IAAInB,MAAM,EAAG;IACxB;EACD;;EAEA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,IAAAoB,eAAQ,EAAE,YAAY,EAAEf,OAAO,EAAEC,OAAO,EAAEa,OAAQ,CAAC;;EAEnD;EACAE,OAAO,CAACC,IAAI,CAAEH,OAAQ,CAAC;EAEvBnB,MAAM,CAAEmB,OAAO,CAAE,GAAG,IAAI;AACzB;;AAEA","ignoreList":[]}
{"version":3,"names":["_hooks","require","logged","exports","Object","create","deprecated","feature","options","since","version","alternative","plugin","link","hint","pluginMessage","sinceMessage","versionMessage","useInsteadMessage","linkMessage","hintMessage","message","doAction","console","warn"],"sources":["@wordpress/deprecated/src/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { doAction } from '@wordpress/hooks';\n\n/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n */\nexport const logged: Record< string, true > = Object.create( null );\n\ntype DeprecatedOptions = {\n\t/**\n\t * Version in which the feature was deprecated.\n\t */\n\tsince?: string;\n\t/**\n\t * Version in which the feature will be removed.\n\t */\n\tversion?: string;\n\t/**\n\t * Feature to use instead.\n\t */\n\talternative?: string;\n\t/**\n\t * Plugin name if it's a plugin feature.\n\t */\n\tplugin?: string;\n\t/**\n\t * Link to documentation.\n\t */\n\tlink?: string;\n\t/**\n\t * Additional message to help transition away from the deprecated feature.\n\t */\n\thint?: string;\n};\n\n/**\n * Logs a message to notify developers about a deprecated feature.\n *\n * @param {string} feature Name of the deprecated feature.\n * @param {DeprecatedOptions} [options] Personalisation options\n *\n * @example\n * ```js\n * import deprecated from '@wordpress/deprecated';\n *\n * deprecated( 'Eating meat', {\n * \tsince: '2019.01.01'\n * \tversion: '2020.01.01',\n * \talternative: 'vegetables',\n * \tplugin: 'the earth',\n * \thint: 'You may find it beneficial to transition gradually.',\n * } );\n *\n * // Logs: 'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'\n * ```\n */\nexport default function deprecated(\n\tfeature: string,\n\toptions: DeprecatedOptions = {}\n) {\n\tconst { since, version, alternative, plugin, link, hint } = options;\n\n\tconst pluginMessage = plugin ? ` from ${ plugin }` : '';\n\tconst sinceMessage = since ? ` since version ${ since }` : '';\n\tconst versionMessage = version\n\t\t? ` and will be removed${ pluginMessage } in version ${ version }`\n\t\t: '';\n\tconst useInsteadMessage = alternative\n\t\t? ` Please use ${ alternative } instead.`\n\t\t: '';\n\tconst linkMessage = link ? ` See: ${ link }` : '';\n\tconst hintMessage = hint ? ` Note: ${ hint }` : '';\n\tconst message = `${ feature } is deprecated${ sinceMessage }${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;\n\n\t// Skip if already logged.\n\tif ( message in logged ) {\n\t\treturn;\n\t}\n\n\t/**\n\t * Fires whenever a deprecated feature is encountered\n\t *\n\t * @param {string} feature Name of the deprecated feature.\n\t * @param {DeprecatedOptions} options Personalisation options\n\t * @param {string} message Message sent to console.warn\n\t */\n\tdoAction( 'deprecated', feature, options, message );\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\tlogged[ message ] = true;\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,MAAMC,MAA8B,GAAAC,OAAA,CAAAD,MAAA,GAAGE,MAAM,CAACC,MAAM,CAAE,IAAK,CAAC;AA6BnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,UAAUA,CACjCC,OAAe,EACfC,OAA0B,GAAG,CAAC,CAAC,EAC9B;EACD,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC,WAAW;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAK,CAAC,GAAGN,OAAO;EAEnE,MAAMO,aAAa,GAAGH,MAAM,GAAG,SAAUA,MAAM,EAAG,GAAG,EAAE;EACvD,MAAMI,YAAY,GAAGP,KAAK,GAAG,kBAAmBA,KAAK,EAAG,GAAG,EAAE;EAC7D,MAAMQ,cAAc,GAAGP,OAAO,GAC3B,uBAAwBK,aAAa,eAAiBL,OAAO,EAAG,GAChE,EAAE;EACL,MAAMQ,iBAAiB,GAAGP,WAAW,GAClC,eAAgBA,WAAW,WAAY,GACvC,EAAE;EACL,MAAMQ,WAAW,GAAGN,IAAI,GAAG,SAAUA,IAAI,EAAG,GAAG,EAAE;EACjD,MAAMO,WAAW,GAAGN,IAAI,GAAG,UAAWA,IAAI,EAAG,GAAG,EAAE;EAClD,MAAMO,OAAO,GAAG,GAAId,OAAO,iBAAmBS,YAAY,GAAKC,cAAc,IAAMC,iBAAiB,GAAKC,WAAW,GAAKC,WAAW,EAAG;;EAEvI;EACA,IAAKC,OAAO,IAAInB,MAAM,EAAG;IACxB;EACD;;EAEA;AACD;AACA;AACA;AACA;AACA;AACA;EACC,IAAAoB,eAAQ,EAAE,YAAY,EAAEf,OAAO,EAAEC,OAAO,EAAEa,OAAQ,CAAC;;EAEnD;EACAE,OAAO,CAACC,IAAI,CAAEH,OAAQ,CAAC;EAEvBnB,MAAM,CAAEmB,OAAO,CAAE,GAAG,IAAI;AACzB","ignoreList":[]}

@@ -5,2 +5,4 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->

## 4.26.0 (2025-06-25)
## 4.25.0 (2025-06-04)

@@ -7,0 +9,0 @@

{
"name": "@wordpress/deprecated",
"version": "4.25.0",
"version": "4.26.0",
"description": "Deprecation utility for WordPress.",

@@ -33,3 +33,3 @@ "author": "The WordPress Contributors",

"@babel/runtime": "7.25.7",
"@wordpress/hooks": "^4.25.0"
"@wordpress/hooks": "^4.26.0"
},

@@ -39,3 +39,3 @@ "publishConfig": {

},
"gitHead": "d1acd76ffff33ab01f0a948d2f51e5e45c95158d"
"gitHead": "35e26942820d8237771af0c58e45b4303f0497f1"
}

@@ -62,9 +62,3 @@ # Deprecated

- _feature_ `string`: Name of the deprecated feature.
- _options_ `[Object]`: Personalisation options
- _options.since_ `[string]`: Version in which the feature was deprecated.
- _options.version_ `[string]`: Version in which the feature will be removed.
- _options.alternative_ `[string]`: Feature to use instead
- _options.plugin_ `[string]`: Plugin name if it's a plugin feature
- _options.link_ `[string]`: Link to documentation
- _options.hint_ `[string]`: Additional message to help transition away from the deprecated feature.
- _options_ `[DeprecatedOptions]`: Personalisation options

@@ -77,3 +71,3 @@ ### logged

- `Record<string, true | undefined>`
- `Record< string, true >`

@@ -80,0 +74,0 @@ <!-- END TOKEN(Autogenerated API docs) -->

/**
* WordPress dependencies
*/
import { doAction } from '@wordpress/hooks';
/**
* Object map tracking messages which have been logged, for use in ensuring a
* message is only logged once.
*
* @type {Record<string, true | undefined>}
*/
export const logged = Object.create( null );
/**
* Logs a message to notify developers about a deprecated feature.
*
* @param {string} feature Name of the deprecated feature.
* @param {Object} [options] Personalisation options
* @param {string} [options.since] Version in which the feature was deprecated.
* @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
* @param {string} [options.hint] Additional message to help transition away from the deprecated feature.
*
* @example
* ```js
* import deprecated from '@wordpress/deprecated';
*
* deprecated( 'Eating meat', {
* since: '2019.01.01'
* version: '2020.01.01',
* alternative: 'vegetables',
* plugin: 'the earth',
* hint: 'You may find it beneficial to transition gradually.',
* } );
*
* // Logs: 'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
* ```
*/
export default function deprecated( feature, options = {} ) {
const { since, version, alternative, plugin, link, hint } = options;
const pluginMessage = plugin ? ` from ${ plugin }` : '';
const sinceMessage = since ? ` since version ${ since }` : '';
const versionMessage = version
? ` and will be removed${ pluginMessage } in version ${ version }`
: '';
const useInsteadMessage = alternative
? ` Please use ${ alternative } instead.`
: '';
const linkMessage = link ? ` See: ${ link }` : '';
const hintMessage = hint ? ` Note: ${ hint }` : '';
const message = `${ feature } is deprecated${ sinceMessage }${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;
// Skip if already logged.
if ( message in logged ) {
return;
}
/**
* Fires whenever a deprecated feature is encountered
*
* @param {string} feature Name of the deprecated feature.
* @param {?Object} options Personalisation options
* @param {string} options.since Version in which the feature was deprecated.
* @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
* @param {?string} options.hint Additional message to help transition away from the deprecated feature.
* @param {?string} message Message sent to console.warn
*/
doAction( 'deprecated', feature, options, message );
// eslint-disable-next-line no-console
console.warn( message );
logged[ message ] = true;
}
/** @typedef {import('utility-types').NonUndefined<Parameters<typeof deprecated>[1]>} DeprecatedOptions */
/**
* WordPress dependencies
*/
import { didAction } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import deprecated, { logged } from '../';
describe( 'deprecated', () => {
afterEach( () => {
for ( const key in logged ) {
delete logged[ key ];
}
} );
it( 'should show a deprecation warning', () => {
deprecated( 'Eating meat' );
expect( console ).toHaveWarnedWith( 'Eating meat is deprecated.' );
} );
it( 'should show a deprecation warning with a since', () => {
deprecated( 'Eating meat', { since: '2019.01.01' } );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated since version 2019.01.01.'
);
} );
it( 'should show a deprecation warning with a version', () => {
deprecated( 'Eating meat', { version: '2020.01.01' } );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed in version 2020.01.01.'
);
} );
it( 'should show a deprecation warning with an alternative', () => {
deprecated( 'Eating meat', {
since: '2019.01.01',
version: '2020.01.01',
alternative: 'vegetables',
} );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated since version 2019.01.01 and will be removed in version 2020.01.01. Please use vegetables instead.'
);
} );
it( 'should show a deprecation warning with an alternative specific to a plugin', () => {
deprecated( 'Eating meat', {
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
} );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed from the earth in version 2020.01.01. Please use vegetables instead.'
);
} );
it( 'should show a deprecation warning with a link', () => {
deprecated( 'Eating meat', {
version: '2020.01.01',
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 version 2020.01.01. Please use vegetables instead. See: https://en.wikipedia.org/wiki/Vegetarianism'
);
} );
it( 'should show a deprecation warning with a hint', () => {
deprecated( 'Eating meat', {
since: '2019.01.01',
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
hint: 'You may find it beneficial to transition gradually.',
} );
expect( console ).toHaveWarnedWith(
'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
);
} );
it( 'should show a message once', () => {
deprecated( 'Eating meat' );
deprecated( 'Eating meat' );
expect( console ).toHaveWarned();
// eslint-disable-next-line no-console
expect( console.warn ).toHaveBeenCalledTimes( 1 );
} );
it( 'should do an action', () => {
deprecated( 'turkey', { alternative: 'tofurky' } );
expect( console ).toHaveWarned();
expect( didAction( 'deprecated' ) ).toBeTruthy();
} );
} );

Sorry, the diff of this file is not supported yet