@expo/cli 0.18.18 → 0.18.19

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.
Files changed (45) hide show
  1. package/build/bin/cli +1 -1
  2. package/build/src/export/createMetadataJson.js.map +1 -1
  3. package/build/src/export/embed/exportEmbedAsync.js +41 -110
  4. package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
  5. package/build/src/export/embed/resolveOptions.js +1 -0
  6. package/build/src/export/embed/resolveOptions.js.map +1 -1
  7. package/build/src/export/exportApp.js +92 -130
  8. package/build/src/export/exportApp.js.map +1 -1
  9. package/build/src/export/exportAssets.js.map +1 -1
  10. package/build/src/export/exportHermes.js +0 -15
  11. package/build/src/export/exportHermes.js.map +1 -1
  12. package/build/src/export/exportStaticAsync.js +48 -3
  13. package/build/src/export/exportStaticAsync.js.map +1 -1
  14. package/build/src/export/fork-bundleAsync.js +284 -0
  15. package/build/src/export/fork-bundleAsync.js.map +1 -0
  16. package/build/src/export/saveAssets.js.map +1 -1
  17. package/build/src/run/startBundler.js +8 -1
  18. package/build/src/run/startBundler.js.map +1 -1
  19. package/build/src/start/server/BundlerDevServer.js +2 -9
  20. package/build/src/start/server/BundlerDevServer.js.map +1 -1
  21. package/build/src/start/server/DevServerManager.js +1 -13
  22. package/build/src/start/server/DevServerManager.js.map +1 -1
  23. package/build/src/start/server/getStaticRenderFunctions.js +123 -9
  24. package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
  25. package/build/src/start/server/metro/MetroBundlerDevServer.js +102 -391
  26. package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
  27. package/build/src/start/server/metro/createServerRouteMiddleware.js +9 -0
  28. package/build/src/start/server/metro/createServerRouteMiddleware.js.map +1 -1
  29. package/build/src/start/server/metro/instantiateMetro.js +12 -19
  30. package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
  31. package/build/src/start/server/metro/metroErrorInterface.js +2 -49
  32. package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
  33. package/build/src/start/server/metro/runServer-fork.js +20 -28
  34. package/build/src/start/server/metro/runServer-fork.js.map +1 -1
  35. package/build/src/start/server/metro/withMetroMultiPlatform.js +9 -8
  36. package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
  37. package/build/src/start/server/middleware/ManifestMiddleware.js +3 -6
  38. package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -1
  39. package/build/src/start/server/middleware/metroOptions.js +3 -11
  40. package/build/src/start/server/middleware/metroOptions.js.map +1 -1
  41. package/build/src/start/server/middleware/resolveAssets.js.map +1 -1
  42. package/build/src/utils/telemetry/getContext.js +1 -1
  43. package/package.json +3 -3
  44. package/build/src/start/server/metro/metroPrivateServer.js +0 -26
  45. package/build/src/start/server/metro/metroPrivateServer.js.map +0 -1
@@ -14,6 +14,7 @@ function _export(target, all) {
14
14
  });
15
15
  }
16
16
  _export(exports, {
17
+ ForwardHtmlError: ()=>ForwardHtmlError,
17
18
  MetroBundlerDevServer: ()=>MetroBundlerDevServer,
18
19
  getDeepLinkHandler: ()=>getDeepLinkHandler
19
20
  });
@@ -45,23 +46,9 @@ function _chalk() {
45
46
  };
46
47
  return data;
