@expo/metro-config 0.5.2 → 0.6.0

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.
Files changed (29) hide show
  1. package/build/ExpoMetroConfig.d.ts +1 -4
  2. package/build/ExpoMetroConfig.js +54 -144
  3. package/build/ExpoMetroConfig.js.map +1 -1
  4. package/build/getModulesPaths.js +3 -14
  5. package/build/getModulesPaths.js.map +1 -1
  6. package/build/getWatchFolders.js +32 -48
  7. package/build/getWatchFolders.js.map +1 -1
  8. package/build/importMetroFromProject.js +0 -13
  9. package/build/importMetroFromProject.js.map +1 -1
  10. package/build/transformer/createExoticTransformer.js +21 -24
  11. package/build/transformer/createExoticTransformer.js.map +1 -1
  12. package/build/transformer/createMatcher.js +14 -14
  13. package/build/transformer/createMatcher.js.map +1 -1
  14. package/build/transformer/createMultiRuleTransformer.d.ts +1 -1
  15. package/build/transformer/createMultiRuleTransformer.js +78 -101
  16. package/build/transformer/createMultiRuleTransformer.js.map +1 -1
  17. package/build/transformer/generateFunctionMap.js +0 -5
  18. package/build/transformer/generateFunctionMap.js.map +1 -1
  19. package/build/transformer/getBabelConfig.js +26 -40
  20. package/build/transformer/getBabelConfig.js.map +1 -1
  21. package/build/transformer/getCacheKey.js +6 -13
  22. package/build/transformer/getCacheKey.js.map +1 -1
  23. package/build/transformer/index.js +0 -12
  24. package/build/transformer/index.js.map +1 -1
  25. package/build/transformer/metro-expo-babel-transformer.js +2 -14
  26. package/build/transformer/metro-expo-babel-transformer.js.map +1 -1
  27. package/build/transformer/metro-expo-exotic-babel-transformer.js +1 -3
  28. package/build/transformer/metro-expo-exotic-babel-transformer.js.map +1 -1
  29. package/package.json +3 -4
@@ -1,10 +1,8 @@
1
- import { ProjectTarget } from '@expo/config';
2
1
  import { Reporter } from 'metro';
3
2
  import type MetroConfig from 'metro-config';
4
3
  export declare const EXPO_DEBUG: boolean;
5
4
  export declare const INTERNAL_CALLSITES_REGEX: RegExp;
6
5
  export interface DefaultConfigOptions {
7
- target?: ProjectTarget;
8
6
  mode?: 'exotic';
9
7
  }
10
8
  export declare function getDefaultConfig(projectRoot: string, options?: DefaultConfigOptions): MetroConfig.InputConfigT;
@@ -14,6 +12,5 @@ export interface LoadOptions {
14
12
  port?: number;
15
13
  reporter?: Reporter;
16
14
  resetCache?: boolean;
17
- target?: ProjectTarget;
18
15
  }
19
- export declare function loadAsync(projectRoot: string, { reporter, target, ...metroOptions }?: LoadOptions): Promise<MetroConfig.ConfigT>;
16
+ export declare function loadAsync(projectRoot: string, { reporter, ...metroOptions }?: LoadOptions): Promise<MetroConfig.ConfigT>;
@@ -6,128 +6,101 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = void 0;
7
7
  exports.getDefaultConfig = getDefaultConfig;
8
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
9
  function _paths() {
21
10
  const data = require("@expo/config/paths");
22
-
23
11
  _paths = function () {
24
12
  return data;
25
13
  };
26
-
27
14
  return data;
28
15
  }
29
-
30
16
  function _chalk() {
31
17
  const data = _interopRequireDefault(require("chalk"));
32
-
33
18
  _chalk = function () {
34
19
  return data;
35
20
  };
36
-
37
21
  return data;
38
22
  }
39
-
40
23
  function _getenv() {
41
24
  const data = require("getenv");
42
-
43
25
  _getenv = function () {
44
26
  return data;
45
27
  };
46
-
47
28
  return data;
48
29
  }
49
-
50
30
  function _path() {
51
31
  const data = _interopRequireDefault(require("path"));
52
-
53
32
  _path = function () {
54
33
  return data;
55
34
  };
56
-
57
35
  return data;
58
36
  }
59
-
60
37
  function _resolveFrom() {
61
38
  const data = _interopRequireDefault(require("resolve-from"));
62
-
63
39
  _resolveFrom = function () {
64
40
  return data;
65
41
  };
66
-
67
42
  return data;
68
43
  }
