metro 0.80.9 → 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 (60) 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 +1 -1
  13. package/src/DeltaBundler/Transformer.js.flow +4 -2
  14. package/src/DeltaBundler/types.flow.js.flow +2 -1
  15. package/src/ModuleGraph/worker/collectDependencies.js +54 -4
  16. package/src/ModuleGraph/worker/collectDependencies.js.flow +69 -4
  17. package/src/Server.js +113 -10
  18. package/src/Server.js.flow +130 -10
  19. package/src/cli/parseKeyValueParamArray.js +4 -5
  20. package/src/cli/parseKeyValueParamArray.js.flow +5 -3
  21. package/src/index.flow.js +7 -0
  22. package/src/index.flow.js.flow +8 -0
  23. package/src/integration_tests/basic_bundle/excluded_from_file_map.js +8 -0
  24. package/src/integration_tests/basic_bundle/excluded_from_file_map.js.flow +11 -0
  25. package/src/integration_tests/basic_bundle/import-export/export-7.js +5 -0
  26. package/src/integration_tests/basic_bundle/import-export/export-7.js.flow +15 -0
  27. package/src/integration_tests/basic_bundle/import-export/export-8.js +10 -0
  28. package/src/integration_tests/basic_bundle/import-export/export-8.js.flow +15 -0
  29. package/src/integration_tests/basic_bundle/import-export/index.js +9 -1
  30. package/src/integration_tests/basic_bundle/import-export/index.js.flow +9 -0
  31. package/src/integration_tests/basic_bundle/import-export/utils.js +1 -0
  32. package/src/integration_tests/basic_bundle/import-export/utils.js.flow +14 -0
  33. package/src/integration_tests/basic_bundle/not_a_source_file.xyz +1 -0
  34. package/src/integration_tests/metro.config.js +1 -0
  35. package/src/lib/BatchProcessor.js +3 -0
  36. package/src/lib/BatchProcessor.js.flow +4 -0
  37. package/src/lib/JsonReporter.js +30 -3
  38. package/src/lib/JsonReporter.js.flow +40 -7
  39. package/src/lib/TerminalReporter.js +4 -0
  40. package/src/lib/TerminalReporter.js.flow +12 -1
  41. package/src/lib/getAppendScripts.js +4 -1
  42. package/src/lib/getAppendScripts.js.flow +5 -1
  43. package/src/lib/parseOptionsFromUrl.js +4 -0
  44. package/src/lib/parseOptionsFromUrl.js.flow +4 -0
  45. package/src/lib/reporting.d.ts +6 -0
  46. package/src/lib/reporting.js.flow +6 -0
  47. package/src/lib/splitBundleOptions.js +1 -0
  48. package/src/lib/splitBundleOptions.js.flow +1 -0
  49. package/src/node-haste/DependencyGraph/ModuleResolution.js +10 -9
  50. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +16 -14
  51. package/src/node-haste/DependencyGraph.js +8 -4
  52. package/src/node-haste/DependencyGraph.js.flow +12 -4
  53. package/src/node-haste/Module.js +1 -1
  54. package/src/node-haste/Module.js.flow +1 -1
  55. package/src/node-haste/ModuleCache.js +28 -14
  56. package/src/node-haste/ModuleCache.js.flow +43 -18
  57. package/src/shared/output/bundle.flow.js +2 -2
  58. package/src/shared/output/bundle.flow.js.flow +2 -2
  59. package/src/shared/types.flow.js +10 -0
  60. package/src/shared/types.flow.js.flow +9 -0
@@ -5,7 +5,9 @@ function _interopRequireDefault(obj) {
5
5
  return obj && obj.__esModule ? obj : { default: obj };
6
6
  }
7
7
  const getInlineSourceMappingURL = require("../DeltaBundler/Serializers/helpers/getInlineSourceMappingURL");
8
- const sourceMapString = require("../DeltaBundler/Serializers/sourceMapString");
8
+ const {
9
+ sourceMapString,
10
+ } = require("../DeltaBundler/Serializers/sourceMapString");
9
11
  const countLines = require("./countLines");
10
12
  const nullthrows = require("nullthrows");
11
13
  function getAppendScripts(entryPoint, modules, options) {
@@ -43,6 +45,7 @@ function getAppendScripts(entryPoint, modules, options) {
43
45
  processModuleFilter: () => true,
44
46
  excludeSource: false,
45
47
  shouldAddToIgnoreList: options.shouldAddToIgnoreList,
48
+ getSourceUrl: options.getSourceUrl,
46
49
  })
47
50
  )
