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
@@ -13,7 +13,7 @@ class Module {
13
13
  this._moduleCache = moduleCache;
14
14
  }
15
15
  getPackage() {
16
- return this._moduleCache.getPackageForModule(this);
16
+ return this._moduleCache.getPackageForModule(this)?.pkg;
17
17
  }
18
18
  invalidate() {}
19
19
  }
@@ -32,7 +32,7 @@ class Module {
32
32
  }
33
33
 
34
34
  getPackage(): ?Package {
35
- return this._moduleCache.getPackageForModule(this);
35
+ return this._moduleCache.getPackageForModule(this)?.pkg;
36
36
  }
37
37
 
38
38
  invalidate() {}
@@ -7,7 +7,7 @@ class ModuleCache {
7
7
  this._getClosestPackage = options.getClosestPackage;
8
8
  this._moduleCache = Object.create(null);
9
9
  this._packageCache = Object.create(null);
10
- this._packagePathByModulePath = Object.create(null);
10
+ this._packagePathAndSubpathByModulePath = Object.create(null);
11
11
  this._modulePathsByPackagePath = Object.create(null);
12
12
  }
13
13
  getModule(filePath) {
@@ -27,21 +27,33 @@ class ModuleCache {
27
27
  getPackageForModule(module) {
28
28
  return this.getPackageOf(module.path);
29
29
  }
30
- getPackageOf(modulePath) {
31
- let packagePath = this._packagePathByModulePath[modulePath];
32
- if (packagePath && this._packageCache[packagePath]) {
33
- return this._packageCache[packagePath];
30
+ getPackageOf(absoluteModulePath) {
31
+ let packagePathAndSubpath =
32
+ this._packagePathAndSubpathByModulePath[absoluteModulePath];
33
+ if (
34
+ packagePathAndSubpath &&
35
+ this._packageCache[packagePathAndSubpath.packageJsonPath]
36
+ ) {
37
+ return {
38
+ pkg: this._packageCache[packagePathAndSubpath.packageJsonPath],
39
+ packageRelativePath: packagePathAndSubpath.packageRelativePath,
40
+ };
34
41
  }
35
- packagePath = this._getClosestPackage(modulePath);
36
- if (!packagePath) {
42
+ packagePathAndSubpath = this._getClosestPackage(absoluteModulePath);
43
+ if (!packagePathAndSubpath) {
37
44
  return null;
38
45
  }
39
- this._packagePathByModulePath[modulePath] = packagePath;
46
+ const packagePath = packagePathAndSubpath.packageJsonPath;
47
+ this._packagePathAndSubpathByModulePath[absoluteModulePath] =
48
+ packagePathAndSubpath;
40
49
  const modulePaths =
41
50
  this._modulePathsByPackagePath[packagePath] ?? new Set();
42
- modulePaths.add(modulePath);
51
+ modulePaths.add(absoluteModulePath);
43
52
  this._modulePathsByPackagePath[packagePath] = modulePaths;
44
- return this.getPackage(packagePath);
53
+ return {
54
+ pkg: this.getPackage(packagePath),
55
+ packageRelativePath: packagePathAndSubpath.packageRelativePath,
56
+ };
45
57
  }
46
58
  invalidate(filePath) {
47
59
  if (this._moduleCache[filePath]) {
@@ -52,9 +64,11 @@ class ModuleCache {
52
64
  this._packageCache[filePath].invalidate();
53
65
  delete this._packageCache[filePath];
54
66
  }
55
- if (this._packagePathByModulePath[filePath]) {
56
- const packagePath = this._packagePathByModulePath[filePath];
57
- delete this._packagePathByModulePath[filePath];
67
+ const packagePathAndSubpath =
68
+ this._packagePathAndSubpathByModulePath[filePath];
69
+ if (packagePathAndSubpath) {
70
+ const packagePath = packagePathAndSubpath.packageJsonPath;
71
+ delete this._packagePathAndSubpathByModulePath[filePath];
58
72
  const modulePaths = this._modulePathsByPackagePath[packagePath];
59
73
  if (modulePaths) {
60
74
  modulePaths.delete(filePath);
@@ -66,7 +80,7 @@ class ModuleCache {
66
80
  if (this._modulePathsByPackagePath[filePath]) {
67
81
  const modulePaths = this._modulePathsByPackagePath[filePath];
68
82
  for (const modulePath of modulePaths) {
69
- delete this._packagePathByModulePath[modulePath];
83
+ delete this._packagePathAndSubpathByModulePath[modulePath];
70
84
  }
71
85
  modulePaths.clear();
72
86
  delete this._modulePathsByPackagePath[filePath];
@@ -14,7 +14,10 @@
14
14
  const Module = require('./Module');
15
15
  const Package = require('./Package');
16
16
 
17
- type GetClosestPackageFn = (filePath: string) => ?string;
17
+ type GetClosestPackageFn = (absoluteFilePath: string) => ?{
18
+ packageJsonPath: string,
19
+ packageRelativePath: string,
20
+ };
18
21
 
19
22
  class ModuleCache {
20
23
  _getClosestPackage: GetClosestPackageFn;
@@ -29,8 +32,11 @@ class ModuleCache {
29
32
  ...
30
33
  };
31
34
  // Cache for "closest package.json" queries by module path.
32
- _packagePathByModulePath: {
33
- [filePath: string]: string,
35
+ _packagePathAndSubpathByModulePath: {
36
+ [filePath: string]: ?{
37
+ packageJsonPath: string,
38
+ packageRelativePath: string,
39
+ },
34
40
  __proto__: null,
35
41
  ...
36
42
  };
@@ -45,7 +51,7 @@ class ModuleCache {
45
51
  this._getClosestPackage = options.getClosestPackage;
46
52
  this._moduleCache = Object.create(null);
47
53
  this._packageCache = Object.create(null);
48
- this._packagePathByModulePath = Object.create(null);
54
+ this._packagePathAndSubpathByModulePath = Object.create(null);
49
55
  this._modulePathsByPackagePath = Object.create(null);
50
56
  }
51
57
 
@@ -65,28 +71,45 @@ class ModuleCache {
65
71
  return this._packageCache[filePath];
66
72
  }
67
73
 
68
- getPackageForModule(module: Module): ?Package {
74
+ getPackageForModule(
75
+ module: Module,
76
+ ): ?{pkg: Package, packageRelativePath: string} {
69
77
  return this.getPackageOf(module.path);
70
78
  }
71
79
 
72
- getPackageOf(modulePath: string): ?Package {
73
- let packagePath: ?string = this._packagePathByModulePath[modulePath];
74
- if (packagePath && this._packageCache[packagePath]) {
75
- return this._packageCache[packagePath];
80
+ getPackageOf(
81
+ absoluteModulePath: string,
82
+ ): ?{pkg: Package, packageRelativePath: string} {
83
+ let packagePathAndSubpath =
84
+ this._packagePathAndSubpathByModulePath[absoluteModulePath];
85
+ if (
86
+ packagePathAndSubpath &&
87
+ this._packageCache[packagePathAndSubpath.packageJsonPath]
88
+ ) {
89
+ return {
90
+ pkg: this._packageCache[packagePathAndSubpath.packageJsonPath],
91
+ packageRelativePath: packagePathAndSubpath.packageRelativePath,
92
+ };
76
93
  }
77
94
 
78
- packagePath = this._getClosestPackage(modulePath);
79
- if (!packagePath) {
95
+ packagePathAndSubpath = this._getClosestPackage(absoluteModulePath);
96
+ if (!packagePathAndSubpath) {
80
97
  return null;
81
98
  }
82
99
 
83
- this._packagePathByModulePath[modulePath] = packagePath;
100
+ const packagePath = packagePathAndSubpath.packageJsonPath;
101
+
102
+ this._packagePathAndSubpathByModulePath[absoluteModulePath] =
103
+ packagePathAndSubpath;
84
104
  const modulePaths =
85
105
  this._modulePathsByPackagePath[packagePath] ?? new Set();
86
- modulePaths.add(modulePath);
106
+ modulePaths.add(absoluteModulePath);
87
107
  this._modulePathsByPackagePath[packagePath] = modulePaths;
88
108
 
89
- return this.getPackage(packagePath);
109
+ return {
110
+ pkg: this.getPackage(packagePath),
111
+ packageRelativePath: packagePathAndSubpath.packageRelativePath,
112
+ };
90
113
  }
91
114
 
92
115
  invalidate(filePath: string) {
@@ -98,10 +121,12 @@ class ModuleCache {
98
121
  this._packageCache[filePath].invalidate();
99
122
  delete this._packageCache[filePath];
100
123
  }
101
- if (this._packagePathByModulePath[filePath]) {
124
+ const packagePathAndSubpath =
125
+ this._packagePathAndSubpathByModulePath[filePath];
126
+ if (packagePathAndSubpath) {
102
127
  // filePath is a module inside a package.
103
- const packagePath = this._packagePathByModulePath[filePath];
104
- delete this._packagePathByModulePath[filePath];
128
+ const packagePath = packagePathAndSubpath.packageJsonPath;
129
+ delete this._packagePathAndSubpathByModulePath[filePath];
105
130
  // This change doesn't invalidate any cached "closest package.json"
106
131
  // queries for the package's other modules. Clean up only this module.
107
132
  const modulePaths = this._modulePathsByPackagePath[packagePath];
@@ -117,7 +142,7 @@ class ModuleCache {
117
142
  // package.json" queries for modules inside this package.
118
143
  const modulePaths = this._modulePathsByPackagePath[filePath];
119
144
  for (const modulePath of modulePaths) {
120
- delete this._packagePathByModulePath[modulePath];
145
+ delete this._packagePathAndSubpathByModulePath[modulePath];
121
146
  }
122
147
  modulePaths.clear();
123
148
  delete this._modulePathsByPackagePath[filePath];
@@ -41,7 +41,7 @@ function tryParse(filePath, platforms) {
41
41
  function parse(filePath, platforms) {
42
42
  const result = tryParse(filePath, platforms);
43
43
  if (result == null) {
44
- throw new Error("invalid asset file path: `${filePath}");
44
+ throw new Error(`invalid asset file path: ${filePath}`);
45
45
  }
46
46
  return result;
47
47
  }
@@ -69,7 +69,7 @@ function tryParse(
69
69
  function parse(filePath: string, platforms: $ReadOnlySet<string>): AssetPath {
70
70
  const result = tryParse(filePath, platforms);
71
71
  if (result == null) {
72
- throw new Error('invalid asset file path: `${filePath}');
72
+ throw new Error(`invalid asset file path: ${filePath}`);
73
73
  }
74
74
  return result;
75
75
  }
@@ -24,7 +24,7 @@ async function saveBundleAndMap(bundle, options, log) {
24
24
  } = options;
25
25
  const writeFns = [];
26
26
  writeFns.push(async () => {
27
- log("Writing bundle output to:", bundleOutput);
27
+ log(`Writing bundle output to: ${bundleOutput}`);
28
28
  await writeFile(bundleOutput, bundle.code, encoding);
29
29
  log("Done writing bundle output");
30
30
  });
@@ -36,7 +36,7 @@ async function saveBundleAndMap(bundle, options, log) {
36
36
  log("finished relativating");
37
37
  }
38
38
  writeFns.push(async () => {
39
- log("Writing sourcemap output to:", sourcemapOutput);
39
+ log(`Writing sourcemap output to: ${sourcemapOutput}`);
40
40
  await writeFile(sourcemapOutput, map, null);
41
41
  log("Done writing sourcemap output");
42
42
  });
@@ -61,7 +61,7 @@ async function saveBundleAndMap(
61
61
  const writeFns = [];
62
62
 
63
63
  writeFns.push(async () => {
64
- log('Writing bundle output to:', bundleOutput);
64
+ log(`Writing bundle output to: ${bundleOutput}`);
65
65
  await writeFile(bundleOutput, bundle.code, encoding);
66
66
  log('Done writing bundle output');
67
67
  });
@@ -75,7 +75,7 @@ async function saveBundleAndMap(
75
75
  }
76
76
 
77
77
  writeFns.push(async () => {
78
- log('Writing sourcemap output to:', sourcemapOutput);
78
+ log(`Writing sourcemap output to: ${sourcemapOutput}`);
79
79
  await writeFile(sourcemapOutput, map, null);
80
80
  log('Done writing sourcemap output');
81
81
  });
@@ -1 +1,11 @@
1
1
  "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.SourcePathsMode = void 0;
7
+ const SourcePathsMode = require("flow-enums-runtime")({
8
+ Absolute: "absolute",
9
+ ServerUrl: "url-server",
10
+ });
11
+ exports.SourcePathsMode = SourcePathsMode;
@@ -41,6 +41,13 @@ type MetroSourceMapOrMappings =
41
41
  | MixedSourceMap
42
42
  | Array<MetroSourceMapSegmentTuple>;
43
43
 
44
+ export enum SourcePathsMode {
45
+ /* Use absolute paths for source files in source maps (default). */
46
+ Absolute = 'absolute',
47
+ /* Use server-relative URL paths for source files in source maps. */
48
+ ServerUrl = 'url-server',
49
+ }
50
+
44
51
  export type BundleOptions = {
45
52
  bundleType: BundleType,
46
53
  +customResolverOptions: CustomResolverOptions,
@@ -61,6 +68,7 @@ export type BundleOptions = {
61
68
  sourceUrl: ?string,
62
69
  createModuleIdFactory?: () => (path: string) => number,
63
70
  +unstable_transformProfile: TransformProfile,
71
+ +sourcePaths: SourcePathsMode,
64
72
  };
65
73
 
66
74
  export type ResolverInputOptions = $ReadOnly<{
@@ -75,6 +83,7 @@ export type SerializerOptions = {
75
83
  +excludeSource: boolean,
76
84
  +inlineSourceMap: boolean,
77
85
  +modulesOnly: boolean,
86
+ +sourcePaths: SourcePathsMode,
78
87
  };
79
88
 
80
89
  export type GraphOptions = {