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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.80.4",
3
+ "version": "0.80.6",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
@@ -28,25 +28,24 @@
28
28
  "denodeify": "^1.2.1",
29
29
  "error-stack-parser": "^2.0.6",
30
30
  "graceful-fs": "^4.2.4",
31
- "hermes-parser": "0.18.2",
31
+ "hermes-parser": "0.19.1",
32
32
  "image-size": "^1.0.2",
33
33
  "invariant": "^2.2.4",
34
34
  "jest-worker": "^29.6.3",
35
35
  "jsc-safe-url": "^0.2.2",
36
36
  "lodash.throttle": "^4.1.1",
37
- "metro-babel-transformer": "0.80.4",
38
- "metro-cache": "0.80.4",
39
- "metro-cache-key": "0.80.4",
40
- "metro-config": "0.80.4",
41
- "metro-core": "0.80.4",
42
- "metro-file-map": "0.80.4",
43
- "metro-minify-terser": "0.80.4",
44
- "metro-resolver": "0.80.4",
45
- "metro-runtime": "0.80.4",
46
- "metro-source-map": "0.80.4",
47
- "metro-symbolicate": "0.80.4",
48
- "metro-transform-plugins": "0.80.4",
49
- "metro-transform-worker": "0.80.4",
37
+ "metro-babel-transformer": "0.80.6",
38
+ "metro-cache": "0.80.6",
39
+ "metro-cache-key": "0.80.6",
40
+ "metro-config": "0.80.6",
41
+ "metro-core": "0.80.6",
42
+ "metro-file-map": "0.80.6",
43
+ "metro-resolver": "0.80.6",
44
+ "metro-runtime": "0.80.6",
45
+ "metro-source-map": "0.80.6",
46
+ "metro-symbolicate": "0.80.6",
47
+ "metro-transform-plugins": "0.80.6",
48
+ "metro-transform-worker": "0.80.6",
50
49
  "mime-types": "^2.1.27",
51
50
  "node-fetch": "^2.2.0",
52
51
  "nullthrows": "^1.1.1",
@@ -67,8 +66,8 @@
67
66
  "dedent": "^0.7.0",
68
67
  "jest-snapshot": "^29.6.3",
69
68
  "jest-snapshot-serializer-raw": "^1.2.0",
70
- "metro-babel-register": "0.80.4",
71
- "metro-memory-fs": "0.80.4",
69
+ "metro-babel-register": "0.80.6",
70
+ "metro-memory-fs": "0.80.6",
72
71
  "mock-req": "^0.2.0",
73
72
  "mock-res": "^0.6.0",
74
73
  "stack-trace": "^0.0.10"
package/src/Assets.js CHANGED
@@ -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 AssetPaths = require("./node-haste/lib/AssetPaths");
@@ -19,8 +8,6 @@ const getImageSize = require("image-size");
19
8
  const path = require("path");
20
9
  const readDir = denodeify(fs.readdir);
21
10
  const readFile = denodeify(fs.readFile);