48
51
  : nullthrows(options.sourceMapUrl);
@@ -16,7 +16,9 @@ import type {Dependency} from '../DeltaBundler/types.flow';
16
16
  import CountingSet from './CountingSet';
17
17
 
18
18
  const getInlineSourceMappingURL = require('../DeltaBundler/Serializers/helpers/getInlineSourceMappingURL');
19
- const sourceMapString = require('../DeltaBundler/Serializers/sourceMapString');
19
+ const {
20
+ sourceMapString,
21
+ } = require('../DeltaBundler/Serializers/sourceMapString');
20
22
  const countLines = require('./countLines');
21
23
  const nullthrows = require('nullthrows');
22
24
 
@@ -30,6 +32,7 @@ type Options<T: number | string> = $ReadOnly<{
30
32
  shouldAddToIgnoreList: (Module<>) => boolean,
31
33
  sourceMapUrl: ?string,
32
34
  sourceUrl: ?string,
35
+ getSourceUrl: ?(Module<>) => string,
33
36
  ...
34
37
  }>;
35
38
 
@@ -75,6 +78,7 @@ function getAppendScripts<T: number | string>(
75
78
  processModuleFilter: (): boolean => true,
76
79
  excludeSource: false,
77
80
  shouldAddToIgnoreList: options.shouldAddToIgnoreList,
81
+ getSourceUrl: options.getSourceUrl,
78
82
  }),
79
83
  )
80
84
  : nullthrows(options.sourceMapUrl);
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _types = require("../shared/types.flow");
3
4
  const parsePlatformFilePath = require("../node-haste/lib/parsePlatformFilePath");
4
5
  const parseCustomResolverOptions = require("./parseCustomResolverOptions");
5
6
  const parseCustomTransformOptions = require("./parseCustomTransformOptions");
@@ -50,6 +51,9 @@ module.exports = function parseOptionsFromUrl(normalizedRequestUrl, platforms) {
50
51
  : "",
51
52
  pathname: pathname.replace(/\.(bundle|delta)$/, ".map"),
52
53
  }),
54
+ sourcePaths:
55
+ _types.SourcePathsMode.cast(query.sourcePaths) ??
56
+ _types.SourcePathsMode.Absolute,
53
57
  sourceUrl: jscSafeUrl.toJscSafeUrl(normalizedRequestUrl),
54
58
  unstable_transformProfile: getTransformProfile(
55
59
  query.unstable_transformProfile
@@ -14,6 +14,8 @@
14
14
  import type {BundleOptions} from '../shared/types.flow';
15
15
  import type {TransformProfile} from 'metro-babel-transformer';
16
16
 
17
+ import {SourcePathsMode} from '../shared/types.flow';
18
+
17
19
  const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath');
18
20
  const parseCustomResolverOptions = require('./parseCustomResolverOptions');
19
21
  const parseCustomTransformOptions = require('./parseCustomTransformOptions');
@@ -81,6 +83,8 @@ module.exports = function parseOptionsFromUrl(
81
83
  : '',
82
84
  pathname: pathname.replace(/\.(bundle|delta)$/, '.map'),
83
85
  }),
86
+ sourcePaths:
87
+ SourcePathsMode.cast(query.sourcePaths) ?? SourcePathsMode.Absolute,
84
88
  sourceUrl: jscSafeUrl.toJscSafeUrl(normalizedRequestUrl),
85
89
  unstable_transformProfile: getTransformProfile(
86
90
  query.unstable_transformProfile,
@@ -96,6 +96,12 @@ export type ReportableEvent =
96
96
  | 'debug';
97
97
  data: unknown[];
98
98
  }
99
+ | {
100
+ type: 'server_listening';
101
+ port: number;
102
+ address: string;
103
+ family: string;
104
+ }
99
105
  | {
100
106
  type: 'transformer_load_started';
101
107
  }
@@ -132,6 +132,12 @@ export type ReportableEvent =
132
132
  type: 'resolver_warning',
133
133
  message: string,
134
134
  }
135
+ | {
136
+ type: 'server_listening',
137
+ port: number,
138
+ address: string,
139
+ family: string,
140
+ }
135
141
  | {
136
142
  type: 'transformer_load_started',
137
143
  }
@@ -23,6 +23,7 @@ function splitBundleOptions(options) {
23
23
  runModule: options.runModule,
24
24
  sourceMapUrl: options.sourceMapUrl,
25
25
  sourceUrl: options.sourceUrl,
26
+ sourcePaths: options.sourcePaths,
26
27
  },
