metro 0.65.2 → 0.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +27 -27
- package/src/Assets.js +9 -9
- package/src/Assets.js.flow +5 -7
- package/src/Bundler/util.js +17 -15
- package/src/Bundler/util.js.flow +12 -10
- package/src/Bundler.js +22 -9
- package/src/Bundler.js.flow +20 -7
- package/src/DeltaBundler/DeltaCalculator.js +17 -15
- package/src/DeltaBundler/DeltaCalculator.js.flow +9 -7
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +13 -13
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +6 -7
- package/src/DeltaBundler/Serializers/baseJSBundle.js +4 -4
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +4 -4
- package/src/DeltaBundler/Serializers/getAllFiles.js +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +3 -3
- package/src/DeltaBundler/Serializers/getAssets.js +3 -3
- package/src/DeltaBundler/Serializers/getAssets.js.flow +4 -5
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +4 -4
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +4 -4
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +20 -20
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +9 -10
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +11 -11
- package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +5 -6
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +1 -1
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -1
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +2 -2
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +4 -4
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +1 -1
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +1 -1
- package/src/DeltaBundler/Serializers/helpers/js.js +18 -8
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +19 -10
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +4 -4
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/helpers/processModules.js +4 -4
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +9 -9
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +9 -8
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +6 -6
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +3 -4
- package/src/DeltaBundler/Serializers/sourceMapObject.js +5 -5
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -4
- package/src/DeltaBundler/Serializers/sourceMapString.js +2 -2
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +3 -3
- package/src/DeltaBundler/Transformer.js +16 -14
- package/src/DeltaBundler/Transformer.js.flow +15 -15
- package/src/DeltaBundler/Worker.js +8 -11
- package/src/DeltaBundler/Worker.js.flow +8 -11
- package/src/DeltaBundler/WorkerFarm.js +15 -18
- package/src/DeltaBundler/WorkerFarm.js.flow +9 -11
- package/src/DeltaBundler/__fixtures__/hasteImpl.js +2 -2
- package/src/DeltaBundler/computeDelta.js +2 -2
- package/src/DeltaBundler/computeDelta.js.flow +2 -2
- package/src/DeltaBundler/getTransformCacheKey.js +4 -4
- package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -6
- package/src/DeltaBundler/mergeDeltas.js +2 -2
- package/src/DeltaBundler/mergeDeltas.js.flow +1 -1
- package/src/DeltaBundler/traverseDependencies.js +22 -22
- package/src/DeltaBundler/traverseDependencies.js.flow +3 -3
- package/src/DeltaBundler/types.flow.js +1 -1
- package/src/DeltaBundler/types.flow.js.flow +15 -1
- package/src/DeltaBundler.js +5 -5
- package/src/DeltaBundler.js.flow +4 -4
- package/src/HmrServer.js +73 -55
- package/src/HmrServer.js.flow +42 -37
- package/src/IncrementalBundler/GraphNotFoundError.js +1 -1
- package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -1
- package/src/IncrementalBundler/ResourceNotFoundError.js +1 -1
- package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -1
- package/src/IncrementalBundler/RevisionNotFoundError.js +1 -1
- package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -1
- package/src/IncrementalBundler.js +46 -32
- package/src/IncrementalBundler.js.flow +32 -24
- package/src/ModuleGraph/module.js +3 -3
- package/src/ModuleGraph/module.js.flow +1 -1
- package/src/ModuleGraph/node-haste/HasteFS.js +5 -3
- package/src/ModuleGraph/node-haste/HasteFS.js.flow +3 -1
- package/src/ModuleGraph/node-haste/Module.js +1 -1
- package/src/ModuleGraph/node-haste/Module.js.flow +1 -1
- package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
- package/src/ModuleGraph/node-haste/ModuleCache.js.flow +3 -3
- package/src/ModuleGraph/node-haste/Package.js +3 -3
- package/src/ModuleGraph/node-haste/Package.js.flow +3 -3
- package/src/ModuleGraph/node-haste/node-haste.flow.js +1 -1
- package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +1 -1
- package/src/ModuleGraph/node-haste/node-haste.js +41 -31
- package/src/ModuleGraph/node-haste/node-haste.js.flow +28 -22
- package/src/ModuleGraph/output/indexed-ram-bundle.js +17 -17
- package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +41 -9
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js +18 -18
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +21 -9
- package/src/ModuleGraph/output/plain-bundle.js +6 -6
- package/src/ModuleGraph/output/plain-bundle.js.flow +7 -7
- package/src/ModuleGraph/output/reverse-dependency-map-references.js +3 -3
- package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +4 -8
- package/src/ModuleGraph/output/util.js +61 -40
- package/src/ModuleGraph/output/util.js.flow +51 -28
- package/src/ModuleGraph/silent-console.js +2 -2
- package/src/ModuleGraph/silent-console.js.flow +1 -1
- package/src/ModuleGraph/test-helpers.js +7 -7
- package/src/ModuleGraph/types.flow.js +1 -1
- package/src/ModuleGraph/types.flow.js.flow +47 -31
- package/src/ModuleGraph/worker/JsFileWrapping.js +16 -16
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +3 -2
- package/src/ModuleGraph/worker/Platforms.js +2 -2
- package/src/ModuleGraph/worker/Platforms.js.flow +1 -1
- package/src/ModuleGraph/worker/collectDependencies.js +24 -25
- package/src/ModuleGraph/worker/collectDependencies.js.flow +16 -18
- package/src/ModuleGraph/worker/generate.js +2 -2
- package/src/ModuleGraph/worker/generate.js.flow +3 -3
- package/src/ModuleGraph/worker/generateImportNames.js +5 -5
- package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -5
- package/src/ModuleGraph/worker/mergeSourceMaps.js +8 -7
- package/src/ModuleGraph/worker/mergeSourceMaps.js.flow +3 -3
- package/src/Server/MultipartResponse.js +4 -8
- package/src/Server/symbolicate.js +8 -8
- package/src/Server/symbolicate.js.flow +17 -5
- package/src/Server.js +204 -150
- package/src/Server.js.flow +131 -87
- package/src/cli-utils.js +4 -4
- package/src/cli-utils.js.flow +15 -13
- package/src/cli.js +4 -4
- package/src/cli.js.flow +2 -4
- package/src/commands/build.js +23 -24
- package/src/commands/build.js.flow +6 -9
- package/src/commands/dependencies.js +25 -19
- package/src/commands/serve.js +19 -19
- package/src/commands/serve.js.flow +7 -9
- package/src/index.js +117 -50
- package/src/index.js.flow +108 -40
- package/src/integration_tests/basic_bundle/AssetRegistry.js +2 -2
- package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
- package/src/integration_tests/basic_bundle/Bar.js +2 -2
- package/src/integration_tests/basic_bundle/Bar.js.flow +1 -1
- package/src/integration_tests/basic_bundle/ErrorBundle.js +2 -2
- package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
- package/src/integration_tests/basic_bundle/Foo.js +2 -2
- package/src/integration_tests/basic_bundle/Foo.js.flow +1 -1
- package/src/integration_tests/basic_bundle/TestBundle.js +2 -2
- package/src/integration_tests/basic_bundle/TestBundle.js.flow +1 -1
- package/src/integration_tests/basic_bundle/TestPolyfill.js +1 -1
- package/src/integration_tests/basic_bundle/TestPolyfill.js.flow +1 -1
- package/src/integration_tests/basic_bundle/TypeScript.ts +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-1.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-1.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-2.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-2.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-3.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-3.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-4.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-4.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-5.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-5.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-6.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-6.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-null.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-null.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/index.js +17 -17
- package/src/integration_tests/basic_bundle/import-export/index.js.flow +1 -1
- package/src/integration_tests/basic_bundle/polyfill.js +1 -1
- package/src/integration_tests/execBundle.js +2 -2
- package/src/integration_tests/execBundle.js.flow +1 -1
- package/src/integration_tests/metro.config.js +8 -8
- package/src/lib/BatchProcessor.js +10 -6
- package/src/lib/BatchProcessor.js.flow +6 -1
- package/src/lib/JsonReporter.js +3 -2
- package/src/lib/JsonReporter.js.flow +2 -1
- package/src/lib/RamBundleParser.js +1 -1
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.js +15 -15
- package/src/lib/TerminalReporter.js.flow +15 -16
- package/src/lib/bundleToBytecode.js +6 -7
- package/src/lib/bundleToBytecode.js.flow +8 -7
- package/src/lib/bundleToString.js +3 -3
- package/src/lib/bundleToString.js.flow +5 -4
- package/src/lib/countLines.js +3 -7
- package/src/lib/countLines.js.flow +4 -7
- package/src/lib/createModuleIdFactory.js +2 -2
- package/src/lib/createModuleIdFactory.js.flow +1 -1
- package/src/lib/{attachWebsocketServer.js → createWebsocketServer.js} +18 -17
- package/src/lib/{attachWebsocketServer.js.flow → createWebsocketServer.js.flow} +13 -23
- package/src/lib/debounceAsyncQueue.js +2 -2
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.js +21 -21
- package/src/lib/formatBundlingError.js.flow +18 -20
- package/src/lib/getAppendScripts.js +26 -27
- package/src/lib/getAppendScripts.js.flow +7 -8
- package/src/lib/getGraphId.js +3 -3
- package/src/lib/getGraphId.js.flow +3 -3
- package/src/lib/getMaxWorkers.js +2 -2
- package/src/lib/getMaxWorkers.js.flow +1 -1
- package/src/lib/getPreludeCode.js +2 -2
- package/src/lib/getPreludeCode.js.flow +1 -1
- package/src/lib/getPrependedScripts.js +16 -15
- package/src/lib/getPrependedScripts.js.flow +8 -8
- package/src/lib/logToConsole.js +12 -5
- package/src/lib/logToConsole.js.flow +19 -6
- package/src/lib/parseCustomTransformOptions.js +2 -2
- package/src/lib/parseCustomTransformOptions.js.flow +3 -3
- package/src/lib/parseOptionsFromUrl.js +7 -7
- package/src/lib/parseOptionsFromUrl.js.flow +29 -9
- package/src/lib/relativizeSourceMap.js +1 -1
- package/src/lib/relativizeSourceMap.js.flow +3 -3
- package/src/lib/reporting.js +5 -5
- package/src/lib/reporting.js.flow +18 -4
- package/src/lib/splitBundleOptions.js +5 -5
- package/src/lib/splitBundleOptions.js.flow +1 -1
- package/src/lib/transformHelpers.js +11 -10
- package/src/lib/transformHelpers.js.flow +6 -13
- package/src/node-haste/DependencyGraph/ModuleResolution.js +51 -30
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +49 -48
- package/src/node-haste/DependencyGraph/createHasteMap.js +99 -0
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +88 -0
- package/src/node-haste/DependencyGraph/{assets/empty-module.js → types.js} +2 -2
- package/src/node-haste/DependencyGraph/types.js.flow +88 -0
- package/src/node-haste/DependencyGraph.js +51 -118
- package/src/node-haste/DependencyGraph.js.flow +38 -111
- package/src/node-haste/Module.js +1 -1
- package/src/node-haste/Module.js.flow +3 -3
- package/src/node-haste/ModuleCache.js +54 -13
- package/src/node-haste/ModuleCache.js.flow +53 -12
- package/src/node-haste/Package.js +2 -2
- package/src/node-haste/Package.js.flow +1 -1
- package/src/node-haste/lib/AssetPaths.js +5 -5
- package/src/node-haste/lib/AssetPaths.js.flow +7 -6
- package/src/node-haste/lib/parsePlatformFilePath.js +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -2
- package/src/shared/output/RamBundle/as-assets.js +14 -15
- package/src/shared/output/RamBundle/as-assets.js.flow +9 -11
- package/src/shared/output/RamBundle/as-indexed-file.js +14 -15
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +8 -12
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +7 -7
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -4
- package/src/shared/output/RamBundle/magic-number.js +1 -1
- package/src/shared/output/RamBundle/magic-number.js.flow +1 -1
- package/src/shared/output/RamBundle/util.js +21 -19
- package/src/shared/output/RamBundle/util.js.flow +5 -8
- package/src/shared/output/RamBundle/write-sourcemap.js +1 -1
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.js +2 -2
- package/src/shared/output/RamBundle.js.flow +4 -5
- package/src/shared/output/bundle.js +6 -6
- package/src/shared/output/bundle.js.flow +4 -5
- package/src/shared/output/meta.js +4 -5
- package/src/shared/output/meta.js.flow +2 -4
- package/src/shared/output/unbundle.js +1 -1
- package/src/shared/output/unbundle.js.flow +1 -1
- package/src/shared/output/writeFile.js +1 -1
- package/src/shared/output/writeFile.js.flow +1 -1
- package/src/shared/types.flow.js +1 -1
- package/src/shared/types.flow.js.flow +6 -4
- package/src/node-haste/DependencyGraph/assets/empty-module.js.flow +0 -9
- package/src/node-haste/types.js +0 -10
- package/src/node-haste/types.js.flow +0 -23
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -9,23 +9,53 @@
|
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const { codeFrameColumns } = require("@babel/code-frame");
|
|
13
13
|
|
|
14
14
|
const fs = require("fs");
|
|
15
15
|
|
|
16
16
|
const invariant = require("invariant");
|
|
17
17
|
|
|
18
|
+
const Resolver = require("metro-resolver");
|
|
19
|
+
|
|
18
20
|
const path = require("path");
|
|
19
21
|
|
|
20
22
|
const util = require("util");
|
|
21
23
|
|
|
22
|
-
const { codeFrameColumns } = require("@babel/code-frame");
|
|
23
|
-
|
|
24
24
|
class ModuleResolver {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// A module representing the project root, used as the origin when resolving `emptyModulePath`.
|
|
26
|
+
// An empty module, the result of resolving `emptyModulePath` from the project root.
|
|
27
27
|
constructor(options) {
|
|
28
28
|
this._options = options;
|
|
29
|
+
const { projectRoot, moduleCache } = this._options;
|
|
30
|
+
this._projectRootFakeModule = {
|
|
31
|
+
path: path.join(projectRoot, "_"),
|
|
32
|
+
getPackage: () =>
|
|
33
|
+
moduleCache.getPackageOf(this._projectRootFakeModule.path),
|
|
34
|
+
|
|
35
|
+
isHaste() {
|
|
36
|
+
throw new Error("not implemented");
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
getName() {
|
|
40
|
+
throw new Error("not implemented");
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_getEmptyModule() {
|
|
46
|
+
let emptyModule = this._cachedEmptyModule;
|
|
47
|
+
|
|
48
|
+
if (!emptyModule) {
|
|
49
|
+
emptyModule = this.resolveDependency(
|
|
50
|
+
this._projectRootFakeModule,
|
|
51
|
+
this._options.emptyModulePath,
|
|
52
|
+
false,
|
|
53
|
+
null
|
|
54
|
+
);
|
|
55
|
+
this._cachedEmptyModule = emptyModule;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return emptyModule;
|
|
29
59
|
}
|
|
30
60
|
|
|
31
61
|
_redirectRequire(fromModule, modulePath) {
|
|
@@ -51,7 +81,6 @@ class ModuleResolver {
|
|
|
51
81
|
); // Since the redirected path is still relative to the package root,
|
|
52
82
|
// we have to transform it back to be module-relative (as it
|
|
53
83
|
// originally was)
|
|
54
|
-
// $FlowFixMe[incompatible-type]
|
|
55
84
|
|
|
56
85
|
if (redirectedPath !== false) {
|
|
57
86
|
redirectedPath =
|
|
@@ -66,7 +95,7 @@ class ModuleResolver {
|
|
|
66
95
|
}
|
|
67
96
|
} else {
|
|
68
97
|
const pck = path.isAbsolute(modulePath)
|
|
69
|
-
? moduleCache.
|
|
98
|
+
? moduleCache.getPackageOf(modulePath)
|
|
70
99
|
: fromModule.getPackage();
|
|
71
100
|
|
|
72
101
|
if (pck) {
|
|
@@ -87,15 +116,15 @@ class ModuleResolver {
|
|
|
87
116
|
{
|
|
88
117
|
...this._options,
|
|
89
118
|
originModulePath: fromModule.path,
|
|
90
|
-
redirectModulePath: modulePath =>
|
|
119
|
+
redirectModulePath: (modulePath) =>
|
|
91
120
|
this._redirectRequire(fromModule, modulePath),
|
|
92
121
|
allowHaste,
|
|
93
122
|
platform,
|
|
94
|
-
resolveHasteModule: name =>
|
|
123
|
+
resolveHasteModule: (name) =>
|
|
95
124
|
this._options.moduleMap.getModule(name, platform, true),
|
|
96
|
-
resolveHastePackage: name =>
|
|
125
|
+
resolveHastePackage: (name) =>
|
|
97
126
|
this._options.moduleMap.getPackage(name, platform, true),
|
|
98
|
-
getPackageMainPath: this._getPackageMainPath
|
|
127
|
+
getPackageMainPath: this._getPackageMainPath,
|
|
99
128
|
},
|
|
100
129
|
moduleName,
|
|
101
130
|
platform
|
|
@@ -114,7 +143,7 @@ class ModuleResolver {
|
|
|
114
143
|
)}`,
|
|
115
144
|
` * ${Resolver.formatFileCandidates(
|
|
116
145
|
this._removeRoot(candidates.dir)
|
|
117
|
-
)}
|
|
146
|
+
)}`,
|
|
118
147
|
].join("\n")
|
|
119
148
|
);
|
|
120
149
|
}
|
|
@@ -122,8 +151,8 @@ class ModuleResolver {
|
|
|
122
151
|
if (error instanceof Resolver.FailedToResolveNameError) {
|
|
123
152
|
const { dirPaths, extraPaths } = error;
|
|
124
153
|
const displayDirPaths = dirPaths
|
|
125
|
-
.filter(dirPath => this._options.dirExists(dirPath))
|
|
126
|
-
.map(dirPath => path.relative(this._options.projectRoot, dirPath))
|
|
154
|
+
.filter((dirPath) => this._options.dirExists(dirPath))
|
|
155
|
+
.map((dirPath) => path.relative(this._options.projectRoot, dirPath))
|
|
127
156
|
.concat(extraPaths);
|
|
128
157
|
const hint = displayDirPaths.length ? " or in these directories:" : "";
|
|
129
158
|
throw new UnableToResolveError(
|
|
@@ -131,12 +160,7 @@ class ModuleResolver {
|
|
|
131
160
|
moduleName,
|
|
132
161
|
[
|
|
133
162
|
`${moduleName} could not be found within the project${hint || "."}`,
|
|
134
|
-
...displayDirPaths.map(dirPath => ` ${dirPath}`),
|
|
135
|
-
"\nIf you are sure the module exists, try these steps:",
|
|
136
|
-
" 1. Clear watchman watches: watchman watch-del-all",
|
|
137
|
-
" 2. Delete node_modules and run yarn install",
|
|
138
|
-
" 3. Reset Metro's cache: yarn start --reset-cache",
|
|
139
|
-
" 4. Remove the cache: rm -rf /tmp/metro-*"
|
|
163
|
+
...displayDirPaths.map((dirPath) => ` ${dirPath}`),
|
|
140
164
|
].join("\n")
|
|
141
165
|
);
|
|
142
166
|
}
|
|
@@ -145,7 +169,7 @@ class ModuleResolver {
|
|
|
145
169
|
}
|
|
146
170
|
}
|
|
147
171
|
|
|
148
|
-
_getPackageMainPath = packageJsonPath => {
|
|
172
|
+
_getPackageMainPath = (packageJsonPath) => {
|
|
149
173
|
const package_ = this._options.moduleCache.getPackage(packageJsonPath);
|
|
150
174
|
|
|
151
175
|
return package_.getMain(this._options.mainFields);
|
|
@@ -168,10 +192,7 @@ class ModuleResolver {
|
|
|
168
192
|
return this._options.moduleCache.getModule(arbitrary);
|
|
169
193
|
|
|
170
194
|
case "empty":
|
|
171
|
-
|
|
172
|
-
const module_ = moduleCache.getModule(ModuleResolver.EMPTY_MODULE);
|
|
173
|
-
invariant(module_ != null, "empty module is not available");
|
|
174
|
-
return module_;
|
|
195
|
+
return this._getEmptyModule();
|
|
175
196
|
|
|
176
197
|
default:
|
|
177
198
|
resolution.type;
|
|
@@ -266,11 +287,11 @@ class UnableToResolveError extends Error {
|
|
|
266
287
|
{
|
|
267
288
|
start: {
|
|
268
289
|
column: column + 1,
|
|
269
|
-
line: lineNumber + 1
|
|
270
|
-
}
|
|
290
|
+
line: lineNumber + 1,
|
|
291
|
+
},
|
|
271
292
|
},
|
|
272
293
|
{
|
|
273
|
-
forceColor: process.env.NODE_ENV !== "test"
|
|
294
|
+
forceColor: process.env.NODE_ENV !== "test",
|
|
274
295
|
}
|
|
275
296
|
);
|
|
276
297
|
}
|
|
@@ -278,5 +299,5 @@ class UnableToResolveError extends Error {
|
|
|
278
299
|
|
|
279
300
|
module.exports = {
|
|
280
301
|
ModuleResolver,
|
|
281
|
-
UnableToResolveError
|
|
302
|
+
UnableToResolveError,
|
|
282
303
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -10,15 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const fs = require('fs');
|
|
16
|
-
const invariant = require('invariant');
|
|
17
|
-
const path = require('path');
|
|
18
|
-
const util = require('util');
|
|
19
|
-
|
|
20
|
-
const {codeFrameColumns} = require('@babel/code-frame');
|
|
21
|
-
|
|
13
|
+
import type {ModuleMap} from './types';
|
|
22
14
|
import type {
|
|
23
15
|
CustomResolver,
|
|
24
16
|
DoesFileExist,
|
|
@@ -28,54 +20,44 @@ import type {
|
|
|
28
20
|
ResolveAsset,
|
|
29
21
|
} from 'metro-resolver';
|
|
30
22
|
|
|
23
|
+
const {codeFrameColumns} = require('@babel/code-frame');
|
|
24
|
+
const fs = require('fs');
|
|
25
|
+
const invariant = require('invariant');
|
|
26
|
+
const Resolver = require('metro-resolver');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
const util = require('util');
|
|
29
|
+
|
|
31
30
|
export type DirExistsFn = (filePath: string) => boolean;
|
|
32
31
|
|
|
33
|
-
export type Packageish = {
|
|
32
|
+
export type Packageish = interface {
|
|
34
33
|
path: string,
|
|
35
34
|
redirectRequire(
|
|
36
35
|
toModuleName: string,
|
|
37
36
|
mainFields: $ReadOnlyArray<string>,
|
|
38
37
|
): string | false,
|
|
39
38
|
getMain(mainFields: $ReadOnlyArray<string>): string,
|
|
40
|
-
...
|
|
41
39
|
};
|
|
42
40
|
|
|
43
|
-
export type Moduleish = {
|
|
41
|
+
export type Moduleish = interface {
|
|
44
42
|
+path: string,
|
|
45
43
|
getPackage(): ?Packageish,
|
|
46
|
-
...
|
|
47
44
|
};
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
* `jest-haste-map`'s interface for ModuleMap.
|
|
51
|
-
*/
|
|
52
|
-
export type ModuleMap = {
|
|
53
|
-
getModule(
|
|
54
|
-
name: string,
|
|
55
|
-
platform: string | null,
|
|
56
|
-
supportsNativePlatform: ?boolean,
|
|
57
|
-
): ?string,
|
|
58
|
-
getPackage(
|
|
59
|
-
name: string,
|
|
60
|
-
platform: string | null,
|
|
61
|
-
supportsNativePlatform: ?boolean,
|
|
62
|
-
): ?string,
|
|
63
|
-
...
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export type ModuleishCache<TModule, TPackage> = {
|
|
46
|
+
export type ModuleishCache<TModule, TPackage> = interface {
|
|
67
47
|
getPackage(
|
|
68
48
|
name: string,
|
|
69
49
|
platform?: string,
|
|
70
50
|
supportsNativePlatform?: boolean,
|
|
71
51
|
): TPackage,
|
|
72
52
|
getModule(path: string): TModule,
|
|
73
|
-
|
|
53
|
+
getPackageOf(modulePath: string): ?TPackage,
|
|
74
54
|
};
|
|
75
55
|
|
|
76
56
|
type Options<TModule, TPackage> = {|
|
|
77
57
|
+dirExists: DirExistsFn,
|
|
58
|
+
+disableHierarchicalLookup: boolean,
|
|
78
59
|
+doesFileExist: DoesFileExist,
|
|
60
|
+
+emptyModulePath: string,
|
|
79
61
|
+extraNodeModules: ?Object,
|
|
80
62
|
+isAssetFile: IsAssetFile,
|
|
81
63
|
+mainFields: $ReadOnlyArray<string>,
|
|
@@ -91,14 +73,42 @@ type Options<TModule, TPackage> = {|
|
|
|
91
73
|
|
|
92
74
|
class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
93
75
|
_options: Options<TModule, TPackage>;
|
|
94
|
-
|
|
95
|
-
|
|
76
|
+
// A module representing the project root, used as the origin when resolving `emptyModulePath`.
|
|
77
|
+
_projectRootFakeModule: Moduleish;
|
|
78
|
+
// An empty module, the result of resolving `emptyModulePath` from the project root.
|
|
79
|
+
_cachedEmptyModule: ?TModule;
|
|
96
80
|
|
|
97
81
|
constructor(options: Options<TModule, TPackage>) {
|
|
98
82
|
this._options = options;
|
|
83
|
+
const {projectRoot, moduleCache} = this._options;
|
|
84
|
+
this._projectRootFakeModule = {
|
|
85
|
+
path: path.join(projectRoot, '_'),
|
|
86
|
+
getPackage: () =>
|
|
87
|
+
moduleCache.getPackageOf(this._projectRootFakeModule.path),
|
|
88
|
+
isHaste() {
|
|
89
|
+
throw new Error('not implemented');
|
|
90
|
+
},
|
|
91
|
+
getName() {
|
|
92
|
+
throw new Error('not implemented');
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_getEmptyModule() {
|
|
98
|
+
let emptyModule = this._cachedEmptyModule;
|
|
99
|
+
if (!emptyModule) {
|
|
100
|
+
emptyModule = this.resolveDependency(
|
|
101
|
+
this._projectRootFakeModule,
|
|
102
|
+
this._options.emptyModulePath,
|
|
103
|
+
false,
|
|
104
|
+
null,
|
|
105
|
+
);
|
|
106
|
+
this._cachedEmptyModule = emptyModule;
|
|
107
|
+
}
|
|
108
|
+
return emptyModule;
|
|
99
109
|
}
|
|
100
110
|
|
|
101
|
-
_redirectRequire(fromModule:
|
|
111
|
+
_redirectRequire(fromModule: Moduleish, modulePath: string): string | false {
|
|
102
112
|
const moduleCache = this._options.moduleCache;
|
|
103
113
|
try {
|
|
104
114
|
if (modulePath.startsWith('.')) {
|
|
@@ -123,7 +133,6 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
|
123
133
|
// Since the redirected path is still relative to the package root,
|
|
124
134
|
// we have to transform it back to be module-relative (as it
|
|
125
135
|
// originally was)
|
|
126
|
-
// $FlowFixMe[incompatible-type]
|
|
127
136
|
if (redirectedPath !== false) {
|
|
128
137
|
redirectedPath =
|
|
129
138
|
'./' +
|
|
@@ -137,7 +146,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
|
137
146
|
}
|
|
138
147
|
} else {
|
|
139
148
|
const pck = path.isAbsolute(modulePath)
|
|
140
|
-
? moduleCache.
|
|
149
|
+
? moduleCache.getPackageOf(modulePath)
|
|
141
150
|
: fromModule.getPackage();
|
|
142
151
|
|
|
143
152
|
if (pck) {
|
|
@@ -153,7 +162,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
|
153
162
|
}
|
|
154
163
|
|
|
155
164
|
resolveDependency(
|
|
156
|
-
fromModule:
|
|
165
|
+
fromModule: Moduleish,
|
|
157
166
|
moduleName: string,
|
|
158
167
|
allowHaste: boolean,
|
|
159
168
|
platform: string | null,
|
|
@@ -217,11 +226,6 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
|
217
226
|
[
|
|
218
227
|
`${moduleName} could not be found within the project${hint || '.'}`,
|
|
219
228
|
...displayDirPaths.map((dirPath: string) => ` ${dirPath}`),
|
|
220
|
-
'\nIf you are sure the module exists, try these steps:',
|
|
221
|
-
' 1. Clear watchman watches: watchman watch-del-all',
|
|
222
|
-
' 2. Delete node_modules and run yarn install',
|
|
223
|
-
" 3. Reset Metro's cache: yarn start --reset-cache",
|
|
224
|
-
' 4. Remove the cache: rm -rf /tmp/metro-*',
|
|
225
229
|
].join('\n'),
|
|
226
230
|
);
|
|
227
231
|
}
|
|
@@ -249,10 +253,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
|
249
253
|
invariant(arbitrary != null, 'invalid asset resolution');
|
|
250
254
|
return this._options.moduleCache.getModule(arbitrary);
|
|
251
255
|
case 'empty':
|
|
252
|
-
|
|
253
|
-
const module_ = moduleCache.getModule(ModuleResolver.EMPTY_MODULE);
|
|
254
|
-
invariant(module_ != null, 'empty module is not available');
|
|
255
|
-
return module_;
|
|
256
|
+
return this._getEmptyModule();
|
|
256
257
|
default:
|
|
257
258
|
(resolution.type: empty);
|
|
258
259
|
throw new Error('invalid type');
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _jestHasteMap = _interopRequireDefault(require("jest-haste-map"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) {
|
|
6
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the MIT license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* @format
|
|
17
|
+
*/
|
|
18
|
+
// $FlowFixMe: Types for `jest-haste-map`
|
|
19
|
+
const ci = require("ci-info");
|
|
20
|
+
|
|
21
|
+
const path = require("path");
|
|
22
|
+
|
|
23
|
+
const JEST_HASTE_MAP_CACHE_BREAKER = 5;
|
|
24
|
+
|
|
25
|
+
function getIgnorePattern(config) {
|
|
26
|
+
// For now we support both options
|
|
27
|
+
const { blockList, blacklistRE } = config.resolver;
|
|
28
|
+
const ignorePattern = blacklistRE || blockList; // If neither option has been set, use default pattern
|
|
29
|
+
|
|
30
|
+
if (!ignorePattern) {
|
|
31
|
+
return / ^/;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const combine = (regexes) =>
|
|
35
|
+
new RegExp(
|
|
36
|
+
regexes
|
|
37
|
+
.map((regex) => "(" + regex.source.replace(/\//g, path.sep) + ")")
|
|
38
|
+
.join("|")
|
|
39
|
+
); // If ignorePattern is an array, merge it into one
|
|
40
|
+
|
|
41
|
+
if (Array.isArray(ignorePattern)) {
|
|
42
|
+
return combine(ignorePattern);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return ignorePattern;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function createHasteMap(config, options) {
|
|
49
|
+
var _options$name, _options$throwOnModul;
|
|
50
|
+
|
|
51
|
+
const dependencyExtractor =
|
|
52
|
+
(options === null || options === void 0
|
|
53
|
+
? void 0
|
|
54
|
+
: options.extractDependencies) === false
|
|
55
|
+
? null
|
|
56
|
+
: config.resolver.dependencyExtractor;
|
|
57
|
+
const computeDependencies = dependencyExtractor != null;
|
|
58
|
+
const hasteConfig = {
|
|
59
|
+
cacheDirectory: config.hasteMapCacheDirectory,
|
|
60
|
+
computeDependencies,
|
|
61
|
+
computeSha1: true,
|
|
62
|
+
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
63
|
+
extensions: config.resolver.sourceExts.concat(config.resolver.assetExts),
|
|
64
|
+
forceNodeFilesystemAPI: !config.resolver.useWatchman,
|
|
65
|
+
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
66
|
+
hasteMapModulePath: config.resolver.unstable_hasteMapModulePath,
|
|
67
|
+
ignorePattern: getIgnorePattern(config),
|
|
68
|
+
maxWorkers: config.maxWorkers,
|
|
69
|
+
mocksPattern: "",
|
|
70
|
+
name: `${
|
|
71
|
+
(_options$name =
|
|
72
|
+
options === null || options === void 0 ? void 0 : options.name) !==
|
|
73
|
+
null && _options$name !== void 0
|
|
74
|
+
? _options$name
|
|
75
|
+
: "metro"
|
|
76
|
+
}-${JEST_HASTE_MAP_CACHE_BREAKER}`,
|
|
77
|
+
platforms: config.resolver.platforms,
|
|
78
|
+
retainAllFiles: true,
|
|
79
|
+
resetCache: config.resetCache,
|
|
80
|
+
rootDir: config.projectRoot,
|
|
81
|
+
roots: config.watchFolders,
|
|
82
|
+
throwOnModuleCollision:
|
|
83
|
+
(_options$throwOnModul =
|
|
84
|
+
options === null || options === void 0
|
|
85
|
+
? void 0
|
|
86
|
+
: options.throwOnModuleCollision) !== null &&
|
|
87
|
+
_options$throwOnModul !== void 0
|
|
88
|
+
? _options$throwOnModul
|
|
89
|
+
: true,
|
|
90
|
+
useWatchman: config.resolver.useWatchman,
|
|
91
|
+
watch:
|
|
92
|
+
(options === null || options === void 0 ? void 0 : options.watch) == null
|
|
93
|
+
? !ci.isCI
|
|
94
|
+
: options.watch,
|
|
95
|
+
};
|
|
96
|
+
return _jestHasteMap.default.create(hasteConfig);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = createHasteMap;
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {HasteConfig, HasteMap} from './types';
|
|
12
|
+
import type {ConfigT} from 'metro-config/src/configTypes.flow';
|
|
13
|
+
|
|
14
|
+
// $FlowFixMe: Types for `jest-haste-map`
|
|
15
|
+
import JestHasteMap from 'jest-haste-map';
|
|
16
|
+
|
|
17
|
+
const ci = require('ci-info');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
const JEST_HASTE_MAP_CACHE_BREAKER = 5;
|
|
21
|
+
|
|
22
|
+
function getIgnorePattern(config: ConfigT): RegExp {
|
|
23
|
+
// For now we support both options
|
|
24
|
+
const {blockList, blacklistRE} = config.resolver;
|
|
25
|
+
const ignorePattern = blacklistRE || blockList;
|
|
26
|
+
|
|
27
|
+
// If neither option has been set, use default pattern
|
|
28
|
+
if (!ignorePattern) {
|
|
29
|
+
return / ^/;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const combine = regexes =>
|
|
33
|
+
new RegExp(
|
|
34
|
+
regexes
|
|
35
|
+
.map(regex => '(' + regex.source.replace(/\//g, path.sep) + ')')
|
|
36
|
+
.join('|'),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// If ignorePattern is an array, merge it into one
|
|
40
|
+
if (Array.isArray(ignorePattern)) {
|
|
41
|
+
return combine(ignorePattern);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return ignorePattern;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createHasteMap(
|
|
48
|
+
config: ConfigT,
|
|
49
|
+
options?: $ReadOnly<{
|
|
50
|
+
extractDependencies?: boolean,
|
|
51
|
+
watch?: boolean,
|
|
52
|
+
throwOnModuleCollision?: boolean,
|
|
53
|
+
name?: string,
|
|
54
|
+
}>,
|
|
55
|
+
): HasteMap {
|
|
56
|
+
const dependencyExtractor =
|
|
57
|
+
options?.extractDependencies === false
|
|
58
|
+
? null
|
|
59
|
+
: config.resolver.dependencyExtractor;
|
|
60
|
+
const computeDependencies = dependencyExtractor != null;
|
|
61
|
+
|
|
62
|
+
const hasteConfig: HasteConfig = {
|
|
63
|
+
cacheDirectory: config.hasteMapCacheDirectory,
|
|
64
|
+
computeDependencies,
|
|
65
|
+
computeSha1: true,
|
|
66
|
+
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
67
|
+
extensions: config.resolver.sourceExts.concat(config.resolver.assetExts),
|
|
68
|
+
forceNodeFilesystemAPI: !config.resolver.useWatchman,
|
|
69
|
+
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
70
|
+
hasteMapModulePath: config.resolver.unstable_hasteMapModulePath,
|
|
71
|
+
ignorePattern: getIgnorePattern(config),
|
|
72
|
+
maxWorkers: config.maxWorkers,
|
|
73
|
+
mocksPattern: '',
|
|
74
|
+
name: `${options?.name ?? 'metro'}-${JEST_HASTE_MAP_CACHE_BREAKER}`,
|
|
75
|
+
platforms: config.resolver.platforms,
|
|
76
|
+
retainAllFiles: true,
|
|
77
|
+
resetCache: config.resetCache,
|
|
78
|
+
rootDir: config.projectRoot,
|
|
79
|
+
roots: config.watchFolders,
|
|
80
|
+
throwOnModuleCollision: options?.throwOnModuleCollision ?? true,
|
|
81
|
+
useWatchman: config.resolver.useWatchman,
|
|
82
|
+
watch: options?.watch == null ? !ci.isCI : options.watch,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return JestHasteMap.create(hasteConfig);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = createHasteMap;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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
|
-
* @format
|
|
8
7
|
*
|
|
8
|
+
* @format
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
import type EventEmitter from 'events';
|
|
14
|
+
|
|
15
|
+
// TODO(cpojer): Create a jest-types repo.
|
|
16
|
+
export type HasteFS = {
|
|
17
|
+
exists(filePath: string): boolean,
|
|
18
|
+
getAllFiles(): Array<string>,
|
|
19
|
+
getDependencies(filePath: string): Array<string>,
|
|
20
|
+
getFileIterator(): Iterator<string>,
|
|
21
|
+
getModuleName(filePath: string): ?string,
|
|
22
|
+
getSha1(string): ?string,
|
|
23
|
+
matchFiles(pattern: RegExp | string): Array<string>,
|
|
24
|
+
...
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type HasteConfig = $ReadOnly<{
|
|
28
|
+
cacheDirectory?: ?string,
|
|
29
|
+
computeDependencies?: ?boolean,
|
|
30
|
+
computeSha1?: ?boolean,
|
|
31
|
+
dependencyExtractor?: ?string | null,
|
|
32
|
+
enableSymlinks?: ?boolean,
|
|
33
|
+
extensions: $ReadOnlyArray<string>,
|
|
34
|
+
forceNodeFilesystemAPI?: ?boolean,
|
|
35
|
+
hasteImplModulePath?: ?string,
|
|
36
|
+
hasteMapModulePath?: ?string,
|
|
37
|
+
ignorePattern?: ?RegExp | ((str: string) => boolean),
|
|
38
|
+
maxWorkers: number,
|
|
39
|
+
mocksPattern?: ?string,
|
|
40
|
+
name: string,
|
|
41
|
+
platforms: $ReadOnlyArray<string>,
|
|
42
|
+
resetCache?: ?boolean,
|
|
43
|
+
retainAllFiles: boolean,
|
|
44
|
+
rootDir: string,
|
|
45
|
+
roots: $ReadOnlyArray<string>,
|
|
46
|
+
skipPackageJson?: ?boolean,
|
|
47
|
+
throwOnModuleCollision?: ?boolean,
|
|
48
|
+
useWatchman?: ?boolean,
|
|
49
|
+
watch?: ?boolean,
|
|
50
|
+
...
|
|
51
|
+
}>;
|
|
52
|
+
|
|
53
|
+
type ModuleMapItem = {[platform: string]: ModuleMetaData};
|
|
54
|
+
type ModuleMetaData = [string, number];
|
|
55
|
+
type MockData = Map<string, string>;
|
|
56
|
+
type ModuleMapData = Map<string, ModuleMapItem>;
|
|
57
|
+
type DuplicatesSet = Map<string, number>;
|
|
58
|
+
type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;
|
|
59
|
+
|
|
60
|
+
type RawModuleMap = {
|
|
61
|
+
rootDir: string,
|
|
62
|
+
duplicates: DuplicatesIndex,
|
|
63
|
+
map: ModuleMapData,
|
|
64
|
+
mocks: MockData,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// `jest-haste-map`'s interface for ModuleMap.
|
|
68
|
+
export type ModuleMap = {
|
|
69
|
+
getModule(
|
|
70
|
+
name: string,
|
|
71
|
+
platform: string | null,
|
|
72
|
+
supportsNativePlatform: ?boolean,
|
|
73
|
+
): ?string,
|
|
74
|
+
getPackage(
|
|
75
|
+
name: string,
|
|
76
|
+
platform: string | null,
|
|
77
|
+
supportsNativePlatform: ?boolean,
|
|
78
|
+
): ?string,
|
|
79
|
+
getRawModuleMap(): RawModuleMap,
|
|
80
|
+
...
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Interface as used by node-haste / internal tools, satisfied by JestHasteMap
|
|
84
|
+
export interface HasteMap extends EventEmitter {
|
|
85
|
+
build: () => Promise<{hasteFS: HasteFS, moduleMap: ModuleMap}>;
|
|
86
|
+
end: () => void;
|
|
87
|
+
getCacheFilePath: () => string;
|
|
88
|
+
}
|