metro 0.76.0 → 0.76.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 +24 -24
- package/src/Asset.d.ts +25 -0
- package/src/Bundler.d.ts +39 -0
- package/src/DeltaBundler/Graph.d.ts +40 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
- package/src/DeltaBundler/Transformer.js +1 -2
- package/src/DeltaBundler/Transformer.js.flow +1 -2
- package/src/DeltaBundler/Worker.d.ts +47 -0
- package/src/DeltaBundler/types.d.ts +167 -0
- package/src/DeltaBundler.d.ts +58 -0
- package/src/HmrServer.js +1 -5
- package/src/HmrServer.js.flow +0 -5
- package/src/IncrementalBundler.d.ts +97 -0
- package/src/IncrementalBundler.js +1 -0
- package/src/IncrementalBundler.js.flow +1 -0
- package/src/ModuleGraph/worker/collectDependencies.d.ts +27 -0
- package/src/ModuleGraph/worker/collectDependencies.js +42 -25
- package/src/ModuleGraph/worker/collectDependencies.js.flow +41 -36
- package/src/Server/MultipartResponse.d.ts +31 -0
- package/src/Server.d.ts +113 -0
- package/src/Server.js +11 -133
- package/src/Server.js.flow +12 -154
- package/src/cli/parseKeyValueParamArray.js +34 -0
- package/src/cli/parseKeyValueParamArray.js.flow +31 -0
- package/src/cli-utils.js.flow +2 -6
- package/src/cli.js +2 -0
- package/src/cli.js.flow +1 -0
- package/src/commands/build.js +34 -7
- package/src/commands/build.js.flow +50 -8
- package/src/commands/dependencies.js +11 -9
- package/src/commands/dependencies.js.flow +128 -0
- package/src/commands/serve.js +11 -4
- package/src/commands/serve.js.flow +26 -6
- package/src/index.d.ts +151 -0
- package/src/index.flow.js +8 -2
- package/src/index.flow.js.flow +18 -6
- package/src/lib/CountingSet.d.ts +48 -0
- package/src/lib/TerminalReporter.d.ts +27 -0
- package/src/lib/TerminalReporter.js +1 -4
- package/src/lib/TerminalReporter.js.flow +1 -5
- package/src/lib/contextModule.d.ts +22 -0
- package/src/lib/getGraphId.d.ts +11 -0
- package/src/lib/getGraphId.js +0 -1
- package/src/lib/getGraphId.js.flow +0 -1
- package/src/lib/getPrependedScripts.js +0 -9
- package/src/lib/getPrependedScripts.js.flow +0 -9
- package/src/lib/parseOptionsFromUrl.js +1 -16
- package/src/lib/parseOptionsFromUrl.js.flow +0 -17
- package/src/lib/reporting.d.ts +140 -0
- package/src/lib/reporting.js.flow +0 -1
- package/src/lib/splitBundleOptions.js +0 -1
- package/src/lib/splitBundleOptions.js.flow +0 -1
- package/src/lib/transformHelpers.js +0 -1
- package/src/lib/transformHelpers.js.flow +0 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js +0 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +0 -1
- package/src/node-haste/DependencyGraph.d.ts +59 -0
- package/src/node-haste/DependencyGraph.js +1 -0
- package/src/node-haste/DependencyGraph.js.flow +1 -0
- package/src/shared/output/RamBundle/as-assets.js +1 -0
- package/src/shared/output/RamBundle/as-assets.js.flow +1 -0
- package/src/shared/output/RamBundle/write-sourcemap.js +1 -0
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -0
- package/src/shared/output/bundle.d.ts +31 -0
- package/src/shared/types.d.ts +138 -0
- package/src/shared/types.flow.js.flow +2 -1
- package/types/Asset.d.ts +25 -0
- package/types/Bundler.d.ts +39 -0
- package/types/DeltaBundler/Graph.d.ts +40 -0
- package/types/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
- package/types/DeltaBundler/Worker.d.ts +47 -0
- package/types/DeltaBundler/types.d.ts +167 -0
- package/types/DeltaBundler.d.ts +58 -0
- package/types/IncrementalBundler.d.ts +97 -0
- package/types/ModuleGraph/worker/collectDependencies.d.ts +27 -0
- package/types/Server/MultipartResponse.d.ts +31 -0
- package/types/Server.d.ts +113 -0
- package/types/index.d.ts +151 -0
- package/types/lib/CountingSet.d.ts +48 -0
- package/types/lib/TerminalReporter.d.ts +27 -0
- package/types/lib/contextModule.d.ts +22 -0
- package/types/lib/getGraphId.d.ts +11 -0
- package/types/lib/reporting.d.ts +140 -0
- package/types/node-haste/DependencyGraph.d.ts +59 -0
- package/types/shared/output/bundle.d.ts +31 -0
- package/types/shared/types.d.ts +138 -0
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +0 -81
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +0 -103
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +0 -61
- package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +0 -75
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +0 -40
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +0 -51
- package/src/lib/bundleToBytecode.js +0 -79
- package/src/lib/bundleToBytecode.js.flow +0 -97
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type ContextMode = 'sync' | 'eager' | 'lazy' | 'lazy-once';
|
|
12
|
+
|
|
13
|
+
export interface ContextFilter {
|
|
14
|
+
pattern: string;
|
|
15
|
+
flags: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RequireContextParams {
|
|
19
|
+
/* Should search for files recursively. Optional, default `true` when `require.context` is used */
|
|
20
|
+
readonly recursive: boolean;
|
|
21
|
+
/* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */
|
|
22
|
+
readonly filter: Readonly<ContextFilter>;
|
|
23
|
+
/** Mode for resolving dynamic dependencies. Defaults to `sync` */
|
|
24
|
+
readonly mode: ContextMode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type DynamicRequiresBehavior = 'throwAtRuntime' | 'reject';
|
|
@@ -31,8 +31,7 @@ function collectDependencies(ast, options) {
|
|
|
31
31
|
const state = {
|
|
32
32
|
asyncRequireModulePathStringLiteral: null,
|
|
33
33
|
dependencyCalls: new Set(),
|
|
34
|
-
dependencyRegistry:
|
|
35
|
-
options.dependencyRegistry ?? new DefaultModuleDependencyRegistry(),
|
|
34
|
+
dependencyRegistry: new DependencyRegistry(),
|
|
36
35
|
dependencyTransformer:
|
|
37
36
|
options.dependencyTransformer ?? DefaultDependencyTransformer,
|
|
38
37
|
dependencyMapIdentifier: null,
|
|
@@ -429,10 +428,16 @@ const dynamicRequireErrorTemplate = template.expression(`
|
|
|
429
428
|
* "require(...)" call to the asyncRequire specified.
|
|
430
429
|
*/
|
|
431
430
|
const makeAsyncRequireTemplate = template.expression(`
|
|
432
|
-
require(ASYNC_REQUIRE_MODULE_PATH)(MODULE_ID,
|
|
431
|
+
require(ASYNC_REQUIRE_MODULE_PATH)(MODULE_ID, DEPENDENCY_MAP.paths)
|
|
432
|
+
`);
|
|
433
|
+
const makeAsyncRequireTemplateWithName = template.expression(`
|
|
434
|
+
require(ASYNC_REQUIRE_MODULE_PATH)(MODULE_ID, DEPENDENCY_MAP.paths, MODULE_NAME)
|
|
433
435
|
`);
|
|
434
436
|
const makeAsyncPrefetchTemplate = template.expression(`
|
|
435
|
-
require(ASYNC_REQUIRE_MODULE_PATH).prefetch(MODULE_ID,
|
|
437
|
+
require(ASYNC_REQUIRE_MODULE_PATH).prefetch(MODULE_ID, DEPENDENCY_MAP.paths)
|
|
438
|
+
`);
|
|
439
|
+
const makeAsyncPrefetchTemplateWithName = template.expression(`
|
|
440
|
+
require(ASYNC_REQUIRE_MODULE_PATH).prefetch(MODULE_ID, DEPENDENCY_MAP.paths, MODULE_NAME)
|
|
436
441
|
`);
|
|
437
442
|
const makeResolveWeakTemplate = template.expression(`
|
|
438
443
|
MODULE_ID
|
|
@@ -447,28 +452,40 @@ const DefaultDependencyTransformer = {
|
|
|
447
452
|
}
|
|
448
453
|
},
|
|
449
454
|
transformImportCall(path, dependency, state) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
455
|
+
const makeNode = state.keepRequireNames
|
|
456
|
+
? makeAsyncRequireTemplateWithName
|
|
457
|
+
: makeAsyncRequireTemplate;
|
|
458
|
+
const opts = {
|
|
459
|
+
ASYNC_REQUIRE_MODULE_PATH: nullthrows(
|
|
460
|
+
state.asyncRequireModulePathStringLiteral
|
|
461
|
+
),
|
|
462
|
+
MODULE_ID: createModuleIDExpression(dependency, state),
|
|
463
|
+
DEPENDENCY_MAP: nullthrows(state.dependencyMapIdentifier),
|
|
464
|
+
...(state.keepRequireNames
|
|
465
|
+
? {
|
|
466
|
+
MODULE_NAME: createModuleNameLiteral(dependency),
|
|
467
|
+
}
|
|
468
|
+
: null),
|
|
469
|
+
};
|
|
470
|
+
path.replaceWith(makeNode(opts));
|
|
460
471
|
},
|
|
461
472
|
transformPrefetch(path, dependency, state) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
473
|
+
const makeNode = state.keepRequireNames
|
|
474
|
+
? makeAsyncPrefetchTemplateWithName
|
|
475
|
+
: makeAsyncPrefetchTemplate;
|
|
476
|
+
const opts = {
|
|
477
|
+
ASYNC_REQUIRE_MODULE_PATH: nullthrows(
|
|
478
|
+
state.asyncRequireModulePathStringLiteral
|
|
479
|
+
),
|
|
480
|
+
MODULE_ID: createModuleIDExpression(dependency, state),
|
|
481
|
+
DEPENDENCY_MAP: nullthrows(state.dependencyMapIdentifier),
|
|
482
|
+
...(state.keepRequireNames
|
|
483
|
+
? {
|
|
484
|
+
MODULE_NAME: createModuleNameLiteral(dependency),
|
|
485
|
+
}
|
|
486
|
+
: null),
|
|
487
|
+
};
|
|
488
|
+
path.replaceWith(makeNode(opts));
|
|
472
489
|
},
|
|
473
490
|
transformIllegalDynamicRequire(path, state) {
|
|
474
491
|
path.replaceWith(
|
|
@@ -530,7 +547,7 @@ function getKeyForDependency(qualifier) {
|
|
|
530
547
|
}
|
|
531
548
|
return key;
|
|
532
549
|
}
|
|
533
|
-
class
|
|
550
|
+
class DependencyRegistry {
|
|
534
551
|
_dependencies = new Map();
|
|
535
552
|
registerDependency(qualifier) {
|
|
536
553
|
const key = getKeyForDependency(qualifier);
|
|
@@ -72,7 +72,7 @@ export type InternalDependency = $ReadOnly<MutableInternalDependency>;
|
|
|
72
72
|
export type State = {
|
|
73
73
|
asyncRequireModulePathStringLiteral: ?StringLiteral,
|
|
74
74
|
dependencyCalls: Set<string>,
|
|
75
|
-
dependencyRegistry:
|
|
75
|
+
dependencyRegistry: DependencyRegistry,
|
|
76
76
|
dependencyTransformer: DependencyTransformer,
|
|
77
77
|
dynamicRequires: DynamicRequiresBehavior,
|
|
78
78
|
dependencyMapIdentifier: ?Identifier,
|
|
@@ -89,7 +89,6 @@ export type Options = $ReadOnly<{
|
|
|
89
89
|
inlineableCalls: $ReadOnlyArray<string>,
|
|
90
90
|
keepRequireNames: boolean,
|
|
91
91
|
allowOptionalDependencies: AllowOptionalDependencies,
|
|
92
|
-
dependencyRegistry?: ModuleDependencyRegistry,
|
|
93
92
|
dependencyTransformer?: DependencyTransformer,
|
|
94
93
|
/** Enable `require.context` statements which can be used to import multiple files in a directory. */
|
|
95
94
|
unstable_allowRequireContext: boolean,
|
|
@@ -101,15 +100,6 @@ export type CollectedDependencies = $ReadOnly<{
|
|
|
101
100
|
dependencies: $ReadOnlyArray<Dependency>,
|
|
102
101
|
}>;
|
|
103
102
|
|
|
104
|
-
// Registry for the dependency of a module.
|
|
105
|
-
// Defines when dependencies should be collapsed.
|
|
106
|
-
// E.g. should a module that's once required optionally and once not
|
|
107
|
-
// be treated as the same or different dependencies.
|
|
108
|
-
export interface ModuleDependencyRegistry {
|
|
109
|
-
registerDependency(qualifier: ImportQualifier): InternalDependency;
|
|
110
|
-
getDependencies(): Array<InternalDependency>;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
103
|
export interface DependencyTransformer {
|
|
114
104
|
transformSyncRequire(
|
|
115
105
|
path: NodePath<CallExpression>,
|
|
@@ -149,8 +139,7 @@ function collectDependencies(
|
|
|
149
139
|
const state: State = {
|
|
150
140
|
asyncRequireModulePathStringLiteral: null,
|
|
151
141
|
dependencyCalls: new Set(),
|
|
152
|
-
dependencyRegistry:
|
|
153
|
-
options.dependencyRegistry ?? new DefaultModuleDependencyRegistry(),
|
|
142
|
+
dependencyRegistry: new DependencyRegistry(),
|
|
154
143
|
dependencyTransformer:
|
|
155
144
|
options.dependencyTransformer ?? DefaultDependencyTransformer,
|
|
156
145
|
dependencyMapIdentifier: null,
|
|
@@ -626,11 +615,19 @@ const dynamicRequireErrorTemplate = template.expression(`
|
|
|
626
615
|
* "require(...)" call to the asyncRequire specified.
|
|
627
616
|
*/
|
|
628
617
|
const makeAsyncRequireTemplate = template.expression(`
|
|
629
|
-
require(ASYNC_REQUIRE_MODULE_PATH)(MODULE_ID,
|
|
618
|
+
require(ASYNC_REQUIRE_MODULE_PATH)(MODULE_ID, DEPENDENCY_MAP.paths)
|
|
619
|
+
`);
|
|
620
|
+
|
|
621
|
+
const makeAsyncRequireTemplateWithName = template.expression(`
|
|
622
|
+
require(ASYNC_REQUIRE_MODULE_PATH)(MODULE_ID, DEPENDENCY_MAP.paths, MODULE_NAME)
|
|
630
623
|
`);
|
|
631
624
|
|
|
632
625
|
const makeAsyncPrefetchTemplate = template.expression(`
|
|
633
|
-
require(ASYNC_REQUIRE_MODULE_PATH).prefetch(MODULE_ID,
|
|
626
|
+
require(ASYNC_REQUIRE_MODULE_PATH).prefetch(MODULE_ID, DEPENDENCY_MAP.paths)
|
|
627
|
+
`);
|
|
628
|
+
|
|
629
|
+
const makeAsyncPrefetchTemplateWithName = template.expression(`
|
|
630
|
+
require(ASYNC_REQUIRE_MODULE_PATH).prefetch(MODULE_ID, DEPENDENCY_MAP.paths, MODULE_NAME)
|
|
634
631
|
`);
|
|
635
632
|
|
|
636
633
|
const makeResolveWeakTemplate = template.expression(`
|
|
@@ -661,16 +658,20 @@ const DefaultDependencyTransformer: DependencyTransformer = {
|
|
|
661
658
|
dependency: InternalDependency,
|
|
662
659
|
state: State,
|
|
663
660
|
): void {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
661
|
+
const makeNode = state.keepRequireNames
|
|
662
|
+
? makeAsyncRequireTemplateWithName
|
|
663
|
+
: makeAsyncRequireTemplate;
|
|
664
|
+
const opts = {
|
|
665
|
+
ASYNC_REQUIRE_MODULE_PATH: nullthrows(
|
|
666
|
+
state.asyncRequireModulePathStringLiteral,
|
|
667
|
+
),
|
|
668
|
+
MODULE_ID: createModuleIDExpression(dependency, state),
|
|
669
|
+
DEPENDENCY_MAP: nullthrows(state.dependencyMapIdentifier),
|
|
670
|
+
...(state.keepRequireNames
|
|
671
|
+
? {MODULE_NAME: createModuleNameLiteral(dependency)}
|
|
672
|
+
: null),
|
|
673
|
+
};
|
|
674
|
+
path.replaceWith(makeNode(opts));
|
|
674
675
|
},
|
|
675
676
|
|
|
676
677
|
transformPrefetch(
|
|
@@ -678,16 +679,20 @@ const DefaultDependencyTransformer: DependencyTransformer = {
|
|
|
678
679
|
dependency: InternalDependency,
|
|
679
680
|
state: State,
|
|
680
681
|
): void {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
682
|
+
const makeNode = state.keepRequireNames
|
|
683
|
+
? makeAsyncPrefetchTemplateWithName
|
|
684
|
+
: makeAsyncPrefetchTemplate;
|
|
685
|
+
const opts = {
|
|
686
|
+
ASYNC_REQUIRE_MODULE_PATH: nullthrows(
|
|
687
|
+
state.asyncRequireModulePathStringLiteral,
|
|
688
|
+
),
|
|
689
|
+
MODULE_ID: createModuleIDExpression(dependency, state),
|
|
690
|
+
DEPENDENCY_MAP: nullthrows(state.dependencyMapIdentifier),
|
|
691
|
+
...(state.keepRequireNames
|
|
692
|
+
? {MODULE_NAME: createModuleNameLiteral(dependency)}
|
|
693
|
+
: null),
|
|
694
|
+
};
|
|
695
|
+
path.replaceWith(makeNode(opts));
|
|
691
696
|
},
|
|
692
697
|
|
|
693
698
|
transformIllegalDynamicRequire(path: NodePath<>, state: State): void {
|
|
@@ -758,7 +763,7 @@ function getKeyForDependency(qualifier: ImportQualifier): string {
|
|
|
758
763
|
return key;
|
|
759
764
|
}
|
|
760
765
|
|
|
761
|
-
class
|
|
766
|
+
class DependencyRegistry {
|
|
762
767
|
_dependencies: Map<string, InternalDependency> = new Map();
|
|
763
768
|
|
|
764
769
|
registerDependency(qualifier: ImportQualifier): InternalDependency {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {IncomingMessage, ServerResponse} from 'http';
|
|
12
|
+
|
|
13
|
+
export type Data = string | Buffer | Uint8Array;
|
|
14
|
+
export interface Headers {
|
|
15
|
+
[name: string]: string | number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class MultipartResponse {
|
|
19
|
+
static wrapIfSupported(
|
|
20
|
+
req: IncomingMessage,
|
|
21
|
+
res: ServerResponse,
|
|
22
|
+
): MultipartResponse | ServerResponse;
|
|
23
|
+
static serializeHeaders(headers: Headers): string;
|
|
24
|
+
res: ServerResponse;
|
|
25
|
+
headers: Headers;
|
|
26
|
+
constructor(res: ServerResponse);
|
|
27
|
+
writeChunk(headers: Headers | null, data?: Data, isLast?: boolean): void;
|
|
28
|
+
writeHead(status: number, headers?: Headers): void;
|
|
29
|
+
setHeader(name: string, value: string | number): void;
|
|
30
|
+
end(data?: Data): void;
|
|
31
|
+
}
|
package/src/Server.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {AssetData} from './Asset';
|
|
12
|
+
import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo';
|
|
13
|
+
import IncrementalBundler, {RevisionId} from './IncrementalBundler';
|
|
14
|
+
import type {GraphId} from './lib/getGraphId';
|
|
15
|
+
import type MultipartResponse from './Server/MultipartResponse';
|
|
16
|
+
import type {
|
|
17
|
+
BundleOptions,
|
|
18
|
+
GraphOptions,
|
|
19
|
+
SplitBundleOptions,
|
|
20
|
+
} from './shared/types';
|
|
21
|
+
import type {IncomingMessage, ServerResponse} from 'http';
|
|
22
|
+
import type {
|
|
23
|
+
CustomTransformOptions,
|
|
24
|
+
TransformProfile,
|
|
25
|
+
} from 'metro-babel-transformer';
|
|
26
|
+
import type {ConfigT, RootPerfLogger} from 'metro-config';
|
|
27
|
+
import type {CustomResolverOptions} from 'metro-resolver';
|
|
28
|
+
|
|
29
|
+
export interface SegmentLoadData {
|
|
30
|
+
[index: number]: [number[], number | null];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface BundleMetadata {
|
|
34
|
+
hash: string;
|
|
35
|
+
otaBuildNumber: string | null;
|
|
36
|
+
mobileConfigs: string[];
|
|
37
|
+
segmentHashes: string[];
|
|
38
|
+
segmentLoadData: SegmentLoadData;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ProcessStartContext extends SplitBundleOptions {
|
|
42
|
+
readonly buildNumber: number;
|
|
43
|
+
readonly bundleOptions: BundleOptions;
|
|
44
|
+
readonly graphId: GraphId;
|
|
45
|
+
readonly graphOptions: GraphOptions;
|
|
46
|
+
readonly mres: MultipartResponse | ServerResponse;
|
|
47
|
+
readonly req: IncomingMessage;
|
|
48
|
+
readonly revisionId?: RevisionId | null;
|
|
49
|
+
readonly bundlePerfLogger: RootPerfLogger;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ProcessDeleteContext {
|
|
53
|
+
readonly graphId: GraphId;
|
|
54
|
+
readonly req: IncomingMessage;
|
|
55
|
+
readonly res: ServerResponse;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ProcessEndContext<T> extends ProcessStartContext {
|
|
59
|
+
readonly result: T;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type ServerOptions = Readonly<{
|
|
63
|
+
hasReducedPerformance?: boolean;
|
|
64
|
+
onBundleBuilt?: (bundlePath: string) => void;
|
|
65
|
+
watch?: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
|
|
68
|
+
export interface DefaultGraphOptions {
|
|
69
|
+
customResolverOptions: CustomResolverOptions;
|
|
70
|
+
customTransformOptions: CustomTransformOptions;
|
|
71
|
+
dev: boolean;
|
|
72
|
+
hot: boolean;
|
|
73
|
+
minify: boolean;
|
|
74
|
+
runtimeBytecodeVersion?: number;
|
|
75
|
+
unstable_transformProfile: TransformProfile;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface DefaultBundleOptions extends DefaultGraphOptions {
|
|
79
|
+
excludeSource: false;
|
|
80
|
+
inlineSourceMap: false;
|
|
81
|
+
modulesOnly: false;
|
|
82
|
+
onProgress: null;
|
|
83
|
+
runModule: true;
|
|
84
|
+
shallow: false;
|
|
85
|
+
sourceMapUrl: null;
|
|
86
|
+
sourceUrl: null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default class Server {
|
|
90
|
+
static DEFAULT_GRAPH_OPTIONS: DefaultGraphOptions;
|
|
91
|
+
static DEFAULT_BUNDLE_OPTIONS: BundleOptions;
|
|
92
|
+
constructor(config: ConfigT, options?: ServerOptions);
|
|
93
|
+
end(): void;
|
|
94
|
+
getBundler(): IncrementalBundler;
|
|
95
|
+
getCreateModuleId(): (path: string) => number;
|
|
96
|
+
build(options: BundleOptions): Promise<{
|
|
97
|
+
code: string;
|
|
98
|
+
map: string;
|
|
99
|
+
}>;
|
|
100
|
+
getRamBundleInfo(options: BundleOptions): Promise<RamBundleInfo>;
|
|
101
|
+
getAssets(options: BundleOptions): Promise<ReadonlyArray<AssetData>>;
|
|
102
|
+
getOrderedDependencyPaths(options: {
|
|
103
|
+
readonly dev: boolean;
|
|
104
|
+
readonly entryFile: string;
|
|
105
|
+
readonly minify: boolean;
|
|
106
|
+
readonly platform: string;
|
|
107
|
+
}): Promise<string[]>;
|
|
108
|
+
processRequest(
|
|
109
|
+
IncomingMessage: IncomingMessage,
|
|
110
|
+
ServerResponse: ServerResponse,
|
|
111
|
+
next: (e: Error | null) => unknown,
|
|
112
|
+
): void;
|
|
113
|
+
}
|
package/src/Server.js
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"use strict";
|
|
13
13
|
|
|
14
14
|
const { getAsset } = require("./Assets");
|
|
15
|
-
const baseBytecodeBundle = require("./DeltaBundler/Serializers/baseBytecodeBundle");
|
|
16
15
|
const baseJSBundle = require("./DeltaBundler/Serializers/baseJSBundle");
|
|
17
16
|
const getAllFiles = require("./DeltaBundler/Serializers/getAllFiles");
|
|
18
17
|
const getAssets = require("./DeltaBundler/Serializers/getAssets");
|
|
@@ -23,7 +22,6 @@ const getRamBundleInfo = require("./DeltaBundler/Serializers/getRamBundleInfo");
|
|
|
23
22
|
const sourceMapString = require("./DeltaBundler/Serializers/sourceMapString");
|
|
24
23
|
const IncrementalBundler = require("./IncrementalBundler");
|
|
25
24
|
const ResourceNotFoundError = require("./IncrementalBundler/ResourceNotFoundError");
|
|
26
|
-
const bundleToBytecode = require("./lib/bundleToBytecode");
|
|
27
25
|
const bundleToString = require("./lib/bundleToString");
|
|
28
26
|
const formatBundlingError = require("./lib/formatBundlingError");
|
|
29
27
|
const getGraphId = require("./lib/getGraphId");
|
|
@@ -54,9 +52,6 @@ const noopLogger = {
|
|
|
54
52
|
};
|
|
55
53
|
const DELTA_ID_HEADER = "X-Metro-Delta-ID";
|
|
56
54
|
const FILES_CHANGED_COUNT_HEADER = "X-Metro-Files-Changed-Count";
|
|
57
|
-
function getBytecodeVersion() {
|
|
58
|
-
return require("metro-hermes-compiler").VERSION;
|
|
59
|
-
}
|
|
60
55
|
class Server {
|
|
61
56
|
constructor(config, options) {
|
|
62
57
|
this._config = config;
|
|
@@ -290,10 +285,10 @@ class Server {
|
|
|
290
285
|
"Accept-Ranges": "bytes",
|
|
291
286
|
"Content-Length": chunksize.toString(),
|
|
292
287
|
"Content-Range": `bytes ${dataStart}-${dataEnd}/${data.length}`,
|
|
293
|
-
"Content-Type": mime.lookup(path.basename(assetPath)),
|
|
294
288
|
});
|
|
295
289
|
return data.slice(dataStart, dataEnd + 1);
|
|
296
290
|
}
|
|
291
|
+
res.setHeader("Content-Length", String(Buffer.byteLength(data)));
|
|
297
292
|
return data;
|
|
298
293
|
}
|
|
299
294
|
async _processSingleAssetRequest(req, res) {
|
|
@@ -334,6 +329,7 @@ class Server {
|
|
|
334
329
|
if (process.env.REACT_NATIVE_ENABLE_ASSET_CACHING === true) {
|
|
335
330
|
res.setHeader("Cache-Control", "max-age=31536000");
|
|
336
331
|
}
|
|
332
|
+
res.setHeader("Content-Type", mime.lookup(path.basename(assetPath)));
|
|
337
333
|
res.end(this._rangeRequestMiddleware(req, res, data, assetPath));
|
|
338
334
|
process.nextTick(() => {
|
|
339
335
|
log(createActionEndEntry(processingAssetRequestLogEntry));
|
|
@@ -348,11 +344,7 @@ class Server {
|
|
|
348
344
|
this._processRequest(req, res, next).catch(next);
|
|
349
345
|
};
|
|
350
346
|
_parseOptions(url) {
|
|
351
|
-
return parseOptionsFromUrl(
|
|
352
|
-
url,
|
|
353
|
-
new Set(this._config.resolver.platforms),
|
|
354
|
-
getBytecodeVersion()
|
|
355
|
-
);
|
|
347
|
+
return parseOptionsFromUrl(url, new Set(this._config.resolver.platforms));
|
|
356
348
|
}
|
|
357
349
|
async _processRequest(req, res, next) {
|
|
358
350
|
const originalUrl = req.url;
|
|
@@ -372,20 +364,13 @@ class Server {
|
|
|
372
364
|
const buildNumber = this.getNewBuildNumber();
|
|
373
365
|
if (pathname.endsWith(".bundle")) {
|
|
374
366
|
const options = this._parseOptions(formattedUrl);
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
buildNumber,
|
|
383
|
-
bundlePerfLogger:
|
|
384
|
-
this._config.unstable_perfLoggerFactory?.("BUNDLING_REQUEST", {
|
|
385
|
-
key: buildNumber,
|
|
386
|
-
}) ?? noopLogger,
|
|
387
|
-
});
|
|
388
|
-
}
|
|
367
|
+
await this._processBundleRequest(req, res, options, {
|
|
368
|
+
buildNumber,
|
|
369
|
+
bundlePerfLogger:
|
|
370
|
+
this._config.unstable_perfLoggerFactory?.("BUNDLING_REQUEST", {
|
|
371
|
+
key: buildNumber,
|
|
372
|
+
}) ?? noopLogger,
|
|
373
|
+
});
|
|
389
374
|
if (this._serverOptions && this._serverOptions.onBundleBuilt) {
|
|
390
375
|
this._serverOptions.onBundleBuilt(pathname);
|
|
391
376
|
}
|
|
@@ -533,7 +518,6 @@ class Server {
|
|
|
533
518
|
entryFile: resolvedEntryFilePath,
|
|
534
519
|
minify: transformOptions.minify,
|
|
535
520
|
platform: transformOptions.platform,
|
|
536
|
-
runtimeBytecodeVersion: transformOptions.runtimeBytecodeVersion,
|
|
537
521
|
},
|
|
538
522
|
isPrefetch: req.method === "HEAD",
|
|
539
523
|
type: "bundle_build_started",
|
|
@@ -742,110 +726,6 @@ class Server {
|
|
|
742
726
|
res.end();
|
|
743
727
|
},
|
|
744
728
|
});
|
|
745
|
-
_processBytecodeBundleRequest = this._createRequestProcessor({
|
|
746
|
-
createStartEntry(context) {
|
|
747
|
-
return {
|
|
748
|
-
action_name: "Requesting bundle",
|
|
749
|
-
bundle_url: context.req.url,
|
|
750
|
-
entry_point: context.entryFile,
|
|
751
|
-
bundler: "delta",
|
|
752
|
-
build_id: getBuildID(context.buildNumber),
|
|
753
|
-
bundle_options: context.bundleOptions,
|
|
754
|
-
bundle_hash: context.graphId,
|
|
755
|
-
};
|
|
756
|
-
},
|
|
757
|
-
createEndEntry(context) {
|
|
758
|
-
return {
|
|
759
|
-
outdated_modules: context.result.numModifiedFiles,
|
|
760
|
-
};
|
|
761
|
-
},
|
|
762
|
-
build: async ({
|
|
763
|
-
entryFile,
|
|
764
|
-
graphId,
|
|
765
|
-
graphOptions,
|
|
766
|
-
onProgress,
|
|
767
|
-
resolverOptions,
|
|
768
|
-
serializerOptions,
|
|
769
|
-
transformOptions,
|
|
770
|
-
}) => {
|
|
771
|
-
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
772
|
-
const { delta, revision } = await (revPromise != null
|
|
773
|
-
? this._bundler.updateGraph(await revPromise, false)
|
|
774
|
-
: this._bundler.initializeGraph(
|
|
775
|
-
entryFile,
|
|
776
|
-
transformOptions,
|
|
777
|
-
resolverOptions,
|
|
778
|
-
{
|
|
779
|
-
onProgress,
|
|
780
|
-
shallow: graphOptions.shallow,
|
|
781
|
-
}
|
|
782
|
-
));
|
|
783
|
-
const bundle = bundleToBytecode(
|
|
784
|
-
baseBytecodeBundle(entryFile, revision.prepend, revision.graph, {
|
|
785
|
-
asyncRequireModulePath: await this._resolveRelativePath(
|
|
786
|
-
this._config.transformer.asyncRequireModulePath,
|
|
787
|
-
{
|
|
788
|
-
relativeTo: "project",
|
|
789
|
-
resolverOptions,
|
|
790
|
-
transformOptions,
|
|
791
|
-
}
|
|
792
|
-
),
|
|
793
|
-
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
794
|
-
createModuleId: this._createModuleId,
|
|
795
|
-
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
796
|
-
includeAsyncPaths:
|
|
797
|
-
this._config.server.experimentalImportBundleSupport,
|
|
798
|
-
dev: transformOptions.dev,
|
|
799
|
-
projectRoot: this._config.projectRoot,
|
|
800
|
-
modulesOnly: serializerOptions.modulesOnly,
|
|
801
|
-
runBeforeMainModule:
|
|
802
|
-
this._config.serializer.getModulesRunBeforeMainModule(
|
|
803
|
-
path.relative(this._config.projectRoot, entryFile)
|
|
804
|
-
),
|
|
805
|
-
runModule: serializerOptions.runModule,
|
|
806
|
-
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
807
|
-
sourceUrl: serializerOptions.sourceUrl,
|
|
808
|
-
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
809
|
-
serverRoot:
|
|
810
|
-
this._config.server.unstable_serverRoot ?? this._config.projectRoot,
|
|
811
|
-
})
|
|
812
|
-
);
|
|
813
|
-
return {
|
|
814
|
-
numModifiedFiles: delta.reset
|
|
815
|
-
? delta.added.size + revision.prepend.length
|
|
816
|
-
: delta.added.size + delta.modified.size + delta.deleted.size,
|
|
817
|
-
lastModifiedDate: revision.date,
|
|
818
|
-
nextRevId: revision.id,
|
|
819
|
-
bytecode: bundle.bytecode,
|
|
820
|
-
};
|
|
821
|
-
},
|
|
822
|
-
finish({ req, mres, result }) {
|
|
823
|
-
if (
|
|
824
|
-
// We avoid parsing the dates since the client should never send a more
|
|
825
|
-
// recent date than the one returned by the Delta Bundler (if that's the
|
|
826
|
-
// case it's fine to return the whole bundle).
|
|
827
|
-
req.headers["if-modified-since"] ===
|
|
828
|
-
result.lastModifiedDate.toUTCString()
|
|
829
|
-
) {
|
|
830
|
-
debug("Responding with 304");
|
|
831
|
-
mres.writeHead(304);
|
|
832
|
-
mres.end();
|
|
833
|
-
} else {
|
|
834
|
-
mres.setHeader(
|
|
835
|
-
FILES_CHANGED_COUNT_HEADER,
|
|
836
|
-
String(result.numModifiedFiles)
|
|
837
|
-
);
|
|
838
|
-
mres.setHeader(DELTA_ID_HEADER, String(result.nextRevId));
|
|
839
|
-
mres.setHeader("Content-Type", "application/x-metro-bytecode-bundle");
|
|
840
|
-
mres.setHeader("Last-Modified", result.lastModifiedDate.toUTCString());
|
|
841
|
-
mres.setHeader(
|
|
842
|
-
"Content-Length",
|
|
843
|
-
String(Buffer.byteLength(result.bytecode))
|
|
844
|
-
);
|
|
845
|
-
mres.end(result.bytecode);
|
|
846
|
-
}
|
|
847
|
-
},
|
|
848
|
-
});
|
|
849
729
|
|
|
850
730
|
// This function ensures that modules in source maps are sorted in the same
|
|
851
731
|
// order as in a plain JS bundle.
|
|
@@ -1061,8 +941,7 @@ class Server {
|
|
|
1061
941
|
async _explodedSourceMapForURL(reqUrl) {
|
|
1062
942
|
const options = parseOptionsFromUrl(
|
|
1063
943
|
reqUrl,
|
|
1064
|
-
new Set(this._config.resolver.platforms)
|
|
1065
|
-
getBytecodeVersion()
|
|
944
|
+
new Set(this._config.resolver.platforms)
|
|
1066
945
|
);
|
|
1067
946
|
const {
|
|
1068
947
|
entryFile,
|
|
@@ -1146,7 +1025,6 @@ class Server {
|
|
|
1146
1025
|
dev: true,
|
|
1147
1026
|
hot: false,
|
|
1148
1027
|
minify: false,
|
|
1149
|
-
runtimeBytecodeVersion: null,
|
|
1150
1028
|
unstable_transformProfile: "default",
|
|
1151
1029
|
};
|
|
1152
1030
|
static DEFAULT_BUNDLE_OPTIONS = {
|