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
@@ -1,18 +1,48 @@
1
1
  "use strict";
2
2
 
3
- const logToConsole = require("./logToConsole");
4
- const reporting = require("./reporting");
5
- const chalk = require("chalk");
6
- const throttle = require("lodash.throttle");
7
- const { AmbiguousModuleResolutionError } = require("metro-core");
8
- const path = require("path");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _logToConsole = _interopRequireDefault(require("./logToConsole"));
8
+ var reporting = _interopRequireWildcard(require("./reporting"));
9
+ var _chalk = _interopRequireDefault(require("chalk"));
10
+ var _lodash = _interopRequireDefault(require("lodash.throttle"));
11
+ var _metroCore = require("metro-core");
12
+ var _path = _interopRequireDefault(require("path"));
13
+ function _getRequireWildcardCache(e) {
14
+ if ("function" != typeof WeakMap) return null;
15
+ var r = new WeakMap(),
16
+ t = new WeakMap();
17
+ return (_getRequireWildcardCache = function (e) {
18
+ return e ? t : r;
19
+ })(e);
20
+ }
21
+ function _interopRequireWildcard(e, r) {
22
+ if (!r && e && e.__esModule) return e;
23
+ if (null === e || ("object" != typeof e && "function" != typeof e))
24
+ return { default: e };
25
+ var t = _getRequireWildcardCache(r);
26
+ if (t && t.has(e)) return t.get(e);
27
+ var n = { __proto__: null },
28
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
29
+ for (var u in e)
30
+ if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
31
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
32
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
33
+ }
34
+ return ((n.default = e), t && t.set(e, n), n);
35
+ }
36
+ function _interopRequireDefault(e) {
37
+ return e && e.__esModule ? e : { default: e };
38
+ }
9
39
  const DARK_BLOCK_CHAR = "\u2593";
10
40
  const LIGHT_BLOCK_CHAR = "\u2591";
11
41
  const MAX_PROGRESS_BAR_CHAR_WIDTH = 16;
