@expo/metro-config 0.3.19 → 0.3.20

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.
@@ -1,238 +1,337 @@
1
1
  "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = void 0;
7
+ exports.getDefaultConfig = getDefaultConfig;
8
+ exports.loadAsync = loadAsync;
9
+
10
+ function _config() {
11
+ const data = require("@expo/config");
12
+
13
+ _config = function () {
14
+ return data;
15
+ };
16
+
17
+ return data;
18
+ }
19
+
20
+ function _paths() {
21
+ const data = require("@expo/config/paths");
22
+
23
+ _paths = function () {
24
+ return data;
25
+ };
26
+
27
+ return data;
28
+ }
29
+
30
+ function _chalk() {
31
+ const data = _interopRequireDefault(require("chalk"));
32
+
33
+ _chalk = function () {
34
+ return data;
35
+ };
36
+
37
+ return data;
38
+ }
39
+
40
+ function _getenv() {
41
+ const data = require("getenv");
42
+
43
+ _getenv = function () {
44
+ return data;
45
+ };
46
+
47
+ return data;
48
+ }
49
+
50
+ function _path() {
51
+ const data = _interopRequireDefault(require("path"));
52
+
53
+ _path = function () {
54
+ return data;
55
+ };
56
+
57
+ return data;
58
+ }
59
+
60
+ function _resolveFrom() {
61
+ const data = _interopRequireDefault(require("resolve-from"));
62
+
63
+ _resolveFrom = function () {
64
+ return data;
65
+ };
66
+
67
+ return data;
68
+ }
69
+
70
+ function _getModulesPaths() {
71
+ const data = require("./getModulesPaths");
72
+
73
+ _getModulesPaths = function () {
74
+ return data;
75
+ };
76
+
77
+ return data;
78
+ }
79
+
80
+ function _getWatchFolders() {
81
+ const data = require("./getWatchFolders");
82
+
83
+ _getWatchFolders = function () {
84
+ return data;
85
+ };
86
+
87
+ return data;
88
+ }
89
+
90
+ function _importMetroFromProject() {
91
+ const data = require("./importMetroFromProject");
92
+
93
+ _importMetroFromProject = function () {
94
+ return data;
95
+ };
96
+
97
+ return data;
98
+ }
99
+
100
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
101
+
2
102
  // Copyright 2021-present 650 Industries (Expo). All rights reserved.
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.loadAsync = exports.getDefaultConfig = exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = void 0;
8
- const config_1 = require("@expo/config");
9
- const paths_1 = require("@expo/config/paths");
10
- const chalk_1 = __importDefault(require("chalk"));
11
- const getenv_1 = require("getenv");
12
- const path_1 = __importDefault(require("path"));
13
- const resolve_from_1 = __importDefault(require("resolve-from"));
14
- const getModulesPaths_1 = require("./getModulesPaths");
15
- const getWatchFolders_1 = require("./getWatchFolders");
16
- const importMetroFromProject_1 = require("./importMetroFromProject");
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
- // Import only the types here, the values will be imported from the project, at runtime.
20
- exports.INTERNAL_CALLSITES_REGEX = new RegExp([
21
- '/Libraries/Renderer/implementations/.+\\.js$',
22
- '/Libraries/BatchedBridge/MessageQueue\\.js$',
23
- '/Libraries/YellowBox/.+\\.js$',
24
- '/Libraries/LogBox/.+\\.js$',
25
- '/Libraries/Core/Timers/.+\\.js$',
26
- 'node_modules/react-devtools-core/.+\\.js$',
27
- 'node_modules/react-refresh/.+\\.js$',
28
- 'node_modules/scheduler/.+\\.js$',
29
- // Metro replaces `require()` with a different method,
30
- // we want to omit this method from the stack trace.
31
- // This is akin to most React tooling.
32
- '/metro/.*/polyfills/require.js$',
33
- // Hide frames related to a fast refresh.
34
- '/metro/.*/lib/bundle-modules/.+\\.js$',
35
- '/metro/.*/lib/bundle-modules/.+\\.js$',
36
- 'node_modules/react-native/Libraries/Utilities/HMRClient.js$',
37
- 'node_modules/eventemitter3/index.js',
38
- 'node_modules/event-target-shim/dist/.+\\.js$',
39
- // Ignore the log forwarder used in the Expo Go app
40
- '/expo/build/environment/react-native-logs.fx.js$',
41
- '/src/environment/react-native-logs.fx.ts$',
42
- '/expo/build/logs/RemoteConsole.js$',
43
- // Improve errors thrown by invariant (ex: `Invariant Violation: "main" has not been registered`).
44
- 'node_modules/invariant/.+\\.js$',
45
- // Remove babel runtime additions
46
- 'node_modules/regenerator-runtime/.+\\.js$',
47
- // Remove react native setImmediate ponyfill
48
- 'node_modules/promise/setimmediate/.+\\.js$',
49
- // Babel helpers that implement language features
50
- 'node_modules/@babel/runtime/.+\\.js$',
51
- // Block native code invocations
52
- `\\[native code\\]`,
53
- ].join('|'));
103
+ const EXPO_DEBUG = (0, _getenv().boolish)('EXPO_DEBUG', false);
104
+ exports.EXPO_DEBUG = EXPO_DEBUG;
105
+ const EXPO_USE_EXOTIC = (0, _getenv().boolish)('EXPO_USE_EXOTIC', false); // Import only the types here, the values will be imported from the project, at runtime.
106
+
107
+ const INTERNAL_CALLSITES_REGEX = new RegExp(['/Libraries/Renderer/implementations/.+\\.js$', '/Libraries/BatchedBridge/MessageQueue\\.js$', '/Libraries/YellowBox/.+\\.js$', '/Libraries/LogBox/.+\\.js$', '/Libraries/Core/Timers/.+\\.js$', 'node_modules/react-devtools-core/.+\\.js$', 'node_modules/react-refresh/.+\\.js$', 'node_modules/scheduler/.+\\.js$', // Metro replaces `require()` with a different method,
108
+ // we want to omit this method from the stack trace.
109
+ // This is akin to most React tooling.
110
+ '/metro/.*/polyfills/require.js$', // Hide frames related to a fast refresh.
111
+ '/metro/.*/lib/bundle-modules/.+\\.js$', '/metro/.*/lib/bundle-modules/.+\\.js$', 'node_modules/react-native/Libraries/Utilities/HMRClient.js$', 'node_modules/eventemitter3/index.js', 'node_modules/event-target-shim/dist/.+\\.js$', // Ignore the log forwarder used in the Expo Go app
112
+ '/expo/build/environment/react-native-logs.fx.js$', '/src/environment/react-native-logs.fx.ts$', '/expo/build/logs/RemoteConsole.js$', // Improve errors thrown by invariant (ex: `Invariant Violation: "main" has not been registered`).
113
+ 'node_modules/invariant/.+\\.js$', // Remove babel runtime additions
114
+ 'node_modules/regenerator-runtime/.+\\.js$', // Remove react native setImmediate ponyfill
115
+ 'node_modules/promise/setimmediate/.+\\.js$', // Babel helpers that implement language features
116
+ 'node_modules/@babel/runtime/.+\\.js$', // Block native code invocations
117
+ `\\[native code\\]`].join('|'));
118
+ exports.INTERNAL_CALLSITES_REGEX = INTERNAL_CALLSITES_REGEX;
119
+
54
120
  function readIsLegacyImportsEnabled(projectRoot) {
55
- const config = (0, config_1.getConfig)(projectRoot, { skipSDKVersionRequirement: true });
56
- return (0, config_1.isLegacyImportsEnabled)(config.exp);
121
+ const config = (0, _config().getConfig)(projectRoot, {
122
+ skipSDKVersionRequirement: true
123
+ });
124
+ return (0, _config().isLegacyImportsEnabled)(config.exp);
57
125
  }
