@expo/metro-config 58.0.10 → 58.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ExpoMetroConfig.d.ts +1 -3
- package/build/ExpoMetroConfig.js +15 -17
- package/build/ExpoMetroConfig.js.map +1 -1
- package/build/serializer/chunking/Chunk.d.ts +45 -0
- package/build/serializer/chunking/Chunk.js +409 -0
- package/build/serializer/chunking/Chunk.js.map +1 -0
- package/build/serializer/chunking/chunkingStrategy.d.ts +40 -0
- package/build/serializer/chunking/chunkingStrategy.js +155 -0
- package/build/serializer/chunking/chunkingStrategy.js.map +1 -0
- package/build/serializer/chunking/computeBitSetChunks.d.ts +49 -0
- package/build/serializer/chunking/computeBitSetChunks.js +268 -0
- package/build/serializer/chunking/computeBitSetChunks.js.map +1 -0
- package/build/serializer/{computeChunkFilenames.d.ts → chunking/computeChunkFilenames.d.ts} +1 -1
- package/build/serializer/chunking/computeChunkFilenames.js.map +1 -0
- package/build/serializer/chunking/createGranularChunkingStrategy.d.ts +2 -0
- package/build/serializer/chunking/createGranularChunkingStrategy.js +282 -0
- package/build/serializer/chunking/createGranularChunkingStrategy.js.map +1 -0
- package/build/serializer/chunking/createLegacyChunkingStrategy.d.ts +2 -0
- package/build/serializer/chunking/createLegacyChunkingStrategy.js +167 -0
- package/build/serializer/chunking/createLegacyChunkingStrategy.js.map +1 -0
- package/build/serializer/chunking/findUnsupportedWorkerAsyncDependency.d.ts +7 -0
- package/build/serializer/chunking/findUnsupportedWorkerAsyncDependency.js +54 -0
- package/build/serializer/chunking/findUnsupportedWorkerAsyncDependency.js.map +1 -0
- package/build/serializer/exportPath.d.ts +1 -0
- package/build/serializer/exportPath.js +18 -3
- package/build/serializer/exportPath.js.map +1 -1
- package/build/serializer/fork/baseJSBundle.d.ts +5 -1
- package/build/serializer/fork/baseJSBundle.js +23 -1
- package/build/serializer/fork/baseJSBundle.js.map +1 -1
- package/build/serializer/fork/js.d.ts +6 -4
- package/build/serializer/fork/js.js +11 -1
- package/build/serializer/fork/js.js.map +1 -1
- package/build/serializer/fork/processModules.d.ts +4 -14
- package/build/serializer/fork/processModules.js +2 -12
- package/build/serializer/fork/processModules.js.map +1 -1
- package/build/serializer/serializeChunks.d.ts +4 -47
- package/build/serializer/serializeChunks.js +17 -655
- package/build/serializer/serializeChunks.js.map +1 -1
- package/build/serializer/serializerAssets.d.ts +13 -1
- package/build/serializer/withExpoSerializers.js +11 -1
- package/build/serializer/withExpoSerializers.js.map +1 -1
- package/package.json +6 -5
- package/build/serializer/computeChunkFilenames.js.map +0 -1
- /package/build/serializer/{computeChunkFilenames.js → chunking/computeChunkFilenames.js} +0 -0
|
@@ -20,122 +20,48 @@ function _export(target, all) {
|
|
|
20
20
|
}
|
|
21
21
|
_export(exports, {
|
|
22
22
|
get Chunk () {
|
|
23
|
-
return Chunk;
|
|
23
|
+
return _Chunk.Chunk;
|
|
24
24
|
},
|
|
25
25
|
get getSortedModules () {
|
|
26
|
-
return getSortedModules;
|
|
26
|
+
return _Chunk.getSortedModules;
|
|
27
27
|
},
|
|
28
28
|
get graphToSerialAssetsAsync () {
|
|
29
29
|
return graphToSerialAssetsAsync;
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
function _bundleToString() {
|
|
33
|
-
const data = /*#__PURE__*/ _interop_require_default(require("@expo/metro/metro/lib/bundleToString"));
|
|
34
|
-
_bundleToString = function() {
|
|
35
|
-
return data;
|
|
36
|
-
};
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
function _isResolvedDependency() {
|
|
40
|
-
const data = require("@expo/metro/metro/lib/isResolvedDependency");
|
|
41
|
-
_isResolvedDependency = function() {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
return data;
|
|
45
|
-
}
|
|
46
|
-
function _assert() {
|
|
47
|
-
const data = /*#__PURE__*/ _interop_require_default(require("assert"));
|
|
48
|
-
_assert = function() {
|
|
49
|
-
return data;
|
|
50
|
-
};
|
|
51
|
-
return data;
|
|
52
|
-
}
|
|
53
|
-
function _path() {
|
|
54
|
-
const data = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
55
|
-
_path = function() {
|
|
56
|
-
return data;
|
|
57
|
-
};
|
|
58
|
-
return data;
|
|
59
|
-
}
|
|
60
32
|
const _getAssets = /*#__PURE__*/ _interop_require_default(require("../transform-worker/getAssets"));
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const _exportPath = require("./exportPath");
|
|
33
|
+
const _Chunk = require("./chunking/Chunk");
|
|
34
|
+
const _createGranularChunkingStrategy = require("./chunking/createGranularChunkingStrategy");
|
|
35
|
+
const _createLegacyChunkingStrategy = require("./chunking/createLegacyChunkingStrategy");
|
|
65
36
|
const _getCssDeps = require("./getCssDeps");
|
|
66
|
-
const _sourceMap = require("./sourceMap");
|
|
67
37
|
function _interop_require_default(obj) {
|
|
68
38
|
return obj && obj.__esModule ? obj : {
|
|
69
39
|
default: obj
|
|
70
40
|
};
|
|
71
41
|
}
|
|
72
|
-
// Lazy-loaded to avoid pulling in metro-source-map at startup
|
|
73
|
-
let _buildHermesBundleAsync;
|
|
74
|
-
function getBuildHermesBundleAsync() {
|
|
75
|
-
if (!_buildHermesBundleAsync) {
|
|
76
|
-
_buildHermesBundleAsync = require('./exportHermes').buildHermesBundleAsync;
|
|
77
|
-
}
|
|
78
|
-
return _buildHermesBundleAsync;
|
|
79
|
-
}
|
|
80
|
-
let _baseJSBundleWithDependencies;
|
|
81
|
-
function getBaseJSBundleWithDependencies() {
|
|
82
|
-
if (!_baseJSBundleWithDependencies) {
|
|
83
|
-
_baseJSBundleWithDependencies = require('./fork/baseJSBundle').baseJSBundleWithDependencies;
|
|
84
|
-
}
|
|
85
|
-
return _baseJSBundleWithDependencies;
|
|
86
|
-
}
|
|
87
|
-
let _getBaseUrlOption;
|
|
88
|
-
function getBaseUrlOption(...args) {
|
|
89
|
-
if (!_getBaseUrlOption) {
|
|
90
|
-
_getBaseUrlOption = require('./fork/baseJSBundle').getBaseUrlOption;
|
|
91
|
-
}
|
|
92
|
-
return _getBaseUrlOption(...args);
|
|
93
|
-
}
|
|
94
|
-
let _getPlatformOption;
|
|
95
|
-
function getPlatformOption(...args) {
|
|
96
|
-
if (!_getPlatformOption) {
|
|
97
|
-
_getPlatformOption = require('./fork/baseJSBundle').getPlatformOption;
|
|
98
|
-
}
|
|
99
|
-
return _getPlatformOption(...args);
|
|
100
|
-
}
|
|
101
42
|
async function graphToSerialAssetsAsync(config, serializeChunkOptions, ...props) {
|
|
102
43
|
const [entryFile, preModules, graph, options] = props;
|
|
103
44
|
const cssDeps = (0, _getCssDeps.getCssSerialAssets)(graph.dependencies, {
|
|
104
45
|
entryFile,
|
|
105
46
|
projectRoot: options.projectRoot
|
|
106
47
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
removeEntryDepsFromAsyncChunks(entryChunk, chunks);
|
|
118
|
-
const commonChunk = extractCommonChunk(chunks, graph, options);
|
|
119
|
-
if (commonChunk) {
|
|
120
|
-
entryChunk.requiredChunks.add(commonChunk);
|
|
121
|
-
chunks.add(commonChunk);
|
|
122
|
-
}
|
|
123
|
-
deduplicateAgainstKnownChunks(chunks, entryChunk, commonChunk);
|
|
124
|
-
removeEmptyChunks(chunks);
|
|
125
|
-
if (commonChunk) {
|
|
126
|
-
createRuntimeChunk(entryChunk, chunks, graph, options);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// TODO(@kitten): unclear why `isExporting` is hardcoded below
|
|
130
|
-
const recomputeChunkNames = !!options.serializerOptions?.exporting;
|
|
131
|
-
const jsAssets = await serializeChunksAsync(chunks, config.serializer ?? {}, serializeChunkOptions, recomputeChunkNames);
|
|
48
|
+
const context = {
|
|
49
|
+
serializerConfig: config.serializer ?? {},
|
|
50
|
+
serializeChunkOptions,
|
|
51
|
+
entryFile,
|
|
52
|
+
preModules,
|
|
53
|
+
graph,
|
|
54
|
+
options
|
|
55
|
+
};
|
|
56
|
+
const strategy = serializeChunkOptions.chunkingStrategy === 'granular' ? (0, _createGranularChunkingStrategy.createGranularChunkingStrategy)(context) : (0, _createLegacyChunkingStrategy.createLegacyChunkingStrategy)(context);
|
|
57
|
+
const jsAssets = await strategy.serializeAsync();
|
|
132
58
|
// TODO: Can this be anything besides true?
|
|
133
59
|
const isExporting = true;
|
|
134
|
-
const baseUrl = getBaseUrlOption(graph, {
|
|
60
|
+
const baseUrl = (0, _Chunk.getBaseUrlOption)(graph, {
|
|
135
61
|
serializerOptions: serializeChunkOptions
|
|
136
62
|
});
|
|
137
63
|
const assetPublicUrl = (baseUrl.replace(/\/+$/, '') ?? '') + '/assets';
|
|
138
|
-
const platform = getPlatformOption(graph, options) ?? 'web';
|
|
64
|
+
const platform = (0, _Chunk.getPlatformOption)(graph, options) ?? 'web';
|
|
139
65
|
const customTransformOptions = graph.transformOptions?.customTransformOptions;
|
|
140
66
|
const isHosted = platform === 'web' || customTransformOptions?.hosted && isExporting;
|
|
141
67
|
const publicPath = isExporting ? isHosted ? `/assets?export_path=${assetPublicUrl}` : assetPublicUrl : '/assets/?unstable_path=.';
|
|
@@ -157,569 +83,5 @@ async function graphToSerialAssetsAsync(config, serializeChunkOptions, ...props)
|
|
|
157
83
|
assets: metroAssets
|
|
158
84
|
};
|
|
159
85
|
}
|
|
160
|
-
class Chunk {
|
|
161
|
-
name;
|
|
162
|
-
entries;
|
|
163
|
-
graph;
|
|
164
|
-
options;
|
|
165
|
-
isAsync;
|
|
166
|
-
isVendor;
|
|
167
|
-
isEntry;
|
|
168
|
-
deps = new Set();
|
|
169
|
-
preModules = new Set();
|
|
170
|
-
// Chunks that are required to be loaded synchronously before this chunk.
|
|
171
|
-
// These are included in the HTML as <script> tags.
|
|
172
|
-
requiredChunks = new Set();
|
|
173
|
-
/** Whether this chunk owns an isolated module registry and must retain all of its dependencies.
|
|
174
|
-
* @remarks
|
|
175
|
-
* When a chunk is sealed, its `deps` and `preModules` shouldn't be altered, and it doesn't qualify
|
|
176
|
-
* for bundle/chunk splitting. This is the case for web workers, which must form a "closed" and
|
|
177
|
-
* self-sufficient entry bundle.
|
|
178
|
-
*/ sealed = false;
|
|
179
|
-
constructor(name, entries, graph, options, isAsync = false, isVendor = false, isEntry = false){
|
|
180
|
-
this.name = name;
|
|
181
|
-
this.entries = entries;
|
|
182
|
-
this.graph = graph;
|
|
183
|
-
this.options = options;
|
|
184
|
-
this.isAsync = isAsync;
|
|
185
|
-
this.isVendor = isVendor;
|
|
186
|
-
this.isEntry = isEntry;
|
|
187
|
-
this.deps = new Set(entries);
|
|
188
|
-
}
|
|
189
|
-
seal() {
|
|
190
|
-
this.sealed = true;
|
|
191
|
-
}
|
|
192
|
-
getPlatform() {
|
|
193
|
-
(0, _assert().default)(this.graph.transformOptions.platform, "platform is required to be in graph's transformOptions");
|
|
194
|
-
return this.graph.transformOptions.platform;
|
|
195
|
-
}
|
|
196
|
-
getFilename(src) {
|
|
197
|
-
return !this.options.serializerOptions?.exporting ? this.name : (0, _exportPath.getExportPathForDependencyWithOptions)(this.name, {
|
|
198
|
-
platform: this.getPlatform(),
|
|
199
|
-
src,
|
|
200
|
-
serverRoot: this.options.serverRoot
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
getStableChunkSource(serializerConfig) {
|
|
204
|
-
return this.options.dev ? '' : this.serializeToCodeWithTemplates(serializerConfig, {
|
|
205
|
-
// Disable source maps when creating a sha to reduce the number of possible changes that could
|
|
206
|
-
// influence the cache hit.
|
|
207
|
-
serializerOptions: {
|
|
208
|
-
includeSourceMaps: false
|
|
209
|
-
},
|
|
210
|
-
sourceMapUrl: undefined,
|
|
211
|
-
debugId: undefined
|
|
212
|
-
}).code;
|
|
213
|
-
}
|
|
214
|
-
serializeToCodeWithTemplates(serializerConfig, options = {}) {
|
|
215
|
-
const entryFile = this.name;
|
|
216
|
-
// TODO: Disable all debugId steps when a dev server is enabled. This is an export-only feature.
|
|
217
|
-
const preModules = [
|
|
218
|
-
...(options.preModules ?? this.preModules).values()
|
|
219
|
-
];
|
|
220
|
-
const dependencies = [
|
|
221
|
-
...this.deps
|
|
222
|
-
];
|
|
223
|
-
const jsSplitBundle = getBaseJSBundleWithDependencies()(entryFile, preModules, dependencies, {
|
|
224
|
-
...this.options,
|
|
225
|
-
runBeforeMainModule: serializerConfig?.getModulesRunBeforeMainModule?.(_path().default.relative(this.options.projectRoot, entryFile)) ?? [],
|
|
226
|
-
runModule: this.options.runModule && !this.isVendor && (this.isEntry || !this.isAsync),
|
|
227
|
-
modulesOnly: this.options.modulesOnly || preModules.length === 0,
|
|
228
|
-
platform: this.getPlatform(),
|
|
229
|
-
baseUrl: getBaseUrlOption(this.graph, this.options),
|
|
230
|
-
splitChunks: !!this.options.serializerOptions?.splitChunks,
|
|
231
|
-
skipWrapping: true,
|
|
232
|
-
computedAsyncModulePaths: null,
|
|
233
|
-
...options
|
|
234
|
-
});
|
|
235
|
-
return {
|
|
236
|
-
code: (0, _bundleToString().default)(jsSplitBundle).code,
|
|
237
|
-
paths: jsSplitBundle.paths
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
hasAbsolutePath(absolutePath) {
|
|
241
|
-
for (const dep of this.deps){
|
|
242
|
-
if (dep.path === absolutePath) {
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
_asyncTargets;
|
|
249
|
-
getAsyncChunkTargets(chunkByPath) {
|
|
250
|
-
if (this._asyncTargets) {
|
|
251
|
-
return this._asyncTargets;
|
|
252
|
-
}
|
|
253
|
-
const targets = new Set();
|
|
254
|
-
this._asyncTargets = targets;
|
|
255
|
-
if (this.options.includeAsyncPaths) {
|
|
256
|
-
return targets;
|
|
257
|
-
}
|
|
258
|
-
for (const module1 of this.deps){
|
|
259
|
-
for (const dep of module1.dependencies.values()){
|
|
260
|
-
if ((0, _isResolvedDependency().isResolvedDependency)(dep) && dep.data.data.asyncType) {
|
|
261
|
-
const target = chunkByPath.get(dep.absolutePath);
|
|
262
|
-
// NOTE(kitten): Chunk merges can leave async imports pointing at non-async
|
|
263
|
-
// (entry/vendor) chunks; those are loaded eagerly so we skip them here.
|
|
264
|
-
if (target?.isAsync) targets.add(target);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return targets;
|
|
269
|
-
}
|
|
270
|
-
getComputedPathsForAsyncDependencies(chunksByPath, filenamesByChunk) {
|
|
271
|
-
const baseUrl = getBaseUrlOption(this.graph, this.options);
|
|
272
|
-
// Only calculate production paths when all chunks are being exported.
|
|
273
|
-
if (this.options.includeAsyncPaths) {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
const computedAsyncModulePaths = {};
|
|
277
|
-
this.deps.forEach((module1)=>{
|
|
278
|
-
module1.dependencies.forEach((dependency)=>{
|
|
279
|
-
if ((0, _isResolvedDependency().isResolvedDependency)(dependency) && dependency.data.data.asyncType) {
|
|
280
|
-
const chunkContainingModule = chunksByPath.get(dependency.absolutePath);
|
|
281
|
-
(0, _assert().default)(chunkContainingModule, 'Chunk containing module not found: ' + dependency.absolutePath);
|
|
282
|
-
if (chunkContainingModule.isAsync) {
|
|
283
|
-
const moduleIdName = filenamesByChunk.get(chunkContainingModule);
|
|
284
|
-
(0, _assert().default)(moduleIdName, 'Precomputed filename missing for async chunk: ' + chunkContainingModule.name);
|
|
285
|
-
computedAsyncModulePaths[dependency.absolutePath] = (baseUrl ?? '/') + moduleIdName;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
return computedAsyncModulePaths;
|
|
291
|
-
}
|
|
292
|
-
getAdjustedSourceMapUrl(filename) {
|
|
293
|
-
// Metro really only accounts for development, so we'll use the defaults here.
|
|
294
|
-
if (this.options.dev) {
|
|
295
|
-
return this.options.sourceMapUrl ?? null;
|
|
296
|
-
}
|
|
297
|
-
if (this.options.serializerOptions?.includeSourceMaps !== true) {
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
if (this.options.inlineSourceMap || !this.options.sourceMapUrl) {
|
|
301
|
-
return this.options.sourceMapUrl ?? null;
|
|
302
|
-
}
|
|
303
|
-
const platform = this.getPlatform();
|
|
304
|
-
const isAbsolute = platform !== 'web';
|
|
305
|
-
const baseUrl = getBaseUrlOption(this.graph, this.options);
|
|
306
|
-
const isAbsoluteBaseUrl = !!baseUrl?.match(/https?:\/\//);
|
|
307
|
-
const pathname = (isAbsoluteBaseUrl ? '' : baseUrl.replace(/\/+$/, '')) + '/' + filename.replace(/^\/+$/, '') + '.map';
|
|
308
|
-
let adjustedSourceMapUrl = this.options.sourceMapUrl;
|
|
309
|
-
// Metro has lots of issues...
|
|
310
|
-
if (this.options.sourceMapUrl.startsWith('//localhost')) {
|
|
311
|
-
adjustedSourceMapUrl = 'http:' + this.options.sourceMapUrl;
|
|
312
|
-
}
|
|
313
|
-
try {
|
|
314
|
-
const parsed = new URL(pathname, isAbsoluteBaseUrl ? baseUrl : adjustedSourceMapUrl);
|
|
315
|
-
if (isAbsoluteBaseUrl || isAbsolute) {
|
|
316
|
-
return parsed.href;
|
|
317
|
-
}
|
|
318
|
-
return parsed.pathname;
|
|
319
|
-
} catch (error) {
|
|
320
|
-
// NOTE: export:embed that don't use baseUrl will use file paths instead of URLs.
|
|
321
|
-
if (!this.options.dev && isAbsolute) {
|
|
322
|
-
return adjustedSourceMapUrl;
|
|
323
|
-
}
|
|
324
|
-
console.error(`Failed to link source maps because the source map URL "${this.options.sourceMapUrl}" is corrupt:`, error);
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
serializeToCode(serializerConfig, { debugId, chunksByPath, filenamesByChunk, filename, preModules }) {
|
|
329
|
-
return this.serializeToCodeWithTemplates(serializerConfig, {
|
|
330
|
-
skipWrapping: false,
|
|
331
|
-
sourceMapUrl: this.getAdjustedSourceMapUrl(filename) ?? undefined,
|
|
332
|
-
computedAsyncModulePaths: this.getComputedPathsForAsyncDependencies(chunksByPath, filenamesByChunk),
|
|
333
|
-
debugId,
|
|
334
|
-
preModules
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
boolishTransformOption(name) {
|
|
338
|
-
const value = this.graph.transformOptions?.customTransformOptions?.[name];
|
|
339
|
-
return value === true || value === 'true' || value === '1';
|
|
340
|
-
}
|
|
341
|
-
async serializeToAssetsAsync(serializerConfig, chunksByPath, filenamesByChunk, { includeSourceMaps, unstable_beforeAssetSerializationPlugins }) {
|
|
342
|
-
const outputFile = filenamesByChunk.get(this);
|
|
343
|
-
(0, _assert().default)(outputFile, 'Precomputed filename missing for chunk: ' + this.name);
|
|
344
|
-
// We already use a stable hash for the output filename, so we'll reuse that for the debugId.
|
|
345
|
-
const debugId = (0, _debugId.stringToUUID)(_path().default.basename(outputFile, _path().default.extname(outputFile)));
|
|
346
|
-
let finalPreModules = [
|
|
347
|
-
...this.preModules
|
|
348
|
-
];
|
|
349
|
-
if (unstable_beforeAssetSerializationPlugins) {
|
|
350
|
-
for (const plugin of unstable_beforeAssetSerializationPlugins){
|
|
351
|
-
finalPreModules = plugin({
|
|
352
|
-
graph: this.graph,
|
|
353
|
-
premodules: finalPreModules,
|
|
354
|
-
debugId
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
const jsCode = this.serializeToCode(serializerConfig, {
|
|
359
|
-
chunksByPath,
|
|
360
|
-
filenamesByChunk,
|
|
361
|
-
filename: outputFile,
|
|
362
|
-
debugId,
|
|
363
|
-
preModules: new Set(finalPreModules)
|
|
364
|
-
});
|
|
365
|
-
const relativeEntry = _path().default.relative(this.options.projectRoot, this.name);
|
|
366
|
-
const jsAsset = {
|
|
367
|
-
filename: outputFile,
|
|
368
|
-
originFilename: relativeEntry,
|
|
369
|
-
type: 'js',
|
|
370
|
-
metadata: {
|
|
371
|
-
isAsync: this.isAsync,
|
|
372
|
-
requires: [
|
|
373
|
-
...this.requiredChunks.values()
|
|
374
|
-
].map((chunk)=>{
|
|
375
|
-
const filename = filenamesByChunk.get(chunk);
|
|
376
|
-
(0, _assert().default)(filename, 'Precomputed filename missing for required chunk: ' + chunk.name);
|
|
377
|
-
return filename;
|
|
378
|
-
}),
|
|
379
|
-
// Provide a list of module paths that can be used for matching chunks to routes.
|
|
380
|
-
// TODO: Move HTML serializing closer to this code so we can reduce passing this much data around.
|
|
381
|
-
modulePaths: [
|
|
382
|
-
...this.deps
|
|
383
|
-
].map((module1)=>module1.path),
|
|
384
|
-
paths: jsCode.paths,
|
|
385
|
-
expoDomComponentReferences: collectOutputReferences(this.deps, 'expoDomComponentReference'),
|
|
386
|
-
reactClientReferences: collectOutputReferences(this.deps, 'reactClientReference'),
|
|
387
|
-
reactServerReferences: collectOutputReferences(this.deps, 'reactServerReference'),
|
|
388
|
-
loaderReferences: collectOutputReferences(this.deps, 'loaderReference')
|
|
389
|
-
},
|
|
390
|
-
source: jsCode.code
|
|
391
|
-
};
|
|
392
|
-
const assets = [
|
|
393
|
-
jsAsset
|
|
394
|
-
];
|
|
395
|
-
// debugId is passed into `sourceMapString` so the bundler-map path
|
|
396
|
-
// emits it inline rather than a JSON.parse + JSON.stringify
|
|
397
|
-
// roundtrip; the Hermes branch below has to splice into a finished
|
|
398
|
-
// JSON string because `buildHermesBundleAsync` is opaque.
|
|
399
|
-
// NOTE: skipped for inline source maps since they don't need
|
|
400
|
-
// disambiguation. We only emit `debugId` (Sentry also reads
|
|
401
|
-
// `debug_id`, but bun doesn't).
|
|
402
|
-
if (// Only include the source map if the `options.sourceMapUrl` option is provided and we are exporting a static build.
|
|
403
|
-
includeSourceMaps && !this.options.inlineSourceMap && this.options.sourceMapUrl) {
|
|
404
|
-
const modules = [
|
|
405
|
-
...finalPreModules,
|
|
406
|
-
...getSortedModules([
|
|
407
|
-
...this.deps
|
|
408
|
-
], {
|
|
409
|
-
createModuleId: this.options.createModuleId
|
|
410
|
-
})
|
|
411
|
-
].map((module1)=>{
|
|
412
|
-
// TODO: Make this user-configurable.
|
|
413
|
-
// Make all paths relative to the server root to prevent the entire user filesystem from being exposed.
|
|
414
|
-
if (_path().default.isAbsolute(module1.path)) {
|
|
415
|
-
return {
|
|
416
|
-
...module1,
|
|
417
|
-
path: '/' + (0, _filePath.toPosixPath)(_path().default.relative(this.options.serverRoot ?? this.options.projectRoot, module1.path))
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
return module1;
|
|
421
|
-
});
|
|
422
|
-
// TODO: We may not need to set `debugId` on the bundler sourcemap when
|
|
423
|
-
// Hermes is enabled, since we ship a separate `.hbc.map` for that case.
|
|
424
|
-
const sourceMap = (0, _sourceMap.sourceMapString)(modules, {
|
|
425
|
-
excludeSource: false,
|
|
426
|
-
...this.options,
|
|
427
|
-
debugId
|
|
428
|
-
});
|
|
429
|
-
assets.push({
|
|
430
|
-
filename: this.options.dev ? jsAsset.filename + '.map' : outputFile + '.map',
|
|
431
|
-
originFilename: jsAsset.originFilename,
|
|
432
|
-
type: 'map',
|
|
433
|
-
metadata: {},
|
|
434
|
-
source: sourceMap
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
if (this.boolishTransformOption('bytecode') && this.isHermesEnabled()) {
|
|
438
|
-
const adjustedSource = jsAsset.source.replace(/^\/\/# (sourceMappingURL)=(.*)$/gm, (...props)=>{
|
|
439
|
-
if (props[1] === 'sourceMappingURL') {
|
|
440
|
-
const mapName = props[2].replace(/\.js\.map$/, '.hbc.map');
|
|
441
|
-
return `//# ${props[1]}=` + mapName;
|
|
442
|
-
}
|
|
443
|
-
return '';
|
|
444
|
-
});
|
|
445
|
-
// TODO: Generate hbc for each chunk
|
|
446
|
-
const hermesBundleOutput = await getBuildHermesBundleAsync()({
|
|
447
|
-
projectRoot: this.options.projectRoot,
|
|
448
|
-
filename: this.name,
|
|
449
|
-
code: adjustedSource,
|
|
450
|
-
map: assets[1] ? assets[1].source : null,
|
|
451
|
-
// TODO: Maybe allow prod + no minify.
|
|
452
|
-
minify: true
|
|
453
|
-
});
|
|
454
|
-
if (hermesBundleOutput.hbc) {
|
|
455
|
-
// TODO: Unclear if we should add multiple assets, link the assets, or mutate the first asset.
|
|
456
|
-
// jsAsset.metadata.hbc = hermesBundleOutput.hbc;
|
|
457
|
-
// @ts-expect-error: TODO
|
|
458
|
-
jsAsset.source = hermesBundleOutput.hbc;
|
|
459
|
-
jsAsset.filename = jsAsset.filename.replace(/\.js$/, '.hbc');
|
|
460
|
-
// Replace mappings with hbc
|
|
461
|
-
if (jsAsset.metadata.paths) {
|
|
462
|
-
jsAsset.metadata.paths = Object.fromEntries(Object.entries(jsAsset.metadata.paths).map(([key, value])=>[
|
|
463
|
-
key,
|
|
464
|
-
Object.fromEntries(Object.entries(value).map(([key, value])=>[
|
|
465
|
-
key,
|
|
466
|
-
value ? value.replace(/\.js$/, '.hbc') : value
|
|
467
|
-
]))
|
|
468
|
-
]));
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
if (assets[1] && hermesBundleOutput.sourcemap) {
|
|
472
|
-
assets[1].source = debugId ? (0, _sourceMap.appendDebugIdToSourceMap)(hermesBundleOutput.sourcemap, debugId) : hermesBundleOutput.sourcemap;
|
|
473
|
-
assets[1].filename = assets[1].filename.replace(/\.js\.map$/, '.hbc.map');
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
return assets;
|
|
477
|
-
}
|
|
478
|
-
supportsBytecode() {
|
|
479
|
-
return this.getPlatform() !== 'web';
|
|
480
|
-
}
|
|
481
|
-
isHermesEnabled() {
|
|
482
|
-
// TODO: Revisit.
|
|
483
|
-
// TODO: There could be an issue with having the serializer for export:embed output hermes since the native scripts will
|
|
484
|
-
// also create hermes bytecode. We may need to disable in one of the two places.
|
|
485
|
-
return !this.options.dev && this.supportsBytecode() && this.graph.transformOptions.customTransformOptions?.engine === 'hermes';
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
function getSortedModules(modules, { createModuleId }) {
|
|
489
|
-
// Assign IDs to modules in a consistent order
|
|
490
|
-
for (const module1 of modules){
|
|
491
|
-
createModuleId(module1.path);
|
|
492
|
-
}
|
|
493
|
-
// Sort by IDs
|
|
494
|
-
return modules.sort((a, b)=>createModuleId(a.path) - createModuleId(b.path));
|
|
495
|
-
}
|
|
496
|
-
// Convert file paths to regex matchers.
|
|
497
|
-
function pathToRegex(path) {
|
|
498
|
-
// Escape regex special characters, except for '*'
|
|
499
|
-
let regexSafePath = path.replace(/[-[\]{}()+?.,\\^$|#\s]/g, '\\$&');
|
|
500
|
-
// Replace '*' with '.*' to act as a wildcard in regex
|
|
501
|
-
regexSafePath = regexSafePath.replace(/\*/g, '.*');
|
|
502
|
-
// Create a RegExp object with the modified string
|
|
503
|
-
return new RegExp('^' + regexSafePath + '$');
|
|
504
|
-
}
|
|
505
|
-
function collectOutputReferences(modules, key) {
|
|
506
|
-
return [
|
|
507
|
-
...new Set([
|
|
508
|
-
...modules
|
|
509
|
-
].map((module1)=>{
|
|
510
|
-
return module1.output.map((output)=>{
|
|
511
|
-
// TODO: This is a mess. This needs to be properly typed
|
|
512
|
-
const data = output.data;
|
|
513
|
-
if (key in data && typeof data[key] === 'string') {
|
|
514
|
-
return data[key];
|
|
515
|
-
}
|
|
516
|
-
return undefined;
|
|
517
|
-
});
|
|
518
|
-
}).flat())
|
|
519
|
-
].filter((value)=>typeof value === 'string');
|
|
520
|
-
}
|
|
521
|
-
function getEntryModulesForChunkSettings(graph, settings) {
|
|
522
|
-
const modules = new Set();
|
|
523
|
-
for (const entry of graph.dependencies){
|
|
524
|
-
if (settings.test.test(entry[0])) {
|
|
525
|
-
modules.add(entry[1]);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
return modules;
|
|
529
|
-
}
|
|
530
|
-
function chunkIdForModules(modules) {
|
|
531
|
-
const modPaths = [];
|
|
532
|
-
for (const mod of modules)modPaths.push(mod.path);
|
|
533
|
-
return modPaths.sort().join('=>');
|
|
534
|
-
}
|
|
535
|
-
// TODO(@kitten): The recursion is starting to hurt clarity here a bit
|
|
536
|
-
function gatherChunks(runtimePremodules, chunks, settings, preModules, graph, options, isAsync = false, isEntry = false) {
|
|
537
|
-
const entryModules = getEntryModulesForChunkSettings(graph, settings);
|
|
538
|
-
const entryChunks = new Set();
|
|
539
|
-
if (!entryModules.size) {
|
|
540
|
-
return entryChunks;
|
|
541
|
-
}
|
|
542
|
-
for (const chunk of chunks){
|
|
543
|
-
for (const entry of chunk.entries){
|
|
544
|
-
// Remove already processed entries
|
|
545
|
-
if (entryModules.delete(entry)) {
|
|
546
|
-
entryChunks.add(chunk);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
// Prevent processing the same entry file twice.
|
|
550
|
-
if (!entryModules.size) {
|
|
551
|
-
return entryChunks;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
const entryChunk = new Chunk(chunkIdForModules(entryModules), entryModules, graph, options, isAsync, false, isEntry);
|
|
555
|
-
// Add all the pre-modules to the first chunk.
|
|
556
|
-
if (preModules.length) {
|
|
557
|
-
// On native, use the preModules in insert code in the entry chunk.
|
|
558
|
-
for (const module1 of preModules.values()){
|
|
559
|
-
entryChunk.preModules.add(module1);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
chunks.add(entryChunk);
|
|
563
|
-
entryChunks.add(entryChunk);
|
|
564
|
-
function includeModule(entryModule) {
|
|
565
|
-
const splitChunks = entryChunk.options.serializerOptions?.splitChunks !== false;
|
|
566
|
-
for (const dependency of entryModule.dependencies.values()){
|
|
567
|
-
const asyncType = dependency.data.data.asyncType;
|
|
568
|
-
const isWorker = asyncType === 'worker';
|
|
569
|
-
if (!(0, _isResolvedDependency().isResolvedDependency)(dependency)) {
|
|
570
|
-
continue;
|
|
571
|
-
} else if (asyncType && // Workers require standalone bundles even when ordinary chunk splitting is disabled.
|
|
572
|
-
(isWorker || splitChunks)) {
|
|
573
|
-
if (isWorker && options.includeAsyncPaths) {
|
|
574
|
-
continue;
|
|
575
|
-
}
|
|
576
|
-
const asyncChunks = gatherChunks(runtimePremodules, chunks, {
|
|
577
|
-
test: pathToRegex(dependency.absolutePath)
|
|
578
|
-
}, isWorker ? runtimePremodules : [], graph, options, true, isWorker);
|
|
579
|
-
// Seal all chunks that are for web workers, as these must be self-sufficient chunks
|
|
580
|
-
if (isWorker) {
|
|
581
|
-
(0, _assert().default)(asyncChunks.size, `Worker chunk not found for: ${dependency.absolutePath}`);
|
|
582
|
-
for (const chunk of asyncChunks){
|
|
583
|
-
chunk.seal();
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
} else {
|
|
587
|
-
const module1 = graph.dependencies.get(dependency.absolutePath);
|
|
588
|
-
if (module1) {
|
|
589
|
-
// Prevent circular dependencies from creating infinite loops.
|
|
590
|
-
if (!entryChunk.deps.has(module1)) {
|
|
591
|
-
entryChunk.deps.add(module1);
|
|
592
|
-
includeModule(module1);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
for (const entryModule of entryModules){
|
|
599
|
-
includeModule(entryModule);
|
|
600
|
-
}
|
|
601
|
-
return entryChunks;
|
|
602
|
-
}
|
|
603
|
-
function removeEntryDepsFromAsyncChunks(entryChunk, chunks) {
|
|
604
|
-
for (const chunk of chunks){
|
|
605
|
-
if (!chunk.sealed && !chunk.isEntry && chunk.isAsync) {
|
|
606
|
-
for (const dep of chunk.deps){
|
|
607
|
-
if (entryChunk.deps.has(dep)) {
|
|
608
|
-
// Remove the dependency from the async chunk since it will be loaded in the main chunk.
|
|
609
|
-
chunk.deps.delete(dep);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
function extractCommonChunk(chunks, graph, options) {
|
|
616
|
-
const toCompare = [
|
|
617
|
-
...chunks.values()
|
|
618
|
-
].filter((chunk)=>!chunk.sealed);
|
|
619
|
-
const commonDependencies = new Set();
|
|
620
|
-
while(toCompare.length){
|
|
621
|
-
const chunk = toCompare.shift();
|
|
622
|
-
for (const chunk2 of toCompare){
|
|
623
|
-
if (chunk !== chunk2 && chunk.isAsync && chunk2.isAsync) {
|
|
624
|
-
for (const dep of chunk.deps){
|
|
625
|
-
if (chunk2.deps.has(dep)) {
|
|
626
|
-
chunk.deps.delete(dep);
|
|
627
|
-
chunk2.deps.delete(dep);
|
|
628
|
-
commonDependencies.add(dep);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
// If common dependencies were found, extract them to the shared chunk.
|
|
635
|
-
if (commonDependencies.size) {
|
|
636
|
-
return new Chunk('/__common.js', commonDependencies, graph, options, false, true);
|
|
637
|
-
}
|
|
638
|
-
return undefined;
|
|
639
|
-
}
|
|
640
|
-
function deduplicateAgainstKnownChunks(chunks, entryChunk, commonChunk) {
|
|
641
|
-
// TODO: Optimize this pass more.
|
|
642
|
-
// Remove all dependencies from async chunks that are already in the common chunk.
|
|
643
|
-
for (const chunk of chunks){
|
|
644
|
-
if (!chunk.sealed && !chunk.isEntry && chunk !== commonChunk) {
|
|
645
|
-
for (const dep of chunk.deps){
|
|
646
|
-
if (entryChunk.deps.has(dep) || commonChunk?.deps.has(dep)) {
|
|
647
|
-
chunk.deps.delete(dep);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
function removeEmptyChunks(chunks) {
|
|
654
|
-
for (const chunk of chunks){
|
|
655
|
-
if (!chunk.sealed && !chunk.isEntry && chunk.deps.size === 0) {
|
|
656
|
-
chunks.delete(chunk);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
function createRuntimeChunk(entryChunk, chunks, graph, options) {
|
|
661
|
-
const runtimeChunk = new Chunk('/__expo-metro-runtime.js', new Set(), graph, options, false, true);
|
|
662
|
-
// All premodules (including metro-runtime) should load first
|
|
663
|
-
for (const preModule of entryChunk.preModules){
|
|
664
|
-
runtimeChunk.preModules.add(preModule);
|
|
665
|
-
}
|
|
666
|
-
entryChunk.preModules = new Set();
|
|
667
|
-
for (const chunk of chunks){
|
|
668
|
-
// Runtime chunk has to load before any other a.k.a all chunks require it.
|
|
669
|
-
chunk.requiredChunks.add(runtimeChunk);
|
|
670
|
-
}
|
|
671
|
-
chunks.add(runtimeChunk);
|
|
672
|
-
}
|
|
673
|
-
function makeChunkByPathLookupMap(chunks) {
|
|
674
|
-
const chunkByPath = new Map();
|
|
675
|
-
// First, we populate chunks with entry module paths
|
|
676
|
-
for (const chunk of chunks){
|
|
677
|
-
for (const entry of chunk.entries){
|
|
678
|
-
if (!chunkByPath.has(entry.path)) {
|
|
679
|
-
chunkByPath.set(entry.path, chunk);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
// We then populate the chunks' module paths, excluding sealed chunks...
|
|
684
|
-
for (const chunk of chunks){
|
|
685
|
-
if (!chunk.sealed) {
|
|
686
|
-
for (const module1 of chunk.deps){
|
|
687
|
-
if (!chunkByPath.has(module1.path)) {
|
|
688
|
-
chunkByPath.set(module1.path, chunk);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
// ...then populate with missing paths from sealed chunks.
|
|
694
|
-
// This gives precedence for modules from unsealed chunks after entry modules
|
|
695
|
-
for (const chunk of chunks){
|
|
696
|
-
if (chunk.sealed) {
|
|
697
|
-
for (const module1 of chunk.deps){
|
|
698
|
-
if (!chunkByPath.has(module1.path)) {
|
|
699
|
-
chunkByPath.set(module1.path, chunk);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
return chunkByPath;
|
|
705
|
-
}
|
|
706
|
-
async function serializeChunksAsync(chunks, serializerConfig, options, recomputeChunkNames) {
|
|
707
|
-
const jsAssets = [];
|
|
708
|
-
const chunksByPath = makeChunkByPathLookupMap(chunks);
|
|
709
|
-
const filenamesByChunk = (0, _computeChunkFilenames.precomputeChunkFilenames)({
|
|
710
|
-
chunks,
|
|
711
|
-
chunksByPath,
|
|
712
|
-
serializerConfig,
|
|
713
|
-
recomputeChunkNames
|
|
714
|
-
});
|
|
715
|
-
const serializeTasks = [];
|
|
716
|
-
for (const chunk of chunks){
|
|
717
|
-
serializeTasks.push((async ()=>{
|
|
718
|
-
jsAssets.push(...await chunk.serializeToAssetsAsync(serializerConfig, chunksByPath, filenamesByChunk, options));
|
|
719
|
-
})());
|
|
720
|
-
}
|
|
721
|
-
await Promise.all(serializeTasks);
|
|
722
|
-
return jsAssets;
|
|
723
|
-
}
|
|
724
86
|
|
|
725
87
|
//# sourceMappingURL=serializeChunks.js.map
|