metro 0.80.4 → 0.80.6

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 (149) hide show
  1. package/package.json +16 -17
  2. package/src/Assets.js +0 -35
  3. package/src/Bundler/util.js +1 -29
  4. package/src/Bundler.js +1 -20
  5. package/src/DeltaBundler/DeltaCalculator.js +0 -86
  6. package/src/DeltaBundler/Graph.js +0 -197
  7. package/src/DeltaBundler/Serializers/baseJSBundle.js +0 -13
  8. package/src/DeltaBundler/Serializers/getAllFiles.js +0 -11
  9. package/src/DeltaBundler/Serializers/getAssets.js +0 -11
  10. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +0 -11
  11. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +0 -18
  12. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +0 -11
  13. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +0 -11
  14. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +0 -14
  15. package/src/DeltaBundler/Serializers/helpers/js.js +0 -21
  16. package/src/DeltaBundler/Serializers/helpers/processModules.js +0 -11
  17. package/src/DeltaBundler/Serializers/hmrJSBundle.js +0 -23
  18. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +0 -16
  19. package/src/DeltaBundler/Serializers/sourceMapObject.js +0 -11
  20. package/src/DeltaBundler/Serializers/sourceMapString.js +0 -11
  21. package/src/DeltaBundler/Transformer.js +0 -30
  22. package/src/DeltaBundler/Worker.flow.js +0 -26
  23. package/src/DeltaBundler/Worker.flow.js.flow +2 -2
  24. package/src/DeltaBundler/Worker.js +0 -14
  25. package/src/DeltaBundler/WorkerFarm.js +1 -21
  26. package/src/DeltaBundler/__fixtures__/hasteImpl.js +0 -14
  27. package/src/DeltaBundler/buildSubgraph.js +0 -24
  28. package/src/DeltaBundler/getTransformCacheKey.js +0 -13
  29. package/src/DeltaBundler/getTransformCacheKey.js.flow +1 -1
  30. package/src/DeltaBundler/mergeDeltas.js +0 -11
  31. package/src/DeltaBundler/types.flow.js +0 -11
  32. package/src/DeltaBundler.js +0 -21
  33. package/src/HmrServer.js +8 -39
  34. package/src/HmrServer.js.flow +8 -6
  35. package/src/IncrementalBundler/GraphNotFoundError.js +0 -11
  36. package/src/IncrementalBundler/ResourceNotFoundError.js +0 -11
  37. package/src/IncrementalBundler/RevisionNotFoundError.js +0 -11
  38. package/src/IncrementalBundler.js +0 -23
  39. package/src/ModuleGraph/test-helpers.js +0 -17
  40. package/src/ModuleGraph/worker/JsFileWrapping.js +1 -22
  41. package/src/ModuleGraph/worker/collectDependencies.js +1 -94
  42. package/src/ModuleGraph/worker/generateImportNames.js +0 -15
  43. package/src/Server/MultipartResponse.js +0 -13
  44. package/src/Server/symbolicate.js +2 -36
  45. package/src/Server.js +6 -83
  46. package/src/cli/parseKeyValueParamArray.js +0 -11
  47. package/src/cli-utils.js +0 -11
  48. package/src/cli.js +0 -13
  49. package/src/commands/build.js +0 -15
  50. package/src/commands/dependencies.js +1 -19
  51. package/src/commands/serve.js +0 -19
  52. package/src/index.flow.js +0 -31
  53. package/src/index.js +0 -14
  54. package/src/integration_tests/basic_bundle/AssetRegistry.js +0 -10
  55. package/src/integration_tests/basic_bundle/Bar.js +0 -10
  56. package/src/integration_tests/basic_bundle/ErrorBundle.js +0 -12
  57. package/src/integration_tests/basic_bundle/Foo.js +0 -10
  58. package/src/integration_tests/basic_bundle/TestBigInt.js +0 -12
  59. package/src/integration_tests/basic_bundle/TestBundle.js +0 -11
  60. package/src/integration_tests/basic_bundle/TestPolyfill.js +0 -10
  61. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +0 -14
  62. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js +0 -14
  63. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js +0 -14
  64. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js +1 -15
  65. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js +0 -13
  66. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js +0 -16
  67. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +0 -14
  68. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js +0 -13
  69. package/src/integration_tests/basic_bundle/import-export/export-1.js +0 -10
  70. package/src/integration_tests/basic_bundle/import-export/export-2.js +0 -10
  71. package/src/integration_tests/basic_bundle/import-export/export-3.js +0 -10
  72. package/src/integration_tests/basic_bundle/import-export/export-4.js +0 -10
  73. package/src/integration_tests/basic_bundle/import-export/export-5.js +0 -10
  74. package/src/integration_tests/basic_bundle/import-export/export-6.js +0 -10
  75. package/src/integration_tests/basic_bundle/import-export/export-null.js +0 -10
  76. package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js +0 -10
  77. package/src/integration_tests/basic_bundle/import-export/index.js +0 -10
  78. package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js +0 -10
  79. package/src/integration_tests/basic_bundle/polyfill.js +0 -12
  80. package/src/integration_tests/basic_bundle/require-context/conflict.js +0 -10
  81. package/src/integration_tests/basic_bundle/require-context/empty.js +0 -10
  82. package/src/integration_tests/basic_bundle/require-context/matching.js +0 -10
  83. package/src/integration_tests/basic_bundle/require-context/mode-eager.js +0 -10
  84. package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +0 -10
  85. package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +0 -10
  86. package/src/integration_tests/basic_bundle/require-context/mode-sync.js +0 -11
  87. package/src/integration_tests/basic_bundle/require-context/subdir/a.js +0 -10
  88. package/src/integration_tests/basic_bundle/require-context/subdir/b.js +0 -9
  89. package/src/integration_tests/basic_bundle/require-context/subdir/c.js +0 -10
  90. package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js +0 -10
  91. package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js +0 -10
  92. package/src/integration_tests/basic_bundle/require-context/utils.js +0 -10
  93. package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js +0 -15
  94. package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js +0 -10
  95. package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js +0 -10
  96. package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js +0 -15
  97. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js +0 -10
  98. package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js +0 -10
  99. package/src/integration_tests/execBundle.js +0 -11
  100. package/src/integration_tests/metro.config.js +0 -10
  101. package/src/lib/BatchProcessor.js +0 -23
  102. package/src/lib/CountingSet.js +0 -35
  103. package/src/lib/JsonReporter.js +0 -17
  104. package/src/lib/RamBundleParser.js +0 -23
  105. package/src/lib/TerminalReporter.js +0 -68
  106. package/src/lib/bundleToString.js +1 -19
  107. package/src/lib/contextModule.js +1 -31
  108. package/src/lib/contextModuleTemplates.js +0 -36
  109. package/src/lib/countLines.js +0 -11
  110. package/src/lib/createModuleIdFactory.js +0 -11
  111. package/src/lib/createWebsocketServer.js +0 -24
  112. package/src/lib/debounceAsyncQueue.js +0 -13
  113. package/src/lib/formatBundlingError.js +0 -14
  114. package/src/lib/getAppendScripts.js +0 -11
  115. package/src/lib/getGraphId.js +0 -11
  116. package/src/lib/getMaxWorkers.js +0 -11
  117. package/src/lib/getPreludeCode.js +0 -18
  118. package/src/lib/getPrependedScripts.js +0 -13
  119. package/src/lib/logToConsole.js +0 -18
  120. package/src/lib/parseCustomResolverOptions.js +0 -11
  121. package/src/lib/parseCustomTransformOptions.js +0 -12
  122. package/src/lib/parseOptionsFromUrl.js +1 -17
  123. package/src/lib/relativizeSourceMap.js +0 -12
  124. package/src/lib/reporting.js +0 -30
  125. package/src/lib/splitBundleOptions.js +0 -14
  126. package/src/lib/transformHelpers.js +0 -20
  127. package/src/node-haste/DependencyGraph/ModuleResolution.js +5 -64
  128. package/src/node-haste/DependencyGraph/createFileMap.js +0 -16
  129. package/src/node-haste/DependencyGraph.js +6 -46
  130. package/src/node-haste/DependencyGraph.js.flow +7 -4
  131. package/src/node-haste/Module.js +0 -11
  132. package/src/node-haste/ModuleCache.js +0 -20
  133. package/src/node-haste/Package.js +0 -11
  134. package/src/node-haste/lib/AssetPaths.js +0 -16
  135. package/src/node-haste/lib/parsePlatformFilePath.js +0 -16
  136. package/src/shared/output/RamBundle/as-assets.js +6 -29
  137. package/src/shared/output/RamBundle/as-indexed-file.js +0 -44
  138. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +0 -13
  139. package/src/shared/output/RamBundle/magic-number.js +0 -11
  140. package/src/shared/output/RamBundle/util.js +1 -17
  141. package/src/shared/output/RamBundle/write-sourcemap.js +0 -12
  142. package/src/shared/output/RamBundle.js +0 -14
  143. package/src/shared/output/bundle.flow.js +0 -13
  144. package/src/shared/output/bundle.flow.js.flow +1 -1
  145. package/src/shared/output/bundle.js +0 -14
  146. package/src/shared/output/meta.js +0 -11
  147. package/src/shared/output/unbundle.js +0 -13
  148. package/src/shared/output/writeFile.js +0 -11
  149. package/src/shared/types.flow.js +0 -11
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const invariant = require("invariant");
@@ -36,12 +25,6 @@ function getModuleParams(module, options) {
36
25
  options.sourceUrl != null,
37
26
  "sourceUrl is required when includeAsyncPaths is true"
38
27
  );
