metro 0.70.2 → 0.71.1

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 (79) hide show
  1. package/package.json +22 -21
  2. package/src/Assets.js.flow +4 -4
  3. package/src/Bundler/util.js +1 -1
  4. package/src/Bundler/util.js.flow +2 -2
  5. package/src/Bundler.js +17 -10
  6. package/src/Bundler.js.flow +19 -14
  7. package/src/DeltaBundler/DeltaCalculator.js +13 -17
  8. package/src/DeltaBundler/DeltaCalculator.js.flow +15 -20
  9. package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
  10. package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
  11. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +4 -4
  12. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +6 -6
  13. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +4 -4
  14. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +2 -2
  15. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +2 -2
  16. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +2 -2
  17. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
  18. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -4
  19. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
  20. package/src/DeltaBundler/Worker.flow.js +78 -0
  21. package/src/DeltaBundler/Worker.flow.js.flow +121 -0
  22. package/src/DeltaBundler/Worker.js +8 -66
  23. package/src/DeltaBundler/Worker.js.flow +8 -107
  24. package/src/DeltaBundler/WorkerFarm.js.flow +4 -4
  25. package/src/DeltaBundler/__fixtures__/hasteImpl.js +4 -0
  26. package/src/DeltaBundler/getTransformCacheKey.js.flow +2 -2
  27. package/src/DeltaBundler/graphOperations.js +634 -0
  28. package/src/DeltaBundler/graphOperations.js.flow +749 -0
  29. package/src/DeltaBundler/types.flow.js.flow +36 -30
  30. package/src/DeltaBundler.js +14 -6
  31. package/src/DeltaBundler.js.flow +14 -10
  32. package/src/HmrServer.js.flow +6 -6
  33. package/src/IncrementalBundler.js +1 -1
  34. package/src/IncrementalBundler.js.flow +8 -8
  35. package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
  36. package/src/ModuleGraph/node-haste/ModuleCache.js.flow +1 -1
  37. package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +2 -2
  38. package/src/ModuleGraph/node-haste/node-haste.js +4 -4
  39. package/src/ModuleGraph/node-haste/node-haste.js.flow +13 -7
  40. package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +2 -2
  41. package/src/ModuleGraph/output/plain-bundle.js.flow +2 -2
  42. package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +8 -8
  43. package/src/ModuleGraph/output/util.js.flow +2 -2
  44. package/src/ModuleGraph/types.flow.js.flow +37 -37
  45. package/src/ModuleGraph/worker/collectDependencies.js.flow +2 -2
  46. package/src/Server/symbolicate.js.flow +1 -1
  47. package/src/Server.js.flow +18 -18
  48. package/src/cli.js +5 -0
  49. package/src/cli.js.flow +5 -0
  50. package/src/commands/build.js +4 -3
  51. package/src/commands/build.js.flow +5 -3
  52. package/src/commands/serve.js +3 -3
  53. package/src/commands/serve.js.flow +5 -3
  54. package/src/index.flow.js +392 -0
  55. package/src/index.flow.js.flow +480 -0
  56. package/src/index.js +8 -366
  57. package/src/index.js.flow +8 -456
  58. package/src/lib/bundleToBytecode.js.flow +2 -2
  59. package/src/lib/bundleToString.js.flow +2 -2
  60. package/src/lib/getPreludeCode.js.flow +2 -2
  61. package/src/lib/transformHelpers.js.flow +2 -2
  62. package/src/node-haste/DependencyGraph/ModuleResolution.js +17 -4
  63. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +20 -12
  64. package/src/node-haste/DependencyGraph/createHasteMap.js +79 -19
  65. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +15 -14
  66. package/src/node-haste/DependencyGraph.js +31 -27
  67. package/src/node-haste/DependencyGraph.js.flow +43 -37
  68. package/src/node-haste/ModuleCache.js.flow +1 -1
  69. package/src/node-haste/lib/AssetPaths.js.flow +2 -2
  70. package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -2
  71. package/src/shared/output/RamBundle/as-indexed-file.js.flow +1 -1
  72. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +2 -2
  73. package/src/shared/types.flow.js.flow +14 -14
  74. package/src/DeltaBundler/computeDelta.js +0 -42
  75. package/src/DeltaBundler/computeDelta.js.flow +0 -47
  76. package/src/DeltaBundler/traverseDependencies.js +0 -470
  77. package/src/DeltaBundler/traverseDependencies.js.flow +0 -565
  78. package/src/node-haste/DependencyGraph/types.js +0 -10
  79. package/src/node-haste/DependencyGraph/types.js.flow +0 -88