27
28
  graphOptions: {
28
29
  shallow: options.shallow,
@@ -39,6 +39,7 @@ function splitBundleOptions(options: BundleOptions): SplitBundleOptions {
39
39
  runModule: options.runModule,
40
40
  sourceMapUrl: options.sourceMapUrl,
41
41
  sourceUrl: options.sourceUrl,
42
+ sourcePaths: options.sourcePaths,
42
43
  },
43
44
  graphOptions: {
44
45
  shallow: options.shallow,
@@ -14,7 +14,7 @@ class ModuleResolver {
14
14
  this._projectRootFakeModule = {
15
15
  path: path.join(projectRoot, "_"),
16
16
  getPackage: () =>
17
- moduleCache.getPackageOf(this._projectRootFakeModule.path),
17
+ moduleCache.getPackageOf(this._projectRootFakeModule.path)?.pkg,
18
18
  isHaste() {
19
19
  throw new Error("not implemented");
20
20
  },
@@ -97,8 +97,8 @@ class ModuleResolver {
97
97
  resolveHastePackage: (name) =>
98
98
  this._options.getHastePackagePath(name, platform),
99
99
  getPackage: this._getPackage,
100
- getPackageForModule: (modulePath) =>
101
- this._getPackageForModule(fromModule, modulePath),
100
+ getPackageForModule: (absoluteModulePath) =>
101
+ this._getPackageForModule(absoluteModulePath),
102
102
  },
103
103
  dependency
104
104
  ),
@@ -159,15 +159,16 @@ class ModuleResolver {
159
159
  } catch (e) {}
160
160
  return null;
161
161
  };
162
- _getPackageForModule = (fromModule, modulePath) => {
163
- let pkg;
162
+ _getPackageForModule = (absolutePath) => {
163
+ let result;
164
164
  try {
165
- pkg = this._options.moduleCache.getPackageOf(modulePath);
165
+ result = this._options.moduleCache.getPackageOf(absolutePath);
166
166
  } catch (e) {}
167
- return pkg != null
167
+ return result != null
168
168
  ? {
169
- rootPath: path.dirname(pkg.path),
170
- packageJson: pkg.read(),
169
+ rootPath: path.dirname(result.pkg.path),
170
+ packageJson: result.pkg.read(),
171
+ packageRelativePath: result.packageRelativePath,
171
172
  }
172
173
  : null;
173
174
  };
@@ -25,7 +25,7 @@ import type {
25
25
  Resolution,
26
26
  ResolveAsset,
27
27
  } from 'metro-resolver';
28
- import type {PackageInfo, PackageJson} from 'metro-resolver/src/types';
28
+ import type {PackageForModule, PackageJson} from 'metro-resolver/src/types';
29
29
 
30
30
  const {codeFrameColumns} = require('@babel/code-frame');
31
31
  const fs = require('fs');
@@ -53,7 +53,10 @@ export type ModuleishCache<TPackage> = interface {
53
53
  platform?: string,
54
54
  supportsNativePlatform?: boolean,
55
55
  ): TPackage,
56
- getPackageOf(modulePath: string): ?TPackage,
56
+ getPackageOf(absolutePath: string): ?{
57
+ pkg: TPackage,
58
+ packageRelativePath: string,
59
+ },
57
60
  };
58
61
 
59
62
  type Options<TPackage> = $ReadOnly<{
@@ -95,7 +98,7 @@ class ModuleResolver<TPackage: Packageish> {
95
98
  this._projectRootFakeModule = {
96
99
  path: path.join(projectRoot, '_'),
97
100
  getPackage: () =>
98
- moduleCache.getPackageOf(this._projectRootFakeModule.path),
101
+ moduleCache.getPackageOf(this._projectRootFakeModule.path)?.pkg,
99
102
  isHaste() {
100
103
  throw new Error('not implemented');
101
104
  },
@@ -179,8 +182,8 @@ class ModuleResolver<TPackage: Packageish> {
179
182
  resolveHastePackage: (name: string) =>
180
183
  this._options.getHastePackagePath(name, platform),
181
184
  getPackage: this._getPackage,
182
- getPackageForModule: (modulePath: string) =>
183
- this._getPackageForModule(fromModule, modulePath),
185
+ getPackageForModule: (absoluteModulePath: string) =>
186
+ this._getPackageForModule(absoluteModulePath),
184
187
  },
185
188
  dependency,
186
189
  ),
@@ -249,23 +252,21 @@ class ModuleResolver<TPackage: Packageish> {
249
252
  return null;
250
253
  };
251
254
 
252
- _getPackageForModule = (
253
- fromModule: Moduleish,
254
- modulePath: string,
255
- ): ?PackageInfo => {
256
- let pkg;
255
+ _getPackageForModule = (absolutePath: string): ?PackageForModule => {
256
+ let result;
257
257
 
258
258
  try {
259
- pkg = this._options.moduleCache.getPackageOf(modulePath);
259
+ result = this._options.moduleCache.getPackageOf(absolutePath);
260
260
  } catch (e) {
261
261
  // Do nothing. The standard module cache does not trigger any error, but
262
262
  // the ModuleGraph one does, if the module does not exist.
263
263
  }
264
264
 
265
- return pkg != null
265
+ return result != null
266
266
  ? {
267
- rootPath: path.dirname(pkg.path),
268
- packageJson: pkg.read(),
267
+ rootPath: path.dirname(result.pkg.path),
268
+ packageJson: result.pkg.read(),
269
+ packageRelativePath: result.packageRelativePath,
269
270
  }
270
271
  : null;
271
272
  };
@@ -322,6 +323,7 @@ function getArrayLowestItem(a: $ReadOnlyArray<string>): string | void {
322
323
  return lowest;
323
324
  }
324
325
 
326
+ // $FlowFixMe[incompatible-extend]
325
327
  class UnableToResolveError extends Error {
326
328
  /**
327
329
  * File path of the module that tried to require a module, ex. `/js/foo.js`.
@@ -80,8 +80,8 @@ class DependencyGraph extends EventEmitter {
80
80
  await self.ready();
81
81
  return self;
82
82
  }
83
- _getClosestPackage(filePath) {
84
- const parsedPath = path.parse(filePath);
83
+ _getClosestPackage(absoluteModulePath) {
84
+ const parsedPath = path.parse(absoluteModulePath);
85
85
  const root = parsedPath.root;
86
86
  let dir = path.join(parsedPath.dir, parsedPath.base);
87
87
  do {
@@ -90,7 +90,10 @@ class DependencyGraph extends EventEmitter {
90
90
  }
91
91
  const candidate = path.join(dir, "package.json");
92
92
  if (this._fileSystem.exists(candidate)) {
93
- return candidate;
93
+ return {
94
+ packageJsonPath: candidate,
95
+ packageRelativePath: path.relative(dir, absoluteModulePath),
96
+ };
94
97
  }
95
98
  dir = path.dirname(dir);
96
99
  } while (dir !== "." && dir !== root);
@@ -163,7 +166,8 @@ class DependencyGraph extends EventEmitter {
163
166
  }
164
167
  _createModuleCache() {
165
168
  return new ModuleCache({
166
- getClosestPackage: (filePath) => this._getClosestPackage(filePath),
169
+ getClosestPackage: (absoluteModulePath) =>
170
+ this._getClosestPackage(absoluteModulePath),
167
171
  });
168
172
  }
169
173
  getAllFiles() {
@@ -152,8 +152,10 @@ class DependencyGraph extends EventEmitter {
152
152
  return self;
153
153
  }
154
154
 
155
- _getClosestPackage(filePath: string): ?string {
156
- const parsedPath = path.parse(filePath);
155
+ _getClosestPackage(
156
+ absoluteModulePath: string,
157
+ ): ?{packageJsonPath: string, packageRelativePath: string} {
158
+ const parsedPath = path.parse(absoluteModulePath);
157
159
  const root = parsedPath.root;
158
160
  let dir = path.join(parsedPath.dir, parsedPath.base);
159
161
 
@@ -165,7 +167,12 @@ class DependencyGraph extends EventEmitter {
165
167
  }
166
168
  const candidate = path.join(dir, 'package.json');
167
169
  if (this._fileSystem.exists(candidate)) {
168
- return candidate;
170
+ return {
171
+ packageJsonPath: candidate,
172
+ // Note that by construction, dir is a prefix of absoluteModulePath,
173
+ // so this relative path has no indirections.
174
+ packageRelativePath: path.relative(dir, absoluteModulePath),
175
+ };
169
176
  }
170
177
  dir = path.dirname(dir);
171
178
  } while (dir !== '.' && dir !== root);
@@ -242,7 +249,8 @@ class DependencyGraph extends EventEmitter {
242
249
 
243
250
  _createModuleCache(): ModuleCache {
244
251
  return new ModuleCache({
245
- getClosestPackage: filePath => this._getClosestPackage(filePath),
252
+ getClosestPackage: absoluteModulePath =>
253
+ this._getClosestPackage(absoluteModulePath),
246
254
  });
247
255
  }
248
256
 
@@ -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];
@@ -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 = {