metro 0.84.1 → 0.84.3
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 +15 -15
- package/src/Assets.d.ts +90 -0
- package/src/Bundler/util.d.ts +34 -0
- package/src/Bundler/util.js.flow +3 -3
- package/src/Bundler.d.ts +45 -0
- package/src/DeltaBundler/DeltaCalculator.d.ts +68 -0
- package/src/DeltaBundler/DeltaCalculator.js +55 -46
- package/src/DeltaBundler/DeltaCalculator.js.flow +72 -61
- package/src/DeltaBundler/Graph.d.ts +174 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +27 -0
- package/src/DeltaBundler/Serializers/getAllFiles.d.ts +29 -0
- package/src/DeltaBundler/Serializers/getAssets.d.ts +32 -0
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +33 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +55 -0
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +19 -0
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +40 -0
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +24 -0
- package/src/DeltaBundler/Serializers/helpers/js.d.ts +37 -0
- package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +32 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +37 -0
- package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +36 -0
- package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +30 -0
- package/src/DeltaBundler/Serializers/sourceMapString.d.ts +29 -0
- package/src/DeltaBundler/Transformer.d.ts +45 -0
- package/src/DeltaBundler/Worker.d.ts +44 -0
- package/src/DeltaBundler/WorkerFarm.d.ts +77 -0
- package/src/DeltaBundler/buildSubgraph.d.ts +37 -0
- package/src/DeltaBundler/getTransformCacheKey.d.ts +25 -0
- package/src/DeltaBundler/getTransformCacheKey.js +3 -1
- package/src/DeltaBundler/getTransformCacheKey.js.flow +7 -2
- package/src/DeltaBundler/mergeDeltas.d.ts +24 -0
- package/src/DeltaBundler/types.d.ts +170 -0
- package/src/DeltaBundler.d.ts +67 -0
- package/src/HmrServer.d.ts +98 -0
- package/src/HmrServer.js +7 -0
- package/src/HmrServer.js.flow +15 -5
- package/src/IncrementalBundler/GraphNotFoundError.d.ts +24 -0
- package/src/IncrementalBundler/ResourceNotFoundError.d.ts +22 -0
- package/src/IncrementalBundler/RevisionNotFoundError.d.ts +24 -0
- package/src/IncrementalBundler.d.ts +103 -0
- package/src/ModuleGraph/worker/JsFileWrapping.d.ts +36 -0
- package/src/ModuleGraph/worker/collectDependencies.d.ts +138 -0
- package/src/ModuleGraph/worker/generateImportNames.d.ts +26 -0
- package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +33 -0
- package/src/Server/MultipartResponse.d.ts +37 -0
- package/src/Server/symbolicate.d.ts +38 -0
- package/src/Server.d.ts +278 -0
- package/src/cli/parseKeyValueParamArray.d.ts +21 -0
- package/src/cli-utils.d.ts +26 -0
- package/src/commands/build.d.ts +23 -0
- package/src/commands/dependencies.d.ts +23 -0
- package/src/commands/serve.d.ts +23 -0
- package/src/index.d.ts +206 -0
- package/src/index.flow.js.flow +21 -2
- package/src/lib/BatchProcessor.d.ts +61 -0
- package/src/lib/CountingSet.d.ts +55 -0
- package/src/lib/JsonReporter.d.ts +44 -0
- package/src/lib/JsonReporter.js.flow +2 -2
- package/src/lib/RamBundleParser.d.ts +36 -0
- package/src/lib/TerminalReporter.d.ts +125 -0
- package/src/lib/bundleProgressUtils.d.ts +33 -0
- package/src/lib/bundleToString.d.ts +26 -0
- package/src/lib/contextModule.d.ts +40 -0
- package/src/lib/contextModuleTemplates.d.ts +32 -0
- package/src/lib/countLines.d.ts +19 -0
- package/src/lib/createWebsocketServer.d.ts +50 -0
- package/src/lib/debounceAsyncQueue.d.ts +22 -0
- package/src/lib/formatBundlingError.d.ts +30 -0
- package/src/lib/getAppendScripts.d.ts +38 -0
- package/src/lib/getAppendScripts.js.flow +2 -2
- package/src/lib/getGraphId.d.ts +32 -0
- package/src/lib/getPreludeCode.d.ts +25 -0
- package/src/lib/getPrependedScripts.d.ts +31 -0
- package/src/lib/isResolvedDependency.d.ts +22 -0
- package/src/lib/logToConsole.d.ts +26 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +24 -0
- package/src/lib/parseCustomResolverOptions.d.ts +23 -0
- package/src/lib/parseCustomTransformOptions.d.ts +23 -0
- package/src/lib/parseJsonBody.d.ts +34 -0
- package/src/lib/pathUtils.d.ts +21 -0
- package/src/lib/relativizeSourceMap.d.ts +24 -0
- package/src/lib/reporting.d.ts +135 -0
- package/src/lib/splitBundleOptions.d.ts +23 -0
- package/src/lib/transformHelpers.d.ts +42 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +120 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.js +4 -22
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +10 -59
- package/src/node-haste/DependencyGraph/createFileMap.d.ts +36 -0
- package/src/node-haste/DependencyGraph/createFileMap.js +1 -1
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +4 -2
- package/src/node-haste/DependencyGraph.d.ts +90 -0
- package/src/node-haste/DependencyGraph.js +22 -11
- package/src/node-haste/DependencyGraph.js.flow +24 -13
- package/src/node-haste/PackageCache.d.ts +37 -0
- package/src/node-haste/PackageCache.js +65 -54
- package/src/node-haste/PackageCache.js.flow +103 -79
- package/src/node-haste/lib/AssetPaths.d.ts +36 -0
- package/src/node-haste/lib/parsePlatformFilePath.d.ts +32 -0
- package/src/shared/output/RamBundle/as-assets.d.ts +32 -0
- package/src/shared/output/RamBundle/as-indexed-file.d.ts +45 -0
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +30 -0
- package/src/shared/output/RamBundle/magic-number.d.ts +21 -0
- package/src/shared/output/RamBundle/util.d.ts +48 -0
- package/src/shared/output/RamBundle/write-sourcemap.d.ts +23 -0
- package/src/shared/output/RamBundle.d.ts +33 -0
- package/src/shared/output/bundle.d.ts +34 -0
- package/src/shared/output/meta.d.ts +22 -0
- package/src/shared/output/unbundle.d.ts +18 -0
- package/src/shared/output/writeFile.d.ts +23 -0
- package/src/shared/types.d.ts +152 -0
- package/src/node-haste/Package.js +0 -28
- package/src/node-haste/Package.js.flow +0 -39
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<15f603afc860c64c7acc5a6cfe2a6717>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/Transformer.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {TransformResult, TransformResultWithSource} from '../DeltaBundler';
|
|
19
|
+
import type {TransformOptions} from './Worker';
|
|
20
|
+
import type {ConfigT} from 'metro-config';
|
|
21
|
+
|
|
22
|
+
import WorkerFarm from './WorkerFarm';
|
|
23
|
+
import {Cache} from 'metro-cache';
|
|
24
|
+
|
|
25
|
+
type GetOrComputeSha1Fn = (
|
|
26
|
+
$$PARAM_0$$: string,
|
|
27
|
+
) => Promise<Readonly<{content?: Buffer; sha1: string}>>;
|
|
28
|
+
declare class Transformer {
|
|
29
|
+
_config: ConfigT;
|
|
30
|
+
_cache: Cache<TransformResult>;
|
|
31
|
+
_baseHash: string;
|
|
32
|
+
_getSha1: GetOrComputeSha1Fn;
|
|
33
|
+
_workerFarm: WorkerFarm;
|
|
34
|
+
constructor(
|
|
35
|
+
config: ConfigT,
|
|
36
|
+
opts: Readonly<{getOrComputeSha1: GetOrComputeSha1Fn}>,
|
|
37
|
+
);
|
|
38
|
+
transformFile(
|
|
39
|
+
filePath: string,
|
|
40
|
+
transformerOptions: TransformOptions,
|
|
41
|
+
fileBuffer?: Buffer,
|
|
42
|
+
): Promise<TransformResultWithSource>;
|
|
43
|
+
end(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export default Transformer;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<36640ae81894592fbdc160fac081bdbf>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/Worker.flow.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {TransformResult} from './types';
|
|
19
|
+
import type {LogEntry} from 'metro-core/private/Logger';
|
|
20
|
+
import type {
|
|
21
|
+
JsTransformerConfig,
|
|
22
|
+
JsTransformOptions,
|
|
23
|
+
} from 'metro-transform-worker';
|
|
24
|
+
|
|
25
|
+
export type {JsTransformOptions as TransformOptions} from 'metro-transform-worker';
|
|
26
|
+
export type TransformerConfig = {
|
|
27
|
+
transformerPath: string;
|
|
28
|
+
transformerConfig: JsTransformerConfig;
|
|
29
|
+
};
|
|
30
|
+
type Data = Readonly<{
|
|
31
|
+
result: TransformResult;
|
|
32
|
+
sha1: string;
|
|
33
|
+
transformFileStartLogEntry: LogEntry;
|
|
34
|
+
transformFileEndLogEntry: LogEntry;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const transform: (
|
|
37
|
+
filename: string,
|
|
38
|
+
transformOptions: JsTransformOptions,
|
|
39
|
+
projectRoot: string,
|
|
40
|
+
transformerConfig: TransformerConfig,
|
|
41
|
+
fileBuffer?: Buffer,
|
|
42
|
+
) => Promise<Data>;
|
|
43
|
+
export declare type transform = typeof transform;
|
|
44
|
+
export type Worker = {readonly transform: typeof transform};
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<bbd52f1dc5e4a9253455034b585115ac>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/WorkerFarm.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {TransformResult} from '../DeltaBundler';
|
|
19
|
+
import type {TransformerConfig, TransformOptions, Worker} from './Worker';
|
|
20
|
+
import type {ConfigT} from 'metro-config';
|
|
21
|
+
import type {Readable} from 'stream';
|
|
22
|
+
|
|
23
|
+
type WorkerInterface = Readonly<
|
|
24
|
+
Omit<
|
|
25
|
+
Worker,
|
|
26
|
+
keyof {
|
|
27
|
+
end(): void | Promise<void>;
|
|
28
|
+
getStdout(): Readable;
|
|
29
|
+
getStderr(): Readable;
|
|
30
|
+
}
|
|
31
|
+
> & {
|
|
32
|
+
end(): void | Promise<void>;
|
|
33
|
+
getStdout(): Readable;
|
|
34
|
+
getStderr(): Readable;
|
|
35
|
+
}
|
|
36
|
+
>;
|
|
37
|
+
type TransformerResult = Readonly<{result: TransformResult; sha1: string}>;
|
|
38
|
+
declare class WorkerFarm {
|
|
39
|
+
_config: ConfigT;
|
|
40
|
+
_transformerConfig: TransformerConfig;
|
|
41
|
+
_worker: WorkerInterface | Worker;
|
|
42
|
+
constructor(config: ConfigT, transformerConfig: TransformerConfig);
|
|
43
|
+
kill(): Promise<void>;
|
|
44
|
+
transform(
|
|
45
|
+
filename: string,
|
|
46
|
+
options: TransformOptions,
|
|
47
|
+
fileBuffer?: Buffer,
|
|
48
|
+
): Promise<TransformerResult>;
|
|
49
|
+
_makeFarm(
|
|
50
|
+
absoluteWorkerPath: string,
|
|
51
|
+
exposedMethods: ReadonlyArray<string>,
|
|
52
|
+
numWorkers: number,
|
|
53
|
+
): WorkerInterface;
|
|
54
|
+
_computeWorkerKey(
|
|
55
|
+
method: string,
|
|
56
|
+
filename: string,
|
|
57
|
+
): null | undefined | string;
|
|
58
|
+
_formatGenericError(
|
|
59
|
+
err: Readonly<{message: string; stack?: string}>,
|
|
60
|
+
filename: string,
|
|
61
|
+
): TransformError;
|
|
62
|
+
_formatBabelError(
|
|
63
|
+
err: Readonly<{
|
|
64
|
+
message: string;
|
|
65
|
+
stack?: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
codeFrame?: unknown;
|
|
68
|
+
loc: {line?: number; column?: number};
|
|
69
|
+
}>,
|
|
70
|
+
filename: string,
|
|
71
|
+
): TransformError;
|
|
72
|
+
}
|
|
73
|
+
export default WorkerFarm;
|
|
74
|
+
declare class TransformError extends SyntaxError {
|
|
75
|
+
type: string;
|
|
76
|
+
constructor(message: string);
|
|
77
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<1e334cd36bb429700b82654f1ddab0a0>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro/src/DeltaBundler/buildSubgraph.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type {RequireContext} from '../lib/contextModule';
|
|
18
|
+
import type {
|
|
19
|
+
ModuleData,
|
|
20
|
+
ResolvedDependency,
|
|
21
|
+
ResolveFn,
|
|
22
|
+
TransformFn,
|
|
23
|
+
} from './types';
|
|
24
|
+
|
|
25
|
+
type Parameters<T> = Readonly<{
|
|
26
|
+
resolve: ResolveFn;
|
|
27
|
+
transform: TransformFn<T>;
|
|
28
|
+
shouldTraverse: ($$PARAM_0$$: ResolvedDependency) => boolean;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function buildSubgraph<T>(
|
|
31
|
+
entryPaths: ReadonlySet<string>,
|
|
32
|
+
resolvedContexts: ReadonlyMap<string, null | undefined | RequireContext>,
|
|
33
|
+
$$PARAM_2$$: Parameters<T>,
|
|
34
|
+
): Promise<{
|
|
35
|
+
moduleData: Map<string, ModuleData<T>>;
|
|
36
|
+
errors: Map<string, Error>;
|
|
37
|
+
}>;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<1a82c2238a94514c16e7bb93bf49d8c9>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/getTransformCacheKey.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {TransformerConfig} from './Worker';
|
|
19
|
+
|
|
20
|
+
declare function getTransformCacheKey(opts: {
|
|
21
|
+
readonly cacheVersion: string;
|
|
22
|
+
readonly projectRoot: string;
|
|
23
|
+
readonly transformerConfig: TransformerConfig;
|
|
24
|
+
}): string;
|
|
25
|
+
export default getTransformCacheKey;
|
|
@@ -14,7 +14,9 @@ function getTransformCacheKey(opts) {
|
|
|
14
14
|
const { transformerPath, transformerConfig } = opts.transformerConfig;
|
|
15
15
|
const Transformer = require.call(null, transformerPath);
|
|
16
16
|
const transformerKey = Transformer.getCacheKey
|
|
17
|
-
? Transformer.getCacheKey(transformerConfig
|
|
17
|
+
? Transformer.getCacheKey(transformerConfig, {
|
|
18
|
+
projectRoot: opts.projectRoot,
|
|
19
|
+
})
|
|
18
20
|
: "";
|
|
19
21
|
return _crypto.default
|
|
20
22
|
.createHash("sha1")
|
|
@@ -19,7 +19,10 @@ import {getCacheKey} from 'metro-cache-key';
|
|
|
19
19
|
const VERSION = require('../../package.json').version;
|
|
20
20
|
|
|
21
21
|
type CacheKeyProvider = {
|
|
22
|
-
getCacheKey?:
|
|
22
|
+
getCacheKey?: (
|
|
23
|
+
config: JsTransformerConfig,
|
|
24
|
+
opts?: Readonly<{projectRoot: string}>,
|
|
25
|
+
) => string,
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
export default function getTransformCacheKey(opts: {
|
|
@@ -32,7 +35,9 @@ export default function getTransformCacheKey(opts: {
|
|
|
32
35
|
// eslint-disable-next-line no-useless-call
|
|
33
36
|
const Transformer: CacheKeyProvider = require.call(null, transformerPath);
|
|
34
37
|
const transformerKey = Transformer.getCacheKey
|
|
35
|
-
? Transformer.getCacheKey(transformerConfig
|
|
38
|
+
? Transformer.getCacheKey(transformerConfig, {
|
|
39
|
+
projectRoot: opts.projectRoot,
|
|
40
|
+
})
|
|
36
41
|
: '';
|
|
37
42
|
|
|
38
43
|
return crypto
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<46981e9bc1ef3945b99b147cbdf9ec5d>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/mergeDeltas.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {DeltaBundle} from 'metro-runtime/src/modules/types';
|
|
19
|
+
|
|
20
|
+
declare function mergeDeltas(
|
|
21
|
+
delta1: DeltaBundle,
|
|
22
|
+
delta2: DeltaBundle,
|
|
23
|
+
): DeltaBundle;
|
|
24
|
+
export default mergeDeltas;
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<feddf9cb00d4a097d348531773c9f0bd>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/types.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {RequireContext} from '../lib/contextModule';
|
|
19
|
+
import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
|
|
20
|
+
import type {ReadonlySourceLocation} from '../shared/types';
|
|
21
|
+
import type {Graph} from './Graph';
|
|
22
|
+
import type {JsTransformOptions} from 'metro-transform-worker';
|
|
23
|
+
|
|
24
|
+
import CountingSet from '../lib/CountingSet';
|
|
25
|
+
|
|
26
|
+
export type MixedOutput = {readonly data: unknown; readonly type: string};
|
|
27
|
+
export type AsyncDependencyType = 'async' | 'maybeSync' | 'prefetch' | 'weak';
|
|
28
|
+
export type TransformResultDependency = Readonly<{
|
|
29
|
+
/**
|
|
30
|
+
* The literal name provided to a require or import call. For example 'foo' in
|
|
31
|
+
* case of `require('foo')`.
|
|
32
|
+
*/
|
|
33
|
+
name: string;
|
|
34
|
+
/**
|
|
35
|
+
* Extra data returned by the dependency extractor.
|
|
36
|
+
*/
|
|
37
|
+
data: Readonly<{
|
|
38
|
+
/**
|
|
39
|
+
* A locally unique key for this dependency within the current module.
|
|
40
|
+
*/
|
|
41
|
+
key: string;
|
|
42
|
+
/**
|
|
43
|
+
* If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
|
|
44
|
+
*/
|
|
45
|
+
asyncType: AsyncDependencyType | null;
|
|
46
|
+
/**
|
|
47
|
+
* True if the dependency is declared with a static "import x from 'y'" or
|
|
48
|
+
* an import() call.
|
|
49
|
+
*/
|
|
50
|
+
isESMImport: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The dependency is enclosed in a try/catch block.
|
|
53
|
+
*/
|
|
54
|
+
isOptional?: boolean;
|
|
55
|
+
locs: ReadonlyArray<ReadonlySourceLocation>;
|
|
56
|
+
/** Context for requiring a collection of modules. */
|
|
57
|
+
contextParams?: RequireContextParams;
|
|
58
|
+
}>;
|
|
59
|
+
}>;
|
|
60
|
+
export type ResolvedDependency = Readonly<{
|
|
61
|
+
absolutePath: string;
|
|
62
|
+
data: TransformResultDependency;
|
|
63
|
+
}>;
|
|
64
|
+
export type Dependency =
|
|
65
|
+
| ResolvedDependency
|
|
66
|
+
| Readonly<{data: TransformResultDependency}>;
|
|
67
|
+
export type Module<T = MixedOutput> = Readonly<{
|
|
68
|
+
dependencies: Map<string, Dependency>;
|
|
69
|
+
inverseDependencies: CountingSet<string>;
|
|
70
|
+
output: ReadonlyArray<T>;
|
|
71
|
+
path: string;
|
|
72
|
+
getSource: () => Buffer;
|
|
73
|
+
unstable_transformResultKey?: null | undefined | string;
|
|
74
|
+
}>;
|
|
75
|
+
export type ModuleData<T = MixedOutput> = Readonly<{
|
|
76
|
+
dependencies: ReadonlyMap<string, Dependency>;
|
|
77
|
+
resolvedContexts: ReadonlyMap<string, RequireContext>;
|
|
78
|
+
output: ReadonlyArray<T>;
|
|
79
|
+
getSource: () => Buffer;
|
|
80
|
+
unstable_transformResultKey?: null | undefined | string;
|
|
81
|
+
}>;
|
|
82
|
+
export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
|
|
83
|
+
export type ReadOnlyDependencies<T = MixedOutput> = ReadonlyMap<
|
|
84
|
+
string,
|
|
85
|
+
Module<T>
|
|
86
|
+
>;
|
|
87
|
+
export type TransformInputOptions = Omit<
|
|
88
|
+
JsTransformOptions,
|
|
89
|
+
'inlinePlatform' | 'inlineRequires'
|
|
90
|
+
>;
|
|
91
|
+
export type GraphInputOptions = Readonly<{
|
|
92
|
+
entryPoints: ReadonlySet<string>;
|
|
93
|
+
transformOptions: TransformInputOptions;
|
|
94
|
+
}>;
|
|
95
|
+
export interface ReadOnlyGraph<T = MixedOutput> {
|
|
96
|
+
readonly entryPoints: ReadonlySet<string>;
|
|
97
|
+
readonly transformOptions: Readonly<TransformInputOptions>;
|
|
98
|
+
readonly dependencies: ReadOnlyDependencies<T>;
|
|
99
|
+
}
|
|
100
|
+
export type {Graph};
|
|
101
|
+
export type TransformResult<T = MixedOutput> = Readonly<{
|
|
102
|
+
dependencies: ReadonlyArray<TransformResultDependency>;
|
|
103
|
+
output: ReadonlyArray<T>;
|
|
104
|
+
unstable_transformResultKey?: null | undefined | string;
|
|
105
|
+
}>;
|
|
106
|
+
export type TransformResultWithSource<T = MixedOutput> = Readonly<
|
|
107
|
+
Omit<TransformResult<T>, keyof {getSource: () => Buffer}> & {
|
|
108
|
+
getSource: () => Buffer;
|
|
109
|
+
}
|
|
110
|
+
>;
|
|
111
|
+
export type TransformFn<T = MixedOutput> = (
|
|
112
|
+
$$PARAM_0$$: string,
|
|
113
|
+
$$PARAM_1$$: null | undefined | RequireContext,
|
|
114
|
+
) => Promise<TransformResultWithSource<T>>;
|
|
115
|
+
export type ResolveFn = (
|
|
116
|
+
from: string,
|
|
117
|
+
dependency: TransformResultDependency,
|
|
118
|
+
) => BundlerResolution;
|
|
119
|
+
export type AllowOptionalDependenciesWithOptions = {
|
|
120
|
+
readonly exclude: Array<string>;
|
|
121
|
+
};
|
|
122
|
+
export type AllowOptionalDependencies =
|
|
123
|
+
| boolean
|
|
124
|
+
| AllowOptionalDependenciesWithOptions;
|
|
125
|
+
export type BundlerResolution = Readonly<{
|
|
126
|
+
type: 'sourceFile';
|
|
127
|
+
filePath: string;
|
|
128
|
+
}>;
|
|
129
|
+
export type Options<T = MixedOutput> = Readonly<{
|
|
130
|
+
resolve: ResolveFn;
|
|
131
|
+
transform: TransformFn<T>;
|
|
132
|
+
transformOptions: TransformInputOptions;
|
|
133
|
+
onProgress:
|
|
134
|
+
| null
|
|
135
|
+
| undefined
|
|
136
|
+
| ((numProcessed: number, total: number) => unknown);
|
|
137
|
+
lazy: boolean;
|
|
138
|
+
unstable_allowRequireContext: boolean;
|
|
139
|
+
unstable_enablePackageExports: boolean;
|
|
140
|
+
unstable_incrementalResolution: boolean;
|
|
141
|
+
shallow: boolean;
|
|
142
|
+
}>;
|
|
143
|
+
export type DeltaResult<T = MixedOutput> = {
|
|
144
|
+
readonly added: Map<string, Module<T>>;
|
|
145
|
+
readonly modified: Map<string, Module<T>>;
|
|
146
|
+
readonly deleted: Set<string>;
|
|
147
|
+
readonly reset: boolean;
|
|
148
|
+
};
|
|
149
|
+
export type SerializerOptions = Readonly<{
|
|
150
|
+
asyncRequireModulePath: string;
|
|
151
|
+
createModuleId: ($$PARAM_0$$: string) => number;
|
|
152
|
+
dev: boolean;
|
|
153
|
+
getRunModuleStatement: (
|
|
154
|
+
moduleId: number | string,
|
|
155
|
+
globalPrefix: string,
|
|
156
|
+
) => string;
|
|
157
|
+
globalPrefix: string;
|
|
158
|
+
includeAsyncPaths: boolean;
|
|
159
|
+
inlineSourceMap: null | undefined | boolean;
|
|
160
|
+
modulesOnly: boolean;
|
|
161
|
+
processModuleFilter: (module: Module) => boolean;
|
|
162
|
+
projectRoot: string;
|
|
163
|
+
runBeforeMainModule: ReadonlyArray<string>;
|
|
164
|
+
runModule: boolean;
|
|
165
|
+
serverRoot: string;
|
|
166
|
+
shouldAddToIgnoreList: ($$PARAM_0$$: Module) => boolean;
|
|
167
|
+
sourceMapUrl: null | undefined | string;
|
|
168
|
+
sourceUrl: null | undefined | string;
|
|
169
|
+
getSourceUrl: null | undefined | (($$PARAM_0$$: Module) => string);
|
|
170
|
+
}>;
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<db564db653a99b07f3ad7585b2bed707>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
DeltaResult,
|
|
20
|
+
Graph,
|
|
21
|
+
MixedOutput,
|
|
22
|
+
Options,
|
|
23
|
+
ReadOnlyGraph,
|
|
24
|
+
} from './DeltaBundler/types';
|
|
25
|
+
import type EventEmitter from 'events';
|
|
26
|
+
|
|
27
|
+
import DeltaCalculator from './DeltaBundler/DeltaCalculator';
|
|
28
|
+
|
|
29
|
+
export type {
|
|
30
|
+
DeltaResult,
|
|
31
|
+
Graph,
|
|
32
|
+
Dependencies,
|
|
33
|
+
MixedOutput,
|
|
34
|
+
Module,
|
|
35
|
+
ReadOnlyGraph,
|
|
36
|
+
TransformFn,
|
|
37
|
+
TransformResult,
|
|
38
|
+
TransformResultDependency,
|
|
39
|
+
TransformResultWithSource,
|
|
40
|
+
} from './DeltaBundler/types';
|
|
41
|
+
/**
|
|
42
|
+
* `DeltaBundler` uses the `DeltaTransformer` to build bundle deltas. This
|
|
43
|
+
* module handles all the transformer instances so it can support multiple
|
|
44
|
+
* concurrent clients requesting their own deltas. This is done through the
|
|
45
|
+
* `clientId` param (which maps a client to a specific delta transformer).
|
|
46
|
+
*/
|
|
47
|
+
declare class DeltaBundler<T = MixedOutput> {
|
|
48
|
+
_changeEventSource: EventEmitter;
|
|
49
|
+
_deltaCalculators: Map<Graph<T>, DeltaCalculator<T>>;
|
|
50
|
+
constructor(changeEventSource: EventEmitter);
|
|
51
|
+
end(): void;
|
|
52
|
+
getDependencies(
|
|
53
|
+
entryPoints: ReadonlyArray<string>,
|
|
54
|
+
options: Options<T>,
|
|
55
|
+
): Promise<ReadOnlyGraph<T>['dependencies']>;
|
|
56
|
+
buildGraph(
|
|
57
|
+
entryPoints: ReadonlyArray<string>,
|
|
58
|
+
options: Options<T>,
|
|
59
|
+
): Promise<Graph<T>>;
|
|
60
|
+
getDelta(
|
|
61
|
+
graph: Graph<T>,
|
|
62
|
+
$$PARAM_1$$: {reset: boolean; shallow: boolean},
|
|
63
|
+
): Promise<DeltaResult<T>>;
|
|
64
|
+
listen(graph: Graph<T>, callback: () => Promise<void>): () => void;
|
|
65
|
+
endGraph(graph: Graph<T>): void;
|
|
66
|
+
}
|
|
67
|
+
export default DeltaBundler;
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<ab4c245134631e14db114a9d49da79d1>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro/src/HmrServer.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
RevisionId,
|
|
19
|
+
default as IncrementalBundler,
|
|
20
|
+
} from './IncrementalBundler';
|
|
21
|
+
import type {GraphOptions} from './shared/types';
|
|
22
|
+
import type {ConfigT, RootPerfLogger} from 'metro-config';
|
|
23
|
+
import type {
|
|
24
|
+
HmrErrorMessage,
|
|
25
|
+
HmrUpdateMessage,
|
|
26
|
+
} from 'metro-runtime/src/modules/types';
|
|
27
|
+
|
|
28
|
+
export type Client = {
|
|
29
|
+
optedIntoHMR: boolean;
|
|
30
|
+
revisionIds: Array<RevisionId>;
|
|
31
|
+
readonly sendFn: ($$PARAM_0$$: string) => void;
|
|
32
|
+
};
|
|
33
|
+
type ClientGroup = {
|
|
34
|
+
readonly clients: Set<Client>;
|
|
35
|
+
clientUrl: URL;
|
|
36
|
+
revisionId: RevisionId;
|
|
37
|
+
readonly unlisten: () => void;
|
|
38
|
+
readonly graphOptions: GraphOptions;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The HmrServer (Hot Module Reloading) implements a lightweight interface
|
|
42
|
+
* to communicate easily to the logic in the React Native repository (which
|
|
43
|
+
* is the one that handles the Web Socket connections).
|
|
44
|
+
*
|
|
45
|
+
* This interface allows the HmrServer to hook its own logic to WS clients
|
|
46
|
+
* getting connected, disconnected or having errors (through the
|
|
47
|
+
* `onClientConnect`, `onClientDisconnect` and `onClientError` methods).
|
|
48
|
+
*/
|
|
49
|
+
declare class HmrServer<TClient extends Client> {
|
|
50
|
+
_config: ConfigT;
|
|
51
|
+
_bundler: IncrementalBundler;
|
|
52
|
+
_createModuleId: (path: string) => number;
|
|
53
|
+
_clientGroups: Map<RevisionId, ClientGroup>;
|
|
54
|
+
constructor(
|
|
55
|
+
bundler: IncrementalBundler,
|
|
56
|
+
createModuleId: (path: string) => number,
|
|
57
|
+
config: ConfigT,
|
|
58
|
+
);
|
|
59
|
+
onClientConnect: (
|
|
60
|
+
requestUrl: string,
|
|
61
|
+
sendFn: (data: string) => void,
|
|
62
|
+
) => Promise<Client>;
|
|
63
|
+
_registerEntryPoint(
|
|
64
|
+
client: Client,
|
|
65
|
+
originalRequestUrl: string,
|
|
66
|
+
sendFn: (data: string) => void,
|
|
67
|
+
): Promise<void>;
|
|
68
|
+
onClientMessage: (
|
|
69
|
+
client: TClient,
|
|
70
|
+
message: string | Buffer | ArrayBuffer | Array<Buffer>,
|
|
71
|
+
sendFn: (data: string) => void,
|
|
72
|
+
) => Promise<void>;
|
|
73
|
+
onClientError: (client: TClient, e: Error) => void;
|
|
74
|
+
onClientDisconnect: (client: TClient) => void;
|
|
75
|
+
_handleFileChange(
|
|
76
|
+
group: ClientGroup,
|
|
77
|
+
options: {isInitialUpdate: boolean},
|
|
78
|
+
changeEvent:
|
|
79
|
+
| null
|
|
80
|
+
| undefined
|
|
81
|
+
| {
|
|
82
|
+
readonly logger: null | undefined | RootPerfLogger;
|
|
83
|
+
readonly changeId?: string;
|
|
84
|
+
},
|
|
85
|
+
): Promise<void>;
|
|
86
|
+
_prepareMessage(
|
|
87
|
+
group: ClientGroup,
|
|
88
|
+
options: {isInitialUpdate: boolean},
|
|
89
|
+
changeEvent:
|
|
90
|
+
| null
|
|
91
|
+
| undefined
|
|
92
|
+
| {
|
|
93
|
+
readonly logger: null | undefined | RootPerfLogger;
|
|
94
|
+
readonly changeId?: string;
|
|
95
|
+
},
|
|
96
|
+
): Promise<HmrUpdateMessage | HmrErrorMessage>;
|
|
97
|
+
}
|
|
98
|
+
export default HmrServer;
|
package/src/HmrServer.js
CHANGED
|
@@ -214,6 +214,10 @@ class HmrServer {
|
|
|
214
214
|
case "log-opt-in":
|
|
215
215
|
client.optedIntoHMR = true;
|
|
216
216
|
break;
|
|
217
|
+
case "heartbeat":
|
|
218
|
+
debug("Heartbeat received");
|
|
219
|
+
sendFn(String(message));
|
|
220
|
+
break;
|
|
217
221
|
default:
|
|
218
222
|
break;
|
|
219
223
|
}
|
|
@@ -265,6 +269,9 @@ class HmrServer {
|
|
|
265
269
|
send(sendFns, message);
|
|
266
270
|
send(sendFns, {
|
|
267
271
|
type: "update-done",
|
|
272
|
+
body: {
|
|
273
|
+
changeId: changeEvent?.changeId,
|
|
274
|
+
},
|
|
268
275
|
});
|
|
269
276
|
log({
|
|
270
277
|
...createActionEndEntry(processingHmrChange),
|