metro 0.80.8 → 0.80.10

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 (65) hide show
  1. package/package.json +18 -18
  2. package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -0
  3. package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -0
  4. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +1 -0
  5. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +1 -0
  6. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +1 -1
  7. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +2 -1
  8. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +1 -0
  9. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +3 -0
  10. package/src/DeltaBundler/Serializers/sourceMapString.js +14 -2
  11. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +18 -2
  12. package/src/DeltaBundler/Transformer.js +17 -3
  13. package/src/DeltaBundler/Transformer.js.flow +20 -4
  14. package/src/DeltaBundler/types.flow.js.flow +2 -1
  15. package/src/ModuleGraph/worker/JsFileWrapping.js +3 -2
  16. package/src/ModuleGraph/worker/JsFileWrapping.js.flow +4 -1
  17. package/src/ModuleGraph/worker/collectDependencies.js +54 -4
  18. package/src/ModuleGraph/worker/collectDependencies.js.flow +69 -4
  19. package/src/Server.js +113 -10
  20. package/src/Server.js.flow +131 -10
  21. package/src/cli/parseKeyValueParamArray.js +4 -5
  22. package/src/cli/parseKeyValueParamArray.js.flow +5 -3
  23. package/src/index.flow.js +7 -0
  24. package/src/index.flow.js.flow +8 -0
  25. package/src/integration_tests/basic_bundle/excluded_from_file_map.js +8 -0
  26. package/src/integration_tests/basic_bundle/excluded_from_file_map.js.flow +11 -0
  27. package/src/integration_tests/basic_bundle/import-export/export-7.js +5 -0
  28. package/src/integration_tests/basic_bundle/import-export/export-7.js.flow +15 -0
  29. package/src/integration_tests/basic_bundle/import-export/export-8.js +10 -0
  30. package/src/integration_tests/basic_bundle/import-export/export-8.js.flow +15 -0
  31. package/src/integration_tests/basic_bundle/import-export/index.js +9 -1
  32. package/src/integration_tests/basic_bundle/import-export/index.js.flow +9 -0
  33. package/src/integration_tests/basic_bundle/import-export/utils.js +1 -0
  34. package/src/integration_tests/basic_bundle/import-export/utils.js.flow +14 -0
  35. package/src/integration_tests/basic_bundle/not_a_source_file.xyz +1 -0
  36. package/src/integration_tests/metro.config.js +1 -0
  37. package/src/lib/BatchProcessor.js +3 -0
  38. package/src/lib/BatchProcessor.js.flow +4 -0
  39. package/src/lib/JsonReporter.js +30 -3
  40. package/src/lib/JsonReporter.js.flow +50 -5
  41. package/src/lib/TerminalReporter.js +4 -24
  42. package/src/lib/TerminalReporter.js.flow +13 -32
  43. package/src/lib/getAppendScripts.js +4 -1
  44. package/src/lib/getAppendScripts.js.flow +5 -1
  45. package/src/lib/logToConsole.js.flow +1 -0
  46. package/src/lib/parseOptionsFromUrl.js +4 -0
  47. package/src/lib/parseOptionsFromUrl.js.flow +4 -0
  48. package/src/lib/reporting.d.ts +9 -5
  49. package/src/lib/reporting.js.flow +9 -5
  50. package/src/lib/splitBundleOptions.js +1 -0
  51. package/src/lib/splitBundleOptions.js.flow +1 -0
  52. package/src/node-haste/DependencyGraph/ModuleResolution.js +10 -9
  53. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +16 -14
  54. package/src/node-haste/DependencyGraph.js +8 -4
  55. package/src/node-haste/DependencyGraph.js.flow +12 -4
  56. package/src/node-haste/Module.js +1 -1
  57. package/src/node-haste/Module.js.flow +1 -1
  58. package/src/node-haste/ModuleCache.js +28 -14
  59. package/src/node-haste/ModuleCache.js.flow +43 -18
  60. package/src/node-haste/lib/AssetPaths.js +1 -1
  61. package/src/node-haste/lib/AssetPaths.js.flow +1 -1
  62. package/src/shared/output/bundle.flow.js +2 -2
  63. package/src/shared/output/bundle.flow.js.flow +2 -2
  64. package/src/shared/types.flow.js +10 -0
  65. package/src/shared/types.flow.js.flow +9 -0
