@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
|
@@ -1,131 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
17
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function babylon() {
|
|
29
|
-
const data = _interopRequireWildcard(require("@babel/parser"));
|
|
30
|
-
babylon = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
function types() {
|
|
36
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
|
37
|
-
types = function () {
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
42
|
-
function _JsFileWrapping() {
|
|
43
|
-
const data = _interopRequireDefault(require("metro/src/ModuleGraph/worker/JsFileWrapping"));
|
|
44
|
-
_JsFileWrapping = function () {
|
|
45
|
-
return data;
|
|
46
|
-
};
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
function _collectDependencies() {
|
|
50
|
-
const data = _interopRequireWildcard(require("metro/src/ModuleGraph/worker/collectDependencies"));
|
|
51
|
-
_collectDependencies = function () {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
function _generateImportNames() {
|
|
57
|
-
const data = _interopRequireDefault(require("metro/src/ModuleGraph/worker/generateImportNames"));
|
|
58
|
-
_generateImportNames = function () {
|
|
59
|
-
return data;
|
|
60
|
-
};
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
function _countLines() {
|
|
64
|
-
const data = _interopRequireDefault(require("metro/src/lib/countLines"));
|
|
65
|
-
_countLines = function () {
|
|
66
|
-
return data;
|
|
67
|
-
};
|
|
68
|
-
return data;
|
|
69
|
-
}
|
|
70
|
-
function _metroCache() {
|
|
71
|
-
const data = require("metro-cache");
|
|
72
|
-
_metroCache = function () {
|
|
73
|
-
return data;
|
|
74
|
-
};
|
|
75
|
-
return data;
|
|
76
|
-
}
|
|
77
|
-
function _metroCacheKey() {
|
|
78
|
-
const data = _interopRequireDefault(require("metro-cache-key"));
|
|
79
|
-
_metroCacheKey = function () {
|
|
80
|
-
return data;
|
|
81
|
-
};
|
|
82
|
-
return data;
|
|
83
|
-
}
|
|
84
|
-
function _metroSourceMap() {
|
|
85
|
-
const data = require("metro-source-map");
|
|
86
|
-
_metroSourceMap = function () {
|
|
87
|
-
return data;
|
|
88
|
-
};
|
|
89
|
-
return data;
|
|
90
|
-
}
|
|
91
|
-
function _metroTransformPlugins() {
|
|
92
|
-
const data = _interopRequireDefault(require("metro-transform-plugins"));
|
|
93
|
-
_metroTransformPlugins = function () {
|
|
94
|
-
return data;
|
|
95
|
-
};
|
|
96
|
-
return data;
|
|
97
|
-
}
|
|
98
|
-
function _metroTransformWorker() {
|
|
99
|
-
const data = require("metro-transform-worker");
|
|
100
|
-
_metroTransformWorker = function () {
|
|
101
|
-
return data;
|
|
102
|
-
};
|
|
103
|
-
return data;
|
|
104
|
-
}
|
|
105
|
-
function _getMinifier() {
|
|
106
|
-
const data = _interopRequireDefault(require("metro-transform-worker/src/utils/getMinifier"));
|
|
107
|
-
_getMinifier = function () {
|
|
108
|
-
return data;
|
|
109
|
-
};
|
|
110
|
-
return data;
|
|
111
|
-
}
|
|
112
|
-
function _nodeAssert() {
|
|
113
|
-
const data = _interopRequireDefault(require("node:assert"));
|
|
114
|
-
_nodeAssert = function () {
|
|
115
|
-
return data;
|
|
116
|
-
};
|
|
117
|
-
return data;
|
|
118
|
-
}
|
|
119
|
-
function assetTransformer() {
|
|
120
|
-
const data = _interopRequireWildcard(require("./asset-transformer"));
|
|
121
|
-
assetTransformer = function () {
|
|
122
|
-
return data;
|
|
123
|
-
};
|
|
124
|
-
return data;
|
|
125
|
-
}
|
|
126
|
-
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); }
|
|
127
|
-
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; }
|
|
128
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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.getCacheKey = exports.transform = void 0;
|
|
129
30
|
/**
|
|
130
31
|
* Copyright 2023-present 650 Industries (Expo). All rights reserved.
|
|
131
32
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -136,403 +37,397 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
136
37
|
* Fork of the Metro transformer worker, but with additional transforms moved to `babel-preset-expo` and modifications made for web support.
|
|
137
38
|
* https://github.com/facebook/metro/blob/412771475c540b6f85d75d9dcd5a39a6e0753582/packages/metro-transform-worker/src/index.js#L1
|
|
138
39
|
*/
|
|
139
|
-
|
|
40
|
+
const core_1 = require("@babel/core");
|
|
41
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
42
|
+
const babylon = __importStar(require("@babel/parser"));
|
|
43
|
+
const types = __importStar(require("@babel/types"));
|
|
44
|
+
const JsFileWrapping_1 = __importDefault(require("metro/src/ModuleGraph/worker/JsFileWrapping"));
|
|
45
|
+
const collectDependencies_1 = __importStar(require("metro/src/ModuleGraph/worker/collectDependencies"));
|
|
46
|
+
const generateImportNames_1 = __importDefault(require("metro/src/ModuleGraph/worker/generateImportNames"));
|
|
47
|
+
const countLines_1 = __importDefault(require("metro/src/lib/countLines"));
|
|
48
|
+
const metro_cache_1 = require("metro-cache");
|
|
49
|
+
const metro_cache_key_1 = __importDefault(require("metro-cache-key"));
|
|
50
|
+
const metro_source_map_1 = require("metro-source-map");
|
|
51
|
+
const metro_transform_plugins_1 = __importDefault(require("metro-transform-plugins"));
|
|
52
|
+
const getMinifier_1 = __importDefault(require("metro-transform-worker/src/utils/getMinifier"));
|
|
53
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
54
|
+
const assetTransformer = __importStar(require("./asset-transformer"));
|
|
140
55
|
// asserts non-null
|
|
141
56
|
function nullthrows(x, message) {
|
|
142
|
-
|
|
143
|
-
|
|
57
|
+
(0, node_assert_1.default)(x != null, message);
|
|
58
|
+
return x;
|
|
144
59
|
}
|
|
145
60
|
function getDynamicDepsBehavior(inPackages, filename) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
61
|
+
switch (inPackages) {
|
|
62
|
+
case 'reject':
|
|
63
|
+
return 'reject';
|
|
64
|
+
case 'throwAtRuntime':
|
|
65
|
+
return /(?:^|[/\\])node_modules[/\\]/.test(filename) ? inPackages : 'reject';
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`invalid value for dynamic deps behavior: \`${inPackages}\``);
|
|
68
|
+
}
|
|
154
69
|
}
|
|
155
70
|
const minifyCode = async (config, projectRoot, filename, code, source, map, reserved = []) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
71
|
+
const sourceMap = (0, metro_source_map_1.fromRawMappings)([
|
|
72
|
+
{
|
|
73
|
+
code,
|
|
74
|
+
source,
|
|
75
|
+
map,
|
|
76
|
+
// functionMap is overridden by the serializer
|
|
77
|
+
functionMap: null,
|
|
78
|
+
path: filename,
|
|
79
|
+
// isIgnored is overriden by the serializer
|
|
80
|
+
isIgnored: false,
|
|
81
|
+
},
|
|
82
|
+
]).toMap(undefined, {});
|
|
83
|
+
const minify = (0, getMinifier_1.default)(config.minifierPath);
|
|
84
|
+
try {
|
|
85
|
+
const minified = await minify({
|
|
86
|
+
code,
|
|
87
|
+
map: sourceMap,
|
|
88
|
+
filename,
|
|
89
|
+
reserved,
|
|
90
|
+
config: config.minifierConfig,
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
code: minified.code,
|
|
94
|
+
map: minified.map ? (0, metro_source_map_1.toBabelSegments)(minified.map).map(metro_source_map_1.toSegmentTuple) : [],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error.constructor.name === 'JS_Parse_Error') {
|
|
99
|
+
throw new Error(`${error.message} in file ${filename} at ${error.line}:${error.col}`);
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
182
102
|
}
|
|
183
|
-
throw error;
|
|
184
|
-
}
|
|
185
103
|
};
|
|
186
104
|
const disabledDependencyTransformer = {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
105
|
+
transformSyncRequire: () => { },
|
|
106
|
+
transformImportCall: () => { },
|
|
107
|
+
transformPrefetch: () => { },
|
|
108
|
+
transformIllegalDynamicRequire: () => { },
|
|
191
109
|
};
|
|
192
110
|
class InvalidRequireCallError extends Error {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
111
|
+
innerError;
|
|
112
|
+
filename;
|
|
113
|
+
constructor(innerError, filename) {
|
|
114
|
+
super(`${filename}:${innerError.message}`);
|
|
115
|
+
this.innerError = innerError;
|
|
116
|
+
this.filename = filename;
|
|
117
|
+
}
|
|
198
118
|
}
|
|
199
|
-
async function transformJS(file, {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
sourceType
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
plugins.push([
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
// NOTE(EvanBacon): This can basically never be safely enabled because it doesn't respect side-effects and
|
|
243
|
-
// has no ability to respect side-effects because the transformer hasn't collected all dependencies yet.
|
|
244
|
-
if (options.inlineRequires) {
|
|
245
|
-
plugins.push([_metroTransformPlugins().default.inlineRequiresPlugin, {
|
|
246
|
-
...babelPluginOpts,
|
|
247
|
-
ignoredRequires: options.nonInlinedRequires
|
|
248
|
-
}]);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// NOTE(EvanBacon): We apply this conditionally in `babel-preset-expo` with other AST transforms.
|
|
252
|
-
// plugins.push([metroTransformPlugins.inlinePlugin, babelPluginOpts]);
|
|
253
|
-
|
|
254
|
-
// TODO: This MUST be run even though no plugins are added, otherwise the babel runtime generators are broken.
|
|
255
|
-
// if (plugins.length) {
|
|
256
|
-
ast = nullthrows(
|
|
257
|
-
// @ts-expect-error
|
|
258
|
-
(0, _core().transformFromAstSync)(ast, '', {
|
|
259
|
-
ast: true,
|
|
260
|
-
babelrc: false,
|
|
261
|
-
code: false,
|
|
262
|
-
configFile: false,
|
|
263
|
-
comments: true,
|
|
264
|
-
filename: file.filename,
|
|
265
|
-
plugins,
|
|
266
|
-
sourceMaps: false,
|
|
267
|
-
// Not-Cloning the input AST here should be safe because other code paths above this call
|
|
268
|
-
// are mutating the AST as well and no code is depending on the original AST.
|
|
269
|
-
// However, switching the flag to false caused issues with ES Modules if `experimentalImportSupport` isn't used https://github.com/facebook/metro/issues/641
|
|
270
|
-
// either because one of the plugins is doing something funky or Babel messes up some caches.
|
|
271
|
-
// Make sure to test the above mentioned case before flipping the flag back to false.
|
|
272
|
-
cloneInputAst: true
|
|
273
|
-
}).ast);
|
|
274
|
-
// }
|
|
275
|
-
|
|
276
|
-
if (!options.dev) {
|
|
277
|
-
// Run the constant folding plugin in its own pass, avoiding race conditions
|
|
278
|
-
// with other plugins that have exit() visitors on Program (e.g. the ESM
|
|
279
|
-
// transform).
|
|
119
|
+
async function transformJS(file, { config, options, projectRoot }) {
|
|
120
|
+
// Transformers can output null ASTs (if they ignore the file). In that case
|
|
121
|
+
// we need to parse the module source code to get their AST.
|
|
122
|
+
let ast = file.ast ?? babylon.parse(file.code, { sourceType: 'unambiguous' });
|
|
123
|
+
// NOTE(EvanBacon): This can be really expensive on larger files. We should replace it with a cheaper alternative that just iterates and matches.
|
|
124
|
+
const { importDefault, importAll } = (0, generateImportNames_1.default)(ast);
|
|
125
|
+
// Add "use strict" if the file was parsed as a module, and the directive did
|
|
126
|
+
// not exist yet.
|
|
127
|
+
const { directives } = ast.program;
|
|
128
|
+
if (ast.program.sourceType === 'module' &&
|
|
129
|
+
directives != null &&
|
|
130
|
+
directives.findIndex((d) => d.value.value === 'use strict') === -1) {
|
|
131
|
+
directives.push(types.directive(types.directiveLiteral('use strict')));
|
|
132
|
+
}
|
|
133
|
+
// Perform the import-export transform (in case it's still needed), then
|
|
134
|
+
// fold requires and perform constant folding (if in dev).
|
|
135
|
+
const plugins = [];
|
|
136
|
+
const babelPluginOpts = {
|
|
137
|
+
...options,
|
|
138
|
+
inlineableCalls: [importDefault, importAll],
|
|
139
|
+
importDefault,
|
|
140
|
+
importAll,
|
|
141
|
+
};
|
|
142
|
+
// NOTE(EvanBacon): This is effectively a replacement for the `@babel/plugin-transform-modules-commonjs`
|
|
143
|
+
// plugin that's running in `@@react-native/babel-preset`, but with shared names for inlining requires.
|
|
144
|
+
if (options.experimentalImportSupport === true) {
|
|
145
|
+
plugins.push([metro_transform_plugins_1.default.importExportPlugin, babelPluginOpts]);
|
|
146
|
+
}
|
|
147
|
+
// NOTE(EvanBacon): This can basically never be safely enabled because it doesn't respect side-effects and
|
|
148
|
+
// has no ability to respect side-effects because the transformer hasn't collected all dependencies yet.
|
|
149
|
+
if (options.inlineRequires) {
|
|
150
|
+
plugins.push([
|
|
151
|
+
metro_transform_plugins_1.default.inlineRequiresPlugin,
|
|
152
|
+
{
|
|
153
|
+
...babelPluginOpts,
|
|
154
|
+
ignoredRequires: options.nonInlinedRequires,
|
|
155
|
+
},
|
|
156
|
+
]);
|
|
157
|
+
}
|
|
158
|
+
// NOTE(EvanBacon): We apply this conditionally in `babel-preset-expo` with other AST transforms.
|
|
159
|
+
// plugins.push([metroTransformPlugins.inlinePlugin, babelPluginOpts]);
|
|
160
|
+
// TODO: This MUST be run even though no plugins are added, otherwise the babel runtime generators are broken.
|
|
161
|
+
// if (plugins.length) {
|
|
280
162
|
ast = nullthrows(
|
|
281
163
|
// @ts-expect-error
|
|
282
|
-
(0,
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
164
|
+
(0, core_1.transformFromAstSync)(ast, '', {
|
|
165
|
+
ast: true,
|
|
166
|
+
babelrc: false,
|
|
167
|
+
code: false,
|
|
168
|
+
configFile: false,
|
|
169
|
+
comments: true,
|
|
170
|
+
filename: file.filename,
|
|
171
|
+
plugins,
|
|
172
|
+
sourceMaps: false,
|
|
173
|
+
// Not-Cloning the input AST here should be safe because other code paths above this call
|
|
174
|
+
// are mutating the AST as well and no code is depending on the original AST.
|
|
175
|
+
// However, switching the flag to false caused issues with ES Modules if `experimentalImportSupport` isn't used https://github.com/facebook/metro/issues/641
|
|
176
|
+
// either because one of the plugins is doing something funky or Babel messes up some caches.
|
|
177
|
+
// Make sure to test the above mentioned case before flipping the flag back to false.
|
|
178
|
+
cloneInputAst: true,
|
|
292
179
|
}).ast);
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
180
|
+
// }
|
|
181
|
+
if (!options.dev) {
|
|
182
|
+
// Run the constant folding plugin in its own pass, avoiding race conditions
|
|
183
|
+
// with other plugins that have exit() visitors on Program (e.g. the ESM
|
|
184
|
+
// transform).
|
|
185
|
+
ast = nullthrows(
|
|
186
|
+
// @ts-expect-error
|
|
187
|
+
(0, core_1.transformFromAstSync)(ast, '', {
|
|
188
|
+
ast: true,
|
|
189
|
+
babelrc: false,
|
|
190
|
+
code: false,
|
|
191
|
+
configFile: false,
|
|
192
|
+
comments: true,
|
|
193
|
+
filename: file.filename,
|
|
194
|
+
plugins: [[metro_transform_plugins_1.default.constantFoldingPlugin, babelPluginOpts]],
|
|
195
|
+
sourceMaps: false,
|
|
196
|
+
cloneInputAst: false,
|
|
197
|
+
}).ast);
|
|
198
|
+
}
|
|
199
|
+
let dependencyMapName = '';
|
|
200
|
+
let dependencies;
|
|
201
|
+
let wrappedAst;
|
|
202
|
+
// If the module to transform is a script (meaning that is not part of the
|
|
203
|
+
// dependency graph and it code will just be prepended to the bundle modules),
|
|
204
|
+
// we need to wrap it differently than a commonJS module (also, scripts do
|
|
205
|
+
// not have dependencies).
|
|
206
|
+
if (file.type === 'js/script') {
|
|
207
|
+
dependencies = [];
|
|
208
|
+
wrappedAst = JsFileWrapping_1.default.wrapPolyfill(ast);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
try {
|
|
212
|
+
const opts = {
|
|
213
|
+
asyncRequireModulePath: config.asyncRequireModulePath,
|
|
214
|
+
dependencyTransformer: config.unstable_disableModuleWrapping === true
|
|
215
|
+
? disabledDependencyTransformer
|
|
216
|
+
: undefined,
|
|
217
|
+
dynamicRequires: getDynamicDepsBehavior(config.dynamicDepsInPackages, file.filename),
|
|
218
|
+
inlineableCalls: [importDefault, importAll],
|
|
219
|
+
keepRequireNames: options.dev,
|
|
220
|
+
allowOptionalDependencies: config.allowOptionalDependencies,
|
|
221
|
+
dependencyMapName: config.unstable_dependencyMapReservedName,
|
|
222
|
+
unstable_allowRequireContext: config.unstable_allowRequireContext,
|
|
223
|
+
};
|
|
224
|
+
({ ast, dependencies, dependencyMapName } = (0, collectDependencies_1.default)(ast, opts));
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (error instanceof collectDependencies_1.InvalidRequireCallError) {
|
|
228
|
+
throw new InvalidRequireCallError(error, file.filename);
|
|
229
|
+
}
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
if (config.unstable_disableModuleWrapping === true) {
|
|
233
|
+
wrappedAst = ast;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// TODO: Replace this with a cheaper transform that doesn't require AST.
|
|
237
|
+
({ ast: wrappedAst } = JsFileWrapping_1.default.wrapModule(ast, importDefault, importAll, dependencyMapName, config.globalPrefix));
|
|
238
|
+
}
|
|
327
239
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
} = _JsFileWrapping().default.wrapModule(ast, importDefault, importAll, dependencyMapName, config.globalPrefix));
|
|
240
|
+
const minify = options.minify &&
|
|
241
|
+
options.unstable_transformProfile !== 'hermes-canary' &&
|
|
242
|
+
options.unstable_transformProfile !== 'hermes-stable';
|
|
243
|
+
const reserved = [];
|
|
244
|
+
if (config.unstable_dependencyMapReservedName != null) {
|
|
245
|
+
reserved.push(config.unstable_dependencyMapReservedName);
|
|
335
246
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
type: file.type
|
|
374
|
-
}];
|
|
375
|
-
return {
|
|
376
|
-
dependencies,
|
|
377
|
-
output
|
|
378
|
-
};
|
|
247
|
+
if (minify &&
|
|
248
|
+
file.inputFileSize <= config.optimizationSizeLimit &&
|
|
249
|
+
!config.unstable_disableNormalizePseudoGlobals) {
|
|
250
|
+
// NOTE(EvanBacon): Simply pushing this function will mutate the AST, so it must run before the `generate` step!!
|
|
251
|
+
reserved.push(...metro_transform_plugins_1.default.normalizePseudoGlobals(wrappedAst, {
|
|
252
|
+
reservedNames: reserved,
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
const result = (0, generator_1.default)(wrappedAst, {
|
|
256
|
+
comments: true,
|
|
257
|
+
compact: config.unstable_compactOutput,
|
|
258
|
+
filename: file.filename,
|
|
259
|
+
retainLines: false,
|
|
260
|
+
sourceFileName: file.filename,
|
|
261
|
+
sourceMaps: true,
|
|
262
|
+
}, file.code);
|
|
263
|
+
// @ts-expect-error: incorrectly typed upstream
|
|
264
|
+
let map = result.rawMappings ? result.rawMappings.map(metro_source_map_1.toSegmentTuple) : [];
|
|
265
|
+
let code = result.code;
|
|
266
|
+
if (minify) {
|
|
267
|
+
({ map, code } = await minifyCode(config, projectRoot, file.filename, result.code, file.code, map, reserved));
|
|
268
|
+
}
|
|
269
|
+
const output = [
|
|
270
|
+
{
|
|
271
|
+
data: {
|
|
272
|
+
code,
|
|
273
|
+
lineCount: (0, countLines_1.default)(code),
|
|
274
|
+
map,
|
|
275
|
+
functionMap: file.functionMap,
|
|
276
|
+
},
|
|
277
|
+
type: file.type,
|
|
278
|
+
},
|
|
279
|
+
];
|
|
280
|
+
return {
|
|
281
|
+
dependencies,
|
|
282
|
+
output,
|
|
283
|
+
};
|
|
379
284
|
}
|
|
380
|
-
|
|
381
285
|
/** Transforms an asset file. */
|
|
382
286
|
async function transformAsset(file, context) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
assetPlugins
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
ast: result.ast,
|
|
394
|
-
functionMap: null
|
|
395
|
-
};
|
|
396
|
-
return transformJS(jsFile, context);
|
|
287
|
+
const { assetRegistryPath, assetPlugins } = context.config;
|
|
288
|
+
// TODO: Add web asset hashing in production.
|
|
289
|
+
const result = await assetTransformer.transform(getBabelTransformArgs(file, context), assetRegistryPath, assetPlugins);
|
|
290
|
+
const jsFile = {
|
|
291
|
+
...file,
|
|
292
|
+
type: 'js/module/asset',
|
|
293
|
+
ast: result.ast,
|
|
294
|
+
functionMap: null,
|
|
295
|
+
};
|
|
296
|
+
return transformJS(jsFile, context);
|
|
397
297
|
}
|
|
398
|
-
|
|
399
298
|
/**
|
|
400
299
|
* Transforms a JavaScript file with Babel before processing the file with
|
|
401
300
|
* the generic JavaScript transformation.
|
|
402
301
|
*/
|
|
403
302
|
async function transformJSWithBabel(file, context) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
};
|
|
419
|
-
return await transformJS(jsFile, context);
|
|
303
|
+
const { babelTransformerPath } = context.config;
|
|
304
|
+
const transformer = require(babelTransformerPath);
|
|
305
|
+
const transformResult = await transformer.transform(
|
|
306
|
+
// functionMapBabelPlugin populates metadata.metro.functionMap
|
|
307
|
+
getBabelTransformArgs(file, context, [metro_source_map_1.functionMapBabelPlugin]));
|
|
308
|
+
const jsFile = {
|
|
309
|
+
...file,
|
|
310
|
+
ast: transformResult.ast,
|
|
311
|
+
functionMap: transformResult.metadata?.metro?.functionMap ??
|
|
312
|
+
// Fallback to deprecated explicitly-generated `functionMap`
|
|
313
|
+
transformResult.functionMap ??
|
|
314
|
+
null,
|
|
315
|
+
};
|
|
316
|
+
return await transformJS(jsFile, context);
|
|
420
317
|
}
|
|
421
|
-
async function transformJSON(file, {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}];
|
|
454
|
-
return {
|
|
455
|
-
dependencies: [],
|
|
456
|
-
output
|
|
457
|
-
};
|
|
318
|
+
async function transformJSON(file, { options, config, projectRoot }) {
|
|
319
|
+
let code = config.unstable_disableModuleWrapping === true
|
|
320
|
+
? JsFileWrapping_1.default.jsonToCommonJS(file.code)
|
|
321
|
+
: JsFileWrapping_1.default.wrapJson(file.code, config.globalPrefix);
|
|
322
|
+
let map = [];
|
|
323
|
+
// TODO: When we can reuse transformJS for JSON, we should not derive `minify` separately.
|
|
324
|
+
const minify = options.minify &&
|
|
325
|
+
options.unstable_transformProfile !== 'hermes-canary' &&
|
|
326
|
+
options.unstable_transformProfile !== 'hermes-stable';
|
|
327
|
+
if (minify) {
|
|
328
|
+
({ map, code } = await minifyCode(config, projectRoot, file.filename, code, file.code, map));
|
|
329
|
+
}
|
|
330
|
+
let jsType;
|
|
331
|
+
if (file.type === 'asset') {
|
|
332
|
+
jsType = 'js/module/asset';
|
|
333
|
+
}
|
|
334
|
+
else if (file.type === 'script') {
|
|
335
|
+
jsType = 'js/script';
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
jsType = 'js/module';
|
|
339
|
+
}
|
|
340
|
+
const output = [
|
|
341
|
+
{
|
|
342
|
+
data: { code, lineCount: (0, countLines_1.default)(code), map, functionMap: null },
|
|
343
|
+
type: jsType,
|
|
344
|
+
},
|
|
345
|
+
];
|
|
346
|
+
return {
|
|
347
|
+
dependencies: [],
|
|
348
|
+
output,
|
|
349
|
+
};
|
|
458
350
|
}
|
|
459
|
-
function getBabelTransformArgs(file, {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
projectRoot,
|
|
477
|
-
publicPath: config.publicPath,
|
|
478
|
-
globalPrefix: config.globalPrefix,
|
|
479
|
-
platform: (_babelTransformerOpti = babelTransformerOptions.platform) !== null && _babelTransformerOpti !== void 0 ? _babelTransformerOpti : null
|
|
480
|
-
},
|
|
481
|
-
plugins,
|
|
482
|
-
src: file.code
|
|
483
|
-
};
|
|
351
|
+
function getBabelTransformArgs(file, { options, config, projectRoot }, plugins = []) {
|
|
352
|
+
const { inlineRequires: _, ...babelTransformerOptions } = options;
|
|
353
|
+
return {
|
|
354
|
+
filename: file.filename,
|
|
355
|
+
options: {
|
|
356
|
+
...babelTransformerOptions,
|
|
357
|
+
enableBabelRCLookup: config.enableBabelRCLookup,
|
|
358
|
+
enableBabelRuntime: config.enableBabelRuntime,
|
|
359
|
+
hermesParser: config.hermesParser,
|
|
360
|
+
projectRoot,
|
|
361
|
+
publicPath: config.publicPath,
|
|
362
|
+
globalPrefix: config.globalPrefix,
|
|
363
|
+
platform: babelTransformerOptions.platform ?? null,
|
|
364
|
+
},
|
|
365
|
+
plugins,
|
|
366
|
+
src: file.code,
|
|
367
|
+
};
|
|
484
368
|
}
|
|
485
369
|
async function transform(config, projectRoot, filename, data, options) {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
};
|
|
491
|
-
const sourceCode = data.toString('utf8');
|
|
492
|
-
const {
|
|
493
|
-
unstable_dependencyMapReservedName
|
|
494
|
-
} = config;
|
|
495
|
-
if (unstable_dependencyMapReservedName != null) {
|
|
496
|
-
const position = sourceCode.indexOf(unstable_dependencyMapReservedName);
|
|
497
|
-
if (position > -1) {
|
|
498
|
-
throw new SyntaxError('Source code contains the reserved string `' + unstable_dependencyMapReservedName + '` at character offset ' + position);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
if (filename.endsWith('.json')) {
|
|
502
|
-
const jsonFile = {
|
|
503
|
-
filename,
|
|
504
|
-
inputFileSize: data.length,
|
|
505
|
-
code: sourceCode,
|
|
506
|
-
type: options.type
|
|
370
|
+
const context = {
|
|
371
|
+
config,
|
|
372
|
+
projectRoot,
|
|
373
|
+
options,
|
|
507
374
|
};
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
375
|
+
const sourceCode = data.toString('utf8');
|
|
376
|
+
const { unstable_dependencyMapReservedName } = config;
|
|
377
|
+
if (unstable_dependencyMapReservedName != null) {
|
|
378
|
+
const position = sourceCode.indexOf(unstable_dependencyMapReservedName);
|
|
379
|
+
if (position > -1) {
|
|
380
|
+
throw new SyntaxError('Source code contains the reserved string `' +
|
|
381
|
+
unstable_dependencyMapReservedName +
|
|
382
|
+
'` at character offset ' +
|
|
383
|
+
position);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (filename.endsWith('.json')) {
|
|
387
|
+
const jsonFile = {
|
|
388
|
+
filename,
|
|
389
|
+
inputFileSize: data.length,
|
|
390
|
+
code: sourceCode,
|
|
391
|
+
type: options.type,
|
|
392
|
+
};
|
|
393
|
+
return transformJSON(jsonFile, context);
|
|
394
|
+
}
|
|
395
|
+
if (options.type === 'asset') {
|
|
396
|
+
const file = {
|
|
397
|
+
filename,
|
|
398
|
+
inputFileSize: data.length,
|
|
399
|
+
code: sourceCode,
|
|
400
|
+
type: options.type,
|
|
401
|
+
};
|
|
402
|
+
return transformAsset(file, context);
|
|
403
|
+
}
|
|
511
404
|
const file = {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
405
|
+
filename,
|
|
406
|
+
inputFileSize: data.length,
|
|
407
|
+
code: sourceCode,
|
|
408
|
+
type: options.type === 'script' ? 'js/script' : 'js/module',
|
|
409
|
+
functionMap: null,
|
|
516
410
|
};
|
|
517
|
-
return
|
|
518
|
-
}
|
|
519
|
-
const file = {
|
|
520
|
-
filename,
|
|
521
|
-
inputFileSize: data.length,
|
|
522
|
-
code: sourceCode,
|
|
523
|
-
type: options.type === 'script' ? 'js/script' : 'js/module',
|
|
524
|
-
functionMap: null
|
|
525
|
-
};
|
|
526
|
-
return transformJSWithBabel(file, context);
|
|
411
|
+
return transformJSWithBabel(file, context);
|
|
527
412
|
}
|
|
413
|
+
exports.transform = transform;
|
|
528
414
|
function getCacheKey(config) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
415
|
+
const { babelTransformerPath, minifierPath, ...remainingConfig } = config;
|
|
416
|
+
const filesKey = (0, metro_cache_key_1.default)([
|
|
417
|
+
require.resolve(babelTransformerPath),
|
|
418
|
+
require.resolve(minifierPath),
|
|
419
|
+
require.resolve('metro-transform-worker/src/utils/getMinifier'),
|
|
420
|
+
require.resolve('./asset-transformer'),
|
|
421
|
+
require.resolve('metro/src/ModuleGraph/worker/generateImportNames'),
|
|
422
|
+
require.resolve('metro/src/ModuleGraph/worker/JsFileWrapping'),
|
|
423
|
+
...metro_transform_plugins_1.default.getTransformPluginCacheKeyFiles(),
|
|
424
|
+
]);
|
|
425
|
+
const babelTransformer = require(babelTransformerPath);
|
|
426
|
+
return [
|
|
427
|
+
filesKey,
|
|
428
|
+
(0, metro_cache_1.stableHash)(remainingConfig).toString('hex'),
|
|
429
|
+
babelTransformer.getCacheKey ? babelTransformer.getCacheKey() : '',
|
|
430
|
+
].join('$');
|
|
537
431
|
}
|
|
432
|
+
exports.getCacheKey = getCacheKey;
|
|
538
433
|
//# sourceMappingURL=metro-transform-worker.js.map
|