metro 0.83.0 → 0.83.2

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 (208) hide show
  1. package/package.json +16 -16
  2. package/src/Assets.js +68 -42
  3. package/src/Assets.js.flow +13 -24
  4. package/src/Bundler/util.js +40 -17
  5. package/src/Bundler/util.js.flow +6 -13
  6. package/src/Bundler.js +17 -6
  7. package/src/Bundler.js.flow +3 -7
  8. package/src/DeltaBundler/DeltaCalculator.js +15 -15
  9. package/src/DeltaBundler/DeltaCalculator.js.flow +4 -7
  10. package/src/DeltaBundler/Graph.js +45 -40
  11. package/src/DeltaBundler/Graph.js.flow +3 -4
  12. package/src/DeltaBundler/Serializers/baseJSBundle.js +24 -10
  13. package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +6 -9
  14. package/src/DeltaBundler/Serializers/getAllFiles.js +9 -6
  15. package/src/DeltaBundler/Serializers/getAllFiles.js.flow +4 -8
  16. package/src/DeltaBundler/Serializers/getAssets.js +18 -11
  17. package/src/DeltaBundler/Serializers/getAssets.js.flow +5 -9
  18. package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +26 -0
  19. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +7 -6
  20. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +3 -9
  21. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +40 -23
  22. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +11 -18
  23. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +4 -1
  24. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -5
  25. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +7 -4
  26. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +3 -7
  27. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +4 -1
  28. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +2 -6
  29. package/src/DeltaBundler/Serializers/helpers/js.js +65 -31
  30. package/src/DeltaBundler/Serializers/helpers/js.js.flow +21 -21
  31. package/src/DeltaBundler/Serializers/helpers/processModules.js +8 -5
  32. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -7
  33. package/src/DeltaBundler/Serializers/hmrJSBundle.js +70 -25
  34. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +43 -33
  35. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +19 -16
  36. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -14
  37. package/src/DeltaBundler/Serializers/sourceMapObject.js +12 -10
  38. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -9
  39. package/src/DeltaBundler/Serializers/sourceMapString.js +14 -12
  40. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +4 -9
  41. package/src/DeltaBundler/Transformer.js +32 -27
  42. package/src/DeltaBundler/Transformer.js.flow +10 -17
  43. package/src/DeltaBundler/Worker.flow.js +25 -18
  44. package/src/DeltaBundler/Worker.flow.js.flow +12 -18
  45. package/src/DeltaBundler/Worker.js.flow +2 -0
  46. package/src/DeltaBundler/WorkerFarm.js +13 -11
  47. package/src/DeltaBundler/WorkerFarm.js.flow +7 -9
  48. package/src/DeltaBundler/buildSubgraph.js +13 -17
  49. package/src/DeltaBundler/buildSubgraph.js.flow +1 -1
  50. package/src/DeltaBundler/getTransformCacheKey.js +12 -6
  51. package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -7
  52. package/src/DeltaBundler/mergeDeltas.js +4 -1
  53. package/src/DeltaBundler/mergeDeltas.js.flow +5 -6
  54. package/src/DeltaBundler/types.d.ts +4 -1
  55. package/src/DeltaBundler/{types.flow.js → types.js} +1 -5
  56. package/src/DeltaBundler/{types.flow.js.flow → types.js.flow} +5 -3
  57. package/src/DeltaBundler.js +15 -6
  58. package/src/DeltaBundler.js.flow +4 -8
  59. package/src/HmrServer.js +116 -68
  60. package/src/HmrServer.js.flow +41 -52
  61. package/src/IncrementalBundler/GraphNotFoundError.js +5 -1
  62. package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -5
  63. package/src/IncrementalBundler/ResourceNotFoundError.js +5 -1
  64. package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -5
  65. package/src/IncrementalBundler/RevisionNotFoundError.js +5 -1
  66. package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -5
  67. package/src/IncrementalBundler.js +71 -35
  68. package/src/IncrementalBundler.js.flow +12 -16
  69. package/src/ModuleGraph/test-helpers.js +19 -14
  70. package/src/ModuleGraph/worker/JsFileWrapping.js +22 -29
  71. package/src/ModuleGraph/worker/JsFileWrapping.js.flow +1 -10
  72. package/src/ModuleGraph/worker/collectDependencies.js +81 -52
  73. package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -22
  74. package/src/ModuleGraph/worker/generateImportNames.js +12 -6
  75. package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -7
  76. package/src/ModuleGraph/worker/importLocationsPlugin.js +5 -4
  77. package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +2 -4
  78. package/src/Server/MultipartResponse.js +11 -4
  79. package/src/Server/MultipartResponse.js.flow +2 -5
  80. package/src/Server/symbolicate.d.ts +31 -0
  81. package/src/Server/symbolicate.js +15 -16
  82. package/src/Server/symbolicate.js.flow +6 -16
  83. package/src/Server.d.ts +0 -1
  84. package/src/Server.js +298 -191
  85. package/src/Server.js.flow +136 -99
  86. package/src/cli-utils.js +13 -4
  87. package/src/cli-utils.js.flow +3 -5
  88. package/src/cli.js.flow +2 -0
  89. package/src/commands/build.js +18 -15
  90. package/src/commands/build.js.flow +6 -6
  91. package/src/commands/dependencies.js +26 -16
  92. package/src/commands/dependencies.js.flow +7 -9
  93. package/src/commands/serve.js +16 -11
  94. package/src/commands/serve.js.flow +5 -6
  95. package/src/index.d.ts +26 -3
  96. package/src/index.flow.js +162 -72
  97. package/src/index.flow.js.flow +60 -47
  98. package/src/index.js.flow +2 -0
  99. package/src/integration_tests/basic_bundle/TestBundle.js.flow +2 -1
  100. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +1 -5
  101. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +1 -5
  102. package/src/integration_tests/basic_bundle/import-export/index.js +5 -13
  103. package/src/integration_tests/basic_bundle/require-context/mode-eager.js +2 -2
  104. package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +2 -2
  105. package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +2 -2
  106. package/src/integration_tests/basic_bundle/require-context/mode-sync.js +1 -1
  107. package/src/integration_tests/basic_bundle/require-context/utils.js +1 -1
  108. package/src/integration_tests/execBundle.js +7 -4
  109. package/src/integration_tests/execBundle.js.flow +1 -3
  110. package/src/integration_tests/metro.config.js +3 -3
  111. package/src/lib/BatchProcessor.js +15 -5
  112. package/src/lib/BatchProcessor.js.flow +2 -6
  113. package/src/lib/CountingSet.js.flow +2 -2
  114. package/src/lib/JsonReporter.js +6 -2
  115. package/src/lib/JsonReporter.js.flow +1 -5
  116. package/src/lib/RamBundleParser.js +12 -3
  117. package/src/lib/RamBundleParser.js.flow +2 -6
  118. package/src/lib/TerminalReporter.js +95 -56
  119. package/src/lib/TerminalReporter.js.flow +9 -12
  120. package/src/lib/bundleToString.js +4 -1
  121. package/src/lib/bundleToString.js.flow +2 -9
  122. package/src/lib/contextModule.js +3 -7
  123. package/src/lib/contextModuleTemplates.js +9 -19
  124. package/src/lib/countLines.js +5 -1
  125. package/src/lib/countLines.js.flow +1 -3
  126. package/src/lib/createWebsocketServer.js +7 -7
  127. package/src/lib/createWebsocketServer.js.flow +4 -4
  128. package/src/lib/debounceAsyncQueue.js +4 -1
  129. package/src/lib/debounceAsyncQueue.js.flow +1 -5
  130. package/src/lib/formatBundlingError.js +32 -22
  131. package/src/lib/formatBundlingError.js.flow +18 -20
  132. package/src/lib/getAppendScripts.js +20 -20
  133. package/src/lib/getAppendScripts.js.flow +9 -13
  134. package/src/lib/getGraphId.js +12 -6
  135. package/src/lib/getGraphId.js.flow +4 -10
  136. package/src/lib/getPreludeCode.js +7 -10
  137. package/src/lib/getPreludeCode.js.flow +2 -6
  138. package/src/lib/getPrependedScripts.js +40 -16
  139. package/src/lib/getPrependedScripts.js.flow +8 -13
  140. package/src/lib/isResolvedDependency.js.flow +1 -1
  141. package/src/lib/logToConsole.js +18 -12
  142. package/src/lib/logToConsole.js.flow +5 -14
  143. package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +144 -0
  144. package/src/lib/parseBundleOptionsFromBundleRequestUrl.js.flow +146 -0
  145. package/src/lib/parseCustomResolverOptions.js +8 -6
  146. package/src/lib/parseCustomResolverOptions.js.flow +6 -12
  147. package/src/lib/parseCustomTransformOptions.js +8 -6
  148. package/src/lib/parseCustomTransformOptions.js.flow +11 -14
  149. package/src/lib/parseJsonBody.js +4 -1
  150. package/src/lib/parseJsonBody.js.flow +1 -3
  151. package/src/lib/pathUtils.js +34 -0
  152. package/src/lib/pathUtils.js.flow +16 -0
  153. package/src/lib/relativizeSourceMap.js +12 -3
  154. package/src/lib/relativizeSourceMap.js.flow +2 -6
  155. package/src/lib/reporting.js +25 -19
  156. package/src/lib/reporting.js.flow +6 -16
  157. package/src/lib/splitBundleOptions.js +4 -2
  158. package/src/lib/splitBundleOptions.js.flow +4 -7
  159. package/src/lib/transformHelpers.js +19 -25
  160. package/src/lib/transformHelpers.js.flow +5 -15
  161. package/src/node-haste/DependencyGraph/ModuleResolution.js +75 -57
  162. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +28 -44
  163. package/src/node-haste/DependencyGraph/createFileMap.js +15 -13
  164. package/src/node-haste/DependencyGraph/createFileMap.js.flow +2 -5
  165. package/src/node-haste/DependencyGraph.js +61 -45
  166. package/src/node-haste/DependencyGraph.js.flow +34 -31
  167. package/src/node-haste/Package.js +13 -6
  168. package/src/node-haste/Package.js.flow +3 -7
  169. package/src/node-haste/{ModuleCache.js → PackageCache.js} +11 -19
  170. package/src/node-haste/{ModuleCache.js.flow → PackageCache.js.flow} +2 -30
  171. package/src/node-haste/lib/AssetPaths.js +14 -8
  172. package/src/node-haste/lib/AssetPaths.js.flow +7 -8
  173. package/src/node-haste/lib/parsePlatformFilePath.js +10 -4
  174. package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -6
  175. package/src/shared/output/RamBundle/as-assets.js +42 -22
  176. package/src/shared/output/RamBundle/as-assets.js.flow +12 -15
  177. package/src/shared/output/RamBundle/as-indexed-file.js +33 -23
  178. package/src/shared/output/RamBundle/as-indexed-file.js.flow +10 -16
  179. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +11 -10
  180. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -6
  181. package/src/shared/output/RamBundle/magic-number.js +5 -1
  182. package/src/shared/output/RamBundle/magic-number.js.flow +1 -3
  183. package/src/shared/output/RamBundle/util.js +21 -18
  184. package/src/shared/output/RamBundle/util.js.flow +4 -6
  185. package/src/shared/output/RamBundle/write-sourcemap.js +9 -3
  186. package/src/shared/output/RamBundle/write-sourcemap.js.flow +2 -6
  187. package/src/shared/output/RamBundle.js +16 -9
  188. package/src/shared/output/RamBundle.js.flow +8 -12
  189. package/src/shared/output/bundle.flow.js +37 -13
  190. package/src/shared/output/bundle.flow.js.flow +24 -12
  191. package/src/shared/output/bundle.js.flow +2 -0
  192. package/src/shared/output/meta.js +16 -9
  193. package/src/shared/output/meta.js.flow +3 -5
  194. package/src/shared/output/unbundle.js +14 -1
  195. package/src/shared/output/unbundle.js.flow +1 -3
  196. package/src/shared/output/writeFile.js +11 -4
  197. package/src/shared/output/writeFile.js.flow +3 -5
  198. package/src/shared/types.d.ts +0 -1
  199. package/src/shared/{types.flow.js.flow → types.js.flow} +16 -17
  200. package/src/lib/createModuleIdFactory.js +0 -15
  201. package/src/lib/createModuleIdFactory.js.flow +0 -27
  202. package/src/lib/getMaxWorkers.js +0 -9
  203. package/src/lib/getMaxWorkers.js.flow +0 -22
  204. package/src/lib/parseOptionsFromUrl.js +0 -62
  205. package/src/lib/parseOptionsFromUrl.js.flow +0 -97
  206. package/src/node-haste/Module.js +0 -24
  207. package/src/node-haste/Module.js.flow +0 -41
  208. /package/src/shared/{types.flow.js → types.js} +0 -0
