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
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Calculates a conservative progress ratio for bundle building.
|
|
14
|
+
*
|
|
15
|
+
* Because we know the `totalFileCount` is going to progressively increase
|
|
16
|
+
* starting with 1:
|
|
17
|
+
* - We use Math.max(totalFileCount, 10) to prevent the ratio from raising too
|
|
18
|
+
* quickly when the total file count is low. (e.g 1/2 5/6)
|
|
19
|
+
* - We use Math.pow(ratio, 2) as a conservative measure of progress.
|
|
20
|
+
* - The ratio is capped at 0.999 to ensure we don't display 100% until done.
|
|
21
|
+
* - If previousRatio is provided, the ratio will not go backwards.
|
|
22
|
+
*/
|
|
23
|
+
export function calculateBundleProgressRatio(
|
|
24
|
+
transformedFileCount: number,
|
|
25
|
+
totalFileCount: number,
|
|
26
|
+
previousRatio?: number,
|
|
27
|
+
): number {
|
|
28
|
+
const baseRatio = Math.pow(
|
|
29
|
+
transformedFileCount / Math.max(totalFileCount, 10),
|
|
30
|
+
2,
|
|
31
|
+
);
|
|
32
|
+
const ratio =
|
|
33
|
+
previousRatio != null ? Math.max(baseRatio, previousRatio) : baseRatio;
|
|
34
|
+
return Math.min(ratio, 0.999);
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 {Bundle, BundleMetadata} from 'metro-runtime/src/modules/types';
|
|
12
|
+
/**
|
|
13
|
+
* Serializes a bundle into a plain JS bundle.
|
|
14
|
+
*/
|
|
15
|
+
declare function bundleToString(bundle: Bundle): {
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly metadata: BundleMetadata;
|
|
18
|
+
};
|
|
19
|
+
export default bundleToString;
|
|
@@ -8,15 +8,26 @@
|
|
|
8
8
|
* @oncall react_native
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
ContextMode,
|
|
13
|
+
RequireContextParams,
|
|
14
|
+
} from '../ModuleGraph/worker/collectDependencies';
|
|
12
15
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */
|
|
17
|
-
readonly filter: RegExp;
|
|
16
|
+
export type RequireContext = Readonly<{
|
|
17
|
+
recursive: boolean;
|
|
18
|
+
filter: RegExp;
|
|
18
19
|
/** Mode for resolving dynamic dependencies. Defaults to `sync` */
|
|
19
|
-
|
|
20
|
+
mode: ContextMode;
|
|
20
21
|
/** Absolute path of the directory to search in */
|
|
21
|
-
|
|
22
|
-
}
|
|
22
|
+
from: string;
|
|
23
|
+
}>;
|
|
24
|
+
/** Given a fully qualified require context, return a virtual file path that ensures uniqueness between paths with different contexts. */
|
|
25
|
+
export declare function deriveAbsolutePathFromContext(
|
|
26
|
+
from: string,
|
|
27
|
+
context: RequireContextParams,
|
|
28
|
+
): string;
|
|
29
|
+
/** Match a file against a require context. */
|
|
30
|
+
export declare function fileMatchesContext(
|
|
31
|
+
testPath: string,
|
|
32
|
+
context: RequireContext,
|
|
33
|
+
): boolean;
|
|
@@ -18,7 +18,7 @@ import crypto from 'crypto';
|
|
|
18
18
|
import nullthrows from 'nullthrows';
|
|
19
19
|
import path from 'path';
|
|
20
20
|
|
|
21
|
-
export type RequireContext =
|
|
21
|
+
export type RequireContext = Readonly<{
|
|
22
22
|
/* Should search for files recursively. Optional, default `true` when `require.context` is used */
|
|
23
23
|
recursive: boolean,
|
|
24
24
|
/* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */
|
|
@@ -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
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {ContextMode} from '../ModuleGraph/worker/collectDependencies';
|
|
12
|
+
/**
|
|
13
|
+
* Generate a context module as a virtual file string.
|
|
14
|
+
*
|
|
15
|
+
* @prop {ContextMode} mode indicates how the modules should be loaded.
|
|
16
|
+
* @prop {string} modulePath virtual file path for the virtual module. Example: `require.context('./src')` -> `'/path/to/project/src'`.
|
|
17
|
+
* @prop {string[]} files list of absolute file paths that must be exported from the context module. Example: `['/path/to/project/src/index.js']`.
|
|
18
|
+
*
|
|
19
|
+
* @returns a string representing a context module (virtual file contents).
|
|
20
|
+
*/
|
|
21
|
+
export declare function getContextModuleTemplate(
|
|
22
|
+
mode: ContextMode,
|
|
23
|
+
modulePath: string,
|
|
24
|
+
files: string[],
|
|
25
|
+
): string;
|
|
@@ -6,28 +6,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getContextModuleTemplate = getContextModuleTemplate;
|
|
7
7
|
var os = _interopRequireWildcard(require("os"));
|
|
8
8
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
function
|
|
10
|
-
if ("function"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var n = { __proto__: null },
|
|
24
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
25
|
-
for (var u in e)
|
|
26
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
27
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
28
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
9
|
+
function _interopRequireWildcard(e, t) {
|
|
10
|
+
if ("function" == typeof WeakMap)
|
|
11
|
+
var r = new WeakMap(),
|
|
12
|
+
n = new WeakMap();
|
|
13
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
14
|
+
if (!t && e && e.__esModule) return e;
|
|
15
|
+
var o,
|
|
16
|
+
i,
|
|
17
|
+
f = { __proto__: null, default: e };
|
|
18
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
19
|
+
return f;
|
|
20
|
+
if ((o = t ? n : r)) {
|
|
21
|
+
if (o.has(e)) return o.get(e);
|
|
22
|
+
o.set(e, f);
|
|
29
23
|
}
|
|
30
|
-
|
|
24
|
+
for (const t in e)
|
|
25
|
+
"default" !== t &&
|
|
26
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
27
|
+
((i =
|
|
28
|
+
(o = Object.defineProperty) &&
|
|
29
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
30
|
+
(i.get || i.set)
|
|
31
|
+
? o(f, t, i)
|
|
32
|
+
: (f[t] = e[t]));
|
|
33
|
+
return f;
|
|
34
|
+
})(e, t);
|
|
31
35
|
}
|
|
32
36
|
function createFileMap(modulePath, files, processModule) {
|
|
33
37
|
let mapString = "\n";
|
|
@@ -0,0 +1,12 @@
|
|
|
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 function countLines(string: string): number;
|
|
12
|
+
export default countLines;
|
package/src/lib/countLines.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = countLines;
|
|
7
7
|
const newline = /\r\n?|\n|\u2028|\u2029/g;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
function countLines(string) {
|
|
9
|
+
return (string.match(newline) || []).length + 1;
|
|
10
|
+
}
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
const newline = /\r\n?|\n|\u2028|\u2029/g;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
(string.match(newline) || []).length + 1;
|
|
16
|
-
|
|
17
|
-
export default countLines;
|
|
14
|
+
export default function countLines(string: string): number {
|
|
15
|
+
return (string.match(newline) || []).length + 1;
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 ws from 'ws';
|
|
12
|
+
|
|
13
|
+
type WebsocketServiceInterface<T> = {
|
|
14
|
+
readonly onClientConnect: (
|
|
15
|
+
url: string,
|
|
16
|
+
sendFn: (data: string) => void,
|
|
17
|
+
) => Promise<null | undefined | T>;
|
|
18
|
+
readonly onClientDisconnect?: (client: T) => unknown;
|
|
19
|
+
readonly onClientError?: (client: T, e: Error) => unknown;
|
|
20
|
+
readonly onClientMessage?: (
|
|
21
|
+
client: T,
|
|
22
|
+
message: string | Buffer | ArrayBuffer | Array<Buffer>,
|
|
23
|
+
sendFn: (data: string) => void,
|
|
24
|
+
) => unknown;
|
|
25
|
+
};
|
|
26
|
+
type HMROptions<TClient> = {
|
|
27
|
+
websocketServer: WebsocketServiceInterface<TClient>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Returns a WebSocketServer to be attached to an existing HTTP instance. It forwards
|
|
31
|
+
* the received events on the given "websocketServer" parameter. It must be an
|
|
32
|
+
* object with the following fields:
|
|
33
|
+
*
|
|
34
|
+
* - onClientConnect
|
|
35
|
+
* - onClientError
|
|
36
|
+
* - onClientMessage
|
|
37
|
+
* - onClientDisconnect
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
declare function createWebsocketServer<TClient>(
|
|
41
|
+
$$PARAM_0$$: HMROptions<TClient>,
|
|
42
|
+
): ws.Server;
|
|
43
|
+
export default createWebsocketServer;
|
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports.default = createWebsocketServer;
|
|
7
|
+
var _timers = require("timers");
|
|
7
8
|
var _ws = _interopRequireDefault(require("ws"));
|
|
8
9
|
function _interopRequireDefault(e) {
|
|
9
10
|
return e && e.__esModule ? e : { default: e };
|
|
10
11
|
}
|
|
12
|
+
const KEEP_ALIVE_INTERVAL_MS = 20000;
|
|
11
13
|
function createWebsocketServer({ websocketServer }) {
|
|
12
14
|
const wss = new _ws.default.Server({
|
|
13
15
|
noServer: true,
|
|
@@ -15,9 +17,9 @@ function createWebsocketServer({ websocketServer }) {
|
|
|
15
17
|
wss.on("connection", async (ws, req) => {
|
|
16
18
|
let connected = true;
|
|
17
19
|
const url = req.url;
|
|
18
|
-
const sendFn = (
|
|
20
|
+
const sendFn = (data) => {
|
|
19
21
|
if (connected) {
|
|
20
|
-
ws.send(
|
|
22
|
+
ws.send(data);
|
|
21
23
|
}
|
|
22
24
|
};
|
|
23
25
|
const client = await websocketServer.onClientConnect(url, sendFn);
|
|
@@ -25,10 +27,15 @@ function createWebsocketServer({ websocketServer }) {
|
|
|
25
27
|
ws.close();
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
30
|
+
const keepAliveInterval = (0, _timers.setInterval)(
|
|
31
|
+
() => ws.ping(),
|
|
32
|
+
KEEP_ALIVE_INTERVAL_MS,
|
|
33
|
+
).unref();
|
|
28
34
|
ws.on("error", (e) => {
|
|
29
35
|
websocketServer.onClientError && websocketServer.onClientError(client, e);
|
|
30
36
|
});
|
|
31
37
|
ws.on("close", () => {
|
|
38
|
+
(0, _timers.clearInterval)(keepAliveInterval);
|
|
32
39
|
websocketServer.onClientDisconnect &&
|
|
33
40
|
websocketServer.onClientDisconnect(client);
|
|
34
41
|
connected = false;
|
|
@@ -4,11 +4,12 @@
|
|
|
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
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import {clearInterval, setInterval} from 'timers';
|
|
12
13
|
import ws from 'ws';
|
|
13
14
|
|
|
14
15
|
type WebsocketServiceInterface<T> = interface {
|
|
@@ -16,13 +17,13 @@ type WebsocketServiceInterface<T> = interface {
|
|
|
16
17
|
url: string,
|
|
17
18
|
sendFn: (data: string) => void,
|
|
18
19
|
) => Promise<?T>,
|
|
19
|
-
+onClientDisconnect?: (client: T) =>
|
|
20
|
-
+onClientError?: (client: T, e:
|
|
20
|
+
+onClientDisconnect?: (client: T) => unknown,
|
|
21
|
+
+onClientError?: (client: T, e: Error) => unknown,
|
|
21
22
|
+onClientMessage?: (
|
|
22
23
|
client: T,
|
|
23
24
|
message: string | Buffer | ArrayBuffer | Array<Buffer>,
|
|
24
25
|
sendFn: (data: string) => void,
|
|
25
|
-
) =>
|
|
26
|
+
) => unknown,
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
type HMROptions<TClient> = {
|
|
@@ -30,6 +31,8 @@ type HMROptions<TClient> = {
|
|
|
30
31
|
...
|
|
31
32
|
};
|
|
32
33
|
|
|
34
|
+
const KEEP_ALIVE_INTERVAL_MS = 20000;
|
|
35
|
+
|
|
33
36
|
/**
|
|
34
37
|
* Returns a WebSocketServer to be attached to an existing HTTP instance. It forwards
|
|
35
38
|
* the received events on the given "websocketServer" parameter. It must be an
|
|
@@ -41,7 +44,7 @@ type HMROptions<TClient> = {
|
|
|
41
44
|
* - onClientDisconnect
|
|
42
45
|
*/
|
|
43
46
|
|
|
44
|
-
export default function createWebsocketServer<TClient
|
|
47
|
+
export default function createWebsocketServer<TClient>({
|
|
45
48
|
websocketServer,
|
|
46
49
|
}: HMROptions<TClient>): ws.Server {
|
|
47
50
|
const wss = new ws.Server({
|
|
@@ -52,10 +55,9 @@ export default function createWebsocketServer<TClient: Object>({
|
|
|
52
55
|
let connected = true;
|
|
53
56
|
const url = req.url;
|
|
54
57
|
|
|
55
|
-
const sendFn = (
|
|
58
|
+
const sendFn = (data: string) => {
|
|
56
59
|
if (connected) {
|
|
57
|
-
|
|
58
|
-
ws.send(...args);
|
|
60
|
+
ws.send(data);
|
|
59
61
|
}
|
|
60
62
|
};
|
|
61
63
|
|
|
@@ -66,12 +68,17 @@ export default function createWebsocketServer<TClient: Object>({
|
|
|
66
68
|
return;
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
const keepAliveInterval = setInterval(
|
|
72
|
+
() => ws.ping(),
|
|
73
|
+
KEEP_ALIVE_INTERVAL_MS,
|
|
74
|
+
).unref();
|
|
75
|
+
|
|
69
76
|
ws.on('error', e => {
|
|
70
|
-
// $FlowFixMe[incompatible-type]
|
|
71
77
|
websocketServer.onClientError && websocketServer.onClientError(client, e);
|
|
72
78
|
});
|
|
73
79
|
|
|
74
80
|
ws.on('close', () => {
|
|
81
|
+
clearInterval(keepAliveInterval);
|
|
75
82
|
websocketServer.onClientDisconnect &&
|
|
76
83
|
websocketServer.onClientDisconnect(client);
|
|
77
84
|
connected = false;
|
|
@@ -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 function debounceAsyncQueue<T>(
|
|
12
|
+
fn: () => Promise<T>,
|
|
13
|
+
delay: number,
|
|
14
|
+
): () => Promise<T>;
|
|
15
|
+
export default debounceAsyncQueue;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 {FormattedError} from 'metro-runtime/src/modules/types';
|
|
11
|
+
|
|
12
|
+
export type CustomError = Error & {
|
|
13
|
+
readonly type?: string;
|
|
14
|
+
filename?: string;
|
|
15
|
+
lineNumber?: number;
|
|
16
|
+
errors?: Array<{
|
|
17
|
+
description: string;
|
|
18
|
+
filename: string;
|
|
19
|
+
lineNumber: number;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
declare function formatBundlingError(error: CustomError): FormattedError;
|
|
23
|
+
export default formatBundlingError;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {Module} from '../DeltaBundler';
|
|
12
|
+
|
|
13
|
+
type Options<T extends number | string> = Readonly<{
|
|
14
|
+
asyncRequireModulePath: string;
|
|
15
|
+
createModuleId: ($$PARAM_0$$: string) => T;
|
|
16
|
+
getRunModuleStatement: (moduleId: T, globalPrefix: string) => string;
|
|
17
|
+
globalPrefix: string;
|
|
18
|
+
inlineSourceMap: null | undefined | boolean;
|
|
19
|
+
runBeforeMainModule: ReadonlyArray<string>;
|
|
20
|
+
runModule: boolean;
|
|
21
|
+
shouldAddToIgnoreList: ($$PARAM_0$$: Module) => boolean;
|
|
22
|
+
sourceMapUrl: null | undefined | string;
|
|
23
|
+
sourceUrl: null | undefined | string;
|
|
24
|
+
getSourceUrl: null | undefined | (($$PARAM_0$$: Module) => string);
|
|
25
|
+
}>;
|
|
26
|
+
declare function getAppendScripts<T extends number | string>(
|
|
27
|
+
entryPoint: string,
|
|
28
|
+
modules: ReadonlyArray<Module>,
|
|
29
|
+
options: Options<T>,
|
|
30
|
+
): ReadonlyArray<Module>;
|
|
31
|
+
export default getAppendScripts;
|
|
@@ -18,13 +18,13 @@ import CountingSet from './CountingSet';
|
|
|
18
18
|
import countLines from './countLines';
|
|
19
19
|
import nullthrows from 'nullthrows';
|
|
20
20
|
|
|
21
|
-
type Options<T: number | string> =
|
|
21
|
+
type Options<T: number | string> = Readonly<{
|
|
22
22
|
asyncRequireModulePath: string,
|
|
23
23
|
createModuleId: string => T,
|
|
24
24
|
getRunModuleStatement: (moduleId: T, globalPrefix: string) => string,
|
|
25
25
|
globalPrefix: string,
|
|
26
26
|
inlineSourceMap: ?boolean,
|
|
27
|
-
runBeforeMainModule:
|
|
27
|
+
runBeforeMainModule: ReadonlyArray<string>,
|
|
28
28
|
runModule: boolean,
|
|
29
29
|
shouldAddToIgnoreList: (Module<>) => boolean,
|
|
30
30
|
sourceMapUrl: ?string,
|
|
@@ -35,9 +35,9 @@ type Options<T: number | string> = $ReadOnly<{
|
|
|
35
35
|
|
|
36
36
|
export default function getAppendScripts<T: number | string>(
|
|
37
37
|
entryPoint: string,
|
|
38
|
-
modules:
|
|
38
|
+
modules: ReadonlyArray<Module<>>,
|
|
39
39
|
options: Options<T>,
|
|
40
|
-
):
|
|
40
|
+
): ReadonlyArray<Module<>> {
|
|
41
41
|
const output: Array<Module<>> = [];
|
|
42
42
|
|
|
43
43
|
if (options.runModule) {
|
package/src/lib/getGraphId.d.ts
CHANGED
|
@@ -8,4 +8,18 @@
|
|
|
8
8
|
* @oncall react_native
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
import type {TransformInputOptions} from '../DeltaBundler/types';
|
|
12
|
+
import type {ResolverInputOptions} from '../shared/types';
|
|
13
|
+
|
|
14
|
+
export declare type GraphId = string;
|
|
15
|
+
declare function getGraphId(
|
|
16
|
+
entryFile: string,
|
|
17
|
+
options: TransformInputOptions,
|
|
18
|
+
$$PARAM_2$$: Readonly<{
|
|
19
|
+
shallow: boolean;
|
|
20
|
+
lazy: boolean;
|
|
21
|
+
unstable_allowRequireContext: boolean;
|
|
22
|
+
resolverOptions: ResolverInputOptions;
|
|
23
|
+
}>,
|
|
24
|
+
): GraphId;
|
|
25
|
+
export default getGraphId;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 function getPreludeCode($$PARAM_0$$: {
|
|
12
|
+
readonly extraVars?: {[$$Key$$: string]: unknown};
|
|
13
|
+
readonly isDev: boolean;
|
|
14
|
+
readonly globalPrefix: string;
|
|
15
|
+
readonly requireCycleIgnorePatterns: ReadonlyArray<RegExp>;
|
|
16
|
+
readonly unstable_forceFullRefreshPatterns: ReadonlyArray<RegExp>;
|
|
17
|
+
}): string;
|
|
18
|
+
export default getPreludeCode;
|
|
@@ -9,6 +9,7 @@ function getPreludeCode({
|
|
|
9
9
|
isDev,
|
|
10
10
|
globalPrefix,
|
|
11
11
|
requireCycleIgnorePatterns,
|
|
12
|
+
unstable_forceFullRefreshPatterns,
|
|
12
13
|
}) {
|
|
13
14
|
const vars = [
|
|
14
15
|
"__BUNDLE_START_TIME__=globalThis.nativePerformanceNow?nativePerformanceNow():Date.now()",
|
|
@@ -21,6 +22,9 @@ function getPreludeCode({
|
|
|
21
22
|
vars.push(
|
|
22
23
|
`${globalPrefix}__requireCycleIgnorePatterns=[${requireCycleIgnorePatterns.map((regex) => regex.toString()).join(",")}]`,
|
|
23
24
|
);
|
|
25
|
+
vars.push(
|
|
26
|
+
`${globalPrefix}__unstable_forceFullRefreshPatterns=[${unstable_forceFullRefreshPatterns.map((regex) => regex.toString()).join(",")}]`,
|
|
27
|
+
);
|
|
24
28
|
}
|
|
25
29
|
return `var ${vars.join(",")};${processEnv(isDev ? "development" : "production")}`;
|
|
26
30
|
}
|
|
@@ -14,11 +14,13 @@ export default function getPreludeCode({
|
|
|
14
14
|
isDev,
|
|
15
15
|
globalPrefix,
|
|
16
16
|
requireCycleIgnorePatterns,
|
|
17
|
+
unstable_forceFullRefreshPatterns,
|
|
17
18
|
}: {
|
|
18
|
-
+extraVars?: {[string]:
|
|
19
|
+
+extraVars?: {[string]: unknown, ...},
|
|
19
20
|
+isDev: boolean,
|
|
20
21
|
+globalPrefix: string,
|
|
21
|
-
+requireCycleIgnorePatterns:
|
|
22
|
+
+requireCycleIgnorePatterns: ReadonlyArray<RegExp>,
|
|
23
|
+
+unstable_forceFullRefreshPatterns: ReadonlyArray<RegExp>,
|
|
22
24
|
}): string {
|
|
23
25
|
const vars = [
|
|
24
26
|
// Ensure these variable names match the ones referenced in metro-runtime
|
|
@@ -38,6 +40,11 @@ export default function getPreludeCode({
|
|
|
38
40
|
.map(regex => regex.toString())
|
|
39
41
|
.join(',')}]`,
|
|
40
42
|
);
|
|
43
|
+
vars.push(
|
|
44
|
+
`${globalPrefix}__unstable_forceFullRefreshPatterns=[${unstable_forceFullRefreshPatterns
|
|
45
|
+
.map(regex => regex.toString())
|
|
46
|
+
.join(',')}]`,
|
|
47
|
+
);
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
return `var ${vars.join(',')};${processEnv(
|
|
@@ -47,7 +54,7 @@ export default function getPreludeCode({
|
|
|
47
54
|
|
|
48
55
|
const excluded = new Set(['__BUNDLE_START_TIME__', '__DEV__', 'process']);
|
|
49
56
|
|
|
50
|
-
function formatExtraVars(extraVars: ?{[string]:
|
|
57
|
+
function formatExtraVars(extraVars: ?{[string]: unknown, ...}): Array<string> {
|
|
51
58
|
const assignments = [];
|
|
52
59
|
|
|
53
60
|
for (const key in extraVars) {
|
|
@@ -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
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type Bundler from '../Bundler';
|
|
12
|
+
import type {Module, default as DeltaBundler} from '../DeltaBundler';
|
|
13
|
+
import type {TransformInputOptions} from '../DeltaBundler/types';
|
|
14
|
+
import type {ResolverInputOptions} from '../shared/types';
|
|
15
|
+
import type {ConfigT} from 'metro-config';
|
|
16
|
+
|
|
17
|
+
declare function getPrependedScripts(
|
|
18
|
+
config: ConfigT,
|
|
19
|
+
options: Omit<TransformInputOptions, 'type'>,
|
|
20
|
+
resolverOptions: ResolverInputOptions,
|
|
21
|
+
bundler: Bundler,
|
|
22
|
+
deltaBundler: DeltaBundler,
|
|
23
|
+
): Promise<ReadonlyArray<Module>>;
|
|
24
|
+
export default getPrependedScripts;
|