Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

@wordpress/warning

Package Overview
Dependencies
Maintainers
24
Versions
206
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/warning - npm Package Compare versions

Comparing version
3.0.1
to
3.1.0
+50
src/index.ts
/**
* Internal dependencies
*/
import { logged } from './utils';
function isDev(): boolean {
// eslint-disable-next-line @wordpress/wp-global-usage
return globalThis.SCRIPT_DEBUG === true;
}
/**
* Shows a warning with `message` if environment is not `production`.
*
* @param message Message to show in the warning.
*
* @example
* ```js
* import warning from '@wordpress/warning';
*
* function MyComponent( props ) {
* if ( ! props.title ) {
* warning( '`props.title` was not passed' );
* }
* ...
* }
* ```
*/
export default function warning( message: string ): void {
if ( ! isDev() ) {
return;
}
// Skip if already logged.
if ( logged.has( message ) ) {
return;
}
// eslint-disable-next-line no-console
console.warn( message );
// Throwing an error and catching it immediately to improve debugging
// A consumer can use 'pause on caught exceptions'
// https://github.com/facebook/react/issues/4216
try {
throw Error( message );
} catch ( x ) {
// Do nothing.
}
logged.add( message );
}
/**
* Object map tracking messages which have been logged, for use in ensuring a
* message is only logged once.
*/
export const logged: Set< string > = new Set();
+1
-1