126
+
58
127
  function getProjectBabelConfigFile(projectRoot) {
59
- return (resolve_from_1.default.silent(projectRoot, './babel.config.js') ||
60
- resolve_from_1.default.silent(projectRoot, './.babelrc') ||
61
- resolve_from_1.default.silent(projectRoot, './.babelrc.js'));
128
+ return _resolveFrom().default.silent(projectRoot, './babel.config.js') || _resolveFrom().default.silent(projectRoot, './.babelrc') || _resolveFrom().default.silent(projectRoot, './.babelrc.js');
62
129
  }
130
+
63
131
  function getAssetPlugins(projectRoot) {
64
- const assetPlugins = [];
65
- let hashAssetFilesPath;
66
- try {
67
- hashAssetFilesPath = (0, resolve_from_1.default)(projectRoot, 'expo-asset/tools/hashAssetFiles');
68
- }
69
- catch {
70
- // TODO: we should warn/throw an error if the user has expo-updates installed but does not
71
- // have hashAssetFiles available, or if the user is in managed workflow and does not have
72
- // hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,
73
- // it is not needed
74
- }
75
- if (hashAssetFilesPath) {
76
- assetPlugins.push(hashAssetFilesPath);
77
- }
78
- return assetPlugins;
132
+ const assetPlugins = [];
133
+ let hashAssetFilesPath;
134
+
135
+ try {
136
+ hashAssetFilesPath = (0, _resolveFrom().default)(projectRoot, 'expo-asset/tools/hashAssetFiles');
137
+ } catch {// TODO: we should warn/throw an error if the user has expo-updates installed but does not
138
+ // have hashAssetFiles available, or if the user is in managed workflow and does not have
139
+ // hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,
140
+ // it is not needed
141
+ }
142
+
143
+ if (hashAssetFilesPath) {
144
+ assetPlugins.push(hashAssetFilesPath);
145
+ }
146
+
147
+ return assetPlugins;
79
148
  }