@@ -12,8 +12,8 @@
12
12
  import type {
13
13
  BundlerResolution,
14
14
  TransformResultDependency,
15
- } from '../DeltaBundler/types.flow';
16
- import type {ResolverInputOptions} from '../shared/types.flow';
15
+ } from '../DeltaBundler/types';
16
+ import type {ResolverInputOptions} from '../shared/types';
17
17
  import type Package from './Package';
18
18
  import type {ConfigT} from 'metro-config';
19
19
  import type MetroFileMap, {
@@ -25,22 +25,23 @@ import type MetroFileMap, {
25
25
  } from 'metro-file-map';
26
26
  import type {FileSystemLookup} from 'metro-resolver';
27
27
 
28
- import {DuplicateHasteCandidatesError} from 'metro-file-map';
29
-
30
- const createFileMap = require('./DependencyGraph/createFileMap');
31
- const {ModuleResolver} = require('./DependencyGraph/ModuleResolution');
32
- const ModuleCache = require('./ModuleCache');
33
- const {EventEmitter} = require('events');
34
- const fs = require('fs');
35
- const {
28
+ import createFileMap from './DependencyGraph/createFileMap';
29
+ import {ModuleResolver} from './DependencyGraph/ModuleResolution';
30
+ import {PackageCache} from './PackageCache';
31
+ import EventEmitter from 'events';
32
+ import fs from 'fs';
33
+ import {
36
34
  AmbiguousModuleResolutionError,
37
- Logger: {createActionStartEntry, createActionEndEntry, log},
35
+ Logger,
38
36
  PackageResolutionError,
39
- } = require('metro-core');
40
- const canonicalize = require('metro-core/private/canonicalize');
41
- const {InvalidPackageError} = require('metro-resolver');
42
- const nullthrows = require('nullthrows');
43
- const path = require('path');
37
+ } from 'metro-core';
38
+ import canonicalize from 'metro-core/private/canonicalize';
39
+ import {DuplicateHasteCandidatesError} from 'metro-file-map';
40
+ import {InvalidPackageError} from 'metro-resolver';
41
+ import nullthrows from 'nullthrows';
42
+ import path from 'path';
43
+
44
+ const {createActionStartEntry, createActionEndEntry, log} = Logger;
44
45
 
45
46
  const NULL_PLATFORM = Symbol();
46
47
 
@@ -56,11 +57,11 @@ function getOrCreateMap<T>(
56
57
  return subMap;
57
58
  }
58
59
 
59
- class DependencyGraph extends EventEmitter {
60
+ export default class DependencyGraph extends EventEmitter {
60
61
  _config: ConfigT;
61
62
  _haste: MetroFileMap;
62
63
  _fileSystem: FileSystem;
63
- _moduleCache: ModuleCache;
64
+ #packageCache: PackageCache;
64
65
  _hasteMap: HasteMap;
65
66
  _moduleResolver: ModuleResolver<Package>;
66
67
  _resolutionCache: Map<
@@ -130,7 +131,7 @@ class DependencyGraph extends EventEmitter {
130
131
  this._onWatcherHealthCheck(result),
131
132
  );
132
133
  this._resolutionCache = new Map();
133
- this._moduleCache = this._createModuleCache();
134
+ this.#packageCache = this._createPackageCache();
134
135
  this._createModuleResolver();
135
136
  });
136
137
  }
