metro 0.83.3 → 0.84.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 +28 -25
- package/src/Assets.js +42 -29
- package/src/Assets.js.flow +26 -15
- package/src/Bundler/util.js +25 -21
- package/src/Bundler/util.js.flow +2 -2
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.js +4 -4
- package/src/DeltaBundler/DeltaCalculator.js.flow +8 -8
- package/src/DeltaBundler/Graph.js +16 -16
- package/src/DeltaBundler/Graph.js.flow +30 -30
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +8 -8
- package/src/DeltaBundler/Serializers/helpers/js.js +25 -21
- 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 +25 -21
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +5 -5
- 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.flow +3 -3
- 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 +4 -4
- package/src/DeltaBundler/buildSubgraph.js.flow +8 -8
- package/src/DeltaBundler/types.js.flow +36 -34
- package/src/DeltaBundler.js.flow +2 -2
- package/src/HmrServer.js +34 -29
- package/src/HmrServer.js.flow +17 -12
- package/src/IncrementalBundler.js +29 -21
- package/src/IncrementalBundler.js.flow +13 -9
- package/src/ModuleGraph/worker/JsFileWrapping.js +25 -21
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +10 -5
- package/src/ModuleGraph/worker/collectDependencies.js +25 -21
- package/src/ModuleGraph/worker/collectDependencies.js.flow +27 -21
- package/src/ModuleGraph/worker/generateImportNames.js.flow +4 -2
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +7 -3
- package/src/Server/MultipartResponse.js.flow +1 -1
- package/src/Server/symbolicate.js.flow +4 -4
- package/src/Server.js +139 -39
- package/src/Server.js.flow +158 -47
- package/src/cli/parseKeyValueParamArray.js.flow +1 -1
- package/src/cli-utils.js.flow +2 -2
- package/src/commands/build.js.flow +11 -10
- 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 +30 -26
- 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.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.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 +25 -21
- 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.flow +1 -1
- package/src/lib/BatchProcessor.js +5 -2
- 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.flow +1 -1
- package/src/lib/TerminalReporter.js +31 -27
- package/src/lib/TerminalReporter.js.flow +15 -15
- package/src/lib/contextModule.js.flow +1 -1
- package/src/lib/contextModuleTemplates.js +25 -21
- package/src/lib/countLines.js +4 -3
- package/src/lib/countLines.js.flow +3 -4
- package/src/lib/createWebsocketServer.js +9 -2
- package/src/lib/createWebsocketServer.js.flow +16 -9
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/getAppendScripts.js.flow +4 -4
- 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 +36 -22
- package/src/lib/getPrependedScripts.js.flow +10 -3
- package/src/lib/logToConsole.js.flow +2 -2
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +25 -21
- 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 +25 -21
- package/src/lib/pathUtils.js.flow +1 -1
- package/src/lib/reporting.js.flow +4 -4
- package/src/lib/transformHelpers.js +11 -9
- package/src/lib/transformHelpers.js.flow +17 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.js +48 -42
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +35 -32
- package/src/node-haste/DependencyGraph/createFileMap.js +56 -38
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +44 -18
- package/src/node-haste/DependencyGraph.js +40 -31
- package/src/node-haste/DependencyGraph.js.flow +35 -37
- package/src/node-haste/lib/AssetPaths.js +2 -2
- package/src/node-haste/lib/AssetPaths.js.flow +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.js +6 -6
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +4 -4
- package/src/shared/output/RamBundle/as-assets.js.flow +6 -6
- 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.flow +5 -5
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.js.flow +1 -1
- package/src/shared/output/bundle.flow.js.flow +3 -3
- package/src/shared/output/meta.js +2 -2
- package/src/shared/output/meta.js.flow +1 -1
- package/src/shared/output/writeFile.js +8 -3
- 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
|
@@ -73,12 +73,12 @@ export type Result<T> = {
|
|
|
73
73
|
deleted: Set<string>,
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
/*
|
|
77
77
|
* Internal data structure that the traversal logic uses to know which of the
|
|
78
78
|
* files have been modified. This allows to return the added modules before the
|
|
79
79
|
* modified ones (which is useful for things like Hot Module Reloading).
|
|
80
|
-
|
|
81
|
-
type Delta<T> =
|
|
80
|
+
*/
|
|
81
|
+
type Delta<T> = Readonly<{
|
|
82
82
|
// `added` and `deleted` are mutually exclusive.
|
|
83
83
|
// Internally, a module can be in both `touched` and (either) `added` or
|
|
84
84
|
// `deleted`. Before returning the result, we'll calculate
|
|
@@ -87,15 +87,15 @@ type Delta<T> = $ReadOnly<{
|
|
|
87
87
|
touched: Set<string>,
|
|
88
88
|
deleted: Set<string>,
|
|
89
89
|
|
|
90
|
-
updatedModuleData:
|
|
90
|
+
updatedModuleData: ReadonlyMap<string, ModuleData<T>>,
|
|
91
91
|
baseModuleData: Map<string, ModuleData<T>>,
|
|
92
|
-
errors:
|
|
92
|
+
errors: ReadonlyMap<string, Error>,
|
|
93
93
|
}>;
|
|
94
94
|
|
|
95
|
-
type InternalOptions<T> =
|
|
95
|
+
type InternalOptions<T> = Readonly<{
|
|
96
96
|
lazy: boolean,
|
|
97
|
-
onDependencyAdd: () =>
|
|
98
|
-
onDependencyAdded: () =>
|
|
97
|
+
onDependencyAdd: () => unknown,
|
|
98
|
+
onDependencyAdded: () => unknown,
|
|
99
99
|
resolve: Options<T>['resolve'],
|
|
100
100
|
transform: Options<T>['transform'],
|
|
101
101
|
shallow: boolean,
|
|
@@ -113,11 +113,11 @@ function getInternalOptions<T>({
|
|
|
113
113
|
|
|
114
114
|
return {
|
|
115
115
|
lazy,
|
|
116
|
-
transform,
|
|
117
|
-
resolve,
|
|
118
116
|
onDependencyAdd: () => onProgress && onProgress(numProcessed, ++total),
|
|
119
117
|
onDependencyAdded: () => onProgress && onProgress(++numProcessed, total),
|
|
118
|
+
resolve,
|
|
120
119
|
shallow,
|
|
120
|
+
transform,
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -130,12 +130,12 @@ function isWeakOrLazy<T>(
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
export class Graph<T = MixedOutput> {
|
|
133
|
-
+entryPoints:
|
|
133
|
+
+entryPoints: ReadonlySet<string>;
|
|
134
134
|
+transformOptions: TransformInputOptions;
|
|
135
135
|
+dependencies: Dependencies<T> = new Map();
|
|
136
136
|
+#importBundleNodes: Map<
|
|
137
137
|
string,
|
|
138
|
-
|
|
138
|
+
Readonly<{
|
|
139
139
|
inverseDependencies: CountingSet<string>,
|
|
140
140
|
}>,
|
|
141
141
|
> = new Map();
|
|
@@ -169,7 +169,7 @@ export class Graph<T = MixedOutput> {
|
|
|
169
169
|
* since the last traversal.
|
|
170
170
|
*/
|
|
171
171
|
async traverseDependencies(
|
|
172
|
-
paths:
|
|
172
|
+
paths: ReadonlyArray<string>,
|
|
173
173
|
options: Options<T>,
|
|
174
174
|
): Promise<Result<T>> {
|
|
175
175
|
const internalOptions = getInternalOptions(options);
|
|
@@ -246,11 +246,11 @@ export class Graph<T = MixedOutput> {
|
|
|
246
246
|
// Roll back to base before re-throwing.
|
|
247
247
|
const rollbackDelta: Delta<T> = {
|
|
248
248
|
added: delta.added,
|
|
249
|
+
baseModuleData: new Map(),
|
|
249
250
|
deleted: delta.deleted,
|
|
251
|
+
errors: new Map(),
|
|
250
252
|
touched: new Set(),
|
|
251
253
|
updatedModuleData: delta.baseModuleData,
|
|
252
|
-
baseModuleData: new Map(),
|
|
253
|
-
errors: new Map(),
|
|
254
254
|
};
|
|
255
255
|
for (const modified of modifiedPathsInBaseGraph) {
|
|
256
256
|
const module = this.dependencies.get(modified);
|
|
@@ -295,8 +295,8 @@ export class Graph<T = MixedOutput> {
|
|
|
295
295
|
|
|
296
296
|
return {
|
|
297
297
|
added,
|
|
298
|
-
modified,
|
|
299
298
|
deleted: delta.deleted,
|
|
299
|
+
modified,
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
302
|
|
|
@@ -338,39 +338,39 @@ export class Graph<T = MixedOutput> {
|
|
|
338
338
|
|
|
339
339
|
return {
|
|
340
340
|
added: this.dependencies,
|
|
341
|
-
modified: new Map(),
|
|
342
341
|
deleted: new Set(),
|
|
342
|
+
modified: new Map(),
|
|
343
343
|
};
|
|
344
344
|
}
|
|
345
345
|
|
|
346
346
|
async _buildDelta(
|
|
347
|
-
pathsToVisit:
|
|
347
|
+
pathsToVisit: ReadonlySet<string>,
|
|
348
348
|
options: InternalOptions<T>,
|
|
349
349
|
moduleFilter?: (path: string) => boolean,
|
|
350
350
|
): Promise<Delta<T>> {
|
|
351
351
|
const subGraph = await buildSubgraph(pathsToVisit, this.#resolvedContexts, {
|
|
352
352
|
resolve: options.resolve,
|
|
353
|
-
transform: async (absolutePath, requireContext) => {
|
|
354
|
-
options.onDependencyAdd();
|
|
355
|
-
const result = await options.transform(absolutePath, requireContext);
|
|
356
|
-
options.onDependencyAdded();
|
|
357
|
-
return result;
|
|
358
|
-
},
|
|
359
353
|
shouldTraverse: (dependency: ResolvedDependency) => {
|
|
360
354
|
if (options.shallow || isWeakOrLazy(dependency, options)) {
|
|
361
355
|
return false;
|
|
362
356
|
}
|
|
363
357
|
return moduleFilter == null || moduleFilter(dependency.absolutePath);
|
|
364
358
|
},
|
|
359
|
+
transform: async (absolutePath, requireContext) => {
|
|
360
|
+
options.onDependencyAdd();
|
|
361
|
+
const result = await options.transform(absolutePath, requireContext);
|
|
362
|
+
options.onDependencyAdded();
|
|
363
|
+
return result;
|
|
364
|
+
},
|
|
365
365
|
});
|
|
366
366
|
|
|
367
367
|
return {
|
|
368
368
|
added: new Set(),
|
|
369
|
-
touched: new Set(),
|
|
370
|
-
deleted: new Set(),
|
|
371
|
-
updatedModuleData: subGraph.moduleData,
|
|
372
369
|
baseModuleData: new Map(),
|
|
370
|
+
deleted: new Set(),
|
|
373
371
|
errors: subGraph.errors,
|
|
372
|
+
touched: new Set(),
|
|
373
|
+
updatedModuleData: subGraph.moduleData,
|
|
374
374
|
};
|
|
375
375
|
}
|
|
376
376
|
|
|
@@ -378,7 +378,7 @@ export class Graph<T = MixedOutput> {
|
|
|
378
378
|
path: string,
|
|
379
379
|
delta: Delta<T>,
|
|
380
380
|
options: InternalOptions<T>,
|
|
381
|
-
commitOptions:
|
|
381
|
+
commitOptions: Readonly<{
|
|
382
382
|
onlyRemove: boolean,
|
|
383
383
|
}> = {onlyRemove: false},
|
|
384
384
|
): Module<T> {
|
|
@@ -775,9 +775,9 @@ export class Graph<T = MixedOutput> {
|
|
|
775
775
|
}
|
|
776
776
|
return {
|
|
777
777
|
dependencies: new Map(dependencies),
|
|
778
|
-
resolvedContexts,
|
|
779
778
|
getSource,
|
|
780
779
|
output,
|
|
780
|
+
resolvedContexts,
|
|
781
781
|
unstable_transformResultKey,
|
|
782
782
|
};
|
|
783
783
|
}
|
|
@@ -936,7 +936,7 @@ export class Graph<T = MixedOutput> {
|
|
|
936
936
|
function dependenciesEqual(
|
|
937
937
|
a: Dependency,
|
|
938
938
|
b: Dependency,
|
|
939
|
-
options:
|
|
939
|
+
options: Readonly<{lazy: boolean, ...}>,
|
|
940
940
|
): boolean {
|
|
941
941
|
return (
|
|
942
942
|
a === b ||
|
|
@@ -22,7 +22,7 @@ import processModules from './helpers/processModules';
|
|
|
22
22
|
|
|
23
23
|
export default function baseJSBundle(
|
|
24
24
|
entryPoint: string,
|
|
25
|
-
preModules:
|
|
25
|
+
preModules: ReadonlyArray<Module<>>,
|
|
26
26
|
graph: ReadOnlyGraph<>,
|
|
27
27
|
options: SerializerOptions,
|
|
28
28
|
): Bundle {
|
|
@@ -20,10 +20,10 @@ type Options = {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export default async function getAllFiles(
|
|
23
|
-
pre:
|
|
23
|
+
pre: ReadonlyArray<Module<>>,
|
|
24
24
|
graph: ReadOnlyGraph<>,
|
|
25
25
|
options: Options,
|
|
26
|
-
): Promise
|
|
26
|
+
): Promise<ReadonlyArray<string>> {
|
|
27
27
|
const modules = graph.dependencies;
|
|
28
28
|
const {processModuleFilter} = options;
|
|
29
29
|
|
|
@@ -18,7 +18,7 @@ import path from 'path';
|
|
|
18
18
|
|
|
19
19
|
type Options = {
|
|
20
20
|
+processModuleFilter: (module: Module<>) => boolean,
|
|
21
|
-
assetPlugins:
|
|
21
|
+
assetPlugins: ReadonlyArray<string>,
|
|
22
22
|
platform: ?string,
|
|
23
23
|
projectRoot: string,
|
|
24
24
|
publicPath: string,
|
|
@@ -27,7 +27,7 @@ type Options = {
|
|
|
27
27
|
export default async function getAssets(
|
|
28
28
|
dependencies: ReadOnlyDependencies<>,
|
|
29
29
|
options: Options,
|
|
30
|
-
): Promise
|
|
30
|
+
): Promise<ReadonlyArray<AssetData>> {
|
|
31
31
|
const promises = [];
|
|
32
32
|
const {processModuleFilter} = options;
|
|
33
33
|
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
|
|
18
18
|
import {getJsOutput, isJsModule} from './helpers/js';
|
|
19
19
|
|
|
20
|
-
export type ExplodedSourceMap =
|
|
20
|
+
export type ExplodedSourceMap = ReadonlyArray<{
|
|
21
21
|
+map: Array<MetroSourceMapSegmentTuple>,
|
|
22
22
|
+firstLine1Based: number,
|
|
23
23
|
+functionMap: ?FBSourceFunctionMap,
|
|
@@ -25,7 +25,7 @@ export type ExplodedSourceMap = $ReadOnlyArray<{
|
|
|
25
25
|
}>;
|
|
26
26
|
|
|
27
27
|
export function getExplodedSourceMap(
|
|
28
|
-
modules:
|
|
28
|
+
modules: ReadonlyArray<Module<>>,
|
|
29
29
|
options: {
|
|
30
30
|
+processModuleFilter: (module: Module<>) => boolean,
|
|
31
31
|
},
|
|
@@ -22,7 +22,7 @@ import {sourceMapObject} from './sourceMapObject';
|
|
|
22
22
|
import nullthrows from 'nullthrows';
|
|
23
23
|
import path from 'path';
|
|
24
24
|
|
|
25
|
-
type Options =
|
|
25
|
+
type Options = Readonly<{
|
|
26
26
|
...SerializerOptions,
|
|
27
27
|
...SourceMapGeneratorOptions,
|
|
28
28
|
getTransformOptions: ?GetTransformOptions,
|
|
@@ -31,18 +31,18 @@ type Options = $ReadOnly<{
|
|
|
31
31
|
|
|
32
32
|
export type RamBundleInfo = {
|
|
33
33
|
getDependencies: string => Set<string>,
|
|
34
|
-
startupModules:
|
|
35
|
-
lazyModules:
|
|
34
|
+
startupModules: ReadonlyArray<ModuleTransportLike>,
|
|
35
|
+
lazyModules: ReadonlyArray<ModuleTransportLike>,
|
|
36
36
|
groups: Map<number, Set<number>>,
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export default async function getRamBundleInfo(
|
|
40
40
|
entryPoint: string,
|
|
41
|
-
pre:
|
|
41
|
+
pre: ReadonlyArray<Module<>>,
|
|
42
42
|
graph: ReadOnlyGraph<>,
|
|
43
43
|
options: Options,
|
|
44
44
|
): Promise<RamBundleInfo> {
|
|
45
|
-
let modules:
|
|
45
|
+
let modules: ReadonlyArray<Module<>> = [
|
|
46
46
|
...pre,
|
|
47
47
|
...graph.dependencies.values(),
|
|
48
48
|
];
|
|
@@ -142,9 +142,9 @@ async function _getRamOptions(
|
|
|
142
142
|
getDependencies: string => Iterable<string>,
|
|
143
143
|
getTransformOptions: ?GetTransformOptions,
|
|
144
144
|
): Promise<
|
|
145
|
-
|
|
146
|
-
preloadedModules:
|
|
147
|
-
ramGroups:
|
|
145
|
+
Readonly<{
|
|
146
|
+
preloadedModules: Readonly<{[string]: true, ...}>,
|
|
147
|
+
ramGroups: ReadonlyArray<string>,
|
|
148
148
|
}>,
|
|
149
149
|
> {
|
|
150
150
|
if (getTransformOptions == null) {
|
|
@@ -13,28 +13,32 @@ var _invariant = _interopRequireDefault(require("invariant"));
|
|
|
13
13
|
var jscSafeUrl = _interopRequireWildcard(require("jsc-safe-url"));
|
|
14
14
|
var _metroTransformPlugins = require("metro-transform-plugins");
|
|
15
15
|
var _path = _interopRequireDefault(require("path"));
|
|
16
|
-
function
|
|
17
|
-
if ("function"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var n = { __proto__: null },
|
|
31
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
32
|
-
for (var u in e)
|
|
33
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
34
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
35
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
16
|
+
function _interopRequireWildcard(e, t) {
|
|
17
|
+
if ("function" == typeof WeakMap)
|
|
18
|
+
var r = new WeakMap(),
|
|
19
|
+
n = new WeakMap();
|
|
20
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
21
|
+
if (!t && e && e.__esModule) return e;
|
|
22
|
+
var o,
|
|
23
|
+
i,
|
|
24
|
+
f = { __proto__: null, default: e };
|
|
25
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
26
|
+
return f;
|
|
27
|
+
if ((o = t ? n : r)) {
|
|
28
|
+
if (o.has(e)) return o.get(e);
|
|
29
|
+
o.set(e, f);
|
|
36
30
|
}
|
|
37
|
-
|
|
31
|
+
for (const t in e)
|
|
32
|
+
"default" !== t &&
|
|
33
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
34
|
+
((i =
|
|
35
|
+
(o = Object.defineProperty) &&
|
|
36
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
37
|
+
(i.get || i.set)
|
|
38
|
+
? o(f, t, i)
|
|
39
|
+
: (f[t] = e[t]));
|
|
40
|
+
return f;
|
|
41
|
+
})(e, t);
|
|
38
42
|
}
|
|
39
43
|
function _interopRequireDefault(e) {
|
|
40
44
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -19,7 +19,7 @@ import * as jscSafeUrl from 'jsc-safe-url';
|
|
|
19
19
|
import {addParamsToDefineCall} from 'metro-transform-plugins';
|
|
20
20
|
import path from 'path';
|
|
21
21
|
|
|
22
|
-
export type Options =
|
|
22
|
+
export type Options = Readonly<{
|
|
23
23
|
createModuleId: string => number | string,
|
|
24
24
|
dev: boolean,
|
|
25
25
|
includeAsyncPaths: boolean,
|
|
@@ -43,10 +43,10 @@ export function wrapModule(module: Module<>, options: Options): string {
|
|
|
43
43
|
export function getModuleParams(
|
|
44
44
|
module: Module<>,
|
|
45
45
|
options: Options,
|
|
46
|
-
): Array<
|
|
46
|
+
): Array<unknown> {
|
|
47
47
|
const moduleId = options.createModuleId(module.path);
|
|
48
48
|
|
|
49
|
-
const paths: {[moduleID: number | string]:
|
|
49
|
+
const paths: {[moduleID: number | string]: unknown} = {};
|
|
50
50
|
let hasPaths = false;
|
|
51
51
|
const dependencyMapArray = Array.from(module.dependencies.values()).map(
|
|
52
52
|
dependency => {
|
|
@@ -118,8 +118,8 @@ export function getModuleParams(
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
export function getJsOutput(
|
|
121
|
-
module:
|
|
122
|
-
output:
|
|
121
|
+
module: Readonly<{
|
|
122
|
+
output: ReadonlyArray<MixedOutput>,
|
|
123
123
|
path?: string,
|
|
124
124
|
...
|
|
125
125
|
}>,
|
|
@@ -133,7 +133,7 @@ export function getJsOutput(
|
|
|
133
133
|
} has ${jsModules.length} JS outputs.`,
|
|
134
134
|
);
|
|
135
135
|
|
|
136
|
-
const jsOutput: JsOutput =
|
|
136
|
+
const jsOutput: JsOutput = jsModules[0] as any;
|
|
137
137
|
|
|
138
138
|
invariant(
|
|
139
139
|
Number.isFinite(jsOutput.data.lineCount),
|
|
@@ -14,7 +14,7 @@ import type {Module} from '../../types';
|
|
|
14
14
|
import {isJsModule, wrapModule} from './js';
|
|
15
15
|
|
|
16
16
|
export default function processModules(
|
|
17
|
-
modules:
|
|
17
|
+
modules: ReadonlyArray<Module<>>,
|
|
18
18
|
{
|
|
19
19
|
filter = () => true,
|
|
20
20
|
createModuleId,
|
|
@@ -23,7 +23,7 @@ export default function processModules(
|
|
|
23
23
|
projectRoot,
|
|
24
24
|
serverRoot,
|
|
25
25
|
sourceUrl,
|
|
26
|
-
}:
|
|
26
|
+
}: Readonly<{
|
|
27
27
|
filter?: (module: Module<>) => boolean,
|
|
28
28
|
createModuleId: string => number,
|
|
29
29
|
dev: boolean,
|
|
@@ -32,7 +32,7 @@ export default function processModules(
|
|
|
32
32
|
serverRoot: string,
|
|
33
33
|
sourceUrl: ?string,
|
|
34
34
|
}>,
|
|
35
|
-
):
|
|
35
|
+
): ReadonlyArray<[Module<>, string]> {
|
|
36
36
|
return [...modules]
|
|
37
37
|
.filter(isJsModule)
|
|
38
38
|
.filter(filter)
|
|
@@ -11,28 +11,32 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
11
11
|
function _interopRequireDefault(e) {
|
|
12
12
|
return e && e.__esModule ? e : { default: e };
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
if ("function"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var n = { __proto__: null },
|
|
29
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
30
|
-
for (var u in e)
|
|
31
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
32
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
33
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
14
|
+
function _interopRequireWildcard(e, t) {
|
|
15
|
+
if ("function" == typeof WeakMap)
|
|
16
|
+
var r = new WeakMap(),
|
|
17
|
+
n = new WeakMap();
|
|
18
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
19
|
+
if (!t && e && e.__esModule) return e;
|
|
20
|
+
var o,
|
|
21
|
+
i,
|
|
22
|
+
f = { __proto__: null, default: e };
|
|
23
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
24
|
+
return f;
|
|
25
|
+
if ((o = t ? n : r)) {
|
|
26
|
+
if (o.has(e)) return o.get(e);
|
|
27
|
+
o.set(e, f);
|
|
34
28
|
}
|
|
35
|
-
|
|
29
|
+
for (const t in e)
|
|
30
|
+
"default" !== t &&
|
|
31
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
32
|
+
((i =
|
|
33
|
+
(o = Object.defineProperty) &&
|
|
34
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
35
|
+
(i.get || i.set)
|
|
36
|
+
? o(f, t, i)
|
|
37
|
+
: (f[t] = e[t]));
|
|
38
|
+
return f;
|
|
39
|
+
})(e, t);
|
|
36
40
|
}
|
|
37
41
|
const debug = require("debug")("Metro:HMR");
|
|
38
42
|
function generateModules(sourceModules, graph, options) {
|
|
@@ -20,7 +20,7 @@ import path from 'path';
|
|
|
20
20
|
// eslint-disable-next-line import/no-commonjs
|
|
21
21
|
const debug = require('debug')('Metro:HMR');
|
|
22
22
|
|
|
23
|
-
type Options =
|
|
23
|
+
type Options = Readonly<{
|
|
24
24
|
clientUrl: URL,
|
|
25
25
|
createModuleId: string => number,
|
|
26
26
|
includeAsyncPaths: boolean,
|
|
@@ -33,7 +33,7 @@ function generateModules(
|
|
|
33
33
|
sourceModules: Iterable<Module<>>,
|
|
34
34
|
graph: ReadOnlyGraph<>,
|
|
35
35
|
options: Options,
|
|
36
|
-
):
|
|
36
|
+
): ReadonlyArray<HmrModule> {
|
|
37
37
|
const modules = [];
|
|
38
38
|
|
|
39
39
|
for (const module of sourceModules) {
|
|
@@ -148,9 +148,9 @@ export default function hmrJSBundle(
|
|
|
148
148
|
graph: ReadOnlyGraph<>,
|
|
149
149
|
options: Options,
|
|
150
150
|
): {
|
|
151
|
-
+added:
|
|
152
|
-
+deleted:
|
|
153
|
-
+modified:
|
|
151
|
+
+added: ReadonlyArray<HmrModule>,
|
|
152
|
+
+deleted: ReadonlyArray<number>,
|
|
153
|
+
+modified: ReadonlyArray<HmrModule>,
|
|
154
154
|
} {
|
|
155
155
|
return {
|
|
156
156
|
added: generateModules(delta.added.values(), graph, options),
|
|
@@ -15,7 +15,7 @@ import getSourceMapInfo from './helpers/getSourceMapInfo';
|
|
|
15
15
|
import {isJsModule} from './helpers/js';
|
|
16
16
|
import {fromRawMappings, fromRawMappingsNonBlocking} from 'metro-source-map';
|
|
17
17
|
|
|
18
|
-
export type SourceMapGeneratorOptions =
|
|
18
|
+
export type SourceMapGeneratorOptions = Readonly<{
|
|
19
19
|
excludeSource: boolean,
|
|
20
20
|
processModuleFilter: (module: Module<>) => boolean,
|
|
21
21
|
shouldAddToIgnoreList: (module: Module<>) => boolean,
|
|
@@ -24,8 +24,8 @@ export type SourceMapGeneratorOptions = $ReadOnly<{
|
|
|
24
24
|
|
|
25
25
|
function getSourceMapInfosImpl(
|
|
26
26
|
isBlocking: boolean,
|
|
27
|
-
onDone: (
|
|
28
|
-
modules:
|
|
27
|
+
onDone: (ReadonlyArray<ReturnType<typeof getSourceMapInfo>>) => void,
|
|
28
|
+
modules: ReadonlyArray<Module<>>,
|
|
29
29
|
options: SourceMapGeneratorOptions,
|
|
30
30
|
): void {
|
|
31
31
|
const sourceMapInfos = [];
|
|
@@ -76,7 +76,7 @@ function getSourceMapInfosImpl(
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
function sourceMapGenerator(
|
|
79
|
-
modules:
|
|
79
|
+
modules: ReadonlyArray<Module<>>,
|
|
80
80
|
options: SourceMapGeneratorOptions,
|
|
81
81
|
): ReturnType<typeof fromRawMappings> {
|
|
82
82
|
let sourceMapInfos;
|
|
@@ -97,11 +97,11 @@ function sourceMapGenerator(
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
async function sourceMapGeneratorNonBlocking(
|
|
100
|
-
modules:
|
|
100
|
+
modules: ReadonlyArray<Module<>>,
|
|
101
101
|
options: SourceMapGeneratorOptions,
|
|
102
102
|
): ReturnType<typeof fromRawMappingsNonBlocking> {
|
|
103
103
|
const sourceMapInfos = await new Promise<
|
|
104
|
-
|
|
104
|
+
ReadonlyArray<ReturnType<typeof getSourceMapInfo>>,
|
|
105
105
|
>(resolve => {
|
|
106
106
|
getSourceMapInfosImpl(false, resolve, modules, options);
|
|
107
107
|
});
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from './sourceMapGenerator';
|
|
20
20
|
|
|
21
21
|
function sourceMapObject(
|
|
22
|
-
modules:
|
|
22
|
+
modules: ReadonlyArray<Module<>>,
|
|
23
23
|
options: SourceMapGeneratorOptions,
|
|
24
24
|
): MixedSourceMap {
|
|
25
25
|
const generator = sourceMapGenerator(modules, options);
|
|
@@ -29,7 +29,7 @@ function sourceMapObject(
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
async function sourceMapObjectNonBlocking(
|
|
32
|
-
modules:
|
|
32
|
+
modules: ReadonlyArray<Module<>>,
|
|
33
33
|
options: SourceMapGeneratorOptions,
|
|
34
34
|
): Promise<MixedSourceMap> {
|
|
35
35
|
const generator = await sourceMapGeneratorNonBlocking(modules, options);
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from './sourceMapGenerator';
|
|
19
19
|
|
|
20
20
|
function sourceMapString(
|
|
21
|
-
modules:
|
|
21
|
+
modules: ReadonlyArray<Module<>>,
|
|
22
22
|
options: SourceMapGeneratorOptions,
|
|
23
23
|
): string {
|
|
24
24
|
return sourceMapGenerator(modules, options).toString(undefined, {
|
|
@@ -27,7 +27,7 @@ function sourceMapString(
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
async function sourceMapStringNonBlocking(
|
|
30
|
-
modules:
|
|
30
|
+
modules: ReadonlyArray<Module<>>,
|
|
31
31
|
options: SourceMapGeneratorOptions,
|
|
32
32
|
): Promise<string> {
|
|
33
33
|
const generator = await sourceMapGeneratorNonBlocking(modules, options);
|
|
@@ -26,7 +26,7 @@ import path from 'path';
|
|
|
26
26
|
const debug = require('debug')('Metro:Transformer');
|
|
27
27
|
|
|
28
28
|
type GetOrComputeSha1Fn = string => Promise<
|
|
29
|
-
|
|
29
|
+
Readonly<{content?: Buffer, sha1: string}>,
|
|
30
30
|
>;
|
|
31
31
|
|
|
32
32
|
export default class Transformer {
|
|
@@ -38,7 +38,7 @@ export default class Transformer {
|
|
|
38
38
|
|
|
39
39
|
constructor(
|
|
40
40
|
config: ConfigT,
|
|
41
|
-
opts:
|
|
41
|
+
opts: Readonly<{getOrComputeSha1: GetOrComputeSha1Fn}>,
|
|
42
42
|
) {
|
|
43
43
|
this._config = config;
|
|
44
44
|
|
|
@@ -160,7 +160,7 @@ export default class Transformer {
|
|
|
160
160
|
|
|
161
161
|
// A valid result from the cache is used directly; otherwise we call into
|
|
162
162
|
// the transformer to computed the corresponding result.
|
|
163
|
-
const data:
|
|
163
|
+
const data: Readonly<{
|
|
164
164
|
result: TransformResult<>,
|
|
165
165
|
sha1: string,
|
|
166
166
|
}> = result
|
|
@@ -95,7 +95,7 @@ class WorkerFarm {
|
|
|
95
95
|
}
|
|
96
96
|
_formatBabelError(err, filename) {
|
|
97
97
|
const error = new TransformError(
|
|
98
|
-
`${err.type
|
|
98
|
+
`${err.type ?? "Error"}${err.message.includes(filename) ? "" : " in " + filename}: ${err.message}`,
|
|
99
99
|
);
|
|
100
100
|
return Object.assign(error, {
|
|
101
101
|
stack: err.stack,
|