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,17 +9,16 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import type {DeltaResult, Options} from './types.flow';
|
|
12
|
+
import type {DeltaResult, Options} from './types';
|
|
15
13
|
import type {RootPerfLogger} from 'metro-config';
|
|
16
14
|
import type {ChangeEvent} from 'metro-file-map';
|
|
17
15
|
|
|
18
16
|
import {Graph} from './Graph';
|
|
17
|
+
import EventEmitter from 'events';
|
|
19
18
|
import path from 'path';
|
|
20
19
|
|
|
20
|
+
// eslint-disable-next-line import/no-commonjs
|
|
21
21
|
const debug = require('debug')('Metro:DeltaCalculator');
|
|
22
|
-
const {EventEmitter} = require('events');
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* This class is in charge of calculating the delta of changed modules that
|
|
@@ -27,7 +26,7 @@ const {EventEmitter} = require('events');
|
|
|
27
26
|
* traverse the files that have been changed between calls and avoid having to
|
|
28
27
|
* traverse the whole dependency tree for trivial small changes.
|
|
29
28
|
*/
|
|
30
|
-
class DeltaCalculator<T> extends EventEmitter {
|
|
29
|
+
export default class DeltaCalculator<T> extends EventEmitter {
|
|
31
30
|
_changeEventSource: EventEmitter;
|
|
32
31
|
_options: Options<T>;
|
|
33
32
|
|
|
@@ -324,5 +323,3 @@ class DeltaCalculator<T> extends EventEmitter {
|
|
|
324
323
|
};
|
|
325
324
|
}
|
|
326
325
|
}
|
|
327
|
-
|
|
328
|
-
module.exports = DeltaCalculator;
|
|
@@ -8,15 +8,11 @@ var _contextModule = require("../lib/contextModule");
|
|
|
8
8
|
var _CountingSet = _interopRequireDefault(require("../lib/CountingSet"));
|
|
9
9
|
var _isResolvedDependency = require("../lib/isResolvedDependency");
|
|
10
10
|
var _buildSubgraph = require("./buildSubgraph");
|
|
11
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
12
|
+
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
11
13
|
function _interopRequireDefault(e) {
|
|
12
|
-
return e && e.__esModule
|
|
13
|
-
? e
|
|
14
|
-
: {
|
|
15
|
-
default: e,
|
|
16
|
-
};
|
|
14
|
+
return e && e.__esModule ? e : { default: e };
|
|
17
15
|
}
|
|
18
|
-
const invariant = require("invariant");
|
|
19
|
-
const nullthrows = require("nullthrows");
|
|
20
16
|
function getInternalOptions({ transform, resolve, onProgress, lazy, shallow }) {
|
|
21
17
|
let numProcessed = 0;
|
|
22
18
|
let total = 0;
|
|
@@ -48,7 +44,7 @@ class Graph {
|
|
|
48
44
|
async traverseDependencies(paths, options) {
|
|
49
45
|
const internalOptions = getInternalOptions(options);
|
|
50
46
|
const modifiedPathsInBaseGraph = new Set(
|
|
51
|
-
paths.filter((path) => this.dependencies.has(path))
|
|
47
|
+
paths.filter((path) => this.dependencies.has(path)),
|
|
52
48
|
);
|
|
53
49
|
const allModifiedPaths = new Set(paths);
|
|
54
50
|
const delta = await this._buildDelta(
|
|
@@ -56,13 +52,15 @@ class Graph {
|
|
|
56
52
|
internalOptions,
|
|
57
53
|
(absolutePath) =>
|
|
58
54
|
!this.dependencies.has(absolutePath) ||
|
|
59
|
-
allModifiedPaths.has(absolutePath)
|
|
55
|
+
allModifiedPaths.has(absolutePath),
|
|
60
56
|
);
|
|
61
57
|
if (delta.errors.size > 0) {
|
|
62
58
|
for (const modified of modifiedPathsInBaseGraph) {
|
|
63
59
|
delta.baseModuleData.set(
|
|
64
60
|
modified,
|
|
65
|
-
this._moduleSnapshot(
|
|
61
|
+
this._moduleSnapshot(
|
|
62
|
+
(0, _nullthrows.default)(this.dependencies.get(modified)),
|
|
63
|
+
),
|
|
66
64
|
);
|
|
67
65
|
}
|
|
68
66
|
}
|
|
@@ -104,15 +102,15 @@ class Graph {
|
|
|
104
102
|
this._recursivelyCommitModule(modified, rollbackDelta, internalOptions);
|
|
105
103
|
}
|
|
106
104
|
this._collectCycles(delta, internalOptions);
|
|
107
|
-
|
|
105
|
+
(0, _invariant.default)(
|
|
108
106
|
rollbackDelta.added.size === 0 && rollbackDelta.deleted.size === 0,
|
|
109
|
-
"attempted to roll back a graph commit but there were still changes"
|
|
107
|
+
"attempted to roll back a graph commit but there were still changes",
|
|
110
108
|
);
|
|
111
109
|
throw error;
|
|
112
110
|
}
|
|
113
111
|
const added = new Map();
|
|
114
112
|
for (const path of delta.added) {
|
|
115
|
-
added.set(path,
|
|
113
|
+
added.set(path, (0, _nullthrows.default)(this.dependencies.get(path)));
|
|
116
114
|
}
|
|
117
115
|
const modified = new Map();
|
|
118
116
|
for (const path of modifiedPathsInBaseGraph) {
|
|
@@ -121,7 +119,10 @@ class Graph {
|
|
|
121
119
|
!delta.deleted.has(path) &&
|
|
122
120
|
!delta.added.has(path)
|
|
123
121
|
) {
|
|
124
|
-
modified.set(
|
|
122
|
+
modified.set(
|
|
123
|
+
path,
|
|
124
|
+
(0, _nullthrows.default)(this.dependencies.get(path)),
|
|
125
|
+
);
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
return {
|
|
@@ -132,9 +133,9 @@ class Graph {
|
|
|
132
133
|
}
|
|
133
134
|
async initialTraverseDependencies(options) {
|
|
134
135
|
const internalOptions = getInternalOptions(options);
|
|
135
|
-
|
|
136
|
+
(0, _invariant.default)(
|
|
136
137
|
this.dependencies.size === 0,
|
|
137
|
-
"initialTraverseDependencies called on nonempty graph"
|
|
138
|
+
"initialTraverseDependencies called on nonempty graph",
|
|
138
139
|
);
|
|
139
140
|
this.#gc.color.clear();
|
|
140
141
|
this.#gc.possibleCycleRoots.clear();
|
|
@@ -176,7 +177,7 @@ class Graph {
|
|
|
176
177
|
}
|
|
177
178
|
return moduleFilter == null || moduleFilter(dependency.absolutePath);
|
|
178
179
|
},
|
|
179
|
-
}
|
|
180
|
+
},
|
|
180
181
|
);
|
|
181
182
|
return {
|
|
182
183
|
added: new Set(),
|
|
@@ -193,14 +194,14 @@ class Graph {
|
|
|
193
194
|
options,
|
|
194
195
|
commitOptions = {
|
|
195
196
|
onlyRemove: false,
|
|
196
|
-
}
|
|
197
|
+
},
|
|
197
198
|
) {
|
|
198
199
|
if (delta.errors.has(path)) {
|
|
199
200
|
throw delta.errors.get(path);
|
|
200
201
|
}
|
|
201
202
|
const previousModule = this.dependencies.get(path);
|
|
202
|
-
const currentModule =
|
|
203
|
-
delta.updatedModuleData.get(path) ?? delta.baseModuleData.get(path)
|
|
203
|
+
const currentModule = (0, _nullthrows.default)(
|
|
204
|
+
delta.updatedModuleData.get(path) ?? delta.baseModuleData.get(path),
|
|
204
205
|
);
|
|
205
206
|
const previousDependencies = previousModule?.dependencies ?? new Map();
|
|
206
207
|
const {
|
|
@@ -250,7 +251,7 @@ class Graph {
|
|
|
250
251
|
curDependency,
|
|
251
252
|
resolvedContexts.get(key),
|
|
252
253
|
delta,
|
|
253
|
-
options
|
|
254
|
+
options,
|
|
254
255
|
);
|
|
255
256
|
}
|
|
256
257
|
}
|
|
@@ -259,7 +260,7 @@ class Graph {
|
|
|
259
260
|
const dependencyKeysChangedOrReordered =
|
|
260
261
|
currentDependencies.size !== previousDependencies.size ||
|
|
261
262
|
[...currentDependencies.keys()].some(
|
|
262
|
-
(currentKey, index) => currentKey !== previousDependencyKeys[index]
|
|
263
|
+
(currentKey, index) => currentKey !== previousDependencyKeys[index],
|
|
263
264
|
);
|
|
264
265
|
if (
|
|
265
266
|
previousModule != null &&
|
|
@@ -275,9 +276,9 @@ class Graph {
|
|
|
275
276
|
if (commitOptions.onlyRemove) {
|
|
276
277
|
return nextModule;
|
|
277
278
|
}
|
|
278
|
-
|
|
279
|
+
(0, _invariant.default)(
|
|
279
280
|
nextModule.dependencies.size === currentDependencies.size,
|
|
280
|
-
"Failed to add the correct dependencies"
|
|
281
|
+
"Failed to add the correct dependencies",
|
|
281
282
|
);
|
|
282
283
|
nextModule.dependencies = new Map(currentDependencies);
|
|
283
284
|
return nextModule;
|
|
@@ -288,7 +289,7 @@ class Graph {
|
|
|
288
289
|
dependency,
|
|
289
290
|
requireContext,
|
|
290
291
|
delta,
|
|
291
|
-
options
|
|
292
|
+
options,
|
|
292
293
|
) {
|
|
293
294
|
if (options.shallow) {
|
|
294
295
|
} else if (!(0, _isResolvedDependency.isResolvedDependency)(dependency)) {
|
|
@@ -373,7 +374,7 @@ class Graph {
|
|
|
373
374
|
const mainModule = this.dependencies.get(entryPoint);
|
|
374
375
|
if (!mainModule) {
|
|
375
376
|
throw new ReferenceError(
|
|
376
|
-
"Module not registered in graph: " + entryPoint
|
|
377
|
+
"Module not registered in graph: " + entryPoint,
|
|
377
378
|
);
|
|
378
379
|
}
|
|
379
380
|
this._reorderDependencies(mainModule, orderedDependencies, options);
|
|
@@ -416,12 +417,12 @@ class Graph {
|
|
|
416
417
|
}
|
|
417
418
|
_decrementImportBundleReference(dependency, parentModule) {
|
|
418
419
|
const { absolutePath } = dependency;
|
|
419
|
-
const importBundleNode =
|
|
420
|
-
this.#importBundleNodes.get(absolutePath)
|
|
420
|
+
const importBundleNode = (0, _nullthrows.default)(
|
|
421
|
+
this.#importBundleNodes.get(absolutePath),
|
|
421
422
|
);
|
|
422
|
-
|
|
423
|
+
(0, _invariant.default)(
|
|
423
424
|
importBundleNode.inverseDependencies.has(parentModule.path),
|
|
424
|
-
"lazy: import bundle inverse references"
|
|
425
|
+
"lazy: import bundle inverse references",
|
|
425
426
|
);
|
|
426
427
|
importBundleNode.inverseDependencies.delete(parentModule.path);
|
|
427
428
|
if (importBundleNode.inverseDependencies.size === 0) {
|
|
@@ -439,7 +440,9 @@ class Graph {
|
|
|
439
440
|
) {
|
|
440
441
|
continue;
|
|
441
442
|
}
|
|
442
|
-
yield
|
|
443
|
+
yield (0, _nullthrows.default)(
|
|
444
|
+
this.dependencies.get(dependency.absolutePath),
|
|
445
|
+
);
|
|
443
446
|
}
|
|
444
447
|
}
|
|
445
448
|
_moduleSnapshot(module) {
|
|
@@ -451,7 +454,7 @@ class Graph {
|
|
|
451
454
|
continue;
|
|
452
455
|
}
|
|
453
456
|
const resolvedContext = this.#resolvedContexts.get(
|
|
454
|
-
dependency.absolutePath
|
|
457
|
+
dependency.absolutePath,
|
|
455
458
|
);
|
|
456
459
|
if (resolvedContext != null) {
|
|
457
460
|
resolvedContexts.set(key, resolvedContext);
|
|
@@ -500,8 +503,8 @@ class Graph {
|
|
|
500
503
|
}
|
|
501
504
|
_collectCycles(delta, options) {
|
|
502
505
|
for (const path of this.#gc.possibleCycleRoots) {
|
|
503
|
-
const module =
|
|
504
|
-
const color =
|
|
506
|
+
const module = (0, _nullthrows.default)(this.dependencies.get(path));
|
|
507
|
+
const color = (0, _nullthrows.default)(this.#gc.color.get(path));
|
|
505
508
|
if (color === "purple") {
|
|
506
509
|
this._markGray(module, options);
|
|
507
510
|
} else {
|
|
@@ -516,17 +519,17 @@ class Graph {
|
|
|
516
519
|
}
|
|
517
520
|
}
|
|
518
521
|
for (const path of this.#gc.possibleCycleRoots) {
|
|
519
|
-
const module =
|
|
522
|
+
const module = (0, _nullthrows.default)(this.dependencies.get(path));
|
|
520
523
|
this._scan(module, options);
|
|
521
524
|
}
|
|
522
525
|
for (const path of this.#gc.possibleCycleRoots) {
|
|
523
526
|
this.#gc.possibleCycleRoots.delete(path);
|
|
524
|
-
const module =
|
|
527
|
+
const module = (0, _nullthrows.default)(this.dependencies.get(path));
|
|
525
528
|
this._collectWhite(module, delta);
|
|
526
529
|
}
|
|
527
530
|
}
|
|
528
531
|
_markGray(module, options) {
|
|
529
|
-
const color =
|
|
532
|
+
const color = (0, _nullthrows.default)(this.#gc.color.get(module.path));
|
|
530
533
|
if (color !== "gray") {
|
|
531
534
|
this.#gc.color.set(module.path, "gray");
|
|
532
535
|
for (const childModule of this._children(module, options)) {
|
|
@@ -536,7 +539,7 @@ class Graph {
|
|
|
536
539
|
}
|
|
537
540
|
}
|
|
538
541
|
_scan(module, options) {
|
|
539
|
-
const color =
|
|
542
|
+
const color = (0, _nullthrows.default)(this.#gc.color.get(module.path));
|
|
540
543
|
if (color === "gray") {
|
|
541
544
|
if (
|
|
542
545
|
module.inverseDependencies.size > 0 ||
|
|
@@ -555,14 +558,16 @@ class Graph {
|
|
|
555
558
|
this.#gc.color.set(module.path, "black");
|
|
556
559
|
for (const childModule of this._children(module, options)) {
|
|
557
560
|
childModule.inverseDependencies.add(module.path);
|
|
558
|
-
const childColor =
|
|
561
|
+
const childColor = (0, _nullthrows.default)(
|
|
562
|
+
this.#gc.color.get(childModule.path),
|
|
563
|
+
);
|
|
559
564
|
if (childColor !== "black") {
|
|
560
565
|
this._scanBlack(childModule, options);
|
|
561
566
|
}
|
|
562
567
|
}
|
|
563
568
|
}
|
|
564
569
|
_collectWhite(module, delta) {
|
|
565
|
-
const color =
|
|
570
|
+
const color = (0, _nullthrows.default)(this.#gc.color.get(module.path));
|
|
566
571
|
if (color === "white" && !this.#gc.possibleCycleRoots.has(module.path)) {
|
|
567
572
|
this.#gc.color.set(module.path, "black");
|
|
568
573
|
for (const dependency of module.dependencies.values()) {
|
|
@@ -41,15 +41,14 @@ import type {
|
|
|
41
41
|
Options,
|
|
42
42
|
ResolvedDependency,
|
|
43
43
|
TransformInputOptions,
|
|
44
|
-
} from './types
|
|
44
|
+
} from './types';
|
|
45
45
|
|
|
46
46
|
import {fileMatchesContext} from '../lib/contextModule';
|
|
47
47
|
import CountingSet from '../lib/CountingSet';
|
|
48
48
|
import {isResolvedDependency} from '../lib/isResolvedDependency';
|
|
49
49
|
import {buildSubgraph} from './buildSubgraph';
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const nullthrows = require('nullthrows');
|
|
50
|
+
import invariant from 'invariant';
|
|
51
|
+
import nullthrows from 'nullthrows';
|
|
53
52
|
|
|
54
53
|
// TODO: Convert to a Flow enum
|
|
55
54
|
type NodeColor =
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = baseJSBundle;
|
|
7
|
+
var _getAppendScripts = _interopRequireDefault(
|
|
8
|
+
require("../../lib/getAppendScripts"),
|
|
9
|
+
);
|
|
10
|
+
var _processModules = _interopRequireDefault(
|
|
11
|
+
require("./helpers/processModules"),
|
|
12
|
+
);
|
|
13
|
+
function _interopRequireDefault(e) {
|
|
14
|
+
return e && e.__esModule ? e : { default: e };
|
|
15
|
+
}
|
|
5
16
|
function baseJSBundle(entryPoint, preModules, graph, options) {
|
|
6
17
|
for (const module of graph.dependencies.values()) {
|
|
7
18
|
options.createModuleId(module.path);
|
|
@@ -18,17 +29,21 @@ function baseJSBundle(entryPoint, preModules, graph, options) {
|
|
|
18
29
|
if (options.modulesOnly) {
|
|
19
30
|
preModules = [];
|
|
20
31
|
}
|
|
21
|
-
const preCode =
|
|
32
|
+
const preCode = (0, _processModules.default)(
|
|
33
|
+
preModules,
|
|
34
|
+
processModulesOptions,
|
|
35
|
+
)
|
|
22
36
|
.map(([_, code]) => code)
|
|
23
37
|
.join("\n");
|
|
24
38
|
const modules = [...graph.dependencies.values()].sort(
|
|
25
|
-
(a, b) => options.createModuleId(a.path) - options.createModuleId(b.path)
|
|
39
|
+
(a, b) => options.createModuleId(a.path) - options.createModuleId(b.path),
|
|
26
40
|
);
|
|
27
|
-
const postCode =
|
|
28
|
-
|
|
41
|
+
const postCode = (0, _processModules.default)(
|
|
42
|
+
(0, _getAppendScripts.default)(entryPoint, [...preModules, ...modules], {
|
|
29
43
|
asyncRequireModulePath: options.asyncRequireModulePath,
|
|
30
44
|
createModuleId: options.createModuleId,
|
|
31
45
|
getRunModuleStatement: options.getRunModuleStatement,
|
|
46
|
+
globalPrefix: options.globalPrefix,
|
|
32
47
|
inlineSourceMap: options.inlineSourceMap,
|
|
33
48
|
runBeforeMainModule: options.runBeforeMainModule,
|
|
34
49
|
runModule: options.runModule,
|
|
@@ -37,17 +52,16 @@ function baseJSBundle(entryPoint, preModules, graph, options) {
|
|
|
37
52
|
sourceUrl: options.sourceUrl,
|
|
38
53
|
getSourceUrl: options.getSourceUrl,
|
|
39
54
|
}),
|
|
40
|
-
processModulesOptions
|
|
55
|
+
processModulesOptions,
|
|
41
56
|
)
|
|
42
57
|
.map(([_, code]) => code)
|
|
43
58
|
.join("\n");
|
|
44
59
|
return {
|
|
45
60
|
pre: preCode,
|
|
46
61
|
post: postCode,
|
|
47
|
-
modules:
|
|
62
|
+
modules: (0, _processModules.default)(
|
|
48
63
|
[...graph.dependencies.values()],
|
|
49
|
-
processModulesOptions
|
|
64
|
+
processModulesOptions,
|
|
50
65
|
).map(([module, code]) => [options.createModuleId(module.path), code]),
|
|
51
66
|
};
|
|
52
67
|
}
|
|
53
|
-
module.exports = baseJSBundle;
|
|
@@ -9,20 +9,18 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
12
|
import type {
|
|
15
13
|
MixedOutput,
|
|
16
14
|
Module,
|
|
17
15
|
ReadOnlyGraph,
|
|
18
16
|
SerializerOptions,
|
|
19
|
-
} from '../types
|
|
20
|
-
import type {Bundle} from 'metro-runtime/src/modules/types
|
|
17
|
+
} from '../types';
|
|
18
|
+
import type {Bundle} from 'metro-runtime/src/modules/types';
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
import getAppendScripts from '../../lib/getAppendScripts';
|
|
21
|
+
import processModules from './helpers/processModules';
|
|
24
22
|
|
|
25
|
-
function baseJSBundle(
|
|
23
|
+
export default function baseJSBundle(
|
|
26
24
|
entryPoint: string,
|
|
27
25
|
preModules: $ReadOnlyArray<Module<>>,
|
|
28
26
|
graph: ReadOnlyGraph<>,
|
|
@@ -61,6 +59,7 @@ function baseJSBundle(
|
|
|
61
59
|
asyncRequireModulePath: options.asyncRequireModulePath,
|
|
62
60
|
createModuleId: options.createModuleId,
|
|
63
61
|
getRunModuleStatement: options.getRunModuleStatement,
|
|
62
|
+
globalPrefix: options.globalPrefix,
|
|
64
63
|
inlineSourceMap: options.inlineSourceMap,
|
|
65
64
|
runBeforeMainModule: options.runBeforeMainModule,
|
|
66
65
|
runModule: options.runModule,
|
|
@@ -83,5 +82,3 @@ function baseJSBundle(
|
|
|
83
82
|
).map(([module, code]) => [options.createModuleId(module.path), code]),
|
|
84
83
|
};
|
|
85
84
|
}
|
|
86
|
-
|
|
87
|
-
module.exports = baseJSBundle;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = getAllFiles;
|
|
7
|
+
var _Assets = require("../../Assets");
|
|
8
|
+
var _js = require("./helpers/js");
|
|
5
9
|
async function getAllFiles(pre, graph, options) {
|
|
6
10
|
const modules = graph.dependencies;
|
|
7
11
|
const { processModuleFilter } = options;
|
|
@@ -12,11 +16,11 @@ async function getAllFiles(pre, graph, options) {
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
for (const module of modules.values()) {
|
|
15
|
-
if (!isJsModule(module) || !processModuleFilter(module)) {
|
|
19
|
+
if (!(0, _js.isJsModule)(module) || !processModuleFilter(module)) {
|
|
16
20
|
continue;
|
|
17
21
|
}
|
|
18
|
-
if (getJsOutput(module).type === "js/module/asset") {
|
|
19
|
-
promises.push(getAssetFiles(module.path, options.platform));
|
|
22
|
+
if ((0, _js.getJsOutput)(module).type === "js/module/asset") {
|
|
23
|
+
promises.push((0, _Assets.getAssetFiles)(module.path, options.platform));
|
|
20
24
|
} else {
|
|
21
25
|
promises.push([module.path]);
|
|
22
26
|
}
|
|
@@ -28,4 +32,3 @@ async function getAllFiles(pre, graph, options) {
|
|
|
28
32
|
}
|
|
29
33
|
return output;
|
|
30
34
|
}
|
|
31
|
-
module.exports = getAllFiles;
|
|
@@ -9,19 +9,17 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
import type {Module, ReadOnlyGraph} from '../types';
|
|
13
13
|
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
const {getAssetFiles} = require('../../Assets');
|
|
17
|
-
const {getJsOutput, isJsModule} = require('./helpers/js');
|
|
14
|
+
import {getAssetFiles} from '../../Assets';
|
|
15
|
+
import {getJsOutput, isJsModule} from './helpers/js';
|
|
18
16
|
|
|
19
17
|
type Options = {
|
|
20
18
|
platform: ?string,
|
|
21
19
|
+processModuleFilter: (module: Module<>) => boolean,
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
async function getAllFiles(
|
|
22
|
+
export default async function getAllFiles(
|
|
25
23
|
pre: $ReadOnlyArray<Module<>>,
|
|
26
24
|
graph: ReadOnlyGraph<>,
|
|
27
25
|
options: Options,
|
|
@@ -58,5 +56,3 @@ async function getAllFiles(
|
|
|
58
56
|
|
|
59
57
|
return output;
|
|
60
58
|
}
|
|
61
|
-
|
|
62
|
-
module.exports = getAllFiles;
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = getAssets;
|
|
7
|
+
var _Assets = require("../../Assets");
|
|
8
|
+
var _js = require("./helpers/js");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
function _interopRequireDefault(e) {
|
|
11
|
+
return e && e.__esModule ? e : { default: e };
|
|
12
|
+
}
|
|
6
13
|
async function getAssets(dependencies, options) {
|
|
7
14
|
const promises = [];
|
|
8
15
|
const { processModuleFilter } = options;
|
|
9
16
|
for (const module of dependencies.values()) {
|
|
10
17
|
if (
|
|
11
|
-
isJsModule(module) &&
|
|
18
|
+
(0, _js.isJsModule)(module) &&
|
|
12
19
|
processModuleFilter(module) &&
|
|
13
|
-
getJsOutput(module).type === "js/module/asset" &&
|
|
14
|
-
|
|
20
|
+
(0, _js.getJsOutput)(module).type === "js/module/asset" &&
|
|
21
|
+
_path.default.relative(options.projectRoot, module.path) !==
|
|
22
|
+
"package.json"
|
|
15
23
|
) {
|
|
16
24
|
promises.push(
|
|
17
|
-
getAssetData(
|
|
25
|
+
(0, _Assets.getAssetData)(
|
|
18
26
|
module.path,
|
|
19
|
-
|
|
27
|
+
_path.default.relative(options.projectRoot, module.path),
|
|
20
28
|
options.assetPlugins,
|
|
21
29
|
options.platform,
|
|
22
|
-
options.publicPath
|
|
23
|
-
)
|
|
30
|
+
options.publicPath,
|
|
31
|
+
),
|
|
24
32
|
);
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
return await Promise.all(promises);
|
|
28
36
|
}
|
|
29
|
-
module.exports = getAssets;
|
|
@@ -9,14 +9,12 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
12
|
import type {AssetData} from '../../Assets';
|
|
15
|
-
import type {Module, ReadOnlyDependencies} from '../types
|
|
13
|
+
import type {Module, ReadOnlyDependencies} from '../types';
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
import {getAssetData} from '../../Assets';
|
|
16
|
+
import {getJsOutput, isJsModule} from './helpers/js';
|
|
17
|
+
import path from 'path';
|
|
20
18
|
|
|
21
19
|
type Options = {
|
|
22
20
|
+processModuleFilter: (module: Module<>) => boolean,
|
|
@@ -26,7 +24,7 @@ type Options = {
|
|
|
26
24
|
publicPath: string,
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
async function getAssets(
|
|
27
|
+
export default async function getAssets(
|
|
30
28
|
dependencies: ReadOnlyDependencies<>,
|
|
31
29
|
options: Options,
|
|
32
30
|
): Promise<$ReadOnlyArray<AssetData>> {
|
|
@@ -54,5 +52,3 @@ async function getAssets(
|
|
|
54
52
|
|
|
55
53
|
return await Promise.all(promises);
|
|
56
54
|
}
|
|
57
|
-
|
|
58
|
-
module.exports = getAssets;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {Module} from '../types';
|
|
12
|
+
import type {
|
|
13
|
+
FBSourceFunctionMap,
|
|
14
|
+
MetroSourceMapSegmentTuple,
|
|
15
|
+
} from 'metro-source-map';
|
|
16
|
+
|
|
17
|
+
export type ExplodedSourceMap = ReadonlyArray<{
|
|
18
|
+
readonly map: Array<MetroSourceMapSegmentTuple>;
|
|
19
|
+
readonly firstLine1Based: number;
|
|
20
|
+
readonly functionMap: null | undefined | FBSourceFunctionMap;
|
|
21
|
+
readonly path: string;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function getExplodedSourceMap(
|
|
24
|
+
modules: ReadonlyArray<Module>,
|
|
25
|
+
options: {readonly processModuleFilter: (module: Module) => boolean},
|
|
26
|
+
): ExplodedSourceMap;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.getExplodedSourceMap = getExplodedSourceMap;
|
|
7
|
+
var _js = require("./helpers/js");
|
|
4
8
|
function getExplodedSourceMap(modules, options) {
|
|
5
9
|
const modulesToProcess = modules
|
|
6
|
-
.filter(isJsModule)
|
|
10
|
+
.filter(_js.isJsModule)
|
|
7
11
|
.filter(options.processModuleFilter);
|
|
8
12
|
const result = [];
|
|
9
13
|
let firstLine1Based = 1;
|
|
10
14
|
for (const module of modulesToProcess) {
|
|
11
15
|
const { path } = module;
|
|
12
|
-
const { lineCount, functionMap, map } = getJsOutput(module).data;
|
|
16
|
+
const { lineCount, functionMap, map } = (0, _js.getJsOutput)(module).data;
|
|
13
17
|
result.push({
|
|
14
18
|
firstLine1Based,
|
|
15
19
|
functionMap,
|
|
@@ -20,6 +24,3 @@ function getExplodedSourceMap(modules, options) {
|
|
|
20
24
|
}
|
|
21
25
|
return result;
|
|
22
26
|
}
|
|
23
|
-
module.exports = {
|
|
24
|
-
getExplodedSourceMap,
|
|
25
|
-
};
|
|
@@ -9,15 +9,13 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import type {Module} from '../types.flow';
|
|
12
|
+
import type {Module} from '../types';
|
|
15
13
|
import type {
|
|
16
14
|
FBSourceFunctionMap,
|
|
17
15
|
MetroSourceMapSegmentTuple,
|
|
18
16
|
} from 'metro-source-map';
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
import {getJsOutput, isJsModule} from './helpers/js';
|
|
21
19
|
|
|
22
20
|
export type ExplodedSourceMap = $ReadOnlyArray<{
|
|
23
21
|
+map: Array<MetroSourceMapSegmentTuple>,
|
|
@@ -26,7 +24,7 @@ export type ExplodedSourceMap = $ReadOnlyArray<{
|
|
|
26
24
|
+path: string,
|
|
27
25
|
}>;
|
|
28
26
|
|
|
29
|
-
function getExplodedSourceMap(
|
|
27
|
+
export function getExplodedSourceMap(
|
|
30
28
|
modules: $ReadOnlyArray<Module<>>,
|
|
31
29
|
options: {
|
|
32
30
|
+processModuleFilter: (module: Module<>) => boolean,
|
|
@@ -47,7 +45,3 @@ function getExplodedSourceMap(
|
|
|
47
45
|
}
|
|
48
46
|
return result;
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
module.exports = {
|
|
52
|
-
getExplodedSourceMap,
|
|
53
|
-
};
|