12
42
  class TerminalReporter {
13
43
  constructor(terminal) {
14
44
  this._activeBundles = new Map();
15
- this._scheduleUpdateBundleProgress = throttle((data) => {
45
+ this._scheduleUpdateBundleProgress = (0, _lodash.default)((data) => {
16
46
  this.update({
17
47
  ...data,
18
48
  type: "bundle_transform_progressed_throttled",
@@ -28,32 +58,32 @@ class TerminalReporter {
28
58
  ratio,
29
59
  isPrefetch,
30
60
  },
31
- phase
61
+ phase,
32
62
  ) {
33
63
  if (isPrefetch) {
34
64
  bundleType = "PREBUNDLE";
35
65
  }
36
- const localPath = path.relative(".", entryFile);
66
+ const localPath = _path.default.relative(".", entryFile);
37
67
  const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
38
68
  const bundleTypeColor =
39
69
  phase === "done"
40
- ? chalk.green
70
+ ? _chalk.default.green
41
71
  : phase === "failed"
42
- ? chalk.red
43
- : chalk.yellow;
72
+ ? _chalk.default.red
73
+ : _chalk.default.yellow;
44
74
  const progress =
45
75
  phase === "in_progress"
46
- ? chalk.green.bgGreen(DARK_BLOCK_CHAR.repeat(filledBar)) +
47
- chalk.bgWhite.white(
48
- LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar)
76
+ ? _chalk.default.green.bgGreen(DARK_BLOCK_CHAR.repeat(filledBar)) +
77
+ _chalk.default.bgWhite.white(
78
+ LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
49
79
  ) +
50
- chalk.bold(` ${(100 * ratio).toFixed(1)}% `) +
51
- chalk.dim(`(${transformedFileCount}/${totalFileCount})`)
80
+ _chalk.default.bold(` ${(100 * ratio).toFixed(1)}% `) +
81
+ _chalk.default.dim(`(${transformedFileCount}/${totalFileCount})`)
52
82
  : "";
53
83
  return (
54
84
  bundleTypeColor.inverse.bold(` ${bundleType.toUpperCase()} `) +
55
- chalk.reset.dim(` ${path.dirname(localPath)}/`) +
56
- chalk.bold(path.basename(localPath)) +
85
+ _chalk.default.reset.dim(` ${_path.default.dirname(localPath)}/`) +
86
+ _chalk.default.bold(_path.default.basename(localPath)) +
57
87
  " " +
58
88
  progress
59
89
  );
@@ -67,7 +97,7 @@ class TerminalReporter {
67
97
  ratio: 1,
68
98
  transformedFileCount: progress.totalFileCount,
69
99
  },
70
- "done"
100
+ "done",
71
101
  );
72
102
  this.terminal.log(msg);
73
103
  this._activeBundles.delete(buildID);
@@ -98,30 +128,38 @@ class TerminalReporter {
98
128
  "",
99
129
  "",
100
130
  ];
101
- const color = hasReducedPerformance ? chalk.red : chalk.blue;
131
+ const color = hasReducedPerformance
132
+ ? _chalk.default.red
133
+ : _chalk.default.blue;
102
134
  this.terminal.log(color(logo.join("\n")));
103
135
  }
104
136
  _logInitializingFailed(port, error) {
105
137
  if (error.code === "EADDRINUSE") {
106
138
  this.terminal.log(
107
- chalk.bgRed.bold(" ERROR "),
108
- chalk.red("Metro can't listen on port", chalk.bold(String(port)))
139
+ _chalk.default.bgRed.bold(" ERROR "),
140
+ _chalk.default.red(
141
+ "Metro can't listen on port",
142
+ _chalk.default.bold(String(port)),
143
+ ),
109
144
  );
110
145
  this.terminal.log(
111
- "Most likely another process is already using this port"
146
+ "Most likely another process is already using this port",
112
147
  );
113
148
  this.terminal.log("Run the following command to find out which process:");
114
- this.terminal.log("\n ", chalk.bold("lsof -i :" + port), "\n");
149
+ this.terminal.log("\n ", _chalk.default.bold("lsof -i :" + port), "\n");
115
150
  this.terminal.log("Then, you can either shut down the other process:");
116
- this.terminal.log("\n ", chalk.bold("kill -9 <PID>"), "\n");
151
+ this.terminal.log("\n ", _chalk.default.bold("kill -9 <PID>"), "\n");
117
152
  this.terminal.log("or run Metro on different port.");
118
153
  } else {
119
- this.terminal.log(chalk.bgRed.bold(" ERROR "), chalk.red(error.message));
154
+ this.terminal.log(
155
+ _chalk.default.bgRed.bold(" ERROR "),
156
+ _chalk.default.red(error.message),
157
+ );
120
158
  const errorAttributes = JSON.stringify(error);
121
159
  if (errorAttributes !== "{}") {
122
- this.terminal.log(chalk.red(errorAttributes));
160
+ this.terminal.log(_chalk.default.red(errorAttributes));
123
161
  }
124
- this.terminal.log(chalk.red(error.stack));
162
+ this.terminal.log(_chalk.default.red(error.stack));
125
163
  }
126
164
  }
127
165
  _log(event) {
@@ -160,7 +198,7 @@ class TerminalReporter {
160
198
  this._logHmrClientError(event.error);
161
199
  break;
162
200
  case "client_log":
163
- logToConsole(this.terminal, event.level, event.mode, ...event.data);
201
+ (0, _logToConsole.default)(this.terminal, event.level, ...event.data);
164
202
  break;
165
203
  case "unstable_server_log":
166
204
  const logFn = {
@@ -172,20 +210,25 @@ class TerminalReporter {
172
210
  logFn(this.terminal, String(format), ...args);
173
211
  break;
174
212
  case "dep_graph_loading":
175
- const color = event.hasReducedPerformance ? chalk.red : chalk.blue;
213
+ const color = event.hasReducedPerformance
214
+ ? _chalk.default.red
215
+ : _chalk.default.blue;
176
216
  const version = "v" + require("../../package.json").version;
177
217
  this.terminal.log(
178
218
  color.bold(
179
219
  " ".repeat(19 - version.length / 2),
180
- "Welcome to Metro " + chalk.white(version) + "\n"
181
- ) + chalk.dim(" Fast - Scalable - Integrated\n\n")
220
+ "Welcome to Metro " + _chalk.default.white(version) + "\n",
221
+ ) +
222
+ _chalk.default.dim(
223
+ " Fast - Scalable - Integrated\n\n",
224
+ ),
182
225
  );
183
226
  if (event.hasReducedPerformance) {
184
227
  this.terminal.log(
185
- chalk.red(
228
+ _chalk.default.red(
186
229
  "Metro is operating with reduced performance.\n" +
187
- "Please fix the problem above and restart Metro.\n\n"
188
- )
230
+ "Please fix the problem above and restart Metro.\n\n",
231
+ ),
189
232
  );
190
233
  }
191
234
  break;
@@ -198,7 +241,7 @@ class TerminalReporter {
198
241
  }
199
242
  }
200
243
  _logBundlingError(error) {
201
- if (error instanceof AmbiguousModuleResolutionError) {
244
+ if (error instanceof _metroCore.AmbiguousModuleResolutionError) {
202
245
  const he = error.hasteError;
203
246
  const message =
204
247
  "ambiguous resolution: module `" +
@@ -243,9 +286,9 @@ class TerminalReporter {
243
286
  const ratio = Math.min(
244
287
  Math.max(
245
288
  Math.pow(transformedFileCount / Math.max(totalFileCount, 10), 2),
246
- currentProgress.ratio
289
+ currentProgress.ratio,
247
290
  ),
248
- 0.999
291
+ 0.999,
249
292
  );
250
293
  Object.assign(currentProgress, {
251
294
  ratio,
@@ -283,7 +326,7 @@ class TerminalReporter {
283
326
  _getStatusMessage() {
284
327
  return Array.from(this._activeBundles.entries())
285
328
  .map(([_, progress]) =>
286
- this._getBundleStatusMessage(progress, "in_progress")
329
+ this._getBundleStatusMessage(progress, "in_progress"),
287
330
  )
288
331
  .concat([this._interactionStatus])
289
332
  .filter((str) => str != null)
@@ -294,7 +337,7 @@ class TerminalReporter {
294
337
  this.terminal,
295
338
  "A WebSocket client got a connection error. Please reload your device " +
296
339
  "to get HMR working again: %s",
297
- e
340
+ e,
298
341
  );
299
342
  }
300
343
  _logWarning(message) {
@@ -314,14 +357,14 @@ class TerminalReporter {
314
357
  case "success":
315
358
  if (this._prevHealthCheckResult) {
316
359
  this.terminal.log(
317
- chalk.green(`Watcher ${watcherName} is now healthy.`)
360
+ _chalk.default.green(`Watcher ${watcherName} is now healthy.`),
318
361
  );
319
362
  }
320
363
  break;
321
364
  case "error":
322
365
  reporting.logWarning(
323
366
  this.terminal,
324
- "Failed to perform watcher health check. Check whether the project root is writable."
367
+ "Failed to perform watcher health check. Check whether the project root is writable.",
325
368
  );
326
369
  break;
327
370
  case "timeout":
@@ -332,7 +375,7 @@ class TerminalReporter {
332
375
  reporting.logWarning(
333
376
  this.terminal,
334
377
  `Watcher ${watcherName} failed to detect a file change within ${result.timeout}ms.` +
335
- why
378
+ why,
336
379
  );
337
380
  break;
338
381
  }
@@ -348,25 +391,21 @@ class TerminalReporter {
348
391
  : `unknown warning (type: ${typeof status.warning})`;
349
392
  reporting.logWarning(
350
393
  this.terminal,
351
- `Watchman \`${status.command}\` returned a warning: ${warning}`
394
+ `Watchman \`${status.command}\` returned a warning: ${warning}`,
352
395
  );
353
396
  break;
354
397
  case "watchman_slow_command":
355
398
  this.terminal.log(
356
- chalk.dim(
357
- `Waiting for Watchman \`${status.command}\` (${Math.round(
358
- status.timeElapsed / 1000
359
- )}s)...`
360
- )
399
+ _chalk.default.dim(
400
+ `Waiting for Watchman \`${status.command}\` (${Math.round(status.timeElapsed / 1000)}s)...`,
401
+ ),
361
402
  );
362
403
  break;
363
404
  case "watchman_slow_command_complete":
364
405
  this.terminal.log(
365
- chalk.green(
366
- `Watchman \`${status.command}\` finished after ${(
367
- status.timeElapsed / 1000
368
- ).toFixed(1)}s.`
369
- )
406
+ _chalk.default.green(
407
+ `Watchman \`${status.command}\` finished after ${(status.timeElapsed / 1000).toFixed(1)}s.`,
408
+ ),
370
409
  );
371
410
  break;
372
411
  }
@@ -381,4 +420,4 @@ class TerminalReporter {
381
420
  this.terminal.status(this._getStatusMessage());
382
421
  }
383
422
  }
384
- module.exports = TerminalReporter;
423
+ exports.default = TerminalReporter;
@@ -9,18 +9,16 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {BundleDetails, ReportableEvent} from './reporting';
15
13
  import type {Terminal} from 'metro-core';
16
14
  import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
17
15
 
18
- const logToConsole = require('./logToConsole');
19
- const reporting = require('./reporting');
20
- const chalk = require('chalk');
21
- const throttle = require('lodash.throttle');
22
- const {AmbiguousModuleResolutionError} = require('metro-core');
23
- const path = require('path');
16
+ import logToConsole from './logToConsole';
17
+ import * as reporting from './reporting';
18
+ import chalk from 'chalk';
19
+ import throttle from 'lodash.throttle';
20
+ import {AmbiguousModuleResolutionError} from 'metro-core';
21
+ import path from 'path';
24
22
 
25
23
  type BundleProgress = {
26
24
  bundleDetails: BundleDetails,
@@ -72,7 +70,7 @@ const MAX_PROGRESS_BAR_CHAR_WIDTH = 16;
72
70
  * We try to print useful information to the terminal for interactive builds.
73
71
  * This implements the `Reporter` interface from the './reporting' module.
74
72
  */
75
- class TerminalReporter {
73
+ export default class TerminalReporter {
76
74
  /**
77
75
  * The bundle builds for which we are actively maintaining the status on the
78
76
  * terminal, ie. showing a progress bar. There can be several bundles being
@@ -261,7 +259,7 @@ class TerminalReporter {
261
259
  this._logHmrClientError(event.error);
262
260
  break;
263
261
  case 'client_log':
264
- logToConsole(this.terminal, event.level, event.mode, ...event.data);
262
+ logToConsole(this.terminal, event.level, ...event.data);
265
263
  break;
266
264
  case 'unstable_server_log':
267
265
  const logFn = {
@@ -274,6 +272,7 @@ class TerminalReporter {
274
272
  break;
275
273
  case 'dep_graph_loading':
276
274
  const color = event.hasReducedPerformance ? chalk.red : chalk.blue;
275
+ // eslint-disable-next-line import/no-commonjs
277
276
  const version = 'v' + require('../../package.json').version;
278
277
  this.terminal.log(
279
278
  color.bold(
@@ -543,5 +542,3 @@ class TerminalReporter {
543
542
  this.terminal.status(this._getStatusMessage());
544
543
  }
545
544
  }
546
-
547
- module.exports = TerminalReporter;
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = bundleToString;
3
7
  function bundleToString(bundle) {
4
8
  let code = bundle.pre.length > 0 ? bundle.pre + "\n" : "";
5
9
  const modules = [];
@@ -24,4 +28,3 @@ function bundleToString(bundle) {
24
28
  },
25
29
  };
26
30
  }
27
- module.exports = bundleToString;
@@ -9,17 +9,12 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- import type {
15
- Bundle,
16
- BundleMetadata,
17
- } from 'metro-runtime/src/modules/types.flow';
12
+ import type {Bundle, BundleMetadata} from 'metro-runtime/src/modules/types';
18
13
 
19
14
  /**
20
15
  * Serializes a bundle into a plain JS bundle.
21
16
  */
22
- function bundleToString(bundle: Bundle): {
17
+ export default function bundleToString(bundle: Bundle): {
23
18
  +code: string,
24
19
  +metadata: BundleMetadata,
25
20
  } {
@@ -50,5 +45,3 @@ function bundleToString(bundle: Bundle): {
50
45
  metadata: {pre: bundle.pre.length, post: bundle.post.length, modules},
51
46
  };
52
47
  }
53
-
54
- module.exports = bundleToString;
@@ -9,11 +9,7 @@ var _crypto = _interopRequireDefault(require("crypto"));
9
9
  var _nullthrows = _interopRequireDefault(require("nullthrows"));
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
  function _interopRequireDefault(e) {
12
- return e && e.__esModule
13
- ? e
14
- : {
15
- default: e,
16
- };
12
+ return e && e.__esModule ? e : { default: e };
17
13
  }
18
14
  function toHash(value) {
19
15
  return _crypto.default.createHash("sha1").update(value).digest("hex");
@@ -30,14 +26,14 @@ function deriveAbsolutePathFromContext(from, context) {
30
26
  new RegExp(context.filter.pattern, context.filter.flags).toString(),
31
27
  ]
32
28
  .filter(Boolean)
33
- .join(" ")
29
+ .join(" "),
34
30
  )
35
31
  );
36
32
  }
37
33
  function fileMatchesContext(testPath, context) {
38
34
  const filePath = _path.default.relative(
39
35
  (0, _nullthrows.default)(context.from),
40
- testPath
36
+ testPath,
41
37
  );
42
38
  const filter = context.filter;
43
39
  if (
@@ -17,21 +17,17 @@ function _getRequireWildcardCache(e) {
17
17
  function _interopRequireWildcard(e, r) {
18
18
  if (!r && e && e.__esModule) return e;
19
19
  if (null === e || ("object" != typeof e && "function" != typeof e))
20
- return {
21
- default: e,
22
- };
20
+ return { default: e };
23
21
  var t = _getRequireWildcardCache(r);
24
22
  if (t && t.has(e)) return t.get(e);
25
- var n = {
26
- __proto__: null,
27
- },
23
+ var n = { __proto__: null },
28
24
  a = Object.defineProperty && Object.getOwnPropertyDescriptor;
29
25
  for (var u in e)
30
26
  if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
31
27
  var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
32
28
  i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
33
29
  }
34
- return (n.default = e), t && t.set(e, n), n;
30
+ return ((n.default = e), t && t.set(e, n), n);
35
31
  }
36
32
  function createFileMap(modulePath, files, processModule) {
37
33
  let mapString = "\n";
@@ -47,9 +43,7 @@ function createFileMap(modulePath, files, processModule) {
47
43
  filePath = `./${filePath}`;
48
44
  }
49
45
  const key = JSON.stringify(filePath);
50
- mapString += ` ${key}: { enumerable: true, get() { return ${processModule(
51
- file
52
- )}; } },\n`;
46
+ mapString += ` ${key}: { enumerable: true, get() { return ${processModule(file)}; } },\n`;
53
47
  });
54
48
  return `Object.defineProperties({}, {${mapString}})`;
55
49
  }
@@ -75,14 +69,10 @@ function getLoadableContextModuleTemplate(
75
69
  modulePath,
76
70
  files,
77
71
  importSyntax,
78
- getContextTemplate
72
+ getContextTemplate,
79
73
  ) {
80
74
  return `// All of the requested modules are loaded behind enumerable getters.
81
- const map = ${createFileMap(
82
- modulePath,
83
- files,
84
- (moduleId) => `${importSyntax}(${JSON.stringify(moduleId)})`
85
- )};
75
+ const map = ${createFileMap(modulePath, files, (moduleId) => `${importSyntax}(${JSON.stringify(moduleId)})`)};
86
76
 
87
77
  function metroContext(request) {
88
78
  ${getContextTemplate}
@@ -114,14 +104,14 @@ function getContextModuleTemplate(mode, modulePath, files) {
114
104
  " // Here Promise.resolve().then() is used instead of new Promise() to prevent",
115
105
  " // uncaught exception popping up in devtools",
116
106
  " return Promise.resolve().then(() => map[request]);",
117
- ].join("\n")
107
+ ].join("\n"),
118
108
  );
119
109
  case "sync":
120
110
  return getLoadableContextModuleTemplate(
121
111
  modulePath,
122
112
  files,
123
113
  "require",
124
- " return map[request];"
114
+ " return map[request];",
125
115
  );
126
116
  case "lazy":
127
117
  case "lazy-once":
@@ -129,7 +119,7 @@ function getContextModuleTemplate(mode, modulePath, files) {
129
119
  modulePath,
130
120
  files,
131
121
  "import",
132
- " return map[request];"
122
+ " return map[request];",
133
123
  );
134
124
  default:
135
125
  throw new Error(`Metro context mode "${mode}" is unimplemented`);
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
3
7
  const newline = /\r\n?|\n|\u2028|\u2029/g;
4
8
  const countLines = (string) => (string.match(newline) || []).length + 1;
5
- module.exports = countLines;
9
+ var _default = (exports.default = countLines);
@@ -9,11 +9,9 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  const newline = /\r\n?|\n|\u2028|\u2029/g;
15
13
 
16
14
  const countLines = (string: string): number =>
17
15
  (string.match(newline) || []).length + 1;
18
16
 
19
- module.exports = countLines;
17
+ export default countLines;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = createWebsocketServer;
3
7
  var _ws = _interopRequireDefault(require("ws"));
4
8
  function _interopRequireDefault(e) {
5
- return e && e.__esModule
6
- ? e
7
- : {
8
- default: e,
9
- };
9
+ return e && e.__esModule ? e : { default: e };
10
10
  }
11
- module.exports = function createWebsocketServer({ websocketServer }) {
11
+ function createWebsocketServer({ websocketServer }) {
12
12
  const wss = new _ws.default.Server({
13
13
  noServer: true,
14
14
  });
@@ -39,4 +39,4 @@ module.exports = function createWebsocketServer({ websocketServer }) {
39
39
  });
40
40
  });
41
41
  return wss;
42
- };
42
+ }
@@ -41,7 +41,7 @@ type HMROptions<TClient> = {
41
41
  * - onClientDisconnect
42
42
  */
43
43
 
44
- module.exports = function createWebsocketServer<TClient: Object>({
44
+ export default function createWebsocketServer<TClient: Object>({
45
45
  websocketServer,
46
46
  }: HMROptions<TClient>): ws.Server {
47
47
  const wss = new ws.Server({
@@ -54,7 +54,7 @@ module.exports = function createWebsocketServer<TClient: Object>({
54
54
 
55
55
  const sendFn = (...args: Array<string>) => {
56
56
  if (connected) {
57
- // $FlowFixMe[incompatible-call]
57
+ // $FlowFixMe[incompatible-type]
58
58
  ws.send(...args);
59
59
  }
60
60
  };
@@ -67,7 +67,7 @@ module.exports = function createWebsocketServer<TClient: Object>({
67
67
  }
68
68
 
69
69
  ws.on('error', e => {
70
- // $FlowFixMe[incompatible-call]
70
+ // $FlowFixMe[incompatible-type]
71
71
  websocketServer.onClientError && websocketServer.onClientError(client, e);
72
72
  });
73
73
 
@@ -84,4 +84,4 @@ module.exports = function createWebsocketServer<TClient: Object>({
84
84
  });
85
85
 
86
86
  return wss;
87
- };
87
+ }
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = debounceAsyncQueue;
3
7
  function debounceAsyncQueue(fn, delay) {
4
8
  let timeout;
5
9
  let waiting = false;
@@ -32,4 +36,3 @@ function debounceAsyncQueue(fn, delay) {
32
36
  }
33
37
  });
34
38
  }
35
- module.exports = debounceAsyncQueue;
@@ -9,11 +9,9 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  // Debounces calls with the given delay, and queues the next call while the
15
13
  // previous one hasn't completed so that no two calls can execute concurrently.
16
- function debounceAsyncQueue<T>(
14
+ export default function debounceAsyncQueue<T>(
17
15
  fn: () => Promise<T>,
18
16
  delay: number,
19
17
  ): () => Promise<T> {
@@ -51,5 +49,3 @@ function debounceAsyncQueue<T>(
51
49
  }
52
50
  });
53
51
  }
54
-
55
- module.exports = debounceAsyncQueue;