@expo/metro-config 0.5.2 → 0.7.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.
- package/build/ExpoMetroConfig.d.ts +1 -4
- package/build/ExpoMetroConfig.js +61 -145
- package/build/ExpoMetroConfig.js.map +1 -1
- package/build/getModulesPaths.js +3 -14
- package/build/getModulesPaths.js.map +1 -1
- package/build/getWatchFolders.js +32 -48
- package/build/getWatchFolders.js.map +1 -1
- package/build/importMetroFromProject.js +0 -13
- package/build/importMetroFromProject.js.map +1 -1
- package/build/transformer/createExoticTransformer.js +21 -24
- package/build/transformer/createExoticTransformer.js.map +1 -1
- package/build/transformer/createMatcher.js +14 -14
- package/build/transformer/createMatcher.js.map +1 -1
- package/build/transformer/createMultiRuleTransformer.d.ts +1 -1
- package/build/transformer/createMultiRuleTransformer.js +78 -101
- package/build/transformer/createMultiRuleTransformer.js.map +1 -1
- package/build/transformer/generateFunctionMap.js +0 -5
- package/build/transformer/generateFunctionMap.js.map +1 -1
- package/build/transformer/getBabelConfig.js +26 -40
- package/build/transformer/getBabelConfig.js.map +1 -1
- package/build/transformer/getCacheKey.js +6 -13
- package/build/transformer/getCacheKey.js.map +1 -1
- package/build/transformer/index.js +0 -12
- package/build/transformer/index.js.map +1 -1
- package/build/transformer/metro-expo-babel-transformer.js +2 -14
- package/build/transformer/metro-expo-babel-transformer.js.map +1 -1
- package/build/transformer/metro-expo-exotic-babel-transformer.js +1 -3
- package/build/transformer/metro-expo-exotic-babel-transformer.js.map +1 -1
- 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,
|
|
16
|
+
export declare function loadAsync(projectRoot: string, { reporter, ...metroOptions }?: LoadOptions): Promise<MetroConfig.ConfigT>;
|
package/build/ExpoMetroConfig.js
CHANGED
|
@@ -6,128 +6,102 @@ 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
|
|
77
|
+
const EXPO_USE_METRO_WORKSPACE_ROOT = (0, _getenv().boolish)('EXPO_USE_METRO_WORKSPACE_ROOT', false);
|
|
78
|
+
const EXPO_USE_EXOTIC = (0, _getenv().boolish)('EXPO_USE_EXOTIC', false);
|
|
116
79
|
|
|
117
|
-
|
|
80
|
+
// Import only the types here, the values will be imported from the project, at runtime.
|
|
81
|
+
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$',
|
|
82
|
+
// Metro replaces `require()` with a different method,
|
|
118
83
|
// we want to omit this method from the stack trace.
|
|
119
84
|
// This is akin to most React tooling.
|
|
120
|
-
'/metro/.*/polyfills/require.js$',
|
|
121
|
-
|
|
122
|
-
'/
|
|
123
|
-
|
|
124
|
-
'
|
|
125
|
-
|
|
126
|
-
'node_modules
|
|
127
|
-
|
|
128
|
-
|
|
85
|
+
'/metro/.*/polyfills/require.js$',
|
|
86
|
+
// Hide frames related to a fast refresh.
|
|
87
|
+
'/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$',
|
|
88
|
+
// Ignore the log forwarder used in the expo package.
|
|
89
|
+
'/expo/build/logs/RemoteConsole.js$',
|
|
90
|
+
// Improve errors thrown by invariant (ex: `Invariant Violation: "main" has not been registered`).
|
|
91
|
+
'node_modules/invariant/.+\\.js$',
|
|
92
|
+
// Remove babel runtime additions
|
|
93
|
+
'node_modules/regenerator-runtime/.+\\.js$',
|
|
94
|
+
// Remove react native setImmediate ponyfill
|
|
95
|
+
'node_modules/promise/setimmediate/.+\\.js$',
|
|
96
|
+
// Babel helpers that implement language features
|
|
97
|
+
'node_modules/@babel/runtime/.+\\.js$',
|
|
98
|
+
// Hide Hermes internal bytecode
|
|
99
|
+
'/InternalBytecode/InternalBytecode\\.js$',
|
|
100
|
+
// Block native code invocations
|
|
101
|
+
`\\[native code\\]`,
|
|
102
|
+
// Hide react-dom (web)
|
|
103
|
+
'node_modules/react-dom/.+\\.js$'].join('|'));
|
|
129
104
|
exports.INTERNAL_CALLSITES_REGEX = INTERNAL_CALLSITES_REGEX;
|
|
130
|
-
|
|
131
105
|
function isUrl(value) {
|
|
132
106
|
try {
|
|
133
107
|
// eslint-disable-next-line no-new
|
|
@@ -137,134 +111,73 @@ function isUrl(value) {
|
|
|
137
111
|
return false;
|
|
138
112
|
}
|
|
139
113
|
}
|
|
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
114
|
function getProjectBabelConfigFile(projectRoot) {
|
|
149
115
|
return _resolveFrom().default.silent(projectRoot, './babel.config.js') || _resolveFrom().default.silent(projectRoot, './.babelrc') || _resolveFrom().default.silent(projectRoot, './.babelrc.js');
|
|
150
116
|
}
|
|
151
|
-
|
|
152
117
|
function getAssetPlugins(projectRoot) {
|
|
153
118
|
const assetPlugins = [];
|
|
154
119
|
let hashAssetFilesPath;
|
|
155
|
-
|
|
156
120
|
try {
|
|
157
121
|
hashAssetFilesPath = (0, _resolveFrom().default)(projectRoot, 'expo-asset/tools/hashAssetFiles');
|
|
158
|
-
} catch {
|
|
122
|
+
} catch {
|
|
123
|
+
// TODO: we should warn/throw an error if the user has expo-updates installed but does not
|
|
159
124
|
// have hashAssetFiles available, or if the user is in managed workflow and does not have
|
|
160
125
|
// hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,
|
|
161
126
|
// it is not needed
|
|
162
127
|
}
|
|
163
|
-
|
|
164
128
|
if (hashAssetFilesPath) {
|
|
165
129
|
assetPlugins.push(hashAssetFilesPath);
|
|
166
130
|
}
|
|
167
|
-
|
|
168
131
|
return assetPlugins;
|
|
169
132
|
}
|
|
170
|
-
|
|
171
133
|
let hasWarnedAboutExotic = false;
|
|
172
|
-
|
|
173
134
|
function getDefaultConfig(projectRoot, options = {}) {
|
|
135
|
+
var _getWorkspaceRoot;
|
|
174
136
|
const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;
|
|
175
|
-
|
|
176
137
|
if (isExotic && !hasWarnedAboutExotic) {
|
|
177
138
|
hasWarnedAboutExotic = true;
|
|
178
139
|
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
140
|
}
|
|
180
|
-
|
|
181
141
|
const MetroConfig = (0, _importMetroFromProject().importMetroConfigFromProject)(projectRoot);
|
|
182
|
-
|
|
183
142
|
const reactNativePath = _path().default.dirname((0, _resolveFrom().default)(projectRoot, 'react-native/package.json'));
|
|
184
|
-
|
|
185
143
|
try {
|
|
186
144
|
// Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.
|
|
187
145
|
// This hack is used because there doesn't appear to be anyway to resolve
|
|
188
146
|
// `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).
|
|
189
147
|
const babelPresetFbjsPath = (0, _resolveFrom().default)(projectRoot, 'babel-preset-fbjs/package.json');
|
|
190
148
|
process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);
|
|
191
|
-
} catch {
|
|
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)}`);
|
|
149
|
+
} catch {
|
|
150
|
+
// noop -- falls back to a hardcoded value.
|
|
230
151
|
}
|
|
231
|
-
|
|
232
152
|
const sourceExtsConfig = {
|
|
233
153
|
isTS: true,
|
|
234
154
|
isReact: true,
|
|
235
155
|
isModern: false
|
|
236
156
|
};
|
|
237
|
-
const sourceExts =
|
|
238
|
-
|
|
157
|
+
const sourceExts = (0, _paths().getBareExtensions)([], sourceExtsConfig);
|
|
239
158
|
if (isExotic) {
|
|
240
159
|
// Add support for cjs (without platform extensions).
|
|
241
160
|
sourceExts.push('cjs');
|
|
242
161
|
}
|
|
243
|
-
|
|
244
162
|
const babelConfigPath = getProjectBabelConfigFile(projectRoot);
|
|
245
163
|
const isCustomBabelConfigDefined = !!babelConfigPath;
|
|
246
|
-
const resolverMainFields = [];
|
|
247
|
-
// use it to ship raw application code to the project.
|
|
164
|
+
const resolverMainFields = [];
|
|
248
165
|
|
|
166
|
+
// Disable `react-native` in exotic mode, since library authors
|
|
167
|
+
// use it to ship raw application code to the project.
|
|
249
168
|
if (!isExotic) {
|
|
250
169
|
resolverMainFields.push('react-native');
|
|
251
170
|
}
|
|
252
|
-
|
|
253
171
|
resolverMainFields.push('browser', 'main');
|
|
254
|
-
const watchFolders = (0, _getWatchFolders().getWatchFolders)(projectRoot);
|
|
255
|
-
|
|
172
|
+
const watchFolders = (0, _getWatchFolders().getWatchFolders)(projectRoot);
|
|
173
|
+
// 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
174
|
const nodeModulesPaths = (0, _getModulesPaths().getModulesPaths)(projectRoot);
|
|
257
|
-
|
|
258
175
|
if (EXPO_DEBUG) {
|
|
259
176
|
console.log();
|
|
260
177
|
console.log(`Expo Metro config:`);
|
|
261
|
-
|
|
262
178
|
try {
|
|
263
179
|
console.log(`- Version: ${require('../package.json').version}`);
|
|
264
180
|
} catch {}
|
|
265
|
-
|
|
266
|
-
console.log(`- Bundler target: ${target}`);
|
|
267
|
-
console.log(`- Legacy: ${isLegacy}`);
|
|
268
181
|
console.log(`- Extensions: ${sourceExts.join(', ')}`);
|
|
269
182
|
console.log(`- React Native: ${reactNativePath}`);
|
|
270
183
|
console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);
|
|
@@ -274,36 +187,45 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
274
187
|
console.log(`- Exotic: ${isExotic}`);
|
|
275
188
|
console.log();
|
|
276
189
|
}
|
|
277
|
-
|
|
278
190
|
const {
|
|
279
191
|
// Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.
|
|
280
192
|
// This prints a giant React logo which is less accessible to users on smaller terminals.
|
|
281
193
|
reporter,
|
|
282
194
|
...metroDefaultValues
|
|
283
|
-
} = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);
|
|
284
|
-
// This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
|
|
195
|
+
} = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);
|
|
285
196
|
|
|
197
|
+
// Merge in the default config from Metro here, even though loadConfig uses it as defaults.
|
|
198
|
+
// This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
|
|
286
199
|
return MetroConfig.mergeConfig(metroDefaultValues, {
|
|
287
200
|
watchFolders,
|
|
288
201
|
resolver: {
|
|
289
202
|
resolverMainFields,
|
|
290
203
|
platforms: ['ios', 'android', 'native', 'testing'],
|
|
291
|
-
assetExts: metroDefaultValues.resolver.assetExts.
|
|
204
|
+
assetExts: metroDefaultValues.resolver.assetExts.concat(
|
|
205
|
+
// Add default support for `expo-image` file types.
|
|
206
|
+
['heic', 'avif']).filter(assetExt => !sourceExts.includes(assetExt)),
|
|
292
207
|
sourceExts,
|
|
293
208
|
nodeModulesPaths
|
|
294
209
|
},
|
|
295
210
|
serializer: {
|
|
296
|
-
getModulesRunBeforeMainModule: () => [require.resolve(_path().default.join(reactNativePath, 'Libraries/Core/InitializeCore'))
|
|
211
|
+
getModulesRunBeforeMainModule: () => [require.resolve(_path().default.join(reactNativePath, 'Libraries/Core/InitializeCore'))
|
|
212
|
+
// TODO: Bacon: load Expo side-effects
|
|
297
213
|
],
|
|
214
|
+
|
|
298
215
|
getPolyfills: () => require(_path().default.join(reactNativePath, 'rn-get-polyfills'))()
|
|
299
216
|
},
|
|
300
217
|
server: {
|
|
301
|
-
port: Number(process.env.RCT_METRO_PORT) || 8081
|
|
218
|
+
port: Number(process.env.RCT_METRO_PORT) || 8081,
|
|
219
|
+
// NOTE(EvanBacon): Moves the server root down to the monorepo root.
|
|
220
|
+
// This enables proper monorepo support for web.
|
|
221
|
+
// @ts-expect-error: not on type
|
|
222
|
+
unstable_serverRoot: EXPO_USE_METRO_WORKSPACE_ROOT ? (_getWorkspaceRoot = (0, _getModulesPaths().getWorkspaceRoot)(projectRoot)) !== null && _getWorkspaceRoot !== void 0 ? _getWorkspaceRoot : projectRoot : projectRoot
|
|
302
223
|
},
|
|
303
224
|
symbolicator: {
|
|
304
225
|
customizeFrame: frame => {
|
|
305
226
|
if (frame.file && isUrl(frame.file)) {
|
|
306
|
-
return {
|
|
227
|
+
return {
|
|
228
|
+
...frame,
|
|
307
229
|
// HACK: This prevents Metro from attempting to read the invalid file URL it sent us.
|
|
308
230
|
lineNumber: null,
|
|
309
231
|
column: null,
|
|
@@ -311,12 +233,9 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
311
233
|
collapse: true
|
|
312
234
|
};
|
|
313
235
|
}
|
|
314
|
-
|
|
315
236
|
let collapse = Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file));
|
|
316
|
-
|
|
317
237
|
if (!collapse) {
|
|
318
238
|
var _frame$file;
|
|
319
|
-
|
|
320
239
|
// This represents the first frame of the stacktrace.
|
|
321
240
|
// Often this looks like: `__r(0);`.
|
|
322
241
|
// The URL will also be unactionable in the app and therefore not very useful to the developer.
|
|
@@ -324,8 +243,8 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
324
243
|
collapse = true;
|
|
325
244
|
}
|
|
326
245
|
}
|
|
327
|
-
|
|
328
|
-
|
|
246
|
+
return {
|
|
247
|
+
...(frame || {}),
|
|
329
248
|
collapse
|
|
330
249
|
};
|
|
331
250
|
}
|
|
@@ -334,32 +253,29 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
334
253
|
// `require.context` support
|
|
335
254
|
unstable_allowRequireContext: true,
|
|
336
255
|
allowOptionalDependencies: true,
|
|
337
|
-
babelTransformerPath: isExotic ? require.resolve('./transformer/metro-expo-exotic-babel-transformer') : isCustomBabelConfigDefined ?
|
|
256
|
+
babelTransformerPath: isExotic ? require.resolve('./transformer/metro-expo-exotic-babel-transformer') : isCustomBabelConfigDefined ?
|
|
257
|
+
// If the user defined a babel config file in their project,
|
|
338
258
|
// then use the default transformer.
|
|
339
259
|
// Try to use the project copy before falling back on the global version
|
|
340
|
-
_resolveFrom().default.silent(projectRoot, 'metro-react-native-babel-transformer') :
|
|
260
|
+
_resolveFrom().default.silent(projectRoot, 'metro-react-native-babel-transformer') :
|
|
261
|
+
// Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.
|
|
341
262
|
require.resolve('./transformer/metro-expo-babel-transformer'),
|
|
342
263
|
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
|
|
343
264
|
assetPlugins: getAssetPlugins(projectRoot)
|
|
344
265
|
}
|
|
345
266
|
});
|
|
346
267
|
}
|
|
347
|
-
|
|
348
268
|
async function loadAsync(projectRoot, {
|
|
349
269
|
reporter,
|
|
350
|
-
target,
|
|
351
270
|
...metroOptions
|
|
352
271
|
} = {}) {
|
|
353
|
-
let defaultConfig = getDefaultConfig(projectRoot
|
|
354
|
-
target
|
|
355
|
-
});
|
|
356
|
-
|
|
272
|
+
let defaultConfig = getDefaultConfig(projectRoot);
|
|
357
273
|
if (reporter) {
|
|
358
|
-
defaultConfig = {
|
|
274
|
+
defaultConfig = {
|
|
275
|
+
...defaultConfig,
|
|
359
276
|
reporter
|
|
360
277
|
};
|
|
361
278
|
}
|
|
362
|
-
|
|
363
279
|
const MetroConfig = (0, _importMetroFromProject().importMetroConfigFromProject)(projectRoot);
|
|
364
280
|
return await MetroConfig.loadConfig({
|
|
365
281
|
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);\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;;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;AAA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;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_METRO_WORKSPACE_ROOT","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","unstable_serverRoot","getWorkspaceRoot","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, getWorkspaceRoot } from './getModulesPaths';\nimport { getWatchFolders } from './getWatchFolders';\nimport { importMetroConfigFromProject } from './importMetroFromProject';\n\nexport const EXPO_DEBUG = boolish('EXPO_DEBUG', false);\nconst EXPO_USE_METRO_WORKSPACE_ROOT = boolish('EXPO_USE_METRO_WORKSPACE_ROOT', 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 // NOTE(EvanBacon): Moves the server root down to the monorepo root.\n // This enables proper monorepo support for web.\n // @ts-expect-error: not on type\n unstable_serverRoot: EXPO_USE_METRO_WORKSPACE_ROOT\n ? getWorkspaceRoot(projectRoot) ?? projectRoot\n : projectRoot,\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,6BAA6B,GAAG,IAAAD,iBAAO,EAAC,+BAA+B,EAAE,KAAK,CAAC;AACrF,MAAME,eAAe,GAAG,IAAAF,iBAAO,EAAC,iBAAiB,EAAE,KAAK,CAAC;;AAEzD;AACO,MAAMG,wBAAwB,GAAG,IAAIC,MA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
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 = [];
|
|
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":"
|
|
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"}
|