69
-
70
44
  function _url() {
71
45
  const data = require("url");
72
-
73
46
  _url = function () {
74
47
  return data;
75
48
  };
76
-
77
49
  return data;
78
50
  }
79
-
80
51
  function _getModulesPaths() {
81
52
  const data = require("./getModulesPaths");
82
-
83
53
  _getModulesPaths = function () {
84
54
  return data;
85
55
  };
86
-
87
56
  return data;
88
57
  }
89
-
90
58
  function _getWatchFolders() {
91
59
  const data = require("./getWatchFolders");
92
-
93
60
  _getWatchFolders = function () {
94
61
  return data;
95
62
  };
96
-
97
63
  return data;
98
64
  }
99
-
100
65
  function _importMetroFromProject() {
101
66
  const data = require("./importMetroFromProject");
102
-
103
67
  _importMetroFromProject = function () {
104
68
  return data;
105
69
  };
106
-
107
70
  return data;
108
71
  }
109
-
110
72
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
111
-
112
73
  // Copyright 2021-present 650 Industries (Expo). All rights reserved.
74
+
113
75
  const EXPO_DEBUG = (0, _getenv().boolish)('EXPO_DEBUG', false);
114
76
  exports.EXPO_DEBUG = EXPO_DEBUG;
115
- 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.
77
+ const EXPO_USE_EXOTIC = (0, _getenv().boolish)('EXPO_USE_EXOTIC', false);
116
78
 
117
- 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,
79
+ // Import only the types here, the values will be imported from the project, at runtime.
80
+ 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$',
81
+ // Metro replaces `require()` with a different method,
118
82
  // we want to omit this method from the stack trace.
119
83
  // This is akin to most React tooling.
120
- '/metro/.*/polyfills/require.js$', // Hide frames related to a fast refresh.
121
- '/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 package.
122
- '/expo/build/logs/RemoteConsole.js$', // Improve errors thrown by invariant (ex: `Invariant Violation: "main" has not been registered`).
123
- 'node_modules/invariant/.+\\.js$', // Remove babel runtime additions
124
- 'node_modules/regenerator-runtime/.+\\.js$', // Remove react native setImmediate ponyfill
125
- 'node_modules/promise/setimmediate/.+\\.js$', // Babel helpers that implement language features
126
- 'node_modules/@babel/runtime/.+\\.js$', // Hide Hermes internal bytecode
127
- '/InternalBytecode/InternalBytecode\\.js$', // Block native code invocations
128
- `\\[native code\\]`].join('|'));
84
+ '/metro/.*/polyfills/require.js$',
85
+ // Hide frames related to a fast refresh.
86
+ '/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$',
87
+ // Ignore the log forwarder used in the expo package.
88
+ '/expo/build/logs/RemoteConsole.js$',
89
+ // Improve errors thrown by invariant (ex: `Invariant Violation: "main" has not been registered`).
90
+ 'node_modules/invariant/.+\\.js$',
91
+ // Remove babel runtime additions
92
+ 'node_modules/regenerator-runtime/.+\\.js$',
93
+ // Remove react native setImmediate ponyfill
94
+ 'node_modules/promise/setimmediate/.+\\.js$',
95
+ // Babel helpers that implement language features
96
+ 'node_modules/@babel/runtime/.+\\.js$',
97
+ // Hide Hermes internal bytecode
98
+ '/InternalBytecode/InternalBytecode\\.js$',
99
+ // Block native code invocations
100
+ `\\[native code\\]`,
101
+ // Hide react-dom (web)
102
+ 'node_modules/react-dom/.+\\.js$'].join('|'));
129
103
  exports.INTERNAL_CALLSITES_REGEX = INTERNAL_CALLSITES_REGEX;
