metro 0.83.3 → 0.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -25
- package/src/Assets.js +42 -29
- package/src/Assets.js.flow +26 -15
- package/src/Bundler/util.js +25 -21
- package/src/Bundler/util.js.flow +2 -2
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.js +4 -4
- package/src/DeltaBundler/DeltaCalculator.js.flow +8 -8
- package/src/DeltaBundler/Graph.js +16 -16
- package/src/DeltaBundler/Graph.js.flow +30 -30
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +8 -8
- 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.js.flow +3 -3
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +25 -21
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +5 -5
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +2 -2
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
- package/src/DeltaBundler/Transformer.js.flow +3 -3
- package/src/DeltaBundler/Worker.flow.js.flow +1 -1
- package/src/DeltaBundler/WorkerFarm.js +1 -1
- package/src/DeltaBundler/WorkerFarm.js.flow +26 -13
- package/src/DeltaBundler/buildSubgraph.js +4 -4
- package/src/DeltaBundler/buildSubgraph.js.flow +8 -8
- package/src/DeltaBundler/types.js.flow +36 -34
- package/src/DeltaBundler.js.flow +2 -2
- package/src/HmrServer.js +34 -29
- package/src/HmrServer.js.flow +17 -12
- package/src/IncrementalBundler.js +29 -21
- package/src/IncrementalBundler.js.flow +13 -9
- package/src/ModuleGraph/worker/JsFileWrapping.js +25 -21
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +10 -5
- package/src/ModuleGraph/worker/collectDependencies.js +25 -21
- package/src/ModuleGraph/worker/collectDependencies.js.flow +27 -21
- package/src/ModuleGraph/worker/generateImportNames.js.flow +4 -2
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +7 -3
- package/src/Server/MultipartResponse.js.flow +1 -1
- package/src/Server/symbolicate.js.flow +4 -4
- package/src/Server.js +139 -39
- package/src/Server.js.flow +158 -47
- package/src/cli/parseKeyValueParamArray.js.flow +1 -1
- package/src/cli-utils.js.flow +2 -2
- package/src/commands/build.js.flow +11 -10
- package/src/commands/dependencies.js.flow +8 -4
- package/src/commands/serve.js +2 -0
- package/src/commands/serve.js.flow +14 -9
- package/src/index.flow.js +30 -26
- package/src/index.flow.js.flow +25 -20
- 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.js +5 -2
- package/src/lib/BatchProcessor.js.flow +10 -7
- package/src/lib/CountingSet.js.flow +4 -4
- package/src/lib/JsonReporter.js +5 -3
- package/src/lib/JsonReporter.js.flow +19 -17
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.js +31 -27
- package/src/lib/TerminalReporter.js.flow +15 -15
- package/src/lib/contextModule.js.flow +1 -1
- package/src/lib/contextModuleTemplates.js +25 -21
- package/src/lib/countLines.js +4 -3
- package/src/lib/countLines.js.flow +3 -4
- package/src/lib/createWebsocketServer.js +9 -2
- package/src/lib/createWebsocketServer.js.flow +16 -9
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/getAppendScripts.js.flow +4 -4
- package/src/lib/getGraphId.js.flow +1 -1
- package/src/lib/getPreludeCode.js +4 -0
- package/src/lib/getPreludeCode.js.flow +10 -3
- package/src/lib/getPrependedScripts.js +36 -22
- package/src/lib/getPrependedScripts.js.flow +10 -3
- package/src/lib/logToConsole.js.flow +2 -2
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +25 -21
- package/src/lib/parseCustomResolverOptions.js.flow +2 -2
- package/src/lib/parseCustomTransformOptions.js.flow +1 -1
- package/src/lib/parseJsonBody.js.flow +11 -1
- package/src/lib/pathUtils.js +25 -21
- package/src/lib/pathUtils.js.flow +1 -1
- package/src/lib/reporting.js.flow +4 -4
- package/src/lib/transformHelpers.js +11 -9
- package/src/lib/transformHelpers.js.flow +17 -15
- 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.js +56 -38
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +44 -18
- package/src/node-haste/DependencyGraph.js +40 -31
- package/src/node-haste/DependencyGraph.js.flow +35 -37
- 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.js +6 -6
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +4 -4
- package/src/shared/output/RamBundle/as-assets.js.flow +6 -6
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +5 -5
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +5 -5
- package/src/shared/output/RamBundle/util.js.flow +5 -5
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.js.flow +1 -1
- package/src/shared/output/bundle.flow.js.flow +3 -3
- package/src/shared/output/meta.js +2 -2
- package/src/shared/output/meta.js.flow +1 -1
- package/src/shared/output/writeFile.js +8 -3
- package/src/shared/output/writeFile.js.flow +8 -2
- package/src/shared/types.js.flow +20 -5
- package/src/Asset.d.ts +0 -25
- package/src/Bundler.d.ts +0 -39
- package/src/DeltaBundler/Graph.d.ts +0 -40
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +0 -26
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +0 -18
- package/src/DeltaBundler/Worker.d.ts +0 -45
- package/src/DeltaBundler/types.d.ts +0 -166
- package/src/DeltaBundler.d.ts +0 -58
- package/src/IncrementalBundler.d.ts +0 -98
- package/src/ModuleGraph/test-helpers.js +0 -75
- package/src/ModuleGraph/worker/collectDependencies.d.ts +0 -27
- package/src/Server/MultipartResponse.d.ts +0 -31
- package/src/Server/symbolicate.d.ts +0 -31
- package/src/Server.d.ts +0 -118
- package/src/index.d.ts +0 -193
- package/src/lib/CountingSet.d.ts +0 -48
- package/src/lib/TerminalReporter.d.ts +0 -27
- package/src/lib/contextModule.d.ts +0 -22
- package/src/lib/getGraphId.d.ts +0 -11
- package/src/lib/reporting.d.ts +0 -144
- package/src/node-haste/DependencyGraph.d.ts +0 -62
- package/src/shared/output/bundle.d.ts +0 -35
- package/src/shared/types.d.ts +0 -130
|
@@ -4,7 +4,7 @@
|
|
|
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
|
|
7
|
+
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
@@ -17,14 +17,14 @@ import type {Readable} from 'stream';
|
|
|
17
17
|
import {Worker as JestWorker} from 'jest-worker';
|
|
18
18
|
import {Logger} from 'metro-core';
|
|
19
19
|
|
|
20
|
-
type WorkerInterface = {
|
|
20
|
+
type WorkerInterface = Readonly<{
|
|
21
|
+
...Worker,
|
|
22
|
+
end(): void | Promise<void>,
|
|
21
23
|
getStdout(): Readable,
|
|
22
24
|
getStderr(): Readable,
|
|
23
|
-
|
|
24
|
-
...Worker,
|
|
25
|
-
};
|
|
25
|
+
}>;
|
|
26
26
|
|
|
27
|
-
type TransformerResult =
|
|
27
|
+
type TransformerResult = Readonly<{
|
|
28
28
|
result: TransformResult<>,
|
|
29
29
|
sha1: string,
|
|
30
30
|
}>;
|
|
@@ -62,7 +62,7 @@ export default class WorkerFarm {
|
|
|
62
62
|
this._worker = worker;
|
|
63
63
|
} else {
|
|
64
64
|
// eslint-disable-next-line import/no-commonjs
|
|
65
|
-
this._worker =
|
|
65
|
+
this._worker = require('./Worker') as Worker;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -104,16 +104,16 @@ export default class WorkerFarm {
|
|
|
104
104
|
|
|
105
105
|
_makeFarm(
|
|
106
106
|
absoluteWorkerPath: string,
|
|
107
|
-
exposedMethods:
|
|
107
|
+
exposedMethods: ReadonlyArray<string>,
|
|
108
108
|
numWorkers: number,
|
|
109
|
-
):
|
|
109
|
+
): WorkerInterface {
|
|
110
110
|
const env = {
|
|
111
111
|
...process.env,
|
|
112
112
|
// Force color to print syntax highlighted code frames.
|
|
113
113
|
FORCE_COLOR: 1,
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
return new JestWorker(absoluteWorkerPath, {
|
|
116
|
+
return new JestWorker<Worker>(absoluteWorkerPath, {
|
|
117
117
|
computeWorkerKey: this._config.stickyWorkers
|
|
118
118
|
? // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
119
119
|
// $FlowFixMe[incompatible-type]
|
|
@@ -143,7 +143,10 @@ export default class WorkerFarm {
|
|
|
143
143
|
return null;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
_formatGenericError(
|
|
146
|
+
_formatGenericError(
|
|
147
|
+
err: Readonly<{message: string, stack?: string, ...}>,
|
|
148
|
+
filename: string,
|
|
149
|
+
): TransformError {
|
|
147
150
|
const error = new TransformError(`${filename}: ${err.message}`);
|
|
148
151
|
|
|
149
152
|
// $FlowFixMe[unsafe-object-assign]
|
|
@@ -153,9 +156,19 @@ export default class WorkerFarm {
|
|
|
153
156
|
});
|
|
154
157
|
}
|
|
155
158
|
|
|
156
|
-
_formatBabelError(
|
|
159
|
+
_formatBabelError(
|
|
160
|
+
err: Readonly<{
|
|
161
|
+
message: string,
|
|
162
|
+
stack?: string,
|
|
163
|
+
type?: string,
|
|
164
|
+
codeFrame?: unknown,
|
|
165
|
+
loc: {line?: number, column?: number, ...},
|
|
166
|
+
...
|
|
167
|
+
}>,
|
|
168
|
+
filename: string,
|
|
169
|
+
): TransformError {
|
|
157
170
|
const error = new TransformError(
|
|
158
|
-
`${err.type
|
|
171
|
+
`${err.type ?? 'Error'}${
|
|
159
172
|
err.message.includes(filename) ? '' : ' in ' + filename
|
|
160
173
|
}: ${err.message}`,
|
|
161
174
|
);
|
|
@@ -24,13 +24,13 @@ function resolveDependencies(parentPath, dependencies, resolve) {
|
|
|
24
24
|
contextParams,
|
|
25
25
|
);
|
|
26
26
|
const resolvedContext = {
|
|
27
|
-
from,
|
|
28
|
-
mode: contextParams.mode,
|
|
29
|
-
recursive: contextParams.recursive,
|
|
30
27
|
filter: new RegExp(
|
|
31
28
|
contextParams.filter.pattern,
|
|
32
29
|
contextParams.filter.flags,
|
|
33
30
|
),
|
|
31
|
+
from,
|
|
32
|
+
mode: contextParams.mode,
|
|
33
|
+
recursive: contextParams.recursive,
|
|
34
34
|
};
|
|
35
35
|
resolvedContexts.set(key, resolvedContext);
|
|
36
36
|
maybeResolvedDep = {
|
|
@@ -110,7 +110,7 @@ async function buildSubgraph(
|
|
|
110
110
|
),
|
|
111
111
|
);
|
|
112
112
|
return {
|
|
113
|
-
moduleData,
|
|
114
113
|
errors,
|
|
114
|
+
moduleData,
|
|
115
115
|
};
|
|
116
116
|
}
|
|
@@ -22,7 +22,7 @@ import {deriveAbsolutePathFromContext} from '../lib/contextModule';
|
|
|
22
22
|
import {isResolvedDependency} from '../lib/isResolvedDependency';
|
|
23
23
|
import path from 'path';
|
|
24
24
|
|
|
25
|
-
type Parameters<T> =
|
|
25
|
+
type Parameters<T> = Readonly<{
|
|
26
26
|
resolve: ResolveFn,
|
|
27
27
|
transform: TransformFn<T>,
|
|
28
28
|
shouldTraverse: ResolvedDependency => boolean,
|
|
@@ -30,7 +30,7 @@ type Parameters<T> = $ReadOnly<{
|
|
|
30
30
|
|
|
31
31
|
function resolveDependencies(
|
|
32
32
|
parentPath: string,
|
|
33
|
-
dependencies:
|
|
33
|
+
dependencies: ReadonlyArray<TransformResultDependency>,
|
|
34
34
|
resolve: ResolveFn,
|
|
35
35
|
): {
|
|
36
36
|
dependencies: Map<string, Dependency>,
|
|
@@ -52,13 +52,13 @@ function resolveDependencies(
|
|
|
52
52
|
const absolutePath = deriveAbsolutePathFromContext(from, contextParams);
|
|
53
53
|
|
|
54
54
|
const resolvedContext: RequireContext = {
|
|
55
|
-
from,
|
|
56
|
-
mode: contextParams.mode,
|
|
57
|
-
recursive: contextParams.recursive,
|
|
58
55
|
filter: new RegExp(
|
|
59
56
|
contextParams.filter.pattern,
|
|
60
57
|
contextParams.filter.flags,
|
|
61
58
|
),
|
|
59
|
+
from,
|
|
60
|
+
mode: contextParams.mode,
|
|
61
|
+
recursive: contextParams.recursive,
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
resolvedContexts.set(key, resolvedContext);
|
|
@@ -100,8 +100,8 @@ function resolveDependencies(
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export async function buildSubgraph<T>(
|
|
103
|
-
entryPaths:
|
|
104
|
-
resolvedContexts:
|
|
103
|
+
entryPaths: ReadonlySet<string>,
|
|
104
|
+
resolvedContexts: ReadonlyMap<string, ?RequireContext>,
|
|
105
105
|
{resolve, transform, shouldTraverse}: Parameters<T>,
|
|
106
106
|
): Promise<{
|
|
107
107
|
moduleData: Map<string, ModuleData<T>>,
|
|
@@ -157,5 +157,5 @@ export async function buildSubgraph<T>(
|
|
|
157
157
|
),
|
|
158
158
|
);
|
|
159
159
|
|
|
160
|
-
return {
|
|
160
|
+
return {errors, moduleData};
|
|
161
161
|
}
|
|
@@ -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.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(
|
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
|
};
|
|
@@ -19,28 +19,32 @@ var transformHelpers = _interopRequireWildcard(
|
|
|
19
19
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
20
20
|
var _fs = _interopRequireDefault(require("fs"));
|
|
21
21
|
var _path = _interopRequireDefault(require("path"));
|
|
22
|
-
function
|
|
23
|
-
if ("function"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var n = { __proto__: null },
|
|
37
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
|
-
for (var u in e)
|
|
39
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
40
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
41
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
22
|
+
function _interopRequireWildcard(e, t) {
|
|
23
|
+
if ("function" == typeof WeakMap)
|
|
24
|
+
var r = new WeakMap(),
|
|
25
|
+
n = new WeakMap();
|
|
26
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
27
|
+
if (!t && e && e.__esModule) return e;
|
|
28
|
+
var o,
|
|
29
|
+
i,
|
|
30
|
+
f = { __proto__: null, default: e };
|
|
31
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
32
|
+
return f;
|
|
33
|
+
if ((o = t ? n : r)) {
|
|
34
|
+
if (o.has(e)) return o.get(e);
|
|
35
|
+
o.set(e, f);
|
|
42
36
|
}
|
|
43
|
-
|
|
37
|
+
for (const t in e)
|
|
38
|
+
"default" !== t &&
|
|
39
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
40
|
+
((i =
|
|
41
|
+
(o = Object.defineProperty) &&
|
|
42
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
43
|
+
(i.get || i.set)
|
|
44
|
+
? o(f, t, i)
|
|
45
|
+
: (f[t] = e[t]));
|
|
46
|
+
return f;
|
|
47
|
+
})(e, t);
|
|
44
48
|
}
|
|
45
49
|
function _interopRequireDefault(e) {
|
|
46
50
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -108,6 +112,8 @@ class IncrementalBundler {
|
|
|
108
112
|
this._config.transformer.unstable_allowRequireContext,
|
|
109
113
|
unstable_enablePackageExports:
|
|
110
114
|
this._config.resolver.unstable_enablePackageExports,
|
|
115
|
+
unstable_incrementalResolution:
|
|
116
|
+
this._config.resolver.unstable_incrementalResolution,
|
|
111
117
|
shallow: otherOptions.shallow,
|
|
112
118
|
});
|
|
113
119
|
this._config.serializer.experimentalSerializerHook(graph, {
|
|
@@ -152,6 +158,8 @@ class IncrementalBundler {
|
|
|
152
158
|
this._config.transformer.unstable_allowRequireContext,
|
|
153
159
|
unstable_enablePackageExports:
|
|
154
160
|
this._config.resolver.unstable_enablePackageExports,
|
|
161
|
+
unstable_incrementalResolution:
|
|
162
|
+
this._config.resolver.unstable_incrementalResolution,
|
|
155
163
|
shallow: otherOptions.shallow,
|
|
156
164
|
},
|
|
157
165
|
);
|