metro 0.83.5 → 0.83.7
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 -16
- package/src/Assets.d.ts +8 -1
- package/src/Assets.js +20 -13
- package/src/Assets.js.flow +20 -13
- package/src/Bundler/util.d.ts +8 -1
- package/src/Bundler/util.js.flow +3 -3
- package/src/Bundler.d.ts +8 -1
- package/src/DeltaBundler/DeltaCalculator.d.ts +8 -11
- package/src/DeltaBundler/DeltaCalculator.js +55 -46
- package/src/DeltaBundler/DeltaCalculator.js.flow +72 -61
- package/src/DeltaBundler/Graph.d.ts +8 -1
- package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +8 -1
- package/src/DeltaBundler/Serializers/getAllFiles.d.ts +8 -1
- package/src/DeltaBundler/Serializers/getAssets.d.ts +8 -1
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +8 -1
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +8 -1
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +8 -1
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +8 -1
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +8 -1
- package/src/DeltaBundler/Serializers/helpers/js.d.ts +8 -1
- package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +8 -1
- package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +8 -1
- package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +8 -1
- package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +8 -1
- package/src/DeltaBundler/Serializers/sourceMapString.d.ts +8 -1
- package/src/DeltaBundler/Transformer.d.ts +8 -1
- package/src/DeltaBundler/Worker.d.ts +8 -1
- package/src/DeltaBundler/WorkerFarm.d.ts +8 -1
- package/src/DeltaBundler/buildSubgraph.d.ts +8 -1
- package/src/DeltaBundler/getTransformCacheKey.d.ts +8 -1
- package/src/DeltaBundler/getTransformCacheKey.js +3 -1
- package/src/DeltaBundler/getTransformCacheKey.js.flow +7 -2
- package/src/DeltaBundler/mergeDeltas.d.ts +8 -1
- package/src/DeltaBundler/types.d.ts +8 -1
- package/src/DeltaBundler.d.ts +8 -1
- package/src/HmrServer.d.ts +22 -3
- package/src/HmrServer.js +7 -0
- package/src/HmrServer.js.flow +15 -5
- package/src/IncrementalBundler/GraphNotFoundError.d.ts +8 -1
- package/src/IncrementalBundler/ResourceNotFoundError.d.ts +8 -1
- package/src/IncrementalBundler/RevisionNotFoundError.d.ts +8 -1
- package/src/IncrementalBundler.d.ts +8 -1
- package/src/ModuleGraph/worker/JsFileWrapping.d.ts +8 -1
- package/src/ModuleGraph/worker/collectDependencies.d.ts +8 -1
- package/src/ModuleGraph/worker/collectDependencies.js +52 -0
- package/src/ModuleGraph/worker/collectDependencies.js.flow +67 -0
- package/src/ModuleGraph/worker/generateImportNames.d.ts +8 -1
- package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +8 -1
- package/src/Server/MultipartResponse.d.ts +8 -1
- package/src/Server/symbolicate.d.ts +8 -1
- package/src/Server.d.ts +11 -1
- package/src/Server.js +42 -5
- package/src/Server.js.flow +45 -5
- package/src/cli/parseKeyValueParamArray.d.ts +8 -1
- package/src/cli-utils.d.ts +8 -1
- package/src/commands/build.d.ts +8 -1
- package/src/commands/dependencies.d.ts +8 -1
- package/src/commands/serve.d.ts +8 -1
- package/src/index.d.ts +29 -3
- package/src/index.flow.js +2 -2
- package/src/index.flow.js.flow +23 -4
- package/src/lib/BatchProcessor.d.ts +8 -1
- package/src/lib/CountingSet.d.ts +8 -1
- package/src/lib/JsonReporter.d.ts +8 -1
- package/src/lib/JsonReporter.js.flow +2 -2
- package/src/lib/RamBundleParser.d.ts +8 -1
- package/src/lib/TerminalReporter.d.ts +8 -1
- package/src/lib/TerminalReporter.js +39 -41
- package/src/lib/TerminalReporter.js.flow +51 -32
- package/src/lib/bundleProgressUtils.d.ts +8 -1
- package/src/lib/bundleToString.d.ts +8 -1
- package/src/lib/contextModule.d.ts +8 -1
- package/src/lib/contextModuleTemplates.d.ts +8 -1
- package/src/lib/countLines.d.ts +8 -1
- package/src/lib/createWebsocketServer.d.ts +8 -1
- package/src/lib/debounceAsyncQueue.d.ts +8 -1
- package/src/lib/formatBundlingError.d.ts +8 -1
- package/src/lib/getAppendScripts.d.ts +8 -1
- package/src/lib/getAppendScripts.js.flow +2 -2
- package/src/lib/getGraphId.d.ts +8 -1
- package/src/lib/getPreludeCode.d.ts +8 -1
- package/src/lib/getPrependedScripts.d.ts +8 -1
- package/src/lib/isResolvedDependency.d.ts +8 -1
- package/src/lib/logToConsole.d.ts +8 -1
- package/src/lib/logToConsole.js +8 -7
- package/src/lib/logToConsole.js.flow +7 -7
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +8 -1
- package/src/lib/parseCustomResolverOptions.d.ts +8 -1
- package/src/lib/parseCustomTransformOptions.d.ts +8 -1
- package/src/lib/parseJsonBody.d.ts +8 -1
- package/src/lib/pathUtils.d.ts +8 -1
- package/src/lib/relativizeSourceMap.d.ts +8 -1
- package/src/lib/reporting.d.ts +8 -1
- package/src/lib/reporting.js +16 -7
- package/src/lib/reporting.js.flow +16 -5
- package/src/lib/splitBundleOptions.d.ts +8 -1
- package/src/lib/transformHelpers.d.ts +8 -1
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +16 -22
- 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 +8 -1
- package/src/node-haste/DependencyGraph/createFileMap.js +1 -2
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +4 -3
- package/src/node-haste/DependencyGraph.d.ts +9 -5
- package/src/node-haste/DependencyGraph.js +22 -11
- package/src/node-haste/DependencyGraph.js.flow +24 -13
- package/src/node-haste/PackageCache.d.ts +19 -16
- 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 +8 -1
- package/src/node-haste/lib/parsePlatformFilePath.d.ts +8 -1
- package/src/shared/output/RamBundle/as-assets.d.ts +8 -1
- package/src/shared/output/RamBundle/as-indexed-file.d.ts +8 -1
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +8 -1
- package/src/shared/output/RamBundle/magic-number.d.ts +8 -1
- package/src/shared/output/RamBundle/util.d.ts +8 -1
- package/src/shared/output/RamBundle/write-sourcemap.d.ts +8 -1
- package/src/shared/output/RamBundle.d.ts +8 -1
- package/src/shared/output/bundle.d.ts +8 -1
- package/src/shared/output/meta.d.ts +8 -1
- package/src/shared/output/unbundle.d.ts +8 -1
- package/src/shared/output/writeFile.d.ts +8 -1
- package/src/shared/types.d.ts +8 -1
- package/src/node-haste/Package.d.ts +0 -21
- package/src/node-haste/Package.js +0 -28
- 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.7",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -27,31 +27,30 @@
|
|
|
27
27
|
"@babel/traverse": "^7.29.0",
|
|
28
28
|
"@babel/types": "^7.29.0",
|
|
29
29
|
"accepts": "^2.0.0",
|
|
30
|
-
"chalk": "^4.0.0",
|
|
31
30
|
"ci-info": "^2.0.0",
|
|
32
31
|
"connect": "^3.6.5",
|
|
33
32
|
"debug": "^4.4.0",
|
|
34
33
|
"error-stack-parser": "^2.0.6",
|
|
35
34
|
"flow-enums-runtime": "^0.0.6",
|
|
36
35
|
"graceful-fs": "^4.2.4",
|
|
37
|
-
"hermes-parser": "0.
|
|
36
|
+
"hermes-parser": "0.35.0",
|
|
38
37
|
"image-size": "^1.0.2",
|
|
39
38
|
"invariant": "^2.2.4",
|
|
40
39
|
"jest-worker": "^29.7.0",
|
|
41
40
|
"jsc-safe-url": "^0.2.2",
|
|
42
41
|
"lodash.throttle": "^4.1.1",
|
|
43
|
-
"metro-babel-transformer": "0.83.
|
|
44
|
-
"metro-cache": "0.83.
|
|
45
|
-
"metro-cache-key": "0.83.
|
|
46
|
-
"metro-config": "0.83.
|
|
47
|
-
"metro-core": "0.83.
|
|
48
|
-
"metro-file-map": "0.83.
|
|
49
|
-
"metro-resolver": "0.83.
|
|
50
|
-
"metro-runtime": "0.83.
|
|
51
|
-
"metro-source-map": "0.83.
|
|
52
|
-
"metro-symbolicate": "0.83.
|
|
53
|
-
"metro-transform-plugins": "0.83.
|
|
54
|
-
"metro-transform-worker": "0.83.
|
|
42
|
+
"metro-babel-transformer": "0.83.7",
|
|
43
|
+
"metro-cache": "0.83.7",
|
|
44
|
+
"metro-cache-key": "0.83.7",
|
|
45
|
+
"metro-config": "0.83.7",
|
|
46
|
+
"metro-core": "0.83.7",
|
|
47
|
+
"metro-file-map": "0.83.7",
|
|
48
|
+
"metro-resolver": "0.83.7",
|
|
49
|
+
"metro-runtime": "0.83.7",
|
|
50
|
+
"metro-source-map": "0.83.7",
|
|
51
|
+
"metro-symbolicate": "0.83.7",
|
|
52
|
+
"metro-transform-plugins": "0.83.7",
|
|
53
|
+
"metro-transform-worker": "0.83.7",
|
|
55
54
|
"mime-types": "^3.0.1",
|
|
56
55
|
"nullthrows": "^1.1.1",
|
|
57
56
|
"serialize-error": "^2.1.0",
|
|
@@ -72,7 +71,7 @@
|
|
|
72
71
|
"dedent": "^0.7.0",
|
|
73
72
|
"jest-snapshot": "^29.7.0",
|
|
74
73
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
75
|
-
"metro-babel-register": "0.83.
|
|
74
|
+
"metro-babel-register": "0.83.7",
|
|
76
75
|
"metro-memory-fs": "*",
|
|
77
76
|
"mock-req": "^0.2.0",
|
|
78
77
|
"mock-res": "^0.6.0",
|
package/src/Assets.d.ts
CHANGED
|
@@ -4,8 +4,15 @@
|
|
|
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
|
-
* @
|
|
7
|
+
* @noformat
|
|
8
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)
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
export type AssetInfo = {
|
package/src/Assets.js
CHANGED
|
@@ -221,26 +221,33 @@ async function getAsset(
|
|
|
221
221
|
`'${relativePath}' cannot be loaded as its extension is not registered in assetExts`,
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
|
|
232
|
-
throw new Error(
|
|
233
|
-
`'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
|
|
234
|
-
);
|
|
235
|
-
}
|
|
224
|
+
if (
|
|
225
|
+
fileExistsInFileMap == null &&
|
|
226
|
+
!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])
|
|
227
|
+
) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
|
|
230
|
+
);
|
|
236
231
|
}
|
|
237
232
|
const record = await getAbsoluteAssetRecord(absolutePath, platform ?? null);
|
|
238
233
|
for (let i = 0; i < record.scales.length; i++) {
|
|
239
234
|
if (record.scales[i] >= assetData.resolution) {
|
|
235
|
+
if (
|
|
236
|
+
fileExistsInFileMap != null &&
|
|
237
|
+
!fileExistsInFileMap(record.files[i])
|
|
238
|
+
) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
240
241
|
return _fs.default.promises.readFile(record.files[i]);
|
|
241
242
|
}
|
|
242
243
|
}
|
|
243
|
-
|
|
244
|
+
const lastFile = record.files[record.files.length - 1];
|
|
245
|
+
if (fileExistsInFileMap != null && !fileExistsInFileMap(lastFile)) {
|
|
246
|
+
throw new Error(
|
|
247
|
+
`'${relativePath}' could not be found, because it is not within the projectRoot or watchFolders, or it is blocked via the resolver.blockList config`,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return _fs.default.promises.readFile(lastFile);
|
|
244
251
|
}
|
|
245
252
|
function pathBelongsToRoots(pathToCheck, roots) {
|
|
246
253
|
for (const rootFolder of roots) {
|
package/src/Assets.js.flow
CHANGED
|
@@ -299,29 +299,36 @@ export async function getAsset(
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
// NOTE: If fileExistsInFileMap is not provided, we fall back to pathBelongsToRoots for backward compatibility, as getAsset is part of the public API.
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
|
|
310
|
-
throw new Error(
|
|
311
|
-
`'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
|
|
312
|
-
);
|
|
313
|
-
}
|
|
302
|
+
if (
|
|
303
|
+
fileExistsInFileMap == null &&
|
|
304
|
+
!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])
|
|
305
|
+
) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
|
|
308
|
+
);
|
|
314
309
|
}
|
|
315
310
|
|
|
316
311
|
const record = await getAbsoluteAssetRecord(absolutePath, platform ?? null);
|
|
317
312
|
|
|
318
313
|
for (let i = 0; i < record.scales.length; i++) {
|
|
319
314
|
if (record.scales[i] >= assetData.resolution) {
|
|
315
|
+
if (
|
|
316
|
+
fileExistsInFileMap != null &&
|
|
317
|
+
!fileExistsInFileMap(record.files[i])
|
|
318
|
+
) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
320
321
|
return fs.promises.readFile(record.files[i]);
|
|
321
322
|
}
|
|
322
323
|
}
|
|
323
324
|
|
|
324
|
-
|
|
325
|
+
const lastFile = record.files[record.files.length - 1];
|
|
326
|
+
if (fileExistsInFileMap != null && !fileExistsInFileMap(lastFile)) {
|
|
327
|
+
throw new Error(
|
|
328
|
+
`'${relativePath}' could not be found, because it is not within the projectRoot or watchFolders, or it is blocked via the resolver.blockList config`,
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
return fs.promises.readFile(lastFile);
|
|
325
332
|
}
|
|
326
333
|
|
|
327
334
|
function pathBelongsToRoots(
|
package/src/Bundler/util.d.ts
CHANGED
|
@@ -4,8 +4,15 @@
|
|
|
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
|
-
* @
|
|
7
|
+
* @noformat
|
|
8
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)
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
import type {AssetDataWithoutFiles} from '../Assets';
|
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
CHANGED
|
@@ -4,8 +4,15 @@
|
|
|
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
|
-
* @
|
|
7
|
+
* @noformat
|
|
8
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)
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
import type {TransformResultWithSource} from './DeltaBundler';
|
|
@@ -4,12 +4,18 @@
|
|
|
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
|
-
* @
|
|
7
|
+
* @noformat
|
|
8
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)
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
import type {DeltaResult, Options} from './types';
|
|
12
|
-
import type {RootPerfLogger} from 'metro-config';
|
|
13
19
|
import type {ChangeEvent} from 'metro-file-map';
|
|
14
20
|
|
|
15
21
|
import {Graph} from './Graph';
|
|
@@ -53,15 +59,6 @@ declare class DeltaCalculator<T> extends EventEmitter {
|
|
|
53
59
|
*/
|
|
54
60
|
getGraph(): Graph<T>;
|
|
55
61
|
_handleMultipleFileChanges: (changeEvent: ChangeEvent) => void;
|
|
56
|
-
/**
|
|
57
|
-
* Handles a single file change. To avoid doing any work before it's needed,
|
|
58
|
-
* the listener only stores the modified file, which will then be used later
|
|
59
|
-
* when the delta needs to be calculated.
|
|
60
|
-
*/
|
|
61
|
-
_handleFileChange: (
|
|
62
|
-
$$PARAM_0$$: ChangeEvent['eventsQueue'][number],
|
|
63
|
-
logger: null | undefined | RootPerfLogger,
|
|
64
|
-
) => unknown;
|
|
65
62
|
_getChangedDependencies(
|
|
66
63
|
modifiedFiles: Set<string>,
|
|
67
64
|
deletedFiles: Set<string>,
|
|
@@ -5,12 +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
12
|
return e && e.__esModule ? e : { default: e };
|
|
12
13
|
}
|
|
13
14
|
const debug = require("debug")("Metro:DeltaCalculator");
|
|
15
|
+
const changeEventIds = new WeakMap();
|
|
14
16
|
class DeltaCalculator extends _events.default {
|
|
15
17
|
_deletedFiles = new Set();
|
|
16
18
|
_modifiedFiles = new Set();
|
|
@@ -94,60 +96,67 @@ class DeltaCalculator extends _events.default {
|
|
|
94
96
|
getGraph() {
|
|
95
97
|
return this._graph;
|
|
96
98
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
_handleFileChange = ({ type, filePath, metadata }, logger) => {
|
|
103
|
-
debug("Handling %s: %s (type: %s)", type, filePath, metadata.type);
|
|
99
|
+
#shouldReset(canonicalPath, metadata) {
|
|
100
|
+
if (metadata.isSymlink) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
104
103
|
if (
|
|
105
|
-
|
|
106
|
-
(
|
|
107
|
-
|
|
104
|
+
this._options.unstable_enablePackageExports &&
|
|
105
|
+
(canonicalPath === "package.json" ||
|
|
106
|
+
canonicalPath.endsWith(_path.default.sep + "package.json"))
|
|
108
107
|
) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
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
|
+
}
|
|
113
127
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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);
|
|
121
138
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
}
|
|
129
151
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this._addedFiles.delete(filePath);
|
|
135
|
-
break;
|
|
136
|
-
case "added":
|
|
137
|
-
this._addedFiles.add(filePath);
|
|
138
|
-
this._deletedFiles.delete(filePath);
|
|
139
|
-
this._modifiedFiles.delete(filePath);
|
|
140
|
-
break;
|
|
141
|
-
case "modified":
|
|
142
|
-
this._modifiedFiles.add(filePath);
|
|
143
|
-
this._deletedFiles.delete(filePath);
|
|
144
|
-
this._addedFiles.delete(filePath);
|
|
145
|
-
break;
|
|
146
|
-
default:
|
|
147
|
-
nextState;
|
|
152
|
+
let changeId = changeEventIds.get(changeEvent);
|
|
153
|
+
if (changeId == null) {
|
|
154
|
+
changeId = _crypto.default.randomUUID();
|
|
155
|
+
changeEventIds.set(changeEvent, changeId);
|
|
148
156
|
}
|
|
149
157
|
this.emit("change", {
|
|
150
158
|
logger,
|
|
159
|
+
changeId,
|
|
151
160
|
});
|
|
152
161
|
};
|
|
153
162
|
async _getChangedDependencies(modifiedFiles, deletedFiles, addedFiles) {
|
|
@@ -10,16 +10,24 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type {DeltaResult, Options} from './types';
|
|
13
|
-
import type {RootPerfLogger} from 'metro-config';
|
|
14
13
|
import type {ChangeEvent} from 'metro-file-map';
|
|
15
14
|
|
|
16
15
|
import {Graph} from './Graph';
|
|
16
|
+
import crypto from 'crypto';
|
|
17
17
|
import EventEmitter from 'events';
|
|
18
18
|
import path from 'path';
|
|
19
19
|
|
|
20
20
|
// eslint-disable-next-line import/no-commonjs
|
|
21
21
|
const debug = require('debug')('Metro:DeltaCalculator');
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Assigns a unique, stable `changeId` to each `ChangeEvent` from the file
|
|
25
|
+
* watcher. Since all `DeltaCalculator` instances share the same
|
|
26
|
+
* `ChangeEvent` object reference per file system change, the `WeakMap`
|
|
27
|
+
* ensures each gets the same `changeId`.
|
|
28
|
+
*/
|
|
29
|
+
const changeEventIds: WeakMap<ChangeEvent, string> = new WeakMap();
|
|
30
|
+
|
|
23
31
|
/**
|
|
24
32
|
* This class is in charge of calculating the delta of changed modules that
|
|
25
33
|
* happen between calls. To do so, it subscribes to file changes, so it can
|
|
@@ -172,76 +180,79 @@ export default class DeltaCalculator<T> extends EventEmitter {
|
|
|
172
180
|
return this._graph;
|
|
173
181
|
}
|
|
174
182
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
#shouldReset(
|
|
184
|
+
canonicalPath: string,
|
|
185
|
+
metadata: {+isSymlink: boolean, ...},
|
|
186
|
+
): boolean {
|
|
187
|
+
if (metadata.isSymlink) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
180
190
|
|
|
181
|
-
/**
|
|
182
|
-
* Handles a single file change. To avoid doing any work before it's needed,
|
|
183
|
-
* the listener only stores the modified file, which will then be used later
|
|
184
|
-
* when the delta needs to be calculated.
|
|
185
|
-
*/
|
|
186
|
-
_handleFileChange = (
|
|
187
|
-
{type, filePath, metadata}: ChangeEvent['eventsQueue'][number],
|
|
188
|
-
logger: ?RootPerfLogger,
|
|
189
|
-
): unknown => {
|
|
190
|
-
debug('Handling %s: %s (type: %s)', type, filePath, metadata.type);
|
|
191
191
|
if (
|
|
192
|
-
|
|
193
|
-
(
|
|
194
|
-
|
|
192
|
+
this._options.unstable_enablePackageExports &&
|
|
193
|
+
(canonicalPath === 'package.json' ||
|
|
194
|
+
canonicalPath.endsWith(path.sep + 'package.json'))
|
|
195
195
|
) {
|
|
196
|
-
|
|
197
|
-
this.emit('change', {logger});
|
|
196
|
+
return true;
|
|
198
197
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
198
|
+
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
_handleMultipleFileChanges = (changeEvent: ChangeEvent) => {
|
|
203
|
+
const {changes, logger, rootDir} = changeEvent;
|
|
204
|
+
|
|
205
|
+
// Process added files: deleted+added = modified, otherwise added
|
|
206
|
+
for (const [canonicalPath, metadata] of changes.addedFiles) {
|
|
207
|
+
debug('Handling add: %s', canonicalPath);
|
|
208
|
+
if (this.#shouldReset(canonicalPath, metadata)) {
|
|
209
|
+
this._requiresReset = true;
|
|
210
|
+
}
|
|
211
|
+
const absolutePath = path.join(rootDir, canonicalPath);
|
|
212
|
+
if (this._deletedFiles.has(absolutePath)) {
|
|
213
|
+
this._deletedFiles.delete(absolutePath);
|
|
214
|
+
this._modifiedFiles.add(absolutePath);
|
|
215
|
+
} else {
|
|
216
|
+
this._addedFiles.add(absolutePath);
|
|
217
|
+
this._modifiedFiles.delete(absolutePath);
|
|
218
|
+
}
|
|
206
219
|
}
|
|
207
220
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
221
|
+
// Process modified files: added+modified stays added, otherwise modified
|
|
222
|
+
for (const [canonicalPath, metadata] of changes.modifiedFiles) {
|
|
223
|
+
debug('Handling change: %s', canonicalPath);
|
|
224
|
+
if (this.#shouldReset(canonicalPath, metadata)) {
|
|
225
|
+
this._requiresReset = true;
|
|
226
|
+
}
|
|
227
|
+
const absolutePath = path.join(rootDir, canonicalPath);
|
|
228
|
+
if (!this._addedFiles.has(absolutePath)) {
|
|
229
|
+
this._modifiedFiles.add(absolutePath);
|
|
230
|
+
}
|
|
231
|
+
this._deletedFiles.delete(absolutePath);
|
|
218
232
|
}
|
|
219
233
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
this.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
this._deletedFiles.delete(filePath);
|
|
234
|
-
this._addedFiles.delete(filePath);
|
|
235
|
-
break;
|
|
236
|
-
default:
|
|
237
|
-
nextState as empty;
|
|
234
|
+
// Process removed files: added+deleted = no change, otherwise deleted
|
|
235
|
+
for (const [canonicalPath, metadata] of changes.removedFiles) {
|
|
236
|
+
debug('Handling delete: %s', canonicalPath);
|
|
237
|
+
if (this.#shouldReset(canonicalPath, metadata)) {
|
|
238
|
+
this._requiresReset = true;
|
|
239
|
+
}
|
|
240
|
+
const absolutePath = path.resolve(rootDir, canonicalPath);
|
|
241
|
+
if (this._addedFiles.has(absolutePath)) {
|
|
242
|
+
this._addedFiles.delete(absolutePath);
|
|
243
|
+
} else {
|
|
244
|
+
this._deletedFiles.add(absolutePath);
|
|
245
|
+
this._modifiedFiles.delete(absolutePath);
|
|
246
|
+
}
|
|
238
247
|
}
|
|
239
248
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
249
|
+
let changeId = changeEventIds.get(changeEvent);
|
|
250
|
+
if (changeId == null) {
|
|
251
|
+
changeId = crypto.randomUUID();
|
|
252
|
+
changeEventIds.set(changeEvent, changeId);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
this.emit('change', {logger, changeId});
|
|
245
256
|
};
|
|
246
257
|
|
|
247
258
|
async _getChangedDependencies(
|
|
@@ -4,8 +4,15 @@
|
|
|
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
|
-
* @
|
|
7
|
+
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<2af7aa3b61c2afa4d8794e127666c226>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/Graph.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
/**
|
|
@@ -4,8 +4,15 @@
|
|
|
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
|
-
* @
|
|
7
|
+
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<e21aeb433f191f32b37d05733b0b76bd>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/Serializers/baseJSBundle.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
import type {Module, ReadOnlyGraph, SerializerOptions} from '../types';
|
|
@@ -4,8 +4,15 @@
|
|
|
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
|
-
* @
|
|
7
|
+
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<1d044a890d1eebbef947f78609d7c58f>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/Serializers/getAllFiles.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
import type {Module, ReadOnlyGraph} from '../types';
|
|
@@ -4,8 +4,15 @@
|
|
|
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
|
-
* @
|
|
7
|
+
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<0a49d828c4a80d52ccab4d4766b84c86>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/DeltaBundler/Serializers/getAssets.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
import type {AssetData} from '../../Assets';
|