@@ -1,9 +1,47 @@
1
1
  "use strict";
2
2
 
3
- var _jestHasteMap = _interopRequireDefault(require("jest-haste-map"));
3
+ var _metroFileMap = _interopRequireWildcard(require("metro-file-map"));
4
4
 
5
- function _interopRequireDefault(obj) {
6
- return obj && obj.__esModule ? obj : { default: obj };
5
+ function _getRequireWildcardCache(nodeInterop) {
6
+ if (typeof WeakMap !== "function") return null;
7
+ var cacheBabelInterop = new WeakMap();
8
+ var cacheNodeInterop = new WeakMap();
9
+ return (_getRequireWildcardCache = function (nodeInterop) {
10
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
11
+ })(nodeInterop);
12
+ }
13
+
14
+ function _interopRequireWildcard(obj, nodeInterop) {
15
+ if (!nodeInterop && obj && obj.__esModule) {
16
+ return obj;
17
+ }
18
+ if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) {
19
+ return { default: obj };
20
+ }
21
+ var cache = _getRequireWildcardCache(nodeInterop);
22
+ if (cache && cache.has(obj)) {
23
+ return cache.get(obj);
24
+ }
25
+ var newObj = {};
26
+ var hasPropertyDescriptor =
27
+ Object.defineProperty && Object.getOwnPropertyDescriptor;
28
+ for (var key in obj) {
29
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
30
+ var desc = hasPropertyDescriptor
31
+ ? Object.getOwnPropertyDescriptor(obj, key)
32
+ : null;
33
+ if (desc && (desc.get || desc.set)) {
34
+ Object.defineProperty(newObj, key, desc);
35
+ } else {
36
+ newObj[key] = obj[key];
37
+ }
38
+ }
39
+ }
40
+ newObj.default = obj;
41
+ if (cache) {
42
+ cache.set(obj, newObj);
43
+ }
44
+ return newObj;
7
45
  }
8
46
 
9
47
  /**
@@ -15,13 +53,10 @@ function _interopRequireDefault(obj) {
15
53
  *
16
54
  * @format
17
55
  */
18
- // $FlowFixMe: Types for `jest-haste-map`
19
56
  const ci = require("ci-info");
20
57
 
21
58
  const path = require("path");
22
59
 