130
-
131
104
  function isUrl(value) {
132
105
  try {
133
106
  // eslint-disable-next-line no-new
@@ -137,134 +110,72 @@ function isUrl(value) {
137
110
  return false;
138
111
  }
139
112
  }
140
-
141
- function readIsLegacyImportsEnabled(projectRoot) {
142
- const config = (0, _config().getConfig)(projectRoot, {
143
- skipSDKVersionRequirement: true
144
- });
145
- return (0, _config().isLegacyImportsEnabled)(config.exp);
146
- }
147
-
148
113
  function getProjectBabelConfigFile(projectRoot) {
149
114
  return _resolveFrom().default.silent(projectRoot, './babel.config.js') || _resolveFrom().default.silent(projectRoot, './.babelrc') || _resolveFrom().default.silent(projectRoot, './.babelrc.js');
150
115
  }
151
-
152
116
  function getAssetPlugins(projectRoot) {
153
117
  const assetPlugins = [];
154
118
  let hashAssetFilesPath;
155
-
156
119
  try {
157
120
  hashAssetFilesPath = (0, _resolveFrom().default)(projectRoot, 'expo-asset/tools/hashAssetFiles');
158
- } catch {// TODO: we should warn/throw an error if the user has expo-updates installed but does not
121
+ } catch {
122
+ // TODO: we should warn/throw an error if the user has expo-updates installed but does not
159
123
  // have hashAssetFiles available, or if the user is in managed workflow and does not have
160
124
  // hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,
161
125
  // it is not needed
162
126
  }
163
-
164
127
  if (hashAssetFilesPath) {
165
128
  assetPlugins.push(hashAssetFilesPath);
166
129
  }
167
-
168
130
  return assetPlugins;
169
131
  }
170
-
171
132
  let hasWarnedAboutExotic = false;
172
-
173
133
  function getDefaultConfig(projectRoot, options = {}) {
174
134
  const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;
175
-
176
135
  if (isExotic && !hasWarnedAboutExotic) {
177
136
  hasWarnedAboutExotic = true;
178
137
  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.`));
179
138
  }
180
-
181
139
  const MetroConfig = (0, _importMetroFromProject().importMetroConfigFromProject)(projectRoot);
182
-
183
140
  const reactNativePath = _path().default.dirname((0, _resolveFrom().default)(projectRoot, 'react-native/package.json'));
184
-
185
141
  try {
186
142
  // Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.
187
143
  // This hack is used because there doesn't appear to be anyway to resolve
188
144
  // `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).
189
145
  const babelPresetFbjsPath = (0, _resolveFrom().default)(projectRoot, 'babel-preset-fbjs/package.json');
190
146
  process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);
191
- } catch {// noop -- falls back to a hardcoded value.
192
- }
193
-
194
- const isLegacy = readIsLegacyImportsEnabled(projectRoot); // Deprecated -- SDK 41 --
195
-
196
- if (options.target) {
197
- if (!isLegacy) {
198
- console.warn(_chalk().default.yellow(`The target option is deprecated. Learn more: http://expo.fyi/expo-extension-migration`));
199
- delete options.target;
200
- }
201
- } else if (process.env.EXPO_TARGET) {
202
- console.error('EXPO_TARGET is deprecated. Learn more: http://expo.fyi/expo-extension-migration');
203
-
204
- if (isLegacy) {
205
- // EXPO_TARGET is used by @expo/metro-config to determine the target when getDefaultConfig is
206
- // called from metro.config.js.
207
- // @ts-ignore
208
- options.target = process.env.EXPO_TARGET;
209
- }
210
- } else if (isLegacy) {
211
- // Fall back to guessing based on the project structure in legacy mode.
212
- options.target = (0, _config().getDefaultTarget)(projectRoot);
213
- }
214
-
215
- if (!options.target) {
216
- // Default to bare -- no .expo extension.
217
- options.target = 'bare';
218
- } // End deprecated -- SDK 41 --
219
-
220
-
221
- const {
222
- target
223
- } = options;
224
-
225
- if (!(target === 'managed' || target === 'bare')) {
226
- throw new Error(`Invalid target: '${target}'. Debug info: \n${JSON.stringify({
227
- 'options.target': options.target,
228
- default: (0, _config().getDefaultTarget)(projectRoot)
229
- }, null, 2)}`);
147
+ } catch {
148
+ // noop -- falls back to a hardcoded value.
230
149
  }
231
-
232
150
  const sourceExtsConfig = {
233
151
  isTS: true,
234
152
  isReact: true,
235
153
  isModern: false
236
154
  };
237
- const sourceExts = target === 'bare' ? (0, _paths().getBareExtensions)([], sourceExtsConfig) : (0, _paths().getManagedExtensions)([], sourceExtsConfig);
238
-
155
+ const sourceExts = (0, _paths().getBareExtensions)([], sourceExtsConfig);
239
156
  if (isExotic) {
240
157
  // Add support for cjs (without platform extensions).
241
158
  sourceExts.push('cjs');
242
159
  }
243
-
244
160
  const babelConfigPath = getProjectBabelConfigFile(projectRoot);
245
161
  const isCustomBabelConfigDefined = !!babelConfigPath;
246
- const resolverMainFields = []; // Disable `react-native` in exotic mode, since library authors
247
- // use it to ship raw application code to the project.
162
+ const resolverMainFields = [];
248
163
 
