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