metro 0.82.4 → 0.83.0

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 (76) hide show
  1. package/package.json +18 -21
  2. package/src/DeltaBundler/DeltaCalculator.js +5 -1
  3. package/src/DeltaBundler/Graph.js +37 -10
  4. package/src/DeltaBundler/Graph.js.flow +49 -22
  5. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +1 -0
  6. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +4 -1
  7. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +5 -1
  8. package/src/DeltaBundler/Serializers/helpers/js.js +4 -0
  9. package/src/DeltaBundler/Serializers/helpers/js.js.flow +6 -0
  10. package/src/DeltaBundler/Transformer.js +5 -2
  11. package/src/DeltaBundler/Transformer.js.flow +3 -2
  12. package/src/DeltaBundler/Worker.d.ts +7 -9
  13. package/src/DeltaBundler/Worker.flow.js.flow +2 -2
  14. package/src/DeltaBundler/WorkerFarm.js +2 -2
  15. package/src/DeltaBundler/WorkerFarm.js.flow +2 -6
  16. package/src/DeltaBundler/buildSubgraph.js +21 -15
  17. package/src/DeltaBundler/buildSubgraph.js.flow +21 -21
  18. package/src/DeltaBundler/getTransformCacheKey.js +1 -1
  19. package/src/DeltaBundler/getTransformCacheKey.js.flow +1 -1
  20. package/src/DeltaBundler/types.flow.js +5 -1
  21. package/src/DeltaBundler/types.flow.js.flow +7 -1
  22. package/src/ModuleGraph/worker/JsFileWrapping.js +39 -9
  23. package/src/ModuleGraph/worker/JsFileWrapping.js.flow +32 -5
  24. package/src/ModuleGraph/worker/collectDependencies.js.flow +7 -1
  25. package/src/Server/symbolicate.js +4 -2
  26. package/src/Server/symbolicate.js.flow +4 -2
  27. package/src/Server.d.ts +6 -1
  28. package/src/Server.js +51 -14
  29. package/src/Server.js.flow +75 -21
  30. package/src/commands/build.js +5 -1
  31. package/src/commands/serve.js +4 -1
  32. package/src/commands/serve.js.flow +4 -1
  33. package/src/index.d.ts +13 -7
  34. package/src/index.flow.js +9 -3
  35. package/src/index.flow.js.flow +69 -63
  36. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +5 -1
  37. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +5 -1
  38. package/src/integration_tests/basic_bundle/import-export/index.js +11 -3
  39. package/src/integration_tests/basic_bundle/optional-dependencies/index.js +20 -0
  40. package/src/integration_tests/basic_bundle/optional-dependencies/index.js.flow +34 -0
  41. package/src/integration_tests/basic_bundle/optional-dependencies/optional-b.js +3 -0
  42. package/src/integration_tests/basic_bundle/optional-dependencies/optional-b.js.flow +11 -0
  43. package/src/integration_tests/basic_bundle/optional-dependencies/optional-c.js +3 -0
  44. package/src/integration_tests/basic_bundle/optional-dependencies/optional-c.js.flow +11 -0
  45. package/src/integration_tests/basic_bundle/optional-dependencies/required-a.js +3 -0
  46. package/src/integration_tests/basic_bundle/optional-dependencies/required-a.js.flow +11 -0
  47. package/src/lib/RamBundleParser.js.flow +1 -0
  48. package/src/lib/contextModule.js +5 -1
  49. package/src/lib/contextModuleTemplates.js +6 -2
  50. package/src/lib/createWebsocketServer.js +5 -1
  51. package/src/lib/createWebsocketServer.js.flow +1 -0
  52. package/src/lib/formatBundlingError.js.flow +1 -1
  53. package/src/lib/getAppendScripts.js +5 -1
  54. package/src/lib/getGraphId.js +1 -1
  55. package/src/lib/getGraphId.js.flow +1 -1
  56. package/src/lib/getPrependedScripts.js +6 -2
  57. package/src/lib/getPrependedScripts.js.flow +2 -2
  58. package/src/lib/isResolvedDependency.js +9 -0
  59. package/src/lib/isResolvedDependency.js.flow +18 -0
  60. package/src/lib/transformHelpers.js +6 -6
  61. package/src/lib/transformHelpers.js.flow +1 -5
  62. package/src/node-haste/DependencyGraph/ModuleResolution.js +2 -1
  63. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +6 -2
  64. package/src/node-haste/DependencyGraph/createFileMap.js +6 -2
  65. package/src/node-haste/DependencyGraph.js +1 -1
  66. package/src/node-haste/DependencyGraph.js.flow +5 -4
  67. package/src/node-haste/Module.js +5 -1
  68. package/src/node-haste/Package.js.flow +1 -1
  69. package/src/shared/output/RamBundle/util.js +5 -1
  70. package/src/shared/output/RamBundle/util.js.flow +3 -1
  71. package/src/shared/output/RamBundle.js.flow +2 -0
  72. package/src/shared/output/bundle.d.ts +5 -1
  73. package/src/shared/output/bundle.flow.js +8 -5
  74. package/src/shared/output/bundle.flow.js.flow +11 -5
  75. package/src/shared/types.d.ts +4 -0
  76. package/src/shared/types.flow.js.flow +12 -8
