diff --git a/flow-typed/npm/pretty-format_v26.x.x.js b/flow-typed/npm/pretty-format_v26.x.x.js deleted file mode 100644 index bd2c68334cffb3..00000000000000 --- a/flow-typed/npm/pretty-format_v26.x.x.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @flow strict - * @format - */ - -type PrettyFormatPlugin = - | { - test: (value: mixed) => boolean, - print: (value: mixed) => string, - } - | { - test: (value: mixed) => boolean, - serialize: (value: mixed) => string, - }; - -declare module 'pretty-format' { - declare module.exports: { - ( - value: mixed, - options?: ?{ - callToJSON?: ?boolean, - escapeRegex?: ?boolean, - escapeString?: ?boolean, - highlight?: ?boolean, - indent?: ?number, - maxDepth?: ?number, - min?: ?boolean, - plugins?: ?Array, - printFunctionName?: ?boolean, - theme?: ?{ - comment?: ?string, - prop?: ?string, - tag?: ?string, - value: ?string, - }, - }, - ): string, - - plugins: { - AsymmetricMatcher: PrettyFormatPlugin, - ConvertAnsi: PrettyFormatPlugin, - DOMCollection: PrettyFormatPlugin, - DOMElement: PrettyFormatPlugin, - Immutable: PrettyFormatPlugin, - ReactElement: PrettyFormatPlugin, - ReactTestComponent: PrettyFormatPlugin, - }, - }; -} diff --git a/flow-typed/npm/pretty-format_v29.x.x.js b/flow-typed/npm/pretty-format_v29.x.x.js new file mode 100644 index 00000000000000..fddcc13375d519 --- /dev/null +++ b/flow-typed/npm/pretty-format_v29.x.x.js @@ -0,0 +1,73 @@ +/** + * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. + * + * @flow strict + * @format + * @oncall react_native + */ +declare type Print = (value: mixed) => string; +declare type Indent = (value: string) => string; +declare type PluginOptions = { + edgeSpacing: string, + min: boolean, + spacing: string, +}; +declare type Colors = { + comment: {close: string; open: string}, + content: {close: string; open: string}, + prop: {close: string; open: string}, + tag: {close: string; open: string}, + value: {close: string; open: string}, +}; +declare type CompareKeys = ((a: string, b: string) => number) | null | void; + +declare type PrettyFormatPlugin = + | { + print: ( + value: mixed, + print?: ?Print, + indent?: ?Indent, + options?: ?PluginOptions, + colors?: ?Colors, + ) => string, + test: (value: mixed) => boolean, + } + | { + serialize: (value: mixed) => string, + test: (value: mixed) => boolean, + }; + +declare module 'pretty-format' { + declare export function format( + value: mixed, + options?: ?{ + callToJSON?: ?boolean, + compareKeys?: CompareKeys, + escapeRegex?: ?boolean, + escapeString?: ?boolean, + highlight?: ?boolean, + indent?: ?number, + maxDepth?: ?number, + maxWidth?: ?number, + min?: ?boolean, + plugins?: ?Array, + printBasicPrototype?: ?boolean, + printFunctionName?: ?boolean, + theme?: ?{ + comment?: ?string, + content?: ?string, + prop?: ?string, + tag?: ?string, + value: ?string, + }, + }, + ): string; + declare export const plugins: { + AsymmetricMatcher: PrettyFormatPlugin, + DOMCollection: PrettyFormatPlugin, + DOMElement: PrettyFormatPlugin, + Immutable: PrettyFormatPlugin, + ReactElement: PrettyFormatPlugin, + ReactTestComponent: PrettyFormatPlugin, + }; +} diff --git a/packages/react-native/Libraries/Utilities/HMRClient.js b/packages/react-native/Libraries/Utilities/HMRClient.js index 8a772abfb8bc27..bed704f269c0c3 100644 --- a/packages/react-native/Libraries/Utilities/HMRClient.js +++ b/packages/react-native/Libraries/Utilities/HMRClient.js @@ -126,7 +126,7 @@ const HMRClient: HMRClientNativeInterface = { data: data.map(item => typeof item === 'string' ? item - : prettyFormat(item, { + : prettyFormat.format(item, { escapeString: true, highlight: true, maxDepth: 3, diff --git a/packages/react-native/Libraries/promiseRejectionTrackingOptions.js b/packages/react-native/Libraries/promiseRejectionTrackingOptions.js index 04e5d14bebddd6..5a12d2d300b3e4 100644 --- a/packages/react-native/Libraries/promiseRejectionTrackingOptions.js +++ b/packages/react-native/Libraries/promiseRejectionTrackingOptions.js @@ -27,7 +27,7 @@ let rejectionTrackingOptions: $NonMaybeType[0]> = { stack = error.stack; } else { try { - message = require('pretty-format')(rejection); + message = require('pretty-format').format(rejection); } catch { message = typeof rejection === 'string' diff --git a/packages/react-native/package.json b/packages/react-native/package.json index de7c5d34c40c7c..709a4de0221e28 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -133,7 +133,7 @@ "metro-source-map": "^0.80.3", "mkdirp": "^0.5.1", "nullthrows": "^1.1.1", - "pretty-format": "^26.5.2", + "pretty-format": "^29.7.0", "promise": "^8.3.0", "react-devtools-core": "^5.3.1", "react-refresh": "^0.14.0", diff --git a/yarn.lock b/yarn.lock index d9e65901938414..5c7cb5ab507124 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7399,7 +7399,7 @@ pretty-format@^24.9.0: ansi-styles "^3.2.0" react-is "^16.8.4" -pretty-format@^26.5.2, pretty-format@^26.6.2: +pretty-format@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93" integrity sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg== @@ -7427,6 +7427,15 @@ pretty-format@^29.6.3: ansi-styles "^5.0.0" react-is "^18.0.0" +pretty-format@^29.7.0: + version "29.7.0" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.7.0.tgz#ca42c758310f365bfa71a0bda0a807160b776812" + integrity sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ== + dependencies: + "@jest/schemas" "^29.6.3" + ansi-styles "^5.0.0" + react-is "^18.0.0" + prettyjson@^1.2.1: version "1.2.5" resolved "https://registry.yarnpkg.com/prettyjson/-/prettyjson-1.2.5.tgz#ef3cfffcc70505c032abc59785884b4027031835"