149
+
80
150
  let hasWarnedAboutExotic = false;
151
+
81
152
  function getDefaultConfig(projectRoot, options = {}) {
82
- const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;
83
- if (isExotic && !hasWarnedAboutExotic) {
84
- hasWarnedAboutExotic = true;
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
- }
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
- try {
90
- // Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.
91
- // This hack is used because there doesn't appear to be anyway to resolve
92
- // `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).
93
- const babelPresetFbjsPath = (0, resolve_from_1.default)(projectRoot, 'babel-preset-fbjs/package.json');
94
- process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);
153
+ const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;
154
+
155
+ if (isExotic && !hasWarnedAboutExotic) {
156
+ hasWarnedAboutExotic = true;
157
+ console.log(_chalk().default.gray(`\u203A Unstable feature ${_chalk().default.bold`EXPO_USE_EXOTIC`} is enabled. Bundling may not work as expected, and is subject to breaking changes.`));
158
+ }
159
+
160
+ const MetroConfig = (0, _importMetroFromProject().importMetroConfigFromProject)(projectRoot);
161
+
162
+ const reactNativePath = _path().default.dirname((0, _resolveFrom().default)(projectRoot, 'react-native/package.json'));
163
+
164
+ try {
165
+ // Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.
166
+ // This hack is used because there doesn't appear to be anyway to resolve
167
+ // `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).
168
+ const babelPresetFbjsPath = (0, _resolveFrom().default)(projectRoot, 'babel-preset-fbjs/package.json');
169
+ process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);
170
+ } catch {// noop -- falls back to a hardcoded value.
171
+ }
172
+
173
+ const isLegacy = readIsLegacyImportsEnabled(projectRoot); // Deprecated -- SDK 41 --
174
+
175
+ if (options.target) {
176
+ if (!isLegacy) {
177
+ console.warn(_chalk().default.yellow(`The target option is deprecated. Learn more: http://expo.fyi/expo-extension-migration`));
178
+ delete options.target;
95
179
  }
96
- catch {
97
- // noop -- falls back to a hardcoded value.
180
+ } else if (process.env.EXPO_TARGET) {
181
+ console.error('EXPO_TARGET is deprecated. Learn more: http://expo.fyi/expo-extension-migration');
182
+
183
+ if (isLegacy) {
184
+ // EXPO_TARGET is used by @expo/metro-config to determine the target when getDefaultConfig is
185
+ // called from metro.config.js.
186
+ // @ts-ignore
187
+ options.target = process.env.EXPO_TARGET;
98
188
  }
99
- const isLegacy = readIsLegacyImportsEnabled(projectRoot);
100
- // Deprecated -- SDK 41 --
101
- if (options.target) {
102
- if (!isLegacy) {
103
- console.warn(chalk_1.default.yellow(`The target option is deprecated. Learn more: http://expo.fyi/expo-extension-migration`));
104
- delete options.target;
105
- }
106
- }
107
- else if (process.env.EXPO_TARGET) {
108
- console.error('EXPO_TARGET is deprecated. Learn more: http://expo.fyi/expo-extension-migration');
109
- if (isLegacy) {
110
- // EXPO_TARGET is used by @expo/metro-config to determine the target when getDefaultConfig is
111
- // called from metro.config.js.
112
- // @ts-ignore
113
- options.target = process.env.EXPO_TARGET;
114
- }
115
- }
116
- else if (isLegacy) {
117
- // Fall back to guessing based on the project structure in legacy mode.
118
- options.target = (0, config_1.getDefaultTarget)(projectRoot);
119
- }
120
- if (!options.target) {
121
- // Default to bare -- no .expo extension.
122
- options.target = 'bare';
123
- }
124
- // End deprecated -- SDK 41 --
125
- const { target } = options;
126
- if (!(target === 'managed' || target === 'bare')) {
127
- throw new Error(`Invalid target: '${target}'. Debug info: \n${JSON.stringify({
128
- 'options.target': options.target,
129
- default: (0, config_1.getDefaultTarget)(projectRoot),
130
- }, null, 2)}`);
131
- }
132
- const sourceExtsConfig = { isTS: true, isReact: true, isModern: false };
133
- const sourceExts = target === 'bare'
134
- ? (0, paths_1.getBareExtensions)([], sourceExtsConfig)
135
- : (0, paths_1.getManagedExtensions)([], sourceExtsConfig);
136
- if (isExotic) {
137
- // Add support for cjs (without platform extensions).
138
- sourceExts.push('cjs');
139
- }
140
- const babelConfigPath = getProjectBabelConfigFile(projectRoot);
141
- const isCustomBabelConfigDefined = !!babelConfigPath;
142
- const resolverMainFields = [];
143
- // Disable `react-native` in exotic mode, since library authors
144
- // use it to ship raw application code to the project.
145
- if (!isExotic) {
146
- resolverMainFields.push('react-native');
147
- }
148
- resolverMainFields.push('browser', 'main');
149
- const watchFolders = (0, getWatchFolders_1.getWatchFolders)(projectRoot);
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 = (0, getModulesPaths_1.getModulesPaths)(projectRoot);
152
- if (exports.EXPO_DEBUG) {
153
- console.log();
154
- console.log(`Expo Metro config:`);
155
- try {
156
- console.log(`- Version: ${require('../package.json').version}`);
157
- }
158
- catch { }
159
- console.log(`- Bundler target: ${target}`);
160
- console.log(`- Legacy: ${isLegacy}`);
161
- console.log(`- Extensions: ${sourceExts.join(', ')}`);
162
- console.log(`- React Native: ${reactNativePath}`);
163
- console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);
164
- console.log(`- Resolver Fields: ${resolverMainFields.join(', ')}`);
165
- console.log(`- Watch Folders: ${watchFolders.join(', ')}`);
166
- console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`);
167
- console.log(`- Exotic: ${isExotic}`);
168
- console.log();
169
- }
170
- const {
189
+ } else if (isLegacy) {
190
+ // Fall back to guessing based on the project structure in legacy mode.
191
+ options.target = (0, _config().getDefaultTarget)(projectRoot);
192
+ }
193
+
194
+ if (!options.target) {
195
+ // Default to bare -- no .expo extension.
196
+ options.target = 'bare';
197
+ } // End deprecated -- SDK 41 --
198
+
199
+
200
+ const {
201
+ target
202
+ } = options;
203
+
204
+ if (!(target === 'managed' || target === 'bare')) {
205
+ throw new Error(`Invalid target: '${target}'. Debug info: \n${JSON.stringify({
206
+ 'options.target': options.target,
207
+ default: (0, _config().getDefaultTarget)(projectRoot)
208
+ }, null, 2)}`);
209
+ }
210
+
211
+ const sourceExtsConfig = {
212
+ isTS: true,
213
+ isReact: true,
214
+ isModern: false
215
+ };
216
+ const sourceExts = target === 'bare' ? (0, _paths().getBareExtensions)([], sourceExtsConfig) : (0, _paths().getManagedExtensions)([], sourceExtsConfig);
217
+
218
+ if (isExotic) {
219
+ // Add support for cjs (without platform extensions).
220
+ sourceExts.push('cjs');
221
+ }
222
+
223
+ const babelConfigPath = getProjectBabelConfigFile(projectRoot);
224
+ const isCustomBabelConfigDefined = !!babelConfigPath;
225
+ const resolverMainFields = []; // Disable `react-native` in exotic mode, since library authors
226
+ // use it to ship raw application code to the project.
227
+
228
+ if (!isExotic) {
229
+ resolverMainFields.push('react-native');
230
+ }
231
+
232
+ resolverMainFields.push('browser', 'main');
233
+ const watchFolders = (0, _getWatchFolders().getWatchFolders)(projectRoot); // TODO: nodeModulesPaths does not work with the new Node.js package.json exports API, this causes packages like uuid to fail. Disabling for now.
234
+
235
+ const nodeModulesPaths = (0, _getModulesPaths().getModulesPaths)(projectRoot);
236
+
237
+ if (EXPO_DEBUG) {
238
+ console.log();
239
+ console.log(`Expo Metro config:`);
240
+
241
+ try {
242
+ console.log(`- Version: ${require('../package.json').version}`);
243
+ } catch {}
244
+
245
+ console.log(`- Bundler target: ${target}`);
246
+ console.log(`- Legacy: ${isLegacy}`);
247
+ console.log(`- Extensions: ${sourceExts.join(', ')}`);
248
+ console.log(`- React Native: ${reactNativePath}`);
249
+ console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);
250
+ console.log(`- Resolver Fields: ${resolverMainFields.join(', ')}`);
251
+ console.log(`- Watch Folders: ${watchFolders.join(', ')}`);
252
+ console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`);
253
+ console.log(`- Exotic: ${isExotic}`);
254
+ console.log();
255
+ }
256
+
257
+ const {
171
258
  // Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.
172
259
  // This prints a giant React logo which is less accessible to users on smaller terminals.
173
- reporter, ...metroDefaultValues } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);
174
- // Merge in the default config from Metro here, even though loadConfig uses it as defaults.
175
- // This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
176
- return MetroConfig.mergeConfig(metroDefaultValues, {
177
- watchFolders,
178
- resolver: {
179
- resolverMainFields,
180
- platforms: ['ios', 'android', 'native', 'testing'],
181
- assetExts: metroDefaultValues.resolver.assetExts.filter(assetExt => !sourceExts.includes(assetExt)),
182
- sourceExts,
183
- nodeModulesPaths,
184
- },
185
- serializer: {
186
- getModulesRunBeforeMainModule: () => [
187
- require.resolve(path_1.default.join(reactNativePath, 'Libraries/Core/InitializeCore')),
188
- // TODO: Bacon: load Expo side-effects
189
- ],
190
- getPolyfills: () => require(path_1.default.join(reactNativePath, 'rn-get-polyfills'))(),
191
- },
192
- server: {
193
- port: Number(process.env.RCT_METRO_PORT) || 8081,
194
- },
195
- symbolicator: {
196
- customizeFrame: frame => {
197
- var _a;
198
- let collapse = Boolean(frame.file && exports.INTERNAL_CALLSITES_REGEX.test(frame.file));
199
- if (!collapse) {
200
- // This represents the first frame of the stacktrace.
201
- // Often this looks like: `__r(0);`.
202
- // The URL will also be unactionable in the app and therefore not very useful to the developer.
203
- if (frame.column === 3 &&
204
- frame.methodName === 'global code' &&
205
- ((_a = frame.file) === null || _a === void 0 ? void 0 : _a.match(/^https?:\/\//g))) {
206
- collapse = true;
207
- }
208
- }
209
- return { ...(frame || {}), collapse };
210
- },
211
- },
212
- transformer: {
213
- allowOptionalDependencies: true,
214
- babelTransformerPath: isExotic
215
- ? require.resolve('./transformer/metro-expo-exotic-babel-transformer')
216
- : isCustomBabelConfigDefined
217
- ? // If the user defined a babel config file in their project,
218
- // then use the default transformer.
219
- // Try to use the project copy before falling back on the global version
220
- resolve_from_1.default.silent(projectRoot, 'metro-react-native-babel-transformer')
221
- : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.
222
- require.resolve('./transformer/metro-expo-babel-transformer'),
223
- assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
224
- assetPlugins: getAssetPlugins(projectRoot),
225
- },
226
- });
227
- }
228
- exports.getDefaultConfig = getDefaultConfig;
229
- async function loadAsync(projectRoot, { reporter, target, ...metroOptions } = {}) {
230
- let defaultConfig = getDefaultConfig(projectRoot, { target });
231
- if (reporter) {
232
- defaultConfig = { ...defaultConfig, reporter };
260
+ reporter,
261
+ ...metroDefaultValues
262
+ } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot); // Merge in the default config from Metro here, even though loadConfig uses it as defaults.
263
+ // This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
264
+
265
+ return MetroConfig.mergeConfig(metroDefaultValues, {
266
+ watchFolders,
267
+ resolver: {
268
+ resolverMainFields,
269
+ platforms: ['ios', 'android', 'native', 'testing'],
270
+ assetExts: metroDefaultValues.resolver.assetExts.filter(assetExt => !sourceExts.includes(assetExt)),
271
+ sourceExts,
272
+ nodeModulesPaths
273
+ },
274
+ serializer: {
275
+ getModulesRunBeforeMainModule: () => [require.resolve(_path().default.join(reactNativePath, 'Libraries/Core/InitializeCore')) // TODO: Bacon: load Expo side-effects
276
+ ],
277
+ getPolyfills: () => require(_path().default.join(reactNativePath, 'rn-get-polyfills'))()
278
+ },
279
+ server: {
280
+ port: Number(process.env.RCT_METRO_PORT) || 8081
281
+ },
282
+ symbolicator: {
283
+ customizeFrame: frame => {
284
+ let collapse = Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file));
285
+
286
+ if (!collapse) {
287
+ var _frame$file;
288
+
289
+ // This represents the first frame of the stacktrace.
290
+ // Often this looks like: `__r(0);`.
291
+ // The URL will also be unactionable in the app and therefore not very useful to the developer.
292
+ if (frame.column === 3 && frame.methodName === 'global code' && (_frame$file = frame.file) !== null && _frame$file !== void 0 && _frame$file.match(/^https?:\/\//g)) {
293
+ collapse = true;
294
+ }
295
+ }
296
+
297
+ return { ...(frame || {}),
298
+ collapse
299
+ };
300
+ }
301
+ },
302
+ transformer: {
303
+ allowOptionalDependencies: true,
304
+ babelTransformerPath: isExotic ? require.resolve('./transformer/metro-expo-exotic-babel-transformer') : isCustomBabelConfigDefined ? // If the user defined a babel config file in their project,
305
+ // then use the default transformer.
306
+ // Try to use the project copy before falling back on the global version
307
+ _resolveFrom().default.silent(projectRoot, 'metro-react-native-babel-transformer') : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.
308
+ require.resolve('./transformer/metro-expo-babel-transformer'),
309
+ assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
310
+ assetPlugins: getAssetPlugins(projectRoot)
233
311
  }
234
- const MetroConfig = (0, importMetroFromProject_1.importMetroConfigFromProject)(projectRoot);
235
- return await MetroConfig.loadConfig({ cwd: projectRoot, projectRoot, ...metroOptions }, defaultConfig);
312
+ });
313
+ }
314
+
315
+ async function loadAsync(projectRoot, {
316
+ reporter,
317
+ target,
318
+ ...metroOptions
319
+ } = {}) {
320
+ let defaultConfig = getDefaultConfig(projectRoot, {
321
+ target
322
+ });
323
+
324
+ if (reporter) {
325
+ defaultConfig = { ...defaultConfig,
326
+ reporter
327
+ };
328
+ }
329
+
330
+ const MetroConfig = (0, _importMetroFromProject().importMetroConfigFromProject)(projectRoot);
331
+ return await MetroConfig.loadConfig({
332
+ cwd: projectRoot,
333
+ projectRoot,
334
+ ...metroOptions
335
+ }, defaultConfig);
236
336
  }
237
- exports.loadAsync = loadAsync;
238
337
  //# sourceMappingURL=ExpoMetroConfig.js.map