22
- // Test extension against all types supported by image-size module.
23
- // If it's not one of these, we won't treat it as an image.
24
11
  function isAssetTypeAnImage(type) {
25
12
  return (
26
13
  [
@@ -155,14 +142,9 @@ async function getAssetData(
155
142
  platform = null,
156
143
  publicPath
157
144
  ) {
158
- // If the path of the asset is outside of the projectRoot, we don't want to
159
- // use `path.join` since this will generate an incorrect URL path. In that
160
- // case we just concatenate the publicPath with the relative path.
161
145
  let assetUrlPath = localPath.startsWith("..")
162
146
  ? publicPath.replace(/\/$/, "") + "/" + path.dirname(localPath)
163
147
  : path.join(publicPath, path.dirname(localPath));
164
-
165
- // On Windows, change backslashes to slashes to get proper URL path from file path.
166
148
  if (path.sep === "\\") {
167
149
  assetUrlPath = assetUrlPath.replaceAll("\\", "/");
168
150
  }
@@ -192,31 +174,14 @@ async function applyAssetDataPlugins(assetDataPlugins, assetData) {
192
174
  return assetData;
193
175
  }
194
176
  const [currentAssetPlugin, ...remainingAssetPlugins] = assetDataPlugins;
195
- // $FlowFixMe: impossible to type a dynamic require.
196
177
  const assetPluginFunction = require(currentAssetPlugin);
197
178
  const resultAssetData = await assetPluginFunction(assetData);
198
179
  return await applyAssetDataPlugins(remainingAssetPlugins, resultAssetData);
199
180
  }
200
-
201
- /**
202
- * Returns all the associated files (for different resolutions) of an asset.
203
- **/
204
181
  async function getAssetFiles(assetPath, platform = null) {
205
182
  const assetData = await getAbsoluteAssetRecord(assetPath, platform);
206
183
  return assetData.files;
207
184
  }
208
-
209
- /**
210
- * Return a buffer with the actual image given a request for an image by path.
211
- * The relativePath can contain a resolution postfix, in this case we need to
212
- * find that image (or the closest one to it's resolution) in one of the
213
- * project roots:
214
- *
215
- * 1. We first parse the directory of the asset
216
- * 2. We then build a map of all assets and their scales in this directory
217
- * 3. Then try to pick platform-specific asset records
218
- * 4. Then pick the closest resolution (rounding up) to the requested one
219
- */
220
185
  async function getAsset(
221
186
  relativePath,
222
187
  projectRoot,
@@ -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 babylon = require("@babel/parser");
@@ -20,14 +9,10 @@ function generateAssetCodeFileAst(assetRegistryPath, assetDescriptor) {
20
9
  assetDescriptor,
21
10
  assetPropertyBlockList
22
11
  );
23
-
24
- // {...}
25
12
  const descriptorAst = babylon.parseExpression(
26
13
  JSON.stringify(properDescriptor)
27
14
  );
28
15
  const t = babelTypes;
29
-
30
- // require('AssetRegistry').registerAsset({...})
31
16
  const buildRequire = template.statement(`
32
17
  module.exports = require(ASSET_REGISTRY_PATH).registerAsset(DESCRIPTOR_AST)
33
18
  `);
@@ -45,48 +30,35 @@ function filterObject(object, blockList) {
45
30
  ...object,
46
31
  };
47
32
  for (const key of blockList) {
48
- // $FlowFixMe[prop-missing]
49
33
  delete copied[key];
50
34
  }
51
35
  return copied;
52
36
  }
53
37
  function createRamBundleGroups(ramGroups, groupableModules, subtree) {
54
- // build two maps that allow to lookup module data
55
- // by path or (numeric) module id;
56
38
  const byPath = new Map();
57
39
  const byId = new Map();
58
40
  groupableModules.forEach((m) => {
59
41
  byPath.set(m.sourcePath, m);
60
42
  byId.set(m.id, m.sourcePath);
61
43
  });
62
-
63
- // build a map of group root IDs to an array of module IDs in the group
64
44
  const result = new Map(
65
45
  ramGroups.map((modulePath) => {
66
46
  const root = byPath.get(modulePath);
67
47
  if (root == null) {
68
48
  throw Error(`Group root ${modulePath} is not part of the bundle`);
69
49
  }
70
- return [
71
- root.id,
72
- // `subtree` yields the IDs of all transitive dependencies of a module
73
- new Set(subtree(root, byPath)),
74
- ];
50
+ return [root.id, new Set(subtree(root, byPath))];
75
51
  })
76
52
  );
77
53
  if (ramGroups.length > 1) {
78
- // build a map of all grouped module IDs to an array of group root IDs
79
54
  const all = new ArrayMap();
80
55
  for (const [parent, children] of result) {
81
56
  for (const module of children) {
82
57
  all.get(module).push(parent);
83
58
  }
84
59
  }
85
-
86
- // find all module IDs that are part of more than one group
87
60
  const doubles = filter(all, ([, parents]) => parents.length > 1);
88
61
  for (const [moduleId, parents] of doubles) {
89
- // $FlowFixMe[method-unbinding] added when improving typing for this parameters
90
62
  const parentNames = parents.map(byId.get, byId);
91
63
  const lastName = parentNames.pop();
92
64
  throw new Error(
package/src/Bundler.js CHANGED
@@ -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 Transformer = require("./DeltaBundler/Transformer");
@@ -49,13 +38,7 @@ class Bundler {
49
38
  await this._depGraph.ready();
50
39
  return this._depGraph;
51
40
  }
52
- async transformFile(
53
- filePath,
54
- transformOptions /** Optionally provide the file contents, this can be used to provide virtual contents for a file. */,
55
- fileBuffer
56
- ) {
57
- // We need to be sure that the DependencyGraph has been initialized.
58
- // TODO: Remove this ugly hack!
41
+ async transformFile(filePath, transformOptions, fileBuffer) {
59
42
  await this._depGraph.ready();
60
43
  return this._transformer.transformFile(
61
44
  filePath,
@@ -63,8 +46,6 @@ class Bundler {
63
46
  fileBuffer
64
47
  );
65
48
  }
66
-
67
- // Waits for the bundler to become ready.
68
49
  async ready() {
69
50
  await this._readyPromise;
70
51
  }
@@ -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 _Graph = require("./Graph");
@@ -18,13 +7,6 @@ function _interopRequireDefault(obj) {
18
7
  }
19
8
  const debug = require("debug")("Metro:DeltaCalculator");
20
9
  const { EventEmitter } = require("events");
21
-
22
- /**
23
- * This class is in charge of calculating the delta of changed modules that
24
- * happen between calls. To do so, it subscribes to file changes, so it can
25
- * traverse the files that have been changed between calls and avoid having to
26
- * traverse the whole dependency tree for trivial small changes.
27
- */
28
10
  class DeltaCalculator extends EventEmitter {
29
11
  _deletedFiles = new Set();
30
12
  _modifiedFiles = new Set();
@@ -40,18 +22,12 @@ class DeltaCalculator extends EventEmitter {
40
22
  });
41
23
  this._changeEventSource.on("change", this._handleMultipleFileChanges);
42
24
  }
43
-
44
- /**
45
- * Stops listening for file changes and clears all the caches.
46
- */
47
25
  end() {
48
26
  this._changeEventSource.removeListener(
49
27
  "change",
50
28
  this._handleMultipleFileChanges
51
29
  );
52
30
  this.removeAllListeners();
53
-
54
- // Clean up all the cache data structures to deallocate memory.
55
31
  this._graph = new _Graph.Graph({
56
32
  entryPoints: this._graph.entryPoints,
57
33
  transformOptions: this._options.transformOptions,
@@ -60,22 +36,11 @@ class DeltaCalculator extends EventEmitter {
60
36
  this._deletedFiles = new Set();
61
37
  this._addedFiles = new Set();
62
38
  }
63
-
64
- /**
65
- * Main method to calculate the delta of modules. It returns a DeltaResult,
66
- * which contain the modified/added modules and the removed modules.
67
- */
68
39
  async getDelta({ reset, shallow }) {
69
40
  debug("Calculating delta (reset: %s, shallow: %s)", reset, shallow);
70
- // If there is already a build in progress, wait until it finish to start
71
- // processing a new one (delta server doesn't support concurrent builds).
72
41
  if (this._currentBuildPromise) {
73
42
  await this._currentBuildPromise;
74
43
  }
75
-
76
- // We don't want the modified files Set to be modified while building the
77
- // bundle, so we isolate them by using the current instance for the bundling
78
- // and creating a new instance for the file watcher.
79
44
  const modifiedFiles = this._modifiedFiles;
80
45
  this._modifiedFiles = new Set();
81
46
  const deletedFiles = this._deletedFiles;
@@ -84,10 +49,6 @@ class DeltaCalculator extends EventEmitter {
84
49
  this._addedFiles = new Set();
85
50
  const requiresReset = this._requiresReset;
86
51
  this._requiresReset = false;
87
-
88
- // Revisit all files if changes require a graph reset - resolutions may be
89
- // invalidated but we don't yet know which. This should be optimized in the
90
- // future.
91
52
  if (requiresReset) {
92
53
  const markModified = (file) => {
93
54
  if (!addedFiles.has(file) && !deletedFiles.has(file)) {
@@ -97,10 +58,6 @@ class DeltaCalculator extends EventEmitter {
97
58
  this._graph.dependencies.forEach((_, key) => markModified(key));
98
59
  this._graph.entryPoints.forEach(markModified);
99
60
  }
100
-
101
- // Concurrent requests should reuse the same bundling process. To do so,
102
- // this method stores the promise as an instance variable, and then it's
103
- // removed after it gets resolved.
104
61
  this._currentBuildPromise = this._getChangedDependencies(
105
62
  modifiedFiles,
106
63
  deletedFiles,
@@ -110,10 +67,6 @@ class DeltaCalculator extends EventEmitter {
110
67
  try {
111
68
  result = await this._currentBuildPromise;
112
69
  } catch (error) {
113
- // In case of error, we don't want to mark the modified files as
114
- // processed (since we haven't actually created any delta). If we do not
115
- // do so, asking for a delta after an error will produce an empty Delta,
116
- // which is not correct.
117
70
  modifiedFiles.forEach((file) => this._modifiedFiles.add(file));
118
71
  deletedFiles.forEach((file) => this._deletedFiles.add(file));
119
72
  addedFiles.forEach((file) => this._addedFiles.add(file));
@@ -121,8 +74,6 @@ class DeltaCalculator extends EventEmitter {
121
74
  } finally {
122
75
  this._currentBuildPromise = null;
123
76
  }
124
-
125
- // Return all the modules if the client requested a reset delta.
126
77
  if (reset) {
127
78
  this._graph.reorderGraph({
128
79
  shallow,
@@ -136,29 +87,14 @@ class DeltaCalculator extends EventEmitter {
136
87
  }
137
88
  return result;
138
89
  }
139
-
140
- /**
141
- * Returns the graph with all the dependencies. Each module contains the
142
- * needed information to do the traversing (dependencies, inverseDependencies)
143
- * plus some metadata.
144
- */
145
90
  getGraph() {
146
91
  return this._graph;
147
92
  }
148
-
149
- /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
150
- * LTI update could not be added via codemod */
151
93
  _handleMultipleFileChanges = (changeEvent) => {
152
94
  changeEvent.eventsQueue.forEach((eventInfo) => {
153
95
  this._handleFileChange(eventInfo, changeEvent.logger);
154
96
  });
155
97
  };
156
-
157
- /**
158
- * Handles a single file change. To avoid doing any work before it's needed,
159
- * the listener only stores the modified file, which will then be used later
160
- * when the delta needs to be calculated.
161
- */
162
98
  _handleFileChange = ({ type, filePath, metadata }, logger) => {
163
99
  debug("Handling %s: %s (type: %s)", type, filePath, metadata.type);
164
100
  if (
@@ -183,11 +119,8 @@ class DeltaCalculator extends EventEmitter {
183
119
  if (type === "delete") {
184
120
  nextState = "deleted";
185
121
  } else if (type === "add") {
186
- // A deleted+added file is modified
187
122
  nextState = state === "deleted" ? "modified" : "added";
188
123
  } else {
189
- // type === 'change'
190
- // An added+modified file is added
191
124
  nextState = state === "added" ? "added" : "modified";
192
125
  }
193
126
  switch (nextState) {
@@ -209,9 +142,6 @@ class DeltaCalculator extends EventEmitter {
209
142
  default:
210
143
  nextState;
211
144
  }
212
-
213
- // Notify users that there is a change in some of the bundle files. This
214
- // way the client can choose to refetch the bundle.
215
145
  this.emit("change", {
216
146
  logger,
217
147
  });
@@ -228,39 +158,23 @@ class DeltaCalculator extends EventEmitter {
228
158
  reset: true,
229
159
  };
230
160
  }
231
-
232
- // If a file has been deleted, we want to invalidate any other file that
233
- // depends on it, so we can process it and correctly return an error.
234
161
  deletedFiles.forEach((filePath) => {
235
162
  for (const modifiedModulePath of this._graph.getModifiedModulesForDeletedPath(
236
163
  filePath
237
164
  )) {
238
- // Only mark the inverse dependency as modified if it's not already
239
- // marked as deleted (in that case we can just ignore it).
240
165
  if (!deletedFiles.has(modifiedModulePath)) {
241
166
  modifiedFiles.add(modifiedModulePath);
242
167
  }
243
168
  }
244
169
  });
245
-
246
- // NOTE(EvanBacon): This check adds extra complexity so we feature gate it
247
- // to enable users to opt out.
248
170
  if (this._options.unstable_allowRequireContext) {
249
- // Check if any added or removed files are matched in a context module.
250
- // We only need to do this for added files because (1) deleted files will have a context
251
- // module as an inverse dependency, (2) modified files don't invalidate the contents
252
- // of the context module.
253
171
  addedFiles.forEach((filePath) => {
254
172
  this._graph.markModifiedContextModules(filePath, modifiedFiles);
255
173
  });
256
174
  }
257
-
258
- // We only want to process files that are in the bundle.
259
175
  const modifiedDependencies = Array.from(modifiedFiles).filter((filePath) =>
260
176
  this._graph.dependencies.has(filePath)
261
177
  );
262
-
263
- // No changes happened. Return empty delta.
264
178
  if (modifiedDependencies.length === 0) {
265
179
  return {
266
180
  added: new Map(),