package/src/Server.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _types = require("./shared/types.flow");
3
4
  const { getAsset } = require("./Assets");
4
5
  const baseJSBundle = require("./DeltaBundler/Serializers/baseJSBundle");
5
6
  const getAllFiles = require("./DeltaBundler/Serializers/getAllFiles");
@@ -8,7 +9,9 @@ const {
8
9
  getExplodedSourceMap,
9
10
  } = require("./DeltaBundler/Serializers/getExplodedSourceMap");
10
11
  const getRamBundleInfo = require("./DeltaBundler/Serializers/getRamBundleInfo");
11
- const sourceMapString = require("./DeltaBundler/Serializers/sourceMapString");
12
+ const {
13
+ sourceMapStringNonBlocking,
14
+ } = require("./DeltaBundler/Serializers/sourceMapString");
12
15
  const IncrementalBundler = require("./IncrementalBundler");
13
16
  const ResourceNotFoundError = require("./IncrementalBundler/ResourceNotFoundError");
14
17
  const bundleToString = require("./lib/bundleToString");
@@ -60,6 +63,22 @@ class Server {
60
63
  this._reporter = config.reporter;
61
64
  this._logger = Logger;
62
65
  this._platforms = new Set(this._config.resolver.platforms);
66
+ this._allowedSuffixesForSourceRequests = [
67
+ ...new Set(
68
+ [
69
+ ...this._config.resolver.sourceExts,
70
+ ...this._config.watcher.additionalExts,
71
+ ...this._config.resolver.assetExts,
72
+ ].map((ext) => "." + ext)
73
+ ),
74
+ ];
75
+ this._sourceRequestRoutingMap = [
76
+ ["/[metro-project]/", path.resolve(this._config.projectRoot)],
77
+ ...this._config.watchFolders.map((watchFolder, index) => [
78
+ `/[metro-watchFolders]/${index}/`,
79
+ path.resolve(watchFolder),
80
+ ]),
81
+ ];
63
82
  this._isEnded = false;
64
83
  this._createModuleId = config.serializer.createModuleIdFactory();
65
84
  this._bundler = new IncrementalBundler(config, {
@@ -128,6 +147,8 @@ class Server {
128
147
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
129
148
  shouldAddToIgnoreList: (module) =>
130
149
  this._shouldAddModuleToIgnoreList(module),
150
+ getSourceUrl: (module) =>
151
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
131
152
  };
132
153
  let bundleCode = null;
133
154
  let bundleMap = null;
@@ -150,12 +171,14 @@ class Server {
150
171
  ).code;
151
172
  }
152
173
  if (!bundleMap) {
153
- bundleMap = sourceMapString(
174
+ bundleMap = await sourceMapStringNonBlocking(
154
175
  [...prepend, ...this._getSortedModules(graph)],
155
176
  {
156
177
  excludeSource: serializerOptions.excludeSource,
157
178
  processModuleFilter: this._config.serializer.processModuleFilter,
158
179
  shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList,
180
+ getSourceUrl: (module) =>
181
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
159
182
  }
160
183
  );
161
184
  }
@@ -215,6 +238,8 @@ class Server {
215
238
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
216
239
  shouldAddToIgnoreList: (module) =>
217
240
  this._shouldAddModuleToIgnoreList(module),
241
+ getSourceUrl: (module) =>
242
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
218
243
  });
219
244
  }
220
245
  async getAssets(options) {
@@ -342,7 +367,7 @@ class Server {
342
367
  async _processRequest(req, res, next) {
343
368
  const originalUrl = req.url;
344
369
  req.url = this._rewriteAndNormalizeUrl(req.url);
345
- const urlObj = url.parse(req.url, true);
370
+ const urlObj = url.parse(decodeURI(req.url), true);
346
371
  const { host } = req.headers;
347
372
  debug(
348
373
  `Handling request: ${host ? "http://" + host : ""}${req.url}` +
@@ -393,9 +418,58 @@ class Server {
393
418
  } else if (pathname === "/symbolicate") {
394
419
  await this._symbolicate(req, res);
395
420
  } else {
396
- next();
421
+ let handled = false;
422
+ for (const [pathnamePrefix, normalizedRootDir] of this
423
+ ._sourceRequestRoutingMap) {
424
+ if (pathname.startsWith(pathnamePrefix)) {
425
+ const relativePathname = pathname.substr(pathnamePrefix.length);
426
+ await this._processSourceRequest(
427
+ relativePathname,
428
+ normalizedRootDir,
429
+ res
430
+ );
431
+ handled = true;
432
+ break;
433
+ }
434
+ }
435
+ if (!handled) {
436
+ next();
437
+ }
397
438
  }
398
439
  }
440
+ async _processSourceRequest(relativePathname, rootDir, res) {
441
+ if (
442
+ !this._allowedSuffixesForSourceRequests.some((suffix) =>
443
+ relativePathname.endsWith(suffix)
444
+ )
445
+ ) {
446
+ res.writeHead(404);
447
+ res.end();
448
+ return;
449
+ }
450
+ const depGraph = await this._bundler.getBundler().getDependencyGraph();
451
+ const filePath = path.join(rootDir, relativePathname);
452
+ try {
453
+ depGraph.getSha1(filePath);
454
+ } catch {
455
+ res.writeHead(404);
456
+ res.end();
457
+ return;
458
+ }
459
+ const mimeType = mime.lookup(path.basename(relativePathname));
460
+ res.setHeader("Content-Type", mimeType);
461
+ const stream = fs.createReadStream(filePath);
462
+ stream.pipe(res);
463
+ stream.on("error", (error) => {
464
+ if (error.code === "ENOENT") {
465
+ res.writeHead(404);
466
+ res.end();
467
+ } else {
468
+ res.writeHead(500);
469
+ res.end();
470
+ }
471
+ });
472
+ }
399
473
  _createRequestProcessor({
400
474
  createStartEntry,
401
475
  createEndEntry,
@@ -673,6 +747,8 @@ class Server {
673
747
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
674
748
  shouldAddToIgnoreList: (module) =>
675
749
  this._shouldAddModuleToIgnoreList(module),
750
+ getSourceUrl: (module) =>
751
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
676
752
  }
677
753
  );
678
754
  bundlePerfLogger.point("serializingBundle_end");
@@ -795,12 +871,17 @@ class Server {
795
871
  if (serializerOptions.modulesOnly) {
796
872
  prepend = [];
797
873
  }
798
- return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
799
- excludeSource: serializerOptions.excludeSource,
800
- processModuleFilter: this._config.serializer.processModuleFilter,
801
- shouldAddToIgnoreList: (module) =>
802
- this._shouldAddModuleToIgnoreList(module),
803
- });
874
+ return await sourceMapStringNonBlocking(
875
+ [...prepend, ...this._getSortedModules(graph)],
876
+ {
877
+ excludeSource: serializerOptions.excludeSource,
878
+ processModuleFilter: this._config.serializer.processModuleFilter,
879
+ shouldAddToIgnoreList: (module) =>
880
+ this._shouldAddModuleToIgnoreList(module),
881
+ getSourceUrl: (module) =>
882
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
883
+ }
884
+ );
804
885
  },
805
886
  finish({ mres, result }) {
806
887
  mres.setHeader("Content-Type", "application/json");
@@ -1057,6 +1138,7 @@ class Server {
1057
1138
  shallow: false,
1058
1139
  sourceMapUrl: null,
1059
1140
  sourceUrl: null,
1141
+ sourcePaths: _types.SourcePathsMode.Absolute,
1060
1142
  };
1061
1143
  _getServerRootDir() {
1062
1144
  return this._config.server.unstable_serverRoot ?? this._config.projectRoot;
@@ -1074,6 +1156,27 @@ class Server {
1074
1156
  this._config.serializer.isThirdPartyModule(module)
1075
1157
  );
1076
1158
  }
1159
+ _getModuleSourceUrl(module, mode) {
1160
+ switch (mode) {
1161
+ case _types.SourcePathsMode.ServerUrl:
1162
+ for (const [pathnamePrefix, normalizedRootDir] of this
1163
+ ._sourceRequestRoutingMap) {
1164
+ if (module.path.startsWith(normalizedRootDir + path.sep)) {
1165
+ const relativePath = module.path.slice(
1166
+ normalizedRootDir.length + 1
1167
+ );
1168
+ const relativePathPosix = relativePath.split(path.sep).join("/");
1169
+ return pathnamePrefix + encodeURI(relativePathPosix);
1170
+ }
1171
+ }
1172
+ const modulePathPosix = module.path.split(path.sep).join("/");
1173
+ return modulePathPosix.startsWith("/")
1174
+ ? encodeURI(modulePathPosix)
1175
+ : "/" + encodeURI(modulePathPosix);
1176
+ case _types.SourcePathsMode.Absolute:
1177
+ return module.path;
1178
+ }
1179
+ }
1077
1180
  }
1078
1181
  function* zip(xs, ys) {
1079
1182
  const ysIter = ys[Symbol.iterator]();
@@ -43,6 +43,8 @@ import type {
43
43
  import type {CustomResolverOptions} from 'metro-resolver/src/types';
44
44
  import type {CustomTransformOptions} from 'metro-transform-worker';
45
45
 
46
+ import {SourcePathsMode} from './shared/types.flow';
47
+
46
48
  const {getAsset} = require('./Assets');
47
49
  const baseJSBundle = require('./DeltaBundler/Serializers/baseJSBundle');
48
50
  const getAllFiles = require('./DeltaBundler/Serializers/getAllFiles');
@@ -51,7 +53,9 @@ const {
51
53
  getExplodedSourceMap,
52
54
  } = require('./DeltaBundler/Serializers/getExplodedSourceMap');
53
55
  const getRamBundleInfo = require('./DeltaBundler/Serializers/getRamBundleInfo');
54
- const sourceMapString = require('./DeltaBundler/Serializers/sourceMapString');
56
+ const {
57
+ sourceMapStringNonBlocking,
58
+ } = require('./DeltaBundler/Serializers/sourceMapString');
55
59
  const IncrementalBundler = require('./IncrementalBundler');
56
60
  const ResourceNotFoundError = require('./IncrementalBundler/ResourceNotFoundError');
57
61
  const bundleToString = require('./lib/bundleToString');
@@ -143,6 +147,10 @@ class Server {
143
147
  _platforms: Set<string>;
144
148
  _reporter: Reporter;
145
149
  _serverOptions: ServerOptions | void;
150
+ _allowedSuffixesForSourceRequests: $ReadOnlyArray<string>;
151
+ _sourceRequestRoutingMap: $ReadOnlyArray<
152
+ [pathnamePrefix: string, normalizedRootDir: string],
153
+ >;
146
154
 
147
155
  constructor(config: ConfigT, options?: ServerOptions) {
148
156
  this._config = config;
@@ -158,6 +166,22 @@ class Server {
158
166
  this._reporter = config.reporter;
159
167
  this._logger = Logger;
160
168
  this._platforms = new Set(this._config.resolver.platforms);
169
+ this._allowedSuffixesForSourceRequests = [
170
+ ...new Set(
171
+ [
172
+ ...this._config.resolver.sourceExts,
173
+ ...this._config.watcher.additionalExts,
174
+ ...this._config.resolver.assetExts,
175
+ ].map(ext => '.' + ext),
176
+ ),
177
+ ];
178
+ this._sourceRequestRoutingMap = [
179
+ ['/[metro-project]/', path.resolve(this._config.projectRoot)],
180
+ ...this._config.watchFolders.map((watchFolder, index) => [
181
+ `/[metro-watchFolders]/${index}/`,
182
+ path.resolve(watchFolder),
183
+ ]),
184
+ ];
161
185
  this._isEnded = false;
162
186
 
163
187
  // TODO(T34760917): These two properties should eventually be instantiated
@@ -242,6 +266,8 @@ class Server {
242
266
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
243
267
  shouldAddToIgnoreList: (module: Module<>) =>
244
268
  this._shouldAddModuleToIgnoreList(module),
269
+ getSourceUrl: (module: Module<>) =>
270
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
245
271
  };
246
272
  let bundleCode = null;
247
273
  let bundleMap = null;
@@ -264,12 +290,14 @@ class Server {
264
290
  ).code;
265
291
  }
266
292
  if (!bundleMap) {
267
- bundleMap = sourceMapString(
293
+ bundleMap = await sourceMapStringNonBlocking(
268
294
  [...prepend, ...this._getSortedModules(graph)],
269
295
  {
270
296
  excludeSource: serializerOptions.excludeSource,
271
297
  processModuleFilter: this._config.serializer.processModuleFilter,
272
298
  shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList,
299
+ getSourceUrl: (module: Module<>) =>
300
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
273
301
  },
274
302
  );
275
303
  }
@@ -333,6 +361,8 @@ class Server {
333
361
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
334
362
  shouldAddToIgnoreList: (module: Module<>) =>
335
363
  this._shouldAddModuleToIgnoreList(module),
364
+ getSourceUrl: (module: Module<>) =>
365
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
336
366
  });
337
367
  }
338
368
 
@@ -465,6 +495,7 @@ class Server {
465
495
  );
466
496
  // Tell clients to cache this for 1 year.
467
497
  // This is safe as the asset url contains a hash of the asset.
498
+ // $FlowFixMe[incompatible-type]
468
499
  if (process.env.REACT_NATIVE_ENABLE_ASSET_CACHING === true) {
469
500
  res.setHeader('Cache-Control', 'max-age=31536000');
470
501
  }
@@ -509,7 +540,7 @@ class Server {
509
540
  ) {
510
541
  const originalUrl = req.url;
511
542
  req.url = this._rewriteAndNormalizeUrl(req.url);
512
- const urlObj = url.parse(req.url, true);
543
+ const urlObj = url.parse(decodeURI(req.url), true);
513
544
  const {host} = req.headers;
514
545
  debug(
515
546
  `Handling request: ${host ? 'http://' + host : ''}${req.url}` +
@@ -562,8 +593,62 @@ class Server {
562
593
  } else if (pathname === '/symbolicate') {
563
594
  await this._symbolicate(req, res);
564
595
  } else {
565
- next();
596
+ let handled = false;
597
+ for (const [pathnamePrefix, normalizedRootDir] of this
598
+ ._sourceRequestRoutingMap) {
599
+ if (pathname.startsWith(pathnamePrefix)) {
600
+ const relativePathname = pathname.substr(pathnamePrefix.length);
601
+ await this._processSourceRequest(
602
+ relativePathname,
603
+ normalizedRootDir,
604
+ res,
605
+ );
606
+ handled = true;
607
+ break;
608
+ }
609
+ }
610
+ if (!handled) {
611
+ next();
612
+ }
613
+ }
614
+ }
615
+
616
+ async _processSourceRequest(
617
+ relativePathname: string,
618
+ rootDir: string,
619
+ res: ServerResponse,
620
+ ): Promise<void> {
621
+ if (
622
+ !this._allowedSuffixesForSourceRequests.some(suffix =>
623
+ relativePathname.endsWith(suffix),
624
+ )
625
+ ) {
626
+ res.writeHead(404);
627
+ res.end();
628
+ return;
629
+ }
630
+ const depGraph = await this._bundler.getBundler().getDependencyGraph();
631
+ const filePath = path.join(rootDir, relativePathname);
632
+ try {
633
+ depGraph.getSha1(filePath);
634
+ } catch {
635
+ res.writeHead(404);
636
+ res.end();
637
+ return;
566
638
  }
639
+ const mimeType = mime.lookup(path.basename(relativePathname));
640
+ res.setHeader('Content-Type', mimeType);
641
+ const stream = fs.createReadStream(filePath);
642
+ stream.pipe(res);
643
+ stream.on('error', error => {
644
+ if (error.code === 'ENOENT') {
645
+ res.writeHead(404);
646
+ res.end();
647
+ } else {
648
+ res.writeHead(500);
649
+ res.end();
650
+ }
651
+ });
567
652
  }
568
653
 
569
654
  _createRequestProcessor<T>({
@@ -920,6 +1005,8 @@ class Server {
920
1005
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
921
1006
  shouldAddToIgnoreList: (module: Module<>) =>
922
1007
  this._shouldAddModuleToIgnoreList(module),
1008
+ getSourceUrl: (module: Module<>) =>
1009
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
923
1010
  },
924
1011
  );
925
1012
  bundlePerfLogger.point('serializingBundle_end');
@@ -1061,12 +1148,17 @@ class Server {
1061
1148
  prepend = [];
1062
1149
  }
1063
1150
 
1064
- return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
1065
- excludeSource: serializerOptions.excludeSource,
1066
- processModuleFilter: this._config.serializer.processModuleFilter,
1067
- shouldAddToIgnoreList: (module: Module<>) =>
1068
- this._shouldAddModuleToIgnoreList(module),
1069
- });
1151
+ return await sourceMapStringNonBlocking(
1152
+ [...prepend, ...this._getSortedModules(graph)],
1153
+ {
1154
+ excludeSource: serializerOptions.excludeSource,
1155
+ processModuleFilter: this._config.serializer.processModuleFilter,
1156
+ shouldAddToIgnoreList: (module: Module<>) =>
1157
+ this._shouldAddModuleToIgnoreList(module),
1158
+ getSourceUrl: (module: Module<>) =>
1159
+ this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
1160
+ },
1161
+ );
1070
1162
  },
1071
1163
  finish({mres, result}) {
1072
1164
  mres.setHeader('Content-Type', 'application/json');
@@ -1371,6 +1463,7 @@ class Server {
1371
1463
  shallow: false,
1372
1464
  sourceMapUrl: null,
1373
1465
  sourceUrl: null,
1466
+ sourcePaths: SourcePathsMode,
1374
1467
  } = {
1375
1468
  ...Server.DEFAULT_GRAPH_OPTIONS,
1376
1469
  excludeSource: false,
@@ -1382,6 +1475,7 @@ class Server {
1382
1475
  shallow: false,
1383
1476
  sourceMapUrl: null,
1384
1477
  sourceUrl: null,
1478
+ sourcePaths: SourcePathsMode.Absolute,
1385
1479
  };
1386
1480
 
1387
1481
  _getServerRootDir(): string {
@@ -1408,6 +1502,33 @@ class Server {
1408
1502
  this._config.serializer.isThirdPartyModule(module)
1409
1503
  );
1410
1504
  }
1505
+
1506
+ // Flow checking is enough to ensure that a value is returned in all cases.
1507
+ // eslint-disable-next-line consistent-return
1508
+ _getModuleSourceUrl(module: Module<>, mode: SourcePathsMode): string {
1509
+ switch (mode) {
1510
+ case SourcePathsMode.ServerUrl:
1511
+ for (const [pathnamePrefix, normalizedRootDir] of this
1512
+ ._sourceRequestRoutingMap) {
1513
+ if (module.path.startsWith(normalizedRootDir + path.sep)) {
1514
+ const relativePath = module.path.slice(
1515
+ normalizedRootDir.length + 1,
1516
+ );
1517
+ const relativePathPosix = relativePath.split(path.sep).join('/');
1518
+ return pathnamePrefix + encodeURI(relativePathPosix);
1519
+ }
1520
+ }
1521
+ // Ordinarily all files should match one of the roots above. If they
1522
+ // don't, try to preserve useful information, even if fetching the path
1523
+ // from Metro might fail.
1524
+ const modulePathPosix = module.path.split(path.sep).join('/');
1525
+ return modulePathPosix.startsWith('/')
1526
+ ? encodeURI(modulePathPosix)
1527
+ : '/' + encodeURI(modulePathPosix);
1528
+ case SourcePathsMode.Absolute:
1529
+ return module.path;
1530
+ }
1531
+ }
1411
1532
  }
1412
1533
 
1413
1534
  function* zip<X, Y>(xs: Iterable<X>, ys: Iterable<Y>): Iterable<[X, Y]> {
@@ -4,10 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true,
5
5
  });
6
6
  exports.default = coerceKeyValueArray;
7
- var _querystring = _interopRequireDefault(require("querystring"));
8
- function _interopRequireDefault(obj) {
9
- return obj && obj.__esModule ? obj : { default: obj };
10
- }
11
7
  function coerceKeyValueArray(keyValueArray) {
12
8
  const result = Object.create(null);
13
9
  for (const item of keyValueArray) {
@@ -17,7 +13,10 @@ function coerceKeyValueArray(keyValueArray) {
17
13
  if (item.indexOf("&") !== -1) {
18
14
  throw new Error('Parameter cannot include "&" but found: ' + item);
19
15
  }
20
- Object.assign(result, _querystring.default.parse(item));
16
+ const params = new URLSearchParams(item);
17
+ params.forEach((value, key) => {
18
+ result[key] = value;
19
+ });
21
20
  }
22
21
  return result;
23
22
  }
@@ -9,8 +9,6 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import querystring from 'querystring';
13
-
14
12
  export default function coerceKeyValueArray(
15
13
  keyValueArray: $ReadOnlyArray<string>,
16
14
  ): {
@@ -25,7 +23,11 @@ export default function coerceKeyValueArray(
25
23
  if (item.indexOf('&') !== -1) {
26
24
  throw new Error('Parameter cannot include "&" but found: ' + item);
27
25
  }
28
- Object.assign(result, querystring.parse(item));
26
+ const params = new URLSearchParams(item);
27
+ params.forEach((value, key) => {
28
+ // $FlowExpectedError[prop-missing]
29
+ result[key] = value;
30
+ });
29
31
  }
30
32
  return result;
31
33
  }
package/src/index.flow.js CHANGED
@@ -167,6 +167,13 @@ exports.runServer = async (
167
167
  end();
168
168
  });
169
169
  httpServer.listen(config.server.port, host, () => {
170
+ const { address, port, family } = httpServer.address();
171
+ config.reporter.update({
172
+ type: "server_listening",
173
+ address,
174
+ port,
175
+ family,
176
+ });
170
177
  if (onReady) {
171
178
  onReady(httpServer);
172
179
  }
@@ -309,6 +309,14 @@ exports.runServer = async (
309
309
  });
310
310
 
311
311
  httpServer.listen(config.server.port, host, () => {
312
+ const {address, port, family} = httpServer.address();
313
+ config.reporter.update({
314
+ type: 'server_listening',
315
+ address,
316
+ port, // Assigned port if configured with port 0
317
+ family,
318
+ });
319
+
312
320
  if (onReady) {
313
321
  onReady(httpServer);
314
322
  }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _default = "/* secret */";
8
+ exports.default = _default;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ export default '/* secret */';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ foo: "export-7: FOO",
5
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ module.exports = {
14
+ foo: 'export-7: FOO',
15
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.foo = exports.default = void 0;
7
+ var _default = "export-8: DEFAULT";
8
+ exports.default = _default;
9
+ const foo = "export-8: FOO";
10
+ exports.foo = foo;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ export default 'export-8: DEFAULT';
14
+
15
+ export const foo = 'export-8: FOO';
@@ -3,7 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true,
5
5
  });
6
- exports.asyncImportESM = exports.asyncImportCJS = void 0;
6
+ exports.asyncImportMaybeSyncESM =
7
+ exports.asyncImportMaybeSyncCJS =
8
+ exports.asyncImportESM =
9
+ exports.asyncImportCJS =
10
+ void 0;
7
11
  Object.defineProperty(exports, "default", {
8
12
  enumerable: true,
9
13
  get: function () {
@@ -82,3 +86,7 @@ const asyncImportCJS = import("./export-5");
82
86
  exports.asyncImportCJS = asyncImportCJS;
83
87
  const asyncImportESM = import("./export-6");
84
88
  exports.asyncImportESM = asyncImportESM;
89
+ const asyncImportMaybeSyncCJS = require.unstable_importMaybeSync("./export-7");
90
+ exports.asyncImportMaybeSyncCJS = asyncImportMaybeSyncCJS;
91
+ const asyncImportMaybeSyncESM = require.unstable_importMaybeSync("./export-8");
92
+ exports.asyncImportMaybeSyncESM = asyncImportMaybeSyncESM;
@@ -10,6 +10,8 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {RequireWithUnstableImportMaybeSync} from './utils';
14
+
13
15
  import {default as myDefault, foo as myFoo, myFunction} from './export-1';
14
16
  import * as importStar from './export-2';
15
17
  import {foo} from './export-null';
@@ -17,6 +19,8 @@ import primitiveDefault, {
17
19
  foo as primitiveFoo,
18
20
  } from './export-primitive-default';
19
21
 
22
+ declare var require: RequireWithUnstableImportMaybeSync;
23
+
20
24
  export {default as namedDefaultExported} from './export-3';
21
25
  export {foo as default} from './export-4';
22
26
 
@@ -32,3 +36,8 @@ export const extraData = {
32
36
 
33
37
  export const asyncImportCJS = import('./export-5');
34
38
  export const asyncImportESM = import('./export-6');
39
+
40
+ export const asyncImportMaybeSyncCJS: mixed =
41
+ require.unstable_importMaybeSync('./export-7');
42
+ export const asyncImportMaybeSyncESM: mixed =
43
+ require.unstable_importMaybeSync('./export-8');
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ export type RequireWithUnstableImportMaybeSync = {
12
+ (id: string | number): mixed,
13
+ unstable_importMaybeSync: (id: string) => mixed,
14
+ };
@@ -14,6 +14,7 @@ module.exports = {
14
14
  port: 10028,
15
15
  },
16
16
  resolver: {
17
+ blockList: [/excluded_from_file_map\.js$/],
17
18
  useWatchman: false,
18
19
  },
19
20
  transformer: {