@expo/cli 0.18.19 → 0.18.21
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/bin/cli +1 -1
- package/build/src/export/createMetadataJson.js.map +1 -1
- package/build/src/export/embed/exportEmbedAsync.js +110 -41
- package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
- package/build/src/export/embed/resolveOptions.js +0 -1
- package/build/src/export/embed/resolveOptions.js.map +1 -1
- package/build/src/export/exportApp.js +133 -92
- package/build/src/export/exportApp.js.map +1 -1
- package/build/src/export/exportAssets.js.map +1 -1
- package/build/src/export/exportHermes.js +15 -0
- package/build/src/export/exportHermes.js.map +1 -1
- package/build/src/export/exportStaticAsync.js +5 -49
- package/build/src/export/exportStaticAsync.js.map +1 -1
- package/build/src/export/favicon.js +5 -4
- package/build/src/export/favicon.js.map +1 -1
- package/build/src/export/saveAssets.js.map +1 -1
- package/build/src/run/startBundler.js +1 -8
- package/build/src/run/startBundler.js.map +1 -1
- package/build/src/start/server/BundlerDevServer.js +10 -3
- package/build/src/start/server/BundlerDevServer.js.map +1 -1
- package/build/src/start/server/DevServerManager.js +19 -4
- package/build/src/start/server/DevServerManager.js.map +1 -1
- package/build/src/start/server/DevelopmentSession.js +21 -11
- package/build/src/start/server/DevelopmentSession.js.map +1 -1
- package/build/src/start/server/getStaticRenderFunctions.js +9 -123
- package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
- package/build/src/start/server/metro/MetroBundlerDevServer.js +469 -177
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/createServerRouteMiddleware.js +0 -9
- package/build/src/start/server/metro/createServerRouteMiddleware.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +44 -37
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/metroErrorInterface.js +49 -2
- package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
- package/build/src/start/server/metro/metroPrivateServer.js +26 -0
- package/build/src/start/server/metro/metroPrivateServer.js.map +1 -0
- package/build/src/start/server/metro/runServer-fork.js +44 -21
- package/build/src/start/server/metro/runServer-fork.js.map +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js +9 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/server/middleware/ManifestMiddleware.js +7 -4
- package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/metroOptions.js +16 -4
- package/build/src/start/server/middleware/metroOptions.js.map +1 -1
- package/build/src/start/server/middleware/resolveAssets.js.map +1 -1
- package/build/src/utils/telemetry/getContext.js +1 -1
- package/package.json +3 -3
- package/build/src/export/fork-bundleAsync.js +0 -284
- package/build/src/export/fork-bundleAsync.js.map +0 -1
|
@@ -14,7 +14,6 @@ function _export(target, all) {
|
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
_export(exports, {
|
|
17
|
-
ForwardHtmlError: ()=>ForwardHtmlError,
|
|
18
17
|
MetroBundlerDevServer: ()=>MetroBundlerDevServer,
|
|
19
18
|
getDeepLinkHandler: ()=>getDeepLinkHandler
|
|
20
19
|
});
|
|
@@ -46,9 +45,23 @@ function _chalk() {
|
|
|
46
45
|
};
|
|
47
46
|
return data;
|
|
48
47
|
}
|
|
49
|
-
function
|
|
50
|
-
const data = /*#__PURE__*/ _interopRequireDefault(require("
|
|
51
|
-
|
|
48
|
+
function _baseJSBundle() {
|
|
49
|
+
const data = /*#__PURE__*/ _interopRequireDefault(require("metro/src/DeltaBundler/Serializers/baseJSBundle"));
|
|
50
|
+
_baseJSBundle = function() {
|
|
51
|
+
return data;
|
|
52
|
+
};
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
function _sourceMapGenerator() {
|
|
56
|
+
const data = require("metro/src/DeltaBundler/Serializers/sourceMapGenerator");
|
|
57
|
+
_sourceMapGenerator = function() {
|
|
58
|
+
return data;
|
|
59
|
+
};
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
function _bundleToString() {
|
|
63
|
+
const data = /*#__PURE__*/ _interopRequireDefault(require("metro/src/lib/bundleToString"));
|
|
64
|
+
_bundleToString = function() {
|
|
52
65
|
return data;
|
|
53
66
|
};
|
|
54
67
|
return data;
|
|
@@ -64,6 +77,7 @@ const _createServerRouteMiddleware = require("./createServerRouteMiddleware");
|
|
|
64
77
|
const _fetchRouterManifest = require("./fetchRouterManifest");
|
|
65
78
|
const _instantiateMetro = require("./instantiateMetro");
|
|
66
79
|
const _metroErrorInterface = require("./metroErrorInterface");
|
|
80
|
+
const _metroPrivateServer = require("./metroPrivateServer");
|
|
67
81
|
const _metroWatchTypeScriptFiles = require("./metroWatchTypeScriptFiles");
|
|
68
82
|
const _router = require("./router");
|
|
69
83
|
const _serializeHtml = require("./serializeHtml");
|
|
@@ -133,14 +147,8 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
133
147
|
}
|
|
134
148
|
return newObj;
|
|
135
149
|
}
|
|
136
|
-
class ForwardHtmlError extends _errors.CommandError {
|
|
137
|
-
constructor(message, html, statusCode){
|
|
138
|
-
super(message);
|
|
139
|
-
this.html = html;
|
|
140
|
-
this.statusCode = statusCode;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
150
|
const debug = require("debug")("expo:start:server:metro");
|
|
151
|
+
const getGraphId = require("metro/src/lib/getGraphId");
|
|
144
152
|
/** Default port to use for apps running in Expo Go. */ const EXPO_GO_METRO_PORT = 8081;
|
|
145
153
|
/** Default port to use for apps that run in standard React Native projects or Expo Dev Clients. */ const DEV_CLIENT_METRO_PORT = 8081;
|
|
146
154
|
class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
@@ -175,16 +183,17 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
175
183
|
// Alternatively, check whether `sourcesRoot` helps here
|
|
176
184
|
const artifactBasename = encodeURIComponent(_path().default.basename(artifactFilename) + ".map");
|
|
177
185
|
src = src.replace(/\/\/# sourceMappingURL=.*/g, `//# sourceMappingURL=${artifactBasename}`);
|
|
186
|
+
const parsedMap = JSON.parse(contents.map);
|
|
178
187
|
files.set(artifactFilename + ".map", {
|
|
179
188
|
contents: JSON.stringify({
|
|
180
|
-
version:
|
|
181
|
-
sources:
|
|
189
|
+
version: parsedMap.version,
|
|
190
|
+
sources: parsedMap.sources.map((source)=>{
|
|
182
191
|
source = typeof source === "string" && source.startsWith(this.projectRoot) ? _path().default.relative(this.projectRoot, source) : source;
|
|
183
|
-
return
|
|
192
|
+
return (0, _metroOptions.convertPathToModuleSpecifier)(source);
|
|
184
193
|
}),
|
|
185
|
-
sourcesContent: new Array(
|
|
186
|
-
names:
|
|
187
|
-
mappings:
|
|
194
|
+
sourcesContent: new Array(parsedMap.sources.length).fill(null),
|
|
195
|
+
names: parsedMap.names,
|
|
196
|
+
mappings: parsedMap.mappings
|
|
188
197
|
}),
|
|
189
198
|
targetDomain: "server"
|
|
190
199
|
});
|
|
@@ -221,14 +230,8 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
221
230
|
}
|
|
222
231
|
async getStaticRenderFunctionAsync() {
|
|
223
232
|
var ref;
|
|
224
|
-
const { mode , minify , isExporting } = this.instanceMetroOptions;
|
|
225
|
-
(0, _assert().default)(mode != null && isExporting != null, "The server must be started before calling ssrLoadModule.");
|
|
226
233
|
const url = this.getDevServerUrl();
|
|
227
|
-
const { getStaticContent , getManifest , getBuildTimeServerManifestAsync } = await this.ssrLoadModule("expo-router/node/render.js"
|
|
228
|
-
minify,
|
|
229
|
-
mode,
|
|
230
|
-
isExporting
|
|
231
|
-
});
|
|
234
|
+
const { getStaticContent , getManifest , getBuildTimeServerManifestAsync } = await this.ssrLoadModule("expo-router/node/render.js");
|
|
232
235
|
const { exp } = (0, _config().getConfig)(this.projectRoot);
|
|
233
236
|
return {
|
|
234
237
|
serverManifest: await getBuildTimeServerManifestAsync(),
|
|
@@ -244,79 +247,39 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
244
247
|
};
|
|
245
248
|
}
|
|
246
249
|
async getStaticResourcesAsync({ includeSourceMaps , mainModuleName } = {}) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
(0, _assert().default)(mode != null && isExporting != null && baseUrl != null && routerRoot != null && asyncRoutes != null, "The server must be started before calling getStaticPageAsync.");
|
|
250
|
+
const { mode , minify , isExporting , baseUrl , reactCompiler , routerRoot , asyncRoutes } = this.instanceMetroOptions;
|
|
251
|
+
(0, _assert().default)(mode != null && isExporting != null && baseUrl != null && routerRoot != null && reactCompiler != null && asyncRoutes != null, "The server must be started before calling getStaticResourcesAsync.");
|
|
250
252
|
const platform = "web";
|
|
251
|
-
const
|
|
253
|
+
const resolvedMainModuleName = mainModuleName != null ? mainModuleName : "./" + (0, _manifestMiddleware.resolveMainModuleName)(this.projectRoot, {
|
|
254
|
+
platform
|
|
255
|
+
});
|
|
256
|
+
return await this.metroImportAsArtifactsAsync(resolvedMainModuleName, {
|
|
252
257
|
splitChunks: isExporting && !_env1.env.EXPO_NO_BUNDLE_SPLITTING,
|
|
253
258
|
platform,
|
|
254
259
|
mode,
|
|
255
260
|
minify,
|
|
256
261
|
environment: "client",
|
|
257
|
-
serializerOutput: "static",
|
|
258
262
|
serializerIncludeMaps: includeSourceMaps,
|
|
259
|
-
mainModuleName:
|
|
260
|
-
platform
|
|
261
|
-
}),
|
|
263
|
+
mainModuleName: resolvedMainModuleName,
|
|
262
264
|
lazy: (0, _metroOptions.shouldEnableAsyncImports)(this.projectRoot),
|
|
263
265
|
asyncRoutes,
|
|
264
266
|
baseUrl,
|
|
265
267
|
isExporting,
|
|
266
268
|
routerRoot,
|
|
269
|
+
reactCompiler,
|
|
267
270
|
bytecode: false
|
|
268
271
|
});
|
|
269
|
-
const bundleUrl = new URL(devBundleUrlPathname, this.getDevServerUrl());
|
|
270
|
-
// Fetch the generated HTML from our custom Metro serializer
|
|
271
|
-
const results = await (0, _nodeFetch().default)(bundleUrl.toString());
|
|
272
|
-
const txt = await results.text();
|
|
273
|
-
let data;
|
|
274
|
-
try {
|
|
275
|
-
data = JSON.parse(txt);
|
|
276
|
-
} catch (error) {
|
|
277
|
-
debug(txt);
|
|
278
|
-
// Metro can throw this error when the initial module id cannot be resolved.
|
|
279
|
-
if (!results.ok && txt.startsWith("<!DOCTYPE html>")) {
|
|
280
|
-
throw new ForwardHtmlError(`Metro failed to bundle the project. Check the console for more information.`, txt, results.status);
|
|
281
|
-
}
|
|
282
|
-
_log.Log.error("Failed to generate resources with Metro, the Metro config may not be using the correct serializer. Ensure the metro.config.js is extending the expo/metro-config and is not overriding the serializer.");
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
// NOTE: This could potentially need more validation in the future.
|
|
286
|
-
if ("artifacts" in data && Array.isArray(data.artifacts)) {
|
|
287
|
-
return data;
|
|
288
|
-
}
|
|
289
|
-
if (data != null && (data.errors || ((ref = data.type) == null ? void 0 : ref.match(/.*Error$/)))) {
|
|
290
|
-
// {
|
|
291
|
-
// type: 'InternalError',
|
|
292
|
-
// errors: [],
|
|
293
|
-
// message: 'Metro has encountered an error: While trying to resolve module `stylis` from file `/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/@emotion/cache/dist/emotion-cache.browser.esm.js`, the package `/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs`. Indeed, none of these files exist:\n' +
|
|
294
|
-
// '\n' +
|
|
295
|
-
// ' * /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs(.web.ts|.ts|.web.tsx|.tsx|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css)\n' +
|
|
296
|
-
// ' * /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/stylis/dist/stylis.mjs/index(.web.ts|.ts|.web.tsx|.tsx|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css): /Users/evanbacon/Documents/GitHub/lab/emotion-error-test/node_modules/metro/src/node-haste/DependencyGraph.js (289:17)\n' +
|
|
297
|
-
// '\n' +
|
|
298
|
-
// '\x1B[0m \x1B[90m 287 |\x1B[39m }\x1B[0m\n' +
|
|
299
|
-
// '\x1B[0m \x1B[90m 288 |\x1B[39m \x1B[36mif\x1B[39m (error \x1B[36minstanceof\x1B[39m \x1B[33mInvalidPackageError\x1B[39m) {\x1B[0m\n' +
|
|
300
|
-
// '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 289 |\x1B[39m \x1B[36mthrow\x1B[39m \x1B[36mnew\x1B[39m \x1B[33mPackageResolutionError\x1B[39m({\x1B[0m\n' +
|
|
301
|
-
// '\x1B[0m \x1B[90m |\x1B[39m \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
|
|
302
|
-
// '\x1B[0m \x1B[90m 290 |\x1B[39m packageError\x1B[33m:\x1B[39m error\x1B[33m,\x1B[39m\x1B[0m\n' +
|
|
303
|
-
// '\x1B[0m \x1B[90m 291 |\x1B[39m originModulePath\x1B[33m:\x1B[39m \x1B[36mfrom\x1B[39m\x1B[33m,\x1B[39m\x1B[0m\n' +
|
|
304
|
-
// '\x1B[0m \x1B[90m 292 |\x1B[39m targetModuleName\x1B[33m:\x1B[39m to\x1B[33m,\x1B[39m\x1B[0m'
|
|
305
|
-
// }
|
|
306
|
-
// The Metro logger already showed this error.
|
|
307
|
-
throw new Error(data.message);
|
|
308
|
-
}
|
|
309
|
-
throw new Error("Invalid resources returned from the Metro serializer. Expected array, found: " + data);
|
|
310
272
|
}
|
|
311
273
|
async getStaticPageAsync(pathname) {
|
|
312
|
-
const { mode , isExporting , baseUrl , routerRoot , asyncRoutes } = this.instanceMetroOptions;
|
|
313
|
-
(0, _assert().default)(mode != null && isExporting != null && baseUrl != null && routerRoot != null && asyncRoutes != null, "The server must be started before calling getStaticPageAsync.");
|
|
274
|
+
const { mode , isExporting , baseUrl , reactCompiler , routerRoot , asyncRoutes } = this.instanceMetroOptions;
|
|
275
|
+
(0, _assert().default)(mode != null && isExporting != null && baseUrl != null && reactCompiler != null && routerRoot != null && asyncRoutes != null, "The server must be started before calling getStaticPageAsync.");
|
|
314
276
|
const platform = "web";
|
|
315
277
|
const devBundleUrlPathname = (0, _metroOptions.createBundleUrlPath)({
|
|
316
278
|
splitChunks: isExporting && !_env1.env.EXPO_NO_BUNDLE_SPLITTING,
|
|
317
279
|
platform,
|
|
318
280
|
mode,
|
|
319
281
|
environment: "client",
|
|
282
|
+
reactCompiler,
|
|
320
283
|
mainModuleName: (0, _manifestMiddleware.resolveMainModuleName)(this.projectRoot, {
|
|
321
284
|
platform
|
|
322
285
|
}),
|
|
@@ -356,36 +319,165 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
356
319
|
// Set when the server is started.
|
|
357
320
|
instanceMetroOptions = {};
|
|
358
321
|
async ssrLoadModule(filePath, specificOptions = {}) {
|
|
359
|
-
const
|
|
360
|
-
(0,
|
|
361
|
-
|
|
322
|
+
const res = await this.ssrLoadModuleContents(filePath, specificOptions);
|
|
323
|
+
return (0, _getStaticRenderFunctions.evalMetroAndWrapFunctions)(this.projectRoot, res.src, res.filename);
|
|
324
|
+
}
|
|
325
|
+
async metroImportAsArtifactsAsync(filePath, specificOptions = {}) {
|
|
326
|
+
const results = await this.ssrLoadModuleContents(filePath, {
|
|
327
|
+
serializerOutput: "static",
|
|
328
|
+
...specificOptions
|
|
329
|
+
});
|
|
330
|
+
// NOTE: This could potentially need more validation in the future.
|
|
331
|
+
if (results.artifacts && results.assets) {
|
|
332
|
+
return {
|
|
333
|
+
artifacts: results.artifacts,
|
|
334
|
+
assets: results.assets,
|
|
335
|
+
src: results.src,
|
|
336
|
+
filename: results.filename,
|
|
337
|
+
map: results.map
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
throw new _errors.CommandError("Invalid bundler results: " + results);
|
|
341
|
+
}
|
|
342
|
+
async metroLoadModuleContents(filePath, specificOptions, extraOptions = {}) {
|
|
343
|
+
const { baseUrl } = this.instanceMetroOptions;
|
|
344
|
+
(0, _assert().default)(baseUrl != null, "The server must be started before calling metroLoadModuleContents.");
|
|
345
|
+
const opts = {
|
|
346
|
+
// TODO: Possibly issues with using an absolute path here...
|
|
347
|
+
// mainModuleName: filePath,
|
|
348
|
+
lazy: false,
|
|
349
|
+
asyncRoutes: false,
|
|
350
|
+
inlineSourceMap: false,
|
|
351
|
+
engine: "hermes",
|
|
352
|
+
minify: false,
|
|
353
|
+
// bytecode: false,
|
|
362
354
|
// Bundle in Node.js mode for SSR.
|
|
363
355
|
environment: "node",
|
|
364
|
-
platform:
|
|
365
|
-
mode:
|
|
366
|
-
|
|
356
|
+
// platform: 'web',
|
|
357
|
+
// mode: 'development',
|
|
358
|
+
//
|
|
367
359
|
...this.instanceMetroOptions,
|
|
368
360
|
baseUrl,
|
|
369
|
-
routerRoot,
|
|
370
|
-
isExporting,
|
|
361
|
+
// routerRoot,
|
|
362
|
+
// isExporting,
|
|
371
363
|
...specificOptions
|
|
372
|
-
}
|
|
364
|
+
};
|
|
365
|
+
const expoBundleOptions = (0, _metroOptions.getMetroDirectBundleOptions)(opts);
|
|
366
|
+
var _customResolverOptions, _dev;
|
|
367
|
+
const resolverOptions = {
|
|
368
|
+
customResolverOptions: (_customResolverOptions = expoBundleOptions.customResolverOptions) != null ? _customResolverOptions : {},
|
|
369
|
+
dev: (_dev = expoBundleOptions.dev) != null ? _dev : true
|
|
370
|
+
};
|
|
371
|
+
var _dev1, _minify, _unstable_transformProfile, ref, _customTransformOptions, _platform;
|
|
372
|
+
const transformOptions = {
|
|
373
|
+
dev: (_dev1 = expoBundleOptions.dev) != null ? _dev1 : true,
|
|
374
|
+
hot: true,
|
|
375
|
+
minify: (_minify = expoBundleOptions.minify) != null ? _minify : false,
|
|
376
|
+
type: "module",
|
|
377
|
+
unstable_transformProfile: (ref = (_unstable_transformProfile = extraOptions.unstable_transformProfile) != null ? _unstable_transformProfile : expoBundleOptions.unstable_transformProfile) != null ? ref : "default",
|
|
378
|
+
customTransformOptions: (_customTransformOptions = expoBundleOptions.customTransformOptions) != null ? _customTransformOptions : Object.create(null),
|
|
379
|
+
platform: (_platform = expoBundleOptions.platform) != null ? _platform : "web",
|
|
380
|
+
runtimeBytecodeVersion: expoBundleOptions.runtimeBytecodeVersion
|
|
381
|
+
};
|
|
382
|
+
const resolvedEntryFilePath = await this.resolveRelativePathAsync(filePath, {
|
|
383
|
+
resolverOptions,
|
|
384
|
+
transformOptions
|
|
385
|
+
});
|
|
386
|
+
// Use fully qualified URL with all options to represent the file path that's used for source maps and HMR. This prevents collisions.
|
|
387
|
+
const filename = (0, _metroOptions.createBundleUrlPath)({
|
|
388
|
+
...opts,
|
|
389
|
+
mainModuleName: resolvedEntryFilePath
|
|
390
|
+
});
|
|
391
|
+
var _lazy, _shallow, _inlineSourceMap, _modulesOnly, _runModule, _sourceMapUrl;
|
|
392
|
+
// https://github.com/facebook/metro/blob/2405f2f6c37a1b641cc379b9c733b1eff0c1c2a1/packages/metro/src/lib/parseOptionsFromUrl.js#L55-L87
|
|
393
|
+
const results = await this._bundleDirectAsync(resolvedEntryFilePath, {
|
|
394
|
+
graphOptions: {
|
|
395
|
+
lazy: (_lazy = expoBundleOptions.lazy) != null ? _lazy : false,
|
|
396
|
+
shallow: (_shallow = expoBundleOptions.shallow) != null ? _shallow : false
|
|
397
|
+
},
|
|
398
|
+
resolverOptions,
|
|
399
|
+
serializerOptions: {
|
|
400
|
+
...expoBundleOptions.serializerOptions,
|
|
401
|
+
inlineSourceMap: (_inlineSourceMap = expoBundleOptions.inlineSourceMap) != null ? _inlineSourceMap : false,
|
|
402
|
+
modulesOnly: (_modulesOnly = expoBundleOptions.modulesOnly) != null ? _modulesOnly : false,
|
|
403
|
+
runModule: (_runModule = expoBundleOptions.runModule) != null ? _runModule : true,
|
|
404
|
+
// @ts-expect-error
|
|
405
|
+
sourceUrl: expoBundleOptions.sourceUrl,
|
|
406
|
+
// @ts-expect-error
|
|
407
|
+
sourceMapUrl: (_sourceMapUrl = extraOptions.sourceMapUrl) != null ? _sourceMapUrl : expoBundleOptions.sourceMapUrl
|
|
408
|
+
},
|
|
409
|
+
transformOptions
|
|
410
|
+
});
|
|
411
|
+
return {
|
|
412
|
+
...results,
|
|
413
|
+
filename
|
|
414
|
+
};
|
|
373
415
|
}
|
|
374
416
|
async ssrLoadModuleContents(filePath, specificOptions = {}) {
|
|
375
417
|
const { baseUrl , routerRoot , isExporting } = this.instanceMetroOptions;
|
|
376
|
-
(0, _assert().default)(baseUrl != null && routerRoot != null && isExporting != null, "The server must be started before calling
|
|
377
|
-
|
|
418
|
+
(0, _assert().default)(baseUrl != null && routerRoot != null && isExporting != null, "The server must be started before calling ssrLoadModuleContents.");
|
|
419
|
+
const opts = {
|
|
420
|
+
// TODO: Possibly issues with using an absolute path here...
|
|
421
|
+
mainModuleName: (0, _metroOptions.convertPathToModuleSpecifier)(filePath),
|
|
422
|
+
lazy: false,
|
|
423
|
+
asyncRoutes: false,
|
|
424
|
+
inlineSourceMap: false,
|
|
425
|
+
engine: "hermes",
|
|
426
|
+
minify: false,
|
|
427
|
+
bytecode: false,
|
|
378
428
|
// Bundle in Node.js mode for SSR.
|
|
379
429
|
environment: "node",
|
|
380
430
|
platform: "web",
|
|
381
431
|
mode: "development",
|
|
382
|
-
|
|
432
|
+
//
|
|
383
433
|
...this.instanceMetroOptions,
|
|
434
|
+
// Mostly disable compiler in SSR bundles.
|
|
435
|
+
reactCompiler: false,
|
|
384
436
|
baseUrl,
|
|
385
437
|
routerRoot,
|
|
386
438
|
isExporting,
|
|
387
439
|
...specificOptions
|
|
388
|
-
}
|
|
440
|
+
};
|
|
441
|
+
// https://github.com/facebook/metro/blob/2405f2f6c37a1b641cc379b9c733b1eff0c1c2a1/packages/metro/src/lib/parseOptionsFromUrl.js#L55-L87
|
|
442
|
+
const { filename , bundle , map , ...rest } = await this.metroLoadModuleContents(filePath, opts);
|
|
443
|
+
const scriptContents = wrapBundle(bundle);
|
|
444
|
+
if (map) {
|
|
445
|
+
debug("Registering SSR source map for:", filename);
|
|
446
|
+
_getStaticRenderFunctions.cachedSourceMaps.set(filename, {
|
|
447
|
+
url: this.projectRoot,
|
|
448
|
+
map
|
|
449
|
+
});
|
|
450
|
+
} else {
|
|
451
|
+
debug("No SSR source map found for:", filename);
|
|
452
|
+
}
|
|
453
|
+
return {
|
|
454
|
+
...rest,
|
|
455
|
+
src: scriptContents,
|
|
456
|
+
filename,
|
|
457
|
+
map
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
async legacySinglePageExportBundleAsync(options, extraOptions = {}) {
|
|
461
|
+
const { baseUrl , routerRoot , isExporting } = this.instanceMetroOptions;
|
|
462
|
+
(0, _assert().default)(baseUrl != null && routerRoot != null && isExporting != null, "The server must be started before calling legacySinglePageExportBundleAsync.");
|
|
463
|
+
const opts = {
|
|
464
|
+
...this.instanceMetroOptions,
|
|
465
|
+
baseUrl,
|
|
466
|
+
routerRoot,
|
|
467
|
+
isExporting,
|
|
468
|
+
...options,
|
|
469
|
+
environment: "client",
|
|
470
|
+
serializerOutput: "static"
|
|
471
|
+
};
|
|
472
|
+
// https://github.com/facebook/metro/blob/2405f2f6c37a1b641cc379b9c733b1eff0c1c2a1/packages/metro/src/lib/parseOptionsFromUrl.js#L55-L87
|
|
473
|
+
if (!opts.mainModuleName.startsWith("/")) {
|
|
474
|
+
opts.mainModuleName = "./" + opts.mainModuleName;
|
|
475
|
+
}
|
|
476
|
+
const output = await this.metroLoadModuleContents(opts.mainModuleName, opts, extraOptions);
|
|
477
|
+
return {
|
|
478
|
+
artifacts: output.artifacts,
|
|
479
|
+
assets: output.assets
|
|
480
|
+
};
|
|
389
481
|
}
|
|
390
482
|
async watchEnvironmentVariables() {
|
|
391
483
|
if (!this.instance) {
|
|
@@ -409,26 +501,24 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
409
501
|
});
|
|
410
502
|
});
|
|
411
503
|
}
|
|
412
|
-
getExpoLineOptions() {
|
|
413
|
-
return this.instanceMetroOptions;
|
|
414
|
-
}
|
|
415
504
|
async startImplementationAsync(options) {
|
|
416
|
-
var ref;
|
|
505
|
+
var ref, ref1;
|
|
417
506
|
options.port = await this.resolvePortAsync(options);
|
|
418
507
|
this.urlCreator = this.getUrlCreator(options);
|
|
419
508
|
const config = (0, _config().getConfig)(this.projectRoot, {
|
|
420
509
|
skipSDKVersionRequirement: true
|
|
421
510
|
});
|
|
422
511
|
const { exp } = config;
|
|
423
|
-
var
|
|
512
|
+
var ref2;
|
|
424
513
|
const useServerRendering = [
|
|
425
514
|
"static",
|
|
426
515
|
"server"
|
|
427
|
-
].includes((
|
|
516
|
+
].includes((ref2 = (ref = exp.web) == null ? void 0 : ref.output) != null ? ref2 : "");
|
|
428
517
|
const baseUrl = (0, _metroOptions.getBaseUrlFromExpoConfig)(exp);
|
|
429
518
|
var _mode;
|
|
430
519
|
const asyncRoutes = (0, _metroOptions.getAsyncRoutesFromExpoConfig)(exp, (_mode = options.mode) != null ? _mode : "development", "web");
|
|
431
520
|
const routerRoot = (0, _router.getRouterDirectoryModuleIdWithManifest)(this.projectRoot, exp);
|
|
521
|
+
const reactCompiler = !!((ref1 = exp.experiments) == null ? void 0 : ref1.reactCompiler);
|
|
432
522
|
const appDir = _path().default.join(this.projectRoot, routerRoot);
|
|
433
523
|
var _mode1;
|
|
434
524
|
const mode = (_mode1 = options.mode) != null ? _mode1 : "development";
|
|
@@ -437,6 +527,7 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
437
527
|
baseUrl,
|
|
438
528
|
mode,
|
|
439
529
|
routerRoot,
|
|
530
|
+
reactCompiler,
|
|
440
531
|
minify: options.minify,
|
|
441
532
|
asyncRoutes
|
|
442
533
|
};
|
|
@@ -448,86 +539,89 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
448
539
|
// Required for symbolication:
|
|
449
540
|
process.env.EXPO_DEV_SERVER_ORIGIN = `http://localhost:${options.port}`;
|
|
450
541
|
const { metro , server , middleware , messageSocket } = await (0, _instantiateMetro.instantiateMetroAsync)(this, parsedOptions, {
|
|
451
|
-
isExporting: !!options.isExporting
|
|
452
|
-
|
|
453
|
-
const manifestMiddleware = await this.getManifestMiddlewareAsync(options);
|
|
454
|
-
// Important that we noop source maps for context modules as soon as possible.
|
|
455
|
-
(0, _mutations.prependMiddleware)(middleware, new _contextModuleSourceMapsMiddleware.ContextModuleSourceMapsMiddleware().getHandler());
|
|
456
|
-
// We need the manifest handler to be the first middleware to run so our
|
|
457
|
-
// routes take precedence over static files. For example, the manifest is
|
|
458
|
-
// served from '/' and if the user has an index.html file in their project
|
|
459
|
-
// then the manifest handler will never run, the static middleware will run
|
|
460
|
-
// and serve index.html instead of the manifest.
|
|
461
|
-
// https://github.com/expo/expo/issues/13114
|
|
462
|
-
(0, _mutations.prependMiddleware)(middleware, manifestMiddleware.getHandler());
|
|
463
|
-
var _scheme;
|
|
464
|
-
middleware.use(new _interstitialPageMiddleware.InterstitialPageMiddleware(this.projectRoot, {
|
|
465
|
-
// TODO: Prevent this from becoming stale.
|
|
466
|
-
scheme: (_scheme = options.location.scheme) != null ? _scheme : null
|
|
467
|
-
}).getHandler());
|
|
468
|
-
middleware.use(new _reactDevToolsPageMiddleware.ReactDevToolsPageMiddleware(this.projectRoot).getHandler());
|
|
469
|
-
middleware.use(new _devToolsPluginMiddleware.DevToolsPluginMiddleware(this.projectRoot, this.devToolsPluginManager).getHandler());
|
|
470
|
-
const deepLinkMiddleware = new _runtimeRedirectMiddleware.RuntimeRedirectMiddleware(this.projectRoot, {
|
|
471
|
-
onDeepLink: getDeepLinkHandler(this.projectRoot),
|
|
472
|
-
getLocation: ({ runtime })=>{
|
|
473
|
-
if (runtime === "custom") {
|
|
474
|
-
var ref;
|
|
475
|
-
return (ref = this.urlCreator) == null ? void 0 : ref.constructDevClientUrl();
|
|
476
|
-
} else {
|
|
477
|
-
var ref1;
|
|
478
|
-
return (ref1 = this.urlCreator) == null ? void 0 : ref1.constructUrl({
|
|
479
|
-
scheme: "exp"
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
}
|
|
542
|
+
isExporting: !!options.isExporting,
|
|
543
|
+
exp
|
|
483
544
|
});
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
//
|
|
489
|
-
|
|
490
|
-
//
|
|
491
|
-
middleware
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
545
|
+
if (!options.isExporting) {
|
|
546
|
+
const manifestMiddleware = await this.getManifestMiddlewareAsync(options);
|
|
547
|
+
// Important that we noop source maps for context modules as soon as possible.
|
|
548
|
+
(0, _mutations.prependMiddleware)(middleware, new _contextModuleSourceMapsMiddleware.ContextModuleSourceMapsMiddleware().getHandler());
|
|
549
|
+
// We need the manifest handler to be the first middleware to run so our
|
|
550
|
+
// routes take precedence over static files. For example, the manifest is
|
|
551
|
+
// served from '/' and if the user has an index.html file in their project
|
|
552
|
+
// then the manifest handler will never run, the static middleware will run
|
|
553
|
+
// and serve index.html instead of the manifest.
|
|
554
|
+
// https://github.com/expo/expo/issues/13114
|
|
555
|
+
(0, _mutations.prependMiddleware)(middleware, manifestMiddleware.getHandler());
|
|
556
|
+
var _scheme;
|
|
557
|
+
middleware.use(new _interstitialPageMiddleware.InterstitialPageMiddleware(this.projectRoot, {
|
|
558
|
+
// TODO: Prevent this from becoming stale.
|
|
559
|
+
scheme: (_scheme = options.location.scheme) != null ? _scheme : null
|
|
560
|
+
}).getHandler());
|
|
561
|
+
middleware.use(new _reactDevToolsPageMiddleware.ReactDevToolsPageMiddleware(this.projectRoot).getHandler());
|
|
562
|
+
middleware.use(new _devToolsPluginMiddleware.DevToolsPluginMiddleware(this.projectRoot, this.devToolsPluginManager).getHandler());
|
|
563
|
+
const deepLinkMiddleware = new _runtimeRedirectMiddleware.RuntimeRedirectMiddleware(this.projectRoot, {
|
|
564
|
+
onDeepLink: getDeepLinkHandler(this.projectRoot),
|
|
565
|
+
getLocation: ({ runtime })=>{
|
|
566
|
+
if (runtime === "custom") {
|
|
567
|
+
var ref;
|
|
568
|
+
return (ref = this.urlCreator) == null ? void 0 : ref.constructDevClientUrl();
|
|
569
|
+
} else {
|
|
570
|
+
var ref1;
|
|
571
|
+
return (ref1 = this.urlCreator) == null ? void 0 : ref1.constructUrl({
|
|
572
|
+
scheme: "exp"
|
|
573
|
+
});
|
|
502
574
|
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
middleware.use(deepLinkMiddleware.getHandler());
|
|
578
|
+
middleware.use(new _createFileMiddleware.CreateFileMiddleware(this.projectRoot).getHandler());
|
|
579
|
+
// Append support for redirecting unhandled requests to the index.html page on web.
|
|
580
|
+
if (this.isTargetingWeb()) {
|
|
581
|
+
// This MUST be after the manifest middleware so it doesn't have a chance to serve the template `public/index.html`.
|
|
582
|
+
middleware.use(new _serveStaticMiddleware.ServeStaticMiddleware(this.projectRoot).getHandler());
|
|
583
|
+
// This should come after the static middleware so it doesn't serve the favicon from `public/favicon.ico`.
|
|
584
|
+
middleware.use(new _faviconMiddleware.FaviconMiddleware(this.projectRoot).getHandler());
|
|
585
|
+
if (useServerRendering) {
|
|
586
|
+
var ref3;
|
|
587
|
+
middleware.use((0, _createServerRouteMiddleware.createRouteHandlerMiddleware)(this.projectRoot, {
|
|
588
|
+
appDir,
|
|
589
|
+
routerRoot,
|
|
590
|
+
config,
|
|
591
|
+
...(ref3 = config.exp.extra) == null ? void 0 : ref3.router,
|
|
592
|
+
bundleApiRoute: (functionFilePath)=>this.ssrImportApiRoute(functionFilePath),
|
|
593
|
+
getStaticPageAsync: (pathname)=>{
|
|
594
|
+
return this.getStaticPageAsync(pathname);
|
|
595
|
+
}
|
|
596
|
+
}));
|
|
597
|
+
(0, _waitForMetroToObserveTypeScriptFile.observeAnyFileChanges)({
|
|
598
|
+
metro,
|
|
599
|
+
server
|
|
600
|
+
}, (events)=>{
|
|
601
|
+
var ref;
|
|
602
|
+
if (((ref = exp.web) == null ? void 0 : ref.output) === "server") {
|
|
603
|
+
// NOTE(EvanBacon): We aren't sure what files the API routes are using so we'll just invalidate
|
|
604
|
+
// aggressively to ensure we always have the latest. The only caching we really get here is for
|
|
605
|
+
// cases where the user is making subsequent requests to the same API route without changing anything.
|
|
606
|
+
// This is useful for testing but pretty suboptimal. Luckily our caching is pretty aggressive so it makes
|
|
607
|
+
// up for a lot of the overhead.
|
|
608
|
+
this.invalidateApiRouteCache();
|
|
609
|
+
} else if (!(0, _router.hasWarnedAboutApiRoutes)()) {
|
|
610
|
+
for (const event of events){
|
|
611
|
+
var // If the user did not delete a file that matches the Expo Router API Route convention, then we should warn that
|
|
612
|
+
// API Routes are not enabled in the project.
|
|
613
|
+
ref1;
|
|
614
|
+
if (((ref1 = event.metadata) == null ? void 0 : ref1.type) !== "d" && // Ensure the file is in the project's routes directory to prevent false positives in monorepos.
|
|
615
|
+
event.filePath.startsWith(appDir) && (0, _router.isApiRouteConvention)(event.filePath)) {
|
|
616
|
+
(0, _router.warnInvalidWebOutput)();
|
|
617
|
+
}
|
|
524
618
|
}
|
|
525
619
|
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
620
|
+
});
|
|
621
|
+
} else {
|
|
622
|
+
// This MUST run last since it's the fallback.
|
|
623
|
+
middleware.use(new _historyFallbackMiddleware.HistoryFallbackMiddleware(manifestMiddleware.getHandler().internal).getHandler());
|
|
624
|
+
}
|
|
531
625
|
}
|
|
532
626
|
}
|
|
533
627
|
// Extend the close method to ensure that we clean up the local info.
|
|
@@ -539,6 +633,7 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
539
633
|
callback == null ? void 0 : callback(err);
|
|
540
634
|
});
|
|
541
635
|
};
|
|
636
|
+
(0, _metroPrivateServer.assertMetroPrivateServer)(metro);
|
|
542
637
|
this.metro = metro;
|
|
543
638
|
return {
|
|
544
639
|
server,
|
|
@@ -624,13 +719,17 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
624
719
|
debug("Bundle API route:", this.instanceMetroOptions.routerRoot, filePath);
|
|
625
720
|
return await this.ssrLoadModuleContents(filePath);
|
|
626
721
|
} catch (error) {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
722
|
+
var ref;
|
|
723
|
+
const appDir = ((ref = this.instanceMetroOptions) == null ? void 0 : ref.routerRoot) ? _path().default.join(this.projectRoot, this.instanceMetroOptions.routerRoot) : undefined;
|
|
724
|
+
const relativePath = appDir ? _path().default.relative(appDir, filePath) : filePath;
|
|
725
|
+
// Expected errors: invalid syntax, missing resolutions.
|
|
726
|
+
// Wrap with command error for better error messages.
|
|
727
|
+
const err = new _errors.CommandError("API_ROUTE", (0, _chalk().default)`Failed to bundle API Route: {bold ${relativePath}}\n\n` + error.message);
|
|
728
|
+
for(const key in error){
|
|
729
|
+
// @ts-expect-error
|
|
730
|
+
err[key] = error[key];
|
|
632
731
|
}
|
|
633
|
-
throw
|
|
732
|
+
throw err;
|
|
634
733
|
} finally{
|
|
635
734
|
// pendingRouteOperations.delete(filepath);
|
|
636
735
|
}
|
|
@@ -654,7 +753,7 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
654
753
|
const htmlServerError = await (0, _metroErrorInterface.getErrorOverlayHtmlAsync)({
|
|
655
754
|
error,
|
|
656
755
|
projectRoot: this.projectRoot,
|
|
657
|
-
routerRoot: this.
|
|
756
|
+
routerRoot: this.instanceMetroOptions.routerRoot
|
|
658
757
|
});
|
|
659
758
|
return new Response(htmlServerError, {
|
|
660
759
|
status: 500,
|
|
@@ -674,6 +773,188 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
|
|
|
674
773
|
invalidateApiRouteCache() {
|
|
675
774
|
this.pendingRouteOperations.clear();
|
|
676
775
|
}
|
|
776
|
+
// Direct Metro access
|
|
777
|
+
// Emulates the Metro dev server .bundle endpoint without having to go through a server.
|
|
778
|
+
async _bundleDirectAsync(resolvedEntryFilePath, { transformOptions , resolverOptions , graphOptions , serializerOptions }) {
|
|
779
|
+
var ref;
|
|
780
|
+
(0, _assert().default)(this.metro, "Metro server must be running to bundle directly.");
|
|
781
|
+
const config = this.metro._config;
|
|
782
|
+
const buildNumber = this.metro.getNewBuildNumber();
|
|
783
|
+
const bundlePerfLogger = config.unstable_perfLoggerFactory == null ? void 0 : config.unstable_perfLoggerFactory("BUNDLING_REQUEST", {
|
|
784
|
+
key: buildNumber
|
|
785
|
+
});
|
|
786
|
+
const onProgress = (transformedFileCount, totalFileCount)=>{
|
|
787
|
+
var ref, ref1;
|
|
788
|
+
(ref = this.metro) == null ? void 0 : (ref1 = ref._reporter) == null ? void 0 : ref1.update == null ? void 0 : ref1.update({
|
|
789
|
+
buildID: getBuildID(buildNumber),
|
|
790
|
+
type: "bundle_transform_progressed",
|
|
791
|
+
transformedFileCount,
|
|
792
|
+
totalFileCount
|
|
793
|
+
});
|
|
794
|
+
};
|
|
795
|
+
const revPromise = this.getMetroRevision(resolvedEntryFilePath, {
|
|
796
|
+
graphOptions,
|
|
797
|
+
transformOptions,
|
|
798
|
+
resolverOptions
|
|
799
|
+
});
|
|
800
|
+
bundlePerfLogger == null ? void 0 : bundlePerfLogger.point("resolvingAndTransformingDependencies_start");
|
|
801
|
+
bundlePerfLogger == null ? void 0 : bundlePerfLogger.annotate({
|
|
802
|
+
bool: {
|
|
803
|
+
initial_build: revPromise == null
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
(ref = this.metro) == null ? void 0 : ref._reporter.update({
|
|
807
|
+
buildID: getBuildID(buildNumber),
|
|
808
|
+
bundleDetails: {
|
|
809
|
+
bundleType: transformOptions.type,
|
|
810
|
+
dev: transformOptions.dev,
|
|
811
|
+
entryFile: resolvedEntryFilePath,
|
|
812
|
+
minify: transformOptions.minify,
|
|
813
|
+
platform: transformOptions.platform,
|
|
814
|
+
// @ts-expect-error: typed incorrectly upstream
|
|
815
|
+
customResolverOptions: resolverOptions.customResolverOptions,
|
|
816
|
+
customTransformOptions: transformOptions.customTransformOptions
|
|
817
|
+
},
|
|
818
|
+
isPrefetch: false,
|
|
819
|
+
type: "bundle_build_started"
|
|
820
|
+
});
|
|
821
|
+
try {
|
|
822
|
+
const { delta , revision } = await (revPromise != null ? this.metro.getBundler().updateGraph(await revPromise, false) : this.metro.getBundler().initializeGraph(// NOTE: Using absolute path instead of relative input path is a breaking change.
|
|
823
|
+
// entryFile,
|
|
824
|
+
resolvedEntryFilePath, transformOptions, resolverOptions, {
|
|
825
|
+
onProgress,
|
|
826
|
+
shallow: graphOptions.shallow,
|
|
827
|
+
// @ts-expect-error: typed incorrectly
|
|
828
|
+
lazy: graphOptions.lazy
|
|
829
|
+
}));
|
|
830
|
+
bundlePerfLogger == null ? void 0 : bundlePerfLogger.annotate({
|
|
831
|
+
int: {
|
|
832
|
+
graph_node_count: revision.graph.dependencies.size
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
bundlePerfLogger == null ? void 0 : bundlePerfLogger.point("resolvingAndTransformingDependencies_end");
|
|
836
|
+
bundlePerfLogger == null ? void 0 : bundlePerfLogger.point("serializingBundle_start");
|
|
837
|
+
const shouldAddToIgnoreList = this.metro._shouldAddModuleToIgnoreList.bind(this.metro);
|
|
838
|
+
const serializer = this.getMetroSerializer();
|
|
839
|
+
var _unstable_serverRoot;
|
|
840
|
+
const bundle = await serializer(// NOTE: Using absolute path instead of relative input path is a breaking change.
|
|
841
|
+
// entryFile,
|
|
842
|
+
resolvedEntryFilePath, revision.prepend, revision.graph, {
|
|
843
|
+
asyncRequireModulePath: await this.metro._resolveRelativePath(config.transformer.asyncRequireModulePath, {
|
|
844
|
+
relativeTo: "project",
|
|
845
|
+
resolverOptions,
|
|
846
|
+
transformOptions
|
|
847
|
+
}),
|
|
848
|
+
// ...serializerOptions,
|
|
849
|
+
processModuleFilter: config.serializer.processModuleFilter,
|
|
850
|
+
createModuleId: this.metro._createModuleId,
|
|
851
|
+
getRunModuleStatement: config.serializer.getRunModuleStatement,
|
|
852
|
+
includeAsyncPaths: graphOptions.lazy,
|
|
853
|
+
dev: transformOptions.dev,
|
|
854
|
+
projectRoot: config.projectRoot,
|
|
855
|
+
modulesOnly: serializerOptions.modulesOnly,
|
|
856
|
+
runBeforeMainModule: config.serializer.getModulesRunBeforeMainModule(resolvedEntryFilePath),
|
|
857
|
+
runModule: serializerOptions.runModule,
|
|
858
|
+
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
859
|
+
sourceUrl: serializerOptions.sourceUrl,
|
|
860
|
+
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
861
|
+
serverRoot: (_unstable_serverRoot = config.server.unstable_serverRoot) != null ? _unstable_serverRoot : config.projectRoot,
|
|
862
|
+
shouldAddToIgnoreList,
|
|
863
|
+
// @ts-expect-error: passed to our serializer to enable non-serial return values.
|
|
864
|
+
serializerOptions
|
|
865
|
+
});
|
|
866
|
+
this.metro._reporter.update({
|
|
867
|
+
buildID: getBuildID(buildNumber),
|
|
868
|
+
type: "bundle_build_done"
|
|
869
|
+
});
|
|
870
|
+
bundlePerfLogger == null ? void 0 : bundlePerfLogger.point("serializingBundle_end");
|
|
871
|
+
let bundleCode = null;
|
|
872
|
+
let bundleMap = null;
|
|
873
|
+
// @ts-expect-error: If the output is multi-bundle...
|
|
874
|
+
if (serializerOptions.output === "static") {
|
|
875
|
+
try {
|
|
876
|
+
var ref1, ref2;
|
|
877
|
+
const parsed = typeof bundle === "string" ? JSON.parse(bundle) : bundle;
|
|
878
|
+
(0, _assert().default)("artifacts" in parsed && Array.isArray(parsed.artifacts), "Expected serializer to return an object with key artifacts to contain an array of serial assets.");
|
|
879
|
+
const artifacts = parsed.artifacts;
|
|
880
|
+
const assets = parsed.assets;
|
|
881
|
+
const bundleCode1 = artifacts.filter((asset)=>asset.type === "js")[0];
|
|
882
|
+
var ref3;
|
|
883
|
+
const bundleMap1 = (ref3 = (ref1 = artifacts.filter((asset)=>asset.type === "map")) == null ? void 0 : (ref2 = ref1[0]) == null ? void 0 : ref2.source) != null ? ref3 : "";
|
|
884
|
+
return {
|
|
885
|
+
numModifiedFiles: delta.reset ? delta.added.size + revision.prepend.length : delta.added.size + delta.modified.size + delta.deleted.size,
|
|
886
|
+
lastModifiedDate: revision.date,
|
|
887
|
+
nextRevId: revision.id,
|
|
888
|
+
bundle: bundleCode1.source,
|
|
889
|
+
map: bundleMap1,
|
|
890
|
+
artifacts,
|
|
891
|
+
assets
|
|
892
|
+
};
|
|
893
|
+
} catch (error) {
|
|
894
|
+
throw new Error("Serializer did not return expected format. The project copy of `expo/metro-config` may be out of date. Error: " + error.message);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
if (typeof bundle === "string") {
|
|
898
|
+
bundleCode = bundle;
|
|
899
|
+
// Create the source map in a second pass...
|
|
900
|
+
let { prepend , graph } = revision;
|
|
901
|
+
if (serializerOptions.modulesOnly) {
|
|
902
|
+
prepend = [];
|
|
903
|
+
}
|
|
904
|
+
bundleMap = await sourceMapStringAsync([
|
|
905
|
+
//
|
|
906
|
+
...prepend,
|
|
907
|
+
...this.metro._getSortedModules(graph),
|
|
908
|
+
], {
|
|
909
|
+
excludeSource: serializerOptions.excludeSource,
|
|
910
|
+
processModuleFilter: config.serializer.processModuleFilter,
|
|
911
|
+
shouldAddToIgnoreList
|
|
912
|
+
});
|
|
913
|
+
} else {
|
|
914
|
+
bundleCode = bundle.code;
|
|
915
|
+
bundleMap = bundle.map;
|
|
916
|
+
}
|
|
917
|
+
return {
|
|
918
|
+
numModifiedFiles: delta.reset ? delta.added.size + revision.prepend.length : delta.added.size + delta.modified.size + delta.deleted.size,
|
|
919
|
+
lastModifiedDate: revision.date,
|
|
920
|
+
nextRevId: revision.id,
|
|
921
|
+
bundle: bundleCode,
|
|
922
|
+
map: bundleMap
|
|
923
|
+
};
|
|
924
|
+
} catch (error1) {
|
|
925
|
+
this.metro._reporter.update({
|
|
926
|
+
buildID: getBuildID(buildNumber),
|
|
927
|
+
type: "bundle_build_failed"
|
|
928
|
+
});
|
|
929
|
+
throw error1;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
getMetroSerializer() {
|
|
933
|
+
var ref, ref1;
|
|
934
|
+
return ((ref = this.metro) == null ? void 0 : (ref1 = ref._config) == null ? void 0 : ref1.serializer.customSerializer) || ((entryPoint, preModules, graph, options)=>(0, _bundleToString().default)((0, _baseJSBundle().default)(entryPoint, preModules, graph, options)).code);
|
|
935
|
+
}
|
|
936
|
+
getMetroRevision(resolvedEntryFilePath, { graphOptions , transformOptions , resolverOptions }) {
|
|
937
|
+
(0, _assert().default)(this.metro, "Metro server must be running to bundle directly.");
|
|
938
|
+
const config = this.metro._config;
|
|
939
|
+
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
940
|
+
unstable_allowRequireContext: config.transformer.unstable_allowRequireContext,
|
|
941
|
+
resolverOptions,
|
|
942
|
+
shallow: graphOptions.shallow,
|
|
943
|
+
lazy: graphOptions.lazy
|
|
944
|
+
});
|
|
945
|
+
return this.metro.getBundler().getRevisionByGraphId(graphId);
|
|
946
|
+
}
|
|
947
|
+
async resolveRelativePathAsync(moduleId, { resolverOptions , transformOptions }) {
|
|
948
|
+
(0, _assert().default)(this.metro, "cannot invoke resolveRelativePathAsync without metro instance");
|
|
949
|
+
return await this.metro._resolveRelativePath((0, _metroOptions.convertPathToModuleSpecifier)(moduleId), {
|
|
950
|
+
relativeTo: "server",
|
|
951
|
+
resolverOptions,
|
|
952
|
+
transformOptions
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
function getBuildID(buildNumber) {
|
|
957
|
+
return buildNumber.toString(36);
|
|
677
958
|
}
|
|
678
959
|
function getDeepLinkHandler(projectRoot) {
|
|
679
960
|
return async ({ runtime })=>{
|
|
@@ -685,5 +966,16 @@ function getDeepLinkHandler(projectRoot) {
|
|
|
685
966
|
});
|
|
686
967
|
};
|
|
687
968
|
}
|
|
969
|
+
function wrapBundle(str) {
|
|
970
|
+
// Skip the metro runtime so debugging is a bit easier.
|
|
971
|
+
// Replace the __r() call with an export statement.
|
|
972
|
+
// Use gm to apply to the last require line. This is needed when the bundle has side-effects.
|
|
973
|
+
return str.replace(/^(__r\(.*\);)$/gm, "module.exports = $1");
|
|
974
|
+
}
|
|
975
|
+
async function sourceMapStringAsync(modules, options) {
|
|
976
|
+
return (await (0, _sourceMapGenerator().sourceMapGeneratorNonBlocking)(modules, options)).toString(undefined, {
|
|
977
|
+
excludeSource: options.excludeSource
|
|
978
|
+
});
|
|
979
|
+
}
|
|
688
980
|
|
|
689
981
|
//# sourceMappingURL=MetroBundlerDevServer.js.map
|