164
+ // Disable `react-native` in exotic mode, since library authors
165
+ // use it to ship raw application code to the project.
249
166
  if (!isExotic) {
250
167
  resolverMainFields.push('react-native');
251
168
  }
252
-
253
169
  resolverMainFields.push('browser', 'main');
254
- 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.
255
-
170
+ const watchFolders = (0, _getWatchFolders().getWatchFolders)(projectRoot);
171
+ // TODO: nodeModulesPaths does not work with the new Node.js package.json exports API, this causes packages like uuid to fail. Disabling for now.
256
172
  const nodeModulesPaths = (0, _getModulesPaths().getModulesPaths)(projectRoot);
257
-
258
173
  if (EXPO_DEBUG) {
259
174
  console.log();
260
175
  console.log(`Expo Metro config:`);
261
-
262
176
  try {
263
177
  console.log(`- Version: ${require('../package.json').version}`);
264
178
  } catch {}
265
-
266
- console.log(`- Bundler target: ${target}`);
267
- console.log(`- Legacy: ${isLegacy}`);
268
179
  console.log(`- Extensions: ${sourceExts.join(', ')}`);
269
180
  console.log(`- React Native: ${reactNativePath}`);
270
181
  console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);
@@ -274,27 +185,31 @@ function getDefaultConfig(projectRoot, options = {}) {
274
185
  console.log(`- Exotic: ${isExotic}`);
275
186
  console.log();
276
187
  }
277
-
278
188
  const {
279
189
  // Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.
280
190
  // This prints a giant React logo which is less accessible to users on smaller terminals.
281
191
  reporter,
282
192
  ...metroDefaultValues
283
- } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot); // Merge in the default config from Metro here, even though loadConfig uses it as defaults.
284
- // This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
193
+ } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);
285
194
 
