metro 0.83.2 → 0.83.4
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 +25 -23
- package/src/Assets.js +50 -30
- package/src/Assets.js.flow +26 -15
- package/src/Bundler/util.js +33 -22
- package/src/Bundler/util.js.flow +2 -2
- package/src/Bundler.js +5 -1
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.js +9 -5
- package/src/DeltaBundler/DeltaCalculator.js.flow +8 -8
- package/src/DeltaBundler/Graph.js +21 -17
- package/src/DeltaBundler/Graph.js.flow +30 -30
- package/src/DeltaBundler/Serializers/baseJSBundle.js +5 -1
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getAssets.js +5 -1
- package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +5 -1
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +8 -8
- package/src/DeltaBundler/Serializers/helpers/js.js +33 -22
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +6 -6
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +33 -22
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +5 -5
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +5 -1
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +2 -2
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
- package/src/DeltaBundler/Transformer.js +5 -1
- package/src/DeltaBundler/Transformer.js.flow +3 -3
- package/src/DeltaBundler/Worker.flow.js +5 -1
- package/src/DeltaBundler/Worker.flow.js.flow +1 -1
- package/src/DeltaBundler/WorkerFarm.js +1 -1
- package/src/DeltaBundler/WorkerFarm.js.flow +26 -13
- package/src/DeltaBundler/buildSubgraph.js +9 -5
- package/src/DeltaBundler/buildSubgraph.js.flow +8 -8
- package/src/DeltaBundler/getTransformCacheKey.js +5 -1
- package/src/DeltaBundler/types.js +5 -1
- package/src/DeltaBundler/types.js.flow +36 -34
- package/src/DeltaBundler.js +5 -1
- package/src/DeltaBundler.js.flow +2 -2
- package/src/HmrServer.js +42 -30
- package/src/HmrServer.js.flow +17 -12
- package/src/IncrementalBundler.js +37 -22
- package/src/IncrementalBundler.js.flow +13 -9
- package/src/ModuleGraph/worker/JsFileWrapping.js +33 -22
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +10 -5
- package/src/ModuleGraph/worker/collectDependencies.js +33 -22
- package/src/ModuleGraph/worker/collectDependencies.js.flow +27 -21
- package/src/ModuleGraph/worker/generateImportNames.js +5 -1
- package/src/ModuleGraph/worker/generateImportNames.js.flow +4 -2
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +7 -3
- package/src/Server/MultipartResponse.js +5 -1
- package/src/Server/MultipartResponse.js.flow +1 -1
- package/src/Server/symbolicate.js.flow +4 -4
- package/src/Server.js +112 -40
- package/src/Server.js.flow +110 -47
- package/src/cli/parseKeyValueParamArray.js.flow +1 -1
- package/src/cli-utils.js +5 -1
- package/src/cli-utils.js.flow +2 -2
- package/src/commands/build.js +5 -1
- package/src/commands/build.js.flow +11 -10
- package/src/commands/dependencies.js +5 -1
- package/src/commands/dependencies.js.flow +8 -4
- package/src/commands/serve.js +2 -0
- package/src/commands/serve.js.flow +14 -9
- package/src/index.flow.js +38 -27
- package/src/index.flow.js.flow +25 -20
- package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
- package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +5 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +5 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/index.js +33 -22
- package/src/integration_tests/basic_bundle/import-export/index.js.flow +3 -3
- package/src/integration_tests/basic_bundle/import-export/utils.js.flow +2 -2
- package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js.flow +1 -1
- package/src/integration_tests/basic_bundle/optional-dependencies/index.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/empty.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/matching.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +2 -2
- package/src/integration_tests/basic_bundle/require-context/utils.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/execBundle.js +5 -1
- package/src/integration_tests/execBundle.js.flow +1 -1
- package/src/lib/BatchProcessor.js +10 -3
- package/src/lib/BatchProcessor.js.flow +10 -7
- package/src/lib/CountingSet.js.flow +4 -4
- package/src/lib/JsonReporter.js +5 -3
- package/src/lib/JsonReporter.js.flow +19 -17
- package/src/lib/RamBundleParser.js +5 -1
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.js +39 -28
- package/src/lib/TerminalReporter.js.flow +15 -15
- package/src/lib/contextModule.js +5 -1
- package/src/lib/contextModule.js.flow +1 -1
- package/src/lib/contextModuleTemplates.js +28 -21
- package/src/lib/countLines.js +4 -3
- package/src/lib/countLines.js.flow +3 -4
- package/src/lib/createWebsocketServer.js +14 -3
- package/src/lib/createWebsocketServer.js.flow +16 -9
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.js +5 -1
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/getAppendScripts.js +5 -1
- package/src/lib/getAppendScripts.js.flow +4 -4
- package/src/lib/getGraphId.js +5 -1
- package/src/lib/getGraphId.js.flow +1 -1
- package/src/lib/getPreludeCode.js +4 -0
- package/src/lib/getPreludeCode.js.flow +10 -3
- package/src/lib/getPrependedScripts.js +44 -23
- package/src/lib/getPrependedScripts.js.flow +10 -3
- package/src/lib/logToConsole.js +5 -1
- package/src/lib/logToConsole.js.flow +2 -2
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +33 -22
- package/src/lib/parseCustomResolverOptions.js.flow +2 -2
- package/src/lib/parseCustomTransformOptions.js.flow +1 -1
- package/src/lib/parseJsonBody.js.flow +11 -1
- package/src/lib/pathUtils.js +28 -21
- package/src/lib/pathUtils.js.flow +1 -1
- package/src/lib/relativizeSourceMap.js +5 -1
- package/src/lib/reporting.js +5 -1
- package/src/lib/reporting.js.flow +4 -4
- package/src/lib/transformHelpers.js +16 -10
- package/src/lib/transformHelpers.js.flow +17 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.js +56 -43
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +35 -32
- package/src/node-haste/DependencyGraph/createFileMap.js +64 -39
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +44 -18
- package/src/node-haste/DependencyGraph.js +45 -32
- package/src/node-haste/DependencyGraph.js.flow +35 -37
- package/src/node-haste/Package.js +5 -1
- package/src/node-haste/PackageCache.js +5 -1
- package/src/node-haste/lib/AssetPaths.js +7 -3
- package/src/node-haste/lib/AssetPaths.js.flow +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.js +11 -7
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +4 -4
- package/src/shared/output/RamBundle/as-assets.js +5 -1
- package/src/shared/output/RamBundle/as-assets.js.flow +6 -6
- package/src/shared/output/RamBundle/as-indexed-file.js +5 -1
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +5 -5
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +5 -5
- package/src/shared/output/RamBundle/util.js +5 -1
- package/src/shared/output/RamBundle/util.js.flow +5 -5
- package/src/shared/output/RamBundle/write-sourcemap.js +5 -1
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.js +5 -1
- package/src/shared/output/RamBundle.js.flow +1 -1
- package/src/shared/output/bundle.flow.js +5 -1
- package/src/shared/output/bundle.flow.js.flow +3 -3
- package/src/shared/output/meta.js +7 -3
- package/src/shared/output/meta.js.flow +1 -1
- package/src/shared/output/writeFile.js +13 -4
- package/src/shared/output/writeFile.js.flow +8 -2
- package/src/shared/types.js.flow +20 -5
- package/src/Asset.d.ts +0 -25
- package/src/Bundler.d.ts +0 -39
- package/src/DeltaBundler/Graph.d.ts +0 -40
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +0 -26
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +0 -18
- package/src/DeltaBundler/Worker.d.ts +0 -45
- package/src/DeltaBundler/types.d.ts +0 -166
- package/src/DeltaBundler.d.ts +0 -58
- package/src/IncrementalBundler.d.ts +0 -98
- package/src/ModuleGraph/test-helpers.js +0 -75
- package/src/ModuleGraph/worker/collectDependencies.d.ts +0 -27
- package/src/Server/MultipartResponse.d.ts +0 -31
- package/src/Server/symbolicate.d.ts +0 -31
- package/src/Server.d.ts +0 -118
- package/src/index.d.ts +0 -193
- package/src/lib/CountingSet.d.ts +0 -48
- package/src/lib/TerminalReporter.d.ts +0 -27
- package/src/lib/contextModule.d.ts +0 -22
- package/src/lib/getGraphId.d.ts +0 -11
- package/src/lib/reporting.d.ts +0 -144
- package/src/node-haste/DependencyGraph.d.ts +0 -62
- package/src/shared/output/bundle.d.ts +0 -35
- package/src/shared/types.d.ts +0 -130
|
@@ -56,8 +56,8 @@ export type PackageishCache<TPackage> = interface {
|
|
|
56
56
|
},
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
type Options<TPackage> =
|
|
60
|
-
assetExts:
|
|
59
|
+
type Options<TPackage> = Readonly<{
|
|
60
|
+
assetExts: ReadonlySet<string>,
|
|
61
61
|
dirExists: DirExistsFn,
|
|
62
62
|
disableHierarchicalLookup: boolean,
|
|
63
63
|
doesFileExist: DoesFileExist,
|
|
@@ -66,20 +66,21 @@ type Options<TPackage> = $ReadOnly<{
|
|
|
66
66
|
fileSystemLookup: FileSystemLookup,
|
|
67
67
|
getHasteModulePath: (name: string, platform: ?string) => ?string,
|
|
68
68
|
getHastePackagePath: (name: string, platform: ?string) => ?string,
|
|
69
|
-
mainFields:
|
|
69
|
+
mainFields: ReadonlyArray<string>,
|
|
70
70
|
packageCache: PackageishCache<TPackage>,
|
|
71
|
-
nodeModulesPaths:
|
|
71
|
+
nodeModulesPaths: ReadonlyArray<string>,
|
|
72
72
|
preferNativePlatform: boolean,
|
|
73
73
|
projectRoot: string,
|
|
74
74
|
reporter: Reporter,
|
|
75
75
|
resolveAsset: ResolveAsset,
|
|
76
76
|
resolveRequest: ?CustomResolver,
|
|
77
|
-
sourceExts:
|
|
78
|
-
unstable_conditionNames:
|
|
79
|
-
unstable_conditionsByPlatform:
|
|
80
|
-
[platform: string]:
|
|
77
|
+
sourceExts: ReadonlyArray<string>,
|
|
78
|
+
unstable_conditionNames: ReadonlyArray<string>,
|
|
79
|
+
unstable_conditionsByPlatform: Readonly<{
|
|
80
|
+
[platform: string]: ReadonlyArray<string>,
|
|
81
81
|
}>,
|
|
82
82
|
unstable_enablePackageExports: boolean,
|
|
83
|
+
unstable_incrementalResolution: boolean,
|
|
83
84
|
}>;
|
|
84
85
|
|
|
85
86
|
export class ModuleResolver<TPackage: Packageish> {
|
|
@@ -101,13 +102,13 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
101
102
|
emptyModule = this.resolveDependency(
|
|
102
103
|
this._projectRootFakeModulePath,
|
|
103
104
|
{
|
|
104
|
-
name: this._options.emptyModulePath,
|
|
105
105
|
data: {
|
|
106
|
-
key: this._options.emptyModulePath,
|
|
107
106
|
asyncType: null,
|
|
108
107
|
isESMImport: false,
|
|
108
|
+
key: this._options.emptyModulePath,
|
|
109
109
|
locs: [],
|
|
110
110
|
},
|
|
111
|
+
name: this._options.emptyModulePath,
|
|
111
112
|
},
|
|
112
113
|
false,
|
|
113
114
|
null,
|
|
@@ -140,6 +141,7 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
140
141
|
unstable_conditionNames,
|
|
141
142
|
unstable_conditionsByPlatform,
|
|
142
143
|
unstable_enablePackageExports,
|
|
144
|
+
unstable_incrementalResolution,
|
|
143
145
|
} = this._options;
|
|
144
146
|
|
|
145
147
|
try {
|
|
@@ -148,31 +150,32 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
148
150
|
{
|
|
149
151
|
allowHaste,
|
|
150
152
|
assetExts,
|
|
153
|
+
customResolverOptions: resolverOptions.customResolverOptions ?? {},
|
|
151
154
|
dev: resolverOptions.dev,
|
|
152
155
|
disableHierarchicalLookup,
|
|
153
156
|
doesFileExist,
|
|
154
157
|
extraNodeModules,
|
|
155
158
|
fileSystemLookup,
|
|
159
|
+
getPackage: this._getPackage,
|
|
160
|
+
getPackageForModule: (absoluteModulePath: string) =>
|
|
161
|
+
this._getPackageForModule(absoluteModulePath),
|
|
156
162
|
isESMImport: dependency.data.isESMImport,
|
|
157
163
|
mainFields,
|
|
158
164
|
nodeModulesPaths,
|
|
165
|
+
originModulePath,
|
|
159
166
|
preferNativePlatform,
|
|
160
167
|
resolveAsset,
|
|
168
|
+
resolveHasteModule: (name: string) =>
|
|
169
|
+
this._options.getHasteModulePath(name, platform),
|
|
170
|
+
resolveHastePackage: (name: string) =>
|
|
171
|
+
this._options.getHastePackagePath(name, platform),
|
|
161
172
|
resolveRequest,
|
|
162
173
|
sourceExts,
|
|
163
174
|
unstable_conditionNames,
|
|
164
175
|
unstable_conditionsByPlatform,
|
|
165
176
|
unstable_enablePackageExports,
|
|
177
|
+
unstable_incrementalResolution,
|
|
166
178
|
unstable_logWarning: this._logWarning,
|
|
167
|
-
customResolverOptions: resolverOptions.customResolverOptions ?? {},
|
|
168
|
-
originModulePath,
|
|
169
|
-
resolveHasteModule: (name: string) =>
|
|
170
|
-
this._options.getHasteModulePath(name, platform),
|
|
171
|
-
resolveHastePackage: (name: string) =>
|
|
172
|
-
this._options.getHastePackagePath(name, platform),
|
|
173
|
-
getPackage: this._getPackage,
|
|
174
|
-
getPackageForModule: (absoluteModulePath: string) =>
|
|
175
|
-
this._getPackageForModule(absoluteModulePath),
|
|
176
179
|
},
|
|
177
180
|
dependency,
|
|
178
181
|
),
|
|
@@ -260,9 +263,9 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
260
263
|
|
|
261
264
|
return result != null
|
|
262
265
|
? {
|
|
263
|
-
rootPath: path.dirname(result.pkg.path),
|
|
264
266
|
packageJson: result.pkg.read(),
|
|
265
267
|
packageRelativePath: result.packageRelativePath,
|
|
268
|
+
rootPath: path.dirname(result.pkg.path),
|
|
266
269
|
}
|
|
267
270
|
: null;
|
|
268
271
|
};
|
|
@@ -279,19 +282,19 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
279
282
|
// not just an arbitrary item!
|
|
280
283
|
const arbitrary = getArrayLowestItem(resolution.filePaths);
|
|
281
284
|
invariant(arbitrary != null, 'invalid asset resolution');
|
|
282
|
-
return {type: 'sourceFile'
|
|
285
|
+
return {filePath: arbitrary, type: 'sourceFile'};
|
|
283
286
|
case 'empty':
|
|
284
287
|
return this._getEmptyModule();
|
|
285
288
|
default:
|
|
286
|
-
|
|
289
|
+
resolution.type as empty;
|
|
287
290
|
throw new Error('invalid type');
|
|
288
291
|
}
|
|
289
292
|
}
|
|
290
293
|
|
|
291
294
|
_logWarning = (message: string): void => {
|
|
292
295
|
this._options.reporter.update({
|
|
293
|
-
type: 'resolver_warning',
|
|
294
296
|
message,
|
|
297
|
+
type: 'resolver_warning',
|
|
295
298
|
});
|
|
296
299
|
};
|
|
297
300
|
|
|
@@ -306,7 +309,7 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
306
309
|
}
|
|
307
310
|
}
|
|
308
311
|
|
|
309
|
-
function getArrayLowestItem(a:
|
|
312
|
+
function getArrayLowestItem(a: ReadonlyArray<string>): string | void {
|
|
310
313
|
if (a.length === 0) {
|
|
311
314
|
return undefined;
|
|
312
315
|
}
|
|
@@ -343,7 +346,7 @@ export class UnableToResolveError extends Error {
|
|
|
343
346
|
originModulePath: string,
|
|
344
347
|
targetModuleName: string,
|
|
345
348
|
message: string,
|
|
346
|
-
options?:
|
|
349
|
+
options?: Readonly<{
|
|
347
350
|
dependency?: ?TransformResultDependency,
|
|
348
351
|
cause?: Error,
|
|
349
352
|
}>,
|
|
@@ -429,8 +432,8 @@ function refineDependencyLocation(
|
|
|
429
432
|
if (isQuote(maybeQuoteBefore) && maybeQuoteBefore === maybeQuoteAfter) {
|
|
430
433
|
return {
|
|
431
434
|
start: {
|
|
432
|
-
line: line + 1,
|
|
433
435
|
column: minColumn + offset + 1,
|
|
436
|
+
line: line + 1,
|
|
434
437
|
},
|
|
435
438
|
};
|
|
436
439
|
}
|
|
@@ -439,13 +442,13 @@ function refineDependencyLocation(
|
|
|
439
442
|
// Otherwise, if this is a single-line loc, return it exactly, as a range.
|
|
440
443
|
if (loc.start.line === loc.end.line) {
|
|
441
444
|
return {
|
|
442
|
-
start: {
|
|
443
|
-
line: loc.start.line,
|
|
444
|
-
column: loc.start.column + 1,
|
|
445
|
-
},
|
|
446
445
|
end: {
|
|
447
|
-
line: loc.end.line,
|
|
448
446
|
column: loc.end.column + 1,
|
|
447
|
+
line: loc.end.line,
|
|
448
|
+
},
|
|
449
|
+
start: {
|
|
450
|
+
column: loc.start.column + 1,
|
|
451
|
+
line: loc.start.line,
|
|
449
452
|
},
|
|
450
453
|
};
|
|
451
454
|
}
|
|
@@ -453,8 +456,8 @@ function refineDependencyLocation(
|
|
|
453
456
|
// much unnecessary context.
|
|
454
457
|
return {
|
|
455
458
|
start: {
|
|
456
|
-
line: loc.start.line,
|
|
457
459
|
column: loc.start.column + 1,
|
|
460
|
+
line: loc.start.line,
|
|
458
461
|
},
|
|
459
462
|
};
|
|
460
463
|
}
|
|
@@ -6,31 +6,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = createFileMap;
|
|
7
7
|
var _ciInfo = _interopRequireDefault(require("ci-info"));
|
|
8
8
|
var _metroFileMap = _interopRequireWildcard(require("metro-file-map"));
|
|
9
|
-
function
|
|
10
|
-
if ("function"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
27
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
28
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
9
|
+
function _interopRequireWildcard(e, t) {
|
|
10
|
+
if ("function" == typeof WeakMap)
|
|
11
|
+
var r = new WeakMap(),
|
|
12
|
+
n = new WeakMap();
|
|
13
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
14
|
+
if (!t && e && e.__esModule) return e;
|
|
15
|
+
var o,
|
|
16
|
+
i,
|
|
17
|
+
f = {
|
|
18
|
+
__proto__: null,
|
|
19
|
+
default: e,
|
|
20
|
+
};
|
|
21
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
22
|
+
return f;
|
|
23
|
+
if ((o = t ? n : r)) {
|
|
24
|
+
if (o.has(e)) return o.get(e);
|
|
25
|
+
o.set(e, f);
|
|
29
26
|
}
|
|
30
|
-
|
|
27
|
+
for (const t in e)
|
|
28
|
+
"default" !== t &&
|
|
29
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
30
|
+
((i =
|
|
31
|
+
(o = Object.defineProperty) &&
|
|
32
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
33
|
+
(i.get || i.set)
|
|
34
|
+
? o(f, t, i)
|
|
35
|
+
: (f[t] = e[t]));
|
|
36
|
+
return f;
|
|
37
|
+
})(e, t);
|
|
31
38
|
}
|
|
32
39
|
function _interopRequireDefault(e) {
|
|
33
|
-
return e && e.__esModule
|
|
40
|
+
return e && e.__esModule
|
|
41
|
+
? e
|
|
42
|
+
: {
|
|
43
|
+
default: e,
|
|
44
|
+
};
|
|
34
45
|
}
|
|
35
46
|
function getIgnorePattern(config) {
|
|
36
47
|
const { blockList, blacklistRE } = config.resolver;
|
|
@@ -63,16 +74,35 @@ function getIgnorePattern(config) {
|
|
|
63
74
|
return ignorePattern;
|
|
64
75
|
}
|
|
65
76
|
function createFileMap(config, options) {
|
|
66
|
-
const dependencyExtractor =
|
|
67
|
-
options?.extractDependencies === false
|
|
68
|
-
? null
|
|
69
|
-
: config.resolver.dependencyExtractor;
|
|
70
|
-
const computeDependencies = dependencyExtractor != null;
|
|
71
77
|
const watch = options?.watch == null ? !_ciInfo.default.isCI : options.watch;
|
|
72
78
|
const { enabled: autoSaveEnabled, ...autoSaveOpts } =
|
|
73
79
|
config.watcher.unstable_autoSaveCache ?? {};
|
|
74
80
|
const autoSave = watch && autoSaveEnabled ? autoSaveOpts : false;
|
|
75
|
-
|
|
81
|
+
const plugins = [];
|
|
82
|
+
let dependencyPlugin = null;
|
|
83
|
+
if (
|
|
84
|
+
config.resolver.dependencyExtractor != null &&
|
|
85
|
+
options?.extractDependencies !== false
|
|
86
|
+
) {
|
|
87
|
+
dependencyPlugin = new _metroFileMap.DependencyPlugin({
|
|
88
|
+
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
89
|
+
computeDependencies: true,
|
|
90
|
+
rootDir: config.projectRoot,
|
|
91
|
+
});
|
|
92
|
+
plugins.push(dependencyPlugin);
|
|
93
|
+
}
|
|
94
|
+
const hasteMap = new _metroFileMap.HastePlugin({
|
|
95
|
+
platforms: new Set([
|
|
96
|
+
...config.resolver.platforms,
|
|
97
|
+
_metroFileMap.default.H.NATIVE_PLATFORM,
|
|
98
|
+
]),
|
|
99
|
+
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
100
|
+
enableHastePackages: config.resolver.enableGlobalPackages,
|
|
101
|
+
rootDir: config.projectRoot,
|
|
102
|
+
failValidationOnConflicts: options?.throwOnModuleCollision ?? true,
|
|
103
|
+
});
|
|
104
|
+
plugins.push(hasteMap);
|
|
105
|
+
const fileMap = new _metroFileMap.default({
|
|
76
106
|
cacheManagerFactory:
|
|
77
107
|
config?.unstable_fileMapCacheManagerFactory ??
|
|
78
108
|
((factoryParams) =>
|
|
@@ -83,12 +113,8 @@ function createFileMap(config, options) {
|
|
|
83
113
|
autoSave,
|
|
84
114
|
})),
|
|
85
115
|
perfLoggerFactory: config.unstable_perfLoggerFactory,
|
|
86
|
-
computeDependencies,
|
|
87
116
|
computeSha1: !config.watcher.unstable_lazySha1,
|
|
88
|
-
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
89
|
-
enableHastePackages: config?.resolver.enableGlobalPackages,
|
|
90
117
|
enableSymlinks: true,
|
|
91
|
-
enableWorkerThreads: config.watcher.unstable_workerThreads,
|
|
92
118
|
extensions: Array.from(
|
|
93
119
|
new Set([
|
|
94
120
|
...config.resolver.sourceExts,
|
|
@@ -97,22 +123,21 @@ function createFileMap(config, options) {
|
|
|
97
123
|
]),
|
|
98
124
|
),
|
|
99
125
|
forceNodeFilesystemAPI: !config.resolver.useWatchman,
|
|
100
|
-
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
101
126
|
healthCheck: config.watcher.healthCheck,
|
|
102
127
|
ignorePattern: getIgnorePattern(config),
|
|
103
128
|
maxWorkers: config.maxWorkers,
|
|
104
|
-
|
|
105
|
-
platforms: [
|
|
106
|
-
...config.resolver.platforms,
|
|
107
|
-
_metroFileMap.default.H.NATIVE_PLATFORM,
|
|
108
|
-
],
|
|
129
|
+
plugins,
|
|
109
130
|
retainAllFiles: true,
|
|
110
131
|
resetCache: config.resetCache,
|
|
111
132
|
rootDir: config.projectRoot,
|
|
112
133
|
roots: config.watchFolders,
|
|
113
|
-
throwOnModuleCollision: options?.throwOnModuleCollision ?? true,
|
|
114
134
|
useWatchman: config.resolver.useWatchman,
|
|
115
135
|
watch,
|
|
116
136
|
watchmanDeferStates: config.watcher.watchman.deferStates,
|
|
117
137
|
});
|
|
138
|
+
return {
|
|
139
|
+
fileMap,
|
|
140
|
+
hasteMap,
|
|
141
|
+
dependencyPlugin,
|
|
142
|
+
};
|
|
118
143
|
}
|
|
@@ -10,9 +10,14 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type {ConfigT} from 'metro-config';
|
|
13
|
+
import type {HasteMap} from 'metro-file-map';
|
|
13
14
|
|
|
14
15
|
import ci from 'ci-info';
|
|
15
|
-
import MetroFileMap, {
|
|
16
|
+
import MetroFileMap, {
|
|
17
|
+
DependencyPlugin,
|
|
18
|
+
DiskCacheManager,
|
|
19
|
+
HastePlugin,
|
|
20
|
+
} from 'metro-file-map';
|
|
16
21
|
|
|
17
22
|
function getIgnorePattern(config: ConfigT): RegExp {
|
|
18
23
|
// For now we support both options
|
|
@@ -54,25 +59,52 @@ function getIgnorePattern(config: ConfigT): RegExp {
|
|
|
54
59
|
|
|
55
60
|
export default function createFileMap(
|
|
56
61
|
config: ConfigT,
|
|
57
|
-
options?:
|
|
62
|
+
options?: Readonly<{
|
|
58
63
|
extractDependencies?: boolean,
|
|
59
64
|
watch?: boolean,
|
|
60
65
|
throwOnModuleCollision?: boolean,
|
|
61
66
|
cacheFilePrefix?: string,
|
|
62
67
|
}>,
|
|
63
|
-
):
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const computeDependencies = dependencyExtractor != null;
|
|
69
|
-
|
|
68
|
+
): {
|
|
69
|
+
fileMap: MetroFileMap,
|
|
70
|
+
hasteMap: HasteMap,
|
|
71
|
+
dependencyPlugin: ?DependencyPlugin,
|
|
72
|
+
} {
|
|
70
73
|
const watch = options?.watch == null ? !ci.isCI : options.watch;
|
|
71
74
|
const {enabled: autoSaveEnabled, ...autoSaveOpts} =
|
|
72
75
|
config.watcher.unstable_autoSaveCache ?? {};
|
|
73
76
|
const autoSave = watch && autoSaveEnabled ? autoSaveOpts : false;
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
const plugins: Array<DependencyPlugin | HastePlugin> = [];
|
|
79
|
+
|
|
80
|
+
let dependencyPlugin = null;
|
|
81
|
+
// Add DependencyPlugin if dependencies should be extracted
|
|
82
|
+
if (
|
|
83
|
+
config.resolver.dependencyExtractor != null &&
|
|
84
|
+
options?.extractDependencies !== false
|
|
85
|
+
) {
|
|
86
|
+
dependencyPlugin = new DependencyPlugin({
|
|
87
|
+
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
88
|
+
computeDependencies: true,
|
|
89
|
+
rootDir: config.projectRoot,
|
|
90
|
+
});
|
|
91
|
+
plugins.push(dependencyPlugin);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const hasteMap = new HastePlugin({
|
|
95
|
+
platforms: new Set([
|
|
96
|
+
...config.resolver.platforms,
|
|
97
|
+
MetroFileMap.H.NATIVE_PLATFORM,
|
|
98
|
+
]),
|
|
99
|
+
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
100
|
+
enableHastePackages: config.resolver.enableGlobalPackages,
|
|
101
|
+
rootDir: config.projectRoot,
|
|
102
|
+
failValidationOnConflicts: options?.throwOnModuleCollision ?? true,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
plugins.push(hasteMap);
|
|
106
|
+
|
|
107
|
+
const fileMap = new MetroFileMap({
|
|
76
108
|
cacheManagerFactory:
|
|
77
109
|
config?.unstable_fileMapCacheManagerFactory ??
|
|
78
110
|
(factoryParams =>
|
|
@@ -83,12 +115,8 @@ export default function createFileMap(
|
|
|
83
115
|
autoSave,
|
|
84
116
|
})),
|
|
85
117
|
perfLoggerFactory: config.unstable_perfLoggerFactory,
|
|
86
|
-
computeDependencies,
|
|
87
118
|
computeSha1: !config.watcher.unstable_lazySha1,
|
|
88
|
-
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
89
|
-
enableHastePackages: config?.resolver.enableGlobalPackages,
|
|
90
119
|
enableSymlinks: true,
|
|
91
|
-
enableWorkerThreads: config.watcher.unstable_workerThreads,
|
|
92
120
|
extensions: Array.from(
|
|
93
121
|
new Set([
|
|
94
122
|
...config.resolver.sourceExts,
|
|
@@ -97,19 +125,17 @@ export default function createFileMap(
|
|
|
97
125
|
]),
|
|
98
126
|
),
|
|
99
127
|
forceNodeFilesystemAPI: !config.resolver.useWatchman,
|
|
100
|
-
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
101
128
|
healthCheck: config.watcher.healthCheck,
|
|
102
129
|
ignorePattern: getIgnorePattern(config),
|
|
103
130
|
maxWorkers: config.maxWorkers,
|
|
104
|
-
|
|
105
|
-
platforms: [...config.resolver.platforms, MetroFileMap.H.NATIVE_PLATFORM],
|
|
131
|
+
plugins,
|
|
106
132
|
retainAllFiles: true,
|
|
107
133
|
resetCache: config.resetCache,
|
|
108
134
|
rootDir: config.projectRoot,
|
|
109
135
|
roots: config.watchFolders,
|
|
110
|
-
throwOnModuleCollision: options?.throwOnModuleCollision ?? true,
|
|
111
136
|
useWatchman: config.resolver.useWatchman,
|
|
112
137
|
watch,
|
|
113
138
|
watchmanDeferStates: config.watcher.watchman.deferStates,
|
|
114
139
|
});
|
|
140
|
+
return {fileMap, hasteMap, dependencyPlugin};
|
|
115
141
|
}
|
|
@@ -20,7 +20,11 @@ var _metroResolver = require("metro-resolver");
|
|
|
20
20
|
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
21
21
|
var _path = _interopRequireDefault(require("path"));
|
|
22
22
|
function _interopRequireDefault(e) {
|
|
23
|
-
return e && e.__esModule
|
|
23
|
+
return e && e.__esModule
|
|
24
|
+
? e
|
|
25
|
+
: {
|
|
26
|
+
default: e,
|
|
27
|
+
};
|
|
24
28
|
}
|
|
25
29
|
const { createActionStartEntry, createActionEndEntry, log } = _metroCore.Logger;
|
|
26
30
|
const NULL_PLATFORM = Symbol();
|
|
@@ -34,6 +38,7 @@ function getOrCreateMap(map, field) {
|
|
|
34
38
|
}
|
|
35
39
|
class DependencyGraph extends _events.default {
|
|
36
40
|
#packageCache;
|
|
41
|
+
#dependencyPlugin;
|
|
37
42
|
constructor(config, options) {
|
|
38
43
|
super();
|
|
39
44
|
this._config = config;
|
|
@@ -45,32 +50,34 @@ class DependencyGraph extends _events.default {
|
|
|
45
50
|
type: "dep_graph_loading",
|
|
46
51
|
hasReducedPerformance: !!hasReducedPerformance,
|
|
47
52
|
});
|
|
48
|
-
const fileMap = (0, _createFileMap.default)(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
const { fileMap, hasteMap, dependencyPlugin } = (0, _createFileMap.default)(
|
|
54
|
+
config,
|
|
55
|
+
{
|
|
56
|
+
throwOnModuleCollision: false,
|
|
57
|
+
watch,
|
|
58
|
+
},
|
|
59
|
+
);
|
|
52
60
|
fileMap.setMaxListeners(1000);
|
|
53
61
|
this._haste = fileMap;
|
|
54
62
|
this._haste.on("status", (status) => this._onWatcherStatus(status));
|
|
55
|
-
this._initializedPromise = fileMap
|
|
56
|
-
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
config.reporter.update({
|
|
60
|
-
type: "dep_graph_loaded",
|
|
61
|
-
});
|
|
62
|
-
this._fileSystem = fileSystem;
|
|
63
|
-
this._hasteMap = hasteMap;
|
|
64
|
-
this._haste.on("change", (changeEvent) =>
|
|
65
|
-
this._onHasteChange(changeEvent),
|
|
66
|
-
);
|
|
67
|
-
this._haste.on("healthCheck", (result) =>
|
|
68
|
-
this._onWatcherHealthCheck(result),
|
|
69
|
-
);
|
|
70
|
-
this._resolutionCache = new Map();
|
|
71
|
-
this.#packageCache = this._createPackageCache();
|
|
72
|
-
this._createModuleResolver();
|
|
63
|
+
this._initializedPromise = fileMap.build().then(({ fileSystem }) => {
|
|
64
|
+
log(createActionEndEntry(initializingMetroLogEntry));
|
|
65
|
+
config.reporter.update({
|
|
66
|
+
type: "dep_graph_loaded",
|
|
73
67
|
});
|
|
68
|
+
this._fileSystem = fileSystem;
|
|
69
|
+
this._hasteMap = hasteMap;
|
|
70
|
+
this.#dependencyPlugin = dependencyPlugin;
|
|
71
|
+
this._haste.on("change", (changeEvent) =>
|
|
72
|
+
this._onHasteChange(changeEvent),
|
|
73
|
+
);
|
|
74
|
+
this._haste.on("healthCheck", (result) =>
|
|
75
|
+
this._onWatcherHealthCheck(result),
|
|
76
|
+
);
|
|
77
|
+
this._resolutionCache = new Map();
|
|
78
|
+
this.#packageCache = this._createPackageCache();
|
|
79
|
+
this._createModuleResolver();
|
|
80
|
+
});
|
|
74
81
|
}
|
|
75
82
|
_onWatcherHealthCheck(result) {
|
|
76
83
|
this._config.reporter.update({
|
|
@@ -87,11 +94,6 @@ class DependencyGraph extends _events.default {
|
|
|
87
94
|
async ready() {
|
|
88
95
|
await this._initializedPromise;
|
|
89
96
|
}
|
|
90
|
-
static async load(config, options) {
|
|
91
|
-
const self = new DependencyGraph(config, options);
|
|
92
|
-
await self.ready();
|
|
93
|
-
return self;
|
|
94
|
-
}
|
|
95
97
|
_onHasteChange({ eventsQueue }) {
|
|
96
98
|
this._resolutionCache = new Map();
|
|
97
99
|
eventsQueue.forEach(({ filePath }) =>
|
|
@@ -124,7 +126,7 @@ class DependencyGraph extends _events.default {
|
|
|
124
126
|
},
|
|
125
127
|
disableHierarchicalLookup:
|
|
126
128
|
this._config.resolver.disableHierarchicalLookup,
|
|
127
|
-
doesFileExist: this.
|
|
129
|
+
doesFileExist: this.doesFileExist,
|
|
128
130
|
emptyModulePath: this._config.resolver.emptyModulePath,
|
|
129
131
|
extraNodeModules: this._config.resolver.extraNodeModules,
|
|
130
132
|
fileSystemLookup,
|
|
@@ -157,6 +159,8 @@ class DependencyGraph extends _events.default {
|
|
|
157
159
|
this._config.resolver.unstable_conditionsByPlatform,
|
|
158
160
|
unstable_enablePackageExports:
|
|
159
161
|
this._config.resolver.unstable_enablePackageExports,
|
|
162
|
+
unstable_incrementalResolution:
|
|
163
|
+
this._config.resolver.unstable_incrementalResolution,
|
|
160
164
|
});
|
|
161
165
|
}
|
|
162
166
|
_getClosestPackage(absoluteModulePath) {
|
|
@@ -276,18 +280,27 @@ class DependencyGraph extends _events.default {
|
|
|
276
280
|
mapByPlatform.set(platformKey, resolution);
|
|
277
281
|
return resolution;
|
|
278
282
|
}
|
|
279
|
-
|
|
283
|
+
doesFileExist = (filePath) => {
|
|
280
284
|
return this._fileSystem.exists(filePath);
|
|
281
285
|
};
|
|
282
286
|
getHasteName(filePath) {
|
|
283
|
-
const hasteName = this.
|
|
287
|
+
const hasteName = this._hasteMap.getModuleNameByPath(filePath);
|
|
284
288
|
if (hasteName) {
|
|
285
289
|
return hasteName;
|
|
286
290
|
}
|
|
287
291
|
return _path.default.relative(this._config.projectRoot, filePath);
|
|
288
292
|
}
|
|
289
293
|
getDependencies(filePath) {
|
|
290
|
-
|
|
294
|
+
if (!this.#dependencyPlugin) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
"getDependencies called but extractDependencies is false",
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
return Array.from(
|
|
300
|
+
(0, _nullthrows.default)(
|
|
301
|
+
this.#dependencyPlugin.getDependencies(filePath),
|
|
302
|
+
),
|
|
303
|
+
);
|
|
291
304
|
}
|
|
292
305
|
}
|
|
293
306
|
exports.default = DependencyGraph;
|