package/package.json CHANGED
@@ -1,16 +1,13 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.82.4",
3
+ "version": "0.83.0",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
9
9
  "./package.json": "./package.json",
10
- "./private/*": "./src/*.js",
11
- "./src": "./src/index.js",
12
- "./src/*.js": "./src/*.js",
13
- "./src/*": "./src/*.js"
10
+ "./private/*": "./src/*.js"
14
11
  },
15
12
  "repository": {
16
13
  "type": "git",
@@ -36,24 +33,24 @@
36
33
  "error-stack-parser": "^2.0.6",
37
34
  "flow-enums-runtime": "^0.0.6",
38
35
  "graceful-fs": "^4.2.4",
39
- "hermes-parser": "0.28.1",
36
+ "hermes-parser": "0.29.1",
40
37
  "image-size": "^1.0.2",
41
38
  "invariant": "^2.2.4",
42
39
  "jest-worker": "^29.7.0",
43
40
  "jsc-safe-url": "^0.2.2",
44
41
  "lodash.throttle": "^4.1.1",
45
- "metro-babel-transformer": "0.82.4",
46
- "metro-cache": "0.82.4",
47
- "metro-cache-key": "0.82.4",
48
- "metro-config": "0.82.4",
49
- "metro-core": "0.82.4",
50
- "metro-file-map": "0.82.4",
51
- "metro-resolver": "0.82.4",
52
- "metro-runtime": "0.82.4",
53
- "metro-source-map": "0.82.4",
54
- "metro-symbolicate": "0.82.4",
55
- "metro-transform-plugins": "0.82.4",
56
- "metro-transform-worker": "0.82.4",
42
+ "metro-babel-transformer": "0.83.0",
43
+ "metro-cache": "0.83.0",
44
+ "metro-cache-key": "0.83.0",
45
+ "metro-config": "0.83.0",
46
+ "metro-core": "0.83.0",
47
+ "metro-file-map": "0.83.0",
48
+ "metro-resolver": "0.83.0",
49
+ "metro-runtime": "0.83.0",
50
+ "metro-source-map": "0.83.0",
51
+ "metro-symbolicate": "0.83.0",
52
+ "metro-transform-plugins": "0.83.0",
53
+ "metro-transform-worker": "0.83.0",
57
54
  "mime-types": "^2.1.27",
58
55
  "nullthrows": "^1.1.1",
59
56
  "serialize-error": "^2.1.0",
@@ -72,14 +69,14 @@
72
69
  "dedent": "^0.7.0",
73
70
  "jest-snapshot": "^29.7.0",
74
71
  "jest-snapshot-serializer-raw": "^1.2.0",
75
- "metro-babel-register": "0.82.4",
76
- "metro-memory-fs": "0.82.4",
72
+ "metro-babel-register": "0.83.0",
73
+ "metro-memory-fs": "*",
77
74
  "mock-req": "^0.2.0",
78
75
  "mock-res": "^0.6.0",
79
76
  "stack-trace": "^0.0.10"
80
77
  },
81
78
  "license": "MIT",
82
79
  "engines": {
83
- "node": ">=18.18"
80
+ "node": ">=22.14"
84
81
  }
85
82
  }
@@ -3,7 +3,11 @@
3
3
  var _Graph = require("./Graph");
4
4
  var _path = _interopRequireDefault(require("path"));
