metro 0.71.2 → 0.72.1
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 +21 -21
- package/src/Assets.js +3 -2
- package/src/Assets.js.flow +3 -2
- package/src/Bundler.js +11 -2
- package/src/Bundler.js.flow +7 -1
- package/src/DeltaBundler/DeltaCalculator.js +85 -21
- package/src/DeltaBundler/DeltaCalculator.js.flow +63 -8
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +1 -3
- package/src/DeltaBundler/Transformer.js +27 -4
- package/src/DeltaBundler/Transformer.js.flow +18 -2
- package/src/DeltaBundler/Worker.flow.js +45 -1
- package/src/DeltaBundler/Worker.flow.js.flow +42 -1
- package/src/DeltaBundler/WorkerFarm.js +3 -2
- package/src/DeltaBundler/WorkerFarm.js.flow +5 -3
- package/src/DeltaBundler/graphOperations.js +170 -63
- package/src/DeltaBundler/graphOperations.js.flow +144 -64
- package/src/DeltaBundler/types.flow.js.flow +11 -5
- package/src/HmrServer.js +2 -0
- package/src/HmrServer.js.flow +2 -0
- package/src/IncrementalBundler.js +6 -0
- package/src/IncrementalBundler.js.flow +6 -0
- package/src/ModuleGraph/node-haste/HasteFS.js.flow +1 -1
- package/src/ModuleGraph/node-haste/node-haste.js +14 -7
- package/src/ModuleGraph/node-haste/node-haste.js.flow +35 -10
- package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +5 -13
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +4 -14
- package/src/ModuleGraph/output/util.js +1 -0
- package/src/ModuleGraph/output/util.js.flow +4 -3
- package/src/ModuleGraph/silent-console.js +5 -4
- package/src/ModuleGraph/silent-console.js.flow +8 -4
- package/src/ModuleGraph/worker/collectDependencies.js +19 -30
- package/src/ModuleGraph/worker/collectDependencies.js.flow +28 -43
- package/src/Server.js +8 -0
- package/src/Server.js.flow +48 -12
- package/src/cli-utils.js.flow +1 -1
- package/src/commands/build.js +1 -2
- package/src/commands/build.js.flow +6 -9
- package/src/commands/dependencies.js +1 -1
- package/src/commands/serve.js +2 -1
- package/src/commands/serve.js.flow +7 -8
- package/src/index.flow.js +11 -8
- package/src/index.flow.js.flow +10 -7
- package/src/integration_tests/basic_bundle/require-context/conflict.js +25 -0
- package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +27 -0
- package/src/integration_tests/basic_bundle/require-context/empty.js +29 -0
- package/src/integration_tests/basic_bundle/require-context/empty.js.flow +26 -0
- package/src/integration_tests/basic_bundle/require-context/matching.js +26 -0
- package/src/integration_tests/basic_bundle/require-context/matching.js.flow +27 -0
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js +22 -0
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +24 -0
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +22 -0
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +24 -0
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +22 -0
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +24 -0
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js +20 -0
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +22 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/a.js +12 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/a.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/b.js +18 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/b.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/c.js +12 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/c.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js +12 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js +12 -0
- package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/utils.js +29 -0
- package/src/integration_tests/basic_bundle/require-context/utils.js.flow +44 -0
- package/src/lib/CountingSet.js +1 -0
- package/src/lib/CountingSet.js.flow +1 -0
- package/src/lib/contextModule.js +80 -0
- package/src/lib/contextModule.js.flow +86 -0
- package/src/lib/contextModuleTemplates.js +186 -0
- package/src/lib/contextModuleTemplates.js.flow +148 -0
- package/src/lib/getGraphId.js +2 -1
- package/src/lib/getGraphId.js.flow +3 -0
- package/src/lib/getPrependedScripts.js +2 -0
- package/src/lib/getPrependedScripts.js.flow +2 -0
- package/src/lib/parseOptionsFromUrl.js.flow +7 -18
- package/src/lib/transformHelpers.js +41 -9
- package/src/lib/transformHelpers.js.flow +46 -9
- package/src/node-haste/DependencyGraph/ModuleResolution.js +1 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +3 -2
- package/src/node-haste/DependencyGraph/createHasteMap.js +7 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +8 -2
- package/src/node-haste/DependencyGraph.js +7 -0
- package/src/node-haste/DependencyGraph.js.flow +17 -2
- package/src/shared/output/bundle.flow.js +67 -0
- package/src/shared/output/bundle.flow.js.flow +89 -0
- package/src/shared/output/bundle.js +8 -55
- package/src/shared/output/bundle.js.flow +8 -75
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
-
import type {IdsForPathFn} from '../types.flow';
|
|
13
|
-
|
|
14
12
|
import type {Module, OutputFn, OutputFnArg, OutputResult} from '../types.flow';
|
|
15
13
|
import type {IndexMap} from 'metro-source-map';
|
|
16
14
|
|
|
@@ -30,18 +28,10 @@ function asMultipleFilesRamBundle({
|
|
|
30
28
|
modules,
|
|
31
29
|
requireCalls,
|
|
32
30
|
preloadedModules,
|
|
33
|
-
}: $
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
filename: string,
|
|
37
|
-
globalPrefix: string,
|
|
38
|
-
idsForPath: IdsForPathFn,
|
|
39
|
-
modules: Iterable<Module>,
|
|
40
|
-
preloadedModules: Set<string>,
|
|
31
|
+
}: $ReadOnly<{
|
|
32
|
+
...OutputFnArg,
|
|
33
|
+
preloadedModules: $ReadOnlySet<string>,
|
|
41
34
|
ramGroupHeads: ?$ReadOnlyArray<string>,
|
|
42
|
-
requireCalls: Iterable<Module>,
|
|
43
|
-
segmentID: number,
|
|
44
|
-
sourceMapPath?: ?string,
|
|
45
35
|
}>): OutputResult<IndexMap> {
|
|
46
36
|
const idForPath = (x: {path: string, ...}) => idsForPath(x).moduleId;
|
|
47
37
|
const [startup, deferred] = partition(modules, preloadedModules);
|
|
@@ -96,7 +86,7 @@ function asMultipleFilesRamBundle({
|
|
|
96
86
|
}
|
|
97
87
|
|
|
98
88
|
function createBuilder(
|
|
99
|
-
preloadedModules:
|
|
89
|
+
preloadedModules: $ReadOnlySet<string>,
|
|
100
90
|
ramGroupHeads: ?$ReadOnlyArray<string>,
|
|
101
91
|
): OutputFn<IndexMap> {
|
|
102
92
|
return (x: OutputFnArg) =>
|
|
@@ -62,11 +62,11 @@ type InlineModuleIdsOptions = $ReadOnly<{
|
|
|
62
62
|
}>;
|
|
63
63
|
|
|
64
64
|
// TS detection conditions copied from metro-react-native-babel-preset
|
|
65
|
-
function isTypeScriptSource(fileName) {
|
|
65
|
+
function isTypeScriptSource(fileName: string) {
|
|
66
66
|
return !!fileName && fileName.endsWith('.ts');
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function isTSXSource(fileName) {
|
|
69
|
+
function isTSXSource(fileName: string) {
|
|
70
70
|
return !!fileName && fileName.endsWith('.tsx');
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -181,6 +181,7 @@ function inlineModuleIds(
|
|
|
181
181
|
? parseSync(code, babelConfig)
|
|
182
182
|
: HermesParser.parse(code, {
|
|
183
183
|
babel: true,
|
|
184
|
+
// $FlowFixMe[prop-missing]
|
|
184
185
|
sourceType: babelConfig.sourceType,
|
|
185
186
|
});
|
|
186
187
|
|
|
@@ -317,7 +318,7 @@ exports.requireCallsTo = function* (
|
|
|
317
318
|
// the ones loaded deferredly (lazy loaded).
|
|
318
319
|
exports.partition = (
|
|
319
320
|
modules: Iterable<Module>,
|
|
320
|
-
preloadedModules:
|
|
321
|
+
preloadedModules: $ReadOnlySet<string>,
|
|
321
322
|
): Array<Array<Module>> => {
|
|
322
323
|
const startup = [];
|
|
323
324
|
const deferred = [];
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
const { Console } = require("console");
|
|
13
13
|
|
|
14
14
|
const { Writable } = require("stream");
|
|
15
|
-
/* $FlowFixMe(>=0.97.0 site=react_native_fb) This comment suppresses an error
|
|
16
|
-
* found when Flow v0.97 was deployed. To see the error delete this comment and
|
|
17
|
-
* run Flow. */
|
|
18
15
|
|
|
19
|
-
const write = (_, __, callback) =>
|
|
16
|
+
const write = (_, __, callback) =>
|
|
17
|
+
/* $FlowFixMe(>=0.97.0 site=react_native_fb) This comment suppresses an error
|
|
18
|
+
* found when Flow v0.97 was deployed. To see the error delete this comment and
|
|
19
|
+
* run Flow. */
|
|
20
|
+
callback();
|
|
20
21
|
|
|
21
22
|
module.exports = new Console(
|
|
22
23
|
new Writable({
|
|
@@ -13,8 +13,12 @@
|
|
|
13
13
|
const {Console} = require('console');
|
|
14
14
|
const {Writable} = require('stream');
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const write = (
|
|
17
|
+
_: Buffer | string | Array<{chunk: Buffer | string, encoding: string, ...}>,
|
|
18
|
+
__: string | ((error?: Error) => void),
|
|
19
|
+
callback: void | ((error?: Error) => void),
|
|
20
|
+
/* $FlowFixMe(>=0.97.0 site=react_native_fb) This comment suppresses an error
|
|
21
|
+
* found when Flow v0.97 was deployed. To see the error delete this comment and
|
|
22
|
+
* run Flow. */
|
|
23
|
+
) => callback();
|
|
20
24
|
module.exports = (new Console(new Writable({write, writev: write})): Console);
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
|
+
const crypto = require("crypto");
|
|
13
|
+
|
|
12
14
|
const generate = require("@babel/generator").default;
|
|
13
15
|
|
|
14
16
|
const template = require("@babel/template").default;
|
|
@@ -586,8 +588,9 @@ function createModuleNameLiteral(dependency) {
|
|
|
586
588
|
}
|
|
587
589
|
/**
|
|
588
590
|
* Given an import qualifier, return a key used to register the dependency.
|
|
589
|
-
* Generally this return the `ImportQualifier.name` property, but
|
|
590
|
-
*
|
|
591
|
+
* Generally this return the `ImportQualifier.name` property, but more
|
|
592
|
+
* attributes can be appended to distinguish various combinations that would
|
|
593
|
+
* otherwise conflict.
|
|
591
594
|
*
|
|
592
595
|
* For example, the following case would have collision issues if they all utilized the `name` property:
|
|
593
596
|
* ```
|
|
@@ -603,6 +606,12 @@ function createModuleNameLiteral(dependency) {
|
|
|
603
606
|
|
|
604
607
|
function getKeyForDependency(qualifier) {
|
|
605
608
|
let key = qualifier.name;
|
|
609
|
+
const { asyncType } = qualifier;
|
|
610
|
+
|
|
611
|
+
if (asyncType) {
|
|
612
|
+
key += ["", asyncType].join("\0");
|
|
613
|
+
}
|
|
614
|
+
|
|
606
615
|
const { contextParams } = qualifier; // Add extra qualifiers when using `require.context` to prevent collisions.
|
|
607
616
|
|
|
608
617
|
if (contextParams) {
|
|
@@ -616,7 +625,7 @@ function getKeyForDependency(qualifier) {
|
|
|
616
625
|
String(contextParams.filter.pattern),
|
|
617
626
|
String(contextParams.filter.flags),
|
|
618
627
|
contextParams.mode, // Join together and append to the name:
|
|
619
|
-
].join("
|
|
628
|
+
].join("\0");
|
|
620
629
|
}
|
|
621
630
|
|
|
622
631
|
return key;
|
|
@@ -636,6 +645,7 @@ class DefaultModuleDependencyRegistry {
|
|
|
636
645
|
asyncType: qualifier.asyncType,
|
|
637
646
|
locs: [],
|
|
638
647
|
index: this._dependencies.size,
|
|
648
|
+
key: crypto.createHash("sha1").update(key).digest("base64"),
|
|
639
649
|
};
|
|
640
650
|
|
|
641
651
|
if (qualifier.optional) {
|
|
@@ -647,17 +657,16 @@ class DefaultModuleDependencyRegistry {
|
|
|
647
657
|
}
|
|
648
658
|
|
|
649
659
|
dependency = newDependency;
|
|
650
|
-
|
|
651
|
-
this._dependencies.set(key, dependency);
|
|
652
660
|
} else {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
this._dependencies.set(key, dependency);
|
|
661
|
+
if (dependency.isOptional && !qualifier.optional) {
|
|
662
|
+
// A previously optionally required dependency was required non-optionally.
|
|
663
|
+
// Mark it non optional for the whole module
|
|
664
|
+
dependency = { ...dependency, isOptional: false };
|
|
658
665
|
}
|
|
659
666
|
}
|
|
660
667
|
|
|
668
|
+
this._dependencies.set(key, dependency);
|
|
669
|
+
|
|
661
670
|
return dependency;
|
|
662
671
|
}
|
|
663
672
|
|
|
@@ -666,24 +675,4 @@ class DefaultModuleDependencyRegistry {
|
|
|
666
675
|
}
|
|
667
676
|
}
|
|
668
677
|
|
|
669
|
-
function collapseDependencies(dependency, qualifier) {
|
|
670
|
-
let collapsed = dependency; // A previously optionally required dependency was required non-optionaly.
|
|
671
|
-
// Mark it non optional for the whole module
|
|
672
|
-
|
|
673
|
-
if (collapsed.isOptional && !qualifier.optional) {
|
|
674
|
-
collapsed = { ...dependency, isOptional: false };
|
|
675
|
-
} // A previously asynchronously (or prefetch) required module was required synchronously.
|
|
676
|
-
// Make the dependency sync.
|
|
677
|
-
|
|
678
|
-
if (collapsed.asyncType != null && qualifier.asyncType == null) {
|
|
679
|
-
collapsed = { ...dependency, asyncType: null };
|
|
680
|
-
} // A prefetched dependency was required async in the module. Mark it as async.
|
|
681
|
-
|
|
682
|
-
if (collapsed.asyncType === "prefetch" && qualifier.asyncType === "async") {
|
|
683
|
-
collapsed = { ...dependency, asyncType: "async" };
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
return collapsed;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
678
|
module.exports = collectDependencies;
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
AsyncDependencyType,
|
|
18
18
|
} from 'metro/src/DeltaBundler/types.flow.js';
|
|
19
19
|
|
|
20
|
+
const crypto = require('crypto');
|
|
20
21
|
const generate = require('@babel/generator').default;
|
|
21
22
|
const template = require('@babel/template').default;
|
|
22
23
|
const traverse = require('@babel/traverse').default;
|
|
@@ -38,7 +39,7 @@ export type Dependency<TSplitCondition> = $ReadOnly<{
|
|
|
38
39
|
}>;
|
|
39
40
|
|
|
40
41
|
// TODO: Convert to a Flow enum
|
|
41
|
-
type ContextMode = 'sync' | 'eager' | 'lazy' | 'lazy-once';
|
|
42
|
+
export type ContextMode = 'sync' | 'eager' | 'lazy' | 'lazy-once';
|
|
42
43
|
|
|
43
44
|
type ContextFilter = {pattern: string, flags: string};
|
|
44
45
|
|
|
@@ -52,6 +53,8 @@ export type RequireContextParams = $ReadOnly<{
|
|
|
52
53
|
}>;
|
|
53
54
|
|
|
54
55
|
type DependencyData<TSplitCondition> = $ReadOnly<{
|
|
56
|
+
// A locally unique key for this dependency within the current module.
|
|
57
|
+
key: string,
|
|
55
58
|
// If null, then the dependency is synchronous.
|
|
56
59
|
// (ex. `require('foo')`)
|
|
57
60
|
asyncType: AsyncDependencyType | null,
|
|
@@ -175,7 +178,10 @@ function collectDependencies<TSplitCondition = void>(
|
|
|
175
178
|
};
|
|
176
179
|
|
|
177
180
|
const visitor = {
|
|
178
|
-
CallExpression(
|
|
181
|
+
CallExpression(
|
|
182
|
+
path: NodePath<BabelNodeCallExpression>,
|
|
183
|
+
state: State<TSplitCondition>,
|
|
184
|
+
): void {
|
|
179
185
|
if (visited.has(path.node)) {
|
|
180
186
|
return;
|
|
181
187
|
}
|
|
@@ -254,7 +260,7 @@ function collectDependencies<TSplitCondition = void>(
|
|
|
254
260
|
ExportNamedDeclaration: collectImports,
|
|
255
261
|
ExportAllDeclaration: collectImports,
|
|
256
262
|
|
|
257
|
-
Program(path
|
|
263
|
+
Program(path: NodePath<BabelNodeProgram>, state: State<TSplitCondition>) {
|
|
258
264
|
state.asyncRequireModulePathStringLiteral = types.stringLiteral(
|
|
259
265
|
options.asyncRequireModulePath,
|
|
260
266
|
);
|
|
@@ -723,8 +729,9 @@ function createModuleNameLiteral(dependency: InternalDependency<mixed>) {
|
|
|
723
729
|
|
|
724
730
|
/**
|
|
725
731
|
* Given an import qualifier, return a key used to register the dependency.
|
|
726
|
-
* Generally this return the `ImportQualifier.name` property, but
|
|
727
|
-
*
|
|
732
|
+
* Generally this return the `ImportQualifier.name` property, but more
|
|
733
|
+
* attributes can be appended to distinguish various combinations that would
|
|
734
|
+
* otherwise conflict.
|
|
728
735
|
*
|
|
729
736
|
* For example, the following case would have collision issues if they all utilized the `name` property:
|
|
730
737
|
* ```
|
|
@@ -740,6 +747,11 @@ function createModuleNameLiteral(dependency: InternalDependency<mixed>) {
|
|
|
740
747
|
function getKeyForDependency(qualifier: ImportQualifier): string {
|
|
741
748
|
let key = qualifier.name;
|
|
742
749
|
|
|
750
|
+
const {asyncType} = qualifier;
|
|
751
|
+
if (asyncType) {
|
|
752
|
+
key += ['', asyncType].join('\0');
|
|
753
|
+
}
|
|
754
|
+
|
|
743
755
|
const {contextParams} = qualifier;
|
|
744
756
|
// Add extra qualifiers when using `require.context` to prevent collisions.
|
|
745
757
|
if (contextParams) {
|
|
@@ -754,7 +766,7 @@ function getKeyForDependency(qualifier: ImportQualifier): string {
|
|
|
754
766
|
String(contextParams.filter.flags),
|
|
755
767
|
contextParams.mode,
|
|
756
768
|
// Join together and append to the name:
|
|
757
|
-
].join('
|
|
769
|
+
].join('\0');
|
|
758
770
|
}
|
|
759
771
|
return key;
|
|
760
772
|
}
|
|
@@ -777,6 +789,7 @@ class DefaultModuleDependencyRegistry<TSplitCondition = void>
|
|
|
777
789
|
asyncType: qualifier.asyncType,
|
|
778
790
|
locs: [],
|
|
779
791
|
index: this._dependencies.size,
|
|
792
|
+
key: crypto.createHash('sha1').update(key).digest('base64'),
|
|
780
793
|
};
|
|
781
794
|
|
|
782
795
|
if (qualifier.optional) {
|
|
@@ -787,15 +800,19 @@ class DefaultModuleDependencyRegistry<TSplitCondition = void>
|
|
|
787
800
|
}
|
|
788
801
|
|
|
789
802
|
dependency = newDependency;
|
|
790
|
-
this._dependencies.set(key, dependency);
|
|
791
803
|
} else {
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
804
|
+
if (dependency.isOptional && !qualifier.optional) {
|
|
805
|
+
// A previously optionally required dependency was required non-optionally.
|
|
806
|
+
// Mark it non optional for the whole module
|
|
807
|
+
dependency = {
|
|
808
|
+
...dependency,
|
|
809
|
+
isOptional: false,
|
|
810
|
+
};
|
|
796
811
|
}
|
|
797
812
|
}
|
|
798
813
|
|
|
814
|
+
this._dependencies.set(key, dependency);
|
|
815
|
+
|
|
799
816
|
return dependency;
|
|
800
817
|
}
|
|
801
818
|
|
|
@@ -804,36 +821,4 @@ class DefaultModuleDependencyRegistry<TSplitCondition = void>
|
|
|
804
821
|
}
|
|
805
822
|
}
|
|
806
823
|
|
|
807
|
-
function collapseDependencies<TSplitCondition>(
|
|
808
|
-
dependency: InternalDependency<TSplitCondition>,
|
|
809
|
-
qualifier: ImportQualifier,
|
|
810
|
-
): InternalDependency<TSplitCondition> {
|
|
811
|
-
let collapsed = dependency;
|
|
812
|
-
|
|
813
|
-
// A previously optionally required dependency was required non-optionaly.
|
|
814
|
-
// Mark it non optional for the whole module
|
|
815
|
-
if (collapsed.isOptional && !qualifier.optional) {
|
|
816
|
-
collapsed = {
|
|
817
|
-
...dependency,
|
|
818
|
-
isOptional: false,
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
// A previously asynchronously (or prefetch) required module was required synchronously.
|
|
823
|
-
// Make the dependency sync.
|
|
824
|
-
if (collapsed.asyncType != null && qualifier.asyncType == null) {
|
|
825
|
-
collapsed = {...dependency, asyncType: null};
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
// A prefetched dependency was required async in the module. Mark it as async.
|
|
829
|
-
if (collapsed.asyncType === 'prefetch' && qualifier.asyncType === 'async') {
|
|
830
|
-
collapsed = {
|
|
831
|
-
...dependency,
|
|
832
|
-
asyncType: 'async',
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
return collapsed;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
824
|
module.exports = collectDependencies;
|
package/src/Server.js
CHANGED
|
@@ -453,6 +453,8 @@ class Server {
|
|
|
453
453
|
delete: deleteFn,
|
|
454
454
|
finish,
|
|
455
455
|
}) {
|
|
456
|
+
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
|
|
457
|
+
* Flow's LTI update could not be added via codemod */
|
|
456
458
|
return async function requestProcessor(req, res, bundleOptions) {
|
|
457
459
|
const { entryFile, graphOptions, transformOptions, serializerOptions } =
|
|
458
460
|
splitBundleOptions(bundleOptions);
|
|
@@ -469,6 +471,8 @@ class Server {
|
|
|
469
471
|
shallow: graphOptions.shallow,
|
|
470
472
|
experimentalImportBundleSupport:
|
|
471
473
|
this._config.transformer.experimentalImportBundleSupport,
|
|
474
|
+
unstable_allowRequireContext:
|
|
475
|
+
this._config.transformer.unstable_allowRequireContext,
|
|
472
476
|
}); // For resources that support deletion, handle the DELETE method.
|
|
473
477
|
|
|
474
478
|
if (deleteFn && req.method === "DELETE") {
|
|
@@ -660,6 +664,8 @@ class Server {
|
|
|
660
664
|
|
|
661
665
|
const serializer =
|
|
662
666
|
this._config.serializer.customSerializer ||
|
|
667
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
|
|
668
|
+
* Flow's LTI update could not be added via codemod */
|
|
663
669
|
((...args) => bundleToString(baseJSBundle(...args)).code);
|
|
664
670
|
|
|
665
671
|
const bundle = await serializer(
|
|
@@ -1093,6 +1099,8 @@ class Server {
|
|
|
1093
1099
|
shallow: graphOptions.shallow,
|
|
1094
1100
|
experimentalImportBundleSupport:
|
|
1095
1101
|
this._config.transformer.experimentalImportBundleSupport,
|
|
1102
|
+
unstable_allowRequireContext:
|
|
1103
|
+
this._config.transformer.unstable_allowRequireContext,
|
|
1096
1104
|
});
|
|
1097
1105
|
let revision;
|
|
1098
1106
|
|
package/src/Server.js.flow
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
+
|
|
13
|
+
import type {StackFrameOutput} from './Server/symbolicate';
|
|
12
14
|
import type {AssetData} from './Assets';
|
|
13
15
|
import type {ExplodedSourceMap} from './DeltaBundler/Serializers/getExplodedSourceMap';
|
|
14
16
|
import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo';
|
|
@@ -349,7 +351,7 @@ class Server {
|
|
|
349
351
|
res: ServerResponse,
|
|
350
352
|
data: string | Buffer,
|
|
351
353
|
assetPath: string,
|
|
352
|
-
) {
|
|
354
|
+
): Buffer | string {
|
|
353
355
|
if (req.headers && req.headers.range) {
|
|
354
356
|
const [rangeStart, rangeEnd] = req.headers.range
|
|
355
357
|
.replace(/bytes=/, '')
|
|
@@ -371,7 +373,10 @@ class Server {
|
|
|
371
373
|
return data;
|
|
372
374
|
}
|
|
373
375
|
|
|
374
|
-
async _processSingleAssetRequest(
|
|
376
|
+
async _processSingleAssetRequest(
|
|
377
|
+
req: IncomingMessage,
|
|
378
|
+
res: ServerResponse,
|
|
379
|
+
): Promise<void> {
|
|
375
380
|
const urlObj = url.parse(decodeURI(req.url), true);
|
|
376
381
|
let [, assetPath] =
|
|
377
382
|
(urlObj &&
|
|
@@ -512,7 +517,13 @@ class Server {
|
|
|
512
517
|
+build: (context: ProcessStartContext) => Promise<T>,
|
|
513
518
|
+delete?: (context: ProcessDeleteContext) => Promise<void>,
|
|
514
519
|
+finish: (context: ProcessEndContext<T>) => void,
|
|
515
|
-
})
|
|
520
|
+
}): (
|
|
521
|
+
req: IncomingMessage,
|
|
522
|
+
res: ServerResponse,
|
|
523
|
+
bundleOptions: BundleOptions,
|
|
524
|
+
) => Promise<void> {
|
|
525
|
+
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
|
|
526
|
+
* Flow's LTI update could not be added via codemod */
|
|
516
527
|
return async function requestProcessor(
|
|
517
528
|
req: IncomingMessage,
|
|
518
529
|
res: ServerResponse,
|
|
@@ -533,6 +544,8 @@ class Server {
|
|
|
533
544
|
shallow: graphOptions.shallow,
|
|
534
545
|
experimentalImportBundleSupport:
|
|
535
546
|
this._config.transformer.experimentalImportBundleSupport,
|
|
547
|
+
unstable_allowRequireContext:
|
|
548
|
+
this._config.transformer.unstable_allowRequireContext,
|
|
536
549
|
});
|
|
537
550
|
|
|
538
551
|
// For resources that support deletion, handle the DELETE method.
|
|
@@ -690,7 +703,11 @@ class Server {
|
|
|
690
703
|
};
|
|
691
704
|
}
|
|
692
705
|
|
|
693
|
-
_processBundleRequest
|
|
706
|
+
_processBundleRequest: (
|
|
707
|
+
req: IncomingMessage,
|
|
708
|
+
res: ServerResponse,
|
|
709
|
+
bundleOptions: BundleOptions,
|
|
710
|
+
) => Promise<void> = this._createRequestProcessor({
|
|
694
711
|
createStartEntry(context: ProcessStartContext) {
|
|
695
712
|
return {
|
|
696
713
|
action_name: 'Requesting bundle',
|
|
@@ -733,6 +750,8 @@ class Server {
|
|
|
733
750
|
|
|
734
751
|
const serializer =
|
|
735
752
|
this._config.serializer.customSerializer ||
|
|
753
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
|
|
754
|
+
* Flow's LTI update could not be added via codemod */
|
|
736
755
|
((...args) => bundleToString(baseJSBundle(...args)).code);
|
|
737
756
|
|
|
738
757
|
const bundle = await serializer(
|
|
@@ -807,7 +826,11 @@ class Server {
|
|
|
807
826
|
},
|
|
808
827
|
});
|
|
809
828
|
|
|
810
|
-
_processBytecodeBundleRequest
|
|
829
|
+
_processBytecodeBundleRequest: (
|
|
830
|
+
req: IncomingMessage,
|
|
831
|
+
res: ServerResponse,
|
|
832
|
+
bundleOptions: BundleOptions,
|
|
833
|
+
) => Promise<void> = this._createRequestProcessor({
|
|
811
834
|
createStartEntry(context: ProcessStartContext) {
|
|
812
835
|
return {
|
|
813
836
|
action_name: 'Requesting bundle',
|
|
@@ -925,7 +948,11 @@ class Server {
|
|
|
925
948
|
);
|
|
926
949
|
}
|
|
927
950
|
|
|
928
|
-
_processSourceMapRequest
|
|
951
|
+
_processSourceMapRequest: (
|
|
952
|
+
req: IncomingMessage,
|
|
953
|
+
res: ServerResponse,
|
|
954
|
+
bundleOptions: BundleOptions,
|
|
955
|
+
) => Promise<void> = this._createRequestProcessor({
|
|
929
956
|
createStartEntry(context: ProcessStartContext) {
|
|
930
957
|
return {
|
|
931
958
|
action_name: 'Requesting sourcemap',
|
|
@@ -975,7 +1002,11 @@ class Server {
|
|
|
975
1002
|
},
|
|
976
1003
|
});
|
|
977
1004
|
|
|
978
|
-
_processAssetsRequest
|
|
1005
|
+
_processAssetsRequest: (
|
|
1006
|
+
req: IncomingMessage,
|
|
1007
|
+
res: ServerResponse,
|
|
1008
|
+
bundleOptions: BundleOptions,
|
|
1009
|
+
) => Promise<void> = this._createRequestProcessor({
|
|
979
1010
|
createStartEntry(context: ProcessStartContext) {
|
|
980
1011
|
return {
|
|
981
1012
|
action_name: 'Requesting assets',
|
|
@@ -1011,7 +1042,10 @@ class Server {
|
|
|
1011
1042
|
});
|
|
1012
1043
|
|
|
1013
1044
|
async _symbolicate(req: IncomingMessage, res: ServerResponse) {
|
|
1014
|
-
const getCodeFrame = (
|
|
1045
|
+
const getCodeFrame = (
|
|
1046
|
+
urls: Set<string>,
|
|
1047
|
+
symbolicatedStack: $ReadOnlyArray<StackFrameOutput>,
|
|
1048
|
+
) => {
|
|
1015
1049
|
for (let i = 0; i < symbolicatedStack.length; i++) {
|
|
1016
1050
|
const {collapse, column, file, lineNumber} = symbolicatedStack[i];
|
|
1017
1051
|
const fileAbsolute = path.resolve(this._config.projectRoot, file ?? '');
|
|
@@ -1134,6 +1168,8 @@ class Server {
|
|
|
1134
1168
|
shallow: graphOptions.shallow,
|
|
1135
1169
|
experimentalImportBundleSupport:
|
|
1136
1170
|
this._config.transformer.experimentalImportBundleSupport,
|
|
1171
|
+
unstable_allowRequireContext:
|
|
1172
|
+
this._config.transformer.unstable_allowRequireContext,
|
|
1137
1173
|
});
|
|
1138
1174
|
let revision;
|
|
1139
1175
|
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
@@ -1161,7 +1197,7 @@ class Server {
|
|
|
1161
1197
|
}
|
|
1162
1198
|
|
|
1163
1199
|
async _resolveRelativePath(
|
|
1164
|
-
filePath,
|
|
1200
|
+
filePath: string,
|
|
1165
1201
|
{
|
|
1166
1202
|
transformOptions,
|
|
1167
1203
|
relativeTo,
|
|
@@ -1169,7 +1205,7 @@ class Server {
|
|
|
1169
1205
|
transformOptions: TransformInputOptions,
|
|
1170
1206
|
relativeTo: 'project' | 'server',
|
|
1171
1207
|
}>,
|
|
1172
|
-
) {
|
|
1208
|
+
): Promise<string> {
|
|
1173
1209
|
const resolutionFn = await transformHelpers.getResolveDependencyFn(
|
|
1174
1210
|
this._bundler.getBundler(),
|
|
1175
1211
|
transformOptions.platform,
|
|
@@ -1231,11 +1267,11 @@ class Server {
|
|
|
1231
1267
|
sourceUrl: null,
|
|
1232
1268
|
};
|
|
1233
1269
|
|
|
1234
|
-
_getServerRootDir() {
|
|
1270
|
+
_getServerRootDir(): string {
|
|
1235
1271
|
return this._config.server.unstable_serverRoot ?? this._config.projectRoot;
|
|
1236
1272
|
}
|
|
1237
1273
|
|
|
1238
|
-
_getEntryPointAbsolutePath(entryFile: string) {
|
|
1274
|
+
_getEntryPointAbsolutePath(entryFile: string): string {
|
|
1239
1275
|
return path.resolve(this._getServerRootDir(), entryFile);
|
|
1240
1276
|
}
|
|
1241
1277
|
|
package/src/cli-utils.js.flow
CHANGED
|
@@ -27,7 +27,7 @@ exports.watchFile = async function (
|
|
|
27
27
|
|
|
28
28
|
exports.makeAsyncCommand =
|
|
29
29
|
(
|
|
30
|
-
command: (argv: YargArguments) => Promise<
|
|
30
|
+
command: (argv: YargArguments) => Promise<void>,
|
|
31
31
|
): ((argv: YargArguments) => void) =>
|
|
32
32
|
(argv: YargArguments) => {
|
|
33
33
|
Promise.resolve(command(argv)).catch(error => {
|
package/src/commands/build.js
CHANGED
|
@@ -22,8 +22,7 @@ const updateReporter = new TerminalReporter(term);
|
|
|
22
22
|
|
|
23
23
|
module.exports = () => ({
|
|
24
24
|
command: "build <entry>",
|
|
25
|
-
|
|
26
|
-
"Generates a JavaScript bundle containing the specified entrypoint and its descendants",
|
|
25
|
+
desc: "Generates a JavaScript bundle containing the specified entrypoint and its descendants",
|
|
27
26
|
builder: (yargs) => {
|
|
28
27
|
yargs.option("project-roots", {
|
|
29
28
|
alias: "P",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import type {RunBuildOptions} from '../index';
|
|
14
14
|
import type {YargArguments} from 'metro-config/src/configTypes.flow';
|
|
15
15
|
import typeof Yargs from 'yargs';
|
|
16
|
+
import type {ModuleObject} from 'yargs';
|
|
16
17
|
|
|
17
18
|
const {makeAsyncCommand} = require('../cli-utils');
|
|
18
19
|
const TerminalReporter = require('../lib/TerminalReporter');
|
|
@@ -22,16 +23,12 @@ const {Terminal} = require('metro-core');
|
|
|
22
23
|
const term = new Terminal(process.stdout);
|
|
23
24
|
const updateReporter = new TerminalReporter(term);
|
|
24
25
|
|
|
25
|
-
module.exports = ():
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
handler: (argv: YargArguments) => void,
|
|
30
|
-
}) => ({
|
|
26
|
+
module.exports = (): {
|
|
27
|
+
...ModuleObject,
|
|
28
|
+
handler: Function,
|
|
29
|
+
} => ({
|
|
31
30
|
command: 'build <entry>',
|
|
32
|
-
|
|
33
|
-
description:
|
|
34
|
-
'Generates a JavaScript bundle containing the specified entrypoint and its descendants',
|
|
31
|
+
desc: 'Generates a JavaScript bundle containing the specified entrypoint and its descendants',
|
|
35
32
|
|
|
36
33
|
builder: (yargs: Yargs): void => {
|
|
37
34
|
yargs.option('project-roots', {
|
package/src/commands/serve.js
CHANGED
|
@@ -17,7 +17,8 @@ const { promisify } = require("util");
|
|
|
17
17
|
|
|
18
18
|
module.exports = () => ({
|
|
19
19
|
command: "serve",
|
|
20
|
-
|
|
20
|
+
aliases: ["start"],
|
|
21
|
+
desc: "Starts Metro on the given port, building bundles on the fly",
|
|
21
22
|
builder: (yargs) => {
|
|
22
23
|
yargs.option("project-roots", {
|
|
23
24
|
alias: "P",
|
|
@@ -13,20 +13,19 @@
|
|
|
13
13
|
import type {RunServerOptions} from '../index';
|
|
14
14
|
import type {YargArguments} from 'metro-config/src/configTypes.flow';
|
|
15
15
|
import typeof Yargs from 'yargs';
|
|
16
|
+
import type {ModuleObject} from 'yargs';
|
|
16
17
|
|
|
17
18
|
const {makeAsyncCommand, watchFile} = require('../cli-utils');
|
|
18
19
|
const {loadConfig, resolveConfig} = require('metro-config');
|
|
19
20
|
const {promisify} = require('util');
|
|
20
21
|
|
|
21
|
-
module.exports = ():
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
handler: (argv: YargArguments) => void,
|
|
26
|
-
}) => ({
|
|
22
|
+
module.exports = (): {
|
|
23
|
+
...ModuleObject,
|
|
24
|
+
handler: Function,
|
|
25
|
+
} => ({
|
|
27
26
|
command: 'serve',
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
aliases: ['start'],
|
|
28
|
+
desc: 'Starts Metro on the given port, building bundles on the fly',
|
|
30
29
|
|
|
31
30
|
builder: (yargs: Yargs): void => {
|
|
32
31
|
yargs.option('project-roots', {
|