23
- const JEST_HASTE_MAP_CACHE_BREAKER = 5;
24
-
25
60
  function getIgnorePattern(config) {
26
61
  // For now we support both options
27
62
  const { blockList, blacklistRE } = config.resolver;
@@ -46,7 +81,10 @@ function getIgnorePattern(config) {
46
81
  }
47
82
 
48
83
  function createHasteMap(config, options) {
49
- var _options$name, _options$throwOnModul;
84
+ var _config$unstable_file,
85
+ _config$unstable_perf,
86
+ _config$unstable_perf2,
87
+ _options$throwOnModul;
50
88
 
51
89
  const dependencyExtractor =
52
90
  (options === null || options === void 0
@@ -55,25 +93,48 @@ function createHasteMap(config, options) {
55
93
  ? null
56
94
  : config.resolver.dependencyExtractor;
57
95
  const computeDependencies = dependencyExtractor != null;
58
- const hasteConfig = {
59
- cacheDirectory: config.hasteMapCacheDirectory,
96
+ return _metroFileMap.default.create({
97
+ cacheManagerFactory:
98
+ (_config$unstable_file =
99
+ config === null || config === void 0
100
+ ? void 0
101
+ : config.unstable_fileMapCacheManagerFactory) !== null &&
102
+ _config$unstable_file !== void 0
103
+ ? _config$unstable_file
104
+ : (buildParameters) => {
105
+ var _config$fileMapCacheD;
106
+
107
+ return new _metroFileMap.DiskCacheManager({
108
+ buildParameters,
109
+ cacheDirectory:
110
+ (_config$fileMapCacheD = config.fileMapCacheDirectory) !==
111
+ null && _config$fileMapCacheD !== void 0
112
+ ? _config$fileMapCacheD
113
+ : config.hasteMapCacheDirectory,
114
+ cacheFilePrefix:
115
+ options === null || options === void 0
116
+ ? void 0
117
+ : options.cacheFilePrefix,
118
+ });
119
+ },
120
+ perfLogger:
121
+ (_config$unstable_perf =
122
+ (_config$unstable_perf2 = config.unstable_perfLogger) === null ||
123
+ _config$unstable_perf2 === void 0
124
+ ? void 0
125
+ : _config$unstable_perf2.subSpan("hasteMap")) !== null &&
126
+ _config$unstable_perf !== void 0
127
+ ? _config$unstable_perf
128
+ : null,
60
129
  computeDependencies,
61
130
  computeSha1: true,
62
131
  dependencyExtractor: config.resolver.dependencyExtractor,
63
132
  extensions: config.resolver.sourceExts.concat(config.resolver.assetExts),
64
133
  forceNodeFilesystemAPI: !config.resolver.useWatchman,
65
134
  hasteImplModulePath: config.resolver.hasteImplModulePath,
66
- hasteMapModulePath: config.resolver.unstable_hasteMapModulePath,
67
135
  ignorePattern: getIgnorePattern(config),
68
136
  maxWorkers: config.maxWorkers,
69
137
  mocksPattern: "",
70
- name: `${
71
- (_options$name =
72
- options === null || options === void 0 ? void 0 : options.name) !==
73
- null && _options$name !== void 0
74
- ? _options$name
75
- : "metro"
76
- }-${JEST_HASTE_MAP_CACHE_BREAKER}`,
77
138
  platforms: config.resolver.platforms,
78
139
  retainAllFiles: true,
79
140
  resetCache: config.resetCache,
@@ -92,8 +153,7 @@ function createHasteMap(config, options) {
92
153
  (options === null || options === void 0 ? void 0 : options.watch) == null
93
154
  ? !ci.isCI
94
155
  : options.watch,
95
- };
96
- return _jestHasteMap.default.create(hasteConfig);
156
+ });
97
157
  }
98
158
 
99
159
  module.exports = createHasteMap;
@@ -8,17 +8,13 @@
8
8
  * @format
9
9
  */
10
10
 
11
- import type {HasteConfig, HasteMap} from './types';
12
11
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
13
12
 
14
- // $FlowFixMe: Types for `jest-haste-map`
15
- import JestHasteMap from 'jest-haste-map';
13
+ import MetroFileMap, {DiskCacheManager} from 'metro-file-map';
16
14
 
17
15
  const ci = require('ci-info');
18
16
  const path = require('path');
19
17
 
20
- const JEST_HASTE_MAP_CACHE_BREAKER = 5;
21
-
22
18
  function getIgnorePattern(config: ConfigT): RegExp {
23
19
  // For now we support both options
24
20
  const {blockList, blacklistRE} = config.resolver;
@@ -50,28 +46,35 @@ function createHasteMap(
50
46
  extractDependencies?: boolean,
51
47
  watch?: boolean,
52
48
  throwOnModuleCollision?: boolean,
53
- name?: string,
49
+ cacheFilePrefix?: string,
54
50
  }>,
55
- ): HasteMap {
51
+ ): MetroFileMap {
56
52
  const dependencyExtractor =
57
53
  options?.extractDependencies === false
58
54
  ? null
59
55
  : config.resolver.dependencyExtractor;
60
56
  const computeDependencies = dependencyExtractor != null;
61
57
 
62
- const hasteConfig: HasteConfig = {
63
- cacheDirectory: config.hasteMapCacheDirectory,
58
+ return MetroFileMap.create({
59
+ cacheManagerFactory:
60
+ config?.unstable_fileMapCacheManagerFactory ??
61
+ (buildParameters =>
62
+ new DiskCacheManager({
63
+ buildParameters,
64
+ cacheDirectory:
65
+ config.fileMapCacheDirectory ?? config.hasteMapCacheDirectory,
66
+ cacheFilePrefix: options?.cacheFilePrefix,
67
+ })),
68
+ perfLogger: config.unstable_perfLogger?.subSpan('hasteMap') ?? null,
64
69
  computeDependencies,
65
70
  computeSha1: true,
66
71
  dependencyExtractor: config.resolver.dependencyExtractor,
67
72
  extensions: config.resolver.sourceExts.concat(config.resolver.assetExts),
68
73
  forceNodeFilesystemAPI: !config.resolver.useWatchman,
69
74
  hasteImplModulePath: config.resolver.hasteImplModulePath,
70
- hasteMapModulePath: config.resolver.unstable_hasteMapModulePath,
71
75
  ignorePattern: getIgnorePattern(config),
72
76
  maxWorkers: config.maxWorkers,
73
77
  mocksPattern: '',
74
- name: `${options?.name ?? 'metro'}-${JEST_HASTE_MAP_CACHE_BREAKER}`,
75
78
  platforms: config.resolver.platforms,
76
79
  retainAllFiles: true,
77
80
  resetCache: config.resetCache,
@@ -80,9 +83,7 @@ function createHasteMap(
80
83
  throwOnModuleCollision: options?.throwOnModuleCollision ?? true,
81
84
  useWatchman: config.resolver.useWatchman,
82
85
  watch: options?.watch == null ? !ci.isCI : options.watch,
83
- };
84
-
85
- return JestHasteMap.create(hasteConfig);
86
+ });
86
87
  }
87
88
 
88
89
  module.exports = createHasteMap;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _jestHasteMap = require("jest-haste-map");
3
+ var _metroFileMap = require("metro-file-map");
4
4
 
5
5
  /**
6
6
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -35,7 +35,7 @@ const nullthrows = require("nullthrows");
35
35
 
36
36
  const path = require("path");
37
37
 
38
- const { DuplicateHasteCandidatesError } = _jestHasteMap.ModuleMap;
38
+ const { DuplicateHasteCandidatesError } = _metroFileMap.ModuleMap;
39
39
 
40
40
  function getOrCreate(map, field) {
41
41
  let subMap = map.get(field);
@@ -49,25 +49,12 @@ function getOrCreate(map, field) {
49
49
  }
50
50
 
51
51
  class DependencyGraph extends EventEmitter {
52
- constructor({ config, haste, initialHasteFS, initialModuleMap }) {
52
+ constructor(config, options) {
53
53
  super();
54
54
  this._config = config;
55
- this._haste = haste;
56
- this._hasteFS = initialHasteFS;
57
- this._moduleMap = initialModuleMap;
58
55
  this._assetExtensions = new Set(
59
56
  config.resolver.assetExts.map((asset) => "." + asset)
60
- ); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
61
-
62
- this._haste.on("change", this._onHasteChange.bind(this));
63
-
64
- this._resolutionCache = new Map();
65
- this._moduleCache = this._createModuleCache();
66
-
67
- this._createModuleResolver();
68
- }
69
-
70
- static async load(config, options) {
57
+ );
71
58
  const { hasReducedPerformance, watch } =
72
59
  options !== null && options !== void 0 ? options : {};
73
60
  const initializingMetroLogEntry = log(
@@ -83,17 +70,34 @@ class DependencyGraph extends EventEmitter {
83
70
  // Bump this up to silence the max listeners EventEmitter warning.
84
71
 
85
72
  haste.setMaxListeners(1000);
86
- const { hasteFS, moduleMap } = await haste.build();
87
- log(createActionEndEntry(initializingMetroLogEntry));
88
- config.reporter.update({
89
- type: "dep_graph_loaded",
90
- });
91
- return new DependencyGraph({
92
- haste,
93
- initialHasteFS: hasteFS,
94
- initialModuleMap: moduleMap,
95
- config,
73
+ this._haste = haste;
74
+ this._readyPromise = haste.build().then(({ hasteFS, moduleMap }) => {
75
+ log(createActionEndEntry(initializingMetroLogEntry));
76
+ config.reporter.update({
77
+ type: "dep_graph_loaded",
78
+ });
79
+ this._hasteFS = hasteFS;
80
+ this._moduleMap = moduleMap; // $FlowFixMe[method-unbinding] added when improving typing for this parameters
81
+
82
+ this._haste.on("change", this._onHasteChange.bind(this));
83
+
84
+ this._resolutionCache = new Map();
85
+ this._moduleCache = this._createModuleCache();
86
+
87
+ this._createModuleResolver();
96
88
  });
89
+ } // Waits for the dependency graph to become ready after initialisation.
90
+ // Don't read anything from the graph until this resolves.
91
+
92
+ async ready() {
93
+ await this._readyPromise;
94
+ } // Creates the dependency graph and waits for it to become ready.
95
+ // @deprecated Use the constructor + ready() directly.
96
+
97
+ static async load(config, options) {
98
+ const self = new DependencyGraph(config, options);
99
+ await self.ready();
100
+ return self;
97
101
  }
98
102
 
99
103
  _getClosestPackage(filePath) {
@@ -8,11 +8,11 @@
8
8
  * @format
9
9
  */
10
10
 
11
- import type {HasteFS, HasteMap, ModuleMap} from './DependencyGraph/types';
12
11
  import type Package from './Package';
13
12
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
13
+ import type MetroFileMap, {HasteFS} from 'metro-file-map';
14
14
 
15
- import {ModuleMap as JestHasteModuleMap} from 'jest-haste-map';
15
+ import {ModuleMap as MetroFileMapModuleMap} from 'metro-file-map';
16
16
 
17
17
  const createHasteMap = require('./DependencyGraph/createHasteMap');
18
18
  const {ModuleResolver} = require('./DependencyGraph/ModuleResolution');
@@ -29,7 +29,7 @@ const {InvalidPackageError} = require('metro-resolver');
29
29
  const nullthrows = require('nullthrows');
30
30
  const path = require('path');
31
31
 
32
- const {DuplicateHasteCandidatesError} = JestHasteModuleMap;
32
+ const {DuplicateHasteCandidatesError} = MetroFileMapModuleMap;
33
33
 
34
34
  function getOrCreate<T>(
35
35
  map: Map<string, Map<string, T>>,
@@ -46,43 +46,28 @@ function getOrCreate<T>(
46
46
  class DependencyGraph extends EventEmitter {
47
47
  _assetExtensions: Set<string>;
48
48
  _config: ConfigT;
49
- _haste: HasteMap;
49
+ _haste: MetroFileMap;
50
50
  _hasteFS: HasteFS;
51
51
  _moduleCache: ModuleCache;
52
- _moduleMap: ModuleMap;
52
+ _moduleMap: MetroFileMapModuleMap;
53
53
  _moduleResolver: ModuleResolver<Module, Package>;
54
54
  _resolutionCache: Map<string, Map<string, Map<string, string>>>;
55
+ _readyPromise: Promise<void>;
55
56
 
56
- constructor({
57
- config,
58
- haste,
59
- initialHasteFS,
60
- initialModuleMap,
61
- }: {|
62
- +config: ConfigT,
63
- +haste: HasteMap,
64
- +initialHasteFS: HasteFS,
65
- +initialModuleMap: ModuleMap,
66
- |}) {
57
+ constructor(
58
+ config: ConfigT,
59
+ options?: {
60
+ +hasReducedPerformance?: boolean,
61
+ +watch?: boolean,
62
+ },
63
+ ) {
67
64
  super();
65
+
68
66
  this._config = config;
69
- this._haste = haste;
70
- this._hasteFS = initialHasteFS;
71
- this._moduleMap = initialModuleMap;
72
67
  this._assetExtensions = new Set(
73
68
  config.resolver.assetExts.map(asset => '.' + asset),
74
69
  );
75
- // $FlowFixMe[method-unbinding] added when improving typing for this parameters
76
- this._haste.on('change', this._onHasteChange.bind(this));
77
- this._resolutionCache = new Map();
78
- this._moduleCache = this._createModuleCache();
79
- this._createModuleResolver();
80
- }
81
70
 
82
- static async load(
83
- config: ConfigT,
84
- options?: {|+hasReducedPerformance?: boolean, +watch?: boolean|},
85
- ): Promise<DependencyGraph> {
86
71
  const {hasReducedPerformance, watch} = options ?? {};
87
72
  const initializingMetroLogEntry = log(
88
73
  createActionStartEntry('Initializing Metro'),
@@ -98,19 +83,40 @@ class DependencyGraph extends EventEmitter {
98
83
  // Bump this up to silence the max listeners EventEmitter warning.
99
84
  haste.setMaxListeners(1000);
100
85
 
101
- const {hasteFS, moduleMap} = await haste.build();
86
+ this._haste = haste;
87
+
88
+ this._readyPromise = haste.build().then(({hasteFS, moduleMap}) => {
89
+ log(createActionEndEntry(initializingMetroLogEntry));
90
+ config.reporter.update({type: 'dep_graph_loaded'});
102
91
 
103
- log(createActionEndEntry(initializingMetroLogEntry));
104
- config.reporter.update({type: 'dep_graph_loaded'});
92
+ this._hasteFS = hasteFS;
93
+ this._moduleMap = moduleMap;
105
94
 
106
- return new DependencyGraph({
107
- haste,
108
- initialHasteFS: hasteFS,
109
- initialModuleMap: moduleMap,
110
- config,
95
+ // $FlowFixMe[method-unbinding] added when improving typing for this parameters
96
+ this._haste.on('change', this._onHasteChange.bind(this));
97
+ this._resolutionCache = new Map();
98
+ this._moduleCache = this._createModuleCache();
99
+ this._createModuleResolver();
111
100
  });
112
101
  }
113
102
 
103
+ // Waits for the dependency graph to become ready after initialisation.
104
+ // Don't read anything from the graph until this resolves.
105
+ async ready(): Promise<void> {
106
+ await this._readyPromise;
107
+ }
108
+
109
+ // Creates the dependency graph and waits for it to become ready.
110
+ // @deprecated Use the constructor + ready() directly.
111
+ static async load(
112
+ config: ConfigT,
113
+ options?: {+hasReducedPerformance?: boolean, +watch?: boolean},
114
+ ): Promise<DependencyGraph> {
115
+ const self = new DependencyGraph(config, options);
116
+ await self.ready();
117
+ return self;
118
+ }
119
+
114
120
  _getClosestPackage(filePath: string): ?string {
115
121
  const parsedPath = path.parse(filePath);
116
122
  const root = parsedPath.root;
@@ -69,7 +69,7 @@ class ModuleCache {
69
69
  }
70
70
 
71
71
  getPackageOf(modulePath: string): ?Package {
72
- let packagePath = this._packagePathByModulePath[modulePath];
72
+ let packagePath: ?string = this._packagePathByModulePath[modulePath];
73
73
  if (packagePath && this._packageCache[packagePath]) {
74
74
  return this._packageCache[packagePath];
75
75
  }
@@ -13,13 +13,13 @@
13
13
  const parsePlatformFilePath = require('./parsePlatformFilePath');
14
14
  const path = require('path');
15
15
 
16
- export type AssetPath = {|
16
+ export type AssetPath = {
17
17
  assetName: string,
18
18
  name: string,
19
19
  platform: ?string,
20
20
  resolution: number,
21
21
  type: string,
22
- |};
22
+ };
23
23
 
24
24
  const ASSET_BASE_NAME_RE = /(.+?)(@([\d.]+)x)?$/;
25
25
 
@@ -12,12 +12,12 @@
12
12
 
13
13
  const path = require('path');
14
14
 
15
- type PlatformFilePathParts = {|
15
+ type PlatformFilePathParts = {
16
16
  dirPath: string,
17
17
  baseName: string,
18
18
  platform: ?string,
19
19
  extension: ?string,
20
- |};
20
+ };
21
21
 
22
22
  const PATH_RE = /^(.+?)(\.([^.]+))?\.([^.]+)$/;
23
23
 
@@ -109,7 +109,7 @@ function moduleToBuffer(
109
109
  id: number,
110
110
  code: string,
111
111
  encoding: void | 'ascii' | 'utf16le' | 'utf8',
112
- ): {|buffer: Buffer, id: number|} {
112
+ ): {buffer: Buffer, id: number} {
113
113
  return {
114
114
  id,
115
115
  buffer: nullTerminatedBuffer(code, encoding),
@@ -19,12 +19,12 @@ const {
19
19
  joinModules,
20
20
  } = require('./util');
21
21
 
22
- type Params = {|
22
+ type Params = {
23
23
  fixWrapperOffset: boolean,
24
24
  lazyModules: $ReadOnlyArray<ModuleTransportLike>,
25
25
  moduleGroups: ?ModuleGroups,
26
26
  startupModules: $ReadOnlyArray<ModuleTransportLike>,
27
- |};
27
+ };
28
28
 
29
29
  module.exports = (({
30
30
  fixWrapperOffset,
@@ -61,33 +61,33 @@ export type BundleOptions = {
61
61
  ...
62
62
  };
63
63
 
64
- export type SerializerOptions = {|
64
+ export type SerializerOptions = {
65
65
  +sourceMapUrl: ?string,
66
66
  +sourceUrl: ?string,
67
67
  +runModule: boolean,
68
68
  +excludeSource: boolean,
69
69
  +inlineSourceMap: boolean,
70
70
  +modulesOnly: boolean,
71
- |};
71
+ };
72
72
 
73
- export type GraphOptions = {|
73
+ export type GraphOptions = {
74
74
  +shallow: boolean,
75
- |};
75
+ };
76
76
 
77
77
  // Stricter representation of BundleOptions.
78
- export type SplitBundleOptions = {|
78
+ export type SplitBundleOptions = {
79
79
  +entryFile: string,
80
80
  +transformOptions: TransformInputOptions,
81
81
  +serializerOptions: SerializerOptions,
82
82
  +graphOptions: GraphOptions,
83
83
  +onProgress: $PropertyType<DeltaBundlerOptions<>, 'onProgress'>,
84
- |};
84
+ };
85
85
 
86
- export type ModuleGroups = {|
86
+ export type ModuleGroups = {
87
87
  groups: Map<number, Set<number>>,
88
88
  modulesById: Map<number, ModuleTransportLike>,
89
89
  modulesInGroups: Set<number>,
90
- |};
90
+ };
91
91
 
92
92
  export type ModuleTransportLike = {
93
93
  +code: string,
@@ -97,18 +97,18 @@ export type ModuleTransportLike = {
97
97
  +sourcePath: string,
98
98
  ...
99
99
  };
100
- export type ModuleTransportLikeStrict = {|
100
+ export type ModuleTransportLikeStrict = {
101
101
  +code: string,
102
102
  +id: number,
103
103
  +map: ?MetroSourceMapOrMappings,
104
104
  +name?: string,
105
105
  +sourcePath: string,
106
- |};
107
- export type RamModuleTransport = {|
106
+ };
107
+ export type RamModuleTransport = {
108
108
  ...ModuleTransportLikeStrict,
109
109
  +source: string,
110
110
  +type: string,
111
- |};
111
+ };
112
112
 
113
113
  export type OutputOptions = {
114
114
  bundleOutput: string,
@@ -122,7 +122,7 @@ export type OutputOptions = {
122
122
  ...
123
123
  };
124
124
 
125
- export type RequestOptions = {|
125
+ export type RequestOptions = {
126
126
  entryFile: string,
127
127
  inlineSourceMap?: boolean,
128
128
  sourceMapUrl?: string,
@@ -131,6 +131,6 @@ export type RequestOptions = {|
131
131
  platform: string,
132
132
  createModuleIdFactory?: () => (path: string) => number,
133
133
  onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
134
- |};
134
+ };
135
135
 
136
136
  export type {MinifierOptions};
@@ -1,42 +0,0 @@
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
- *
8
- * @format
9
- */
10
- "use strict";
11
-
12
- function computeDelta(entries1, entries2) {
13
- const modules1 = new Map(entries1);
14
- const modules2 = new Map(entries2);
15
- const added = new Map();
16
- const modified = new Map();
17
- const deleted = new Set();
18
-
19
- for (const [id, code] of modules1.entries()) {
20
- const newCode = modules2.get(id);
21
-
22
- if (newCode == null) {
23
- deleted.add(id);
24
- } else if (newCode !== code) {
25
- modified.set(id, newCode);
26
- }
27
- }
28
-
29
- for (const [id, code] of modules2.entries()) {
30
- if (!modules1.has(id)) {
31
- added.set(id, code);
32
- }
33
- }
34
-
35
- return {
36
- added: [...added.entries()],
37
- modified: [...modified.entries()],
38
- deleted: [...deleted],
39
- };
40
- }
41
-
42
- module.exports = computeDelta;
@@ -1,47 +0,0 @@
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
- 'use strict';
12
-
13
- import type {
14
- DeltaBundle,
15
- ModuleMap,
16
- } from 'metro-runtime/src/modules/types.flow';
17
-
18
- function computeDelta(entries1: ModuleMap, entries2: ModuleMap): DeltaBundle {
19
- const modules1 = new Map(entries1);
20
- const modules2 = new Map(entries2);
21
- const added = new Map();
22
- const modified = new Map();
23
- const deleted = new Set();
24
-
25
- for (const [id, code] of modules1.entries()) {
26
- const newCode = modules2.get(id);
27
- if (newCode == null) {
28
- deleted.add(id);
29
- } else if (newCode !== code) {
30
- modified.set(id, newCode);
31
- }
32
- }
33
-
34
- for (const [id, code] of modules2.entries()) {
35
- if (!modules1.has(id)) {
36
- added.set(id, code);
37
- }
38
- }
39
-
40
- return {
41
- added: [...added.entries()],
42
- modified: [...modified.entries()],
43
- deleted: [...deleted],
44
- };
45
- }
46
-
47
- module.exports = computeDelta;