47
48
  }
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() {
49
+ function _nodeFetch() {
50
+ const data = /*#__PURE__*/ _interopRequireDefault(require("node-fetch"));
51
+ _nodeFetch = function() {
65
52
  return data;
66
53
  };
67
54
  return data;
@@ -77,7 +64,6 @@ const _createServerRouteMiddleware = require("./createServerRouteMiddleware");
77
64
  const _fetchRouterManifest = require("./fetchRouterManifest");
78
65
  const _instantiateMetro = require("./instantiateMetro");
79
66
  const _metroErrorInterface = require("./metroErrorInterface");
80
- const _metroPrivateServer = require("./metroPrivateServer");
81
67
  const _metroWatchTypeScriptFiles = require("./metroWatchTypeScriptFiles");
82
68
  const _router = require("./router");
83
69
  const _serializeHtml = require("./serializeHtml");
@@ -147,8 +133,14 @@ function _interopRequireWildcard(obj, nodeInterop) {
147
133
  }
148
134
  return newObj;
149
135
  }
136
+ class ForwardHtmlError extends _errors.CommandError {
137
+ constructor(message, html, statusCode){
138
+ super(message);
139
+ this.html = html;
140
+ this.statusCode = statusCode;
141
+ }
142
+ }
150
143
  const debug = require("debug")("expo:start:server:metro");
151
- const getGraphId = require("metro/src/lib/getGraphId");
152
144
  /** Default port to use for apps running in Expo Go. */ const EXPO_GO_METRO_PORT = 8081;
153
145
  /** Default port to use for apps that run in standard React Native projects or Expo Dev Clients. */ const DEV_CLIENT_METRO_PORT = 8081;
154
146
  class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
@@ -183,17 +175,16 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
183
175
  // Alternatively, check whether `sourcesRoot` helps here
184
176
  const artifactBasename = encodeURIComponent(_path().default.basename(artifactFilename) + ".map");
185
177
  src = src.replace(/\/\/# sourceMappingURL=.*/g, `//# sourceMappingURL=${artifactBasename}`);
186
- const parsedMap = JSON.parse(contents.map);
187
178
  files.set(artifactFilename + ".map", {
188
179
  contents: JSON.stringify({
189
- version: parsedMap.version,
190
- sources: parsedMap.sources.map((source)=>{
180
+ version: contents.map.version,
181
+ sources: contents.map.sources.map((source)=>{
191
182
  source = typeof source === "string" && source.startsWith(this.projectRoot) ? _path().default.relative(this.projectRoot, source) : source;
192
183
  return source.split(_path().default.sep).join("/");
193
184
  }),
194
- sourcesContent: new Array(parsedMap.sources.length).fill(null),
195
- names: parsedMap.names,
196
- mappings: parsedMap.mappings
185
+ sourcesContent: new Array(contents.map.sources.length).fill(null),
186
+ names: contents.map.names,
187
+ mappings: contents.map.mappings
197
188
  }),
198
189
  targetDomain: "server"
199
190
  });
@@ -230,8 +221,14 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
230
221
  }
231
222
  async getStaticRenderFunctionAsync() {
232
223
  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.");
233
226
  const url = this.getDevServerUrl();
234
- const { getStaticContent , getManifest , getBuildTimeServerManifestAsync } = await this.ssrLoadModule("expo-router/node/render.js");
227
+ const { getStaticContent , getManifest , getBuildTimeServerManifestAsync } = await this.ssrLoadModule("expo-router/node/render.js", {
228
+ minify,
229
+ mode,
230
+ isExporting
231
+ });
235
232
  const { exp } = (0, _config().getConfig)(this.projectRoot);
236
233
  return {
237
234
  serverManifest: await getBuildTimeServerManifestAsync(),
@@ -247,39 +244,79 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
247
244
  };
248
245
  }
249
246
  async getStaticResourcesAsync({ includeSourceMaps , mainModuleName } = {}) {
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.");
247
+ var ref;
248
+ const { mode , minify , isExporting , baseUrl , routerRoot , asyncRoutes } = this.instanceMetroOptions;
249
+ (0, _assert().default)(mode != null && isExporting != null && baseUrl != null && routerRoot != null && asyncRoutes != null, "The server must be started before calling getStaticPageAsync.");
252
250
  const platform = "web";
253
- const resolvedMainModuleName = mainModuleName != null ? mainModuleName : "." + _path().default.sep + (0, _manifestMiddleware.resolveMainModuleName)(this.projectRoot, {
254
- platform
255
- });
256
- return await this.metroImportAsArtifactsAsync(resolvedMainModuleName, {
251
+ const devBundleUrlPathname = (0, _metroOptions.createBundleUrlPath)({
257
252
  splitChunks: isExporting && !_env1.env.EXPO_NO_BUNDLE_SPLITTING,
258
253
  platform,
259
254
  mode,
260
255
  minify,
261
256
  environment: "client",
257
+ serializerOutput: "static",
262
258
  serializerIncludeMaps: includeSourceMaps,
263
- mainModuleName: resolvedMainModuleName,
259
+ mainModuleName: mainModuleName != null ? mainModuleName : (0, _manifestMiddleware.resolveMainModuleName)(this.projectRoot, {
260
+ platform
261
+ }),
264
262
  lazy: (0, _metroOptions.shouldEnableAsyncImports)(this.projectRoot),
265
263
  asyncRoutes,
266
264
  baseUrl,
267
265
  isExporting,
268
266
  routerRoot,
269
- reactCompiler,
270
267
  bytecode: false
271
268
  });
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);
272
310
  }
273
311
  async getStaticPageAsync(pathname) {
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.");
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.");
276
314
  const platform = "web";
277
315
  const devBundleUrlPathname = (0, _metroOptions.createBundleUrlPath)({
278
316
  splitChunks: isExporting && !_env1.env.EXPO_NO_BUNDLE_SPLITTING,
279
317
  platform,
280
318
  mode,
281
319
  environment: "client",
282
- reactCompiler,
283
320
  mainModuleName: (0, _manifestMiddleware.resolveMainModuleName)(this.projectRoot, {
284
321
  platform
285
322
  }),
@@ -319,165 +356,36 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
319
356
  // Set when the server is started.
320
357
  instanceMetroOptions = {};
321
358
  async ssrLoadModule(filePath, specificOptions = {}) {
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,
359
+ const { baseUrl , routerRoot , isExporting } = this.instanceMetroOptions;
360
+ (0, _assert().default)(baseUrl != null && routerRoot != null && isExporting != null, "The server must be started before calling ssrLoadModule.");
361
+ return (await (0, _getStaticRenderFunctions.getStaticRenderFunctionsForEntry)(this.projectRoot, this.getDevServerUrl(), {
354
362
  // Bundle in Node.js mode for SSR.
355
363
  environment: "node",
356
- // platform: 'web',
357
- // mode: 'development',
358
- //
364
+ platform: "web",
365
+ mode: "development",
366
+ bytecode: false,
359
367
  ...this.instanceMetroOptions,
360
368
  baseUrl,
361
- // routerRoot,
362
- // isExporting,
369
+ routerRoot,
370
+ isExporting,
363
371
  ...specificOptions
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
- };
372
+ }, filePath)).fn;
415
373
  }
416
374
  async ssrLoadModuleContents(filePath, specificOptions = {}) {
417
375
  const { baseUrl , routerRoot , isExporting } = this.instanceMetroOptions;
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: filePath,
422
- lazy: false,
423
- asyncRoutes: false,
424
- inlineSourceMap: false,
425
- engine: "hermes",
426
- minify: false,
427
- bytecode: false,
376
+ (0, _assert().default)(baseUrl != null && routerRoot != null && isExporting != null, "The server must be started before calling ssrLoadModule.");
377
+ return await (0, _getStaticRenderFunctions.requireFileContentsWithMetro)(this.projectRoot, this.getDevServerUrl(), filePath, {
428
378
  // Bundle in Node.js mode for SSR.
429
379
  environment: "node",
430
380
  platform: "web",
431
381
  mode: "development",
432
- //
382
+ bytecode: false,
433
383
  ...this.instanceMetroOptions,
434
- // Mostly disable compiler in SSR bundles.
435
- reactCompiler: false,
436
384
  baseUrl,
437
385
  routerRoot,
438
386
  isExporting,
439
387
  ...specificOptions
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(_path().default.sep)) {
474
- opts.mainModuleName = "." + _path().default.sep + opts.mainModuleName;
475
- }
476
- const output = await this.metroLoadModuleContents(opts.mainModuleName, opts, extraOptions);
477
- return {
478
- artifacts: output.artifacts,
479
- assets: output.assets
480
- };
388
+ });
481
389
  }
482
390
  async watchEnvironmentVariables() {
483
391
  if (!this.instance) {
@@ -501,24 +409,26 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
501
409
  });
502
410
  });
503
411
  }
412
+ getExpoLineOptions() {
413
+ return this.instanceMetroOptions;
414
+ }
504
415
  async startImplementationAsync(options) {
505
- var ref, ref1;
416
+ var ref;
506
417
  options.port = await this.resolvePortAsync(options);
507
418
  this.urlCreator = this.getUrlCreator(options);
508
419
  const config = (0, _config().getConfig)(this.projectRoot, {
509
420
  skipSDKVersionRequirement: true
510
421
  });
511
422
  const { exp } = config;
512
- var ref2;
423
+ var ref1;
513
424
  const useServerRendering = [
514
425
  "static",
515
426
  "server"
516
- ].includes((ref2 = (ref = exp.web) == null ? void 0 : ref.output) != null ? ref2 : "");
427
+ ].includes((ref1 = (ref = exp.web) == null ? void 0 : ref.output) != null ? ref1 : "");
517
428
  const baseUrl = (0, _metroOptions.getBaseUrlFromExpoConfig)(exp);
518
429
  var _mode;
519
430
  const asyncRoutes = (0, _metroOptions.getAsyncRoutesFromExpoConfig)(exp, (_mode = options.mode) != null ? _mode : "development", "web");
520
431
  const routerRoot = (0, _router.getRouterDirectoryModuleIdWithManifest)(this.projectRoot, exp);
521
- const reactCompiler = !!((ref1 = exp.experiments) == null ? void 0 : ref1.reactCompiler);
522
432
  const appDir = _path().default.join(this.projectRoot, routerRoot);
523
433
  var _mode1;
524
434
  const mode = (_mode1 = options.mode) != null ? _mode1 : "development";
@@ -527,7 +437,6 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
527
437
  baseUrl,
528
438
  mode,
529
439
  routerRoot,
530
- reactCompiler,
531
440
  minify: options.minify,
532
441
  asyncRoutes
533
442
  };
@@ -581,12 +490,12 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
581
490
  // This should come after the static middleware so it doesn't serve the favicon from `public/favicon.ico`.
582
491
  middleware.use(new _faviconMiddleware.FaviconMiddleware(this.projectRoot).getHandler());
583
492
  if (useServerRendering) {
584
- var ref3;
493
+ var ref2;
585
494
  middleware.use((0, _createServerRouteMiddleware.createRouteHandlerMiddleware)(this.projectRoot, {
586
495
  appDir,
587
496
  routerRoot,
588
497
  config,
589
- ...(ref3 = config.exp.extra) == null ? void 0 : ref3.router,
498
+ ...(ref2 = config.exp.extra) == null ? void 0 : ref2.router,
590
499
  bundleApiRoute: (functionFilePath)=>this.ssrImportApiRoute(functionFilePath),
591
500
  getStaticPageAsync: (pathname)=>{
592
501
  return this.getStaticPageAsync(pathname);
@@ -630,7 +539,6 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
630
539
  callback == null ? void 0 : callback(err);
631
540
  });
632
541
  };
633
- (0, _metroPrivateServer.assertMetroPrivateServer)(metro);
634
542
  this.metro = metro;
635
543
  return {
636
544
  server,
@@ -716,17 +624,13 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
716
624
  debug("Bundle API route:", this.instanceMetroOptions.routerRoot, filePath);
717
625
  return await this.ssrLoadModuleContents(filePath);
718
626
  } catch (error) {
719
- var ref;
720
- const appDir = ((ref = this.instanceMetroOptions) == null ? void 0 : ref.routerRoot) ? _path().default.join(this.projectRoot, this.instanceMetroOptions.routerRoot) : undefined;
721
- const relativePath = appDir ? _path().default.relative(appDir, filePath) : filePath;
722
- // Expected errors: invalid syntax, missing resolutions.
723
- // Wrap with command error for better error messages.
724
- const err = new _errors.CommandError("API_ROUTE", (0, _chalk().default)`Failed to bundle API Route: {bold ${relativePath}}\n\n` + error.message);
725
- for(const key in error){
726
- // @ts-expect-error
727
- err[key] = error[key];
627
+ if (error instanceof Error) {
628
+ await (0, _metroErrorInterface.logMetroErrorAsync)({
629
+ error,
630
+ projectRoot: this.projectRoot
631
+ });
728
632
  }
729
- throw err;
633
+ throw error;
730
634
  } finally{
731
635
  // pendingRouteOperations.delete(filepath);
732
636
  }
@@ -750,7 +654,7 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
750
654
  const htmlServerError = await (0, _metroErrorInterface.getErrorOverlayHtmlAsync)({
751
655
  error,
752
656
  projectRoot: this.projectRoot,
753
- routerRoot: this.instanceMetroOptions.routerRoot
657
+ routerRoot: this.getExpoLineOptions().routerRoot
754
658
  });
755
659
  return new Response(htmlServerError, {
756
660
  status: 500,
@@ -770,188 +674,6 @@ class MetroBundlerDevServer extends _bundlerDevServer.BundlerDevServer {
770
674
  invalidateApiRouteCache() {
771
675
  this.pendingRouteOperations.clear();
772
676
  }
773
- // Direct Metro access
774
- // Emulates the Metro dev server .bundle endpoint without having to go through a server.
775
- async _bundleDirectAsync(resolvedEntryFilePath, { transformOptions , resolverOptions , graphOptions , serializerOptions }) {
776
- var ref;
777
- (0, _assert().default)(this.metro, "Metro server must be running to bundle directly.");
778
- const config = this.metro._config;
779
- const buildNumber = this.metro.getNewBuildNumber();
780
- const bundlePerfLogger = config.unstable_perfLoggerFactory == null ? void 0 : config.unstable_perfLoggerFactory("BUNDLING_REQUEST", {
781
- key: buildNumber
782
- });
783
- const onProgress = (transformedFileCount, totalFileCount)=>{
784
- var ref, ref1;
785
- (ref = this.metro) == null ? void 0 : (ref1 = ref._reporter) == null ? void 0 : ref1.update == null ? void 0 : ref1.update({
786
- buildID: getBuildID(buildNumber),
787
- type: "bundle_transform_progressed",
788
- transformedFileCount,
789
- totalFileCount
790
- });
791
- };
792
- const revPromise = this.getMetroRevision(resolvedEntryFilePath, {
793
- graphOptions,
794
- transformOptions,
795
- resolverOptions
796
- });
797
- bundlePerfLogger == null ? void 0 : bundlePerfLogger.point("resolvingAndTransformingDependencies_start");
798
- bundlePerfLogger == null ? void 0 : bundlePerfLogger.annotate({
799
- bool: {
800
- initial_build: revPromise == null
801
- }
802
- });
803
- (ref = this.metro) == null ? void 0 : ref._reporter.update({
804
- buildID: getBuildID(buildNumber),
805
- bundleDetails: {
806
- bundleType: transformOptions.type,
807
- dev: transformOptions.dev,
808
- entryFile: resolvedEntryFilePath,
809
- minify: transformOptions.minify,
810
- platform: transformOptions.platform,
811
- // @ts-expect-error: typed incorrectly upstream
812
- customResolverOptions: resolverOptions.customResolverOptions,
813
- customTransformOptions: transformOptions.customTransformOptions
814
- },
815
- isPrefetch: false,
816
- type: "bundle_build_started"
817
- });
818
- try {
819
- 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.
820
- // entryFile,
821
- resolvedEntryFilePath, transformOptions, resolverOptions, {
822
- onProgress,
823
- shallow: graphOptions.shallow,
824
- // @ts-expect-error: typed incorrectly
825
- lazy: graphOptions.lazy
826
- }));
827
- bundlePerfLogger == null ? void 0 : bundlePerfLogger.annotate({
828
- int: {
829
- graph_node_count: revision.graph.dependencies.size
830
- }
831
- });
832
- bundlePerfLogger == null ? void 0 : bundlePerfLogger.point("resolvingAndTransformingDependencies_end");
833
- bundlePerfLogger == null ? void 0 : bundlePerfLogger.point("serializingBundle_start");
834
- const shouldAddToIgnoreList = this.metro._shouldAddModuleToIgnoreList.bind(this.metro);
835
- const serializer = this.getMetroSerializer();
836
- var _unstable_serverRoot;
837
- const bundle = await serializer(// NOTE: Using absolute path instead of relative input path is a breaking change.
838
- // entryFile,
839
- resolvedEntryFilePath, revision.prepend, revision.graph, {
840
- asyncRequireModulePath: await this.metro._resolveRelativePath(config.transformer.asyncRequireModulePath, {
841
- relativeTo: "project",
842
- resolverOptions,
843
- transformOptions
844
- }),
845
- // ...serializerOptions,
846
- processModuleFilter: config.serializer.processModuleFilter,
847
- createModuleId: this.metro._createModuleId,
848
- getRunModuleStatement: config.serializer.getRunModuleStatement,
849
- includeAsyncPaths: graphOptions.lazy,
850
- dev: transformOptions.dev,
851
- projectRoot: config.projectRoot,
852
- modulesOnly: serializerOptions.modulesOnly,
853
- runBeforeMainModule: config.serializer.getModulesRunBeforeMainModule(resolvedEntryFilePath),
854
- runModule: serializerOptions.runModule,
855
- sourceMapUrl: serializerOptions.sourceMapUrl,
856
- sourceUrl: serializerOptions.sourceUrl,
857
- inlineSourceMap: serializerOptions.inlineSourceMap,
858
- serverRoot: (_unstable_serverRoot = config.server.unstable_serverRoot) != null ? _unstable_serverRoot : config.projectRoot,
859
- shouldAddToIgnoreList,
860
- // @ts-expect-error: passed to our serializer to enable non-serial return values.
861
- serializerOptions
862
- });
863
- this.metro._reporter.update({
864
- buildID: getBuildID(buildNumber),
865
- type: "bundle_build_done"
866
- });
867
- bundlePerfLogger == null ? void 0 : bundlePerfLogger.point("serializingBundle_end");
868
- let bundleCode = null;
869
- let bundleMap = null;
870
- // @ts-expect-error: If the output is multi-bundle...
871
- if (serializerOptions.output === "static") {
872
- try {
873
- var ref1, ref2;
874
- const parsed = typeof bundle === "string" ? JSON.parse(bundle) : bundle;
875
- (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.");
876
- const artifacts = parsed.artifacts;
877
- const assets = parsed.assets;
878
- const bundleCode1 = artifacts.filter((asset)=>asset.type === "js")[0];
879
- var ref3;
880
- const bundleMap1 = (ref3 = (ref1 = artifacts.filter((asset)=>asset.type === "map")) == null ? void 0 : (ref2 = ref1[0]) == null ? void 0 : ref2.source) != null ? ref3 : "";
881
- return {
882
- numModifiedFiles: delta.reset ? delta.added.size + revision.prepend.length : delta.added.size + delta.modified.size + delta.deleted.size,
883
- lastModifiedDate: revision.date,
884
- nextRevId: revision.id,
885
- bundle: bundleCode1.source,
886
- map: bundleMap1,
887
- artifacts,
888
- assets
889
- };
890
- } catch (error) {
891
- throw new Error("Serializer did not return expected format. The project copy of `expo/metro-config` may be out of date. Error: " + error.message);
892
- }
893
- }
894
- if (typeof bundle === "string") {
895
- bundleCode = bundle;
896
- // Create the source map in a second pass...
897
- let { prepend , graph } = revision;
898
- if (serializerOptions.modulesOnly) {
899
- prepend = [];
900
- }
901
- bundleMap = await sourceMapStringAsync([
902
- //
903
- ...prepend,
904
- ...this.metro._getSortedModules(graph),
905
- ], {
906
- excludeSource: serializerOptions.excludeSource,
907
- processModuleFilter: config.serializer.processModuleFilter,
908
- shouldAddToIgnoreList
909
- });
910
- } else {
911
- bundleCode = bundle.code;
912
- bundleMap = bundle.map;
913
- }
914
- return {
915
- numModifiedFiles: delta.reset ? delta.added.size + revision.prepend.length : delta.added.size + delta.modified.size + delta.deleted.size,
916
- lastModifiedDate: revision.date,
917
- nextRevId: revision.id,
918
- bundle: bundleCode,
919
- map: bundleMap
920
- };
921
- } catch (error1) {
922
- this.metro._reporter.update({
923
- buildID: getBuildID(buildNumber),
924
- type: "bundle_build_failed"
925
- });
926
- throw error1;
927
- }
928
- }
929
- getMetroSerializer() {
930
- var ref, ref1;
931
- 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);
932
- }
933
- getMetroRevision(resolvedEntryFilePath, { graphOptions , transformOptions , resolverOptions }) {
934
- (0, _assert().default)(this.metro, "Metro server must be running to bundle directly.");
935
- const config = this.metro._config;
936
- const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
937
- unstable_allowRequireContext: config.transformer.unstable_allowRequireContext,
938
- resolverOptions,
939
- shallow: graphOptions.shallow,
940
- lazy: graphOptions.lazy
941
- });
942
- return this.metro.getBundler().getRevisionByGraphId(graphId);
943
- }
944
- async resolveRelativePathAsync(moduleId, { resolverOptions , transformOptions }) {
945
- (0, _assert().default)(this.metro, "cannot invoke resolveRelativePathAsync without metro instance");
946
- return await this.metro._resolveRelativePath(moduleId, {
947
- relativeTo: "server",
948
- resolverOptions,
949
- transformOptions
950
- });
951
- }
952
- }
953
- function getBuildID(buildNumber) {
954
- return buildNumber.toString(36);
955
677
  }
956
678
  function getDeepLinkHandler(projectRoot) {
957
679
  return async ({ runtime })=>{
@@ -963,16 +685,5 @@ function getDeepLinkHandler(projectRoot) {
963
685
  });
964
686
  };
965
687
  }
966
- function wrapBundle(str) {
967
- // Skip the metro runtime so debugging is a bit easier.
968
- // Replace the __r() call with an export statement.
969
- // Use gm to apply to the last require line. This is needed when the bundle has side-effects.
970
- return str.replace(/^(__r\(.*\);)$/gm, "module.exports = $1");
971
- }
972
- async function sourceMapStringAsync(modules, options) {
973
- return (await (0, _sourceMapGenerator().sourceMapGeneratorNonBlocking)(modules, options)).toString(undefined, {
974
- excludeSource: options.excludeSource
975
- });
976
- }
977
688
 
978
689
  //# sourceMappingURL=MetroBundlerDevServer.js.map