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nC,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC;aAC7B;iBAAM;gBACL,8CAA8C;gBAC9C,MAAM,KAAK,CAAC;aACb;SACF;KACF;SAAM;QACL,MAAM,IAAI,oBAAW,CACnB,iCAAiC,OAAO,aAAa,EAAE,EACvD,qBAAqB,CACtB,CAAC;KACH;IACD,sBAAsB;IACtB,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { boolish } from 'getenv';\n\nimport { ConfigPlugin, StaticPlugin } from '../Plugin.types';\nimport { assert, PluginError } from '../utils/errors';\nimport {\n assertInternalProjectRoot,\n normalizeStaticPlugin,\n resolveConfigPluginFunction,\n} from '../utils/plugin-resolver';\n\nconst EXPO_DEBUG = boolish('EXPO_DEBUG', false);\nconst EXPO_CONFIG_PLUGIN_VERBOSE_ERRORS = boolish('EXPO_CONFIG_PLUGIN_VERBOSE_ERRORS', false);\n\nfunction isModuleMissingError(name: string, error: Error): boolean {\n // @ts-ignore\n if (error.code === 'MODULE_NOT_FOUND') {\n return true;\n }\n return error.message.includes(`Cannot find module '${name}'`);\n}\n\nfunction isUnexpectedTokenError(error: Error): boolean {\n if (error instanceof SyntaxError) {\n return (\n // These are the most common errors that'll be thrown when a package isn't transpiled correctly.\n !!error.message.match(/Unexpected token/) ||\n !!error.message.match(/Cannot use import statement/)\n );\n }\n return false;\n}\n\n/**\n * Resolves static module plugin and potentially falls back on a provided plugin if the module cannot be resolved\n *\n * @param config\n * @param fallback Plugin with `_resolverError` explaining why the module couldn't be used\n * @param projectRoot optional project root, fallback to _internal.projectRoot. Used for testing.\n * @param _isLegacyPlugin Used to suppress errors thrown by plugins that are applied automatically\n */\nexport const withStaticPlugin: ConfigPlugin<{\n plugin: StaticPlugin | ConfigPlugin | string;\n fallback?: ConfigPlugin<{ _resolverError: Error } & any>;\n projectRoot?: string;\n _isLegacyPlugin?: boolean;\n}> = (config, props) => {\n let projectRoot = props.projectRoot;\n if (!projectRoot) {\n projectRoot = config._internal?.projectRoot;\n assertInternalProjectRoot(projectRoot);\n }\n\n let [pluginResolve, pluginProps] = normalizeStaticPlugin(props.plugin);\n // Ensure no one uses this property by accident.\n assert(\n !pluginProps?._resolverError,\n `Plugin property '_resolverError' is a reserved property of \\`withStaticPlugin\\``\n );\n\n let withPlugin: ConfigPlugin;\n // Function was provided, no need to resolve: [withPlugin, {}]\n if (typeof pluginResolve === 'function') {\n withPlugin = pluginResolve;\n } else if (typeof pluginResolve === 'string') {\n try {\n // Resolve and evaluate plugins.\n withPlugin = resolveConfigPluginFunction(projectRoot, pluginResolve);\n } catch (error) {\n if (EXPO_DEBUG) {\n if (EXPO_CONFIG_PLUGIN_VERBOSE_ERRORS) {\n // Log the error in debug mode for plugins with fallbacks (like the Expo managed plugins).\n console.log(`Error resolving plugin \"${pluginResolve}\"`);\n console.log(error);\n console.log();\n } else {\n const shouldMuteWarning =\n props._isLegacyPlugin &&\n (isModuleMissingError(pluginResolve, error) || isUnexpectedTokenError(error));\n if (!shouldMuteWarning) {\n if (isModuleMissingError(pluginResolve, error)) {\n // Prevent causing log spew for basic resolution errors.\n console.log(`Could not find plugin \"${pluginResolve}\"`);\n } else {\n // Log the error in debug mode for plugins with fallbacks (like the Expo managed plugins).\n console.log(`Error resolving plugin \"${pluginResolve}\"`);\n console.log(error);\n console.log();\n }\n }\n }\n }\n // TODO: Maybe allow for `PluginError`s to be thrown so external plugins can assert invalid options.\n\n // If the static module failed to resolve, attempt to use a fallback.\n // This enables support for built-in plugins with versioned variations living in other packages.\n if (props.fallback) {\n if (!pluginProps) pluginProps = {};\n // Pass this to the fallback plugin for potential warnings about needing to install a versioned package.\n pluginProps._resolverError = error;\n withPlugin = props.fallback;\n } else {\n // If no fallback, throw the resolution error.\n throw error;\n }\n }\n } else {\n throw new PluginError(\n `Plugin is an unexpected type: ${typeof pluginResolve}`,\n 'INVALID_PLUGIN_TYPE'\n );\n }\n // Execute the plugin.\n config = withPlugin(config, pluginProps);\n return config;\n};\n"]}