39
-
40
- // TODO: Only include path if the target is not in the bundle
41
-
42
- // Construct a server-relative URL for the split bundle, propagating
43
- // most parameters from the main bundle's URL.
44
-
45
28
  const { searchParams } = new URL(
46
29
  jscSafeUrl.toNormalUrl(options.sourceUrl)
47
30
  );
@@ -55,7 +38,6 @@ function getModuleParams(module, options) {
55
38
  "/" +
56
39
  path.join(
57
40
  path.dirname(bundlePath),
58
- // Strip the file extension
59
41
  path.basename(bundlePath, path.extname(bundlePath))
60
42
  ) +
61
43
  ".bundle?" +
@@ -68,15 +50,12 @@ function getModuleParams(module, options) {
68
50
  moduleId,
69
51
  hasPaths
70
52
  ? {
71
- // $FlowIgnore[not-an-object] Intentionally spreading an array into an object
72
53
  ...dependencyMapArray,
73
54
  paths,
74
55
  }
75
56
  : dependencyMapArray,
76
57
  ];
77
58
  if (options.dev) {
78
- // Add the relative path of the module to make debugging easier.
79
- // This is mapped to `module.verboseName` in `require.js`.
80
59
  params.push(path.relative(options.projectRoot, module.path));
81
60
  }
82
61
  return params;
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const { isJsModule, wrapModule } = require("./js");
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const { isJsModule, wrapModule } = require("./helpers/js");
@@ -20,7 +9,6 @@ function generateModules(sourceModules, graph, options) {
20
9
  const modules = [];
21
10
  for (const module of sourceModules) {
22
11
  if (isJsModule(module)) {
23
- // Construct a bundle URL for this specific module only
24
12
  const getURL = (extension) => {
25
13
  options.clientUrl.pathname = path.relative(
26
14
  options.serverRoot ?? options.projectRoot,
@@ -55,26 +43,15 @@ function prepareModule(module, graph, options) {
55
43
  dev: true,
56
44
  });
57
45
  const inverseDependencies = getInverseDependencies(module.path, graph);
58
- // Transform the inverse dependency paths to ids.
59
46
  const inverseDependenciesById = Object.create(null);
60
47
  Object.keys(inverseDependencies).forEach((path) => {
61
- // $FlowFixMe[prop-missing]
62
- // $FlowFixMe[invalid-computed-prop]
63
48
  inverseDependenciesById[options.createModuleId(path)] = inverseDependencies[
64
49
  path
65
50
  ].map(options.createModuleId);
66
51
  });
67
52
  return addParamsToDefineCall(code, inverseDependenciesById);
68
53
  }
69
-
70
- /**
71
- * Instead of adding the whole inverseDependncies object into each changed
72
- * module (which can be really huge if the dependency graph is big), we only
73
- * add the needed inverseDependencies for each changed module (we do this by
74
- * traversing upwards the dependency graph).
75
- */
76
54
  function getInverseDependencies(path, graph, inverseDependencies = {}) {
77
- // Dependency alredy traversed.
78
55
  if (path in inverseDependencies) {
79
56
  return inverseDependencies;
80
57
  }
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const getSourceMapInfo = require("./helpers/getSourceMapInfo");
@@ -43,14 +32,9 @@ function getSourceMapInfosImpl(isBlocking, onDone, modules, options) {
43
32
  break;
44
33
  }
45
34
  if (!isBlocking) {
46
- // Keep the loop running but try to avoid blocking
47
- // for too long because this is not in a worker yet.
48
35
  const diff = process.hrtime(time);
49
36
  const NS_IN_MS = 1000000;
50
37
  if (diff[1] > 50 * NS_IN_MS) {
51
- // We've blocked for more than 50ms.
52
- // This code currently runs on the main thread,
53
- // so let's give Metro an opportunity to handle requests.
54
38
  setImmediate(workLoop);
55
39
  break;
56
40
  }
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const {
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const { sourceMapGenerator } = require("./sourceMapGenerator");
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  var _crypto = _interopRequireDefault(require("crypto"));
@@ -27,10 +16,6 @@ class Transformer {
27
16
  this._config.watchFolders.forEach(verifyRootExists);
28
17
  this._cache = new Cache(config.cacheStores);
29
18
  this._getSha1 = getSha1Fn;
30
-
31
- // Remove the transformer config params that we don't want to pass to the
32
- // transformer. We should change the config object and move them away so we
33
- // can treat the transformer config params as opaque.
34
19
  const {
35
20
  getTransformOptions: _getTransformOptions,
36
21
  transformVariants: _transformVariants,
@@ -70,7 +55,6 @@ class Transformer {
70
55
  ...extra
71
56
  } = transformerOptions;
72
57
  for (const key in extra) {
73
- // $FlowFixMe[cannot-resolve-name]
74
58
  if (hasOwnProperty.call(extra, key)) {
75
59
  throw new Error(
76
60
  "Extra keys detected: " + Object.keys(extra).join(", ")
@@ -79,9 +63,7 @@ class Transformer {
79
63
  }
80
64
  const localPath = path.relative(this._config.projectRoot, filePath);
81
65
  const partialKey = stableHash([
82
- // This is the hash related to the global Bundler config.
83
66
  this._baseHash,
84
- // Path.
85
67
  localPath,
86
68
  customTransformOptions,
87
69
  dev,
@@ -98,7 +80,6 @@ class Transformer {
98
80
  ]);
99
81
  let sha1;
100
82
  if (fileBuffer) {
101
- // Shortcut for virtual modules which provide the contents with the filename.
102
83
  sha1 = _crypto.default
103
84
  .createHash("sha1")
104
85
  .update(fileBuffer)
@@ -108,9 +89,6 @@ class Transformer {
108
89
  }
109
90
  let fullKey = Buffer.concat([partialKey, Buffer.from(sha1, "hex")]);
110
91
  const result = await cache.get(fullKey);
111
-
112
- // A valid result from the cache is used directly; otherwise we call into
113
- // the transformer to computed the corresponding result.
114
92
  const data = result
115
93
  ? {
116
94
  result,
@@ -121,15 +99,9 @@ class Transformer {
121
99
  transformerOptions,
122
100
  fileBuffer
123
101
  );
124
-
125
- // Only re-compute the full key if the SHA-1 changed. This is because
126
- // references are used by the cache implementation in a weak map to keep
127
- // track of the cache that returned the result.
128
102
  if (sha1 !== data.sha1) {
129
103
  fullKey = Buffer.concat([partialKey, Buffer.from(data.sha1, "hex")]);
130
104
  }
131
-
132
- // Fire-and-forget cache set promise.
133
105
  void cache.set(fullKey, data.result);
134
106
  return {
135
107
  ...data.result,
@@ -143,12 +115,10 @@ class Transformer {
143
115
  };
144
116
  }
145
117
  end() {
146
- // $FlowFixMe[unused-promise]
147
118
  this._workerFarm.kill();
148
119
  }
149
120
  }
150
121
  function verifyRootExists(root) {
151
- // Verify that the root exists.
152
122
  assert(fs.statSync(root).isDirectory(), "Root has to be a valid directory");
153
123
  }
154
124
  module.exports = Transformer;
@@ -1,27 +1,9 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const traverse = require("@babel/traverse").default;
15
4
  const crypto = require("crypto");
16
5
  const fs = require("fs");
17
6
  const path = require("path");
18
- /**
19
- * When the `Buffer` is sent over the worker thread it gets serialized into a JSON object.
20
- * This helper method will deserialize it if needed.
21
- *
22
- * @returns `Buffer` representation of the JSON object.
23
- * @returns `null` if the given object is nullish or not a serialized `Buffer` object.
24
- */
25
7
  function asDeserializedBuffer(value) {
26
8
  if (Buffer.isBuffer(value)) {
27
9
  return value;
@@ -60,7 +42,6 @@ async function transformFile(
60
42
  projectRoot,
61
43
  transformerConfig
62
44
  ) {
63
- // eslint-disable-next-line no-useless-call
64
45
  const Transformer = require.call(null, transformerConfig.transformerPath);
65
46
  const transformFileStartLogEntry = {
66
47
  action_name: "Transforming file",
@@ -77,13 +58,6 @@ async function transformFile(
77
58
  data,
78
59
  transformOptions
79
60
  );
80
-
81
- // The babel cache caches scopes and pathes for already traversed AST nodes.
82
- // Clearing the cache here since the nodes of the transformed file are no longer referenced.
83
- // This isn't stritcly necessary since the cache uses a WeakMap. However, WeakMap only permit
84
- // that unreferenced keys are collected but the values still hold references to the Scope and NodePaths.
85
- // Manually clearing the cache allows the GC to collect the Scope and NodePaths without checking if there
86
- // exist any other references to the keys.
87
61
  traverse.cache.clear();
88
62
  const transformFileEndLogEntry = getEndLogEntry(
89
63
  transformFileStartLogEntry,
@@ -101,10 +101,10 @@ async function transformFile(
101
101
  transformerConfig: TransformerConfig,
102
102
  ): Promise<Data> {
103
103
  // eslint-disable-next-line no-useless-call
104
- const Transformer = (require.call(
104
+ const Transformer: TransformerInterface = require.call(
105
105
  null,
106
106
  transformerConfig.transformerPath,
107
- ): TransformerInterface);
107
+ );
108
108
 
109
109
  const transformFileStartLogEntry = {
110
110
  action_name: 'Transforming file',
@@ -1,19 +1,5 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
- /*::
15
- export type * from './Worker.flow';
16
- */
17
3
  try {
18
4
  require("metro-babel-register").unstable_registerForMetroMonorepo();
19
5
  } catch {}
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const { Worker: JestWorker } = require("jest-worker");
@@ -38,7 +27,6 @@ class WorkerFarm {
38
27
  });
39
28
  this._worker = worker;
40
29
  } else {
41
- // eslint-disable-next-line no-useless-call
42
30
  this._worker = require.call(null, this._config.transformer.workerPath);
43
31
  }
44
32
  }
@@ -73,14 +61,11 @@ class WorkerFarm {
73
61
  _makeFarm(absoluteWorkerPath, exposedMethods, numWorkers) {
74
62
  const env = {
75
63
  ...process.env,
76
- // Force color to print syntax highlighted code frames.
77
64
  FORCE_COLOR: 1,
78
65
  };
79
66
  return new JestWorker(absoluteWorkerPath, {
80
67
  computeWorkerKey: this._config.stickyWorkers
81
- ? // $FlowFixMe[method-unbinding] added when improving typing for this parameters
82
- // $FlowFixMe[incompatible-call]
83
- this._computeWorkerKey
68
+ ? this._computeWorkerKey
84
69
  : undefined,
85
70
  exposedMethods,
86
71
  enableWorkerThreads: this._config.transformer.unstable_workerThreads,
@@ -91,9 +76,6 @@ class WorkerFarm {
91
76
  });
92
77
  }
93
78
  _computeWorkerKey(method, filename) {
94
- // Only when transforming a file we want to stick to the same worker; and
95
- // we'll shard by file path. If not; we return null, which tells the worker
96
- // to pick the first available one.
97
79
  if (method === "transform") {
98
80
  return filename;
99
81
  }
@@ -112,8 +94,6 @@ class WorkerFarm {
112
94
  err.message.includes(filename) ? "" : " in " + filename
113
95
  }: ${err.message}`
114
96
  );
115
-
116
- // $FlowExpectedError: TODO(t67543470): Change this to properly extend the error.
117
97
  return Object.assign(error, {
118
98
  stack: err.stack,
119
99
  snippet: err.codeFrame,
@@ -1,20 +1,6 @@
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
- * @format
8
- * @oncall react_native
9
- */
10
-
11
1
  "use strict";
12
2
 
13
3
  const fs = require("fs");
14
-
15
- /**
16
- * Simple hasteImpl that parses @providesModule annotation from JS modules.
17
- */
18
4
  module.exports = {
19
5
  getHasteName(filename) {
20
6
  const matches = fs
@@ -9,28 +9,14 @@ var _path = _interopRequireDefault(require("path"));
9
9
  function _interopRequireDefault(obj) {
10
10
  return obj && obj.__esModule ? obj : { default: obj };
11
11
  }
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- *
19
- * @format
20
- */
21
-
22
12
  function resolveDependencies(parentPath, dependencies, resolve) {
23
13
  const maybeResolvedDeps = new Map();
24
14
  const resolvedContexts = new Map();
25
15
  for (const dep of dependencies) {
26
16
  let resolvedDep;
27
17
  const key = dep.data.key;
28
-
29
- // `require.context`
30
18
  const { contextParams } = dep.data;
31
19
  if (contextParams) {
32
- // Ensure the filepath has uniqueness applied to ensure multiple `require.context`
33
- // statements can be used to target the same file with different properties.
34
20
  const from = _path.default.join(parentPath, "..", dep.name);
35
21
  const absolutePath = (0, _contextModule.deriveAbsolutePathFromContext)(
36
22
  from,
@@ -57,8 +43,6 @@ function resolveDependencies(parentPath, dependencies, resolve) {
57
43
  data: dep,
58
44
  };
59
45
  } catch (error) {
60
- // Ignore unavailable optional dependencies. They are guarded
61
- // with a try-catch block and will be handled during runtime.
62
46
  if (dep.data.isOptional !== true) {
63
47
  throw error;
64
48
  }
@@ -72,11 +56,6 @@ function resolveDependencies(parentPath, dependencies, resolve) {
72
56
  maybeResolvedDeps.set(key, resolvedDep);
73
57
  }
74
58
  const resolvedDeps = new Map();
75
- // Return just the dependencies we successfully resolved.
76
- // FIXME: This has a bad bug affecting all dependencies *after* an unresolved
77
- // optional dependency. We'll need to propagate the nulls all the way to the
78
- // serializer and the require() runtime to keep the dependency map from being
79
- // desynced from the contents of the module.
80
59
  for (const [key, resolvedDep] of maybeResolvedDeps) {
81
60
  if (resolvedDep) {
82
61
  resolvedDeps.set(key, resolvedDep);
@@ -101,9 +80,6 @@ async function buildSubgraph(
101
80
  }
102
81
  visitedPaths.add(absolutePath);
103
82
  const transformResult = await transform(absolutePath, requireContext);
104
-
105
- // Get the absolute path of all sub-dependencies (some of them could have been
106
- // moved but maintain the same relative path).
107
83
  const resolutionResult = resolveDependencies(
108
84
  absolutePath,
109
85
  transformResult.dependencies,
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const VERSION = require("../../package.json").version;
@@ -16,8 +5,6 @@ const crypto = require("crypto");
16
5
  const getCacheKey = require("metro-cache-key");
17
6
  function getTransformCacheKey(opts) {
18
7
  const { transformerPath, transformerConfig } = opts.transformerConfig;
19
-
20
- // eslint-disable-next-line no-useless-call
21
8
  const Transformer = require.call(null, transformerPath);
22
9
  const transformerKey = Transformer.getCacheKey
23
10
  ? Transformer.getCacheKey(transformerConfig)
@@ -30,7 +30,7 @@ function getTransformCacheKey(opts: {
30
30
  const {transformerPath, transformerConfig} = opts.transformerConfig;
31
31
 
32
32
  // eslint-disable-next-line no-useless-call
33
- const Transformer = (require.call(null, transformerPath): CacheKeyProvider);
33
+ const Transformer: CacheKeyProvider = require.call(null, transformerPath);
34
34
  const transformerKey = Transformer.getCacheKey
35
35
  ? Transformer.getCacheKey(transformerConfig)
36
36
  : '';
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  function mergeDeltas(delta1, delta2) {
@@ -1,14 +1,3 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  var _CountingSet = _interopRequireDefault(require("../lib/CountingSet"));
@@ -1,23 +1,6 @@
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
- * @oncall react_native
10
- */
11
-
12
1
  "use strict";
13
2
 
14
3
  const DeltaCalculator = require("./DeltaBundler/DeltaCalculator");
15
- /**
16
- * `DeltaBundler` uses the `DeltaTransformer` to build bundle deltas. This
17
- * module handles all the transformer instances so it can support multiple
18
- * concurrent clients requesting their own deltas. This is done through the
19
- * `clientId` param (which maps a client to a specific delta transformer).
20
- */
21
4
  class DeltaBundler {
22
5
  _deltaCalculators = new Map();
23
6
  constructor(changeEventSource) {
@@ -41,10 +24,6 @@ class DeltaBundler {
41
24
  deltaCalculator.end();
42
25
  return graph.dependencies;
43
26
  }
44
-
45
- // Note: the graph returned by this function needs to be ended when finished
46
- // so that we don't leak graphs that are not reachable.
47
- // To get just the dependencies, use getDependencies which will not leak graphs.
48
27
  async buildGraph(entryPoints, options) {
49
28
  const deltaCalculator = new DeltaCalculator(
50
29
  new Set(entryPoints),
package/src/HmrServer.js CHANGED
@@ -1,13 +1,3 @@
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
- * @format
8
- *
9
- */
10
-
11
1
  "use strict";
12
2
 
13
3
  const hmrJSBundle = require("./DeltaBundler/Serializers/hmrJSBundle");
@@ -28,16 +18,6 @@ function send(sendFns, message) {
28
18
  const strMessage = JSON.stringify(message);
29
19
  sendFns.forEach((sendFn) => sendFn(strMessage));
30
20
  }
31
-
32
- /**
33
- * The HmrServer (Hot Module Reloading) implements a lightweight interface
34
- * to communicate easily to the logic in the React Native repository (which
35
- * is the one that handles the Web Socket connections).
36
- *
37
- * This interface allows the HmrServer to hook its own logic to WS clients
38
- * getting connected, disconnected or having errors (through the
39
- * `onClientConnect`, `onClientDisconnect` and `onClientError` methods).
40
- */
41
21
  class HmrServer {
42
22
  constructor(bundler, createModuleId, config) {
43
23
  this._config = config;
@@ -61,11 +41,6 @@ class HmrServer {
61
41
  );
62
42
  const { entryFile, resolverOptions, transformOptions, graphOptions } =
63
43
  splitBundleOptions(options);
64
-
65
- /**
66
- * `entryFile` is relative to projectRoot, we need to use resolution function
67
- * to find the appropriate file with supported extensions.
68
- */
69
44
  const resolutionFn = await transformHelpers.getResolveDependencyFn(
70
45
  this._bundler.getBundler(),
71
46
  transformOptions.platform,
@@ -104,7 +79,6 @@ class HmrServer {
104
79
  if (clientGroup != null) {
105
80
  clientGroup.clients.add(client);
106
81
  } else {
107
- // Prepare the clientUrl to be used as sourceUrl in HMR updates.
108
82
  clientUrl.protocol = "http";
109
83
  const {
110
84
  dev,
@@ -142,7 +116,6 @@ class HmrServer {
142
116
  }, 50);
143
117
  const unlisten = this._bundler
144
118
  .getDeltaBundler()
145
- // $FlowFixMe[missing-local-annot]
146
119
  .listen(graph, async (...args) => {
147
120
  latestEventArgs = args;
148
121
  await debounceCallHandleFileChange();
@@ -175,12 +148,14 @@ class HmrServer {
175
148
  )
176
149
  );
177
150
  case "log":
178
- this._config.reporter.update({
179
- type: "client_log",
180
- level: data.level,
181
- data: data.data,
182
- mode: data.mode,
183
- });
151
+ if (this._config.server.forwardClientLogs) {
152
+ this._config.reporter.update({
153
+ type: "client_log",
154
+ level: data.level,
155
+ data: data.data,
156
+ mode: data.mode,
157
+ });
158
+ }
184
159
  break;
185
160
  case "log-opt-in":
186
161
  client.optedIntoHMR = true;
@@ -222,12 +197,6 @@ class HmrServer {
222
197
  );
223
198
  const processingHmrChange = log(
224
199
  createActionStartEntry({
225
- // Even when HMR is disabled on the client, this function still
226
- // runs so we can stash updates while it's off and apply them later.
227
- // However, this would mess up our internal analytics because we track
228
- // HMR as being used even for people who have it disabled.
229
- // As a workaround, we use a different event name for clients
230
- // that didn't explicitly opt into HMR.
231
200
  action_name: optedIntoHMR
232
201
  ? "Processing HMR change"
233
202
  : "Processing HMR change (no client opt-in)",