5
5
  function _interopRequireDefault(e) {
6
- return e && e.__esModule ? e : { default: e };
6
+ return e && e.__esModule
7
+ ? e
8
+ : {
9
+ default: e,
10
+ };
7
11
  }
8
12
  const debug = require("debug")("Metro:DeltaCalculator");
9
13
  const { EventEmitter } = require("events");
@@ -6,9 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Graph = void 0;
7
7
  var _contextModule = require("../lib/contextModule");
8
8
  var _CountingSet = _interopRequireDefault(require("../lib/CountingSet"));
9
+ var _isResolvedDependency = require("../lib/isResolvedDependency");
9
10
  var _buildSubgraph = require("./buildSubgraph");
10
11
  function _interopRequireDefault(e) {
11
- return e && e.__esModule ? e : { default: e };
12
+ return e && e.__esModule
13
+ ? e
14
+ : {
15
+ default: e,
16
+ };
12
17
  }
13
18
  const invariant = require("invariant");
14
19
  const nullthrows = require("nullthrows");
@@ -285,13 +290,14 @@ class Graph {
285
290
  delta,
286
291
  options
287
292
  ) {
288
- const path = dependency.absolutePath;
289
- let module = this.dependencies.get(path);
290
293
  if (options.shallow) {
294
+ } else if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
291
295
  } else if (dependency.data.data.asyncType === "weak") {
292
296
  } else if (options.lazy && dependency.data.data.asyncType != null) {
293
297
  this._incrementImportBundleReference(dependency, parentModule);
294
298
  } else {
299
+ const path = dependency.absolutePath;
300
+ let module = this.dependencies.get(path);
295
301
  if (!module) {
296
302
  try {
297
303
  module = this._recursivelyCommitModule(path, delta, options);
@@ -310,19 +316,25 @@ class Graph {
310
316
  module.inverseDependencies.add(parentModule.path);
311
317
  this._markModuleInUse(module);
312
318
  }
313
- if (requireContext) {
314
- this.#resolvedContexts.set(path, requireContext);
315
- } else {
316
- this.#resolvedContexts.delete(path);
319
+ if ((0, _isResolvedDependency.isResolvedDependency)(dependency)) {
320
+ const path = dependency.absolutePath;
321
+ if (requireContext) {
322
+ this.#resolvedContexts.set(path, requireContext);
323
+ } else {
324
+ this.#resolvedContexts.delete(path);
325
+ }
317
326
  }
318
327
  parentModule.dependencies.set(key, dependency);
319
328
  }
320
329
  _removeDependency(parentModule, key, dependency, delta, options) {
321
330
  parentModule.dependencies.delete(key);
322
- const { absolutePath } = dependency;
323
- if (dependency.data.data.asyncType === "weak") {
331
+ if (
332
+ !(0, _isResolvedDependency.isResolvedDependency)(dependency) ||
333
+ dependency.data.data.asyncType === "weak"
334
+ ) {
324
335
  return;
325
336
  }
337
+ const { absolutePath } = dependency;
326
338
  const module = this.dependencies.get(absolutePath);
327
339
  if (options.lazy && dependency.data.data.asyncType != null) {
328
340
  this._decrementImportBundleReference(dependency, parentModule);
@@ -380,6 +392,9 @@ class Graph {
380
392
  }
381
393
  module.dependencies.forEach((dependency) => {
382
394
  const path = dependency.absolutePath;
395
+ if (path == null) {
396
+ return;
397
+ }
383
398
  const childModule = this.dependencies.get(path);
384
399
  if (!childModule) {
385
400
  if (dependency.data.data.asyncType != null || options.shallow) {
@@ -418,7 +433,10 @@ class Graph {
418
433
  }
419
434
  *_children(module, options) {
420
435
  for (const dependency of module.dependencies.values()) {
421
- if (isWeakOrLazy(dependency, options)) {
436
+ if (
437
+ !(0, _isResolvedDependency.isResolvedDependency)(dependency) ||
438
+ isWeakOrLazy(dependency, options)
439
+ ) {
422
440
  continue;
423
441
  }
424
442
  yield nullthrows(this.dependencies.get(dependency.absolutePath));
@@ -429,6 +447,9 @@ class Graph {
429
447
  module;
430
448
  const resolvedContexts = new Map();
431
449
  for (const [key, dependency] of dependencies) {
450
+ if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
451
+ continue;
452
+ }
432
453
  const resolvedContext = this.#resolvedContexts.get(
433
454
  dependency.absolutePath
434
455
  );
@@ -452,6 +473,9 @@ class Graph {
452
473
  delta.baseModuleData.set(module.path, this._moduleSnapshot(module));
453
474
  }
454
475
  for (const [key, dependency] of module.dependencies) {
476
+ if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
477
+ continue;
478
+ }
455
479
  this._removeDependency(module, key, dependency, delta, options);
456
480
  }
457
481
  this.#gc.color.set(module.path, "black");
@@ -542,6 +566,9 @@ class Graph {
542
566
  if (color === "white" && !this.#gc.possibleCycleRoots.has(module.path)) {
543
567
  this.#gc.color.set(module.path, "black");
544
568
  for (const dependency of module.dependencies.values()) {
569
+ if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
570
+ continue;
571
+ }
545
572
  const childModule = this.dependencies.get(dependency.absolutePath);
546
573
  if (childModule) {
547
574
  this._collectWhite(childModule, delta);
@@ -39,11 +39,13 @@ import type {
39
39
  Module,
40
40
  ModuleData,
41
41
  Options,
42
+ ResolvedDependency,
42
43
  TransformInputOptions,
43
44
  } from './types.flow';
44
45
 
45
46
  import {fileMatchesContext} from '../lib/contextModule';
46
47
  import CountingSet from '../lib/CountingSet';
48
+ import {isResolvedDependency} from '../lib/isResolvedDependency';
47
49
  import {buildSubgraph} from './buildSubgraph';
48
50
 
49
51
  const invariant = require('invariant');
@@ -121,7 +123,7 @@ function getInternalOptions<T>({
121
123
  }
122
124
 
123
125
  function isWeakOrLazy<T>(
124
- dependency: Dependency,
126
+ dependency: ResolvedDependency,
125
127
  options: InternalOptions<T>,
126
128
  ): boolean {
127
129
  const asyncType = dependency.data.data.asyncType;
@@ -355,7 +357,7 @@ export class Graph<T = MixedOutput> {
355
357
  options.onDependencyAdded();
356
358
  return result;
357
359
  },
358
- shouldTraverse: (dependency: Dependency) => {
360
+ shouldTraverse: (dependency: ResolvedDependency) => {
359
361
  if (options.shallow || isWeakOrLazy(dependency, options)) {
360
362
  return false;
361
363
  }
@@ -510,14 +512,11 @@ export class Graph<T = MixedOutput> {
510
512
  delta: Delta<T>,
511
513
  options: InternalOptions<T>,
512
514
  ): void {
513
- const path = dependency.absolutePath;
514
-
515
- // The module may already exist, in which case we just need to update some
516
- // bookkeeping instead of adding a new node to the graph.
517
- let module = this.dependencies.get(path);
518
-
519
515
  if (options.shallow) {
520
516
  // Don't add a node for the module if the graph is shallow (single-module).
517
+ } else if (!isResolvedDependency(dependency)) {
518
+ // If the dependency is a missing optional dependency, it has no node of
519
+ // its own. We just need to add it to the parent's dependency map.
521
520
  } else if (dependency.data.data.asyncType === 'weak') {
522
521
  // Exclude weak dependencies from the bundle.
523
522
  } else if (options.lazy && dependency.data.data.asyncType != null) {
@@ -526,6 +525,11 @@ export class Graph<T = MixedOutput> {
526
525
  // importBundleNodes.
527
526
  this._incrementImportBundleReference(dependency, parentModule);
528
527
  } else {
528
+ // The module may already exist, in which case we just need to update some
529
+ // bookkeeping instead of adding a new node to the graph.
530
+ const path = dependency.absolutePath;
531
+ let module = this.dependencies.get(path);
532
+
529
533
  if (!module) {
530
534
  try {
531
535
  module = this._recursivelyCommitModule(path, delta, options);
@@ -550,12 +554,15 @@ export class Graph<T = MixedOutput> {
550
554
  this._markModuleInUse(module);
551
555
  }
552
556
 
553
- if (requireContext) {
554
- this.#resolvedContexts.set(path, requireContext);
555
- } else {
556
- // This dependency may have existed previously as a require.context -
557
- // clean it up.
558
- this.#resolvedContexts.delete(path);
557
+ if (isResolvedDependency(dependency)) {
558
+ const path = dependency.absolutePath;
559
+ if (requireContext) {
560
+ this.#resolvedContexts.set(path, requireContext);
561
+ } else {
562
+ // This dependency may have existed previously as a require.context -
563
+ // clean it up.
564
+ this.#resolvedContexts.delete(path);
565
+ }
559
566
  }
560
567
 
561
568
  // Update the parent's dependency map unless we failed to add a dependency.
@@ -574,13 +581,16 @@ export class Graph<T = MixedOutput> {
574
581
  ): void {
575
582
  parentModule.dependencies.delete(key);
576
583
 
577
- const {absolutePath} = dependency;
578
-
579
- if (dependency.data.data.asyncType === 'weak') {
580
- // Weak dependencies are excluded from the bundle.
584
+ if (
585
+ !isResolvedDependency(dependency) ||
586
+ dependency.data.data.asyncType === 'weak'
587
+ ) {
588
+ // Weak and unresolved dependencies are excluded from the bundle.
581
589
  return;
582
590
  }
583
591
 
592
+ const {absolutePath} = dependency;
593
+
584
594
  const module = this.dependencies.get(absolutePath);
585
595
 
586
596
  if (options.lazy && dependency.data.data.asyncType != null) {
@@ -671,8 +681,12 @@ export class Graph<T = MixedOutput> {
671
681
  orderedDependencies.set(module.path, module);
672
682
  }
673
683
 
674
- module.dependencies.forEach((dependency: Dependency) => {
684
+ module.dependencies.forEach(dependency => {
675
685
  const path = dependency.absolutePath;
686
+ if (path == null) {
687
+ // If the dependency is not a missing optional dependency, it has no children to reorder.
688
+ return;
689
+ }
676
690
  const childModule = this.dependencies.get(path);
677
691
 
678
692
  if (!childModule) {
@@ -691,7 +705,7 @@ export class Graph<T = MixedOutput> {
691
705
 
692
706
  // Add an entry to importBundleNodes (or record an inverse dependency of an existing one)
693
707
  _incrementImportBundleReference(
694
- dependency: Dependency,
708
+ dependency: ResolvedDependency,
695
709
  parentModule: Module<T>,
696
710
  ) {
697
711
  const {absolutePath} = dependency;
@@ -704,7 +718,7 @@ export class Graph<T = MixedOutput> {
704
718
 
705
719
  // Decrease the reference count of an entry in importBundleNodes (and delete it if necessary)
706
720
  _decrementImportBundleReference(
707
- dependency: Dependency,
721
+ dependency: ResolvedDependency,
708
722
  parentModule: Module<T>,
709
723
  ) {
710
724
  const {absolutePath} = dependency;
@@ -734,7 +748,10 @@ export class Graph<T = MixedOutput> {
734
748
  options: InternalOptions<T>,
735
749
  ): Iterator<Module<T>> {
736
750
  for (const dependency of module.dependencies.values()) {
737
- if (isWeakOrLazy(dependency, options)) {
751
+ if (
752
+ !isResolvedDependency(dependency) ||
753
+ isWeakOrLazy(dependency, options)
754
+ ) {
738
755
  continue;
739
756
  }
740
757
  yield nullthrows(this.dependencies.get(dependency.absolutePath));
@@ -747,6 +764,9 @@ export class Graph<T = MixedOutput> {
747
764
 
748
765
  const resolvedContexts: Map<string, RequireContext> = new Map();
749
766
  for (const [key, dependency] of dependencies) {
767
+ if (!isResolvedDependency(dependency)) {
768
+ continue;
769
+ }
750
770
  const resolvedContext = this.#resolvedContexts.get(
751
771
  dependency.absolutePath,
752
772
  );
@@ -783,6 +803,10 @@ export class Graph<T = MixedOutput> {
783
803
  }
784
804
 
785
805
  for (const [key, dependency] of module.dependencies) {
806
+ if (!isResolvedDependency(dependency)) {
807
+ // If the dependency is not a missing optional dependency, it has no children to remove.
808
+ continue;
809
+ }
786
810
  this._removeDependency(module, key, dependency, delta, options);
787
811
  }
788
812
  this.#gc.color.set(module.path, 'black');
@@ -894,6 +918,9 @@ export class Graph<T = MixedOutput> {
894
918
  if (color === 'white' && !this.#gc.possibleCycleRoots.has(module.path)) {
895
919
  this.#gc.color.set(module.path, 'black');
896
920
  for (const dependency of module.dependencies.values()) {
921
+ if (!isResolvedDependency(dependency)) {
922
+ continue;
923
+ }
897
924
  const childModule = this.dependencies.get(dependency.absolutePath);
898
925
  // The child may already have been collected.
899
926
  if (childModule) {
@@ -169,6 +169,7 @@ async function _getRamOptions(
169
169
  );
170
170
 
171
171
  return {
172
+ // $FlowFixMe[sketchy-null-bool]
172
173
  preloadedModules: preloadedModules || {},
173
174
  ramGroups: ramGroups || [],
174
175
  };
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _isResolvedDependency = require("../../../lib/isResolvedDependency");
3
4
  function getTransitiveDependencies(path, graph) {
4
5
  const dependencies = _getDeps(path, graph, new Set());
5
6
  dependencies.delete(path);
@@ -15,7 +16,9 @@ function _getDeps(path, graph, deps) {
15
16
  }
16
17
  deps.add(path);
17
18
  for (const dependency of module.dependencies.values()) {
18
- _getDeps(dependency.absolutePath, graph, deps);
19
+ if ((0, _isResolvedDependency.isResolvedDependency)(dependency)) {
20
+ _getDeps(dependency.absolutePath, graph, deps);
21
+ }
19
22
  }
20
23
  return deps;
21
24
  }
@@ -13,6 +13,8 @@
13
13
 
14
14
  import type {ReadOnlyGraph} from '../../types.flow';
15
15
 
16
+ import {isResolvedDependency} from '../../../lib/isResolvedDependency';
17
+
16
18
  function getTransitiveDependencies<T>(
17
19
  path: string,
18
20
  graph: ReadOnlyGraph<T>,
@@ -44,7 +46,9 @@ function _getDeps<T>(
44
46
  deps.add(path);
45
47
 
46
48
  for (const dependency of module.dependencies.values()) {
47
- _getDeps(dependency.absolutePath, graph, deps);
49
+ if (isResolvedDependency(dependency)) {
50
+ _getDeps(dependency.absolutePath, graph, deps);
51
+ }
48
52
  }
49
53
 
50
54
  return deps;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ const { isResolvedDependency } = require("../../../lib/isResolvedDependency");
3
4
  const invariant = require("invariant");
4
5
  const jscSafeUrl = require("jsc-safe-url");
5
6
  const { addParamsToDefineCall } = require("metro-transform-plugins");
@@ -18,6 +19,9 @@ function getModuleParams(module, options) {
18
19
  let hasPaths = false;
19
20
  const dependencyMapArray = Array.from(module.dependencies.values()).map(
20
21
  (dependency) => {
22
+ if (!isResolvedDependency(dependency)) {
23
+ return null;
24
+ }
21
25
  const id = options.createModuleId(dependency.absolutePath);
22
26
  if (options.includeAsyncPaths && dependency.data.data.asyncType != null) {
23
27
  hasPaths = true;
@@ -14,6 +14,7 @@
14
14
  import type {MixedOutput, Module} from '../../types.flow';
15
15
  import type {JsOutput} from 'metro-transform-worker';
16
16
 
17
+ const {isResolvedDependency} = require('../../../lib/isResolvedDependency');
17
18
  const invariant = require('invariant');
18
19
  const jscSafeUrl = require('jsc-safe-url');
19
20
  const {addParamsToDefineCall} = require('metro-transform-plugins');
@@ -47,6 +48,11 @@ function getModuleParams(module: Module<>, options: Options): Array<mixed> {
47
48
  let hasPaths = false;
48
49
  const dependencyMapArray = Array.from(module.dependencies.values()).map(
49
50
  dependency => {
51
+ if (!isResolvedDependency(dependency)) {
52
+ // An unresolved dependency, which should cause a runtime error
53
+ // when required.
54
+ return null;
55
+ }
50
56
  const id = options.createModuleId(dependency.absolutePath);
51
57
  if (options.includeAsyncPaths && dependency.data.data.asyncType != null) {
52
58
  hasPaths = true;
@@ -2,7 +2,11 @@
2
2
 
3
3
  var _crypto = _interopRequireDefault(require("crypto"));
4
4
  function _interopRequireDefault(e) {
5
- return e && e.__esModule ? e : { default: e };
5
+ return e && e.__esModule
6
+ ? e
7
+ : {
8
+ default: e,
9
+ };
6
10
  }
7
11
  const getTransformCacheKey = require("./getTransformCacheKey");
8
12
  const WorkerFarm = require("./WorkerFarm");
@@ -20,7 +24,6 @@ class Transformer {
20
24
  const {
21
25
  getTransformOptions: _getTransformOptions,
22
26
  transformVariants: _transformVariants,
23
- workerPath: _workerPath,
24
27
  unstable_workerThreads: _workerThreads,
25
28
  ...transformerConfig
26
29
  } = this._config.transformer;
@@ -25,7 +25,9 @@ const fs = require('fs');
25
25
  const {Cache, stableHash} = require('metro-cache');
26
26
  const path = require('path');
27
27
 
28
- type GetOrComputeSha1Fn = string => Promise<{content?: Buffer, sha1: string}>;
28
+ type GetOrComputeSha1Fn = string => Promise<
29
+ $ReadOnly<{content?: Buffer, sha1: string}>,
30
+ >;
29
31
 
30
32
  class Transformer {
31
33
  _config: ConfigT;
@@ -50,7 +52,6 @@ class Transformer {
50
52
  const {
51
53
  getTransformOptions: _getTransformOptions,
52
54
  transformVariants: _transformVariants,
53
- workerPath: _workerPath,
54
55
  unstable_workerThreads: _workerThreads,
55
56
  ...transformerConfig
56
57
  } = this._config.transformer;
@@ -18,16 +18,14 @@ type LogEntry = unknown;
18
18
 
19
19
  export type TransformOptions = JsTransformOptions;
20
20
 
21
- declare function transform(
22
- filename: string,
23
- transformOptions: JsTransformOptions,
24
- projectRoot: string,
25
- transformerConfig: TransformerConfig,
26
- fileBuffer?: Buffer,
27
- ): Promise<Data>;
28
-
29
21
  export interface Worker {
30
- readonly transform: typeof transform;
22
+ readonly transform: (
23
+ filename: string,
24
+ transformOptions: JsTransformOptions,
25
+ projectRoot: string,
26
+ transformerConfig: TransformerConfig,
27
+ fileBuffer?: Buffer,
28
+ ) => Promise<Data>;
31
29
  }
32
30
 
33
31
  export interface TransformerConfig {
@@ -12,7 +12,7 @@
12
12
  'use strict';
13
13
 
14
14
  import type {TransformResult} from './types.flow';
15
- import type {LogEntry} from 'metro-core/src/Logger';
15
+ import type {LogEntry} from 'metro-core/private/Logger';
16
16
  import type {
17
17
  JsTransformerConfig,
18
18
  JsTransformOptions,
@@ -109,7 +109,7 @@ async function transformFile(
109
109
  transformerConfig.transformerPath,
110
110
  );
111
111
 
112
- const transformFileStartLogEntry = {
112
+ const transformFileStartLogEntry: LogEntry = {
113
113
  action_name: 'Transforming file',
114
114
  action_phase: 'start',
115
115
  file_name: filename,
@@ -6,7 +6,7 @@ class WorkerFarm {
6
6
  constructor(config, transformerConfig) {
7
7
  this._config = config;
8
8
  this._transformerConfig = transformerConfig;
9
- const absoluteWorkerPath = require.resolve(config.transformer.workerPath);
9
+ const absoluteWorkerPath = require.resolve("./Worker.js");
10
10
  if (this._config.maxWorkers > 1) {
11
11
  const worker = this._makeFarm(
12
12
  absoluteWorkerPath,
@@ -27,7 +27,7 @@ class WorkerFarm {
27
27
  });
28
28
  this._worker = worker;
29
29
  } else {
30
- this._worker = require.call(null, this._config.transformer.workerPath);
30
+ this._worker = require("./Worker");
31
31
  }
32
32
  }
33
33
  async kill() {
@@ -39,7 +39,7 @@ class WorkerFarm {
39
39
  constructor(config: ConfigT, transformerConfig: TransformerConfig) {
40
40
  this._config = config;
41
41
  this._transformerConfig = transformerConfig;
42
- const absoluteWorkerPath = require.resolve(config.transformer.workerPath);
42
+ const absoluteWorkerPath = require.resolve('./Worker.js');
43
43
 
44
44
  if (this._config.maxWorkers > 1) {
45
45
  const worker = this._makeFarm(
@@ -63,11 +63,7 @@ class WorkerFarm {
63
63
 
64
64
  this._worker = worker;
65
65
  } else {
66
- // eslint-disable-next-line no-useless-call
67
- this._worker = (require.call(
68
- null,
69
- this._config.transformer.workerPath,
70
- ): Worker);
66
+ this._worker = (require('./Worker'): Worker);
71
67
  }
72
68
  }
73
69
 
@@ -5,15 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildSubgraph = buildSubgraph;
7
7
  var _contextModule = require("../lib/contextModule");
8
+ var _isResolvedDependency = require("../lib/isResolvedDependency");
8
9
  var _path = _interopRequireDefault(require("path"));
9
10
  function _interopRequireDefault(e) {
10
- return e && e.__esModule ? e : { default: e };
11
+ return e && e.__esModule
12
+ ? e
13
+ : {
14
+ default: e,
15
+ };
11
16
  }
12
17
  function resolveDependencies(parentPath, dependencies, resolve) {
13
18
  const maybeResolvedDeps = new Map();
14
19
  const resolvedContexts = new Map();
15
20
  for (const dep of dependencies) {
16
- let resolvedDep;
21
+ let maybeResolvedDep;
17
22
  const key = dep.data.key;
18
23
  const { contextParams } = dep.data;
19
24
  if (contextParams) {
@@ -32,13 +37,13 @@ function resolveDependencies(parentPath, dependencies, resolve) {
32
37
  ),
33
38
  };
34
39
  resolvedContexts.set(key, resolvedContext);
35
- resolvedDep = {
40
+ maybeResolvedDep = {
36
41
  absolutePath,
37
42
  data: dep,
38
43
  };
39
44
  } else {
40
45
  try {
41
- resolvedDep = {
46
+ maybeResolvedDep = {
42
47
  absolutePath: resolve(parentPath, dep).filePath,
43
48
  data: dep,
44
49
  };
@@ -46,6 +51,9 @@ function resolveDependencies(parentPath, dependencies, resolve) {
46
51
  if (dep.data.isOptional !== true) {
47
52
  throw error;
48
53
  }
54
+ maybeResolvedDep = {
55
+ data: dep,
56
+ };
49
57
  }
50
58
  }
51
59
  if (maybeResolvedDeps.has(key)) {
@@ -53,16 +61,10 @@ function resolveDependencies(parentPath, dependencies, resolve) {
53
61
  `resolveDependencies: Found duplicate dependency key '${key}' in ${parentPath}`
54
62
  );
55
63
  }
56
- maybeResolvedDeps.set(key, resolvedDep);
57
- }
58
- const resolvedDeps = new Map();
59
- for (const [key, resolvedDep] of maybeResolvedDeps) {
60
- if (resolvedDep) {
61
- resolvedDeps.set(key, resolvedDep);
62
- }
64
+ maybeResolvedDeps.set(key, maybeResolvedDep);
63
65
  }
64
66
  return {
65
- dependencies: resolvedDeps,
67
+ dependencies: maybeResolvedDeps,
66
68
  resolvedContexts,
67
69
  };
68
70
  }
@@ -90,9 +92,13 @@ async function buildSubgraph(
90
92
  ...resolutionResult,
91
93
  });
92
94
  await Promise.all(
93
- [...resolutionResult.dependencies]
94
- .filter(([key, dependency]) => shouldTraverse(dependency))
95
- .map(([key, dependency]) =>
95
+ [...resolutionResult.dependencies.values()]
96
+ .filter(
97
+ (dependency) =>
98
+ (0, _isResolvedDependency.isResolvedDependency)(dependency) &&
99
+ shouldTraverse(dependency)
100
+ )
101
+ .map((dependency) =>
96
102
  visit(
97
103
  dependency.absolutePath,
98
104
  resolutionResult.resolvedContexts.get(dependency.data.data.key)