metro 0.83.0 → 0.83.2
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 +16 -16
- package/src/Assets.js +68 -42
- package/src/Assets.js.flow +13 -24
- package/src/Bundler/util.js +40 -17
- package/src/Bundler/util.js.flow +6 -13
- package/src/Bundler.js +17 -6
- package/src/Bundler.js.flow +3 -7
- package/src/DeltaBundler/DeltaCalculator.js +15 -15
- package/src/DeltaBundler/DeltaCalculator.js.flow +4 -7
- package/src/DeltaBundler/Graph.js +45 -40
- package/src/DeltaBundler/Graph.js.flow +3 -4
- package/src/DeltaBundler/Serializers/baseJSBundle.js +24 -10
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +6 -9
- package/src/DeltaBundler/Serializers/getAllFiles.js +9 -6
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +4 -8
- package/src/DeltaBundler/Serializers/getAssets.js +18 -11
- package/src/DeltaBundler/Serializers/getAssets.js.flow +5 -9
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +26 -0
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +7 -6
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +3 -9
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +40 -23
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +11 -18
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +4 -1
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -5
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +7 -4
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +3 -7
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +4 -1
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +2 -6
- package/src/DeltaBundler/Serializers/helpers/js.js +65 -31
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +21 -21
- package/src/DeltaBundler/Serializers/helpers/processModules.js +8 -5
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -7
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +70 -25
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +43 -33
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +19 -16
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -14
- package/src/DeltaBundler/Serializers/sourceMapObject.js +12 -10
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -9
- package/src/DeltaBundler/Serializers/sourceMapString.js +14 -12
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +4 -9
- package/src/DeltaBundler/Transformer.js +32 -27
- package/src/DeltaBundler/Transformer.js.flow +10 -17
- package/src/DeltaBundler/Worker.flow.js +25 -18
- package/src/DeltaBundler/Worker.flow.js.flow +12 -18
- package/src/DeltaBundler/Worker.js.flow +2 -0
- package/src/DeltaBundler/WorkerFarm.js +13 -11
- package/src/DeltaBundler/WorkerFarm.js.flow +7 -9
- package/src/DeltaBundler/buildSubgraph.js +13 -17
- package/src/DeltaBundler/buildSubgraph.js.flow +1 -1
- package/src/DeltaBundler/getTransformCacheKey.js +12 -6
- package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -7
- package/src/DeltaBundler/mergeDeltas.js +4 -1
- package/src/DeltaBundler/mergeDeltas.js.flow +5 -6
- package/src/DeltaBundler/types.d.ts +4 -1
- package/src/DeltaBundler/{types.flow.js → types.js} +1 -5
- package/src/DeltaBundler/{types.flow.js.flow → types.js.flow} +5 -3
- package/src/DeltaBundler.js +15 -6
- package/src/DeltaBundler.js.flow +4 -8
- package/src/HmrServer.js +116 -68
- package/src/HmrServer.js.flow +41 -52
- package/src/IncrementalBundler/GraphNotFoundError.js +5 -1
- package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler/ResourceNotFoundError.js +5 -1
- package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler/RevisionNotFoundError.js +5 -1
- package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler.js +71 -35
- package/src/IncrementalBundler.js.flow +12 -16
- package/src/ModuleGraph/test-helpers.js +19 -14
- package/src/ModuleGraph/worker/JsFileWrapping.js +22 -29
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +1 -10
- package/src/ModuleGraph/worker/collectDependencies.js +81 -52
- package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -22
- package/src/ModuleGraph/worker/generateImportNames.js +12 -6
- package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -7
- package/src/ModuleGraph/worker/importLocationsPlugin.js +5 -4
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +2 -4
- package/src/Server/MultipartResponse.js +11 -4
- package/src/Server/MultipartResponse.js.flow +2 -5
- package/src/Server/symbolicate.d.ts +31 -0
- package/src/Server/symbolicate.js +15 -16
- package/src/Server/symbolicate.js.flow +6 -16
- package/src/Server.d.ts +0 -1
- package/src/Server.js +298 -191
- package/src/Server.js.flow +136 -99
- package/src/cli-utils.js +13 -4
- package/src/cli-utils.js.flow +3 -5
- package/src/cli.js.flow +2 -0
- package/src/commands/build.js +18 -15
- package/src/commands/build.js.flow +6 -6
- package/src/commands/dependencies.js +26 -16
- package/src/commands/dependencies.js.flow +7 -9
- package/src/commands/serve.js +16 -11
- package/src/commands/serve.js.flow +5 -6
- package/src/index.d.ts +26 -3
- package/src/index.flow.js +162 -72
- package/src/index.flow.js.flow +60 -47
- package/src/index.js.flow +2 -0
- package/src/integration_tests/basic_bundle/TestBundle.js.flow +2 -1
- 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 +5 -13
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js +1 -1
- package/src/integration_tests/basic_bundle/require-context/utils.js +1 -1
- package/src/integration_tests/execBundle.js +7 -4
- package/src/integration_tests/execBundle.js.flow +1 -3
- package/src/integration_tests/metro.config.js +3 -3
- package/src/lib/BatchProcessor.js +15 -5
- package/src/lib/BatchProcessor.js.flow +2 -6
- package/src/lib/CountingSet.js.flow +2 -2
- package/src/lib/JsonReporter.js +6 -2
- package/src/lib/JsonReporter.js.flow +1 -5
- package/src/lib/RamBundleParser.js +12 -3
- package/src/lib/RamBundleParser.js.flow +2 -6
- package/src/lib/TerminalReporter.js +95 -56
- package/src/lib/TerminalReporter.js.flow +9 -12
- package/src/lib/bundleToString.js +4 -1
- package/src/lib/bundleToString.js.flow +2 -9
- package/src/lib/contextModule.js +3 -7
- package/src/lib/contextModuleTemplates.js +9 -19
- package/src/lib/countLines.js +5 -1
- package/src/lib/countLines.js.flow +1 -3
- package/src/lib/createWebsocketServer.js +7 -7
- package/src/lib/createWebsocketServer.js.flow +4 -4
- package/src/lib/debounceAsyncQueue.js +4 -1
- package/src/lib/debounceAsyncQueue.js.flow +1 -5
- package/src/lib/formatBundlingError.js +32 -22
- package/src/lib/formatBundlingError.js.flow +18 -20
- package/src/lib/getAppendScripts.js +20 -20
- package/src/lib/getAppendScripts.js.flow +9 -13
- package/src/lib/getGraphId.js +12 -6
- package/src/lib/getGraphId.js.flow +4 -10
- package/src/lib/getPreludeCode.js +7 -10
- package/src/lib/getPreludeCode.js.flow +2 -6
- package/src/lib/getPrependedScripts.js +40 -16
- package/src/lib/getPrependedScripts.js.flow +8 -13
- package/src/lib/isResolvedDependency.js.flow +1 -1
- package/src/lib/logToConsole.js +18 -12
- package/src/lib/logToConsole.js.flow +5 -14
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +144 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js.flow +146 -0
- package/src/lib/parseCustomResolverOptions.js +8 -6
- package/src/lib/parseCustomResolverOptions.js.flow +6 -12
- package/src/lib/parseCustomTransformOptions.js +8 -6
- package/src/lib/parseCustomTransformOptions.js.flow +11 -14
- package/src/lib/parseJsonBody.js +4 -1
- package/src/lib/parseJsonBody.js.flow +1 -3
- package/src/lib/pathUtils.js +34 -0
- package/src/lib/pathUtils.js.flow +16 -0
- package/src/lib/relativizeSourceMap.js +12 -3
- package/src/lib/relativizeSourceMap.js.flow +2 -6
- package/src/lib/reporting.js +25 -19
- package/src/lib/reporting.js.flow +6 -16
- package/src/lib/splitBundleOptions.js +4 -2
- package/src/lib/splitBundleOptions.js.flow +4 -7
- package/src/lib/transformHelpers.js +19 -25
- package/src/lib/transformHelpers.js.flow +5 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.js +75 -57
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +28 -44
- package/src/node-haste/DependencyGraph/createFileMap.js +15 -13
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +2 -5
- package/src/node-haste/DependencyGraph.js +61 -45
- package/src/node-haste/DependencyGraph.js.flow +34 -31
- package/src/node-haste/Package.js +13 -6
- package/src/node-haste/Package.js.flow +3 -7
- package/src/node-haste/{ModuleCache.js → PackageCache.js} +11 -19
- package/src/node-haste/{ModuleCache.js.flow → PackageCache.js.flow} +2 -30
- package/src/node-haste/lib/AssetPaths.js +14 -8
- package/src/node-haste/lib/AssetPaths.js.flow +7 -8
- package/src/node-haste/lib/parsePlatformFilePath.js +10 -4
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -6
- package/src/shared/output/RamBundle/as-assets.js +42 -22
- package/src/shared/output/RamBundle/as-assets.js.flow +12 -15
- package/src/shared/output/RamBundle/as-indexed-file.js +33 -23
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +10 -16
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +11 -10
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -6
- package/src/shared/output/RamBundle/magic-number.js +5 -1
- package/src/shared/output/RamBundle/magic-number.js.flow +1 -3
- package/src/shared/output/RamBundle/util.js +21 -18
- package/src/shared/output/RamBundle/util.js.flow +4 -6
- package/src/shared/output/RamBundle/write-sourcemap.js +9 -3
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +2 -6
- package/src/shared/output/RamBundle.js +16 -9
- package/src/shared/output/RamBundle.js.flow +8 -12
- package/src/shared/output/bundle.flow.js +37 -13
- package/src/shared/output/bundle.flow.js.flow +24 -12
- package/src/shared/output/bundle.js.flow +2 -0
- package/src/shared/output/meta.js +16 -9
- package/src/shared/output/meta.js.flow +3 -5
- package/src/shared/output/unbundle.js +14 -1
- package/src/shared/output/unbundle.js.flow +1 -3
- package/src/shared/output/writeFile.js +11 -4
- package/src/shared/output/writeFile.js.flow +3 -5
- package/src/shared/types.d.ts +0 -1
- package/src/shared/{types.flow.js.flow → types.js.flow} +16 -17
- package/src/lib/createModuleIdFactory.js +0 -15
- package/src/lib/createModuleIdFactory.js.flow +0 -27
- package/src/lib/getMaxWorkers.js +0 -9
- package/src/lib/getMaxWorkers.js.flow +0 -22
- package/src/lib/parseOptionsFromUrl.js +0 -62
- package/src/lib/parseOptionsFromUrl.js.flow +0 -97
- package/src/node-haste/Module.js +0 -24
- package/src/node-haste/Module.js.flow +0 -41
- /package/src/shared/{types.flow.js → types.js} +0 -0
|
@@ -9,14 +9,12 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
12
|
import type {
|
|
15
13
|
BundlerResolution,
|
|
16
14
|
TransformResultDependency,
|
|
17
|
-
} from '../../DeltaBundler/types
|
|
15
|
+
} from '../../DeltaBundler/types';
|
|
18
16
|
import type {Reporter} from '../../lib/reporting';
|
|
19
|
-
import type {ResolverInputOptions} from '../../shared/types
|
|
17
|
+
import type {ResolverInputOptions} from '../../shared/types';
|
|
20
18
|
import type {
|
|
21
19
|
CustomResolver,
|
|
22
20
|
DoesFileExist,
|
|
@@ -27,13 +25,13 @@ import type {
|
|
|
27
25
|
} from 'metro-resolver';
|
|
28
26
|
import type {PackageForModule, PackageJson} from 'metro-resolver/private/types';
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
import {codeFrameColumns} from '@babel/code-frame';
|
|
29
|
+
import fs from 'fs';
|
|
30
|
+
import invariant from 'invariant';
|
|
31
|
+
import * as Resolver from 'metro-resolver';
|
|
32
|
+
import createDefaultContext from 'metro-resolver/private/createDefaultContext';
|
|
33
|
+
import path from 'path';
|
|
34
|
+
import util from 'util';
|
|
37
35
|
|
|
38
36
|
export type DirExistsFn = (filePath: string) => boolean;
|
|
39
37
|
|
|
@@ -44,10 +42,9 @@ export type Packageish = interface {
|
|
|
44
42
|
|
|
45
43
|
export type Moduleish = interface {
|
|
46
44
|
+path: string,
|
|
47
|
-
getPackage(): ?Packageish,
|
|
48
45
|
};
|
|
49
46
|
|
|
50
|
-
export type
|
|
47
|
+
export type PackageishCache<TPackage> = interface {
|
|
51
48
|
getPackage(
|
|
52
49
|
name: string,
|
|
53
50
|
platform?: string,
|
|
@@ -70,7 +67,7 @@ type Options<TPackage> = $ReadOnly<{
|
|
|
70
67
|
getHasteModulePath: (name: string, platform: ?string) => ?string,
|
|
71
68
|
getHastePackagePath: (name: string, platform: ?string) => ?string,
|
|
72
69
|
mainFields: $ReadOnlyArray<string>,
|
|
73
|
-
|
|
70
|
+
packageCache: PackageishCache<TPackage>,
|
|
74
71
|
nodeModulesPaths: $ReadOnlyArray<string>,
|
|
75
72
|
preferNativePlatform: boolean,
|
|
76
73
|
projectRoot: string,
|
|
@@ -85,34 +82,24 @@ type Options<TPackage> = $ReadOnly<{
|
|
|
85
82
|
unstable_enablePackageExports: boolean,
|
|
86
83
|
}>;
|
|
87
84
|
|
|
88
|
-
class ModuleResolver<TPackage: Packageish> {
|
|
85
|
+
export class ModuleResolver<TPackage: Packageish> {
|
|
89
86
|
_options: Options<TPackage>;
|
|
90
87
|
// A module representing the project root, used as the origin when resolving `emptyModulePath`.
|
|
91
|
-
|
|
88
|
+
_projectRootFakeModulePath: string;
|
|
92
89
|
// An empty module, the result of resolving `emptyModulePath` from the project root.
|
|
93
90
|
_cachedEmptyModule: ?BundlerResolution;
|
|
94
91
|
|
|
95
92
|
constructor(options: Options<TPackage>) {
|
|
96
93
|
this._options = options;
|
|
97
|
-
const {projectRoot
|
|
98
|
-
this.
|
|
99
|
-
path: path.join(projectRoot, '_'),
|
|
100
|
-
getPackage: () =>
|
|
101
|
-
moduleCache.getPackageOf(this._projectRootFakeModule.path)?.pkg,
|
|
102
|
-
isHaste() {
|
|
103
|
-
throw new Error('not implemented');
|
|
104
|
-
},
|
|
105
|
-
getName() {
|
|
106
|
-
throw new Error('not implemented');
|
|
107
|
-
},
|
|
108
|
-
};
|
|
94
|
+
const {projectRoot} = this._options;
|
|
95
|
+
this._projectRootFakeModulePath = path.join(projectRoot, '_');
|
|
109
96
|
}
|
|
110
97
|
|
|
111
98
|
_getEmptyModule(): BundlerResolution {
|
|
112
99
|
let emptyModule = this._cachedEmptyModule;
|
|
113
100
|
if (!emptyModule) {
|
|
114
101
|
emptyModule = this.resolveDependency(
|
|
115
|
-
this.
|
|
102
|
+
this._projectRootFakeModulePath,
|
|
116
103
|
{
|
|
117
104
|
name: this._options.emptyModulePath,
|
|
118
105
|
data: {
|
|
@@ -132,7 +119,7 @@ class ModuleResolver<TPackage: Packageish> {
|
|
|
132
119
|
}
|
|
133
120
|
|
|
134
121
|
resolveDependency(
|
|
135
|
-
|
|
122
|
+
originModulePath: string,
|
|
136
123
|
dependency: TransformResultDependency,
|
|
137
124
|
allowHaste: boolean,
|
|
138
125
|
platform: string | null,
|
|
@@ -178,7 +165,7 @@ class ModuleResolver<TPackage: Packageish> {
|
|
|
178
165
|
unstable_enablePackageExports,
|
|
179
166
|
unstable_logWarning: this._logWarning,
|
|
180
167
|
customResolverOptions: resolverOptions.customResolverOptions ?? {},
|
|
181
|
-
originModulePath
|
|
168
|
+
originModulePath,
|
|
182
169
|
resolveHasteModule: (name: string) =>
|
|
183
170
|
this._options.getHasteModulePath(name, platform),
|
|
184
171
|
resolveHastePackage: (name: string) =>
|
|
@@ -197,14 +184,16 @@ class ModuleResolver<TPackage: Packageish> {
|
|
|
197
184
|
if (error instanceof Resolver.FailedToResolvePathError) {
|
|
198
185
|
const {candidates} = error;
|
|
199
186
|
throw new UnableToResolveError(
|
|
200
|
-
|
|
187
|
+
originModulePath,
|
|
201
188
|
dependency.name,
|
|
202
189
|
'\n\nNone of these files exist:\n' +
|
|
203
190
|
[candidates.file, candidates.dir]
|
|
204
191
|
.filter(Boolean)
|
|
205
192
|
.map(
|
|
206
193
|
candidates =>
|
|
207
|
-
` * ${Resolver.formatFileCandidates(
|
|
194
|
+
` * ${Resolver.formatFileCandidates(
|
|
195
|
+
this._removeRoot(candidates),
|
|
196
|
+
)}`,
|
|
208
197
|
)
|
|
209
198
|
.join('\n'),
|
|
210
199
|
{
|
|
@@ -214,7 +203,7 @@ class ModuleResolver<TPackage: Packageish> {
|
|
|
214
203
|
);
|
|
215
204
|
} else if (error instanceof Resolver.FailedToResolveUnsupportedError) {
|
|
216
205
|
throw new UnableToResolveError(
|
|
217
|
-
|
|
206
|
+
originModulePath,
|
|
218
207
|
dependency.name,
|
|
219
208
|
error.message,
|
|
220
209
|
{cause: error, dependency},
|
|
@@ -230,7 +219,7 @@ class ModuleResolver<TPackage: Packageish> {
|
|
|
230
219
|
const hint = displayDirPaths.length ? ' or in these directories:' : '';
|
|
231
220
|
|
|
232
221
|
throw new UnableToResolveError(
|
|
233
|
-
|
|
222
|
+
originModulePath,
|
|
234
223
|
dependency.name,
|
|
235
224
|
[
|
|
236
225
|
`${dependency.name} could not be found within the project${
|
|
@@ -250,7 +239,7 @@ class ModuleResolver<TPackage: Packageish> {
|
|
|
250
239
|
|
|
251
240
|
_getPackage = (packageJsonPath: string): ?PackageJson => {
|
|
252
241
|
try {
|
|
253
|
-
return this._options.
|
|
242
|
+
return this._options.packageCache.getPackage(packageJsonPath).read();
|
|
254
243
|
} catch (e) {
|
|
255
244
|
// Do nothing. The standard module cache does not trigger any error, but
|
|
256
245
|
// the ModuleGraph one does, if the module does not exist.
|
|
@@ -263,7 +252,7 @@ class ModuleResolver<TPackage: Packageish> {
|
|
|
263
252
|
let result;
|
|
264
253
|
|
|
265
254
|
try {
|
|
266
|
-
result = this._options.
|
|
255
|
+
result = this._options.packageCache.getPackageOf(absolutePath);
|
|
267
256
|
} catch (e) {
|
|
268
257
|
// Do nothing. The standard module cache does not trigger any error, but
|
|
269
258
|
// the ModuleGraph one does, if the module does not exist.
|
|
@@ -330,8 +319,8 @@ function getArrayLowestItem(a: $ReadOnlyArray<string>): string | void {
|
|
|
330
319
|
return lowest;
|
|
331
320
|
}
|
|
332
321
|
|
|
333
|
-
// $FlowFixMe[incompatible-
|
|
334
|
-
class UnableToResolveError extends Error {
|
|
322
|
+
// $FlowFixMe[incompatible-type]
|
|
323
|
+
export class UnableToResolveError extends Error {
|
|
335
324
|
/**
|
|
336
325
|
* File path of the module that tried to require a module, ex. `/js/foo.js`.
|
|
337
326
|
*/
|
|
@@ -493,8 +482,3 @@ function guessDependencyLocation(
|
|
|
493
482
|
function isQuote(str: ?string): boolean {
|
|
494
483
|
return str === '"' || str === "'" || str === '`';
|
|
495
484
|
}
|
|
496
|
-
|
|
497
|
-
module.exports = {
|
|
498
|
-
ModuleResolver,
|
|
499
|
-
UnableToResolveError,
|
|
500
|
-
};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = createFileMap;
|
|
7
|
+
var _ciInfo = _interopRequireDefault(require("ci-info"));
|
|
3
8
|
var _metroFileMap = _interopRequireWildcard(require("metro-file-map"));
|
|
4
9
|
function _getRequireWildcardCache(e) {
|
|
5
10
|
if ("function" != typeof WeakMap) return null;
|
|
@@ -12,23 +17,21 @@ function _getRequireWildcardCache(e) {
|
|
|
12
17
|
function _interopRequireWildcard(e, r) {
|
|
13
18
|
if (!r && e && e.__esModule) return e;
|
|
14
19
|
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
15
|
-
return {
|
|
16
|
-
default: e,
|
|
17
|
-
};
|
|
20
|
+
return { default: e };
|
|
18
21
|
var t = _getRequireWildcardCache(r);
|
|
19
22
|
if (t && t.has(e)) return t.get(e);
|
|
20
|
-
var n = {
|
|
21
|
-
__proto__: null,
|
|
22
|
-
},
|
|
23
|
+
var n = { __proto__: null },
|
|
23
24
|
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
24
25
|
for (var u in e)
|
|
25
26
|
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
26
27
|
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
27
28
|
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
28
29
|
}
|
|
29
|
-
return (n.default = e), t && t.set(e, n), n;
|
|
30
|
+
return ((n.default = e), t && t.set(e, n), n);
|
|
31
|
+
}
|
|
32
|
+
function _interopRequireDefault(e) {
|
|
33
|
+
return e && e.__esModule ? e : { default: e };
|
|
30
34
|
}
|
|
31
|
-
const ci = require("ci-info");
|
|
32
35
|
function getIgnorePattern(config) {
|
|
33
36
|
const { blockList, blacklistRE } = config.resolver;
|
|
34
37
|
const ignorePattern = blacklistRE || blockList;
|
|
@@ -46,13 +49,13 @@ function getIgnorePattern(config) {
|
|
|
46
49
|
regexes[0].toString() +
|
|
47
50
|
"\n" +
|
|
48
51
|
` - Pattern ${index}: ` +
|
|
49
|
-
regexes[index].toString()
|
|
52
|
+
regexes[index].toString(),
|
|
50
53
|
);
|
|
51
54
|
}
|
|
52
55
|
return "(" + regex.source + ")";
|
|
53
56
|
})
|
|
54
57
|
.join("|"),
|
|
55
|
-
regexes[0]?.flags ?? ""
|
|
58
|
+
regexes[0]?.flags ?? "",
|
|
56
59
|
);
|
|
57
60
|
if (Array.isArray(ignorePattern)) {
|
|
58
61
|
return combine(ignorePattern);
|
|
@@ -65,7 +68,7 @@ function createFileMap(config, options) {
|
|
|
65
68
|
? null
|
|
66
69
|
: config.resolver.dependencyExtractor;
|
|
67
70
|
const computeDependencies = dependencyExtractor != null;
|
|
68
|
-
const watch = options?.watch == null ? !
|
|
71
|
+
const watch = options?.watch == null ? !_ciInfo.default.isCI : options.watch;
|
|
69
72
|
const { enabled: autoSaveEnabled, ...autoSaveOpts } =
|
|
70
73
|
config.watcher.unstable_autoSaveCache ?? {};
|
|
71
74
|
const autoSave = watch && autoSaveEnabled ? autoSaveOpts : false;
|
|
@@ -91,7 +94,7 @@ function createFileMap(config, options) {
|
|
|
91
94
|
...config.resolver.sourceExts,
|
|
92
95
|
...config.resolver.assetExts,
|
|
93
96
|
...config.watcher.additionalExts,
|
|
94
|
-
])
|
|
97
|
+
]),
|
|
95
98
|
),
|
|
96
99
|
forceNodeFilesystemAPI: !config.resolver.useWatchman,
|
|
97
100
|
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
@@ -113,4 +116,3 @@ function createFileMap(config, options) {
|
|
|
113
116
|
watchmanDeferStates: config.watcher.watchman.deferStates,
|
|
114
117
|
});
|
|
115
118
|
}
|
|
116
|
-
module.exports = createFileMap;
|
|
@@ -11,10 +11,9 @@
|
|
|
11
11
|
|
|
12
12
|
import type {ConfigT} from 'metro-config';
|
|
13
13
|
|
|
14
|
+
import ci from 'ci-info';
|
|
14
15
|
import MetroFileMap, {DiskCacheManager} from 'metro-file-map';
|
|
15
16
|
|
|
16
|
-
const ci = require('ci-info');
|
|
17
|
-
|
|
18
17
|
function getIgnorePattern(config: ConfigT): RegExp {
|
|
19
18
|
// For now we support both options
|
|
20
19
|
const {blockList, blacklistRE} = config.resolver;
|
|
@@ -53,7 +52,7 @@ function getIgnorePattern(config: ConfigT): RegExp {
|
|
|
53
52
|
return ignorePattern;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
function createFileMap(
|
|
55
|
+
export default function createFileMap(
|
|
57
56
|
config: ConfigT,
|
|
58
57
|
options?: $ReadOnly<{
|
|
59
58
|
extractDependencies?: boolean,
|
|
@@ -114,5 +113,3 @@ function createFileMap(
|
|
|
114
113
|
watchmanDeferStates: config.watcher.watchman.deferStates,
|
|
115
114
|
});
|
|
116
115
|
}
|
|
117
|
-
|
|
118
|
-
module.exports = createFileMap;
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _createFileMap = _interopRequireDefault(
|
|
8
|
+
require("./DependencyGraph/createFileMap"),
|
|
9
|
+
);
|
|
10
|
+
var _ModuleResolution = require("./DependencyGraph/ModuleResolution");
|
|
11
|
+
var _PackageCache = require("./PackageCache");
|
|
12
|
+
var _events = _interopRequireDefault(require("events"));
|
|
13
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
14
|
+
var _metroCore = require("metro-core");
|
|
15
|
+
var _canonicalize = _interopRequireDefault(
|
|
16
|
+
require("metro-core/private/canonicalize"),
|
|
17
|
+
);
|
|
3
18
|
var _metroFileMap = require("metro-file-map");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Logger: { createActionStartEntry, createActionEndEntry, log },
|
|
12
|
-
PackageResolutionError,
|
|
13
|
-
} = require("metro-core");
|
|
14
|
-
const canonicalize = require("metro-core/private/canonicalize");
|
|
15
|
-
const { InvalidPackageError } = require("metro-resolver");
|
|
16
|
-
const nullthrows = require("nullthrows");
|
|
17
|
-
const path = require("path");
|
|
19
|
+
var _metroResolver = require("metro-resolver");
|
|
20
|
+
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
21
|
+
var _path = _interopRequireDefault(require("path"));
|
|
22
|
+
function _interopRequireDefault(e) {
|
|
23
|
+
return e && e.__esModule ? e : { default: e };
|
|
24
|
+
}
|
|
25
|
+
const { createActionStartEntry, createActionEndEntry, log } = _metroCore.Logger;
|
|
18
26
|
const NULL_PLATFORM = Symbol();
|
|
19
27
|
function getOrCreateMap(map, field) {
|
|
20
28
|
let subMap = map.get(field);
|
|
@@ -24,19 +32,20 @@ function getOrCreateMap(map, field) {
|
|
|
24
32
|
}
|
|
25
33
|
return subMap;
|
|
26
34
|
}
|
|
27
|
-
class DependencyGraph extends
|
|
35
|
+
class DependencyGraph extends _events.default {
|
|
36
|
+
#packageCache;
|
|
28
37
|
constructor(config, options) {
|
|
29
38
|
super();
|
|
30
39
|
this._config = config;
|
|
31
40
|
const { hasReducedPerformance, watch } = options ?? {};
|
|
32
41
|
const initializingMetroLogEntry = log(
|
|
33
|
-
createActionStartEntry("Initializing Metro")
|
|
42
|
+
createActionStartEntry("Initializing Metro"),
|
|
34
43
|
);
|
|
35
44
|
config.reporter.update({
|
|
36
45
|
type: "dep_graph_loading",
|
|
37
46
|
hasReducedPerformance: !!hasReducedPerformance,
|
|
38
47
|
});
|
|
39
|
-
const fileMap =
|
|
48
|
+
const fileMap = (0, _createFileMap.default)(config, {
|
|
40
49
|
throwOnModuleCollision: false,
|
|
41
50
|
watch,
|
|
42
51
|
});
|
|
@@ -53,13 +62,13 @@ class DependencyGraph extends EventEmitter {
|
|
|
53
62
|
this._fileSystem = fileSystem;
|
|
54
63
|
this._hasteMap = hasteMap;
|
|
55
64
|
this._haste.on("change", (changeEvent) =>
|
|
56
|
-
this._onHasteChange(changeEvent)
|
|
65
|
+
this._onHasteChange(changeEvent),
|
|
57
66
|
);
|
|
58
67
|
this._haste.on("healthCheck", (result) =>
|
|
59
|
-
this._onWatcherHealthCheck(result)
|
|
68
|
+
this._onWatcherHealthCheck(result),
|
|
60
69
|
);
|
|
61
70
|
this._resolutionCache = new Map();
|
|
62
|
-
this
|
|
71
|
+
this.#packageCache = this._createPackageCache();
|
|
63
72
|
this._createModuleResolver();
|
|
64
73
|
});
|
|
65
74
|
}
|
|
@@ -86,7 +95,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
86
95
|
_onHasteChange({ eventsQueue }) {
|
|
87
96
|
this._resolutionCache = new Map();
|
|
88
97
|
eventsQueue.forEach(({ filePath }) =>
|
|
89
|
-
this.
|
|
98
|
+
this.#packageCache.invalidate(filePath),
|
|
90
99
|
);
|
|
91
100
|
this._createModuleResolver();
|
|
92
101
|
this.emit("change");
|
|
@@ -105,11 +114,11 @@ class DependencyGraph extends EventEmitter {
|
|
|
105
114
|
exists: false,
|
|
106
115
|
};
|
|
107
116
|
};
|
|
108
|
-
this._moduleResolver = new ModuleResolver({
|
|
117
|
+
this._moduleResolver = new _ModuleResolution.ModuleResolver({
|
|
109
118
|
assetExts: new Set(this._config.resolver.assetExts),
|
|
110
119
|
dirExists: (filePath) => {
|
|
111
120
|
try {
|
|
112
|
-
return
|
|
121
|
+
return _fs.default.lstatSync(filePath).isDirectory();
|
|
113
122
|
} catch (e) {}
|
|
114
123
|
return false;
|
|
115
124
|
},
|
|
@@ -124,17 +133,17 @@ class DependencyGraph extends EventEmitter {
|
|
|
124
133
|
getHastePackagePath: (name, platform) =>
|
|
125
134
|
this._hasteMap.getPackage(name, platform, true),
|
|
126
135
|
mainFields: this._config.resolver.resolverMainFields,
|
|
127
|
-
moduleCache: this._moduleCache,
|
|
128
136
|
nodeModulesPaths: this._config.resolver.nodeModulesPaths,
|
|
137
|
+
packageCache: this.#packageCache,
|
|
129
138
|
preferNativePlatform: true,
|
|
130
139
|
projectRoot: this._config.projectRoot,
|
|
131
140
|
reporter: this._config.reporter,
|
|
132
141
|
resolveAsset: (dirPath, assetName, extension) => {
|
|
133
|
-
const basePath = dirPath +
|
|
142
|
+
const basePath = dirPath + _path.default.sep + assetName;
|
|
134
143
|
const assets = [
|
|
135
144
|
basePath + extension,
|
|
136
145
|
...this._config.resolver.assetResolutions.map(
|
|
137
|
-
(resolution) => basePath + "@" + resolution + "x" + extension
|
|
146
|
+
(resolution) => basePath + "@" + resolution + "x" + extension,
|
|
138
147
|
),
|
|
139
148
|
]
|
|
140
149
|
.map((assetPath) => fileSystemLookup(assetPath).realPath)
|
|
@@ -158,7 +167,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
158
167
|
breakOnSegment: "node_modules",
|
|
159
168
|
invalidatedBy: null,
|
|
160
169
|
subpathType: "f",
|
|
161
|
-
}
|
|
170
|
+
},
|
|
162
171
|
);
|
|
163
172
|
return result
|
|
164
173
|
? {
|
|
@@ -167,14 +176,14 @@ class DependencyGraph extends EventEmitter {
|
|
|
167
176
|
}
|
|
168
177
|
: null;
|
|
169
178
|
}
|
|
170
|
-
|
|
171
|
-
return new
|
|
179
|
+
_createPackageCache() {
|
|
180
|
+
return new _PackageCache.PackageCache({
|
|
172
181
|
getClosestPackage: (absolutePath) =>
|
|
173
182
|
this._getClosestPackage(absolutePath),
|
|
174
183
|
});
|
|
175
184
|
}
|
|
176
185
|
getAllFiles() {
|
|
177
|
-
return
|
|
186
|
+
return (0, _nullthrows.default)(this._fileSystem).getAllFiles();
|
|
178
187
|
}
|
|
179
188
|
async getOrComputeSha1(mixedPath) {
|
|
180
189
|
const result = await this._fileSystem.getOrComputeSha1(mixedPath);
|
|
@@ -205,13 +214,13 @@ class DependencyGraph extends EventEmitter {
|
|
|
205
214
|
});
|
|
206
215
|
}
|
|
207
216
|
resolveDependency(
|
|
208
|
-
|
|
217
|
+
originModulePath,
|
|
209
218
|
dependency,
|
|
210
219
|
platform,
|
|
211
220
|
resolverOptions,
|
|
212
221
|
{ assumeFlatNodeModules } = {
|
|
213
222
|
assumeFlatNodeModules: false,
|
|
214
|
-
}
|
|
223
|
+
},
|
|
215
224
|
) {
|
|
216
225
|
const to = dependency.name;
|
|
217
226
|
const isSensitiveToOriginFolder =
|
|
@@ -219,17 +228,21 @@ class DependencyGraph extends EventEmitter {
|
|
|
219
228
|
to.includes("/") ||
|
|
220
229
|
to === "." ||
|
|
221
230
|
to === ".." ||
|
|
222
|
-
|
|
231
|
+
originModulePath.includes(
|
|
232
|
+
_path.default.sep + "node_modules" + _path.default.sep,
|
|
233
|
+
);
|
|
223
234
|
const resolverOptionsKey =
|
|
224
|
-
JSON.stringify(resolverOptions ?? {},
|
|
225
|
-
const originKey = isSensitiveToOriginFolder
|
|
235
|
+
JSON.stringify(resolverOptions ?? {}, _canonicalize.default) ?? "";
|
|
236
|
+
const originKey = isSensitiveToOriginFolder
|
|
237
|
+
? _path.default.dirname(originModulePath)
|
|
238
|
+
: "";
|
|
226
239
|
const targetKey =
|
|
227
240
|
to + (dependency.data.isESMImport === true ? "\0esm" : "\0cjs");
|
|
228
241
|
const platformKey = platform ?? NULL_PLATFORM;
|
|
229
242
|
const mapByResolverOptions = this._resolutionCache;
|
|
230
243
|
const mapByOrigin = getOrCreateMap(
|
|
231
244
|
mapByResolverOptions,
|
|
232
|
-
resolverOptionsKey
|
|
245
|
+
resolverOptionsKey,
|
|
233
246
|
);
|
|
234
247
|
const mapByTarget = getOrCreateMap(mapByOrigin, originKey);
|
|
235
248
|
const mapByPlatform = getOrCreateMap(mapByTarget, targetKey);
|
|
@@ -237,20 +250,23 @@ class DependencyGraph extends EventEmitter {
|
|
|
237
250
|
if (!resolution) {
|
|
238
251
|
try {
|
|
239
252
|
resolution = this._moduleResolver.resolveDependency(
|
|
240
|
-
|
|
253
|
+
originModulePath,
|
|
241
254
|
dependency,
|
|
242
255
|
true,
|
|
243
256
|
platform,
|
|
244
|
-
resolverOptions
|
|
257
|
+
resolverOptions,
|
|
245
258
|
);
|
|
246
259
|
} catch (error) {
|
|
247
260
|
if (error instanceof _metroFileMap.DuplicateHasteCandidatesError) {
|
|
248
|
-
throw new AmbiguousModuleResolutionError(
|
|
261
|
+
throw new _metroCore.AmbiguousModuleResolutionError(
|
|
262
|
+
originModulePath,
|
|
263
|
+
error,
|
|
264
|
+
);
|
|
249
265
|
}
|
|
250
|
-
if (error instanceof InvalidPackageError) {
|
|
251
|
-
throw new PackageResolutionError({
|
|
266
|
+
if (error instanceof _metroResolver.InvalidPackageError) {
|
|
267
|
+
throw new _metroCore.PackageResolutionError({
|
|
252
268
|
packageError: error,
|
|
253
|
-
originModulePath
|
|
269
|
+
originModulePath,
|
|
254
270
|
targetModuleName: to,
|
|
255
271
|
});
|
|
256
272
|
}
|
|
@@ -268,10 +284,10 @@ class DependencyGraph extends EventEmitter {
|
|
|
268
284
|
if (hasteName) {
|
|
269
285
|
return hasteName;
|
|
270
286
|
}
|
|
271
|
-
return
|
|
287
|
+
return _path.default.relative(this._config.projectRoot, filePath);
|
|
272
288
|
}
|
|
273
289
|
getDependencies(filePath) {
|
|
274
|
-
return
|
|
290
|
+
return (0, _nullthrows.default)(this._fileSystem.getDependencies(filePath));
|
|
275
291
|
}
|
|
276
292
|
}
|
|
277
|
-
|
|
293
|
+
exports.default = DependencyGraph;
|