@@ -13,3 +13,3 @@ /**

*
* @param {string} message Message to show in the warning.
* @param message Message to show in the warning.
*

@@ -16,0 +16,0 @@ * @example

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

{"version":3,"names":["logged","isDev","globalThis","SCRIPT_DEBUG","warning","message","has","console","warn","Error","x","add"],"sources":["@wordpress/warning/src/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { logged } from './utils';\n\nfunction isDev() {\n\t// eslint-disable-next-line @wordpress/wp-global-usage\n\treturn globalThis.SCRIPT_DEBUG === true;\n}\n\n/**\n * Shows a warning with `message` if environment is not `production`.\n *\n * @param {string} message Message to show in the warning.\n *\n * @example\n * ```js\n * import warning from '@wordpress/warning';\n *\n * function MyComponent( props ) {\n * if ( ! props.title ) {\n * warning( '`props.title` was not passed' );\n * }\n * ...\n * }\n * ```\n */\nexport default function warning( message ) {\n\tif ( ! isDev() ) {\n\t\treturn;\n\t}\n\n\t// Skip if already logged.\n\tif ( logged.has( message ) ) {\n\t\treturn;\n\t}\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\t// Throwing an error and catching it immediately to improve debugging\n\t// A consumer can use 'pause on caught exceptions'\n\t// https://github.com/facebook/react/issues/4216\n\ttry {\n\t\tthrow Error( message );\n\t} catch ( x ) {\n\t\t// Do nothing.\n\t}\n\n\tlogged.add( message );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,KAAKA,CAAA,EAAG;EAChB;EACA,OAAOC,UAAU,CAACC,YAAY,KAAK,IAAI;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,OAAOA,CAAEC,OAAO,EAAG;EAC1C,IAAK,CAAEJ,KAAK,CAAC,CAAC,EAAG;IAChB;EACD;;EAEA;EACA,IAAKD,MAAM,CAACM,GAAG,CAAED,OAAQ,CAAC,EAAG;IAC5B;EACD;;EAEA;EACAE,OAAO,CAACC,IAAI,CAAEH,OAAQ,CAAC;;EAEvB;EACA;EACA;EACA,IAAI;IACH,MAAMI,KAAK,CAAEJ,OAAQ,CAAC;EACvB,CAAC,CAAC,OAAQK,CAAC,EAAG;IACb;EAAA;EAGDV,MAAM,CAACW,GAAG,CAAEN,OAAQ,CAAC;AACtB","ignoreList":[]}
{"version":3,"names":["logged","isDev","globalThis","SCRIPT_DEBUG","warning","message","has","console","warn","Error","x","add"],"sources":["@wordpress/warning/src/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { logged } from './utils';\n\nfunction isDev(): boolean {\n\t// eslint-disable-next-line @wordpress/wp-global-usage\n\treturn globalThis.SCRIPT_DEBUG === true;\n}\n\n/**\n * Shows a warning with `message` if environment is not `production`.\n *\n * @param message Message to show in the warning.\n *\n * @example\n * ```js\n * import warning from '@wordpress/warning';\n *\n * function MyComponent( props ) {\n * if ( ! props.title ) {\n * warning( '`props.title` was not passed' );\n * }\n * ...\n * }\n * ```\n */\nexport default function warning( message: string ): void {\n\tif ( ! isDev() ) {\n\t\treturn;\n\t}\n\n\t// Skip if already logged.\n\tif ( logged.has( message ) ) {\n\t\treturn;\n\t}\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\t// Throwing an error and catching it immediately to improve debugging\n\t// A consumer can use 'pause on caught exceptions'\n\t// https://github.com/facebook/react/issues/4216\n\ttry {\n\t\tthrow Error( message );\n\t} catch ( x ) {\n\t\t// Do nothing.\n\t}\n\tlogged.add( message );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,KAAKA,CAAA,EAAY;EACzB;EACA,OAAOC,UAAU,CAACC,YAAY,KAAK,IAAI;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,OAAOA,CAAEC,OAAe,EAAS;EACxD,IAAK,CAAEJ,KAAK,CAAC,CAAC,EAAG;IAChB;EACD;;EAEA;EACA,IAAKD,MAAM,CAACM,GAAG,CAAED,OAAQ,CAAC,EAAG;IAC5B;EACD;;EAEA;EACAE,OAAO,CAACC,IAAI,CAAEH,OAAQ,CAAC;;EAEvB;EACA;EACA;EACA,IAAI;IACH,MAAMI,KAAK,CAAEJ,OAAQ,CAAC;EACvB,CAAC,CAAC,OAAQK,CAAC,EAAG;IACb;EAAA;EAEDV,MAAM,CAACW,GAAG,CAAEN,OAAQ,CAAC;AACtB","ignoreList":[]}
/**
* Object map tracking messages which have been logged, for use in ensuring a
* message is only logged once.
*
* @type {Set<string>}
*/
export const logged = new Set();
//# sourceMappingURL=utils.js.map

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

{"version":3,"names":["logged","Set"],"sources":["@wordpress/warning/src/utils.js"],"sourcesContent":["/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n *\n * @type {Set<string>}\n */\nexport const logged = new Set();\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,MAAM,GAAG,IAAIC,GAAG,CAAC,CAAC","ignoreList":[]}
{"version":3,"names":["logged","Set"],"sources":["@wordpress/warning/src/utils.ts"],"sourcesContent":["/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n */\nexport const logged: Set< string > = new Set();\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAO,MAAMA,MAAqB,GAAG,IAAIC,GAAG,CAAC,CAAC","ignoreList":[]}
/**
* Shows a warning with `message` if environment is not `production`.
*
* @param {string} message Message to show in the warning.
* @param message Message to show in the warning.
*

@@ -6,0 +6,0 @@ * @example

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

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;GAgBG;AACH,yCAdW,MAAM,QAqChB"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAE,OAAO,EAAE,MAAM,GAAI,IAAI,CAsBvD"}
/**
* Object map tracking messages which have been logged, for use in ensuring a
* message is only logged once.
*
* @type {Set<string>}
*/
export const logged: Set<string>;
export declare const logged: Set<string>;
//# sourceMappingURL=utils.d.ts.map

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

{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAFU,IAAI,MAAM,CAAC,CAEW"}
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,GAAG,CAAE,MAAM,CAAc,CAAC"}

@@ -20,3 +20,3 @@ "use strict";

*
* @param {string} message Message to show in the warning.
* @param message Message to show in the warning.
*

@@ -23,0 +23,0 @@ * @example

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

{"version":3,"names":["_utils","require","isDev","globalThis","SCRIPT_DEBUG","warning","message","logged","has","console","warn","Error","x","add"],"sources":["@wordpress/warning/src/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { logged } from './utils';\n\nfunction isDev() {\n\t// eslint-disable-next-line @wordpress/wp-global-usage\n\treturn globalThis.SCRIPT_DEBUG === true;\n}\n\n/**\n * Shows a warning with `message` if environment is not `production`.\n *\n * @param {string} message Message to show in the warning.\n *\n * @example\n * ```js\n * import warning from '@wordpress/warning';\n *\n * function MyComponent( props ) {\n * if ( ! props.title ) {\n * warning( '`props.title` was not passed' );\n * }\n * ...\n * }\n * ```\n */\nexport default function warning( message ) {\n\tif ( ! isDev() ) {\n\t\treturn;\n\t}\n\n\t// Skip if already logged.\n\tif ( logged.has( message ) ) {\n\t\treturn;\n\t}\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\t// Throwing an error and catching it immediately to improve debugging\n\t// A consumer can use 'pause on caught exceptions'\n\t// https://github.com/facebook/react/issues/4216\n\ttry {\n\t\tthrow Error( message );\n\t} catch ( x ) {\n\t\t// Do nothing.\n\t}\n\n\tlogged.add( message );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,SAASC,KAAKA,CAAA,EAAG;EAChB;EACA,OAAOC,UAAU,CAACC,YAAY,KAAK,IAAI;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,OAAOA,CAAEC,OAAO,EAAG;EAC1C,IAAK,CAAEJ,KAAK,CAAC,CAAC,EAAG;IAChB;EACD;;EAEA;EACA,IAAKK,aAAM,CAACC,GAAG,CAAEF,OAAQ,CAAC,EAAG;IAC5B;EACD;;EAEA;EACAG,OAAO,CAACC,IAAI,CAAEJ,OAAQ,CAAC;;EAEvB;EACA;EACA;EACA,IAAI;IACH,MAAMK,KAAK,CAAEL,OAAQ,CAAC;EACvB,CAAC,CAAC,OAAQM,CAAC,EAAG;IACb;EAAA;EAGDL,aAAM,CAACM,GAAG,CAAEP,OAAQ,CAAC;AACtB","ignoreList":[]}
{"version":3,"names":["_utils","require","isDev","globalThis","SCRIPT_DEBUG","warning","message","logged","has","console","warn","Error","x","add"],"sources":["@wordpress/warning/src/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { logged } from './utils';\n\nfunction isDev(): boolean {\n\t// eslint-disable-next-line @wordpress/wp-global-usage\n\treturn globalThis.SCRIPT_DEBUG === true;\n}\n\n/**\n * Shows a warning with `message` if environment is not `production`.\n *\n * @param message Message to show in the warning.\n *\n * @example\n * ```js\n * import warning from '@wordpress/warning';\n *\n * function MyComponent( props ) {\n * if ( ! props.title ) {\n * warning( '`props.title` was not passed' );\n * }\n * ...\n * }\n * ```\n */\nexport default function warning( message: string ): void {\n\tif ( ! isDev() ) {\n\t\treturn;\n\t}\n\n\t// Skip if already logged.\n\tif ( logged.has( message ) ) {\n\t\treturn;\n\t}\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn( message );\n\n\t// Throwing an error and catching it immediately to improve debugging\n\t// A consumer can use 'pause on caught exceptions'\n\t// https://github.com/facebook/react/issues/4216\n\ttry {\n\t\tthrow Error( message );\n\t} catch ( x ) {\n\t\t// Do nothing.\n\t}\n\tlogged.add( message );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,SAASC,KAAKA,CAAA,EAAY;EACzB;EACA,OAAOC,UAAU,CAACC,YAAY,KAAK,IAAI;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,OAAOA,CAAEC,OAAe,EAAS;EACxD,IAAK,CAAEJ,KAAK,CAAC,CAAC,EAAG;IAChB;EACD;;EAEA;EACA,IAAKK,aAAM,CAACC,GAAG,CAAEF,OAAQ,CAAC,EAAG;IAC5B;EACD;;EAEA;EACAG,OAAO,CAACC,IAAI,CAAEJ,OAAQ,CAAC;;EAEvB;EACA;EACA;EACA,IAAI;IACH,MAAMK,KAAK,CAAEL,OAAQ,CAAC;EACvB,CAAC,CAAC,OAAQM,CAAC,EAAG;IACb;EAAA;EAEDL,aAAM,CAACM,GAAG,CAAEP,OAAQ,CAAC;AACtB","ignoreList":[]}

@@ -10,6 +10,4 @@ "use strict";

* message is only logged once.
*
* @type {Set<string>}
*/
const logged = exports.logged = new Set();
//# sourceMappingURL=utils.js.map

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

{"version":3,"names":["logged","exports","Set"],"sources":["@wordpress/warning/src/utils.js"],"sourcesContent":["/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n *\n * @type {Set<string>}\n */\nexport const logged = new Set();\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAG,IAAIE,GAAG,CAAC,CAAC","ignoreList":[]}
{"version":3,"names":["logged","exports","Set"],"sources":["@wordpress/warning/src/utils.ts"],"sourcesContent":["/**\n * Object map tracking messages which have been logged, for use in ensuring a\n * message is only logged once.\n */\nexport const logged: Set< string > = new Set();\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACO,MAAMA,MAAqB,GAAAC,OAAA,CAAAD,MAAA,GAAG,IAAIE,GAAG,CAAC,CAAC","ignoreList":[]}

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

## 3.1.0 (2024-06-15)
### Internal
- Refactor to TypeScript ([#62557](https://github.com/WordPress/gutenberg/pull/62557)).
## 3.0.0 (2024-05-31)

@@ -151,1 +157,2 @@

Initial release.
{
"name": "@wordpress/warning",
"version": "3.0.1",
"version": "3.1.0",
"description": "Warning utility for WordPress.",

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

},
"gitHead": "0e973525f7787401b5a544e0727774d52a78639f"
"gitHead": "66d3bf12e67d16deddc4b4a9ec42e1d0bed3479a"
}
/**
* Internal dependencies
*/
import { logged } from './utils';
function isDev() {
// eslint-disable-next-line @wordpress/wp-global-usage
return globalThis.SCRIPT_DEBUG === true;
}
/**
* Shows a warning with `message` if environment is not `production`.
*
* @param {string} message Message to show in the warning.
*
* @example
* ```js
* import warning from '@wordpress/warning';
*
* function MyComponent( props ) {
* if ( ! props.title ) {
* warning( '`props.title` was not passed' );
* }
* ...
* }
* ```
*/
export default function warning( message ) {
if ( ! isDev() ) {
return;
}
// Skip if already logged.
if ( logged.has( message ) ) {
return;
}
// eslint-disable-next-line no-console
console.warn( message );
// Throwing an error and catching it immediately to improve debugging
// A consumer can use 'pause on caught exceptions'
// https://github.com/facebook/react/issues/4216
try {
throw Error( message );
} catch ( x ) {
// Do nothing.
}
logged.add( message );
}
/**
* Object map tracking messages which have been logged, for use in ensuring a
* message is only logged once.
*
* @type {Set<string>}
*/
export const logged = new Set();

Sorry, the diff of this file is not supported yet