5ce567a524666c90ac4fadda7ac78228.json 4.86 KB
{"ast":null,"code":"var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.default=deprecate;var _compareVersions=_interopRequireDefault(require(\"compare-versions\"));var _reactNativeAdapter=require(\"@unimodules/react-native-adapter\");var postedWarnings={};function deprecate(library,deprecatedAPI){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var currentVersion=options.currentVersion,versionToRemove=options.versionToRemove,replacement=options.replacement;var code=codeFromLibrary(library);var key=code+\":\"+deprecatedAPI+\":\"+replacement;if(!postedWarnings[key]){postedWarnings[key]=true;}if(!currentVersion||!versionToRemove||(0,_compareVersions.default)(currentVersion,versionToRemove)>=0){var _message=\"`\"+deprecatedAPI+\"` has been removed\";if(versionToRemove){_message=_message+\" as of version \\\"\"+versionToRemove+\"\\\"\";}if(replacement&&replacement.length){_message=_message+\" please migrate to: `\"+replacement+\"`\";}throw new _reactNativeAdapter.CodedError(\"ERR_DEPRECATED_API\",prependLibrary(library,_message));}var message=\"`\"+deprecatedAPI+\"` has been deprecated\";if(replacement&&replacement.length){message=message+\" in favor of `\"+replacement+\"`\";}if(versionToRemove&&versionToRemove.length){message=message+\" and will be removed in version \\\"\"+versionToRemove+\"\\\"\";}console.warn(prependLibrary(library,message));}function prependLibrary(library,message){return library+\": \"+message;}function codeFromLibrary(library){var code=library.replace(/[-.]/g,'_').toUpperCase();return code;}","map":{"version":3,"sources":["../src/deprecate.ts"],"names":[],"mappings":"sKAAA,yEACA,oEAEA,GAAM,CAAA,cAAc,CAA+B,EAAnD,CAKc,QAAU,CAAA,SAAV,CACZ,OADY,CAEZ,aAFY,CAON,IAJN,CAAA,OAIM,2DAAF,EAAE,IAEE,CAAA,cAFF,CAEmD,OAFnD,CAEE,cAFF,CAEkB,eAFlB,CAEmD,OAFnD,CAEkB,eAFlB,CAEmC,WAFnC,CAEmD,OAFnD,CAEmC,WAFnC,CAGN,GAAM,C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ules/react-native-adapter';\n\nconst postedWarnings: { [key: string]: boolean } = {};\n\n/**\n * Used for deprecating values and throwing an error if a given version of Expo has passed.\n */\nexport default function deprecate(\n  library: string,\n  deprecatedAPI: string,\n  options: {\n    replacement?: string;\n    currentVersion?: string;\n    versionToRemove?: string;\n  } = {}\n): void {\n  const { currentVersion, versionToRemove, replacement } = options;\n  const code = codeFromLibrary(library);\n  const key = `${code}:${deprecatedAPI}:${replacement}`;\n  if (!postedWarnings[key]) {\n    postedWarnings[key] = true;\n  }\n\n  if (\n    !currentVersion ||\n    !versionToRemove ||\n    compareVersions(currentVersion, versionToRemove) >= 0\n  ) {\n    let message = `\\`${deprecatedAPI}\\` has been removed`;\n    if (versionToRemove) {\n      message = `${message} as of version \"${versionToRemove}\"`;\n    }\n    if (replacement && replacement.length) {\n      message = `${message} please migrate to: \\`${replacement}\\``;\n    }\n\n    throw new CodedError(`ERR_DEPRECATED_API`, prependLibrary(library, message));\n  }\n\n  let message = `\\`${deprecatedAPI}\\` has been deprecated`;\n  if (replacement && replacement.length) {\n    message = `${message} in favor of \\`${replacement}\\``;\n  }\n  if (versionToRemove && versionToRemove.length) {\n    message = `${message} and will be removed in version \"${versionToRemove}\"`;\n  }\n  console.warn(prependLibrary(library, message));\n}\n\nfunction prependLibrary(library: string, message: string): string {\n  return `${library}: ${message}`;\n}\n\n/**\n * Transform format:\n * Expo.AR -> EXPO_AR\n * expo-ar -> EXPO_AR\n */\nfunction codeFromLibrary(library: string): string {\n  const code = library.replace(/[-.]/g, '_').toUpperCase();\n  return code;\n}\n"],"sourceRoot":""},"metadata":{},"sourceType":"script"}