@expo/metro-config 0.3.13 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ExpoMetroConfig.js +15 -15
- package/build/ExpoMetroConfig.js.map +1 -1
- package/build/getModulesPaths.js +1 -1
- package/build/getModulesPaths.js.map +1 -1
- package/build/getWatchFolders.js +3 -3
- package/build/getWatchFolders.js.map +1 -1
- package/build/transformer/createExoticTransformer.js +7 -7
- package/build/transformer/createExoticTransformer.js.map +1 -1
- package/build/transformer/createMultiRuleTransformer.js +6 -6
- package/build/transformer/createMultiRuleTransformer.js.map +1 -1
- package/build/transformer/generateFunctionMap.js +1 -1
- package/build/transformer/generateFunctionMap.js.map +1 -1
- package/build/transformer/getBabelConfig.js +1 -1
- package/build/transformer/getBabelConfig.js.map +1 -1
- package/build/transformer/getCacheKey.js +1 -1
- package/build/transformer/getCacheKey.js.map +1 -1
- package/build/transformer/metro-expo-exotic-babel-transformer.js +1 -1
- package/build/transformer/metro-expo-exotic-babel-transformer.js.map +1 -1
- package/package.json +3 -3
package/build/ExpoMetroConfig.js
CHANGED
|
@@ -14,8 +14,8 @@ const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
|
14
14
|
const getModulesPaths_1 = require("./getModulesPaths");
|
|
15
15
|
const getWatchFolders_1 = require("./getWatchFolders");
|
|
16
16
|
const importMetroFromProject_1 = require("./importMetroFromProject");
|
|
17
|
-
exports.EXPO_DEBUG = getenv_1.boolish('EXPO_DEBUG', false);
|
|
18
|
-
const EXPO_USE_EXOTIC = getenv_1.boolish('EXPO_USE_EXOTIC', false);
|
|
17
|
+
exports.EXPO_DEBUG = (0, getenv_1.boolish)('EXPO_DEBUG', false);
|
|
18
|
+
const EXPO_USE_EXOTIC = (0, getenv_1.boolish)('EXPO_USE_EXOTIC', false);
|
|
19
19
|
// Import only the types here, the values will be imported from the project, at runtime.
|
|
20
20
|
exports.INTERNAL_CALLSITES_REGEX = new RegExp([
|
|
21
21
|
'/Libraries/Renderer/implementations/.+\\.js$',
|
|
@@ -52,8 +52,8 @@ exports.INTERNAL_CALLSITES_REGEX = new RegExp([
|
|
|
52
52
|
`\\[native code\\]`,
|
|
53
53
|
].join('|'));
|
|
54
54
|
function readIsLegacyImportsEnabled(projectRoot) {
|
|
55
|
-
const config = config_1.getConfig(projectRoot, { skipSDKVersionRequirement: true });
|
|
56
|
-
return config_1.isLegacyImportsEnabled(config.exp);
|
|
55
|
+
const config = (0, config_1.getConfig)(projectRoot, { skipSDKVersionRequirement: true });
|
|
56
|
+
return (0, config_1.isLegacyImportsEnabled)(config.exp);
|
|
57
57
|
}
|
|
58
58
|
function getProjectBabelConfigFile(projectRoot) {
|
|
59
59
|
return (resolve_from_1.default.silent(projectRoot, './babel.config.js') ||
|
|
@@ -64,7 +64,7 @@ function getAssetPlugins(projectRoot) {
|
|
|
64
64
|
const assetPlugins = [];
|
|
65
65
|
let hashAssetFilesPath;
|
|
66
66
|
try {
|
|
67
|
-
hashAssetFilesPath = resolve_from_1.default(projectRoot, 'expo-asset/tools/hashAssetFiles');
|
|
67
|
+
hashAssetFilesPath = (0, resolve_from_1.default)(projectRoot, 'expo-asset/tools/hashAssetFiles');
|
|
68
68
|
}
|
|
69
69
|
catch {
|
|
70
70
|
// TODO: we should warn/throw an error if the user has expo-updates installed but does not
|
|
@@ -84,13 +84,13 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
84
84
|
hasWarnedAboutExotic = true;
|
|
85
85
|
console.log(chalk_1.default.gray(`\u203A Unstable feature ${chalk_1.default.bold `EXPO_USE_EXOTIC`} is enabled. Bundling may not work as expected, and is subject to breaking changes.`));
|
|
86
86
|
}
|
|
87
|
-
const MetroConfig = importMetroFromProject_1.importMetroConfigFromProject(projectRoot);
|
|
88
|
-
const reactNativePath = path_1.default.dirname(resolve_from_1.default(projectRoot, 'react-native/package.json'));
|
|
87
|
+
const MetroConfig = (0, importMetroFromProject_1.importMetroConfigFromProject)(projectRoot);
|
|
88
|
+
const reactNativePath = path_1.default.dirname((0, resolve_from_1.default)(projectRoot, 'react-native/package.json'));
|
|
89
89
|
try {
|
|
90
90
|
// Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.
|
|
91
91
|
// This hack is used because there doesn't appear to be anyway to resolve
|
|
92
92
|
// `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).
|
|
93
|
-
const babelPresetFbjsPath = resolve_from_1.default(projectRoot, 'babel-preset-fbjs/package.json');
|
|
93
|
+
const babelPresetFbjsPath = (0, resolve_from_1.default)(projectRoot, 'babel-preset-fbjs/package.json');
|
|
94
94
|
process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);
|
|
95
95
|
}
|
|
96
96
|
catch {
|
|
@@ -115,7 +115,7 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
115
115
|
}
|
|
116
116
|
else if (isLegacy) {
|
|
117
117
|
// Fall back to guessing based on the project structure in legacy mode.
|
|
118
|
-
options.target = config_1.getDefaultTarget(projectRoot);
|
|
118
|
+
options.target = (0, config_1.getDefaultTarget)(projectRoot);
|
|
119
119
|
}
|
|
120
120
|
if (!options.target) {
|
|
121
121
|
// Default to bare -- no .expo extension.
|
|
@@ -126,13 +126,13 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
126
126
|
if (!(target === 'managed' || target === 'bare')) {
|
|
127
127
|
throw new Error(`Invalid target: '${target}'. Debug info: \n${JSON.stringify({
|
|
128
128
|
'options.target': options.target,
|
|
129
|
-
default: config_1.getDefaultTarget(projectRoot),
|
|
129
|
+
default: (0, config_1.getDefaultTarget)(projectRoot),
|
|
130
130
|
}, null, 2)}`);
|
|
131
131
|
}
|
|
132
132
|
const sourceExtsConfig = { isTS: true, isReact: true, isModern: false };
|
|
133
133
|
const sourceExts = target === 'bare'
|
|
134
|
-
? paths_1.getBareExtensions([], sourceExtsConfig)
|
|
135
|
-
: paths_1.getManagedExtensions([], sourceExtsConfig);
|
|
134
|
+
? (0, paths_1.getBareExtensions)([], sourceExtsConfig)
|
|
135
|
+
: (0, paths_1.getManagedExtensions)([], sourceExtsConfig);
|
|
136
136
|
if (isExotic) {
|
|
137
137
|
// Add support for cjs (without platform extensions).
|
|
138
138
|
sourceExts.push('cjs');
|
|
@@ -146,9 +146,9 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
146
146
|
resolverMainFields.push('react-native');
|
|
147
147
|
}
|
|
148
148
|
resolverMainFields.push('browser', 'main');
|
|
149
|
-
const watchFolders = getWatchFolders_1.getWatchFolders(projectRoot);
|
|
149
|
+
const watchFolders = (0, getWatchFolders_1.getWatchFolders)(projectRoot);
|
|
150
150
|
// TODO: nodeModulesPaths does not work with the new Node.js package.json exports API, this causes packages like uuid to fail. Disabling for now.
|
|
151
|
-
const nodeModulesPaths = getModulesPaths_1.getModulesPaths(projectRoot);
|
|
151
|
+
const nodeModulesPaths = (0, getModulesPaths_1.getModulesPaths)(projectRoot);
|
|
152
152
|
if (exports.EXPO_DEBUG) {
|
|
153
153
|
console.log();
|
|
154
154
|
console.log(`Expo Metro config:`);
|
|
@@ -231,7 +231,7 @@ async function loadAsync(projectRoot, { reporter, target, ...metroOptions } = {}
|
|
|
231
231
|
if (reporter) {
|
|
232
232
|
defaultConfig = { ...defaultConfig, reporter };
|
|
233
233
|
}
|
|
234
|
-
const MetroConfig = importMetroFromProject_1.importMetroConfigFromProject(projectRoot);
|
|
234
|
+
const MetroConfig = (0, importMetroFromProject_1.importMetroConfigFromProject)(projectRoot);
|
|
235
235
|
return await MetroConfig.loadConfig({ cwd: projectRoot, projectRoot, ...metroOptions }, defaultConfig);
|
|
236
236
|
}
|
|
237
237
|
exports.loadAsync = loadAsync;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoMetroConfig.js","sourceRoot":"","sources":["../src/ExpoMetroConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,yCAAkG;AAClG,8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WAAW,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,IAAI,QAAQ,EAAE;QACZ,aAAa,GAAG,EAAE,GAAG,aAAa,EAAE,QAAQ,EAAE,CAAC;KAChD;IACD,MAAM,WAAW,GAAG,qDAA4B,CAAC,WAAW,CAAC,CAAC;IAC9D,OAAO,MAAM,WAAW,CAAC,UAAU,CACjC,EAAE,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,YAAY,EAAE,EAClD,aAAa,CACd,CAAC;AACJ,CAAC;AAbD,8BAaC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport { 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\nimport { getModulesPaths } from './getModulesPaths';\nimport { getWatchFolders } from './getWatchFolders';\nimport { importMetroConfigFromProject } from './importMetroFromProject';\n\nexport const EXPO_DEBUG = boolish('EXPO_DEBUG', false);\nconst EXPO_USE_EXOTIC = boolish('EXPO_USE_EXOTIC', 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 '/src/environment/react-native-logs.fx.ts$',\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 mode?: 'exotic';\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\nfunction getAssetPlugins(projectRoot: string): string[] {\n const assetPlugins: string[] = [];\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 if (hashAssetFilesPath) {\n assetPlugins.push(hashAssetFilesPath);\n }\n\n return assetPlugins;\n}\n\nlet hasWarnedAboutExotic = false;\n\nexport function getDefaultConfig(\n projectRoot: string,\n options: DefaultConfigOptions = {}\n): MetroConfig.InputConfigT {\n const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;\n\n if (isExotic && !hasWarnedAboutExotic) {\n hasWarnedAboutExotic = true;\n console.log(\n chalk.gray(\n `\\u203A Unstable feature ${chalk.bold`EXPO_USE_EXOTIC`} is enabled. Bundling may not work as expected, and is subject to breaking changes.`\n )\n );\n }\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 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 if (isExotic) {\n // Add support for cjs (without platform extensions).\n sourceExts.push('cjs');\n }\n\n const babelConfigPath = getProjectBabelConfigFile(projectRoot);\n const isCustomBabelConfigDefined = !!babelConfigPath;\n\n const resolverMainFields: string[] = [];\n\n // Disable `react-native` in exotic mode, since library authors\n // use it to ship raw application code to the project.\n if (!isExotic) {\n resolverMainFields.push('react-native');\n }\n resolverMainFields.push('browser', 'main');\n\n const watchFolders = getWatchFolders(projectRoot);\n // TODO: nodeModulesPaths does not work with the new Node.js package.json exports API, this causes packages like uuid to fail. Disabling for now.\n const nodeModulesPaths = getModulesPaths(projectRoot);\n if (EXPO_DEBUG) {\n console.log();\n console.log(`Expo Metro config:`);\n try {\n console.log(`- Version: ${require('../package.json').version}`);\n } catch {}\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(`- Resolver Fields: ${resolverMainFields.join(', ')}`);\n console.log(`- Watch Folders: ${watchFolders.join(', ')}`);\n console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`);\n console.log(`- Exotic: ${isExotic}`);\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 watchFolders,\n resolver: {\n resolverMainFields,\n platforms: ['ios', 'android', 'native', 'testing'],\n assetExts: metroDefaultValues.resolver.assetExts.filter(\n assetExt => !sourceExts.includes(assetExt)\n ),\n sourceExts,\n nodeModulesPaths,\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: isExotic\n ? require.resolve('./transformer/metro-expo-exotic-babel-transformer')\n : isCustomBabelConfigDefined\n ? // If the user defined a babel config file in their project,\n // then use the default transformer.\n // Try to use the project copy before falling back on the global version\n resolveFrom.silent(projectRoot, 'metro-react-native-babel-transformer')\n : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.\n require.resolve('./transformer/metro-expo-babel-transformer'),\n assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',\n assetPlugins: getAssetPlugins(projectRoot),\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"]}
|
|
1
|
+
{"version":3,"file":"ExpoMetroConfig.js","sourceRoot":"","sources":["../src/ExpoMetroConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,yCAAkG;AAClG,8CAA6E;AAC7E,kDAA0B;AAC1B,mCAAiC;AAGjC,gDAAwB;AACxB,gEAAuC;AAEvC,uDAAoD;AACpD,uDAAoD;AACpD,qEAAwE;AAE3D,QAAA,UAAU,GAAG,IAAA,gBAAO,EAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACvD,MAAM,eAAe,GAAG,IAAA,gBAAO,EAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;AAE1D,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,2CAA2C;IAC3C,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;AAOF,SAAS,0BAA0B,CAAC,WAAmB;IACrD,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC,WAAW,EAAE,EAAE,yBAAyB,EAAE,IAAI,EAA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CAAsC,CAAC;oBACzE,CAAC,CAAC,6FAA6F;wBAC7F,OAAO,CAAC,OAAO,CAAC,4CAA4C,CAAC;YACjE,iBAAiB,EAAE,4CAA4C;YAC/D,YAAY,EAAE,eAAe,CAAC,WAAW,CAAC;SAC3C;KACF,CAAC,CAAC;AACL,CAAC;AArLD,4CAqLC;AAWM,KAAK,UAAU,SAAS,CAC7B,WAAmB,EACnB,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,YAAY,KAAkB,EAAE;IAEvD,IAAI,aAAa,GAAG,gBAAgB,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,IAAI,QAAQ,EAAE;QACZ,aAAa,GAAG,EAAE,GAAG,aAAa,EAAE,QAAQ,EAAE,CAAC;KAChD;IACD,MAAM,WAAW,GAAG,IAAA,qDAA4B,EAAC,WAAW,CAAC,CAAC;IAC9D,OAAO,MAAM,WAAW,CAAC,UAAU,CACjC,EAAE,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,YAAY,EAAE,EAClD,aAAa,CACd,CAAC;AACJ,CAAC;AAbD,8BAaC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport { 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\nimport { getModulesPaths } from './getModulesPaths';\nimport { getWatchFolders } from './getWatchFolders';\nimport { importMetroConfigFromProject } from './importMetroFromProject';\n\nexport const EXPO_DEBUG = boolish('EXPO_DEBUG', false);\nconst EXPO_USE_EXOTIC = boolish('EXPO_USE_EXOTIC', 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 '/src/environment/react-native-logs.fx.ts$',\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 mode?: 'exotic';\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\nfunction getAssetPlugins(projectRoot: string): string[] {\n const assetPlugins: string[] = [];\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 if (hashAssetFilesPath) {\n assetPlugins.push(hashAssetFilesPath);\n }\n\n return assetPlugins;\n}\n\nlet hasWarnedAboutExotic = false;\n\nexport function getDefaultConfig(\n projectRoot: string,\n options: DefaultConfigOptions = {}\n): MetroConfig.InputConfigT {\n const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;\n\n if (isExotic && !hasWarnedAboutExotic) {\n hasWarnedAboutExotic = true;\n console.log(\n chalk.gray(\n `\\u203A Unstable feature ${chalk.bold`EXPO_USE_EXOTIC`} is enabled. Bundling may not work as expected, and is subject to breaking changes.`\n )\n );\n }\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 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 if (isExotic) {\n // Add support for cjs (without platform extensions).\n sourceExts.push('cjs');\n }\n\n const babelConfigPath = getProjectBabelConfigFile(projectRoot);\n const isCustomBabelConfigDefined = !!babelConfigPath;\n\n const resolverMainFields: string[] = [];\n\n // Disable `react-native` in exotic mode, since library authors\n // use it to ship raw application code to the project.\n if (!isExotic) {\n resolverMainFields.push('react-native');\n }\n resolverMainFields.push('browser', 'main');\n\n const watchFolders = getWatchFolders(projectRoot);\n // TODO: nodeModulesPaths does not work with the new Node.js package.json exports API, this causes packages like uuid to fail. Disabling for now.\n const nodeModulesPaths = getModulesPaths(projectRoot);\n if (EXPO_DEBUG) {\n console.log();\n console.log(`Expo Metro config:`);\n try {\n console.log(`- Version: ${require('../package.json').version}`);\n } catch {}\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(`- Resolver Fields: ${resolverMainFields.join(', ')}`);\n console.log(`- Watch Folders: ${watchFolders.join(', ')}`);\n console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`);\n console.log(`- Exotic: ${isExotic}`);\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 watchFolders,\n resolver: {\n resolverMainFields,\n platforms: ['ios', 'android', 'native', 'testing'],\n assetExts: metroDefaultValues.resolver.assetExts.filter(\n assetExt => !sourceExts.includes(assetExt)\n ),\n sourceExts,\n nodeModulesPaths,\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: isExotic\n ? require.resolve('./transformer/metro-expo-exotic-babel-transformer')\n : isCustomBabelConfigDefined\n ? // If the user defined a babel config file in their project,\n // then use the default transformer.\n // Try to use the project copy before falling back on the global version\n resolveFrom.silent(projectRoot, 'metro-react-native-babel-transformer')\n : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.\n require.resolve('./transformer/metro-expo-babel-transformer'),\n assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',\n assetPlugins: getAssetPlugins(projectRoot),\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"]}
|
package/build/getModulesPaths.js
CHANGED
|
@@ -10,7 +10,7 @@ function getModulesPaths(projectRoot) {
|
|
|
10
10
|
const paths = [];
|
|
11
11
|
// Only add the project root if it's not the current working directory
|
|
12
12
|
// this minimizes the chance of Metro resolver breaking on new Node.js versions.
|
|
13
|
-
const workspaceRoot = find_yarn_workspace_root_1.default(path_1.default.resolve(projectRoot)); // Absolute path or null
|
|
13
|
+
const workspaceRoot = (0, find_yarn_workspace_root_1.default)(path_1.default.resolve(projectRoot)); // Absolute path or null
|
|
14
14
|
if (workspaceRoot) {
|
|
15
15
|
paths.push(path_1.default.resolve(projectRoot));
|
|
16
16
|
paths.push(path_1.default.resolve(workspaceRoot, 'node_modules'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getModulesPaths.js","sourceRoot":"","sources":["../src/getModulesPaths.ts"],"names":[],"mappings":";;;;;;AAAA,wFAAyD;AACzD,gDAAwB;AAExB,SAAgB,eAAe,CAAC,WAAmB;IACjD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,sEAAsE;IACtE,gFAAgF;IAChF,MAAM,aAAa,GAAG,kCAAiB,
|
|
1
|
+
{"version":3,"file":"getModulesPaths.js","sourceRoot":"","sources":["../src/getModulesPaths.ts"],"names":[],"mappings":";;;;;;AAAA,wFAAyD;AACzD,gDAAwB;AAExB,SAAgB,eAAe,CAAC,WAAmB;IACjD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,sEAAsE;IACtE,gFAAgF;IAChF,MAAM,aAAa,GAAG,IAAA,kCAAiB,EAAC,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,wBAAwB;IAC5F,IAAI,aAAa,EAAE;QACjB,KAAK,CAAC,IAAI,CAAC,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;QACtC,KAAK,CAAC,IAAI,CAAC,cAAI,CAAC,OAAO,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;KACzD;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAZD,0CAYC","sourcesContent":["import findWorkspaceRoot from 'find-yarn-workspace-root';\nimport path from 'path';\n\nexport function getModulesPaths(projectRoot: string): string[] {\n const paths: string[] = [];\n\n // Only add the project root if it's not the current working directory\n // this minimizes the chance of Metro resolver breaking on new Node.js versions.\n const workspaceRoot = findWorkspaceRoot(path.resolve(projectRoot)); // Absolute path or null\n if (workspaceRoot) {\n paths.push(path.resolve(projectRoot));\n paths.push(path.resolve(workspaceRoot, 'node_modules'));\n }\n\n return paths;\n}\n"]}
|
package/build/getWatchFolders.js
CHANGED
|
@@ -17,7 +17,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
17
17
|
function globAllPackageJsonPaths(workspaceProjectRoot, linkedPackages) {
|
|
18
18
|
return linkedPackages
|
|
19
19
|
.map(glob => {
|
|
20
|
-
return glob_1.sync(path_1.default.join(glob, 'package.json').replace(/\\/g, '/'), {
|
|
20
|
+
return (0, glob_1.sync)(path_1.default.join(glob, 'package.json').replace(/\\/g, '/'), {
|
|
21
21
|
cwd: workspaceProjectRoot,
|
|
22
22
|
absolute: true,
|
|
23
23
|
ignore: ['**/@(Carthage|Pods|node_modules)/**'],
|
|
@@ -41,7 +41,7 @@ function getWorkspacePackagesArray({ workspaces }) {
|
|
|
41
41
|
if (Array.isArray(workspaces)) {
|
|
42
42
|
return workspaces;
|
|
43
43
|
}
|
|
44
|
-
assert_1.default(workspaces === null || workspaces === void 0 ? void 0 : workspaces.packages, 'Could not find a `workspaces` object in the root package.json');
|
|
44
|
+
(0, assert_1.default)(workspaces === null || workspaces === void 0 ? void 0 : workspaces.packages, 'Could not find a `workspaces` object in the root package.json');
|
|
45
45
|
return workspaces.packages;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
@@ -68,7 +68,7 @@ exports.resolveAllWorkspacePackageJsonPaths = resolveAllWorkspacePackageJsonPath
|
|
|
68
68
|
* @returns list of node module paths to watch in Metro bundler, ex: `['/Users/me/app/node_modules/', '/Users/me/app/apps/my-app/', '/Users/me/app/packages/my-package/']`
|
|
69
69
|
*/
|
|
70
70
|
function getWatchFolders(projectRoot) {
|
|
71
|
-
const workspaceRoot = find_yarn_workspace_root_1.default(path_1.default.resolve(projectRoot));
|
|
71
|
+
const workspaceRoot = (0, find_yarn_workspace_root_1.default)(path_1.default.resolve(projectRoot));
|
|
72
72
|
// Rely on default behavior in standard projects.
|
|
73
73
|
if (!workspaceRoot) {
|
|
74
74
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWatchFolders.js","sourceRoot":"","sources":["../src/getWatchFolders.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAuC;AACvC,oDAA4B;AAC5B,wFAAyD;AACzD,+BAAwC;AACxC,gDAAwB;AAExB;;;;GAIG;AACH,SAAgB,uBAAuB,CACrC,oBAA4B,EAC5B,cAAwB;IAExB,OAAO,cAAc;SAClB,GAAG,CAAC,IAAI,CAAC,EAAE;QACV,OAAO,WAAQ,
|
|
1
|
+
{"version":3,"file":"getWatchFolders.js","sourceRoot":"","sources":["../src/getWatchFolders.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAuC;AACvC,oDAA4B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AAG,mBAAQ,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAE/D,6FAA6F;QAC7F,MAAM,QAAQ,GAAG,yBAAyB,CAAC,eAAe,CAAC,CAAC;QAE5D,sDAAsD;QACtD,OAAO,uBAAuB,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;KAChE;IAAC,MAAM;QACN,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAdD,kFAcC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,WAAmB;IACjD,MAAM,aAAa,GAAG,IAAA,kCAAiB,EAAC,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,iDAAiD;IACjD,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO,EAAE,CAAC;KACX;IAED,MAAM,QAAQ,GAAG,mCAAmC,CAAC,aAAa,CAAC,CAAC;IACpE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;QACpB,OAAO,EAAE,CAAC;KACX;IAED,OAAO,WAAW,CAAC;QACjB,cAAI,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC;QACxC,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC;AAhBD,0CAgBC;AAED,SAAS,WAAW,CAAC,KAAe;IAClC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import JsonFile from '@expo/json-file';\nimport assert from 'assert';\nimport findWorkspaceRoot from 'find-yarn-workspace-root';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\n\n/**\n * @param workspaceProjectRoot Root file path for the yarn workspace\n * @param linkedPackages List of folders that contain linked node modules, ex: `['packages/*', 'apps/*']`\n * @returns List of valid package.json file paths, ex: `['/Users/me/app/apps/my-app/package.json', '/Users/me/app/packages/my-package/package.json']`\n */\nexport function globAllPackageJsonPaths(\n workspaceProjectRoot: string,\n linkedPackages: string[]\n): string[] {\n return linkedPackages\n .map(glob => {\n return globSync(path.join(glob, 'package.json').replace(/\\\\/g, '/'), {\n cwd: workspaceProjectRoot,\n absolute: true,\n ignore: ['**/@(Carthage|Pods|node_modules)/**'],\n }).map(pkgPath => {\n try {\n JsonFile.read(pkgPath);\n return pkgPath;\n } catch {\n // Skip adding path if the package.json is invalid or cannot be read.\n }\n return null;\n });\n })\n .flat()\n .filter(Boolean)\n .map(p => path.join(p as string));\n}\n\nfunction getWorkspacePackagesArray({ workspaces }: any): string[] {\n if (Array.isArray(workspaces)) {\n return workspaces;\n }\n\n assert(workspaces?.packages, 'Could not find a `workspaces` object in the root package.json');\n\n return workspaces.packages;\n}\n\n/**\n * @param workspaceProjectRoot root file path for a yarn workspace.\n * @returns list of package.json file paths that are linked to the yarn workspace.\n */\nexport function resolveAllWorkspacePackageJsonPaths(workspaceProjectRoot: string) {\n try {\n const rootPackageJsonFilePath = path.join(workspaceProjectRoot, 'package.json');\n // Could throw if package.json is invalid.\n const rootPackageJson = JsonFile.read(rootPackageJsonFilePath);\n\n // Extract the \"packages\" array or use \"workspaces\" as packages array (yarn workspaces spec).\n const packages = getWorkspacePackagesArray(rootPackageJson);\n\n // Glob all package.json files and return valid paths.\n return globAllPackageJsonPaths(workspaceProjectRoot, packages);\n } catch {\n return [];\n }\n}\n\n/**\n * @param projectRoot file path to app's project root\n * @returns list of node module paths to watch in Metro bundler, ex: `['/Users/me/app/node_modules/', '/Users/me/app/apps/my-app/', '/Users/me/app/packages/my-package/']`\n */\nexport function getWatchFolders(projectRoot: string): string[] {\n const workspaceRoot = findWorkspaceRoot(path.resolve(projectRoot));\n // Rely on default behavior in standard projects.\n if (!workspaceRoot) {\n return [];\n }\n\n const packages = resolveAllWorkspacePackageJsonPaths(workspaceRoot);\n if (!packages.length) {\n return [];\n }\n\n return uniqueItems([\n path.join(workspaceRoot, 'node_modules'),\n ...packages.map(pkg => path.dirname(pkg)),\n ]);\n}\n\nfunction uniqueItems(items: string[]): string[] {\n return [...new Set(items)];\n}\n"]}
|
|
@@ -24,10 +24,10 @@ function createExoticTransformer({ nodeModulesPaths, transpileModules, }) {
|
|
|
24
24
|
nodeModulesPaths = ['node_modules'];
|
|
25
25
|
}
|
|
26
26
|
// Match any node modules, or monorepo module.
|
|
27
|
-
const nodeModuleMatcher = createMatcher_1.createModuleMatcher({ folders: nodeModulesPaths, moduleIds: [] });
|
|
27
|
+
const nodeModuleMatcher = (0, createMatcher_1.createModuleMatcher)({ folders: nodeModulesPaths, moduleIds: [] });
|
|
28
28
|
// Match node modules which are so oddly written that we must
|
|
29
29
|
// transpile them with every possible option (most expensive).
|
|
30
|
-
const impossibleNodeModuleMatcher = createMatcher_1.createModuleMatcher({
|
|
30
|
+
const impossibleNodeModuleMatcher = (0, createMatcher_1.createModuleMatcher)({
|
|
31
31
|
moduleIds: [
|
|
32
32
|
// victory is too wild
|
|
33
33
|
// SyntaxError in ../../node_modules/victory-native/lib/components/victory-primitives/bar.js: Missing semicolon. (9:1)
|
|
@@ -38,7 +38,7 @@ function createExoticTransformer({ nodeModulesPaths, transpileModules, }) {
|
|
|
38
38
|
],
|
|
39
39
|
folders: nodeModulesPaths,
|
|
40
40
|
});
|
|
41
|
-
const transform = createMultiRuleTransformer_1.createMultiRuleTransformer({
|
|
41
|
+
const transform = (0, createMultiRuleTransformer_1.createMultiRuleTransformer)({
|
|
42
42
|
// Specify which rules to use on a per-file basis, basically
|
|
43
43
|
// this is used to determine which modules are node modules, and which are application code.
|
|
44
44
|
getRuleType({ filename }) {
|
|
@@ -54,7 +54,7 @@ function createExoticTransformer({ nodeModulesPaths, transpileModules, }) {
|
|
|
54
54
|
{
|
|
55
55
|
name: 'bob',
|
|
56
56
|
type: 'module',
|
|
57
|
-
test: createMatcher_1.createModuleMatcher({ moduleIds: ['.*/lib/commonjs/'], folders: nodeModulesPaths }),
|
|
57
|
+
test: (0, createMatcher_1.createModuleMatcher)({ moduleIds: ['.*/lib/commonjs/'], folders: nodeModulesPaths }),
|
|
58
58
|
transform: createMultiRuleTransformer_1.loaders.passthroughModule,
|
|
59
59
|
warn: true,
|
|
60
60
|
},
|
|
@@ -62,7 +62,7 @@ function createExoticTransformer({ nodeModulesPaths, transpileModules, }) {
|
|
|
62
62
|
{
|
|
63
63
|
name: 'react-native',
|
|
64
64
|
type: 'module',
|
|
65
|
-
test: createMatcher_1.createReactNativeMatcher({ folders: nodeModulesPaths }),
|
|
65
|
+
test: (0, createMatcher_1.createReactNativeMatcher)({ folders: nodeModulesPaths }),
|
|
66
66
|
transform: createMultiRuleTransformer_1.loaders.reactNativeModule,
|
|
67
67
|
warn: true,
|
|
68
68
|
},
|
|
@@ -70,7 +70,7 @@ function createExoticTransformer({ nodeModulesPaths, transpileModules, }) {
|
|
|
70
70
|
{
|
|
71
71
|
name: 'expo-module',
|
|
72
72
|
type: 'module',
|
|
73
|
-
test: createMatcher_1.createExpoMatcher({ folders: nodeModulesPaths }),
|
|
73
|
+
test: (0, createMatcher_1.createExpoMatcher)({ folders: nodeModulesPaths }),
|
|
74
74
|
transform: createMultiRuleTransformer_1.loaders.expoModule,
|
|
75
75
|
warn: true,
|
|
76
76
|
},
|
|
@@ -78,7 +78,7 @@ function createExoticTransformer({ nodeModulesPaths, transpileModules, }) {
|
|
|
78
78
|
{
|
|
79
79
|
name: 'sucrase',
|
|
80
80
|
type: 'module',
|
|
81
|
-
test: createMatcher_1.createKnownCommunityMatcher({
|
|
81
|
+
test: (0, createMatcher_1.createKnownCommunityMatcher)({
|
|
82
82
|
folders: nodeModulesPaths,
|
|
83
83
|
}),
|
|
84
84
|
transform: createMultiRuleTransformer_1.loaders.untranspiledModule,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExoticTransformer.js","sourceRoot":"","sources":["../../src/transformer/createExoticTransformer.ts"],"names":[],"mappings":";;;AAGA,mDAKyB;AACzB,6EAAmF;AACnF,+CAA4C;AAE5C;;;;;;;;;;;;;;GAcG;AACH,SAAgB,uBAAuB,CAAC,EACtC,gBAAgB,EAChB,gBAAgB,GAIjB;IACC,IAAI,CAAC,gBAAgB,EAAE;QACrB,gBAAgB,GAAG,CAAC,cAAc,CAAC,CAAC;KACrC;IACD,8CAA8C;IAC9C,MAAM,iBAAiB,GAAG,mCAAmB,
|
|
1
|
+
{"version":3,"file":"createExoticTransformer.js","sourceRoot":"","sources":["../../src/transformer/createExoticTransformer.ts"],"names":[],"mappings":";;;AAGA,mDAKyB;AACzB,6EAAmF;AACnF,+CAA4C;AAE5C;;;;;;;;;;;;;;GAcG;AACH,SAAgB,uBAAuB,CAAC,EACtC,gBAAgB,EAChB,gBAAgB,GAIjB;IACC,IAAI,CAAC,gBAAgB,EAAE;QACrB,gBAAgB,GAAG,CAAC,cAAc,CAAC,CAAC;KACrC;IACD,8CAA8C;IAC9C,MAAM,iBAAiB,GAAG,IAAA,mCAAmB,EAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;IAE5F,6DAA6D;IAC7D,8DAA8D;IAC9D,MAAM,2BAA2B,GAAG,IAAA,mCAAmB,EAAC;QACtD,SAAS,EAAE;YACT,sBAAsB;YACtB,sHAAsH;YACtH,SAAS;YACT,qDAAqD;YACrD,oBAAoB;YACpB,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC;SAC5B;QACD,OAAO,EAAE,gBAAgB;KAC1B,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAA,uDAA0B,EAAC;QAC3C,4DAA4D;QAC5D,4FAA4F;QAC5F,WAAW,CAAC,EAAE,QAAQ,EAAE;YACtB,8DAA8D;YAC9D,OAAO,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,QAAQ,CAAC;gBACpF,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,KAAK,CAAC;QACZ,CAAC;QAED,kEAAkE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,OAAO;gBACb,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;gBAChB,SAAS,EAAE,oCAAO,CAAC,GAAG;aACvB;SACF;KACF,CAAC,CAAC;IAEH,OAAO;QACL,SAAS;QACT,WAAW,EAAX,yBAAW;KACZ,CAAC;AACJ,CAAC;AApGD,0DAoGC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\nimport { BabelTransformer } from 'metro-babel-transformer';\n\nimport {\n createExpoMatcher,\n createKnownCommunityMatcher,\n createModuleMatcher,\n createReactNativeMatcher,\n} from './createMatcher';\nimport { createMultiRuleTransformer, loaders } from './createMultiRuleTransformer';\nimport { getCacheKey } from './getCacheKey';\n\n/**\n * Create an experimental multi-rule transformer for a React Native app.\n *\n * @example\n * ```\n * module.exports = createExoticTransformer({\n * nodeModulesPaths: ['react-native'],\n * transpileModules: ['@stripe/stripe-react-native'],\n * });\n * ```\n *\n * @param props.nodeModulesPaths paths to node_modules folders, relative to project root. Default: `['node_modules']`\n * @param props.transpileModules matchers for module names that should be transpiled using the project Babel configuration. Example: `['@stripe/stripe-react-native']`\n * @returns a Metro `transformer` function and default `getCacheKey` function.\n */\nexport function createExoticTransformer({\n nodeModulesPaths,\n transpileModules,\n}: {\n nodeModulesPaths?: string[];\n transpileModules?: string[];\n}): BabelTransformer {\n if (!nodeModulesPaths) {\n nodeModulesPaths = ['node_modules'];\n }\n // Match any node modules, or monorepo module.\n const nodeModuleMatcher = createModuleMatcher({ folders: nodeModulesPaths, moduleIds: [] });\n\n // Match node modules which are so oddly written that we must\n // transpile them with every possible option (most expensive).\n const impossibleNodeModuleMatcher = createModuleMatcher({\n moduleIds: [\n // victory is too wild\n // SyntaxError in ../../node_modules/victory-native/lib/components/victory-primitives/bar.js: Missing semicolon. (9:1)\n 'victory',\n // vector icons has some hidden issues that break NCL\n '@expo/vector-icons',\n ...(transpileModules || []),\n ],\n folders: nodeModulesPaths,\n });\n\n const transform = createMultiRuleTransformer({\n // Specify which rules to use on a per-file basis, basically\n // this is used to determine which modules are node modules, and which are application code.\n getRuleType({ filename }) {\n // Is a node module, and is not one of the impossible modules.\n return nodeModuleMatcher.test(filename) && !impossibleNodeModuleMatcher.test(filename)\n ? 'module'\n : 'app';\n },\n\n // Order is very important, we use wild card matchers to transpile\n // \"every unhandled node module\" and \"every unhandled application module\".\n rules: [\n // Match bob compiler modules, use the passthrough loader.\n {\n name: 'bob',\n type: 'module',\n test: createModuleMatcher({ moduleIds: ['.*/lib/commonjs/'], folders: nodeModulesPaths }),\n transform: loaders.passthroughModule,\n warn: true,\n },\n // Match React Native modules, convert them statically using sucrase.\n {\n name: 'react-native',\n type: 'module',\n test: createReactNativeMatcher({ folders: nodeModulesPaths }),\n transform: loaders.reactNativeModule,\n warn: true,\n },\n // Match Expo SDK modules, convert them statically using sucrase.\n {\n name: 'expo-module',\n type: 'module',\n test: createExpoMatcher({ folders: nodeModulesPaths }),\n transform: loaders.expoModule,\n warn: true,\n },\n // Match known problematic modules, convert them statically using an expensive, dynamic sucrase.\n {\n name: 'sucrase',\n type: 'module',\n test: createKnownCommunityMatcher({\n folders: nodeModulesPaths,\n }),\n transform: loaders.untranspiledModule,\n warn: true,\n },\n // Pass through any unhandled node modules as passthrough, this is where the most savings occur.\n // Ideally, you want your project to pass all node modules through this loader.\n // This should be the last \"module\" rule.\n // Message library authors and ask them to ship their modules as pre-transpiled\n // commonjs, to improve the development speed of your project.\n {\n name: 'skip-module',\n type: 'module',\n test: () => true,\n transform: loaders.passthroughModule,\n },\n // All application code should be transpiled with the user's babel preset,\n // this is the most expensive operation but provides the most customization to the user.\n // The goal is to use this as sparingly as possible.\n {\n name: 'babel',\n test: () => true,\n transform: loaders.app,\n },\n ],\n });\n\n return {\n transform,\n getCacheKey,\n };\n}\n"]}
|
|
@@ -10,19 +10,19 @@ const debug_1 = __importDefault(require("debug"));
|
|
|
10
10
|
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
11
11
|
const generateFunctionMap_1 = require("./generateFunctionMap");
|
|
12
12
|
const getBabelConfig_1 = require("./getBabelConfig");
|
|
13
|
-
const debug = debug_1.default('expo:metro:exotic-babel-transformer');
|
|
13
|
+
const debug = (0, debug_1.default)('expo:metro:exotic-babel-transformer');
|
|
14
14
|
let babelCore;
|
|
15
15
|
function getBabelCoreFromProject(projectRoot) {
|
|
16
16
|
if (babelCore)
|
|
17
17
|
return babelCore;
|
|
18
|
-
babelCore = require(resolve_from_1.default(projectRoot, '@babel/core'));
|
|
18
|
+
babelCore = require((0, resolve_from_1.default)(projectRoot, '@babel/core'));
|
|
19
19
|
return babelCore;
|
|
20
20
|
}
|
|
21
21
|
let babelParser;
|
|
22
22
|
function getBabelParserFromProject(projectRoot) {
|
|
23
23
|
if (babelParser)
|
|
24
24
|
return babelParser;
|
|
25
|
-
babelParser = require(resolve_from_1.default(projectRoot, '@babel/parser'));
|
|
25
|
+
babelParser = require((0, resolve_from_1.default)(projectRoot, '@babel/parser'));
|
|
26
26
|
return babelParser;
|
|
27
27
|
}
|
|
28
28
|
function sucrase(args, { transforms, }) {
|
|
@@ -107,7 +107,7 @@ exports.loaders = {
|
|
|
107
107
|
const babelConfig = {
|
|
108
108
|
// ES modules require sourceType='module' but OSS may not always want that
|
|
109
109
|
sourceType: 'unambiguous',
|
|
110
|
-
...getBabelConfig_1.getBabelConfig(filename, options, plugins),
|
|
110
|
+
...(0, getBabelConfig_1.getBabelConfig)(filename, options, plugins),
|
|
111
111
|
// Variables that are exposed to the user's babel preset.
|
|
112
112
|
caller: {
|
|
113
113
|
name: 'metro',
|
|
@@ -132,7 +132,7 @@ exports.loaders = {
|
|
|
132
132
|
return { ast: null };
|
|
133
133
|
const result = transformFromAstSync(sourceAst, src, babelConfig);
|
|
134
134
|
// TODO: Disable by default
|
|
135
|
-
const functionMap = generateFunctionMap_1.generateFunctionMap(options.projectRoot, sourceAst, { filename });
|
|
135
|
+
const functionMap = (0, generateFunctionMap_1.generateFunctionMap)(options.projectRoot, sourceAst, { filename });
|
|
136
136
|
// The result from `transformFromAstSync` can be null (if the file is ignored)
|
|
137
137
|
if (!result) {
|
|
138
138
|
return { ast: null, functionMap };
|
|
@@ -174,7 +174,7 @@ exports.loaders = {
|
|
|
174
174
|
// Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.
|
|
175
175
|
const ast = parseAst(options.projectRoot, src);
|
|
176
176
|
// TODO: Disable by default
|
|
177
|
-
const functionMap = generateFunctionMap_1.generateFunctionMap(options.projectRoot, ast, { filename });
|
|
177
|
+
const functionMap = (0, generateFunctionMap_1.generateFunctionMap)(options.projectRoot, ast, { filename });
|
|
178
178
|
return {
|
|
179
179
|
code: src,
|
|
180
180
|
functionMap,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMultiRuleTransformer.js","sourceRoot":"","sources":["../../src/transformer/createMultiRuleTransformer.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,kDAA0B;AAC1B,kDAA0B;AAE1B,gEAAuC;AAEvC,+DAA4D;AAC5D,qDAAkD;AAElD,MAAM,KAAK,GAAG,eAAK,CAAC,qCAAqC,CAAC,CAAC;AAE3D,IAAI,SAAmD,CAAC;AAExD,SAAS,uBAAuB,CAAC,WAAmB;IAClD,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAChC,SAAS,GAAG,OAAO,CAAC,sBAAW,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC;IAC7D,OAAO,SAAU,CAAC;AACpB,CAAC;AAED,IAAI,WAAuD,CAAC;AAE5D,SAAS,yBAAyB,CAAC,WAAmB;IACpD,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC;IACpC,WAAW,GAAG,OAAO,CAAC,sBAAW,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC;IACjE,OAAO,WAAY,CAAC;AACtB,CAAC;AAED,SAAS,OAAO,CACd,IAA0B,EAC1B,EACE,UAAU,GAGX;IAED,MAAM,EACJ,GAAG,EACH,QAAQ,EACR,OAAO,EAAE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I,CAAC;QACxC,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAEhC,iGAAiG;QACjG,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QAE/C,2BAA2B;QAC3B,MAAM,WAAW,GAAG,yCAAmB,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEhF,OAAO;YACL,IAAI,EAAE,GAAG;YACT,WAAW;YACX,GAAG;SACJ,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport chalk from 'chalk';\nimport Debug from 'debug';\nimport type { BabelTransformer, BabelTransformerArgs } from 'metro-babel-transformer';\nimport resolveFrom from 'resolve-from';\n\nimport { generateFunctionMap } from './generateFunctionMap';\nimport { getBabelConfig } from './getBabelConfig';\n\nconst debug = Debug('expo:metro:exotic-babel-transformer');\n\nlet babelCore: typeof import('@babel/core') | undefined;\n\nfunction getBabelCoreFromProject(projectRoot: string) {\n if (babelCore) return babelCore;\n babelCore = require(resolveFrom(projectRoot, '@babel/core'));\n return babelCore!;\n}\n\nlet babelParser: typeof import('@babel/parser') | undefined;\n\nfunction getBabelParserFromProject(projectRoot: string) {\n if (babelParser) return babelParser;\n babelParser = require(resolveFrom(projectRoot, '@babel/parser'));\n return babelParser!;\n}\n\nfunction sucrase(\n args: BabelTransformerArgs,\n {\n transforms,\n }: {\n transforms: string[];\n }\n): Partial<ReturnType<BabelTransformer['transform']>> {\n const {\n src,\n filename,\n options: { dev },\n } = args;\n const { transform } = require('sucrase');\n\n const results = transform(src, {\n filePath: filename,\n production: !dev,\n transforms,\n });\n\n return {\n code: results.code,\n functionMap: null,\n };\n}\n\nconst getExpensiveSucraseTransforms = (filename: string) => [\n 'jsx',\n 'imports',\n /\\.tsx?$/.test(filename) ? 'typescript' : 'flow',\n];\n\nfunction parseAst(projectRoot: string, sourceCode: string) {\n const babylon = getBabelParserFromProject(projectRoot);\n\n return babylon.parse(sourceCode, {\n sourceType: 'unambiguous',\n });\n}\n\nexport type Rule = {\n warn?: boolean;\n type?: 'module' | 'app';\n name?: string;\n test: ((args: BabelTransformerArgs) => boolean) | RegExp;\n transform: BabelTransformer['transform'];\n};\n\n/** Create a transformer that emulates Webpack's loader system. */\nexport function createMultiRuleTransformer({\n getRuleType,\n rules,\n}: {\n getRuleType: (args: BabelTransformerArgs) => string;\n rules: Rule[];\n}): BabelTransformer['transform'] {\n // const warnings: string[] = [];\n return function transform(args: BabelTransformerArgs) {\n const { filename, options } = args;\n const OLD_BABEL_ENV = process.env.BABEL_ENV;\n process.env.BABEL_ENV = options?.dev ? 'development' : process.env.BABEL_ENV || 'production';\n\n try {\n const ruleType = getRuleType(args);\n\n for (const rule of rules) {\n // optimization for checking node modules\n if (rule.type && rule.type !== ruleType) {\n continue;\n }\n\n const isMatched =\n typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);\n if (isMatched) {\n const results = rule.transform(args);\n // @ts-ignore: Add extra property for testing\n results._ruleName = rule.name;\n // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.\n if (results.code && !results.ast) {\n // Parse AST with babel otherwise Metro transformer will throw away the returned results.\n results.ast = parseAst(options?.projectRoot, results.code);\n }\n\n // TODO: Suboptimal warnings\n // if (rule.warn) {\n // const matchName =\n // filename.match(/node_modules\\/((:?@[\\w\\d-]+\\/[\\w\\d-]+)|(:?[\\w\\d-]+))\\/?/)?.[1] ??\n // filename;\n // if (matchName && !warnings.includes(matchName)) {\n // warnings.push(matchName);\n // console.warn(chalk.yellow.bold`warn `, matchName);\n // console.warn(\n // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`\n // );\n // }\n // }\n\n return results;\n }\n }\n throw new Error('no loader rule to handle file: ' + filename);\n } finally {\n if (OLD_BABEL_ENV) {\n process.env.BABEL_ENV = OLD_BABEL_ENV;\n }\n }\n };\n}\n\nexport const loaders: Record<string, (args: BabelTransformerArgs) => any> = {\n // Perform the standard, and most expensive transpilation sequence.\n app(args) {\n debug('app:', args.filename);\n\n const { filename, options, src, plugins } = args;\n const babelConfig = {\n // ES modules require sourceType='module' but OSS may not always want that\n sourceType: 'unambiguous',\n ...getBabelConfig(filename, options, plugins),\n // Variables that are exposed to the user's babel preset.\n caller: {\n name: 'metro',\n\n platform: options.platform,\n },\n ast: true,\n };\n\n // Surface a warning function so babel linters can be used.\n Object.defineProperty(babelConfig.caller, 'onWarning', {\n enumerable: false,\n writable: false,\n value: (babelConfig.caller.onWarning = function (msg: any) {\n // Format the file path first so users know where the warning came from.\n console.warn(chalk.bold.yellow`warn ` + args.filename);\n console.warn(msg);\n }),\n });\n\n const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);\n const sourceAst = parseSync(src, babelConfig);\n\n // Should never happen.\n if (!sourceAst) return { ast: null };\n\n const result = transformFromAstSync(sourceAst, src, babelConfig);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, sourceAst, { filename });\n // The result from `transformFromAstSync` can be null (if the file is ignored)\n if (!result) {\n return { ast: null, functionMap };\n }\n\n return { ast: result.ast, functionMap };\n },\n\n // Transpile react-native with sucrase.\n reactNativeModule(args) {\n debug('rn:', args.filename);\n return sucrase(args, {\n transforms: ['jsx', 'flow', 'imports'],\n });\n },\n\n // Transpile expo modules with sucrase.\n expoModule(args) {\n debug('expo:', args.filename);\n // TODO: Fix all expo packages\n return sucrase(args, {\n transforms: [\n 'imports',\n // TODO: fix expo-processing, expo/vector-icons\n /(expo-processing|expo\\/vector-icons)/.test(args.filename) && 'jsx',\n // TODO: fix expo-asset-utils\n /(expo-asset-utils)/.test(args.filename) && 'flow',\n ].filter(Boolean) as string[],\n });\n },\n\n // Transpile known community modules with the most expensive sucrase\n untranspiledModule(args) {\n debug('known issues:', args.filename);\n return sucrase(args, {\n transforms: getExpensiveSucraseTransforms(args.filename),\n });\n },\n\n // Pass all modules through without transpiling them.\n passthroughModule(args) {\n const { filename, options, src } = args;\n debug('passthrough:', filename);\n\n // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.\n const ast = parseAst(options.projectRoot, src);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, ast, { filename });\n\n return {\n code: src,\n functionMap,\n ast,\n };\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"createMultiRuleTransformer.js","sourceRoot":"","sources":["../../src/transformer/createMultiRuleTransformer.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,kDAA0B;AAC1B,kDAA0B;AAE1B,gEAAuC;AAEvC,+DAA4D;AAC5D,qDAAkD;AAElD,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,qCAAqC,CAAC,CAAC;AAE3D,IAAI,SAAmD,CAAC;AAExD,SAAS,uBAAuB,CAAC,WAAmB;IAClD,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAChC,SAAS,GAAG,OAAO,CAAC,IAAA,sBAAW,EAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC;IAC7D,OAAO,SAAU,CAAC;AACpB,CAAC;AAED,IAAI,WAAuD,CAAC;AAE5D,SAAS,yBAAyB,CAAC,WAAmB;IACpD,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC;IACpC,WAAW,GAAG,OAAO,CAAC,IAAA,sBAAW,EAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC;IACjE,OAAO,WAAY,CAAC;AACtB,CAAC;AAED,SAAS,OAAO,CACd,IAA0B,EAC1B,EACE,UAAU,GAGX;IAED,MAAM,EACJ,GAAG,EACH,QAAQ,EACR,OAAO,EAAE,EAAE,GAAG,EAAE,GACjB,GAAG,IAAI,CAAC;IACT,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAEzC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,EAAE;QAC7B,QAAQ,EA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AA2B;QAC3B,MAAM,WAAW,GAAG,IAAA,yCAAmB,EAAC,OAAO,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEhF,OAAO;YACL,IAAI,EAAE,GAAG;YACT,WAAW;YACX,GAAG;SACJ,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport chalk from 'chalk';\nimport Debug from 'debug';\nimport type { BabelTransformer, BabelTransformerArgs } from 'metro-babel-transformer';\nimport resolveFrom from 'resolve-from';\n\nimport { generateFunctionMap } from './generateFunctionMap';\nimport { getBabelConfig } from './getBabelConfig';\n\nconst debug = Debug('expo:metro:exotic-babel-transformer');\n\nlet babelCore: typeof import('@babel/core') | undefined;\n\nfunction getBabelCoreFromProject(projectRoot: string) {\n if (babelCore) return babelCore;\n babelCore = require(resolveFrom(projectRoot, '@babel/core'));\n return babelCore!;\n}\n\nlet babelParser: typeof import('@babel/parser') | undefined;\n\nfunction getBabelParserFromProject(projectRoot: string) {\n if (babelParser) return babelParser;\n babelParser = require(resolveFrom(projectRoot, '@babel/parser'));\n return babelParser!;\n}\n\nfunction sucrase(\n args: BabelTransformerArgs,\n {\n transforms,\n }: {\n transforms: string[];\n }\n): Partial<ReturnType<BabelTransformer['transform']>> {\n const {\n src,\n filename,\n options: { dev },\n } = args;\n const { transform } = require('sucrase');\n\n const results = transform(src, {\n filePath: filename,\n production: !dev,\n transforms,\n });\n\n return {\n code: results.code,\n functionMap: null,\n };\n}\n\nconst getExpensiveSucraseTransforms = (filename: string) => [\n 'jsx',\n 'imports',\n /\\.tsx?$/.test(filename) ? 'typescript' : 'flow',\n];\n\nfunction parseAst(projectRoot: string, sourceCode: string) {\n const babylon = getBabelParserFromProject(projectRoot);\n\n return babylon.parse(sourceCode, {\n sourceType: 'unambiguous',\n });\n}\n\nexport type Rule = {\n warn?: boolean;\n type?: 'module' | 'app';\n name?: string;\n test: ((args: BabelTransformerArgs) => boolean) | RegExp;\n transform: BabelTransformer['transform'];\n};\n\n/** Create a transformer that emulates Webpack's loader system. */\nexport function createMultiRuleTransformer({\n getRuleType,\n rules,\n}: {\n getRuleType: (args: BabelTransformerArgs) => string;\n rules: Rule[];\n}): BabelTransformer['transform'] {\n // const warnings: string[] = [];\n return function transform(args: BabelTransformerArgs) {\n const { filename, options } = args;\n const OLD_BABEL_ENV = process.env.BABEL_ENV;\n process.env.BABEL_ENV = options?.dev ? 'development' : process.env.BABEL_ENV || 'production';\n\n try {\n const ruleType = getRuleType(args);\n\n for (const rule of rules) {\n // optimization for checking node modules\n if (rule.type && rule.type !== ruleType) {\n continue;\n }\n\n const isMatched =\n typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);\n if (isMatched) {\n const results = rule.transform(args);\n // @ts-ignore: Add extra property for testing\n results._ruleName = rule.name;\n // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.\n if (results.code && !results.ast) {\n // Parse AST with babel otherwise Metro transformer will throw away the returned results.\n results.ast = parseAst(options?.projectRoot, results.code);\n }\n\n // TODO: Suboptimal warnings\n // if (rule.warn) {\n // const matchName =\n // filename.match(/node_modules\\/((:?@[\\w\\d-]+\\/[\\w\\d-]+)|(:?[\\w\\d-]+))\\/?/)?.[1] ??\n // filename;\n // if (matchName && !warnings.includes(matchName)) {\n // warnings.push(matchName);\n // console.warn(chalk.yellow.bold`warn `, matchName);\n // console.warn(\n // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`\n // );\n // }\n // }\n\n return results;\n }\n }\n throw new Error('no loader rule to handle file: ' + filename);\n } finally {\n if (OLD_BABEL_ENV) {\n process.env.BABEL_ENV = OLD_BABEL_ENV;\n }\n }\n };\n}\n\nexport const loaders: Record<string, (args: BabelTransformerArgs) => any> = {\n // Perform the standard, and most expensive transpilation sequence.\n app(args) {\n debug('app:', args.filename);\n\n const { filename, options, src, plugins } = args;\n const babelConfig = {\n // ES modules require sourceType='module' but OSS may not always want that\n sourceType: 'unambiguous',\n ...getBabelConfig(filename, options, plugins),\n // Variables that are exposed to the user's babel preset.\n caller: {\n name: 'metro',\n\n platform: options.platform,\n },\n ast: true,\n };\n\n // Surface a warning function so babel linters can be used.\n Object.defineProperty(babelConfig.caller, 'onWarning', {\n enumerable: false,\n writable: false,\n value: (babelConfig.caller.onWarning = function (msg: any) {\n // Format the file path first so users know where the warning came from.\n console.warn(chalk.bold.yellow`warn ` + args.filename);\n console.warn(msg);\n }),\n });\n\n const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);\n const sourceAst = parseSync(src, babelConfig);\n\n // Should never happen.\n if (!sourceAst) return { ast: null };\n\n const result = transformFromAstSync(sourceAst, src, babelConfig);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, sourceAst, { filename });\n // The result from `transformFromAstSync` can be null (if the file is ignored)\n if (!result) {\n return { ast: null, functionMap };\n }\n\n return { ast: result.ast, functionMap };\n },\n\n // Transpile react-native with sucrase.\n reactNativeModule(args) {\n debug('rn:', args.filename);\n return sucrase(args, {\n transforms: ['jsx', 'flow', 'imports'],\n });\n },\n\n // Transpile expo modules with sucrase.\n expoModule(args) {\n debug('expo:', args.filename);\n // TODO: Fix all expo packages\n return sucrase(args, {\n transforms: [\n 'imports',\n // TODO: fix expo-processing, expo/vector-icons\n /(expo-processing|expo\\/vector-icons)/.test(args.filename) && 'jsx',\n // TODO: fix expo-asset-utils\n /(expo-asset-utils)/.test(args.filename) && 'flow',\n ].filter(Boolean) as string[],\n });\n },\n\n // Transpile known community modules with the most expensive sucrase\n untranspiledModule(args) {\n debug('known issues:', args.filename);\n return sucrase(args, {\n transforms: getExpensiveSucraseTransforms(args.filename),\n });\n },\n\n // Pass all modules through without transpiling them.\n passthroughModule(args) {\n const { filename, options, src } = args;\n debug('passthrough:', filename);\n\n // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.\n const ast = parseAst(options.projectRoot, src);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, ast, { filename });\n\n return {\n code: src,\n functionMap,\n ast,\n };\n },\n};\n"]}
|
|
@@ -22,7 +22,7 @@ function generateFunctionMap(projectRoot, ast, context) {
|
|
|
22
22
|
// - run AppRegistry.js:117:26
|
|
23
23
|
//
|
|
24
24
|
if (process.env.EXPO_USE_FB_SOURCES) {
|
|
25
|
-
return importMetroFromProject_1.importMetroSourceMapFromProject(projectRoot).generateFunctionMap(ast, context);
|
|
25
|
+
return (0, importMetroFromProject_1.importMetroSourceMapFromProject)(projectRoot).generateFunctionMap(ast, context);
|
|
26
26
|
}
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateFunctionMap.js","sourceRoot":"","sources":["../../src/transformer/generateFunctionMap.ts"],"names":[],"mappings":";;;AAEA,sEAA4E;AAE5E,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,GAAkD,EAClD,OAAsD;IAEtD,qGAAqG;IACrG,sGAAsG;IACtG,2GAA2G;IAC3G,yGAAyG;IACzG,EAAE;IACF,sEAAsE;IACtE,0DAA0D;IAC1D,EAAE;IACF,UAAU;IACV,2BAA2B;IAC3B,gDAAgD;IAChD,+CAA+C;IAC/C,EAAE;IACF,SAAS;IACT,wBAAwB;IACxB,gDAAgD;IAChD,8BAA8B;IAC9B,EAAE;IACF,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;QACnC,OAAO,wDAA+B,
|
|
1
|
+
{"version":3,"file":"generateFunctionMap.js","sourceRoot":"","sources":["../../src/transformer/generateFunctionMap.ts"],"names":[],"mappings":";;;AAEA,sEAA4E;AAE5E,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,GAAkD,EAClD,OAAsD;IAEtD,qGAAqG;IACrG,sGAAsG;IACtG,2GAA2G;IAC3G,yGAAyG;IACzG,EAAE;IACF,sEAAsE;IACtE,0DAA0D;IAC1D,EAAE;IACF,UAAU;IACV,2BAA2B;IAC3B,gDAAgD;IAChD,+CAA+C;IAC/C,EAAE;IACF,SAAS;IACT,wBAAwB;IACxB,gDAAgD;IAChD,8BAA8B;IAC9B,EAAE;IACF,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;QACnC,OAAO,IAAA,wDAA+B,EAAC,WAAW,CAAC,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KACvF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AA3BD,kDA2BC","sourcesContent":["import type { generateFunctionMap as generateFunctionMapType } from 'metro-source-map';\n\nimport { importMetroSourceMapFromProject } from '../importMetroFromProject';\n\nexport function generateFunctionMap(\n projectRoot: string,\n ast: Parameters<typeof generateFunctionMapType>[0],\n context: Parameters<typeof generateFunctionMapType>[1]\n): ReturnType<typeof generateFunctionMapType> | null {\n // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented\n // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.\n // The feature supposedly provides improved function names for anonymous functions, but we will opt towards\n // linting to prevent users from adding anonymous functions for important features like React components.\n //\n // Here is an example stack trace for a component that throws an error\n // in the root component (which is an anonymous function):\n //\n // Before:\n // - <anonymous> App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - runnables.appKey.run AppRegistry.js:117:26\n //\n // After:\n // - _default App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - run AppRegistry.js:117:26\n //\n if (process.env.EXPO_USE_FB_SOURCES) {\n return importMetroSourceMapFromProject(projectRoot).generateFunctionMap(ast, context);\n }\n return null;\n}\n"]}
|
|
@@ -90,7 +90,7 @@ function getBabelConfig(filename, options, plugins = []) {
|
|
|
90
90
|
const extraPlugins = [];
|
|
91
91
|
// TODO: This probably can be removed
|
|
92
92
|
if (options.inlineRequires) {
|
|
93
|
-
const inlineRequiresPlugin = resolve_from_1.default(options.projectRoot, 'babel-preset-fbjs/plugins/inline-requires');
|
|
93
|
+
const inlineRequiresPlugin = (0, resolve_from_1.default)(options.projectRoot, 'babel-preset-fbjs/plugins/inline-requires');
|
|
94
94
|
extraPlugins.push(inlineRequiresPlugin);
|
|
95
95
|
}
|
|
96
96
|
config.plugins = extraPlugins.concat(config.plugins, plugins);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBabelConfig.js","sourceRoot":"","sources":["../../src/transformer/getBabelConfig.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;AAGH,4CAAoB;AAEpB,gDAAwB;AACxB,gEAAuC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC;IAClB,IAAI,OAAO,GAMA,IAAI,CAAC;IAEhB,OAAO,SAAS,WAAW,CAAC,WAAmB,EAAE,OAAgC;;QAC/E,IAAI,OAAO,IAAI,IAAI,EAAE;YACnB,OAAO,OAAO,CAAC;SAChB;QAED,OAAO,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAE1B,0DAA0D;QAC1D,uEAAuE;QACvE,IAAI,kBAAkB,CAAC;QAEvB,WAAW;QACX,IAAI,WAAW,EAAE;YACf,kBAAkB,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;SAC5D;QAED,IAAI,kBAAkB,EAAE;YACtB,cAAc;YACd,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;gBACtC,kBAAkB,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;aAC/D;YAED,kBAAkB;YAClB,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;gBACtC,kBAAkB,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;aACnE;YAED,+DAA+D;YAC/D,4CAA4C;YAC5C,IAAI,YAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;gBACrC,OAAO,CAAC,OAAO,GAAG,kBAAkB,CAAC;aACtC;SACF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,MAAM,CAAC,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE9D,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;QAC9B,sEAAsE;QACtE,uEAAuE;QACvE,qEAAqE;QACrE,uEAAuE;QACvE,sCAAsC;QACtC,0BAA0B;QAC1B,MAAM,iCAAiC,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;QAElF,IAAI,iCAAiC,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;gBACnB,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;aACrB;YACD,6BAA6B;YAC7B,+EAA+E;YAC/E,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC;SACrF;KACF;IAED,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC;AACnC,CAAC;AAlDD,wCAkDC","sourcesContent":["/**\n * Copyright (c) Expo.\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Forks the default metro-react-native-babel-transformer and adds support for known transforms.\n */\n\nimport type { PluginItem as BabelPlugins, PluginItem } from '@babel/core';\nimport fs from 'fs';\nimport type { BabelTransformerOptions } from 'metro-babel-transformer';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\n/**\n * Return a memoized function that checks for the existence of a\n * project level .babelrc file, and if it doesn't exist, reads the\n * default RN babelrc file and uses that.\n */\nconst getBabelRC = (function () {\n let babelRC: {\n // `any` to avoid flow type mismatch with Babel 7's internal type of\n // `Array<string>` even though it correctly accepts the usage below.\n presets?: any;\n extends?: string;\n plugins: BabelPlugins;\n } | null = null;\n\n return function _getBabelRC(projectRoot: string, options: BabelTransformerOptions) {\n if (babelRC != null) {\n return babelRC;\n }\n\n babelRC = { plugins: [] };\n\n // Let's look for a babel config file in the project root.\n // TODO look into adding a command line option to specify this location\n let projectBabelRCPath;\n\n // .babelrc\n if (projectRoot) {\n projectBabelRCPath = path.resolve(projectRoot, '.babelrc');\n }\n\n if (projectBabelRCPath) {\n // .babelrc.js\n if (!fs.existsSync(projectBabelRCPath)) {\n projectBabelRCPath = path.resolve(projectRoot, '.babelrc.js');\n }\n\n // babel.config.js\n if (!fs.existsSync(projectBabelRCPath)) {\n projectBabelRCPath = path.resolve(projectRoot, 'babel.config.js');\n }\n\n // If we found a babel config file, extend our config off of it\n // otherwise the default config will be used\n if (fs.existsSync(projectBabelRCPath)) {\n babelRC.extends = projectBabelRCPath;\n }\n }\n\n // If a babel config file doesn't exist in the project then\n // the default preset for react-native will be used instead.\n if (!babelRC.extends) {\n const { experimentalImportSupport, ...presetOptions } = options;\n\n // Use `babel-preset-expo` instead of `metro-react-native-babel-preset`.\n const presetPath =\n resolveFrom.silent(projectRoot, 'babel-preset-expo') ??\n resolveFrom.silent(projectRoot, 'metro-react-native-babel-preset') ??\n require.resolve('babel-preset-expo');\n\n babelRC.presets = [\n [\n require(presetPath),\n {\n // Default to React 17 automatic JSX transform.\n jsxRuntime: 'automatic',\n ...presetOptions,\n disableImportExportTransform: experimentalImportSupport,\n enableBabelRuntime: options.enableBabelRuntime,\n },\n ],\n ];\n }\n\n return babelRC;\n };\n})();\n\n/**\n * Given a filename and options, build a Babel\n * config object with the appropriate plugins.\n */\nexport function getBabelConfig(\n filename: string,\n options: BabelTransformerOptions,\n plugins: BabelPlugins = []\n) {\n const babelRC = getBabelRC(options.projectRoot, options);\n\n const extraConfig = {\n babelrc: typeof options.enableBabelRCLookup === 'boolean' ? options.enableBabelRCLookup : true,\n code: false,\n filename,\n highlightCode: true,\n };\n\n const config: any = { ...babelRC, ...extraConfig };\n\n // Add extra plugins\n const extraPlugins: (string | PluginItem)[] = [];\n\n // TODO: This probably can be removed\n if (options.inlineRequires) {\n const inlineRequiresPlugin = resolveFrom(\n options.projectRoot,\n 'babel-preset-fbjs/plugins/inline-requires'\n );\n extraPlugins.push(inlineRequiresPlugin);\n }\n\n config.plugins = extraPlugins.concat(config.plugins, plugins);\n\n if (options.dev && options.hot) {\n // Note: this intentionally doesn't include the path separator because\n // I'm not sure which one it should use on Windows, and false positives\n // are unlikely anyway. If you later decide to include the separator,\n // don't forget that the string usually *starts* with \"node_modules\" so\n // the first one often won't be there.\n // TODO: Support monorepos\n const mayContainEditableReactComponents = filename.indexOf('node_modules') === -1;\n\n if (mayContainEditableReactComponents) {\n if (!config.plugins) {\n config.plugins = [];\n }\n // Add react refresh runtime.\n // NOTICE: keep in sync with 'metro-react-native-babel-preset/src/configs/hmr'.\n config.plugins.push(resolveFrom.silent(options.projectRoot, 'react-refresh/babel'));\n }\n }\n\n return { ...babelRC, ...config };\n}\n"]}
|
|
@@ -7,7 +7,7 @@ exports.getCacheKey = exports.cacheKeyParts = void 0;
|
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
9
|
exports.cacheKeyParts = [
|
|
10
|
-
fs_1.readFileSync(__filename),
|
|
10
|
+
(0, fs_1.readFileSync)(__filename),
|
|
11
11
|
// Since babel-preset-fbjs cannot be safely resolved relative to the
|
|
12
12
|
// project root, use this environment variable that we define earlier.
|
|
13
13
|
process.env.EXPO_METRO_CACHE_KEY_VERSION || '3.3.0',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheKey.js","sourceRoot":"","sources":["../../src/transformer/getCacheKey.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2BAAkC;AAErB,QAAA,aAAa,GAAG;IAC3B,iBAAY,
|
|
1
|
+
{"version":3,"file":"getCacheKey.js","sourceRoot":"","sources":["../../src/transformer/getCacheKey.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2BAAkC;AAErB,QAAA,aAAa,GAAG;IAC3B,IAAA,iBAAY,EAAC,UAAU,CAAC;IACxB,oEAAoE;IACpE,sEAAsE;IACtE,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,OAAO;IACnD,uDAAuD;CACxD,CAAC;AAEF,mBAAmB;AACnB,SAAgB,WAAW;IACzB,MAAM,GAAG,GAAG,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,qBAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAJD,kCAIC","sourcesContent":["import crypto from 'crypto';\nimport { readFileSync } from 'fs';\n\nexport const cacheKeyParts = [\n readFileSync(__filename),\n // Since babel-preset-fbjs cannot be safely resolved relative to the\n // project root, use this environment variable that we define earlier.\n process.env.EXPO_METRO_CACHE_KEY_VERSION || '3.3.0',\n // require('babel-preset-fbjs/package.json').version,\n];\n\n// Matches upstream\nexport function getCacheKey(): string {\n const key = crypto.createHash('md5');\n cacheKeyParts.forEach(part => key.update(part));\n return key.digest('hex');\n}\n"]}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
// Copyright 2021-present 650 Industries (Expo). All rights reserved.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const createExoticTransformer_1 = require("./createExoticTransformer");
|
|
5
|
-
module.exports = createExoticTransformer_1.createExoticTransformer({ nodeModulesPaths: ['node_modules'] });
|
|
5
|
+
module.exports = (0, createExoticTransformer_1.createExoticTransformer)({ nodeModulesPaths: ['node_modules'] });
|
|
6
6
|
//# sourceMappingURL=metro-expo-exotic-babel-transformer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metro-expo-exotic-babel-transformer.js","sourceRoot":"","sources":["../../src/transformer/metro-expo-exotic-babel-transformer.ts"],"names":[],"mappings":";AAAA,qEAAqE;;AAErE,uEAAoE;AAEpE,MAAM,CAAC,OAAO,GAAG,iDAAuB,
|
|
1
|
+
{"version":3,"file":"metro-expo-exotic-babel-transformer.js","sourceRoot":"","sources":["../../src/transformer/metro-expo-exotic-babel-transformer.ts"],"names":[],"mappings":";AAAA,qEAAqE;;AAErE,uEAAoE;AAEpE,MAAM,CAAC,OAAO,GAAG,IAAA,iDAAuB,EAAC,EAAE,gBAAgB,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport { createExoticTransformer } from './createExoticTransformer';\n\nmodule.exports = createExoticTransformer({ nodeModulesPaths: ['node_modules'] });\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/metro-config",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16",
|
|
4
4
|
"description": "A Metro config for running React Native projects with the Metro bundler",
|
|
5
5
|
"main": "build/ExpoMetroConfig.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"transformer"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@expo/config": "6.0.
|
|
38
|
-
"@expo/json-file": "8.2.
|
|
37
|
+
"@expo/config": "6.0.23",
|
|
38
|
+
"@expo/json-file": "8.2.36",
|
|
39
39
|
"chalk": "^4.1.0",
|
|
40
40
|
"debug": "^4.3.2",
|
|
41
41
|
"find-yarn-workspace-root": "~2.0.0",
|