GT2/Ejectable/node_modules/@expo/metro-config/build/ExpoMetroConfig.js.map

1 line
15 KiB
Plaintext

{"version":3,"file":"ExpoMetroConfig.js","sourceRoot":"","sources":["../src/ExpoMetroConfig.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAkG;AAClG,8CAA6E;AAC7E,kDAA0B;AAC1B,mCAAiC;AAGjC,gDAAwB;AACxB,gEAAuC;AAE1B,QAAA,UAAU,GAAG,gBAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AAEvD,wFAAwF;AAC3E,QAAA,wBAAwB,GAAG,IAAI,MAAM,CAChD;IACE,8CAA8C;IAC9C,6CAA6C;IAC7C,+BAA+B;IAC/B,4BAA4B;IAC5B,iCAAiC;IACjC,2CAA2C;IAC3C,qCAAqC;IACrC,iCAAiC;IACjC,sDAAsD;IACtD,oDAAoD;IACpD,sCAAsC;IACtC,iCAAiC;IACjC,yCAAyC;IACzC,uCAAuC;IACvC,uCAAuC;IACvC,6DAA6D;IAC7D,qCAAqC;IACrC,8CAA8C;IAC9C,mDAAmD;IACnD,kDAAkD;IAClD,oCAAoC;IACpC,kGAAkG;IAClG,iCAAiC;IACjC,iCAAiC;IACjC,2CAA2C;IAC3C,4CAA4C;IAC5C,4CAA4C;IAC5C,iDAAiD;IACjD,sCAAsC;IACtC,gCAAgC;IAChC,mBAAmB;CACpB,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;AAMF,SAAS,0BAA0B,CAAC,WAAmB;IACrD,MAAM,MAAM,GAAG,kBAAS,CAAC,WAAW,EAAE,EAAE,yBAAyB,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3E,OAAO,+BAAsB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,yBAAyB,CAAC,WAAmB;IACpD,OAAO,CACL,sBAAW,CAAC,MAAM,CAAC,WAAW,EAAE,mBAAmB,CAAC;QACpD,sBAAW,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAA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AAED,SAAS,4BAA4B,CAAC,WAAmB;IACvD,MAAM,YAAY,GAAG,sBAAW,CAAC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IACrE,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CACb,iDAAiD;YAC/C,sDAAsD;YACtD,yEAAyE;YACzE,kCAAkC,CACrC,CAAC;KACH;IACD,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { getConfig, getDefaultTarget, isLegacyImportsEnabled, ProjectTarget } from '@expo/config';\nimport { getBareExtensions, getManagedExtensions } from '@expo/config/paths';\nimport chalk from 'chalk';\nimport { boolish } from 'getenv';\nimport { Reporter } from 'metro';\nimport type MetroConfig from 'metro-config';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nexport const EXPO_DEBUG = boolish('EXPO_DEBUG', false);\n\n// Import only the types here, the values will be imported from the project, at runtime.\nexport const INTERNAL_CALLSITES_REGEX = new RegExp(\n [\n '/Libraries/Renderer/implementations/.+\\\\.js$',\n '/Libraries/BatchedBridge/MessageQueue\\\\.js$',\n '/Libraries/YellowBox/.+\\\\.js$',\n '/Libraries/LogBox/.+\\\\.js$',\n '/Libraries/Core/Timers/.+\\\\.js$',\n 'node_modules/react-devtools-core/.+\\\\.js$',\n 'node_modules/react-refresh/.+\\\\.js$',\n 'node_modules/scheduler/.+\\\\.js$',\n // Metro replaces `require()` with a different method,\n // we want to omit this method from the stack trace.\n // This is akin to most React tooling.\n '/metro/.*/polyfills/require.js$',\n // Hide frames related to a fast refresh.\n '/metro/.*/lib/bundle-modules/.+\\\\.js$',\n '/metro/.*/lib/bundle-modules/.+\\\\.js$',\n 'node_modules/react-native/Libraries/Utilities/HMRClient.js$',\n 'node_modules/eventemitter3/index.js',\n 'node_modules/event-target-shim/dist/.+\\\\.js$',\n // Ignore the log forwarder used in the Expo Go app\n '/expo/build/environment/react-native-logs.fx.js$',\n '/expo/build/logs/RemoteConsole.js$',\n // Improve errors thrown by invariant (ex: `Invariant Violation: \"main\" has not been registered`).\n 'node_modules/invariant/.+\\\\.js$',\n // Remove babel runtime additions\n 'node_modules/regenerator-runtime/.+\\\\.js$',\n // Remove react native setImmediate ponyfill\n 'node_modules/promise/setimmediate/.+\\\\.js$',\n // Babel helpers that implement language features\n 'node_modules/@babel/runtime/.+\\\\.js$',\n // Block native code invocations\n `\\\\[native code\\\\]`,\n ].join('|')\n);\n\nexport interface DefaultConfigOptions {\n target?: ProjectTarget;\n}\n\nfunction readIsLegacyImportsEnabled(projectRoot: string): boolean {\n const config = getConfig(projectRoot, { skipSDKVersionRequirement: true });\n return isLegacyImportsEnabled(config.exp);\n}\n\nfunction getProjectBabelConfigFile(projectRoot: string): string | undefined {\n return (\n resolveFrom.silent(projectRoot, './babel.config.js') ||\n resolveFrom.silent(projectRoot, './.babelrc') ||\n resolveFrom.silent(projectRoot, './.babelrc.js')\n );\n}\n\nexport function getDefaultConfig(\n projectRoot: string,\n options: DefaultConfigOptions = {}\n): MetroConfig.InputConfigT {\n const MetroConfig = importMetroConfigFromProject(projectRoot);\n\n const reactNativePath = path.dirname(resolveFrom(projectRoot, 'react-native/package.json'));\n\n try {\n // Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.\n // This hack is used because there doesn't appear to be anyway to resolve\n // `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).\n const babelPresetFbjsPath = resolveFrom(projectRoot, 'babel-preset-fbjs/package.json');\n process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);\n } catch {\n // noop -- falls back to a hardcoded value.\n }\n\n let hashAssetFilesPath;\n try {\n hashAssetFilesPath = resolveFrom(projectRoot, 'expo-asset/tools/hashAssetFiles');\n } catch {\n // TODO: we should warn/throw an error if the user has expo-updates installed but does not\n // have hashAssetFiles available, or if the user is in managed workflow and does not have\n // hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,\n // it is not needed\n }\n\n const isLegacy = readIsLegacyImportsEnabled(projectRoot);\n // Deprecated -- SDK 41 --\n if (options.target) {\n if (!isLegacy) {\n console.warn(\n chalk.yellow(\n `The target option is deprecated. Learn more: http://expo.fyi/expo-extension-migration`\n )\n );\n delete options.target;\n }\n } else if (process.env.EXPO_TARGET) {\n console.error(\n 'EXPO_TARGET is deprecated. Learn more: http://expo.fyi/expo-extension-migration'\n );\n if (isLegacy) {\n // EXPO_TARGET is used by @expo/metro-config to determine the target when getDefaultConfig is\n // called from metro.config.js.\n // @ts-ignore\n options.target = process.env.EXPO_TARGET;\n }\n } else if (isLegacy) {\n // Fall back to guessing based on the project structure in legacy mode.\n options.target = getDefaultTarget(projectRoot);\n }\n\n if (!options.target) {\n // Default to bare -- no .expo extension.\n options.target = 'bare';\n }\n // End deprecated -- SDK 41 --\n\n const { target } = options;\n if (!(target === 'managed' || target === 'bare')) {\n throw new Error(\n `Invalid target: '${target}'. Debug info: \\n${JSON.stringify(\n {\n 'options.target': options.target,\n default: getDefaultTarget(projectRoot),\n },\n null,\n 2\n )}`\n );\n }\n const sourceExtsConfig = { isTS: true, isReact: true, isModern: false };\n const sourceExts =\n target === 'bare'\n ? getBareExtensions([], sourceExtsConfig)\n : getManagedExtensions([], sourceExtsConfig);\n\n const babelConfigPath = getProjectBabelConfigFile(projectRoot);\n const isCustomBabelConfigDefined = !!babelConfigPath;\n\n if (EXPO_DEBUG) {\n console.log();\n console.log(`Expo Metro config:`);\n console.log(`- Bundler target: ${target}`);\n console.log(`- Legacy: ${isLegacy}`);\n console.log(`- Extensions: ${sourceExts.join(', ')}`);\n console.log(`- React Native: ${reactNativePath}`);\n console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);\n console.log();\n }\n const {\n // Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.\n // This prints a giant React logo which is less accessible to users on smaller terminals.\n reporter,\n ...metroDefaultValues\n } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);\n\n // Merge in the default config from Metro here, even though loadConfig uses it as defaults.\n // This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.\n return MetroConfig.mergeConfig(metroDefaultValues, {\n resolver: {\n resolverMainFields: ['react-native', 'browser', 'main'],\n platforms: ['ios', 'android', 'native'],\n sourceExts,\n },\n serializer: {\n getModulesRunBeforeMainModule: () => [\n require.resolve(path.join(reactNativePath, 'Libraries/Core/InitializeCore')),\n // TODO: Bacon: load Expo side-effects\n ],\n getPolyfills: () => require(path.join(reactNativePath, 'rn-get-polyfills'))(),\n },\n server: {\n port: Number(process.env.RCT_METRO_PORT) || 8081,\n },\n symbolicator: {\n customizeFrame: frame => {\n let collapse = Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file));\n\n if (!collapse) {\n // This represents the first frame of the stacktrace.\n // Often this looks like: `__r(0);`.\n // The URL will also be unactionable in the app and therefore not very useful to the developer.\n if (\n frame.column === 3 &&\n frame.methodName === 'global code' &&\n frame.file?.match(/^https?:\\/\\//g)\n ) {\n collapse = true;\n }\n }\n\n return { ...(frame || {}), collapse };\n },\n },\n transformer: {\n allowOptionalDependencies: true,\n babelTransformerPath: isCustomBabelConfigDefined\n ? // If the user defined a babel config file in their project,\n // then use the default transformer.\n require.resolve('metro-react-native-babel-transformer')\n : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.\n require.resolve('./metro-expo-babel-transformer'),\n assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',\n assetPlugins: hashAssetFilesPath ? [hashAssetFilesPath] : undefined,\n },\n });\n}\n\nexport interface LoadOptions {\n config?: string;\n maxWorkers?: number;\n port?: number;\n reporter?: Reporter;\n resetCache?: boolean;\n target?: ProjectTarget;\n}\n\nexport async function loadAsync(\n projectRoot: string,\n { reporter, target, ...metroOptions }: LoadOptions = {}\n): Promise<MetroConfig.ConfigT> {\n let defaultConfig = getDefaultConfig(projectRoot, { target });\n if (reporter) {\n defaultConfig = { ...defaultConfig, reporter };\n }\n const MetroConfig = importMetroConfigFromProject(projectRoot);\n return await MetroConfig.loadConfig(\n { cwd: projectRoot, projectRoot, ...metroOptions },\n defaultConfig\n );\n}\n\nfunction importMetroConfigFromProject(projectRoot: string): typeof MetroConfig {\n const resolvedPath = resolveFrom.silent(projectRoot, 'metro-config');\n if (!resolvedPath) {\n throw new Error(\n 'Missing package \"metro-config\" in the project. ' +\n 'This usually means `react-native` is not installed. ' +\n 'Please verify that dependencies in package.json include \"react-native\" ' +\n 'and run `yarn` or `npm install`.'\n );\n }\n return require(resolvedPath);\n}\n"]}