metro 0.82.3 → 0.82.5
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.
- package/package.json +16 -16
- package/src/DeltaBundler/Graph.js +32 -9
- package/src/DeltaBundler/Graph.js.flow +49 -22
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +1 -0
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +4 -1
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +5 -1
- package/src/DeltaBundler/Serializers/helpers/js.js +4 -0
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +6 -0
- package/src/DeltaBundler/Transformer.js +4 -1
- package/src/DeltaBundler/Transformer.js.flow +7 -2
- package/src/DeltaBundler/Worker.flow.js.flow +1 -1
- package/src/DeltaBundler/buildSubgraph.js +16 -14
- package/src/DeltaBundler/buildSubgraph.js.flow +21 -21
- package/src/DeltaBundler/types.flow.js.flow +7 -1
- package/src/ModuleGraph/worker/JsFileWrapping.js +28 -6
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +32 -5
- package/src/ModuleGraph/worker/collectDependencies.js.flow +6 -0
- package/src/Server.d.ts +6 -1
- package/src/Server.js +51 -14
- package/src/Server.js.flow +73 -19
- package/src/index.d.ts +5 -2
- package/src/index.flow.js +15 -5
- package/src/index.flow.js.flow +21 -5
- package/src/integration_tests/basic_bundle/optional-dependencies/index.js +20 -0
- package/src/integration_tests/basic_bundle/optional-dependencies/index.js.flow +34 -0
- package/src/integration_tests/basic_bundle/optional-dependencies/optional-b.js +3 -0
- package/src/integration_tests/basic_bundle/optional-dependencies/optional-b.js.flow +11 -0
- package/src/integration_tests/basic_bundle/optional-dependencies/optional-c.js +3 -0
- package/src/integration_tests/basic_bundle/optional-dependencies/optional-c.js.flow +11 -0
- package/src/integration_tests/basic_bundle/optional-dependencies/required-a.js +3 -0
- package/src/integration_tests/basic_bundle/optional-dependencies/required-a.js.flow +11 -0
- package/src/lib/RamBundleParser.js.flow +1 -0
- package/src/lib/createWebsocketServer.js.flow +1 -0
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/isResolvedDependency.js +9 -0
- package/src/lib/isResolvedDependency.js.flow +18 -0
- package/src/lib/transformHelpers.js +0 -4
- package/src/lib/transformHelpers.js.flow +0 -4
- package/src/node-haste/DependencyGraph/ModuleResolution.js +1 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +4 -0
- package/src/node-haste/DependencyGraph.js.flow +2 -1
- package/src/shared/output/RamBundle/util.js.flow +3 -1
- package/src/shared/output/RamBundle.js.flow +2 -0
- package/src/shared/output/bundle.d.ts +5 -1
- package/src/shared/output/bundle.flow.js +8 -5
- package/src/shared/output/bundle.flow.js.flow +11 -5
- package/src/shared/types.d.ts +4 -0
- package/src/shared/types.flow.js.flow +12 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.82.
|
|
3
|
+
"version": "0.82.5",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -36,24 +36,24 @@
|
|
|
36
36
|
"error-stack-parser": "^2.0.6",
|
|
37
37
|
"flow-enums-runtime": "^0.0.6",
|
|
38
38
|
"graceful-fs": "^4.2.4",
|
|
39
|
-
"hermes-parser": "0.
|
|
39
|
+
"hermes-parser": "0.29.1",
|
|
40
40
|
"image-size": "^1.0.2",
|
|
41
41
|
"invariant": "^2.2.4",
|
|
42
42
|
"jest-worker": "^29.7.0",
|
|
43
43
|
"jsc-safe-url": "^0.2.2",
|
|
44
44
|
"lodash.throttle": "^4.1.1",
|
|
45
|
-
"metro-babel-transformer": "0.82.
|
|
46
|
-
"metro-cache": "0.82.
|
|
47
|
-
"metro-cache-key": "0.82.
|
|
48
|
-
"metro-config": "0.82.
|
|
49
|
-
"metro-core": "0.82.
|
|
50
|
-
"metro-file-map": "0.82.
|
|
51
|
-
"metro-resolver": "0.82.
|
|
52
|
-
"metro-runtime": "0.82.
|
|
53
|
-
"metro-source-map": "0.82.
|
|
54
|
-
"metro-symbolicate": "0.82.
|
|
55
|
-
"metro-transform-plugins": "0.82.
|
|
56
|
-
"metro-transform-worker": "0.82.
|
|
45
|
+
"metro-babel-transformer": "0.82.5",
|
|
46
|
+
"metro-cache": "0.82.5",
|
|
47
|
+
"metro-cache-key": "0.82.5",
|
|
48
|
+
"metro-config": "0.82.5",
|
|
49
|
+
"metro-core": "0.82.5",
|
|
50
|
+
"metro-file-map": "0.82.5",
|
|
51
|
+
"metro-resolver": "0.82.5",
|
|
52
|
+
"metro-runtime": "0.82.5",
|
|
53
|
+
"metro-source-map": "0.82.5",
|
|
54
|
+
"metro-symbolicate": "0.82.5",
|
|
55
|
+
"metro-transform-plugins": "0.82.5",
|
|
56
|
+
"metro-transform-worker": "0.82.5",
|
|
57
57
|
"mime-types": "^2.1.27",
|
|
58
58
|
"nullthrows": "^1.1.1",
|
|
59
59
|
"serialize-error": "^2.1.0",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"dedent": "^0.7.0",
|
|
73
73
|
"jest-snapshot": "^29.7.0",
|
|
74
74
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
75
|
-
"metro-babel-register": "0.82.
|
|
76
|
-
"metro-memory-fs": "0.82.
|
|
75
|
+
"metro-babel-register": "0.82.5",
|
|
76
|
+
"metro-memory-fs": "0.82.5",
|
|
77
77
|
"mock-req": "^0.2.0",
|
|
78
78
|
"mock-res": "^0.6.0",
|
|
79
79
|
"stack-trace": "^0.0.10"
|
|
@@ -6,6 +6,7 @@ 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
12
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -285,13 +286,14 @@ class Graph {
|
|
|
285
286
|
delta,
|
|
286
287
|
options
|
|
287
288
|
) {
|
|
288
|
-
const path = dependency.absolutePath;
|
|
289
|
-
let module = this.dependencies.get(path);
|
|
290
289
|
if (options.shallow) {
|
|
290
|
+
} else if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
|
|
291
291
|
} else if (dependency.data.data.asyncType === "weak") {
|
|
292
292
|
} else if (options.lazy && dependency.data.data.asyncType != null) {
|
|
293
293
|
this._incrementImportBundleReference(dependency, parentModule);
|
|
294
294
|
} else {
|
|
295
|
+
const path = dependency.absolutePath;
|
|
296
|
+
let module = this.dependencies.get(path);
|
|
295
297
|
if (!module) {
|
|
296
298
|
try {
|
|
297
299
|
module = this._recursivelyCommitModule(path, delta, options);
|
|
@@ -310,19 +312,25 @@ class Graph {
|
|
|
310
312
|
module.inverseDependencies.add(parentModule.path);
|
|
311
313
|
this._markModuleInUse(module);
|
|
312
314
|
}
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
if ((0, _isResolvedDependency.isResolvedDependency)(dependency)) {
|
|
316
|
+
const path = dependency.absolutePath;
|
|
317
|
+
if (requireContext) {
|
|
318
|
+
this.#resolvedContexts.set(path, requireContext);
|
|
319
|
+
} else {
|
|
320
|
+
this.#resolvedContexts.delete(path);
|
|
321
|
+
}
|
|
317
322
|
}
|
|
318
323
|
parentModule.dependencies.set(key, dependency);
|
|
319
324
|
}
|
|
320
325
|
_removeDependency(parentModule, key, dependency, delta, options) {
|
|
321
326
|
parentModule.dependencies.delete(key);
|
|
322
|
-
|
|
323
|
-
|
|
327
|
+
if (
|
|
328
|
+
!(0, _isResolvedDependency.isResolvedDependency)(dependency) ||
|
|
329
|
+
dependency.data.data.asyncType === "weak"
|
|
330
|
+
) {
|
|
324
331
|
return;
|
|
325
332
|
}
|
|
333
|
+
const { absolutePath } = dependency;
|
|
326
334
|
const module = this.dependencies.get(absolutePath);
|
|
327
335
|
if (options.lazy && dependency.data.data.asyncType != null) {
|
|
328
336
|
this._decrementImportBundleReference(dependency, parentModule);
|
|
@@ -380,6 +388,9 @@ class Graph {
|
|
|
380
388
|
}
|
|
381
389
|
module.dependencies.forEach((dependency) => {
|
|
382
390
|
const path = dependency.absolutePath;
|
|
391
|
+
if (path == null) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
383
394
|
const childModule = this.dependencies.get(path);
|
|
384
395
|
if (!childModule) {
|
|
385
396
|
if (dependency.data.data.asyncType != null || options.shallow) {
|
|
@@ -418,7 +429,10 @@ class Graph {
|
|
|
418
429
|
}
|
|
419
430
|
*_children(module, options) {
|
|
420
431
|
for (const dependency of module.dependencies.values()) {
|
|
421
|
-
if (
|
|
432
|
+
if (
|
|
433
|
+
!(0, _isResolvedDependency.isResolvedDependency)(dependency) ||
|
|
434
|
+
isWeakOrLazy(dependency, options)
|
|
435
|
+
) {
|
|
422
436
|
continue;
|
|
423
437
|
}
|
|
424
438
|
yield nullthrows(this.dependencies.get(dependency.absolutePath));
|
|
@@ -429,6 +443,9 @@ class Graph {
|
|
|
429
443
|
module;
|
|
430
444
|
const resolvedContexts = new Map();
|
|
431
445
|
for (const [key, dependency] of dependencies) {
|
|
446
|
+
if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
432
449
|
const resolvedContext = this.#resolvedContexts.get(
|
|
433
450
|
dependency.absolutePath
|
|
434
451
|
);
|
|
@@ -452,6 +469,9 @@ class Graph {
|
|
|
452
469
|
delta.baseModuleData.set(module.path, this._moduleSnapshot(module));
|
|
453
470
|
}
|
|
454
471
|
for (const [key, dependency] of module.dependencies) {
|
|
472
|
+
if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
455
475
|
this._removeDependency(module, key, dependency, delta, options);
|
|
456
476
|
}
|
|
457
477
|
this.#gc.color.set(module.path, "black");
|
|
@@ -542,6 +562,9 @@ class Graph {
|
|
|
542
562
|
if (color === "white" && !this.#gc.possibleCycleRoots.has(module.path)) {
|
|
543
563
|
this.#gc.color.set(module.path, "black");
|
|
544
564
|
for (const dependency of module.dependencies.values()) {
|
|
565
|
+
if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
545
568
|
const childModule = this.dependencies.get(dependency.absolutePath);
|
|
546
569
|
if (childModule) {
|
|
547
570
|
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:
|
|
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:
|
|
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 (
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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(
|
|
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:
|
|
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:
|
|
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 (
|
|
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) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -7,6 +7,7 @@ function _interopRequireDefault(e) {
|
|
|
7
7
|
const getTransformCacheKey = require("./getTransformCacheKey");
|
|
8
8
|
const WorkerFarm = require("./WorkerFarm");
|
|
9
9
|
const assert = require("assert");
|
|
10
|
+
const debug = require("debug")("Metro:Transformer");
|
|
10
11
|
const fs = require("fs");
|
|
11
12
|
const { Cache, stableHash } = require("metro-cache");
|
|
12
13
|
const path = require("path");
|
|
@@ -35,7 +36,9 @@ class Transformer {
|
|
|
35
36
|
projectRoot: this._config.projectRoot,
|
|
36
37
|
transformerConfig: transformerOptions,
|
|
37
38
|
});
|
|
38
|
-
|
|
39
|
+
const baseHashBuffer = stableHash([globalCacheKey]);
|
|
40
|
+
this._baseHash = baseHashBuffer.toString("binary");
|
|
41
|
+
debug("Base hash: %s", baseHashBuffer.toString("hex"));
|
|
39
42
|
}
|
|
40
43
|
async transformFile(filePath, transformerOptions, fileBuffer) {
|
|
41
44
|
const cache = this._cache;
|
|
@@ -20,11 +20,14 @@ import crypto from 'crypto';
|
|
|
20
20
|
const getTransformCacheKey = require('./getTransformCacheKey');
|
|
21
21
|
const WorkerFarm = require('./WorkerFarm');
|
|
22
22
|
const assert = require('assert');
|
|
23
|
+
const debug = require('debug')('Metro:Transformer');
|
|
23
24
|
const fs = require('fs');
|
|
24
25
|
const {Cache, stableHash} = require('metro-cache');
|
|
25
26
|
const path = require('path');
|
|
26
27
|
|
|
27
|
-
type GetOrComputeSha1Fn = string => Promise<
|
|
28
|
+
type GetOrComputeSha1Fn = string => Promise<
|
|
29
|
+
$ReadOnly<{content?: Buffer, sha1: string}>,
|
|
30
|
+
>;
|
|
28
31
|
|
|
29
32
|
class Transformer {
|
|
30
33
|
_config: ConfigT;
|
|
@@ -69,7 +72,9 @@ class Transformer {
|
|
|
69
72
|
transformerConfig: transformerOptions,
|
|
70
73
|
});
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
const baseHashBuffer = stableHash([globalCacheKey]);
|
|
76
|
+
this._baseHash = baseHashBuffer.toString('binary');
|
|
77
|
+
debug('Base hash: %s', baseHashBuffer.toString('hex'));
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
async transformFile(
|
|
@@ -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,
|
|
@@ -5,6 +5,7 @@ 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
11
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -13,7 +14,7 @@ function resolveDependencies(parentPath, dependencies, resolve) {
|
|
|
13
14
|
const maybeResolvedDeps = new Map();
|
|
14
15
|
const resolvedContexts = new Map();
|
|
15
16
|
for (const dep of dependencies) {
|
|
16
|
-
let
|
|
17
|
+
let maybeResolvedDep;
|
|
17
18
|
const key = dep.data.key;
|
|
18
19
|
const { contextParams } = dep.data;
|
|
19
20
|
if (contextParams) {
|
|
@@ -32,13 +33,13 @@ function resolveDependencies(parentPath, dependencies, resolve) {
|
|
|
32
33
|
),
|
|
33
34
|
};
|
|
34
35
|
resolvedContexts.set(key, resolvedContext);
|
|
35
|
-
|
|
36
|
+
maybeResolvedDep = {
|
|
36
37
|
absolutePath,
|
|
37
38
|
data: dep,
|
|
38
39
|
};
|
|
39
40
|
} else {
|
|
40
41
|
try {
|
|
41
|
-
|
|
42
|
+
maybeResolvedDep = {
|
|
42
43
|
absolutePath: resolve(parentPath, dep).filePath,
|
|
43
44
|
data: dep,
|
|
44
45
|
};
|
|
@@ -46,6 +47,9 @@ function resolveDependencies(parentPath, dependencies, resolve) {
|
|
|
46
47
|
if (dep.data.isOptional !== true) {
|
|
47
48
|
throw error;
|
|
48
49
|
}
|
|
50
|
+
maybeResolvedDep = {
|
|
51
|
+
data: dep,
|
|
52
|
+
};
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
if (maybeResolvedDeps.has(key)) {
|
|
@@ -53,16 +57,10 @@ function resolveDependencies(parentPath, dependencies, resolve) {
|
|
|
53
57
|
`resolveDependencies: Found duplicate dependency key '${key}' in ${parentPath}`
|
|
54
58
|
);
|
|
55
59
|
}
|
|
56
|
-
maybeResolvedDeps.set(key,
|
|
57
|
-
}
|
|
58
|
-
const resolvedDeps = new Map();
|
|
59
|
-
for (const [key, resolvedDep] of maybeResolvedDeps) {
|
|
60
|
-
if (resolvedDep) {
|
|
61
|
-
resolvedDeps.set(key, resolvedDep);
|
|
62
|
-
}
|
|
60
|
+
maybeResolvedDeps.set(key, maybeResolvedDep);
|
|
63
61
|
}
|
|
64
62
|
return {
|
|
65
|
-
dependencies:
|
|
63
|
+
dependencies: maybeResolvedDeps,
|
|
66
64
|
resolvedContexts,
|
|
67
65
|
};
|
|
68
66
|
}
|
|
@@ -90,9 +88,13 @@ async function buildSubgraph(
|
|
|
90
88
|
...resolutionResult,
|
|
91
89
|
});
|
|
92
90
|
await Promise.all(
|
|
93
|
-
[...resolutionResult.dependencies]
|
|
94
|
-
.filter(
|
|
95
|
-
|
|
91
|
+
[...resolutionResult.dependencies.values()]
|
|
92
|
+
.filter(
|
|
93
|
+
(dependency) =>
|
|
94
|
+
(0, _isResolvedDependency.isResolvedDependency)(dependency) &&
|
|
95
|
+
shouldTraverse(dependency)
|
|
96
|
+
)
|
|
97
|
+
.map((dependency) =>
|
|
96
98
|
visit(
|
|
97
99
|
dependency.absolutePath,
|
|
98
100
|
resolutionResult.resolvedContexts.get(dependency.data.data.key)
|
|
@@ -12,18 +12,20 @@ import type {RequireContext} from '../lib/contextModule';
|
|
|
12
12
|
import type {
|
|
13
13
|
Dependency,
|
|
14
14
|
ModuleData,
|
|
15
|
+
ResolvedDependency,
|
|
15
16
|
ResolveFn,
|
|
16
17
|
TransformFn,
|
|
17
18
|
TransformResultDependency,
|
|
18
19
|
} from './types.flow';
|
|
19
20
|
|
|
20
21
|
import {deriveAbsolutePathFromContext} from '../lib/contextModule';
|
|
22
|
+
import {isResolvedDependency} from '../lib/isResolvedDependency';
|
|
21
23
|
import path from 'path';
|
|
22
24
|
|
|
23
25
|
type Parameters<T> = $ReadOnly<{
|
|
24
26
|
resolve: ResolveFn,
|
|
25
27
|
transform: TransformFn<T>,
|
|
26
|
-
shouldTraverse:
|
|
28
|
+
shouldTraverse: ResolvedDependency => boolean,
|
|
27
29
|
}>;
|
|
28
30
|
|
|
29
31
|
function resolveDependencies(
|
|
@@ -34,11 +36,11 @@ function resolveDependencies(
|
|
|
34
36
|
dependencies: Map<string, Dependency>,
|
|
35
37
|
resolvedContexts: Map<string, RequireContext>,
|
|
36
38
|
} {
|
|
37
|
-
const maybeResolvedDeps = new Map<string,
|
|
39
|
+
const maybeResolvedDeps = new Map<string, Dependency>();
|
|
38
40
|
const resolvedContexts = new Map<string, RequireContext>();
|
|
39
41
|
|
|
40
42
|
for (const dep of dependencies) {
|
|
41
|
-
let
|
|
43
|
+
let maybeResolvedDep: Dependency;
|
|
42
44
|
const key = dep.data.key;
|
|
43
45
|
|
|
44
46
|
// `require.context`
|
|
@@ -61,13 +63,13 @@ function resolveDependencies(
|
|
|
61
63
|
|
|
62
64
|
resolvedContexts.set(key, resolvedContext);
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
maybeResolvedDep = {
|
|
65
67
|
absolutePath,
|
|
66
68
|
data: dep,
|
|
67
69
|
};
|
|
68
70
|
} else {
|
|
69
71
|
try {
|
|
70
|
-
|
|
72
|
+
maybeResolvedDep = {
|
|
71
73
|
absolutePath: resolve(parentPath, dep).filePath,
|
|
72
74
|
data: dep,
|
|
73
75
|
};
|
|
@@ -77,6 +79,9 @@ function resolveDependencies(
|
|
|
77
79
|
if (dep.data.isOptional !== true) {
|
|
78
80
|
throw error;
|
|
79
81
|
}
|
|
82
|
+
maybeResolvedDep = {
|
|
83
|
+
data: dep,
|
|
84
|
+
};
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
|
|
@@ -85,21 +90,13 @@ function resolveDependencies(
|
|
|
85
90
|
`resolveDependencies: Found duplicate dependency key '${key}' in ${parentPath}`,
|
|
86
91
|
);
|
|
87
92
|
}
|
|
88
|
-
maybeResolvedDeps.set(key,
|
|
93
|
+
maybeResolvedDeps.set(key, maybeResolvedDep);
|
|
89
94
|
}
|
|
90
95
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// serializer and the require() runtime to keep the dependency map from being
|
|
96
|
-
// desynced from the contents of the module.
|
|
97
|
-
for (const [key, resolvedDep] of maybeResolvedDeps) {
|
|
98
|
-
if (resolvedDep) {
|
|
99
|
-
resolvedDeps.set(key, resolvedDep);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return {dependencies: resolvedDeps, resolvedContexts};
|
|
96
|
+
return {
|
|
97
|
+
dependencies: maybeResolvedDeps,
|
|
98
|
+
resolvedContexts,
|
|
99
|
+
};
|
|
103
100
|
}
|
|
104
101
|
|
|
105
102
|
export async function buildSubgraph<T>(
|
|
@@ -138,9 +135,12 @@ export async function buildSubgraph<T>(
|
|
|
138
135
|
});
|
|
139
136
|
|
|
140
137
|
await Promise.all(
|
|
141
|
-
[...resolutionResult.dependencies]
|
|
142
|
-
.filter(
|
|
143
|
-
|
|
138
|
+
[...resolutionResult.dependencies.values()]
|
|
139
|
+
.filter(
|
|
140
|
+
dependency =>
|
|
141
|
+
isResolvedDependency(dependency) && shouldTraverse(dependency),
|
|
142
|
+
)
|
|
143
|
+
.map(dependency =>
|
|
144
144
|
visit(
|
|
145
145
|
dependency.absolutePath,
|
|
146
146
|
resolutionResult.resolvedContexts.get(dependency.data.data.key),
|