195
+ // Merge in the default config from Metro here, even though loadConfig uses it as defaults.
196
+ // This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
286
197
  return MetroConfig.mergeConfig(metroDefaultValues, {
287
198
  watchFolders,
288
199
  resolver: {
289
200
  resolverMainFields,
290
201
  platforms: ['ios', 'android', 'native', 'testing'],
291
- assetExts: metroDefaultValues.resolver.assetExts.filter(assetExt => !sourceExts.includes(assetExt)),
202
+ assetExts: metroDefaultValues.resolver.assetExts.concat(
203
+ // Add default support for `expo-image` file types.
204
+ ['heic', 'avif']).filter(assetExt => !sourceExts.includes(assetExt)),
292
205
  sourceExts,
293
206
  nodeModulesPaths
294
207
  },
295
208
  serializer: {
296
- getModulesRunBeforeMainModule: () => [require.resolve(_path().default.join(reactNativePath, 'Libraries/Core/InitializeCore')) // TODO: Bacon: load Expo side-effects
209
+ getModulesRunBeforeMainModule: () => [require.resolve(_path().default.join(reactNativePath, 'Libraries/Core/InitializeCore'))
210
+ // TODO: Bacon: load Expo side-effects
297
211
  ],
212
+
298
213
  getPolyfills: () => require(_path().default.join(reactNativePath, 'rn-get-polyfills'))()
299
214
  },
300
215
  server: {
@@ -303,7 +218,8 @@ function getDefaultConfig(projectRoot, options = {}) {
303
218
  symbolicator: {
304
219
  customizeFrame: frame => {
305
220
  if (frame.file && isUrl(frame.file)) {
306
- return { ...frame,
221
+ return {
222
+ ...frame,
307
223
  // HACK: This prevents Metro from attempting to read the invalid file URL it sent us.
308
224
  lineNumber: null,
309
225
  column: null,
@@ -311,12 +227,9 @@ function getDefaultConfig(projectRoot, options = {}) {
311
227
  collapse: true
312
228
  };
313
229
  }
314
-
315
230
  let collapse = Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file));
316
-
317
231
  if (!collapse) {
318
232
  var _frame$file;
319
-
320
233
  // This represents the first frame of the stacktrace.
321
234
  // Often this looks like: `__r(0);`.
322
235
  // The URL will also be unactionable in the app and therefore not very useful to the developer.
@@ -324,8 +237,8 @@ function getDefaultConfig(projectRoot, options = {}) {
324
237
  collapse = true;
325
238
  }
326
239
  }
327
-
328
- return { ...(frame || {}),
240
+ return {
241
+ ...(frame || {}),
329
242
  collapse
330
243
  };
331
244
  }
@@ -334,32 +247,29 @@ function getDefaultConfig(projectRoot, options = {}) {
334
247
  // `require.context` support
335
248
  unstable_allowRequireContext: true,
336
249
  allowOptionalDependencies: true,
337
- babelTransformerPath: isExotic ? require.resolve('./transformer/metro-expo-exotic-babel-transformer') : isCustomBabelConfigDefined ? // If the user defined a babel config file in their project,
250
+ babelTransformerPath: isExotic ? require.resolve('./transformer/metro-expo-exotic-babel-transformer') : isCustomBabelConfigDefined ?
251
+ // If the user defined a babel config file in their project,
338
252
  // then use the default transformer.
339
253
  // Try to use the project copy before falling back on the global version
340
- _resolveFrom().default.silent(projectRoot, 'metro-react-native-babel-transformer') : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.
254
+ _resolveFrom().default.silent(projectRoot, 'metro-react-native-babel-transformer') :
255
+ // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.
341
256
  require.resolve('./transformer/metro-expo-babel-transformer'),
342
257
  assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
343
258
  assetPlugins: getAssetPlugins(projectRoot)
344
259
  }
345
260
  });
346
261
  }
347
-
348
262
  async function loadAsync(projectRoot, {
349
263
  reporter,
350
- target,
351
264
  ...metroOptions
352
265
  } = {}) {
353
- let defaultConfig = getDefaultConfig(projectRoot, {
354
- target
355
- });
356
-
266
+ let defaultConfig = getDefaultConfig(projectRoot);
357
267
  if (reporter) {
358
- defaultConfig = { ...defaultConfig,
268
+ defaultConfig = {
269
+ ...defaultConfig,
359
270
  reporter
360
271
  };
361
272
  }
362
-
363
273
  const MetroConfig = (0, _importMetroFromProject().importMetroConfigFromProject)(projectRoot);
364
274
  return await MetroConfig.loadConfig({
365
275
  cwd: projectRoot,
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoMetroConfig.js","names":["EXPO_DEBUG","boolish","EXPO_USE_EXOTIC","INTERNAL_CALLSITES_REGEX","RegExp","join","isUrl","value","URL","readIsLegacyImportsEnabled","projectRoot","config","getConfig","skipSDKVersionRequirement","isLegacyImportsEnabled","exp","getProjectBabelConfigFile","resolveFrom","silent","getAssetPlugins","assetPlugins","hashAssetFilesPath","push","hasWarnedAboutExotic","getDefaultConfig","options","isExotic","mode","console","log","chalk","gray","bold","MetroConfig","importMetroConfigFromProject","reactNativePath","path","dirname","babelPresetFbjsPath","process","env","EXPO_METRO_CACHE_KEY_VERSION","String","require","version","isLegacy","target","warn","yellow","EXPO_TARGET","error","getDefaultTarget","Error","JSON","stringify","default","sourceExtsConfig","isTS","isReact","isModern","sourceExts","getBareExtensions","getManagedExtensions","babelConfigPath","isCustomBabelConfigDefined","resolverMainFields","watchFolders","getWatchFolders","nodeModulesPaths","getModulesPaths","reporter","metroDefaultValues","getDefaultValues","mergeConfig","resolver","platforms","assetExts","filter","assetExt","includes","serializer","getModulesRunBeforeMainModule","resolve","getPolyfills","server","port","Number","RCT_METRO_PORT","symbolicator","customizeFrame","frame","file","lineNumber","column","collapse","Boolean","test","methodName","match","transformer","unstable_allowRequireContext","allowOptionalDependencies","babelTransformerPath","assetRegistryPath","loadAsync","metroOptions","defaultConfig","loadConfig","cwd"],"sources":["../src/ExpoMetroConfig.ts"],"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';\nimport { URL } from 'url';\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 '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 package.\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 // Hide Hermes internal bytecode\n '/InternalBytecode/InternalBytecode\\\\.js$',\n // Block native code invocations\n `\\\\[native code\\\\]`,\n ].join('|')\n);\n\nfunction isUrl(value: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(value);\n return true;\n } catch {\n return false;\n }\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 if (frame.file && isUrl(frame.file)) {\n return {\n ...frame,\n // HACK: This prevents Metro from attempting to read the invalid file URL it sent us.\n lineNumber: null,\n column: null,\n // This prevents the invalid frame from being shown by default.\n collapse: true,\n };\n }\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 // `require.context` support\n unstable_allowRequireContext: true,\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);\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R,CAAgB,mDAAhB,CAD0B,GAE1BlB,0BAA0B,GAC1B;MACA;MACA;MACA/C,sBAAA,CAAYC,MAAZ,CAAmBR,WAAnB,EAAgC,sCAAhC,CAJ0B,GAK1B;MACAiC,OAAO,CAACuC,OAAR,CAAgB,4CAAhB,CAZO;MAaXqB,iBAAiB,EAAE,4CAbR;MAcXnF,YAAY,EAAED,eAAe,CAACT,WAAD;IAdlB;EAnDoC,CAA5C,CAAP;AAoED;;AAWM,eAAe8F,SAAf,CACL9F,WADK,EAEL;EAAE4D,QAAF;EAAYxB,MAAZ;EAAoB,GAAG2D;AAAvB,IAAqD,EAFhD,EAGyB;EAC9B,IAAIC,aAAa,GAAGlF,gBAAgB,CAACd,WAAD,EAAc;IAAEoC;EAAF,CAAd,CAApC;;EACA,IAAIwB,QAAJ,EAAc;IACZoC,aAAa,GAAG,EAAE,GAAGA,aAAL;MAAoBpC;IAApB,CAAhB;EACD;;EACD,MAAMrC,WAAW,GAAG,IAAAC,sDAAA,EAA6BxB,WAA7B,CAApB;EACA,OAAO,MAAMuB,WAAW,CAAC0E,UAAZ,CACX;IAAEC,GAAG,EAAElG,WAAP;IAAoBA,WAApB;IAAiC,GAAG+F;EAApC,CADW,EAEXC,aAFW,CAAb;AAID"}
1
+ {"version":3,"file":"ExpoMetroConfig.js","names":["EXPO_DEBUG","boolish","EXPO_USE_EXOTIC","INTERNAL_CALLSITES_REGEX","RegExp","join","isUrl","value","URL","getProjectBabelConfigFile","projectRoot","resolveFrom","silent","getAssetPlugins","assetPlugins","hashAssetFilesPath","push","hasWarnedAboutExotic","getDefaultConfig","options","isExotic","mode","console","log","chalk","gray","bold","MetroConfig","importMetroConfigFromProject","reactNativePath","path","dirname","babelPresetFbjsPath","process","env","EXPO_METRO_CACHE_KEY_VERSION","String","require","version","sourceExtsConfig","isTS","isReact","isModern","sourceExts","getBareExtensions","babelConfigPath","isCustomBabelConfigDefined","resolverMainFields","watchFolders","getWatchFolders","nodeModulesPaths","getModulesPaths","reporter","metroDefaultValues","getDefaultValues","mergeConfig","resolver","platforms","assetExts","concat","filter","assetExt","includes","serializer","getModulesRunBeforeMainModule","resolve","getPolyfills","server","port","Number","RCT_METRO_PORT","symbolicator","customizeFrame","frame","file","lineNumber","column","collapse","Boolean","test","methodName","match","transformer","unstable_allowRequireContext","allowOptionalDependencies","babelTransformerPath","assetRegistryPath","loadAsync","metroOptions","defaultConfig","loadConfig","cwd"],"sources":["../src/ExpoMetroConfig.ts"],"sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport { getBareExtensions } 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';\nimport { URL } from 'url';\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 '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 package.\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 // Hide Hermes internal bytecode\n '/InternalBytecode/InternalBytecode\\\\.js$',\n // Block native code invocations\n `\\\\[native code\\\\]`,\n // Hide react-dom (web)\n 'node_modules/react-dom/.+\\\\.js$',\n ].join('|')\n);\n\nfunction isUrl(value: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new URL(value);\n return true;\n } catch {\n return false;\n }\n}\n\nexport interface DefaultConfigOptions {\n mode?: 'exotic';\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 sourceExtsConfig = { isTS: true, isReact: true, isModern: false };\n const sourceExts = getBareExtensions([], 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(`- 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\n .concat(\n // Add default support for `expo-image` file types.\n ['heic', 'avif']\n )\n .filter((assetExt) => !sourceExts.includes(assetExt)),\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 if (frame.file && isUrl(frame.file)) {\n return {\n ...frame,\n // HACK: This prevents Metro from attempting to read the invalid file URL it sent us.\n lineNumber: null,\n column: null,\n // This prevents the invalid frame from being shown by default.\n collapse: true,\n };\n }\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 // `require.context` support\n unstable_allowRequireContext: true,\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}\n\nexport async function loadAsync(\n projectRoot: string,\n { reporter, ...metroOptions }: LoadOptions = {}\n): Promise<MetroConfig.ConfigT> {\n let defaultConfig = getDefaultConfig(projectRoot);\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"],"mappings":";;;;;;;;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAwE;AAbxE;;AAeO,MAAMA,UAAU,GAAG,IAAAC,iBAAO,EAAC,YAAY,EAAE,KAAK,CAAC;AAAC;AACvD,MAAMC,eAAe,GAAG,IAAAD,iBAAO,EAAC,iBAAiB,EAAE,KAAK,CAAC;;AAEzD;AACO,MAAME,wBAAwB,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AAI,wCAAV,YAAYO,KAAK,CAAC,eAAe,CAAC,EAClC;YACAJ,QAAQ,GAAG,IAAI;UACjB;QACF;QAEA,OAAO;UAAE,IAAIJ,KAAK,IAAI,CAAC,CAAC,CAAC;UAAEI;QAAS,CAAC;MACvC;IACF,CAAC;IACDK,WAAW,EAAE;MACX;MACAC,4BAA4B,EAAE,IAAI;MAClCC,yBAAyB,EAAE,IAAI;MAC/BC,oBAAoB,EAAEjE,QAAQ,GAC1BiB,OAAO,CAAC4B,OAAO,CAAC,mDAAmD,CAAC,GACpEnB,0BAA0B;MAC1B;MACA;MACA;MACAnC,sBAAW,CAACC,MAAM,CAACF,WAAW,EAAE,sCAAsC,CAAC;MACvE;MACA2B,OAAO,CAAC4B,OAAO,CAAC,4CAA4C,CAAC;MACjEqB,iBAAiB,EAAE,4CAA4C;MAC/DxE,YAAY,EAAED,eAAe,CAACH,WAAW;IAC3C;EACF,CAAC,CAAC;AACJ;AAUO,eAAe6E,SAAS,CAC7B7E,WAAmB,EACnB;EAAE0C,QAAQ;EAAE,GAAGoC;AAA0B,CAAC,GAAG,CAAC,CAAC,EACjB;EAC9B,IAAIC,aAAa,GAAGvE,gBAAgB,CAACR,WAAW,CAAC;EACjD,IAAI0C,QAAQ,EAAE;IACZqC,aAAa,GAAG;MAAE,GAAGA,aAAa;MAAErC;IAAS,CAAC;EAChD;EACA,MAAMzB,WAAW,GAAG,IAAAC,sDAA4B,EAAClB,WAAW,CAAC;EAC7D,OAAO,MAAMiB,WAAW,CAAC+D,UAAU,CACjC;IAAEC,GAAG,EAAEjF,WAAW;IAAEA,WAAW;IAAE,GAAG8E;EAAa,CAAC,EAClDC,aAAa,CACd;AACH"}
@@ -5,29 +5,21 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getModulesPaths = getModulesPaths;
7
7
  exports.getWorkspaceRoot = getWorkspaceRoot;
8
-
9
8
  function _findYarnWorkspaceRoot() {
10
9
  const data = _interopRequireDefault(require("find-yarn-workspace-root"));
11
-
12
10
  _findYarnWorkspaceRoot = function () {
13
11
  return data;
14
12
  };
15
-
16
13
  return data;
17
14
  }
18
-
19
15
  function _path() {
20
16
  const data = _interopRequireDefault(require("path"));
21
-
22
17
  _path = function () {
23
18
  return data;
24
19
  };
25
-
26
20
  return data;
27
21
  }
28
-
29
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
31
23
  /** Wraps `findWorkspaceRoot` and guards against having an empty `package.json` file in an upper directory. */
32
24
  function getWorkspaceRoot(projectRoot) {
33
25
  try {
@@ -36,22 +28,19 @@ function getWorkspaceRoot(projectRoot) {
36
28
  if (error.message.includes('Unexpected end of JSON input')) {
37
29
  return null;
38
30
  }
39
-
40
31
  throw error;
41
32
  }
42
33
  }
43
-
44
34
  function getModulesPaths(projectRoot) {
45
- const paths = []; // Only add the project root if it's not the current working directory
46
- // this minimizes the chance of Metro resolver breaking on new Node.js versions.
35
+ const paths = [];
47
36
 
37
+ // Only add the project root if it's not the current working directory
38
+ // this minimizes the chance of Metro resolver breaking on new Node.js versions.
48
39
  const workspaceRoot = getWorkspaceRoot(_path().default.resolve(projectRoot)); // Absolute path or null
49
-
50
40
  if (workspaceRoot) {
51
41
  paths.push(_path().default.resolve(projectRoot));
52
42
  paths.push(_path().default.resolve(workspaceRoot, 'node_modules'));
53
43
  }
54
-
55
44
  return paths;
56
45
  }
57
46
  //# sourceMappingURL=getModulesPaths.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getModulesPaths.js","names":["getWorkspaceRoot","projectRoot","findWorkspaceRoot","error","message","includes","getModulesPaths","paths","workspaceRoot","path","resolve","push"],"sources":["../src/getModulesPaths.ts"],"sourcesContent":["import findWorkspaceRoot from 'find-yarn-workspace-root';\nimport path from 'path';\n\n/** Wraps `findWorkspaceRoot` and guards against having an empty `package.json` file in an upper directory. */\nexport function getWorkspaceRoot(projectRoot: string): string | null {\n try {\n return findWorkspaceRoot(projectRoot);\n } catch (error: any) {\n if (error.message.includes('Unexpected end of JSON input')) {\n return null;\n }\n throw error;\n }\n}\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 = getWorkspaceRoot(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"],"mappings":";;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;AAEA;AACO,SAASA,gBAAT,CAA0BC,WAA1B,EAA8D;EACnE,IAAI;IACF,OAAO,IAAAC,gCAAA,EAAkBD,WAAlB,CAAP;EACD,CAFD,CAEE,OAAOE,KAAP,EAAmB;IACnB,IAAIA,KAAK,CAACC,OAAN,CAAcC,QAAd,CAAuB,8BAAvB,CAAJ,EAA4D;MAC1D,OAAO,IAAP;IACD;;IACD,MAAMF,KAAN;EACD;AACF;;AAEM,SAASG,eAAT,CAAyBL,WAAzB,EAAwD;EAC7D,MAAMM,KAAe,GAAG,EAAxB,CAD6D,CAG7D;EACA;;EACA,MAAMC,aAAa,GAAGR,gBAAgB,CAACS,eAAA,CAAKC,OAAL,CAAaT,WAAb,CAAD,CAAtC,CAL6D,CAKM;;EACnE,IAAIO,aAAJ,EAAmB;IACjBD,KAAK,CAACI,IAAN,CAAWF,eAAA,CAAKC,OAAL,CAAaT,WAAb,CAAX;IACAM,KAAK,CAACI,IAAN,CAAWF,eAAA,CAAKC,OAAL,CAAaF,aAAb,EAA4B,cAA5B,CAAX;EACD;;EAED,OAAOD,KAAP;AACD"}
1
+ {"version":3,"file":"getModulesPaths.js","names":["getWorkspaceRoot","projectRoot","findWorkspaceRoot","error","message","includes","getModulesPaths","paths","workspaceRoot","path","resolve","push"],"sources":["../src/getModulesPaths.ts"],"sourcesContent":["import findWorkspaceRoot from 'find-yarn-workspace-root';\nimport path from 'path';\n\n/** Wraps `findWorkspaceRoot` and guards against having an empty `package.json` file in an upper directory. */\nexport function getWorkspaceRoot(projectRoot: string): string | null {\n try {\n return findWorkspaceRoot(projectRoot);\n } catch (error: any) {\n if (error.message.includes('Unexpected end of JSON input')) {\n return null;\n }\n throw error;\n }\n}\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 = getWorkspaceRoot(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"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAwB;AAExB;AACO,SAASA,gBAAgB,CAACC,WAAmB,EAAiB;EACnE,IAAI;IACF,OAAO,IAAAC,gCAAiB,EAACD,WAAW,CAAC;EACvC,CAAC,CAAC,OAAOE,KAAU,EAAE;IACnB,IAAIA,KAAK,CAACC,OAAO,CAACC,QAAQ,CAAC,8BAA8B,CAAC,EAAE;MAC1D,OAAO,IAAI;IACb;IACA,MAAMF,KAAK;EACb;AACF;AAEO,SAASG,eAAe,CAACL,WAAmB,EAAY;EAC7D,MAAMM,KAAe,GAAG,EAAE;;EAE1B;EACA;EACA,MAAMC,aAAa,GAAGR,gBAAgB,CAACS,eAAI,CAACC,OAAO,CAACT,WAAW,CAAC,CAAC,CAAC,CAAC;EACnE,IAAIO,aAAa,EAAE;IACjBD,KAAK,CAACI,IAAI,CAACF,eAAI,CAACC,OAAO,CAACT,WAAW,CAAC,CAAC;IACrCM,KAAK,CAACI,IAAI,CAACF,eAAI,CAACC,OAAO,CAACF,aAAa,EAAE,cAAc,CAAC,CAAC;EACzD;EAEA,OAAOD,KAAK;AACd"}