metro 0.83.4 → 0.83.6
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 +18 -16
- package/src/Assets.d.ts +90 -0
- package/src/Assets.js +2 -9
- package/src/Bundler/util.d.ts +34 -0
- package/src/Bundler/util.js +2 -9
- package/src/Bundler/util.js.flow +3 -3
- package/src/Bundler.d.ts +45 -0
- package/src/Bundler.js +1 -5
- package/src/DeltaBundler/DeltaCalculator.d.ts +68 -0
- package/src/DeltaBundler/DeltaCalculator.js +56 -51
- package/src/DeltaBundler/DeltaCalculator.js.flow +72 -61
- package/src/DeltaBundler/Graph.d.ts +174 -0
- package/src/DeltaBundler/Graph.js +1 -5
- package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +27 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -5
- package/src/DeltaBundler/Serializers/getAllFiles.d.ts +29 -0
- package/src/DeltaBundler/Serializers/getAssets.d.ts +32 -0
- package/src/DeltaBundler/Serializers/getAssets.js +1 -5
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +33 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +55 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +1 -5
- 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/js.js +2 -9
- package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +32 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +37 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +2 -9
- package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +36 -0
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +1 -5
- 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/Transformer.js +1 -5
- package/src/DeltaBundler/Worker.d.ts +44 -0
- package/src/DeltaBundler/Worker.flow.js +1 -5
- package/src/DeltaBundler/WorkerFarm.d.ts +77 -0
- package/src/DeltaBundler/buildSubgraph.d.ts +37 -0
- package/src/DeltaBundler/buildSubgraph.js +1 -5
- package/src/DeltaBundler/getTransformCacheKey.d.ts +25 -0
- package/src/DeltaBundler/getTransformCacheKey.js +4 -6
- 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/types.js +1 -5
- package/src/DeltaBundler.d.ts +67 -0
- package/src/DeltaBundler.js +1 -5
- package/src/HmrServer.d.ts +98 -0
- package/src/HmrServer.js +9 -9
- 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/IncrementalBundler.js +2 -9
- package/src/ModuleGraph/worker/JsFileWrapping.d.ts +36 -0
- package/src/ModuleGraph/worker/JsFileWrapping.js +2 -9
- package/src/ModuleGraph/worker/collectDependencies.d.ts +138 -0
- package/src/ModuleGraph/worker/collectDependencies.js +2 -9
- package/src/ModuleGraph/worker/generateImportNames.d.ts +26 -0
- package/src/ModuleGraph/worker/generateImportNames.js +1 -5
- package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +33 -0
- package/src/Server/MultipartResponse.d.ts +37 -0
- package/src/Server/MultipartResponse.js +1 -5
- package/src/Server/symbolicate.d.ts +38 -0
- package/src/Server.d.ts +278 -0
- package/src/Server.js +47 -15
- package/src/Server.js.flow +57 -10
- package/src/cli/parseKeyValueParamArray.d.ts +21 -0
- package/src/cli-utils.d.ts +26 -0
- package/src/cli-utils.js +1 -5
- package/src/commands/build.d.ts +23 -0
- package/src/commands/build.js +1 -5
- package/src/commands/dependencies.d.ts +23 -0
- package/src/commands/dependencies.js +1 -5
- package/src/commands/serve.d.ts +23 -0
- package/src/index.d.ts +206 -0
- package/src/index.flow.js +26 -19
- package/src/index.flow.js.flow +46 -12
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +1 -5
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +1 -5
- package/src/integration_tests/basic_bundle/import-export/index.js +2 -9
- package/src/integration_tests/execBundle.js +1 -5
- package/src/lib/BatchProcessor.d.ts +61 -0
- package/src/lib/BatchProcessor.js +1 -5
- 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/RamBundleParser.js +1 -5
- package/src/lib/TerminalReporter.d.ts +125 -0
- package/src/lib/TerminalReporter.js +8 -16
- package/src/lib/TerminalReporter.js.flow +6 -15
- package/src/lib/bundleProgressUtils.d.ts +33 -0
- package/src/lib/bundleProgressUtils.js +19 -0
- package/src/lib/bundleProgressUtils.js.flow +35 -0
- package/src/lib/bundleToString.d.ts +26 -0
- package/src/lib/contextModule.d.ts +40 -0
- package/src/lib/contextModule.js +1 -5
- package/src/lib/contextModuleTemplates.d.ts +32 -0
- package/src/lib/contextModuleTemplates.js +1 -4
- package/src/lib/countLines.d.ts +19 -0
- package/src/lib/createWebsocketServer.d.ts +50 -0
- package/src/lib/createWebsocketServer.js +1 -5
- package/src/lib/debounceAsyncQueue.d.ts +22 -0
- package/src/lib/formatBundlingError.d.ts +30 -0
- package/src/lib/formatBundlingError.js +1 -5
- package/src/lib/getAppendScripts.d.ts +38 -0
- package/src/lib/getAppendScripts.js +1 -5
- package/src/lib/getAppendScripts.js.flow +2 -2
- package/src/lib/getGraphId.d.ts +32 -0
- package/src/lib/getGraphId.js +1 -5
- package/src/lib/getPreludeCode.d.ts +25 -0
- package/src/lib/getPrependedScripts.d.ts +31 -0
- package/src/lib/getPrependedScripts.js +2 -9
- package/src/lib/isResolvedDependency.d.ts +22 -0
- package/src/lib/logToConsole.d.ts +26 -0
- package/src/lib/logToConsole.js +1 -5
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +24 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +2 -9
- 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/pathUtils.js +1 -4
- package/src/lib/relativizeSourceMap.d.ts +24 -0
- package/src/lib/relativizeSourceMap.js +1 -5
- package/src/lib/reporting.d.ts +135 -0
- package/src/lib/reporting.js +1 -5
- package/src/lib/splitBundleOptions.d.ts +23 -0
- package/src/lib/transformHelpers.d.ts +42 -0
- package/src/lib/transformHelpers.js +1 -5
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +120 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.js +6 -31
- 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 +3 -10
- 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 +23 -16
- 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 -58
- package/src/node-haste/PackageCache.js.flow +103 -79
- package/src/node-haste/lib/AssetPaths.d.ts +36 -0
- package/src/node-haste/lib/AssetPaths.js +1 -5
- package/src/node-haste/lib/parsePlatformFilePath.d.ts +32 -0
- package/src/node-haste/lib/parsePlatformFilePath.js +1 -5
- package/src/shared/output/RamBundle/as-assets.d.ts +32 -0
- package/src/shared/output/RamBundle/as-assets.js +1 -5
- package/src/shared/output/RamBundle/as-indexed-file.d.ts +45 -0
- package/src/shared/output/RamBundle/as-indexed-file.js +1 -5
- 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/util.js +1 -5
- package/src/shared/output/RamBundle/write-sourcemap.d.ts +23 -0
- package/src/shared/output/RamBundle/write-sourcemap.js +1 -5
- package/src/shared/output/RamBundle.d.ts +33 -0
- package/src/shared/output/RamBundle.js +1 -5
- package/src/shared/output/bundle.d.ts +34 -0
- package/src/shared/output/bundle.flow.js +1 -5
- package/src/shared/output/meta.d.ts +22 -0
- package/src/shared/output/meta.js +1 -5
- package/src/shared/output/unbundle.d.ts +18 -0
- package/src/shared/output/writeFile.d.ts +23 -0
- package/src/shared/output/writeFile.js +1 -5
- package/src/shared/types.d.ts +152 -0
- package/src/node-haste/Package.js +0 -32
- package/src/node-haste/Package.js.flow +0 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.83.
|
|
3
|
+
"version": "0.83.6",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git
|
|
14
|
+
"url": "git+https://github.com/facebook/metro.git",
|
|
15
|
+
"directory": "packages/metro"
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|
|
17
18
|
"prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
|
|
@@ -33,24 +34,24 @@
|
|
|
33
34
|
"error-stack-parser": "^2.0.6",
|
|
34
35
|
"flow-enums-runtime": "^0.0.6",
|
|
35
36
|
"graceful-fs": "^4.2.4",
|
|
36
|
-
"hermes-parser": "0.
|
|
37
|
+
"hermes-parser": "0.35.0",
|
|
37
38
|
"image-size": "^1.0.2",
|
|
38
39
|
"invariant": "^2.2.4",
|
|
39
40
|
"jest-worker": "^29.7.0",
|
|
40
41
|
"jsc-safe-url": "^0.2.2",
|
|
41
42
|
"lodash.throttle": "^4.1.1",
|
|
42
|
-
"metro-babel-transformer": "0.83.
|
|
43
|
-
"metro-cache": "0.83.
|
|
44
|
-
"metro-cache-key": "0.83.
|
|
45
|
-
"metro-config": "0.83.
|
|
46
|
-
"metro-core": "0.83.
|
|
47
|
-
"metro-file-map": "0.83.
|
|
48
|
-
"metro-resolver": "0.83.
|
|
49
|
-
"metro-runtime": "0.83.
|
|
50
|
-
"metro-source-map": "0.83.
|
|
51
|
-
"metro-symbolicate": "0.83.
|
|
52
|
-
"metro-transform-plugins": "0.83.
|
|
53
|
-
"metro-transform-worker": "0.83.
|
|
43
|
+
"metro-babel-transformer": "0.83.6",
|
|
44
|
+
"metro-cache": "0.83.6",
|
|
45
|
+
"metro-cache-key": "0.83.6",
|
|
46
|
+
"metro-config": "0.83.6",
|
|
47
|
+
"metro-core": "0.83.6",
|
|
48
|
+
"metro-file-map": "0.83.6",
|
|
49
|
+
"metro-resolver": "0.83.6",
|
|
50
|
+
"metro-runtime": "0.83.6",
|
|
51
|
+
"metro-source-map": "0.83.6",
|
|
52
|
+
"metro-symbolicate": "0.83.6",
|
|
53
|
+
"metro-transform-plugins": "0.83.6",
|
|
54
|
+
"metro-transform-worker": "0.83.6",
|
|
54
55
|
"mime-types": "^3.0.1",
|
|
55
56
|
"nullthrows": "^1.1.1",
|
|
56
57
|
"serialize-error": "^2.1.0",
|
|
@@ -71,10 +72,11 @@
|
|
|
71
72
|
"dedent": "^0.7.0",
|
|
72
73
|
"jest-snapshot": "^29.7.0",
|
|
73
74
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
74
|
-
"metro-babel-register": "0.83.
|
|
75
|
+
"metro-babel-register": "0.83.6",
|
|
75
76
|
"metro-memory-fs": "*",
|
|
76
77
|
"mock-req": "^0.2.0",
|
|
77
78
|
"mock-res": "^0.6.0",
|
|
79
|
+
"selfsigned": "^5.5.0",
|
|
78
80
|
"stack-trace": "^0.0.10"
|
|
79
81
|
},
|
|
80
82
|
"license": "MIT",
|
package/src/Assets.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
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<<a58b1d0332fe424196b6d106eacdc2fe>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/Assets.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export type AssetInfo = {
|
|
19
|
+
readonly files: Array<string>;
|
|
20
|
+
readonly hash: string;
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly scales: Array<number>;
|
|
23
|
+
readonly type: string;
|
|
24
|
+
};
|
|
25
|
+
export type AssetDataWithoutFiles = {
|
|
26
|
+
readonly __packager_asset: boolean;
|
|
27
|
+
readonly fileSystemLocation: string;
|
|
28
|
+
readonly hash: string;
|
|
29
|
+
readonly height: null | undefined | number;
|
|
30
|
+
readonly httpServerLocation: string;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly scales: Array<number>;
|
|
33
|
+
readonly type: string;
|
|
34
|
+
readonly width: null | undefined | number;
|
|
35
|
+
};
|
|
36
|
+
export type AssetDataFiltered = {
|
|
37
|
+
readonly __packager_asset: boolean;
|
|
38
|
+
readonly hash: string;
|
|
39
|
+
readonly height: null | undefined | number;
|
|
40
|
+
readonly httpServerLocation: string;
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly scales: Array<number>;
|
|
43
|
+
readonly type: string;
|
|
44
|
+
readonly width: null | undefined | number;
|
|
45
|
+
};
|
|
46
|
+
export declare function isAssetTypeAnImage(type: string): boolean;
|
|
47
|
+
export declare function getAssetSize(
|
|
48
|
+
type: string,
|
|
49
|
+
content: Buffer,
|
|
50
|
+
filePath: string,
|
|
51
|
+
): null | undefined | {readonly width: number; readonly height: number};
|
|
52
|
+
export type AssetData = AssetDataWithoutFiles & {
|
|
53
|
+
readonly files: Array<string>;
|
|
54
|
+
};
|
|
55
|
+
export type AssetDataPlugin = (
|
|
56
|
+
assetData: AssetData,
|
|
57
|
+
) => AssetData | Promise<AssetData>;
|
|
58
|
+
export declare function getAssetData(
|
|
59
|
+
assetPath: string,
|
|
60
|
+
localPath: string,
|
|
61
|
+
assetDataPlugins: ReadonlyArray<string>,
|
|
62
|
+
platform: null | undefined | string,
|
|
63
|
+
publicPath: string,
|
|
64
|
+
): Promise<AssetData>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns all the associated files (for different resolutions) of an asset.
|
|
67
|
+
**/
|
|
68
|
+
export declare function getAssetFiles(
|
|
69
|
+
assetPath: string,
|
|
70
|
+
platform?: null | undefined | string,
|
|
71
|
+
): Promise<Array<string>>;
|
|
72
|
+
/**
|
|
73
|
+
* Return a buffer with the actual image given a request for an image by path.
|
|
74
|
+
* The relativePath can contain a resolution postfix, in this case we need to
|
|
75
|
+
* find that image (or the closest one to it's resolution) in one of the
|
|
76
|
+
* project roots:
|
|
77
|
+
*
|
|
78
|
+
* 1. We first parse the directory of the asset
|
|
79
|
+
* 2. We then build a map of all assets and their scales in this directory
|
|
80
|
+
* 3. Then try to pick platform-specific asset records
|
|
81
|
+
* 4. Then pick the closest resolution (rounding up) to the requested one
|
|
82
|
+
*/
|
|
83
|
+
export declare function getAsset(
|
|
84
|
+
relativePath: string,
|
|
85
|
+
projectRoot: string,
|
|
86
|
+
watchFolders: ReadonlyArray<string>,
|
|
87
|
+
platform: null | undefined | string,
|
|
88
|
+
assetExts: ReadonlyArray<string>,
|
|
89
|
+
fileExistsInFileMap?: (absolutePath: string) => boolean,
|
|
90
|
+
): Promise<Buffer>;
|
package/src/Assets.js
CHANGED
|
@@ -17,11 +17,7 @@ var _fs = _interopRequireDefault(require("fs"));
|
|
|
17
17
|
var _imageSize = _interopRequireDefault(require("image-size"));
|
|
18
18
|
var _path = _interopRequireDefault(require("path"));
|
|
19
19
|
function _interopRequireDefault(e) {
|
|
20
|
-
return e && e.__esModule
|
|
21
|
-
? e
|
|
22
|
-
: {
|
|
23
|
-
default: e,
|
|
24
|
-
};
|
|
20
|
+
return e && e.__esModule ? e : { default: e };
|
|
25
21
|
}
|
|
26
22
|
function _interopRequireWildcard(e, t) {
|
|
27
23
|
if ("function" == typeof WeakMap)
|
|
@@ -31,10 +27,7 @@ function _interopRequireWildcard(e, t) {
|
|
|
31
27
|
if (!t && e && e.__esModule) return e;
|
|
32
28
|
var o,
|
|
33
29
|
i,
|
|
34
|
-
f = {
|
|
35
|
-
__proto__: null,
|
|
36
|
-
default: e,
|
|
37
|
-
};
|
|
30
|
+
f = { __proto__: null, default: e };
|
|
38
31
|
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
39
32
|
return f;
|
|
40
33
|
if ((o = t ? n : r)) {
|
|
@@ -0,0 +1,34 @@
|
|
|
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<<adf0e819f93597b57ff231cca9c918ef>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/Bundler/util.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 {AssetDataWithoutFiles} from '../Assets';
|
|
19
|
+
import type {ModuleTransportLike} from '../shared/types';
|
|
20
|
+
import type {File} from '@babel/types';
|
|
21
|
+
|
|
22
|
+
type SubTree<T extends ModuleTransportLike> = (
|
|
23
|
+
moduleTransport: T,
|
|
24
|
+
moduleTransportsByPath: Map<string, T>,
|
|
25
|
+
) => Iterable<number>;
|
|
26
|
+
export declare function generateAssetCodeFileAst(
|
|
27
|
+
assetRegistryPath: string,
|
|
28
|
+
assetDescriptor: AssetDataWithoutFiles,
|
|
29
|
+
): File;
|
|
30
|
+
export declare function createRamBundleGroups<T extends ModuleTransportLike>(
|
|
31
|
+
ramGroups: ReadonlyArray<string>,
|
|
32
|
+
groupableModules: ReadonlyArray<T>,
|
|
33
|
+
subtree: SubTree<T>,
|
|
34
|
+
): Map<number, Set<number>>;
|
package/src/Bundler/util.js
CHANGED
|
@@ -9,11 +9,7 @@ var babylon = _interopRequireWildcard(require("@babel/parser"));
|
|
|
9
9
|
var _template = _interopRequireDefault(require("@babel/template"));
|
|
10
10
|
var babelTypes = _interopRequireWildcard(require("@babel/types"));
|
|
11
11
|
function _interopRequireDefault(e) {
|
|
12
|
-
return e && e.__esModule
|
|
13
|
-
? e
|
|
14
|
-
: {
|
|
15
|
-
default: e,
|
|
16
|
-
};
|
|
12
|
+
return e && e.__esModule ? e : { default: e };
|
|
17
13
|
}
|
|
18
14
|
function _interopRequireWildcard(e, t) {
|
|
19
15
|
if ("function" == typeof WeakMap)
|
|
@@ -23,10 +19,7 @@ function _interopRequireWildcard(e, t) {
|
|
|
23
19
|
if (!t && e && e.__esModule) return e;
|
|
24
20
|
var o,
|
|
25
21
|
i,
|
|
26
|
-
f = {
|
|
27
|
-
__proto__: null,
|
|
28
|
-
default: e,
|
|
29
|
-
};
|
|
22
|
+
f = { __proto__: null, default: e };
|
|
30
23
|
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
31
24
|
return f;
|
|
32
25
|
if ((o = t ? n : r)) {
|
package/src/Bundler/util.js.flow
CHANGED
|
@@ -17,7 +17,7 @@ import * as babylon from '@babel/parser';
|
|
|
17
17
|
import template from '@babel/template';
|
|
18
18
|
import * as babelTypes from '@babel/types';
|
|
19
19
|
|
|
20
|
-
type SubTree<T
|
|
20
|
+
type SubTree<T extends ModuleTransportLike> = (
|
|
21
21
|
moduleTransport: T,
|
|
22
22
|
moduleTransportsByPath: Map<string, T>,
|
|
23
23
|
) => Iterable<number>;
|
|
@@ -66,7 +66,7 @@ function filterObject(
|
|
|
66
66
|
return copied;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export function createRamBundleGroups<T
|
|
69
|
+
export function createRamBundleGroups<T extends ModuleTransportLike>(
|
|
70
70
|
ramGroups: ReadonlyArray<string>,
|
|
71
71
|
groupableModules: ReadonlyArray<T>,
|
|
72
72
|
subtree: SubTree<T>,
|
|
@@ -123,7 +123,7 @@ export function createRamBundleGroups<T: ModuleTransportLike>(
|
|
|
123
123
|
return result;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
function* filter<A
|
|
126
|
+
function* filter<A extends number, B extends number>(
|
|
127
127
|
iterator: ArrayMap<A, B>,
|
|
128
128
|
predicate: ([A, Array<B>]) => boolean,
|
|
129
129
|
): Generator<[A, Array<B>], void, void> {
|
package/src/Bundler.d.ts
ADDED
|
@@ -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<<3d5664309abdece0f247fcd0c53c3aaf>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/Bundler.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 {TransformResultWithSource} from './DeltaBundler';
|
|
19
|
+
import type {TransformOptions} from './DeltaBundler/Worker';
|
|
20
|
+
import type EventEmitter from 'events';
|
|
21
|
+
import type {ConfigT} from 'metro-config';
|
|
22
|
+
|
|
23
|
+
import Transformer from './DeltaBundler/Transformer';
|
|
24
|
+
import DependencyGraph from './node-haste/DependencyGraph';
|
|
25
|
+
|
|
26
|
+
export type BundlerOptions = Readonly<{
|
|
27
|
+
hasReducedPerformance?: boolean;
|
|
28
|
+
watch?: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
declare class Bundler {
|
|
31
|
+
_depGraph: DependencyGraph;
|
|
32
|
+
_initializedPromise: Promise<void>;
|
|
33
|
+
_transformer: Transformer;
|
|
34
|
+
constructor(config: ConfigT, options?: BundlerOptions);
|
|
35
|
+
getWatcher(): EventEmitter;
|
|
36
|
+
end(): Promise<void>;
|
|
37
|
+
getDependencyGraph(): Promise<DependencyGraph>;
|
|
38
|
+
transformFile(
|
|
39
|
+
filePath: string,
|
|
40
|
+
transformOptions: TransformOptions,
|
|
41
|
+
fileBuffer?: Buffer,
|
|
42
|
+
): Promise<TransformResultWithSource>;
|
|
43
|
+
ready(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export default Bundler;
|
package/src/Bundler.js
CHANGED
|
@@ -11,11 +11,7 @@ var _DependencyGraph = _interopRequireDefault(
|
|
|
11
11
|
require("./node-haste/DependencyGraph"),
|
|
12
12
|
);
|
|
13
13
|
function _interopRequireDefault(e) {
|
|
14
|
-
return e && e.__esModule
|
|
15
|
-
? e
|
|
16
|
-
: {
|
|
17
|
-
default: e,
|
|
18
|
-
};
|
|
14
|
+
return e && e.__esModule ? e : { default: e };
|
|
19
15
|
}
|
|
20
16
|
class Bundler {
|
|
21
17
|
constructor(config, options) {
|
|
@@ -0,0 +1,68 @@
|
|
|
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<<d06b53dd09157df95aeb941035d4ebf0>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/DeltaCalculator.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 {DeltaResult, Options} from './types';
|
|
19
|
+
import type {ChangeEvent} from 'metro-file-map';
|
|
20
|
+
|
|
21
|
+
import {Graph} from './Graph';
|
|
22
|
+
import EventEmitter from 'events';
|
|
23
|
+
/**
|
|
24
|
+
* This class is in charge of calculating the delta of changed modules that
|
|
25
|
+
* happen between calls. To do so, it subscribes to file changes, so it can
|
|
26
|
+
* traverse the files that have been changed between calls and avoid having to
|
|
27
|
+
* traverse the whole dependency tree for trivial small changes.
|
|
28
|
+
*/
|
|
29
|
+
declare class DeltaCalculator<T> extends EventEmitter {
|
|
30
|
+
_changeEventSource: EventEmitter;
|
|
31
|
+
_options: Options<T>;
|
|
32
|
+
_currentBuildPromise: null | undefined | Promise<DeltaResult<T>>;
|
|
33
|
+
_deletedFiles: Set<string>;
|
|
34
|
+
_modifiedFiles: Set<string>;
|
|
35
|
+
_addedFiles: Set<string>;
|
|
36
|
+
_requiresReset: boolean;
|
|
37
|
+
_graph: Graph<T>;
|
|
38
|
+
constructor(
|
|
39
|
+
entryPoints: ReadonlySet<string>,
|
|
40
|
+
changeEventSource: EventEmitter,
|
|
41
|
+
options: Options<T>,
|
|
42
|
+
);
|
|
43
|
+
/**
|
|
44
|
+
* Stops listening for file changes and clears all the caches.
|
|
45
|
+
*/
|
|
46
|
+
end(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Main method to calculate the delta of modules. It returns a DeltaResult,
|
|
49
|
+
* which contain the modified/added modules and the removed modules.
|
|
50
|
+
*/
|
|
51
|
+
getDelta($$PARAM_0$$: {
|
|
52
|
+
reset: boolean;
|
|
53
|
+
shallow: boolean;
|
|
54
|
+
}): Promise<DeltaResult<T>>;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the graph with all the dependencies. Each module contains the
|
|
57
|
+
* needed information to do the traversing (dependencies, inverseDependencies)
|
|
58
|
+
* plus some metadata.
|
|
59
|
+
*/
|
|
60
|
+
getGraph(): Graph<T>;
|
|
61
|
+
_handleMultipleFileChanges: (changeEvent: ChangeEvent) => void;
|
|
62
|
+
_getChangedDependencies(
|
|
63
|
+
modifiedFiles: Set<string>,
|
|
64
|
+
deletedFiles: Set<string>,
|
|
65
|
+
addedFiles: Set<string>,
|
|
66
|
+
): Promise<DeltaResult<T>>;
|
|
67
|
+
}
|
|
68
|
+
export default DeltaCalculator;
|
|
@@ -5,16 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _Graph = require("./Graph");
|
|
8
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
8
9
|
var _events = _interopRequireDefault(require("events"));
|
|
9
10
|
var _path = _interopRequireDefault(require("path"));
|
|
10
11
|
function _interopRequireDefault(e) {
|
|
11
|
-
return e && e.__esModule
|
|
12
|
-
? e
|
|
13
|
-
: {
|
|
14
|
-
default: e,
|
|
15
|
-
};
|
|
12
|
+
return e && e.__esModule ? e : { default: e };
|
|
16
13
|
}
|
|
17
14
|
const debug = require("debug")("Metro:DeltaCalculator");
|
|
15
|
+
const changeEventIds = new WeakMap();
|
|
18
16
|
class DeltaCalculator extends _events.default {
|
|
19
17
|
_deletedFiles = new Set();
|
|
20
18
|
_modifiedFiles = new Set();
|
|
@@ -98,60 +96,67 @@ class DeltaCalculator extends _events.default {
|
|
|
98
96
|
getGraph() {
|
|
99
97
|
return this._graph;
|
|
100
98
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
_handleFileChange = ({ type, filePath, metadata }, logger) => {
|
|
107
|
-
debug("Handling %s: %s (type: %s)", type, filePath, metadata.type);
|
|
99
|
+
#shouldReset(canonicalPath, metadata) {
|
|
100
|
+
if (metadata.isSymlink) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
108
103
|
if (
|
|
109
|
-
|
|
110
|
-
(
|
|
111
|
-
|
|
104
|
+
this._options.unstable_enablePackageExports &&
|
|
105
|
+
(canonicalPath === "package.json" ||
|
|
106
|
+
canonicalPath.endsWith(_path.default.sep + "package.json"))
|
|
112
107
|
) {
|
|
113
|
-
|
|
114
|
-
this.emit("change", {
|
|
115
|
-
logger,
|
|
116
|
-
});
|
|
108
|
+
return true;
|
|
117
109
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
_handleMultipleFileChanges = (changeEvent) => {
|
|
113
|
+
const { changes, logger, rootDir } = changeEvent;
|
|
114
|
+
for (const [canonicalPath, metadata] of changes.addedFiles) {
|
|
115
|
+
debug("Handling add: %s", canonicalPath);
|
|
116
|
+
if (this.#shouldReset(canonicalPath, metadata)) {
|
|
117
|
+
this._requiresReset = true;
|
|
118
|
+
}
|
|
119
|
+
const absolutePath = _path.default.join(rootDir, canonicalPath);
|
|
120
|
+
if (this._deletedFiles.has(absolutePath)) {
|
|
121
|
+
this._deletedFiles.delete(absolutePath);
|
|
122
|
+
this._modifiedFiles.add(absolutePath);
|
|
123
|
+
} else {
|
|
124
|
+
this._addedFiles.add(absolutePath);
|
|
125
|
+
this._modifiedFiles.delete(absolutePath);
|
|
126
|
+
}
|
|
125
127
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
for (const [canonicalPath, metadata] of changes.modifiedFiles) {
|
|
129
|
+
debug("Handling change: %s", canonicalPath);
|
|
130
|
+
if (this.#shouldReset(canonicalPath, metadata)) {
|
|
131
|
+
this._requiresReset = true;
|
|
132
|
+
}
|
|
133
|
+
const absolutePath = _path.default.join(rootDir, canonicalPath);
|
|
134
|
+
if (!this._addedFiles.has(absolutePath)) {
|
|
135
|
+
this._modifiedFiles.add(absolutePath);
|
|
136
|
+
}
|
|
137
|
+
this._deletedFiles.delete(absolutePath);
|
|
138
|
+
}
|
|
139
|
+
for (const [canonicalPath, metadata] of changes.removedFiles) {
|
|
140
|
+
debug("Handling delete: %s", canonicalPath);
|
|
141
|
+
if (this.#shouldReset(canonicalPath, metadata)) {
|
|
142
|
+
this._requiresReset = true;
|
|
143
|
+
}
|
|
144
|
+
const absolutePath = _path.default.resolve(rootDir, canonicalPath);
|
|
145
|
+
if (this._addedFiles.has(absolutePath)) {
|
|
146
|
+
this._addedFiles.delete(absolutePath);
|
|
147
|
+
} else {
|
|
148
|
+
this._deletedFiles.add(absolutePath);
|
|
149
|
+
this._modifiedFiles.delete(absolutePath);
|
|
150
|
+
}
|
|
133
151
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this._addedFiles.delete(filePath);
|
|
139
|
-
break;
|
|
140
|
-
case "added":
|
|
141
|
-
this._addedFiles.add(filePath);
|
|
142
|
-
this._deletedFiles.delete(filePath);
|
|
143
|
-
this._modifiedFiles.delete(filePath);
|
|
144
|
-
break;
|
|
145
|
-
case "modified":
|
|
146
|
-
this._modifiedFiles.add(filePath);
|
|
147
|
-
this._deletedFiles.delete(filePath);
|
|
148
|
-
this._addedFiles.delete(filePath);
|
|
149
|
-
break;
|
|
150
|
-
default:
|
|
151
|
-
nextState;
|
|
152
|
+
let changeId = changeEventIds.get(changeEvent);
|
|
153
|
+
if (changeId == null) {
|
|
154
|
+
changeId = _crypto.default.randomUUID();
|
|
155
|
+
changeEventIds.set(changeEvent, changeId);
|
|
152
156
|
}
|
|
153
157
|
this.emit("change", {
|
|
154
158
|
logger,
|
|
159
|
+
changeId,
|
|
155
160
|
});
|
|
156
161
|
};
|
|
157
162
|
async _getChangedDependencies(modifiedFiles, deletedFiles, addedFiles) {
|