@expo/metro-config 0.17.2 → 0.17.4
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 +239 -366
- package/build/ExpoMetroConfig.js.map +1 -1
- package/build/babel-core.js +6 -23
- package/build/babel-core.js.map +1 -1
- package/build/babel-transformer.js +117 -162
- package/build/babel-transformer.js.map +1 -1
- package/build/customizeFrame.js +84 -78
- package/build/customizeFrame.js.map +1 -1
- package/build/env.js +23 -37
- package/build/env.js.map +1 -1
- package/build/file-store.js +13 -21
- package/build/file-store.js.map +1 -1
- package/build/getModulesPaths.js +31 -48
- package/build/getModulesPaths.js.map +1 -1
- package/build/getWatchFolders.js +70 -98
- package/build/getWatchFolders.js.map +1 -1
- package/build/loadBabelConfig.js +30 -49
- package/build/loadBabelConfig.js.map +1 -1
- package/build/rewriteRequestUrl.js +82 -142
- package/build/rewriteRequestUrl.js.map +1 -1
- package/build/serializer/debugId.js +23 -22
- package/build/serializer/debugId.js.map +1 -1
- package/build/serializer/environmentVariableSerializerPlugin.js +90 -101
- package/build/serializer/environmentVariableSerializerPlugin.js.map +1 -1
- package/build/serializer/exportHermes.js +96 -133
- package/build/serializer/exportHermes.js.map +1 -1
- package/build/serializer/exportPath.js +18 -35
- package/build/serializer/exportPath.js.map +1 -1
- package/build/serializer/fork/baseJSBundle.js +124 -147
- package/build/serializer/fork/baseJSBundle.js.map +1 -1
- package/build/serializer/fork/js.js +81 -116
- package/build/serializer/fork/js.js.map +1 -1
- package/build/serializer/fork/processModules.js +22 -36
- package/build/serializer/fork/processModules.js.map +1 -1
- package/build/serializer/getCssDeps.js +64 -95
- package/build/serializer/getCssDeps.js.map +1 -1
- package/build/serializer/jsOutput.js +6 -16
- package/build/serializer/jsOutput.js.map +1 -1
- package/build/serializer/serializeChunks.js +406 -483
- package/build/serializer/serializeChunks.js.map +1 -1
- package/build/serializer/serializerAssets.js +1 -0
- package/build/serializer/serializerAssets.js.map +1 -1
- package/build/serializer/withExpoSerializers.js +165 -236
- package/build/serializer/withExpoSerializers.js.map +1 -1
- package/build/transform-worker/asset-transformer.js +21 -44
- package/build/transform-worker/asset-transformer.js.map +1 -1
- package/build/transform-worker/css-modules.js +57 -84
- package/build/transform-worker/css-modules.js.map +1 -1
- package/build/transform-worker/css.js +21 -20
- package/build/transform-worker/css.js.map +1 -1
- package/build/transform-worker/getAssets.js +38 -75
- package/build/transform-worker/getAssets.js.map +1 -1
- package/build/transform-worker/metro-transform-worker.js +384 -489
- package/build/transform-worker/metro-transform-worker.js.map +1 -1
- package/build/transform-worker/postcss.js +176 -233
- package/build/transform-worker/postcss.js.map +1 -1
- package/build/transform-worker/sass.js +30 -38
- package/build/transform-worker/sass.js.map +1 -1
- package/build/transform-worker/transform-worker.js +156 -188
- package/build/transform-worker/transform-worker.js.map +1 -1
- package/build/transform-worker/utils/require.js +30 -28
- package/build/transform-worker/utils/require.js.map +1 -1
- package/build/transformSync.js +40 -28
- package/build/transformSync.js.map +1 -1
- package/build/transformer/createExoticTransformer.js +96 -129
- package/build/transformer/createExoticTransformer.js.map +1 -1
- package/build/transformer/createMatcher.js +37 -46
- package/build/transformer/createMatcher.js.map +1 -1
- package/build/transformer/createMultiRuleTransformer.js +170 -240
- package/build/transformer/createMultiRuleTransformer.js.map +1 -1
- package/build/transformer/generateFunctionMap.js +20 -23
- package/build/transformer/generateFunctionMap.js.map +1 -1
- package/build/transformer/getBabelConfig.js +94 -127
- package/build/transformer/getBabelConfig.js.map +1 -1
- package/build/transformer/getCacheKey.js +17 -31
- package/build/transformer/getCacheKey.js.map +1 -1
- package/build/transformer/index.js +11 -62
- package/build/transformer/index.js.map +1 -1
- package/build/transformer/metro-expo-exotic-babel-transformer.js +3 -12
- package/build/transformer/metro-expo-exotic-babel-transformer.js.map +1 -1
- package/build/traveling/metro-config.js +12 -19
- package/build/traveling/metro-config.js.map +1 -1
- package/build/utils/hash.js +8 -14
- package/build/utils/hash.js.map +1 -1
- package/package.json +6 -6
package/build/ExpoMetroConfig.js
CHANGED
|
@@ -1,387 +1,260 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
Object.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
18
17
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
return data;
|
|
33
|
-
}
|
|
34
|
-
function runtimeEnv() {
|
|
35
|
-
const data = _interopRequireWildcard(require("@expo/env"));
|
|
36
|
-
runtimeEnv = function () {
|
|
37
|
-
return data;
|
|
38
|
-
};
|
|
39
|
-
return data;
|
|
40
|
-
}
|
|
41
|
-
function _jsonFile() {
|
|
42
|
-
const data = _interopRequireDefault(require("@expo/json-file"));
|
|
43
|
-
_jsonFile = function () {
|
|
44
|
-
return data;
|
|
45
|
-
};
|
|
46
|
-
return data;
|
|
47
|
-
}
|
|
48
|
-
function _chalk() {
|
|
49
|
-
const data = _interopRequireDefault(require("chalk"));
|
|
50
|
-
_chalk = function () {
|
|
51
|
-
return data;
|
|
52
|
-
};
|
|
53
|
-
return data;
|
|
54
|
-
}
|
|
55
|
-
function _metroCache() {
|
|
56
|
-
const data = require("metro-cache");
|
|
57
|
-
_metroCache = function () {
|
|
58
|
-
return data;
|
|
59
|
-
};
|
|
60
|
-
return data;
|
|
61
|
-
}
|
|
62
|
-
function _metroConfig() {
|
|
63
|
-
const data = require("metro-config");
|
|
64
|
-
_metroConfig = function () {
|
|
65
|
-
return data;
|
|
66
|
-
};
|
|
67
|
-
return data;
|
|
68
|
-
}
|
|
69
|
-
function _os() {
|
|
70
|
-
const data = _interopRequireDefault(require("os"));
|
|
71
|
-
_os = function () {
|
|
72
|
-
return data;
|
|
73
|
-
};
|
|
74
|
-
return data;
|
|
75
|
-
}
|
|
76
|
-
function _path() {
|
|
77
|
-
const data = _interopRequireDefault(require("path"));
|
|
78
|
-
_path = function () {
|
|
79
|
-
return data;
|
|
80
|
-
};
|
|
81
|
-
return data;
|
|
82
|
-
}
|
|
83
|
-
function _resolveFrom() {
|
|
84
|
-
const data = _interopRequireDefault(require("resolve-from"));
|
|
85
|
-
_resolveFrom = function () {
|
|
86
|
-
return data;
|
|
87
|
-
};
|
|
88
|
-
return data;
|
|
89
|
-
}
|
|
90
|
-
function _customizeFrame() {
|
|
91
|
-
const data = require("./customizeFrame");
|
|
92
|
-
_customizeFrame = function () {
|
|
93
|
-
return data;
|
|
94
|
-
};
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
97
|
-
function _env2() {
|
|
98
|
-
const data = require("./env");
|
|
99
|
-
_env2 = function () {
|
|
100
|
-
return data;
|
|
101
|
-
};
|
|
102
|
-
return data;
|
|
103
|
-
}
|
|
104
|
-
function _fileStore() {
|
|
105
|
-
const data = require("./file-store");
|
|
106
|
-
_fileStore = function () {
|
|
107
|
-
return data;
|
|
108
|
-
};
|
|
109
|
-
return data;
|
|
110
|
-
}
|
|
111
|
-
function _getModulesPaths() {
|
|
112
|
-
const data = require("./getModulesPaths");
|
|
113
|
-
_getModulesPaths = function () {
|
|
114
|
-
return data;
|
|
115
|
-
};
|
|
116
|
-
return data;
|
|
117
|
-
}
|
|
118
|
-
function _getWatchFolders() {
|
|
119
|
-
const data = require("./getWatchFolders");
|
|
120
|
-
_getWatchFolders = function () {
|
|
121
|
-
return data;
|
|
122
|
-
};
|
|
123
|
-
return data;
|
|
124
|
-
}
|
|
125
|
-
function _rewriteRequestUrl() {
|
|
126
|
-
const data = require("./rewriteRequestUrl");
|
|
127
|
-
_rewriteRequestUrl = function () {
|
|
128
|
-
return data;
|
|
129
|
-
};
|
|
130
|
-
return data;
|
|
131
|
-
}
|
|
132
|
-
function _withExpoSerializers() {
|
|
133
|
-
const data = require("./serializer/withExpoSerializers");
|
|
134
|
-
_withExpoSerializers = function () {
|
|
135
|
-
return data;
|
|
136
|
-
};
|
|
137
|
-
return data;
|
|
138
|
-
}
|
|
139
|
-
function _postcss() {
|
|
140
|
-
const data = require("./transform-worker/postcss");
|
|
141
|
-
_postcss = function () {
|
|
142
|
-
return data;
|
|
143
|
-
};
|
|
144
|
-
return data;
|
|
145
|
-
}
|
|
146
|
-
function _metroConfig2() {
|
|
147
|
-
const data = require("./traveling/metro-config");
|
|
148
|
-
_metroConfig2 = function () {
|
|
149
|
-
return data;
|
|
150
|
-
};
|
|
151
|
-
return data;
|
|
152
|
-
}
|
|
153
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
154
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
155
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.EXPO_DEBUG = exports.INTERNAL_CALLSITES_REGEX = exports.getDefaultConfig = void 0;
|
|
156
30
|
// Copyright 2023-present 650 Industries (Expo). All rights reserved.
|
|
157
|
-
|
|
31
|
+
const config_1 = require("@expo/config");
|
|
32
|
+
const paths_1 = require("@expo/config/paths");
|
|
33
|
+
const runtimeEnv = __importStar(require("@expo/env"));
|
|
34
|
+
const json_file_1 = __importDefault(require("@expo/json-file"));
|
|
35
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
36
|
+
const metro_cache_1 = require("metro-cache");
|
|
37
|
+
const os_1 = __importDefault(require("os"));
|
|
38
|
+
const path_1 = __importDefault(require("path"));
|
|
39
|
+
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
40
|
+
const customizeFrame_1 = require("./customizeFrame");
|
|
41
|
+
Object.defineProperty(exports, "INTERNAL_CALLSITES_REGEX", { enumerable: true, get: function () { return customizeFrame_1.INTERNAL_CALLSITES_REGEX; } });
|
|
42
|
+
const env_1 = require("./env");
|
|
43
|
+
const file_store_1 = require("./file-store");
|
|
44
|
+
const getModulesPaths_1 = require("./getModulesPaths");
|
|
45
|
+
const getWatchFolders_1 = require("./getWatchFolders");
|
|
46
|
+
const rewriteRequestUrl_1 = require("./rewriteRequestUrl");
|
|
47
|
+
const withExpoSerializers_1 = require("./serializer/withExpoSerializers");
|
|
48
|
+
const postcss_1 = require("./transform-worker/postcss");
|
|
49
|
+
const metro_config_1 = require("./traveling/metro-config");
|
|
158
50
|
const debug = require('debug')('expo:metro:config');
|
|
159
51
|
function getAssetPlugins(projectRoot) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
52
|
+
const hashAssetFilesPath = resolve_from_1.default.silent(projectRoot, 'expo-asset/tools/hashAssetFiles');
|
|
53
|
+
if (!hashAssetFilesPath) {
|
|
54
|
+
throw new Error(`The required package \`expo-asset\` cannot be found`);
|
|
55
|
+
}
|
|
56
|
+
return [hashAssetFilesPath];
|
|
165
57
|
}
|
|
166
58
|
let hasWarnedAboutExotic = false;
|
|
167
|
-
|
|
168
59
|
// Patch Metro's graph to support always parsing certain modules. This enables
|
|
169
60
|
// things like Tailwind CSS which update based on their own heuristics.
|
|
170
61
|
function patchMetroGraphToSupportUncachedModules() {
|
|
171
|
-
|
|
172
|
-
Graph
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return original_traverseDependencies.call(this, paths, options);
|
|
196
|
-
};
|
|
197
|
-
// Ensure we don't patch the method twice.
|
|
198
|
-
Graph.prototype.traverseDependencies.__patched = true;
|
|
199
|
-
}
|
|
62
|
+
const { Graph } = require('metro/src/DeltaBundler/Graph');
|
|
63
|
+
const original_traverseDependencies = Graph.prototype.traverseDependencies;
|
|
64
|
+
if (!original_traverseDependencies.__patched) {
|
|
65
|
+
original_traverseDependencies.__patched = true;
|
|
66
|
+
Graph.prototype.traverseDependencies = function (paths, options) {
|
|
67
|
+
this.dependencies.forEach((dependency) => {
|
|
68
|
+
// Find any dependencies that have been marked as `skipCache` and ensure they are invalidated.
|
|
69
|
+
// `skipCache` is set when a CSS module is found by PostCSS.
|
|
70
|
+
if (dependency.output.find((file) => file.data.css?.skipCache) &&
|
|
71
|
+
!paths.includes(dependency.path)) {
|
|
72
|
+
// Ensure we invalidate the `unstable_transformResultKey` (input hash) so the module isn't removed in
|
|
73
|
+
// the Graph._processModule method.
|
|
74
|
+
dependency.unstable_transformResultKey = dependency.unstable_transformResultKey + '.';
|
|
75
|
+
// Add the path to the list of modified paths so it gets run through the transformer again,
|
|
76
|
+
// this will ensure it is passed to PostCSS -> Tailwind.
|
|
77
|
+
paths.push(dependency.path);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
// Invoke the original method with the new paths to ensure the standard behavior is preserved.
|
|
81
|
+
return original_traverseDependencies.call(this, paths, options);
|
|
82
|
+
};
|
|
83
|
+
// Ensure we don't patch the method twice.
|
|
84
|
+
Graph.prototype.traverseDependencies.__patched = true;
|
|
85
|
+
}
|
|
200
86
|
}
|
|
201
|
-
function getDefaultConfig(projectRoot, {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
const isExotic = mode === 'exotic' || _env2().env.EXPO_USE_EXOTIC;
|
|
214
|
-
if (isExotic && !hasWarnedAboutExotic) {
|
|
215
|
-
hasWarnedAboutExotic = true;
|
|
216
|
-
console.log(_chalk().default.gray(`\u203A Feature ${_chalk().default.bold`EXPO_USE_EXOTIC`} is no longer supported.`));
|
|
217
|
-
}
|
|
218
|
-
const reactNativePath = _path().default.dirname((0, _resolveFrom().default)(projectRoot, 'react-native/package.json'));
|
|
219
|
-
try {
|
|
220
|
-
// Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.
|
|
221
|
-
// This hack is used because there doesn't appear to be anyway to resolve
|
|
222
|
-
// `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).
|
|
223
|
-
const babelPresetFbjsPath = (0, _resolveFrom().default)(projectRoot, 'babel-preset-fbjs/package.json');
|
|
224
|
-
process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);
|
|
225
|
-
} catch {
|
|
226
|
-
// noop -- falls back to a hardcoded value.
|
|
227
|
-
}
|
|
228
|
-
const sourceExtsConfig = {
|
|
229
|
-
isTS: true,
|
|
230
|
-
isReact: true,
|
|
231
|
-
isModern: true
|
|
232
|
-
};
|
|
233
|
-
const sourceExts = (0, _paths().getBareExtensions)([], sourceExtsConfig);
|
|
234
|
-
|
|
235
|
-
// Add support for cjs (without platform extensions).
|
|
236
|
-
sourceExts.push('cjs');
|
|
237
|
-
const reanimatedVersion = getPkgVersion(projectRoot, 'react-native-reanimated');
|
|
238
|
-
let sassVersion = null;
|
|
239
|
-
if (isCSSEnabled) {
|
|
240
|
-
sassVersion = getPkgVersion(projectRoot, 'sass');
|
|
241
|
-
// Enable SCSS by default so we can provide a better error message
|
|
242
|
-
// when sass isn't installed.
|
|
243
|
-
sourceExts.push('scss', 'sass', 'css');
|
|
244
|
-
}
|
|
245
|
-
const envFiles = runtimeEnv().getFiles(process.env.NODE_ENV, {
|
|
246
|
-
silent: true
|
|
247
|
-
});
|
|
248
|
-
const pkg = (0, _config().getPackageJson)(projectRoot);
|
|
249
|
-
const watchFolders = (0, _getWatchFolders().getWatchFolders)(projectRoot);
|
|
250
|
-
const nodeModulesPaths = (0, _getModulesPaths().getModulesPaths)(projectRoot);
|
|
251
|
-
if (_env2().env.EXPO_DEBUG) {
|
|
252
|
-
console.log();
|
|
253
|
-
console.log(`Expo Metro config:`);
|
|
87
|
+
function getDefaultConfig(projectRoot, { mode, isCSSEnabled = true, unstable_beforeAssetSerializationPlugins } = {}) {
|
|
88
|
+
const { getDefaultConfig: getDefaultMetroConfig, mergeConfig } = (0, metro_config_1.importMetroConfig)(projectRoot);
|
|
89
|
+
if (isCSSEnabled) {
|
|
90
|
+
patchMetroGraphToSupportUncachedModules();
|
|
91
|
+
}
|
|
92
|
+
const isExotic = mode === 'exotic' || env_1.env.EXPO_USE_EXOTIC;
|
|
93
|
+
if (isExotic && !hasWarnedAboutExotic) {
|
|
94
|
+
hasWarnedAboutExotic = true;
|
|
95
|
+
console.log(chalk_1.default.gray(`\u203A Feature ${chalk_1.default.bold `EXPO_USE_EXOTIC`} is no longer supported.`));
|
|
96
|
+
}
|
|
97
|
+
const reactNativePath = path_1.default.dirname((0, resolve_from_1.default)(projectRoot, 'react-native/package.json'));
|
|
254
98
|
try {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
web: ['browser']
|
|
286
|
-
},
|
|
287
|
-
unstable_conditionNames: ['require', 'import'],
|
|
288
|
-
resolverMainFields: ['react-native', 'browser', 'main'],
|
|
289
|
-
platforms: ['ios', 'android'],
|
|
290
|
-
assetExts: metroDefaultValues.resolver.assetExts.concat(
|
|
291
|
-
// Add default support for `expo-image` file types.
|
|
292
|
-
['heic', 'avif']).filter(assetExt => !sourceExts.includes(assetExt)),
|
|
293
|
-
sourceExts,
|
|
294
|
-
nodeModulesPaths
|
|
295
|
-
},
|
|
296
|
-
cacheStores: [cacheStore],
|
|
297
|
-
watcher: {
|
|
298
|
-
// strip starting dot from env files
|
|
299
|
-
additionalExts: envFiles.map(file => file.replace(/^\./, ''))
|
|
300
|
-
},
|
|
301
|
-
serializer: {
|
|
302
|
-
getModulesRunBeforeMainModule: () => {
|
|
303
|
-
const preModules = [
|
|
304
|
-
// MUST be first
|
|
305
|
-
require.resolve(_path().default.join(reactNativePath, 'Libraries/Core/InitializeCore'))];
|
|
306
|
-
const stdRuntime = _resolveFrom().default.silent(projectRoot, 'expo/build/winter');
|
|
307
|
-
if (stdRuntime) {
|
|
308
|
-
preModules.push(stdRuntime);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// We need to shift this to be the first module so web Fast Refresh works as expected.
|
|
312
|
-
// This will only be applied if the module is installed and imported somewhere in the bundle already.
|
|
313
|
-
const metroRuntime = _resolveFrom().default.silent(projectRoot, '@expo/metro-runtime');
|
|
314
|
-
if (metroRuntime) {
|
|
315
|
-
preModules.push(metroRuntime);
|
|
316
|
-
}
|
|
317
|
-
return preModules;
|
|
318
|
-
},
|
|
319
|
-
getPolyfills: () => require('@react-native/js-polyfills')()
|
|
320
|
-
},
|
|
321
|
-
server: {
|
|
322
|
-
rewriteRequestUrl: (0, _rewriteRequestUrl().getRewriteRequestUrl)(projectRoot),
|
|
323
|
-
port: Number(_env2().env.RCT_METRO_PORT) || 8081,
|
|
324
|
-
// NOTE(EvanBacon): Moves the server root down to the monorepo root.
|
|
325
|
-
// This enables proper monorepo support for web.
|
|
326
|
-
unstable_serverRoot: (0, _getModulesPaths().getServerRoot)(projectRoot)
|
|
327
|
-
},
|
|
328
|
-
symbolicator: {
|
|
329
|
-
customizeFrame: (0, _customizeFrame().getDefaultCustomizeFrame)()
|
|
330
|
-
},
|
|
331
|
-
transformerPath: require.resolve('./transform-worker/transform-worker'),
|
|
332
|
-
transformer: {
|
|
333
|
-
// Custom: These are passed to `getCacheKey` and ensure invalidation when the version changes.
|
|
334
|
-
// @ts-expect-error: not on type.
|
|
335
|
-
postcssHash: (0, _postcss().getPostcssConfigHash)(projectRoot),
|
|
336
|
-
browserslistHash: pkg.browserslist ? (0, _metroCache().stableHash)(JSON.stringify(pkg.browserslist)).toString('hex') : null,
|
|
337
|
-
sassVersion,
|
|
338
|
-
// Ensure invalidation when the version changes due to the Babel plugin.
|
|
339
|
-
reanimatedVersion,
|
|
340
|
-
// `require.context` support
|
|
341
|
-
unstable_allowRequireContext: true,
|
|
342
|
-
allowOptionalDependencies: true,
|
|
343
|
-
babelTransformerPath: require.resolve('./babel-transformer'),
|
|
344
|
-
// See: https://github.com/facebook/react-native/blob/v0.73.0/packages/metro-config/index.js#L72-L74
|
|
345
|
-
asyncRequireModulePath: (0, _resolveFrom().default)(reactNativePath, metroDefaultValues.transformer.asyncRequireModulePath),
|
|
346
|
-
assetRegistryPath: '@react-native/assets-registry/registry',
|
|
347
|
-
assetPlugins: getAssetPlugins(projectRoot),
|
|
348
|
-
getTransformOptions: async () => ({
|
|
349
|
-
transform: {
|
|
350
|
-
experimentalImportSupport: false,
|
|
351
|
-
inlineRequires: false
|
|
99
|
+
// Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.
|
|
100
|
+
// This hack is used because there doesn't appear to be anyway to resolve
|
|
101
|
+
// `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).
|
|
102
|
+
const babelPresetFbjsPath = (0, resolve_from_1.default)(projectRoot, 'babel-preset-fbjs/package.json');
|
|
103
|
+
process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// noop -- falls back to a hardcoded value.
|
|
107
|
+
}
|
|
108
|
+
const sourceExtsConfig = { isTS: true, isReact: true, isModern: true };
|
|
109
|
+
const sourceExts = (0, paths_1.getBareExtensions)([], sourceExtsConfig);
|
|
110
|
+
// Add support for cjs (without platform extensions).
|
|
111
|
+
sourceExts.push('cjs');
|
|
112
|
+
const reanimatedVersion = getPkgVersion(projectRoot, 'react-native-reanimated');
|
|
113
|
+
let sassVersion = null;
|
|
114
|
+
if (isCSSEnabled) {
|
|
115
|
+
sassVersion = getPkgVersion(projectRoot, 'sass');
|
|
116
|
+
// Enable SCSS by default so we can provide a better error message
|
|
117
|
+
// when sass isn't installed.
|
|
118
|
+
sourceExts.push('scss', 'sass', 'css');
|
|
119
|
+
}
|
|
120
|
+
const envFiles = runtimeEnv.getFiles(process.env.NODE_ENV, { silent: true });
|
|
121
|
+
const pkg = (0, config_1.getPackageJson)(projectRoot);
|
|
122
|
+
const watchFolders = (0, getWatchFolders_1.getWatchFolders)(projectRoot);
|
|
123
|
+
const nodeModulesPaths = (0, getModulesPaths_1.getModulesPaths)(projectRoot);
|
|
124
|
+
if (env_1.env.EXPO_DEBUG) {
|
|
125
|
+
console.log();
|
|
126
|
+
console.log(`Expo Metro config:`);
|
|
127
|
+
try {
|
|
128
|
+
console.log(`- Version: ${require('../package.json').version}`);
|
|
352
129
|
}
|
|
353
|
-
|
|
130
|
+
catch { }
|
|
131
|
+
console.log(`- Extensions: ${sourceExts.join(', ')}`);
|
|
132
|
+
console.log(`- React Native: ${reactNativePath}`);
|
|
133
|
+
console.log(`- Watch Folders: ${watchFolders.join(', ')}`);
|
|
134
|
+
console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`);
|
|
135
|
+
console.log(`- Env Files: ${envFiles}`);
|
|
136
|
+
console.log(`- Sass: ${sassVersion}`);
|
|
137
|
+
console.log(`- Reanimated: ${reanimatedVersion}`);
|
|
138
|
+
console.log();
|
|
354
139
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
140
|
+
const {
|
|
141
|
+
// Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.
|
|
142
|
+
// This prints a giant React logo which is less accessible to users on smaller terminals.
|
|
143
|
+
reporter, ...metroDefaultValues } = getDefaultMetroConfig.getDefaultValues(projectRoot);
|
|
144
|
+
const cacheStore = new file_store_1.FileStore({
|
|
145
|
+
root: path_1.default.join(os_1.default.tmpdir(), 'metro-cache'),
|
|
146
|
+
});
|
|
147
|
+
// Merge in the default config from Metro here, even though loadConfig uses it as defaults.
|
|
148
|
+
// This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
|
|
149
|
+
const metroConfig = mergeConfig(metroDefaultValues, {
|
|
150
|
+
watchFolders,
|
|
151
|
+
resolver: {
|
|
152
|
+
unstable_conditionsByPlatform: {
|
|
153
|
+
ios: ['react-native'],
|
|
154
|
+
android: ['react-native'],
|
|
155
|
+
// This is removed for server platforms.
|
|
156
|
+
web: ['browser'],
|
|
157
|
+
},
|
|
158
|
+
unstable_conditionNames: ['require', 'import'],
|
|
159
|
+
resolverMainFields: ['react-native', 'browser', 'main'],
|
|
160
|
+
platforms: ['ios', 'android'],
|
|
161
|
+
assetExts: metroDefaultValues.resolver.assetExts
|
|
162
|
+
.concat(
|
|
163
|
+
// Add default support for `expo-image` file types.
|
|
164
|
+
['heic', 'avif'])
|
|
165
|
+
.filter((assetExt) => !sourceExts.includes(assetExt)),
|
|
166
|
+
sourceExts,
|
|
167
|
+
nodeModulesPaths,
|
|
168
|
+
},
|
|
169
|
+
cacheStores: [cacheStore],
|
|
170
|
+
watcher: {
|
|
171
|
+
// strip starting dot from env files
|
|
172
|
+
additionalExts: envFiles.map((file) => file.replace(/^\./, '')),
|
|
173
|
+
},
|
|
174
|
+
serializer: {
|
|
175
|
+
getModulesRunBeforeMainModule: () => {
|
|
176
|
+
const preModules = [
|
|
177
|
+
// MUST be first
|
|
178
|
+
require.resolve(path_1.default.join(reactNativePath, 'Libraries/Core/InitializeCore')),
|
|
179
|
+
];
|
|
180
|
+
const stdRuntime = resolve_from_1.default.silent(projectRoot, 'expo/build/winter');
|
|
181
|
+
if (stdRuntime) {
|
|
182
|
+
preModules.push(stdRuntime);
|
|
183
|
+
}
|
|
184
|
+
// We need to shift this to be the first module so web Fast Refresh works as expected.
|
|
185
|
+
// This will only be applied if the module is installed and imported somewhere in the bundle already.
|
|
186
|
+
const metroRuntime = resolve_from_1.default.silent(projectRoot, '@expo/metro-runtime');
|
|
187
|
+
if (metroRuntime) {
|
|
188
|
+
preModules.push(metroRuntime);
|
|
189
|
+
}
|
|
190
|
+
return preModules;
|
|
191
|
+
},
|
|
192
|
+
getPolyfills: () => require('@react-native/js-polyfills')(),
|
|
193
|
+
},
|
|
194
|
+
server: {
|
|
195
|
+
rewriteRequestUrl: (0, rewriteRequestUrl_1.getRewriteRequestUrl)(projectRoot),
|
|
196
|
+
port: Number(env_1.env.RCT_METRO_PORT) || 8081,
|
|
197
|
+
// NOTE(EvanBacon): Moves the server root down to the monorepo root.
|
|
198
|
+
// This enables proper monorepo support for web.
|
|
199
|
+
unstable_serverRoot: (0, getModulesPaths_1.getServerRoot)(projectRoot),
|
|
200
|
+
},
|
|
201
|
+
symbolicator: {
|
|
202
|
+
customizeFrame: (0, customizeFrame_1.getDefaultCustomizeFrame)(),
|
|
203
|
+
},
|
|
204
|
+
transformerPath: require.resolve('./transform-worker/transform-worker'),
|
|
205
|
+
transformer: {
|
|
206
|
+
// Custom: These are passed to `getCacheKey` and ensure invalidation when the version changes.
|
|
207
|
+
// @ts-expect-error: not on type.
|
|
208
|
+
postcssHash: (0, postcss_1.getPostcssConfigHash)(projectRoot),
|
|
209
|
+
browserslistHash: pkg.browserslist
|
|
210
|
+
? (0, metro_cache_1.stableHash)(JSON.stringify(pkg.browserslist)).toString('hex')
|
|
211
|
+
: null,
|
|
212
|
+
sassVersion,
|
|
213
|
+
// Ensure invalidation when the version changes due to the Babel plugin.
|
|
214
|
+
reanimatedVersion,
|
|
215
|
+
// `require.context` support
|
|
216
|
+
unstable_allowRequireContext: true,
|
|
217
|
+
allowOptionalDependencies: true,
|
|
218
|
+
babelTransformerPath: require.resolve('./babel-transformer'),
|
|
219
|
+
// See: https://github.com/facebook/react-native/blob/v0.73.0/packages/metro-config/index.js#L72-L74
|
|
220
|
+
asyncRequireModulePath: (0, resolve_from_1.default)(reactNativePath, metroDefaultValues.transformer.asyncRequireModulePath),
|
|
221
|
+
assetRegistryPath: '@react-native/assets-registry/registry',
|
|
222
|
+
assetPlugins: getAssetPlugins(projectRoot),
|
|
223
|
+
getTransformOptions: async () => ({
|
|
224
|
+
transform: {
|
|
225
|
+
experimentalImportSupport: false,
|
|
226
|
+
inlineRequires: false,
|
|
227
|
+
},
|
|
228
|
+
}),
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
return (0, withExpoSerializers_1.withExpoSerializers)(metroConfig, { unstable_beforeAssetSerializationPlugins });
|
|
359
232
|
}
|
|
360
|
-
|
|
361
|
-
// re-export for use in config files.
|
|
362
|
-
|
|
233
|
+
exports.getDefaultConfig = getDefaultConfig;
|
|
363
234
|
// re-export for legacy cases.
|
|
364
|
-
|
|
365
|
-
exports.EXPO_DEBUG = EXPO_DEBUG;
|
|
235
|
+
exports.EXPO_DEBUG = env_1.env.EXPO_DEBUG;
|
|
366
236
|
function getPkgVersion(projectRoot, pkgName) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
237
|
+
const targetPkg = resolve_from_1.default.silent(projectRoot, pkgName);
|
|
238
|
+
if (!targetPkg)
|
|
239
|
+
return null;
|
|
240
|
+
const targetPkgJson = findUpPackageJson(targetPkg);
|
|
241
|
+
if (!targetPkgJson)
|
|
242
|
+
return null;
|
|
243
|
+
const pkg = json_file_1.default.read(targetPkgJson);
|
|
244
|
+
debug(`${pkgName} package.json:`, targetPkgJson);
|
|
245
|
+
const pkgVersion = pkg.version;
|
|
246
|
+
if (typeof pkgVersion === 'string') {
|
|
247
|
+
return pkgVersion;
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
378
250
|
}
|
|
379
251
|
function findUpPackageJson(cwd) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
252
|
+
if (['.', path_1.default.sep].includes(cwd))
|
|
253
|
+
return null;
|
|
254
|
+
const found = resolve_from_1.default.silent(cwd, './package.json');
|
|
255
|
+
if (found) {
|
|
256
|
+
return found;
|
|
257
|
+
}
|
|
258
|
+
return findUpPackageJson(path_1.default.dirname(cwd));
|
|
386
259
|
}
|
|
387
260
|
//# sourceMappingURL=ExpoMetroConfig.js.map
|