@@ -162,7 +163,9 @@ class DependencyGraph extends EventEmitter {
162
163
 
163
164
  _onHasteChange({eventsQueue}: ChangeEvent) {
164
165
  this._resolutionCache = new Map();
165
- eventsQueue.forEach(({filePath}) => this._moduleCache.invalidate(filePath));
166
+ eventsQueue.forEach(({filePath}) =>
167
+ this.#packageCache.invalidate(filePath),
168
+ );
166
169
  this._createModuleResolver();
167
170
  this.emit('change');
168
171
  }
@@ -199,8 +202,8 @@ class DependencyGraph extends EventEmitter {
199
202
  getHastePackagePath: (name, platform) =>
200
203
  this._hasteMap.getPackage(name, platform, true),
201
204
  mainFields: this._config.resolver.resolverMainFields,
202
- moduleCache: this._moduleCache,
203
205
  nodeModulesPaths: this._config.resolver.nodeModulesPaths,
206
+ packageCache: this.#packageCache,
204
207
  preferNativePlatform: true,
205
208
  projectRoot: this._config.projectRoot,
206
209
  reporter: this._config.reporter,
@@ -247,8 +250,8 @@ class DependencyGraph extends EventEmitter {
247
250
  : null;
248
251
  }
249
252
 
250
- _createModuleCache(): ModuleCache {
251
- return new ModuleCache({
253
+ _createPackageCache(): PackageCache {
254
+ return new PackageCache({
252
255
  getClosestPackage: absolutePath => this._getClosestPackage(absolutePath),
253
256
  });
254
257
  }
@@ -304,7 +307,7 @@ class DependencyGraph extends EventEmitter {
304
307
  }
305
308
 
306
309
  resolveDependency(
307
- from: string,
310
+ originModulePath: string,
308
311
  dependency: TransformResultDependency,
309
312
  platform: string | null,
310
313
  resolverOptions: ResolverInputOptions,
@@ -323,12 +326,14 @@ class DependencyGraph extends EventEmitter {
323
326
  to === '.' ||
324
327
  to === '..' ||
325
328
  // Preserve standard assumptions under node_modules
326
- from.includes(path.sep + 'node_modules' + path.sep);
329
+ originModulePath.includes(path.sep + 'node_modules' + path.sep);
327
330
 
328
331
  // Compound key for the resolver cache
329
332
  const resolverOptionsKey =
330
333
  JSON.stringify(resolverOptions ?? {}, canonicalize) ?? '';
331
- const originKey = isSensitiveToOriginFolder ? path.dirname(from) : '';
334
+ const originKey = isSensitiveToOriginFolder
335
+ ? path.dirname(originModulePath)
336
+ : '';
332
337
  const targetKey =
333
338
  to + (dependency.data.isESMImport === true ? '\0esm' : '\0cjs');
334
339
  const platformKey = platform ?? NULL_PLATFORM;
@@ -346,7 +351,7 @@ class DependencyGraph extends EventEmitter {
346
351
  if (!resolution) {
347
352
  try {
348
353
  resolution = this._moduleResolver.resolveDependency(
349
- this._moduleCache.getModule(from),
354
+ originModulePath,
350
355
  dependency,
351
356
  true,
352
357
  platform,
@@ -354,12 +359,12 @@ class DependencyGraph extends EventEmitter {
354
359
  );
355
360
  } catch (error) {
356
361
  if (error instanceof DuplicateHasteCandidatesError) {
357
- throw new AmbiguousModuleResolutionError(from, error);
362
+ throw new AmbiguousModuleResolutionError(originModulePath, error);
358
363
  }
359
364
  if (error instanceof InvalidPackageError) {
360
365
  throw new PackageResolutionError({
361
366
  packageError: error,
362
- originModulePath: from,
367
+ originModulePath,
363
368
  targetModuleName: to,
364
369
  });
365
370
  }
@@ -389,5 +394,3 @@ class DependencyGraph extends EventEmitter {
389
394
  return nullthrows(this._fileSystem.getDependencies(filePath));
390
395
  }
391
396
  }
392
-
393
- module.exports = DependencyGraph;
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
2
 
3
- const fs = require("fs");
4
- const path = require("path");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ function _interopRequireDefault(e) {
10
+ return e && e.__esModule ? e : { default: e };
11
+ }
5
12
  class Package {
6
13
  constructor({ file }) {
7
- this.path = path.resolve(file);
8
- this._root = path.dirname(this.path);
14
+ this.path = _path.default.resolve(file);
15
+ this._root = _path.default.dirname(this.path);
9
16
  this._content = null;
10
17
  }
11
18
  invalidate() {
@@ -13,9 +20,9 @@ class Package {
13
20
  }
14
21
  read() {
15
22
  if (this._content == null) {
16
- this._content = JSON.parse(fs.readFileSync(this.path, "utf8"));
23
+ this._content = JSON.parse(_fs.default.readFileSync(this.path, "utf8"));
17
24
  }
18
25
  return this._content;
19
26
  }
20
27
  }
21
- module.exports = Package;
28
+ exports.default = Package;
@@ -9,14 +9,12 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {PackageJson} from 'metro-resolver/private/types';
15
13
 
16
- const fs = require('fs');
17
- const path = require('path');
14
+ import fs from 'fs';
15
+ import path from 'path';
18
16
 
19
- class Package {
17
+ export default class Package {
20
18
  path: string;
21
19
 
22
20
  _root: string;
@@ -39,5 +37,3 @@ class Package {
39
37
  return this._content;
40
38
  }
41
39
  }
42
-
43
- module.exports = Package;
@@ -1,32 +1,28 @@
1
1
  "use strict";
2
2
 
3
- const Module = require("./Module");
4
- const Package = require("./Package");
5
- class ModuleCache {
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.PackageCache = void 0;
7
+ var _Package = _interopRequireDefault(require("./Package"));
8
+ function _interopRequireDefault(e) {
9
+ return e && e.__esModule ? e : { default: e };
10
+ }
11
+ class PackageCache {
6
12
  constructor(options) {
7
13
  this._getClosestPackage = options.getClosestPackage;
8
- this._moduleCache = Object.create(null);
9
14
  this._packageCache = Object.create(null);
10
15
  this._packagePathAndSubpathByModulePath = Object.create(null);
11
16
  this._modulePathsByPackagePath = Object.create(null);
12
17
  }
13
- getModule(filePath) {
14
- if (!this._moduleCache[filePath]) {
15
- this._moduleCache[filePath] = new Module(filePath, this);
16
- }
17
- return this._moduleCache[filePath];
18
- }
19
18
  getPackage(filePath) {
20
19
  if (!this._packageCache[filePath]) {
21
- this._packageCache[filePath] = new Package({
20
+ this._packageCache[filePath] = new _Package.default({
22
21
  file: filePath,
23
22
  });
24
23
  }
25
24
  return this._packageCache[filePath];
26
25
  }
27
- getPackageForModule(module) {
28
- return this.getPackageOf(module.path);
29
- }
30
26
  getPackageOf(absoluteModulePath) {
31
27
  let packagePathAndSubpath =
32
28
  this._packagePathAndSubpathByModulePath[absoluteModulePath];
@@ -56,10 +52,6 @@ class ModuleCache {
56
52
  };
57
53
  }
58
54
  invalidate(filePath) {
59
- if (this._moduleCache[filePath]) {
60
- this._moduleCache[filePath].invalidate();
61
- delete this._moduleCache[filePath];
62
- }
63
55
  if (this._packageCache[filePath]) {
64
56
  this._packageCache[filePath].invalidate();
65
57
  delete this._packageCache[filePath];
@@ -87,4 +79,4 @@ class ModuleCache {
87
79
  }
88
80
  }
89
81
  }
90
- module.exports = ModuleCache;
82
+ exports.PackageCache = PackageCache;
@@ -9,23 +9,15 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- const Module = require('./Module');
15
- const Package = require('./Package');
12
+ import Package from './Package';
16
13
 
17
14
  type GetClosestPackageFn = (absoluteFilePath: string) => ?{
18
15
  packageJsonPath: string,
19
16
  packageRelativePath: string,
20
17
  };
21
18
 
22
- class ModuleCache {
19
+ export class PackageCache {
23
20
  _getClosestPackage: GetClosestPackageFn;
24
- _moduleCache: {
25
- [filePath: string]: Module,
26
- __proto__: null,
27
- ...
28
- };
29
21
  _packageCache: {
30
22
  [filePath: string]: Package,
31
23
  __proto__: null,
@@ -49,19 +41,11 @@ class ModuleCache {
49
41
 
50
42
  constructor(options: {getClosestPackage: GetClosestPackageFn, ...}) {
51
43
  this._getClosestPackage = options.getClosestPackage;
52
- this._moduleCache = Object.create(null);
53
44
  this._packageCache = Object.create(null);
54
45
  this._packagePathAndSubpathByModulePath = Object.create(null);
55
46
  this._modulePathsByPackagePath = Object.create(null);
56
47
  }
57
48
 
58
- getModule(filePath: string): Module {
59
- if (!this._moduleCache[filePath]) {
60
- this._moduleCache[filePath] = new Module(filePath, this);
61
- }
62
- return this._moduleCache[filePath];
63
- }
64
-
65
49
  getPackage(filePath: string): Package {
66
50
  if (!this._packageCache[filePath]) {
67
51
  this._packageCache[filePath] = new Package({
@@ -71,12 +55,6 @@ class ModuleCache {
71
55
  return this._packageCache[filePath];
72
56
  }
73
57
 
74
- getPackageForModule(
75
- module: Module,
76
- ): ?{pkg: Package, packageRelativePath: string} {
77
- return this.getPackageOf(module.path);
78
- }
79
-
80
58
  getPackageOf(
81
59
  absoluteModulePath: string,
82
60
  ): ?{pkg: Package, packageRelativePath: string} {
@@ -113,10 +91,6 @@ class ModuleCache {
113
91
  }
114
92
 
115
93
  invalidate(filePath: string) {
116
- if (this._moduleCache[filePath]) {
117
- this._moduleCache[filePath].invalidate();
118
- delete this._moduleCache[filePath];
119
- }
120
94
  if (this._packageCache[filePath]) {
121
95
  this._packageCache[filePath].invalidate();
122
96
  delete this._packageCache[filePath];
@@ -149,5 +123,3 @@ class ModuleCache {
149
123
  }
150
124
  }
151
125
  }
152
-
153
- module.exports = ModuleCache;
@@ -1,7 +1,17 @@
1
1
  "use strict";
2
2
 
3
- const parsePlatformFilePath = require("./parsePlatformFilePath");
4
- const path = require("path");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.parse = parse;
7
+ exports.tryParse = tryParse;
8
+ var _parsePlatformFilePath = _interopRequireDefault(
9
+ require("./parsePlatformFilePath"),
10
+ );
11
+ var _path = _interopRequireDefault(require("path"));
12
+ function _interopRequireDefault(e) {
13
+ return e && e.__esModule ? e : { default: e };
14
+ }
5
15
  const ASSET_BASE_NAME_RE = /(.+?)(@([\d.]+)x)?$/;
6
16
  function parseBaseName(baseName) {
7
17
  const match = baseName.match(ASSET_BASE_NAME_RE);
@@ -24,14 +34,14 @@ function parseBaseName(baseName) {
24
34
  };
25
35
  }
26
36
  function tryParse(filePath, platforms) {
27
- const result = parsePlatformFilePath(filePath, platforms);
37
+ const result = (0, _parsePlatformFilePath.default)(filePath, platforms);
28
38
  const { dirPath, baseName, platform, extension } = result;
29
39
  if (extension == null) {
30
40
  return null;
31
41
  }
32
42
  const { rootName, resolution } = parseBaseName(baseName);
33
43
  return {
34
- assetName: path.join(dirPath, `${rootName}.${extension}`),
44
+ assetName: _path.default.join(dirPath, `${rootName}.${extension}`),
35
45
  name: rootName,
36
46
  platform,
37
47
  resolution,
@@ -45,7 +55,3 @@ function parse(filePath, platforms) {
45
55
  }
46
56
  return result;
47
57
  }
48
- module.exports = {
49
- parse,
50
- tryParse,
51
- };
@@ -9,10 +9,8 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- const parsePlatformFilePath = require('./parsePlatformFilePath');
15
- const path = require('path');
12
+ import parsePlatformFilePath from './parsePlatformFilePath';
13
+ import path from 'path';
16
14
 
17
15
  export type AssetPath = {
18
16
  assetName: string,
@@ -47,7 +45,7 @@ function parseBaseName(baseName: string): {
47
45
  * Return `null` if the `filePath` doesn't have a valid extension, required
48
46
  * to describe the type of an asset.
49
47
  */
50
- function tryParse(
48
+ export function tryParse(
51
49
  filePath: string,
52
50
  platforms: $ReadOnlySet<string>,
53
51
  ): ?AssetPath {
@@ -66,12 +64,13 @@ function tryParse(
66
64
  };
67
65
  }
68
66
 
69
- function parse(filePath: string, platforms: $ReadOnlySet<string>): AssetPath {
67
+ export function parse(
68
+ filePath: string,
69
+ platforms: $ReadOnlySet<string>,
70
+ ): AssetPath {
70
71
  const result = tryParse(filePath, platforms);
71
72
  if (result == null) {
72
73
  throw new Error(`invalid asset file path: ${filePath}`);
73
74
  }
74
75
  return result;
75
76
  }
76
-
77
- module.exports = {parse, tryParse};
@@ -1,10 +1,17 @@
1
1
  "use strict";
2
2
 
3
- const path = require("path");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = parsePlatformFilePath;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ function _interopRequireDefault(e) {
9
+ return e && e.__esModule ? e : { default: e };
10
+ }
4
11
  const PATH_RE = /^(.+?)(\.([^.]+))?\.([^.]+)$/;
5
12
  function parsePlatformFilePath(filePath, platforms) {
6
- const dirPath = path.dirname(filePath);
7
- const fileName = path.basename(filePath);
13
+ const dirPath = _path.default.dirname(filePath);
14
+ const fileName = _path.default.basename(filePath);
8
15
  const match = fileName.match(PATH_RE);
9
16
  if (!match) {
10
17
  return {
@@ -32,4 +39,3 @@ function parsePlatformFilePath(filePath, platforms) {
32
39
  extension,
33
40
  };
34
41
  }
35
- module.exports = parsePlatformFilePath;
@@ -9,9 +9,7 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- const path = require('path');
12
+ import path from 'path';
15
13
 
16
14
  type PlatformFilePathParts = {
17
15
  dirPath: string,
@@ -26,7 +24,7 @@ const PATH_RE = /^(.+?)(\.([^.]+))?\.([^.]+)$/;
26
24
  * Extract the components of a file path that can have a platform specifier: Ex.
27
25
  * `index.ios.js` is specific to the `ios` platform and has the extension `js`.
28
26
  */
29
- function parsePlatformFilePath(
27
+ export default function parsePlatformFilePath(
30
28
  filePath: string,
31
29
  platforms: $ReadOnlySet<string>,
32
30
  ): PlatformFilePathParts {
@@ -44,5 +42,3 @@ function parsePlatformFilePath(
44
42
  const baseName = `${match[1]}.${platform}`;
45
43
  return {dirPath, baseName, platform: null, extension};
46
44
  }
47
-
48
- module.exports = parsePlatformFilePath;
@@ -1,13 +1,24 @@
1
1
  "use strict";
2
2
 
3
- const relativizeSourceMapInline = require("../../../lib/relativizeSourceMap");
4
- const writeFile = require("../writeFile");
5
- const buildSourcemapWithMetadata = require("./buildSourcemapWithMetadata");
6
- const MAGIC_RAM_BUNDLE_NUMBER = require("./magic-number");
7
- const { joinModules } = require("./util");
8
- const writeSourceMap = require("./write-sourcemap");
9
- const fsPromises = require("fs").promises;
10
- const path = require("path");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = saveAsAssets;
7
+ var _relativizeSourceMap = _interopRequireDefault(
8
+ require("../../../lib/relativizeSourceMap"),
9
+ );
10
+ var _writeFile = _interopRequireDefault(require("../writeFile"));
11
+ var _buildSourcemapWithMetadata = _interopRequireDefault(
12
+ require("./buildSourcemapWithMetadata"),
13
+ );
14
+ var _magicNumber = _interopRequireDefault(require("./magic-number"));
15
+ var _util = require("./util");
16
+ var _writeSourcemap = _interopRequireDefault(require("./write-sourcemap"));
17
+ var _fs = require("fs");
18
+ var _path = _interopRequireDefault(require("path"));
19
+ function _interopRequireDefault(e) {
20
+ return e && e.__esModule ? e : { default: e };
21
+ }
11
22
  const MAGIC_RAM_BUNDLE_FILENAME = "UNBUNDLE";
12
23
  const MODULES_DIR = "js-modules";
13
24
  function saveAsAssets(bundle, options, log) {
@@ -20,31 +31,34 @@ function saveAsAssets(bundle, options, log) {
20
31
  log("start");
21
32
  const { startupModules, lazyModules } = bundle;
22
33
  log("finish");
23
- const startupCode = joinModules(startupModules);
34
+ const startupCode = (0, _util.joinModules)(startupModules);
24
35
  log("Writing bundle output to:", bundleOutput);
25
- const modulesDir = path.join(path.dirname(bundleOutput), MODULES_DIR);
36
+ const modulesDir = _path.default.join(
37
+ _path.default.dirname(bundleOutput),
38
+ MODULES_DIR,
39
+ );
26
40
  const writeUnbundle = createDir(modulesDir).then(() =>
27
41
  Promise.all([
28
42
  writeModules(lazyModules, modulesDir, encoding),
29
- writeFile(bundleOutput, startupCode, encoding),
43
+ (0, _writeFile.default)(bundleOutput, startupCode, encoding),
30
44
  writeMagicFlagFile(modulesDir),
31
- ])
45
+ ]),
32
46
  );
33
47
  writeUnbundle.then(() => log("Done writing unbundle output"));
34
48
  if (sourcemapOutput) {
35
- const sourceMap = buildSourcemapWithMetadata({
49
+ const sourceMap = (0, _buildSourcemapWithMetadata.default)({
36
50
  fixWrapperOffset: true,
37
51
  lazyModules: lazyModules.concat(),
38
52
  moduleGroups: null,
39
53
  startupModules: startupModules.concat(),
40
54
  });
41
55
  if (sourcemapSourcesRoot != null) {
42
- relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
56
+ (0, _relativizeSourceMap.default)(sourceMap, sourcemapSourcesRoot);
43
57
  }
44
- const wroteSourceMap = writeSourceMap(
58
+ const wroteSourceMap = (0, _writeSourcemap.default)(
45
59
  sourcemapOutput,
46
60
  JSON.stringify(sourceMap),
47
- log
61
+ log,
48
62
  );
49
63
  return Promise.all([writeUnbundle, wroteSourceMap]);
50
64
  } else {
@@ -52,23 +66,29 @@ function saveAsAssets(bundle, options, log) {
52
66
  }
53
67
  }
54
68
  function createDir(dirName) {
55
- return fsPromises.mkdir(dirName, {
69
+ return _fs.promises.mkdir(dirName, {
56
70
  recursive: true,
57
71
  });
58
72
  }
59
73
  function writeModuleFile(module, modulesDir, encoding) {
60
74
  const { code, id } = module;
61
- return writeFile(path.join(modulesDir, id + ".js"), code, encoding);
75
+ return (0, _writeFile.default)(
76
+ _path.default.join(modulesDir, id + ".js"),
77
+ code,
78
+ encoding,
79
+ );
62
80
  }
63
81
  function writeModules(modules, modulesDir, encoding) {
64
82
  const writeFiles = modules.map((module) =>
65
- writeModuleFile(module, modulesDir, encoding)
83
+ writeModuleFile(module, modulesDir, encoding),
66
84
  );
67
85
  return Promise.all(writeFiles);
68
86
  }
69
87
  function writeMagicFlagFile(outputDir) {
70
88
  const buffer = Buffer.alloc(4);
71
- buffer.writeUInt32LE(MAGIC_RAM_BUNDLE_NUMBER, 0);
72
- return writeFile(path.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME), buffer);
89
+ buffer.writeUInt32LE(_magicNumber.default, 0);
90
+ return (0, _writeFile.default)(
91
+ _path.default.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME),
92
+ buffer,
93
+ );
73
94
  }
74
- module.exports = saveAsAssets;
@@ -9,20 +9,19 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
15
- import type {ModuleTransportLike} from '../../../shared/types.flow';
16
- import type {OutputOptions} from '../../types.flow';
13
+ import type {ModuleTransportLike} from '../../../shared/types';
14
+ import type {OutputOptions} from '../../types';
15
+
16
+ import relativizeSourceMapInline from '../../../lib/relativizeSourceMap';
17
+ import writeFile from '../writeFile';
18
+ import buildSourcemapWithMetadata from './buildSourcemapWithMetadata';
19
+ import MAGIC_RAM_BUNDLE_NUMBER from './magic-number';
20
+ import {joinModules} from './util';
21
+ import writeSourceMap from './write-sourcemap';
22
+ import {promises as fsPromises} from 'fs';
23
+ import path from 'path';
17
24
 
18
- const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
19
- const writeFile = require('../writeFile');
20
- const buildSourcemapWithMetadata = require('./buildSourcemapWithMetadata');
21
- const MAGIC_RAM_BUNDLE_NUMBER = require('./magic-number');
22
- const {joinModules} = require('./util');
23
- const writeSourceMap = require('./write-sourcemap');
24
- const fsPromises = require('fs').promises;
25
- const path = require('path');
26
25
  // must not start with a dot, as that won't go into the apk
27
26
  const MAGIC_RAM_BUNDLE_FILENAME = 'UNBUNDLE';
28
27
  const MODULES_DIR = 'js-modules';
@@ -34,7 +33,7 @@ const MODULES_DIR = 'js-modules';
34
33
  * All other modules go into a 'js-modules' folder that in the same parent
35
34
  * directory as the startup file.
36
35
  */
37
- function saveAsAssets(
36
+ export default function saveAsAssets(
38
37
  bundle: RamBundleInfo,
39
38
  options: OutputOptions,
40
39
  log: (...args: Array<string>) => void,
@@ -123,5 +122,3 @@ function writeMagicFlagFile(outputDir: string): Promise<mixed> {
123
122
  buffer.writeUInt32LE(MAGIC_RAM_BUNDLE_NUMBER, 0);
124
123
  return writeFile(path.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME), buffer);
125
124
  }
126
-
127
- module.exports = saveAsAssets;