metro 0.83.3 → 0.83.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 +28 -24
- package/src/Assets.d.ts +83 -0
- package/src/Assets.js +42 -29
- package/src/Assets.js.flow +26 -15
- package/src/Bundler/util.d.ts +27 -0
- package/src/Bundler/util.js +25 -21
- package/src/Bundler/util.js.flow +2 -2
- package/src/Bundler.d.ts +14 -15
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.d.ts +71 -0
- package/src/DeltaBundler/DeltaCalculator.js +4 -4
- package/src/DeltaBundler/DeltaCalculator.js.flow +8 -8
- package/src/DeltaBundler/Graph.d.ts +135 -8
- package/src/DeltaBundler/Graph.js +16 -16
- package/src/DeltaBundler/Graph.js.flow +30 -30
- package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +20 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.d.ts +22 -0
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getAssets.d.ts +25 -0
- package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +36 -6
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +8 -8
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +12 -0
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +33 -0
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +17 -0
- package/src/DeltaBundler/Serializers/helpers/js.d.ts +30 -0
- package/src/DeltaBundler/Serializers/helpers/js.js +25 -21
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +6 -6
- package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +25 -0
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +30 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +25 -21
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +5 -5
- package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +29 -0
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
- package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +23 -0
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +2 -2
- package/src/DeltaBundler/Serializers/sourceMapString.d.ts +22 -0
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
- package/src/DeltaBundler/Transformer.d.ts +38 -0
- package/src/DeltaBundler/Transformer.js.flow +3 -3
- package/src/DeltaBundler/Worker.d.ts +19 -27
- package/src/DeltaBundler/Worker.flow.js.flow +1 -1
- package/src/DeltaBundler/WorkerFarm.d.ts +70 -0
- package/src/DeltaBundler/WorkerFarm.js +1 -1
- package/src/DeltaBundler/WorkerFarm.js.flow +26 -13
- package/src/DeltaBundler/buildSubgraph.d.ts +30 -0
- package/src/DeltaBundler/buildSubgraph.js +4 -4
- package/src/DeltaBundler/buildSubgraph.js.flow +8 -8
- package/src/DeltaBundler/getTransformCacheKey.d.ts +18 -0
- package/src/DeltaBundler/mergeDeltas.d.ts +17 -0
- package/src/DeltaBundler/types.d.ts +97 -100
- package/src/DeltaBundler/types.js.flow +36 -34
- package/src/DeltaBundler.d.ts +14 -12
- package/src/DeltaBundler.js.flow +2 -2
- package/src/HmrServer.d.ts +79 -0
- package/src/HmrServer.js +34 -29
- package/src/HmrServer.js.flow +17 -12
- package/src/IncrementalBundler/GraphNotFoundError.d.ts +17 -0
- package/src/IncrementalBundler/ResourceNotFoundError.d.ts +15 -0
- package/src/IncrementalBundler/RevisionNotFoundError.d.ts +17 -0
- package/src/IncrementalBundler.d.ts +43 -45
- package/src/IncrementalBundler.js +29 -21
- package/src/IncrementalBundler.js.flow +13 -9
- package/src/ModuleGraph/worker/JsFileWrapping.d.ts +29 -0
- package/src/ModuleGraph/worker/JsFileWrapping.js +25 -21
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +10 -5
- package/src/ModuleGraph/worker/collectDependencies.d.ts +118 -14
- package/src/ModuleGraph/worker/collectDependencies.js +25 -21
- package/src/ModuleGraph/worker/collectDependencies.js.flow +27 -21
- package/src/ModuleGraph/worker/generateImportNames.d.ts +19 -0
- package/src/ModuleGraph/worker/generateImportNames.js.flow +4 -2
- package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +26 -0
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +7 -3
- package/src/Server/MultipartResponse.d.ts +5 -6
- package/src/Server/MultipartResponse.js.flow +1 -1
- package/src/Server/symbolicate.js.flow +4 -4
- package/src/Server.d.ts +220 -67
- package/src/Server.js +149 -45
- package/src/Server.js.flow +167 -57
- package/src/cli/parseKeyValueParamArray.d.ts +14 -0
- package/src/cli/parseKeyValueParamArray.js.flow +1 -1
- package/src/cli-utils.d.ts +19 -0
- package/src/cli-utils.js.flow +2 -2
- package/src/commands/build.d.ts +16 -0
- package/src/commands/build.js.flow +11 -10
- package/src/commands/dependencies.d.ts +16 -0
- package/src/commands/dependencies.js.flow +8 -4
- package/src/commands/serve.d.ts +16 -0
- package/src/commands/serve.js +2 -0
- package/src/commands/serve.js.flow +14 -9
- package/src/index.d.ts +97 -110
- package/src/index.flow.js +53 -35
- package/src/index.flow.js.flow +49 -29
- package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
- package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/index.js +25 -21
- package/src/integration_tests/basic_bundle/import-export/index.js.flow +3 -3
- package/src/integration_tests/basic_bundle/import-export/utils.js.flow +2 -2
- package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js.flow +1 -1
- package/src/integration_tests/basic_bundle/optional-dependencies/index.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/empty.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/matching.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +2 -2
- package/src/integration_tests/basic_bundle/require-context/utils.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/execBundle.js.flow +1 -1
- package/src/lib/BatchProcessor.d.ts +54 -0
- package/src/lib/BatchProcessor.js +5 -2
- package/src/lib/BatchProcessor.js.flow +10 -7
- package/src/lib/CountingSet.d.ts +10 -10
- package/src/lib/CountingSet.js.flow +4 -4
- package/src/lib/JsonReporter.d.ts +37 -0
- package/src/lib/JsonReporter.js +5 -3
- package/src/lib/JsonReporter.js.flow +19 -17
- package/src/lib/RamBundleParser.d.ts +29 -0
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.d.ts +97 -6
- package/src/lib/TerminalReporter.js +37 -34
- package/src/lib/TerminalReporter.js.flow +21 -30
- package/src/lib/bundleProgressUtils.d.ts +26 -0
- package/src/lib/bundleProgressUtils.js +19 -0
- package/src/lib/bundleProgressUtils.js.flow +35 -0
- package/src/lib/bundleToString.d.ts +19 -0
- package/src/lib/contextModule.d.ts +20 -9
- package/src/lib/contextModule.js.flow +1 -1
- package/src/lib/contextModuleTemplates.d.ts +25 -0
- package/src/lib/contextModuleTemplates.js +25 -21
- package/src/lib/countLines.d.ts +12 -0
- package/src/lib/countLines.js +4 -3
- package/src/lib/countLines.js.flow +3 -4
- package/src/lib/createWebsocketServer.d.ts +43 -0
- package/src/lib/createWebsocketServer.js +9 -2
- package/src/lib/createWebsocketServer.js.flow +16 -9
- package/src/lib/debounceAsyncQueue.d.ts +15 -0
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.d.ts +23 -0
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/getAppendScripts.d.ts +31 -0
- package/src/lib/getAppendScripts.js.flow +4 -4
- package/src/lib/getGraphId.d.ts +15 -1
- package/src/lib/getGraphId.js.flow +1 -1
- package/src/lib/getPreludeCode.d.ts +18 -0
- package/src/lib/getPreludeCode.js +4 -0
- package/src/lib/getPreludeCode.js.flow +10 -3
- package/src/lib/getPrependedScripts.d.ts +24 -0
- package/src/lib/getPrependedScripts.js +36 -22
- package/src/lib/getPrependedScripts.js.flow +10 -3
- package/src/lib/isResolvedDependency.d.ts +15 -0
- package/src/lib/logToConsole.d.ts +19 -0
- package/src/lib/logToConsole.js.flow +2 -2
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +17 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +25 -21
- package/src/lib/parseCustomResolverOptions.d.ts +16 -0
- package/src/lib/parseCustomResolverOptions.js.flow +2 -2
- package/src/lib/parseCustomTransformOptions.d.ts +16 -0
- package/src/lib/parseCustomTransformOptions.js.flow +1 -1
- package/src/lib/parseJsonBody.d.ts +27 -0
- package/src/lib/parseJsonBody.js.flow +11 -1
- package/src/lib/pathUtils.d.ts +14 -0
- package/src/lib/pathUtils.js +25 -21
- package/src/lib/pathUtils.js.flow +1 -1
- package/src/lib/relativizeSourceMap.d.ts +17 -0
- package/src/lib/reporting.d.ts +65 -81
- package/src/lib/reporting.js.flow +4 -4
- package/src/lib/splitBundleOptions.d.ts +16 -0
- package/src/lib/transformHelpers.d.ts +35 -0
- package/src/lib/transformHelpers.js +11 -9
- package/src/lib/transformHelpers.js.flow +17 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +126 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.js +48 -42
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +35 -32
- package/src/node-haste/DependencyGraph/createFileMap.d.ts +29 -0
- package/src/node-haste/DependencyGraph/createFileMap.js +56 -38
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +44 -18
- package/src/node-haste/DependencyGraph.d.ts +57 -33
- package/src/node-haste/DependencyGraph.js +40 -31
- package/src/node-haste/DependencyGraph.js.flow +35 -37
- package/src/node-haste/Package.d.ts +21 -0
- package/src/node-haste/PackageCache.d.ts +34 -0
- package/src/node-haste/lib/AssetPaths.d.ts +29 -0
- package/src/node-haste/lib/AssetPaths.js +2 -2
- package/src/node-haste/lib/AssetPaths.js.flow +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.d.ts +25 -0
- package/src/node-haste/lib/parsePlatformFilePath.js +6 -6
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +4 -4
- package/src/shared/output/RamBundle/as-assets.d.ts +25 -0
- package/src/shared/output/RamBundle/as-assets.js.flow +6 -6
- package/src/shared/output/RamBundle/as-indexed-file.d.ts +38 -0
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +5 -5
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +23 -0
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +5 -5
- package/src/shared/output/RamBundle/magic-number.d.ts +14 -0
- package/src/shared/output/RamBundle/util.d.ts +41 -0
- package/src/shared/output/RamBundle/util.js.flow +5 -5
- package/src/shared/output/RamBundle/write-sourcemap.d.ts +16 -0
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.d.ts +26 -0
- package/src/shared/output/RamBundle.js.flow +1 -1
- package/src/shared/output/bundle.d.ts +9 -17
- package/src/shared/output/bundle.flow.js.flow +3 -3
- package/src/shared/output/meta.d.ts +15 -0
- package/src/shared/output/meta.js +2 -2
- package/src/shared/output/meta.js.flow +1 -1
- package/src/shared/output/unbundle.d.ts +11 -0
- package/src/shared/output/writeFile.d.ts +16 -0
- package/src/shared/output/writeFile.js +8 -3
- package/src/shared/output/writeFile.js.flow +8 -2
- package/src/shared/types.d.ts +81 -66
- package/src/shared/types.js.flow +20 -5
- package/src/Asset.d.ts +0 -25
- package/src/ModuleGraph/test-helpers.js +0 -75
|
@@ -11,19 +11,20 @@
|
|
|
11
11
|
|
|
12
12
|
import type {RequireContext} from '../lib/contextModule';
|
|
13
13
|
import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
|
|
14
|
+
import type {ReadonlySourceLocation} from '../shared/types';
|
|
14
15
|
import type {Graph} from './Graph';
|
|
15
16
|
import type {JsTransformOptions} from 'metro-transform-worker';
|
|
16
17
|
|
|
17
18
|
import CountingSet from '../lib/CountingSet';
|
|
18
19
|
|
|
19
20
|
export type MixedOutput = {
|
|
20
|
-
+data:
|
|
21
|
+
+data: unknown,
|
|
21
22
|
+type: string,
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
export type AsyncDependencyType = 'async' | 'maybeSync' | 'prefetch' | 'weak';
|
|
25
26
|
|
|
26
|
-
export type TransformResultDependency =
|
|
27
|
+
export type TransformResultDependency = Readonly<{
|
|
27
28
|
/**
|
|
28
29
|
* The literal name provided to a require or import call. For example 'foo' in
|
|
29
30
|
* case of `require('foo')`.
|
|
@@ -33,7 +34,7 @@ export type TransformResultDependency = $ReadOnly<{
|
|
|
33
34
|
/**
|
|
34
35
|
* Extra data returned by the dependency extractor.
|
|
35
36
|
*/
|
|
36
|
-
data:
|
|
37
|
+
data: Readonly<{
|
|
37
38
|
/**
|
|
38
39
|
* A locally unique key for this dependency within the current module.
|
|
39
40
|
*/
|
|
@@ -52,43 +53,43 @@ export type TransformResultDependency = $ReadOnly<{
|
|
|
52
53
|
*/
|
|
53
54
|
isOptional?: boolean,
|
|
54
55
|
|
|
55
|
-
locs:
|
|
56
|
+
locs: ReadonlyArray<ReadonlySourceLocation>,
|
|
56
57
|
|
|
57
58
|
/** Context for requiring a collection of modules. */
|
|
58
59
|
contextParams?: RequireContextParams,
|
|
59
60
|
}>,
|
|
60
61
|
}>;
|
|
61
62
|
|
|
62
|
-
export type ResolvedDependency =
|
|
63
|
+
export type ResolvedDependency = Readonly<{
|
|
63
64
|
absolutePath: string,
|
|
64
65
|
data: TransformResultDependency,
|
|
65
66
|
}>;
|
|
66
67
|
|
|
67
68
|
export type Dependency =
|
|
68
69
|
| ResolvedDependency
|
|
69
|
-
|
|
|
70
|
+
| Readonly<{
|
|
70
71
|
data: TransformResultDependency,
|
|
71
72
|
}>;
|
|
72
73
|
|
|
73
|
-
export type Module<T = MixedOutput> =
|
|
74
|
+
export type Module<T = MixedOutput> = Readonly<{
|
|
74
75
|
dependencies: Map<string, Dependency>,
|
|
75
76
|
inverseDependencies: CountingSet<string>,
|
|
76
|
-
output:
|
|
77
|
+
output: ReadonlyArray<T>,
|
|
77
78
|
path: string,
|
|
78
79
|
getSource: () => Buffer,
|
|
79
80
|
unstable_transformResultKey?: ?string,
|
|
80
81
|
}>;
|
|
81
82
|
|
|
82
|
-
export type ModuleData<T = MixedOutput> =
|
|
83
|
-
dependencies:
|
|
84
|
-
resolvedContexts:
|
|
85
|
-
output:
|
|
83
|
+
export type ModuleData<T = MixedOutput> = Readonly<{
|
|
84
|
+
dependencies: ReadonlyMap<string, Dependency>,
|
|
85
|
+
resolvedContexts: ReadonlyMap<string, RequireContext>,
|
|
86
|
+
output: ReadonlyArray<T>,
|
|
86
87
|
getSource: () => Buffer,
|
|
87
88
|
unstable_transformResultKey?: ?string,
|
|
88
89
|
}>;
|
|
89
90
|
|
|
90
91
|
export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
|
|
91
|
-
export type ReadOnlyDependencies<T = MixedOutput> =
|
|
92
|
+
export type ReadOnlyDependencies<T = MixedOutput> = ReadonlyMap<
|
|
92
93
|
string,
|
|
93
94
|
Module<T>,
|
|
94
95
|
>;
|
|
@@ -98,28 +99,28 @@ export type TransformInputOptions = Omit<
|
|
|
98
99
|
'inlinePlatform' | 'inlineRequires',
|
|
99
100
|
>;
|
|
100
101
|
|
|
101
|
-
export type GraphInputOptions =
|
|
102
|
-
entryPoints:
|
|
102
|
+
export type GraphInputOptions = Readonly<{
|
|
103
|
+
entryPoints: ReadonlySet<string>,
|
|
103
104
|
// Unused in core but useful for custom serializers / experimentalSerializerHook
|
|
104
105
|
transformOptions: TransformInputOptions,
|
|
105
106
|
}>;
|
|
106
107
|
|
|
107
108
|
export interface ReadOnlyGraph<T = MixedOutput> {
|
|
108
|
-
+entryPoints:
|
|
109
|
+
+entryPoints: ReadonlySet<string>;
|
|
109
110
|
// Unused in core but useful for custom serializers / experimentalSerializerHook
|
|
110
|
-
+transformOptions:
|
|
111
|
+
+transformOptions: Readonly<TransformInputOptions>;
|
|
111
112
|
+dependencies: ReadOnlyDependencies<T>;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
export type {Graph};
|
|
115
116
|
|
|
116
|
-
export type TransformResult<T = MixedOutput> =
|
|
117
|
-
dependencies:
|
|
118
|
-
output:
|
|
117
|
+
export type TransformResult<T = MixedOutput> = Readonly<{
|
|
118
|
+
dependencies: ReadonlyArray<TransformResultDependency>,
|
|
119
|
+
output: ReadonlyArray<T>,
|
|
119
120
|
unstable_transformResultKey?: ?string,
|
|
120
121
|
}>;
|
|
121
122
|
|
|
122
|
-
export type TransformResultWithSource<T = MixedOutput> =
|
|
123
|
+
export type TransformResultWithSource<T = MixedOutput> = Readonly<{
|
|
123
124
|
...TransformResult<T>,
|
|
124
125
|
getSource: () => Buffer,
|
|
125
126
|
}>;
|
|
@@ -141,21 +142,22 @@ export type AllowOptionalDependencies =
|
|
|
141
142
|
| boolean
|
|
142
143
|
| AllowOptionalDependenciesWithOptions;
|
|
143
144
|
|
|
144
|
-
export type BundlerResolution =
|
|
145
|
+
export type BundlerResolution = Readonly<{
|
|
145
146
|
type: 'sourceFile',
|
|
146
147
|
filePath: string,
|
|
147
148
|
}>;
|
|
148
149
|
|
|
149
|
-
export type Options<T = MixedOutput> = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
export type Options<T = MixedOutput> = Readonly<{
|
|
151
|
+
resolve: ResolveFn,
|
|
152
|
+
transform: TransformFn<T>,
|
|
153
|
+
transformOptions: TransformInputOptions,
|
|
154
|
+
onProgress: ?(numProcessed: number, total: number) => unknown,
|
|
155
|
+
lazy: boolean,
|
|
156
|
+
unstable_allowRequireContext: boolean,
|
|
157
|
+
unstable_enablePackageExports: boolean,
|
|
158
|
+
unstable_incrementalResolution: boolean,
|
|
159
|
+
shallow: boolean,
|
|
160
|
+
}>;
|
|
159
161
|
|
|
160
162
|
export type DeltaResult<T = MixedOutput> = {
|
|
161
163
|
+added: Map<string, Module<T>>,
|
|
@@ -164,7 +166,7 @@ export type DeltaResult<T = MixedOutput> = {
|
|
|
164
166
|
+reset: boolean,
|
|
165
167
|
};
|
|
166
168
|
|
|
167
|
-
export type SerializerOptions =
|
|
169
|
+
export type SerializerOptions = Readonly<{
|
|
168
170
|
asyncRequireModulePath: string,
|
|
169
171
|
createModuleId: string => number,
|
|
170
172
|
dev: boolean,
|
|
@@ -178,7 +180,7 @@ export type SerializerOptions = $ReadOnly<{
|
|
|
178
180
|
modulesOnly: boolean,
|
|
179
181
|
processModuleFilter: (module: Module<>) => boolean,
|
|
180
182
|
projectRoot: string,
|
|
181
|
-
runBeforeMainModule:
|
|
183
|
+
runBeforeMainModule: ReadonlyArray<string>,
|
|
182
184
|
runModule: boolean,
|
|
183
185
|
serverRoot: string,
|
|
184
186
|
shouldAddToIgnoreList: (Module<>) => boolean,
|
package/src/DeltaBundler.d.ts
CHANGED
|
@@ -15,7 +15,9 @@ import type {
|
|
|
15
15
|
Options,
|
|
16
16
|
ReadOnlyGraph,
|
|
17
17
|
} from './DeltaBundler/types';
|
|
18
|
-
import type
|
|
18
|
+
import type EventEmitter from 'events';
|
|
19
|
+
|
|
20
|
+
import DeltaCalculator from './DeltaBundler/DeltaCalculator';
|
|
19
21
|
|
|
20
22
|
export type {
|
|
21
23
|
DeltaResult,
|
|
@@ -29,8 +31,15 @@ export type {
|
|
|
29
31
|
TransformResultDependency,
|
|
30
32
|
TransformResultWithSource,
|
|
31
33
|
} from './DeltaBundler/types';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
/**
|
|
35
|
+
* `DeltaBundler` uses the `DeltaTransformer` to build bundle deltas. This
|
|
36
|
+
* module handles all the transformer instances so it can support multiple
|
|
37
|
+
* concurrent clients requesting their own deltas. This is done through the
|
|
38
|
+
* `clientId` param (which maps a client to a specific delta transformer).
|
|
39
|
+
*/
|
|
40
|
+
declare class DeltaBundler<T = MixedOutput> {
|
|
41
|
+
_changeEventSource: EventEmitter;
|
|
42
|
+
_deltaCalculators: Map<Graph<T>, DeltaCalculator<T>>;
|
|
34
43
|
constructor(changeEventSource: EventEmitter);
|
|
35
44
|
end(): void;
|
|
36
45
|
getDependencies(
|
|
@@ -41,18 +50,11 @@ export default class DeltaBundler<T = MixedOutput> {
|
|
|
41
50
|
entryPoints: ReadonlyArray<string>,
|
|
42
51
|
options: Options<T>,
|
|
43
52
|
): Promise<Graph<T>>;
|
|
44
|
-
|
|
45
53
|
getDelta(
|
|
46
54
|
graph: Graph<T>,
|
|
47
|
-
{
|
|
48
|
-
reset,
|
|
49
|
-
shallow,
|
|
50
|
-
}: {
|
|
51
|
-
reset: boolean;
|
|
52
|
-
shallow: boolean;
|
|
53
|
-
},
|
|
55
|
+
$$PARAM_1$$: {reset: boolean; shallow: boolean},
|
|
54
56
|
): Promise<DeltaResult<T>>;
|
|
55
|
-
|
|
56
57
|
listen(graph: Graph<T>, callback: () => Promise<void>): () => void;
|
|
57
58
|
endGraph(graph: Graph<T>): void;
|
|
58
59
|
}
|
|
60
|
+
export default DeltaBundler;
|
package/src/DeltaBundler.js.flow
CHANGED
|
@@ -56,7 +56,7 @@ export default class DeltaBundler<T = MixedOutput> {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async getDependencies(
|
|
59
|
-
entryPoints:
|
|
59
|
+
entryPoints: ReadonlyArray<string>,
|
|
60
60
|
options: Options<T>,
|
|
61
61
|
): Promise<ReadOnlyGraph<T>['dependencies']> {
|
|
62
62
|
const deltaCalculator = new DeltaCalculator(
|
|
@@ -76,7 +76,7 @@ export default class DeltaBundler<T = MixedOutput> {
|
|
|
76
76
|
// so that we don't leak graphs that are not reachable.
|
|
77
77
|
// To get just the dependencies, use getDependencies which will not leak graphs.
|
|
78
78
|
async buildGraph(
|
|
79
|
-
entryPoints:
|
|
79
|
+
entryPoints: ReadonlyArray<string>,
|
|
80
80
|
options: Options<T>,
|
|
81
81
|
): Promise<Graph<T>> {
|
|
82
82
|
const deltaCalculator = new DeltaCalculator(
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
RevisionId,
|
|
12
|
+
default as IncrementalBundler,
|
|
13
|
+
} from './IncrementalBundler';
|
|
14
|
+
import type {GraphOptions} from './shared/types';
|
|
15
|
+
import type {ConfigT, RootPerfLogger} from 'metro-config';
|
|
16
|
+
import type {
|
|
17
|
+
HmrErrorMessage,
|
|
18
|
+
HmrUpdateMessage,
|
|
19
|
+
} from 'metro-runtime/src/modules/types';
|
|
20
|
+
|
|
21
|
+
export type Client = {
|
|
22
|
+
optedIntoHMR: boolean;
|
|
23
|
+
revisionIds: Array<RevisionId>;
|
|
24
|
+
readonly sendFn: ($$PARAM_0$$: string) => void;
|
|
25
|
+
};
|
|
26
|
+
type ClientGroup = {
|
|
27
|
+
readonly clients: Set<Client>;
|
|
28
|
+
clientUrl: URL;
|
|
29
|
+
revisionId: RevisionId;
|
|
30
|
+
readonly unlisten: () => void;
|
|
31
|
+
readonly graphOptions: GraphOptions;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The HmrServer (Hot Module Reloading) implements a lightweight interface
|
|
35
|
+
* to communicate easily to the logic in the React Native repository (which
|
|
36
|
+
* is the one that handles the Web Socket connections).
|
|
37
|
+
*
|
|
38
|
+
* This interface allows the HmrServer to hook its own logic to WS clients
|
|
39
|
+
* getting connected, disconnected or having errors (through the
|
|
40
|
+
* `onClientConnect`, `onClientDisconnect` and `onClientError` methods).
|
|
41
|
+
*/
|
|
42
|
+
declare class HmrServer<TClient extends Client> {
|
|
43
|
+
_config: ConfigT;
|
|
44
|
+
_bundler: IncrementalBundler;
|
|
45
|
+
_createModuleId: (path: string) => number;
|
|
46
|
+
_clientGroups: Map<RevisionId, ClientGroup>;
|
|
47
|
+
constructor(
|
|
48
|
+
bundler: IncrementalBundler,
|
|
49
|
+
createModuleId: (path: string) => number,
|
|
50
|
+
config: ConfigT,
|
|
51
|
+
);
|
|
52
|
+
onClientConnect: (
|
|
53
|
+
requestUrl: string,
|
|
54
|
+
sendFn: (data: string) => void,
|
|
55
|
+
) => Promise<Client>;
|
|
56
|
+
_registerEntryPoint(
|
|
57
|
+
client: Client,
|
|
58
|
+
originalRequestUrl: string,
|
|
59
|
+
sendFn: (data: string) => void,
|
|
60
|
+
): Promise<void>;
|
|
61
|
+
onClientMessage: (
|
|
62
|
+
client: TClient,
|
|
63
|
+
message: string | Buffer | ArrayBuffer | Array<Buffer>,
|
|
64
|
+
sendFn: (data: string) => void,
|
|
65
|
+
) => Promise<void>;
|
|
66
|
+
onClientError: (client: TClient, e: Error) => void;
|
|
67
|
+
onClientDisconnect: (client: TClient) => void;
|
|
68
|
+
_handleFileChange(
|
|
69
|
+
group: ClientGroup,
|
|
70
|
+
options: {isInitialUpdate: boolean},
|
|
71
|
+
changeEvent: null | undefined | {logger: null | undefined | RootPerfLogger},
|
|
72
|
+
): Promise<void>;
|
|
73
|
+
_prepareMessage(
|
|
74
|
+
group: ClientGroup,
|
|
75
|
+
options: {isInitialUpdate: boolean},
|
|
76
|
+
changeEvent: null | undefined | {logger: null | undefined | RootPerfLogger},
|
|
77
|
+
): Promise<HmrUpdateMessage | HmrErrorMessage>;
|
|
78
|
+
}
|
|
79
|
+
export default HmrServer;
|
package/src/HmrServer.js
CHANGED
|
@@ -31,28 +31,32 @@ var transformHelpers = _interopRequireWildcard(
|
|
|
31
31
|
);
|
|
32
32
|
var _metroCore = require("metro-core");
|
|
33
33
|
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
34
|
-
function
|
|
35
|
-
if ("function"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var n = { __proto__: null },
|
|
49
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
50
|
-
for (var u in e)
|
|
51
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
52
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
53
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
34
|
+
function _interopRequireWildcard(e, t) {
|
|
35
|
+
if ("function" == typeof WeakMap)
|
|
36
|
+
var r = new WeakMap(),
|
|
37
|
+
n = new WeakMap();
|
|
38
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
39
|
+
if (!t && e && e.__esModule) return e;
|
|
40
|
+
var o,
|
|
41
|
+
i,
|
|
42
|
+
f = { __proto__: null, default: e };
|
|
43
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
44
|
+
return f;
|
|
45
|
+
if ((o = t ? n : r)) {
|
|
46
|
+
if (o.has(e)) return o.get(e);
|
|
47
|
+
o.set(e, f);
|
|
54
48
|
}
|
|
55
|
-
|
|
49
|
+
for (const t in e)
|
|
50
|
+
"default" !== t &&
|
|
51
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
52
|
+
((i =
|
|
53
|
+
(o = Object.defineProperty) &&
|
|
54
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
55
|
+
(i.get || i.set)
|
|
56
|
+
? o(f, t, i)
|
|
57
|
+
: (f[t] = e[t]));
|
|
58
|
+
return f;
|
|
59
|
+
})(e, t);
|
|
56
60
|
}
|
|
57
61
|
function _interopRequireDefault(e) {
|
|
58
62
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -77,9 +81,10 @@ class HmrServer {
|
|
|
77
81
|
optedIntoHMR: false,
|
|
78
82
|
};
|
|
79
83
|
};
|
|
80
|
-
async _registerEntryPoint(client,
|
|
81
|
-
debug("Registering entry point: %s",
|
|
82
|
-
requestUrl =
|
|
84
|
+
async _registerEntryPoint(client, originalRequestUrl, sendFn) {
|
|
85
|
+
debug("Registering entry point: %s", originalRequestUrl);
|
|
86
|
+
const requestUrl =
|
|
87
|
+
this._config.server.rewriteRequestUrl(originalRequestUrl);
|
|
83
88
|
debug("Rewritten as: %s", requestUrl);
|
|
84
89
|
const { bundleType: _bundleType, ...options } = (0,
|
|
85
90
|
_parseBundleOptionsFromBundleRequestUrl.default)(
|
|
@@ -150,7 +155,7 @@ class HmrServer {
|
|
|
150
155
|
unlisten: () => unlisten(),
|
|
151
156
|
};
|
|
152
157
|
this._clientGroups.set(id, clientGroup);
|
|
153
|
-
let
|
|
158
|
+
let latestChangeEvent = null;
|
|
154
159
|
const debounceCallHandleFileChange = (0, _debounceAsyncQueue.default)(
|
|
155
160
|
async () => {
|
|
156
161
|
await this._handleFileChange(
|
|
@@ -158,15 +163,15 @@ class HmrServer {
|
|
|
158
163
|
{
|
|
159
164
|
isInitialUpdate: false,
|
|
160
165
|
},
|
|
161
|
-
|
|
166
|
+
latestChangeEvent,
|
|
162
167
|
);
|
|
163
168
|
},
|
|
164
169
|
50,
|
|
165
170
|
);
|
|
166
171
|
const unlisten = this._bundler
|
|
167
172
|
.getDeltaBundler()
|
|
168
|
-
.listen(graph, async (
|
|
169
|
-
|
|
173
|
+
.listen(graph, async (changeEvent) => {
|
|
174
|
+
latestChangeEvent = changeEvent;
|
|
170
175
|
await debounceCallHandleFileChange();
|
|
171
176
|
});
|
|
172
177
|
}
|
|
@@ -218,7 +223,7 @@ class HmrServer {
|
|
|
218
223
|
onClientError = (client, e) => {
|
|
219
224
|
this._config.reporter.update({
|
|
220
225
|
type: "hmr_client_error",
|
|
221
|
-
error: e
|
|
226
|
+
error: e,
|
|
222
227
|
});
|
|
223
228
|
this.onClientDisconnect(client);
|
|
224
229
|
};
|
package/src/HmrServer.js.flow
CHANGED
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
+
* @flow strict-local
|
|
7
8
|
* @format
|
|
8
|
-
* @flow
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type
|
|
11
|
+
import type {
|
|
12
|
+
RevisionId,
|
|
13
|
+
default as IncrementalBundler,
|
|
14
|
+
} from './IncrementalBundler';
|
|
12
15
|
import type {GraphOptions} from './shared/types';
|
|
13
16
|
import type {ConfigT, RootPerfLogger} from 'metro-config';
|
|
14
17
|
import type {
|
|
@@ -93,11 +96,12 @@ export default class HmrServer<TClient: Client> {
|
|
|
93
96
|
|
|
94
97
|
async _registerEntryPoint(
|
|
95
98
|
client: Client,
|
|
96
|
-
|
|
99
|
+
originalRequestUrl: string,
|
|
97
100
|
sendFn: (data: string) => void,
|
|
98
101
|
): Promise<void> {
|
|
99
|
-
debug('Registering entry point: %s',
|
|
100
|
-
requestUrl =
|
|
102
|
+
debug('Registering entry point: %s', originalRequestUrl);
|
|
103
|
+
const requestUrl =
|
|
104
|
+
this._config.server.rewriteRequestUrl(originalRequestUrl);
|
|
101
105
|
debug('Rewritten as: %s', requestUrl);
|
|
102
106
|
|
|
103
107
|
const {bundleType: _bundleType, ...options} =
|
|
@@ -176,21 +180,22 @@ export default class HmrServer<TClient: Client> {
|
|
|
176
180
|
|
|
177
181
|
this._clientGroups.set(id, clientGroup);
|
|
178
182
|
|
|
179
|
-
let
|
|
183
|
+
let latestChangeEvent: ?{
|
|
184
|
+
logger: ?RootPerfLogger,
|
|
185
|
+
} = null;
|
|
180
186
|
|
|
181
187
|
const debounceCallHandleFileChange = debounceAsyncQueue(async () => {
|
|
182
188
|
await this._handleFileChange(
|
|
183
189
|
nullthrows(clientGroup),
|
|
184
190
|
{isInitialUpdate: false},
|
|
185
|
-
|
|
191
|
+
latestChangeEvent,
|
|
186
192
|
);
|
|
187
193
|
}, 50);
|
|
188
194
|
|
|
189
195
|
const unlisten = this._bundler
|
|
190
196
|
.getDeltaBundler()
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
latestEventArgs = args;
|
|
197
|
+
.listen(graph, async changeEvent => {
|
|
198
|
+
latestChangeEvent = changeEvent;
|
|
194
199
|
await debounceCallHandleFileChange();
|
|
195
200
|
});
|
|
196
201
|
}
|
|
@@ -242,10 +247,10 @@ export default class HmrServer<TClient: Client> {
|
|
|
242
247
|
return Promise.resolve();
|
|
243
248
|
};
|
|
244
249
|
|
|
245
|
-
onClientError: (client: TClient, e:
|
|
250
|
+
onClientError: (client: TClient, e: Error) => void = (client, e) => {
|
|
246
251
|
this._config.reporter.update({
|
|
247
252
|
type: 'hmr_client_error',
|
|
248
|
-
error: e
|
|
253
|
+
error: e,
|
|
249
254
|
});
|
|
250
255
|
this.onClientDisconnect(client);
|
|
251
256
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {GraphId} from '../lib/getGraphId';
|
|
12
|
+
|
|
13
|
+
declare class GraphNotFoundError extends Error {
|
|
14
|
+
graphId: GraphId;
|
|
15
|
+
constructor(graphId: GraphId);
|
|
16
|
+
}
|
|
17
|
+
export default GraphNotFoundError;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
declare class ResourceNotFoundError extends Error {
|
|
12
|
+
resourcePath: string;
|
|
13
|
+
constructor(resourcePath: string);
|
|
14
|
+
}
|
|
15
|
+
export default ResourceNotFoundError;
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {RevisionId} from '../IncrementalBundler';
|
|
12
|
+
|
|
13
|
+
declare class RevisionNotFoundError extends Error {
|
|
14
|
+
revisionId: RevisionId;
|
|
15
|
+
constructor(revisionId: RevisionId);
|
|
16
|
+
}
|
|
17
|
+
export default RevisionNotFoundError;
|