metro 0.80.4 → 0.80.6
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 -17
- package/src/Assets.js +0 -35
- package/src/Bundler/util.js +1 -29
- package/src/Bundler.js +1 -20
- package/src/DeltaBundler/DeltaCalculator.js +0 -86
- package/src/DeltaBundler/Graph.js +0 -197
- package/src/DeltaBundler/Serializers/baseJSBundle.js +0 -13
- package/src/DeltaBundler/Serializers/getAllFiles.js +0 -11
- package/src/DeltaBundler/Serializers/getAssets.js +0 -11
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +0 -11
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +0 -18
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +0 -11
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +0 -11
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +0 -14
- package/src/DeltaBundler/Serializers/helpers/js.js +0 -21
- package/src/DeltaBundler/Serializers/helpers/processModules.js +0 -11
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +0 -23
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +0 -16
- package/src/DeltaBundler/Serializers/sourceMapObject.js +0 -11
- package/src/DeltaBundler/Serializers/sourceMapString.js +0 -11
- package/src/DeltaBundler/Transformer.js +0 -30
- package/src/DeltaBundler/Worker.flow.js +0 -26
- package/src/DeltaBundler/Worker.flow.js.flow +2 -2
- package/src/DeltaBundler/Worker.js +0 -14
- package/src/DeltaBundler/WorkerFarm.js +1 -21
- package/src/DeltaBundler/__fixtures__/hasteImpl.js +0 -14
- package/src/DeltaBundler/buildSubgraph.js +0 -24
- package/src/DeltaBundler/getTransformCacheKey.js +0 -13
- package/src/DeltaBundler/getTransformCacheKey.js.flow +1 -1
- package/src/DeltaBundler/mergeDeltas.js +0 -11
- package/src/DeltaBundler/types.flow.js +0 -11
- package/src/DeltaBundler.js +0 -21
- package/src/HmrServer.js +8 -39
- package/src/HmrServer.js.flow +8 -6
- package/src/IncrementalBundler/GraphNotFoundError.js +0 -11
- package/src/IncrementalBundler/ResourceNotFoundError.js +0 -11
- package/src/IncrementalBundler/RevisionNotFoundError.js +0 -11
- package/src/IncrementalBundler.js +0 -23
- package/src/ModuleGraph/test-helpers.js +0 -17
- package/src/ModuleGraph/worker/JsFileWrapping.js +1 -22
- package/src/ModuleGraph/worker/collectDependencies.js +1 -94
- package/src/ModuleGraph/worker/generateImportNames.js +0 -15
- package/src/Server/MultipartResponse.js +0 -13
- package/src/Server/symbolicate.js +2 -36
- package/src/Server.js +6 -83
- package/src/cli/parseKeyValueParamArray.js +0 -11
- package/src/cli-utils.js +0 -11
- package/src/cli.js +0 -13
- package/src/commands/build.js +0 -15
- package/src/commands/dependencies.js +1 -19
- package/src/commands/serve.js +0 -19
- package/src/index.flow.js +0 -31
- package/src/index.js +0 -14
- package/src/integration_tests/basic_bundle/AssetRegistry.js +0 -10
- package/src/integration_tests/basic_bundle/Bar.js +0 -10
- package/src/integration_tests/basic_bundle/ErrorBundle.js +0 -12
- package/src/integration_tests/basic_bundle/Foo.js +0 -10
- package/src/integration_tests/basic_bundle/TestBigInt.js +0 -12
- package/src/integration_tests/basic_bundle/TestBundle.js +0 -11
- package/src/integration_tests/basic_bundle/TestPolyfill.js +0 -10
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +0 -14
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js +0 -14
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js +0 -14
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js +1 -15
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js +0 -13
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js +0 -16
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +0 -14
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js +0 -13
- package/src/integration_tests/basic_bundle/import-export/export-1.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-2.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-3.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-4.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-5.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-6.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-null.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/index.js +0 -10
- package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js +0 -10
- package/src/integration_tests/basic_bundle/polyfill.js +0 -12
- package/src/integration_tests/basic_bundle/require-context/conflict.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/empty.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/matching.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js +0 -11
- package/src/integration_tests/basic_bundle/require-context/subdir/a.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/subdir/b.js +0 -9
- package/src/integration_tests/basic_bundle/require-context/subdir/c.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/utils.js +0 -10
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js +0 -15
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js +0 -10
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js +0 -10
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js +0 -15
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js +0 -10
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js +0 -10
- package/src/integration_tests/execBundle.js +0 -11
- package/src/integration_tests/metro.config.js +0 -10
- package/src/lib/BatchProcessor.js +0 -23
- package/src/lib/CountingSet.js +0 -35
- package/src/lib/JsonReporter.js +0 -17
- package/src/lib/RamBundleParser.js +0 -23
- package/src/lib/TerminalReporter.js +0 -68
- package/src/lib/bundleToString.js +1 -19
- package/src/lib/contextModule.js +1 -31
- package/src/lib/contextModuleTemplates.js +0 -36
- package/src/lib/countLines.js +0 -11
- package/src/lib/createModuleIdFactory.js +0 -11
- package/src/lib/createWebsocketServer.js +0 -24
- package/src/lib/debounceAsyncQueue.js +0 -13
- package/src/lib/formatBundlingError.js +0 -14
- package/src/lib/getAppendScripts.js +0 -11
- package/src/lib/getGraphId.js +0 -11
- package/src/lib/getMaxWorkers.js +0 -11
- package/src/lib/getPreludeCode.js +0 -18
- package/src/lib/getPrependedScripts.js +0 -13
- package/src/lib/logToConsole.js +0 -18
- package/src/lib/parseCustomResolverOptions.js +0 -11
- package/src/lib/parseCustomTransformOptions.js +0 -12
- package/src/lib/parseOptionsFromUrl.js +1 -17
- package/src/lib/relativizeSourceMap.js +0 -12
- package/src/lib/reporting.js +0 -30
- package/src/lib/splitBundleOptions.js +0 -14
- package/src/lib/transformHelpers.js +0 -20
- package/src/node-haste/DependencyGraph/ModuleResolution.js +5 -64
- package/src/node-haste/DependencyGraph/createFileMap.js +0 -16
- package/src/node-haste/DependencyGraph.js +6 -46
- package/src/node-haste/DependencyGraph.js.flow +7 -4
- package/src/node-haste/Module.js +0 -11
- package/src/node-haste/ModuleCache.js +0 -20
- package/src/node-haste/Package.js +0 -11
- package/src/node-haste/lib/AssetPaths.js +0 -16
- package/src/node-haste/lib/parsePlatformFilePath.js +0 -16
- package/src/shared/output/RamBundle/as-assets.js +6 -29
- package/src/shared/output/RamBundle/as-indexed-file.js +0 -44
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +0 -13
- package/src/shared/output/RamBundle/magic-number.js +0 -11
- package/src/shared/output/RamBundle/util.js +1 -17
- package/src/shared/output/RamBundle/write-sourcemap.js +0 -12
- package/src/shared/output/RamBundle.js +0 -14
- package/src/shared/output/bundle.flow.js +0 -13
- package/src/shared/output/bundle.flow.js.flow +1 -1
- package/src/shared/output/bundle.js +0 -14
- package/src/shared/output/meta.js +0 -11
- package/src/shared/output/unbundle.js +0 -13
- package/src/shared/output/writeFile.js +0 -11
- package/src/shared/types.flow.js +0 -11
package/src/HmrServer.js.flow
CHANGED
|
@@ -228,12 +228,14 @@ class HmrServer<TClient: Client> {
|
|
|
228
228
|
),
|
|
229
229
|
);
|
|
230
230
|
case 'log':
|
|
231
|
-
this._config.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
231
|
+
if (this._config.server.forwardClientLogs) {
|
|
232
|
+
this._config.reporter.update({
|
|
233
|
+
type: 'client_log',
|
|
234
|
+
level: data.level,
|
|
235
|
+
data: data.data,
|
|
236
|
+
mode: data.mode,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
237
239
|
break;
|
|
238
240
|
case 'log-opt-in':
|
|
239
241
|
client.optedIntoHMR = true;
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
class GraphNotFoundError extends Error {
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
class ResourceNotFoundError extends Error {
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
class RevisionNotFoundError extends Error {
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const Bundler = require("./Bundler");
|
|
@@ -37,7 +26,6 @@ class IncrementalBundler {
|
|
|
37
26
|
}
|
|
38
27
|
end() {
|
|
39
28
|
this._deltaBundler.end();
|
|
40
|
-
// $FlowFixMe[unused-promise]
|
|
41
29
|
this._bundler.end();
|
|
42
30
|
}
|
|
43
31
|
getBundler() {
|
|
@@ -162,9 +150,6 @@ class IncrementalBundler {
|
|
|
162
150
|
graph,
|
|
163
151
|
};
|
|
164
152
|
}
|
|
165
|
-
|
|
166
|
-
// TODO T34760750 (alexkirsz) Eventually, I'd like to get to a point where
|
|
167
|
-
// this class exposes only initializeGraph and updateGraph.
|
|
168
153
|
async initializeGraph(
|
|
169
154
|
entryFile,
|
|
170
155
|
transformOptions,
|
|
@@ -213,8 +198,6 @@ class IncrementalBundler {
|
|
|
213
198
|
delta,
|
|
214
199
|
};
|
|
215
200
|
} catch (err) {
|
|
216
|
-
// Evict a bad revision from the cache since otherwise
|
|
217
|
-
// we'll keep getting it even after the build is fixed.
|
|
218
201
|
this._revisionsById.delete(revisionId);
|
|
219
202
|
this._revisionsByGraphId.delete(graphId);
|
|
220
203
|
throw err;
|
|
@@ -234,8 +217,6 @@ class IncrementalBundler {
|
|
|
234
217
|
this._revisionsById.delete(revision.id);
|
|
235
218
|
revision = {
|
|
236
219
|
...revision,
|
|
237
|
-
// Generate a new revision id, to be used to verify the next incremental
|
|
238
|
-
// request.
|
|
239
220
|
id: crypto.randomBytes(8).toString("hex"),
|
|
240
221
|
date: new Date(),
|
|
241
222
|
};
|
|
@@ -269,8 +250,6 @@ class IncrementalBundler {
|
|
|
269
250
|
absoluteEntryFiles.map(
|
|
270
251
|
(entryFile) =>
|
|
271
252
|
new Promise((resolve, reject) => {
|
|
272
|
-
// This should throw an error if the file doesn't exist.
|
|
273
|
-
// Using this instead of fs.exists to account for SimLinks.
|
|
274
253
|
fs.realpath(entryFile, (err) => {
|
|
275
254
|
if (err) {
|
|
276
255
|
reject(new ResourceNotFoundError(entryFile));
|
|
@@ -283,8 +262,6 @@ class IncrementalBundler {
|
|
|
283
262
|
);
|
|
284
263
|
return absoluteEntryFiles;
|
|
285
264
|
}
|
|
286
|
-
|
|
287
|
-
// Wait for the bundler to become ready.
|
|
288
265
|
async ready() {
|
|
289
266
|
await this._bundler.ready();
|
|
290
267
|
}
|
|
@@ -1,13 +1,3 @@
|
|
|
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
1
|
"use strict";
|
|
12
2
|
|
|
13
3
|
const generate = require("@babel/generator").default;
|
|
@@ -61,17 +51,10 @@ function toEqualComparableCode(received, expected) {
|
|
|
61
51
|
pass,
|
|
62
52
|
};
|
|
63
53
|
}
|
|
64
|
-
|
|
65
|
-
// See https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream
|
|
66
54
|
const ANSI_PATTERN = /\x1b\[[0-9;]*m/g;
|
|
67
55
|
function trimANSICodes(input) {
|
|
68
56
|
return input.replace(ANSI_PATTERN, "");
|
|
69
57
|
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Matches a text that contains ANSI control codes (e.g. [39m[31m[1m^) against a snapshot.
|
|
73
|
-
* Usage: Call expect.extend({toMatchCodeFrameSnapshot}) to add the matcher in your test
|
|
74
|
-
*/
|
|
75
58
|
function toMatchCodeFrameSnapshot(received) {
|
|
76
59
|
return toMatchSnapshot.call(
|
|
77
60
|
this,
|
|
@@ -1,13 +1,3 @@
|
|
|
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
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
1
|
"use strict";
|
|
12
2
|
|
|
13
3
|
var _template = _interopRequireDefault(require("@babel/template"));
|
|
@@ -57,11 +47,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
57
47
|
function _interopRequireDefault(obj) {
|
|
58
48
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
59
49
|
}
|
|
60
|
-
const WRAP_NAME = "$$_REQUIRE";
|
|
61
|
-
|
|
62
|
-
// Check first the `global` variable as the global object. This way serializers
|
|
63
|
-
// can create a local variable called global to fake it as a global object
|
|
64
|
-
// without having to pollute the window object on web.
|
|
50
|
+
const WRAP_NAME = "$$_REQUIRE";
|
|
65
51
|
const IIFE_PARAM = _template.default.expression(
|
|
66
52
|
"typeof globalThis !== 'undefined' ? globalThis : typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this"
|
|
67
53
|
);
|
|
@@ -95,7 +81,6 @@ function jsonToCommonJS(source) {
|
|
|
95
81
|
return `module.exports = ${source};`;
|
|
96
82
|
}
|
|
97
83
|
function wrapJson(source, globalPrefix) {
|
|
98
|
-
// Unused parameters; remember that's wrapping JSON.
|
|
99
84
|
const moduleFactoryParameters = buildParameters(
|
|
100
85
|
"_importDefaultUnused",
|
|
101
86
|
"_importAllUnused",
|
|
@@ -128,12 +113,6 @@ function buildParameters(importDefaultName, importAllName, dependencyMapName) {
|
|
|
128
113
|
dependencyMapName,
|
|
129
114
|
];
|
|
130
115
|
}
|
|
131
|
-
|
|
132
|
-
// Renaming requires should ideally only be done when generating for the target
|
|
133
|
-
// that expects the custom require name in the optimize step.
|
|
134
|
-
// This visitor currently renames all `require` references even if the module
|
|
135
|
-
// contains a custom `require` declaration. This should be fixed by only renaming
|
|
136
|
-
// if the `require` symbol hasn't been redeclared.
|
|
137
116
|
function renameRequires(ast) {
|
|
138
117
|
let newRequireName = WRAP_NAME;
|
|
139
118
|
(0, _traverse.default)(ast, {
|
|
@@ -1,13 +1,3 @@
|
|
|
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
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
1
|
"use strict";
|
|
12
2
|
|
|
13
3
|
const generate = require("@babel/generator").default;
|
|
@@ -17,15 +7,6 @@ const types = require("@babel/types");
|
|
|
17
7
|
const crypto = require("crypto");
|
|
18
8
|
const nullthrows = require("nullthrows");
|
|
19
9
|
const { isImport } = types;
|
|
20
|
-
/**
|
|
21
|
-
* Transform all the calls to `require()` and `import()` in a file into ID-
|
|
22
|
-
* independent code, and return the list of dependencies. For example, a call
|
|
23
|
-
* like `require('Foo')` could be transformed to `require(_depMap[3], 'Foo')`
|
|
24
|
-
* where `_depMap` is provided by the outer scope. As such, we don't need to
|
|
25
|
-
* know the actual module ID.
|
|
26
|
-
*
|
|
27
|
-
* The second argument is only provided for debugging purposes.
|
|
28
|
-
*/
|
|
29
10
|
function collectDependencies(ast, options) {
|
|
30
11
|
const visited = new WeakSet();
|
|
31
12
|
const state = {
|
|
@@ -59,38 +40,27 @@ function collectDependencies(ast, options) {
|
|
|
59
40
|
});
|
|
60
41
|
return;
|
|
61
42
|
}
|
|
62
|
-
|
|
63
|
-
// Match `require.context`
|
|
64
43
|
if (
|
|
65
|
-
// Feature gate, defaults to `false`.
|
|
66
44
|
state.unstable_allowRequireContext &&
|
|
67
45
|
callee.type === "MemberExpression" &&
|
|
68
|
-
// `require`
|
|
69
46
|
callee.object.type === "Identifier" &&
|
|
70
47
|
callee.object.name === "require" &&
|
|
71
|
-
// `context`
|
|
72
48
|
callee.property.type === "Identifier" &&
|
|
73
49
|
callee.property.name === "context" &&
|
|
74
50
|
!callee.computed &&
|
|
75
|
-
// Ensure `require` refers to the global and not something else.
|
|
76
51
|
!path.scope.getBinding("require")
|
|
77
52
|
) {
|
|
78
53
|
processRequireContextCall(path, state);
|
|
79
54
|
visited.add(path.node);
|
|
80
55
|
return;
|
|
81
56
|
}
|
|
82
|
-
|
|
83
|
-
// Match `require.resolveWeak`
|
|
84
57
|
if (
|
|
85
58
|
callee.type === "MemberExpression" &&
|
|
86
|
-
// `require`
|
|
87
59
|
callee.object.type === "Identifier" &&
|
|
88
60
|
callee.object.name === "require" &&
|
|
89
|
-
// `resolveWeak`
|
|
90
61
|
callee.property.type === "Identifier" &&
|
|
91
62
|
callee.property.name === "resolveWeak" &&
|
|
92
63
|
!callee.computed &&
|
|
93
|
-
// Ensure `require` refers to the global and not something else.
|
|
94
64
|
!path.scope.getBinding("require")
|
|
95
65
|
) {
|
|
96
66
|
processResolveWeakCall(path, state);
|
|
@@ -126,7 +96,6 @@ function collectDependencies(ast, options) {
|
|
|
126
96
|
};
|
|
127
97
|
traverse(ast, visitor, null, state);
|
|
128
98
|
const collectedDependencies = state.dependencyRegistry.getDependencies();
|
|
129
|
-
// Compute the list of dependencies.
|
|
130
99
|
const dependencies = new Array(collectedDependencies.length);
|
|
131
100
|
for (const { index, name, ...dependencyData } of collectedDependencies) {
|
|
132
101
|
dependencies[index] = {
|
|
@@ -140,8 +109,6 @@ function collectDependencies(ast, options) {
|
|
|
140
109
|
dependencyMapName: nullthrows(state.dependencyMapIdentifier).name,
|
|
141
110
|
};
|
|
142
111
|
}
|
|
143
|
-
|
|
144
|
-
/** Extract args passed to the `require.context` method. */
|
|
145
112
|
function getRequireContextArgs(path) {
|
|
146
113
|
const args = path.get("arguments");
|
|
147
114
|
let directory;
|
|
@@ -158,8 +125,6 @@ function getRequireContextArgs(path) {
|
|
|
158
125
|
);
|
|
159
126
|
}
|
|
160
127
|
}
|
|
161
|
-
|
|
162
|
-
// Default to requiring through all directories.
|
|
163
128
|
let recursive = true;
|
|
164
129
|
if (args.length > 1) {
|
|
165
130
|
const result = args[1].evaluate();
|
|
@@ -172,19 +137,14 @@ function getRequireContextArgs(path) {
|
|
|
172
137
|
);
|
|
173
138
|
}
|
|
174
139
|
}
|
|
175
|
-
|
|
176
|
-
// Default to all files.
|
|
177
140
|
let filter = {
|
|
178
141
|
pattern: ".*",
|
|
179
142
|
flags: "",
|
|
180
143
|
};
|
|
181
144
|
if (args.length > 2) {
|
|
182
|
-
// evaluate() to check for undefined (because it's technically a scope lookup)
|
|
183
|
-
// but check the AST for the regex literal, since evaluate() doesn't do regex.
|
|
184
145
|
const result = args[2].evaluate();
|
|
185
146
|
const argNode = args[2].node;
|
|
186
147
|
if (argNode.type === "RegExpLiteral") {
|
|
187
|
-
// TODO: Handle `new RegExp(...)` -- `argNode.type === 'NewExpression'`
|
|
188
148
|
filter = {
|
|
189
149
|
pattern: argNode.pattern,
|
|
190
150
|
flags: argNode.flags || "",
|
|
@@ -196,8 +156,6 @@ function getRequireContextArgs(path) {
|
|
|
196
156
|
);
|
|
197
157
|
}
|
|
198
158
|
}
|
|
199
|
-
|
|
200
|
-
// Default to `sync`.
|
|
201
159
|
let mode = "sync";
|
|
202
160
|
if (args.length > 3) {
|
|
203
161
|
const result = args[3].evaluate();
|
|
@@ -245,17 +203,13 @@ function processRequireContextCall(path, state) {
|
|
|
245
203
|
const dep = registerDependency(
|
|
246
204
|
state,
|
|
247
205
|
{
|
|
248
|
-
// We basically want to "import" every file in a folder and then filter them out with the given `filter` RegExp.
|
|
249
206
|
name: directory,
|
|
250
|
-
// Capture the matching context
|
|
251
207
|
contextParams,
|
|
252
208
|
asyncType: null,
|
|
253
209
|
optional: isOptionalDependency(directory, path, state),
|
|
254
210
|
},
|
|
255
211
|
path
|
|
256
212
|
);
|
|
257
|
-
|
|
258
|
-
// require() the generated module representing this context
|
|
259
213
|
path.get("callee").replaceWith(types.identifier("require"));
|
|
260
214
|
transformer.transformSyncRequire(path, dep, state);
|
|
261
215
|
}
|
|
@@ -339,15 +293,11 @@ function getNearestLocFromPath(path) {
|
|
|
339
293
|
while (
|
|
340
294
|
current &&
|
|
341
295
|
!current.node.loc &&
|
|
342
|
-
// $FlowIgnore[prop-missing] METRO_INLINE_REQUIRES_INIT_LOC is Metro-specific and not typed
|
|
343
296
|
!current.node.METRO_INLINE_REQUIRES_INIT_LOC
|
|
344
297
|
) {
|
|
345
298
|
current = current.parentPath;
|
|
346
299
|
}
|
|
347
|
-
return
|
|
348
|
-
// $FlowIgnore[prop-missing] METRO_INLINE_REQUIRES_INIT_LOC is Metro-specific and not typed
|
|
349
|
-
current?.node.METRO_INLINE_REQUIRES_INIT_LOC ?? current?.node.loc
|
|
350
|
-
);
|
|
300
|
+
return current?.node.METRO_INLINE_REQUIRES_INIT_LOC ?? current?.node.loc;
|
|
351
301
|
}
|
|
352
302
|
function registerDependency(state, qualifier, path) {
|
|
353
303
|
const dependency = state.dependencyRegistry.registerDependency(qualifier);
|
|
@@ -359,8 +309,6 @@ function registerDependency(state, qualifier, path) {
|
|
|
359
309
|
}
|
|
360
310
|
function isOptionalDependency(name, path, state) {
|
|
361
311
|
const { allowOptionalDependencies } = state;
|
|
362
|
-
|
|
363
|
-
// The async require module is a 'built-in'. Resolving should never fail -> treat it as non-optional.
|
|
364
312
|
if (name === state.asyncRequireModulePathStringLiteral?.value) {
|
|
365
313
|
return false;
|
|
366
314
|
}
|
|
@@ -370,15 +318,11 @@ function isOptionalDependency(name, path, state) {
|
|
|
370
318
|
if (!allowOptionalDependencies || isExcluded()) {
|
|
371
319
|
return false;
|
|
372
320
|
}
|
|
373
|
-
|
|
374
|
-
// Valid statement stack for single-level try-block: expressionStatement -> blockStatement -> tryStatement
|
|
375
321
|
let sCount = 0;
|
|
376
322
|
let p = path;
|
|
377
323
|
while (p && sCount < 3) {
|
|
378
324
|
if (p.isStatement()) {
|
|
379
325
|
if (p.node.type === "BlockStatement") {
|
|
380
|
-
// A single-level should have the tryStatement immediately followed BlockStatement
|
|
381
|
-
// with the key 'block' to distinguish from the finally block, which has key = 'finalizer'
|
|
382
326
|
return (
|
|
383
327
|
p.parentPath != null &&
|
|
384
328
|
p.parentPath.node.type === "TryStatement" &&
|
|
@@ -417,12 +361,6 @@ class InvalidRequireCallError extends Error {
|
|
|
417
361
|
}
|
|
418
362
|
}
|
|
419
363
|
collectDependencies.InvalidRequireCallError = InvalidRequireCallError;
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Produces a Babel template that will throw at runtime when the require call
|
|
423
|
-
* is reached. This makes dynamic require errors catchable by libraries that
|
|
424
|
-
* want to use them.
|
|
425
|
-
*/
|
|
426
364
|
const dynamicRequireErrorTemplate = template.expression(`
|
|
427
365
|
(function(line) {
|
|
428
366
|
throw new Error(
|
|
@@ -430,11 +368,6 @@ const dynamicRequireErrorTemplate = template.expression(`
|
|
|
430
368
|
);
|
|
431
369
|
})(LINE)
|
|
432
370
|
`);
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Produces a Babel template that transforms an "import(...)" call into a
|
|
436
|
-
* "require(...)" call to the asyncRequire specified.
|
|
437
|
-
*/
|
|
438
371
|
const makeAsyncRequireTemplate = template.expression(`
|
|
439
372
|
require(ASYNC_REQUIRE_MODULE_PATH)(MODULE_ID, DEPENDENCY_MAP.paths)
|
|
440
373
|
`);
|
|
@@ -454,7 +387,6 @@ const DefaultDependencyTransformer = {
|
|
|
454
387
|
transformSyncRequire(path, dependency, state) {
|
|
455
388
|
const moduleIDExpression = createModuleIDExpression(dependency, state);
|
|
456
389
|
path.node.arguments = [moduleIDExpression];
|
|
457
|
-
// Always add the debug name argument last
|
|
458
390
|
if (state.keepRequireNames) {
|
|
459
391
|
path.node.arguments.push(types.stringLiteral(dependency.name));
|
|
460
392
|
}
|
|
@@ -513,24 +445,6 @@ function createModuleIDExpression(dependency, state) {
|
|
|
513
445
|
function createModuleNameLiteral(dependency) {
|
|
514
446
|
return types.stringLiteral(dependency.name);
|
|
515
447
|
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Given an import qualifier, return a key used to register the dependency.
|
|
519
|
-
* Generally this return the `ImportQualifier.name` property, but more
|
|
520
|
-
* attributes can be appended to distinguish various combinations that would
|
|
521
|
-
* otherwise conflict.
|
|
522
|
-
*
|
|
523
|
-
* For example, the following case would have collision issues if they all utilized the `name` property:
|
|
524
|
-
* ```
|
|
525
|
-
* require('./foo');
|
|
526
|
-
* require.context('./foo');
|
|
527
|
-
* require.context('./foo', true, /something/);
|
|
528
|
-
* require.context('./foo', false, /something/);
|
|
529
|
-
* require.context('./foo', false, /something/, 'lazy');
|
|
530
|
-
* ```
|
|
531
|
-
*
|
|
532
|
-
* This method should be utilized by `registerDependency`.
|
|
533
|
-
*/
|
|
534
448
|
function getKeyForDependency(qualifier) {
|
|
535
449
|
let key = qualifier.name;
|
|
536
450
|
const { asyncType } = qualifier;
|
|
@@ -538,11 +452,7 @@ function getKeyForDependency(qualifier) {
|
|
|
538
452
|
key += ["", asyncType].join("\0");
|
|
539
453
|
}
|
|
540
454
|
const { contextParams } = qualifier;
|
|
541
|
-
// Add extra qualifiers when using `require.context` to prevent collisions.
|
|
542
455
|
if (contextParams) {
|
|
543
|
-
// NOTE(EvanBacon): Keep this synchronized with `RequireContextParams`, if any other properties are added
|
|
544
|
-
// then this key algorithm should be updated to account for those properties.
|
|
545
|
-
// Example: `./directory__true__/foobar/m__lazy`
|
|
546
456
|
key += [
|
|
547
457
|
"",
|
|
548
458
|
"context",
|
|
@@ -550,7 +460,6 @@ function getKeyForDependency(qualifier) {
|
|
|
550
460
|
String(contextParams.filter.pattern),
|
|
551
461
|
String(contextParams.filter.flags),
|
|
552
462
|
contextParams.mode,
|
|
553
|
-
// Join together and append to the name:
|
|
554
463
|
].join("\0");
|
|
555
464
|
}
|
|
556
465
|
return key;
|
|
@@ -577,8 +486,6 @@ class DependencyRegistry {
|
|
|
577
486
|
dependency = newDependency;
|
|
578
487
|
} else {
|
|
579
488
|
if (dependency.isOptional && !qualifier.optional) {
|
|
580
|
-
// A previously optionally required dependency was required non-optionally.
|
|
581
|
-
// Mark it non optional for the whole module
|
|
582
489
|
dependency = {
|
|
583
490
|
...dependency,
|
|
584
491
|
isOptional: false,
|
|
@@ -1,22 +1,7 @@
|
|
|
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
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
1
|
"use strict";
|
|
12
2
|
|
|
13
3
|
const traverse = require("@babel/traverse").default;
|
|
14
4
|
const nullthrows = require("nullthrows");
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Select unused names for "metroImportDefault" and "metroImportAll", by
|
|
18
|
-
* calling "generateUid".
|
|
19
|
-
*/
|
|
20
5
|
function generateImportNames(ast) {
|
|
21
6
|
let importDefault;
|
|
22
7
|
let importAll;
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const accepts = require("accepts");
|
|
@@ -52,8 +41,6 @@ class MultipartResponse {
|
|
|
52
41
|
}
|
|
53
42
|
}
|
|
54
43
|
writeHead(status, headers) {
|
|
55
|
-
// We can't actually change the response HTTP status code
|
|
56
|
-
// because the headers have already been sent
|
|
57
44
|
this.setHeader("X-Http-Status", status);
|
|
58
45
|
if (!headers) {
|
|
59
46
|
return;
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const { greatestLowerBound } = require("metro-source-map/src/Consumer/search");
|
|
@@ -24,9 +13,8 @@ function createFunctionNameGetter(module) {
|
|
|
24
13
|
names: [],
|
|
25
14
|
x_facebook_sources: [[module.functionMap]],
|
|
26
15
|
},
|
|
27
|
-
(name) => name
|
|
16
|
+
(name) => name
|
|
28
17
|
);
|
|
29
|
-
|
|
30
18
|
return ({ line1Based, column0Based }) =>
|
|
31
19
|
consumer.functionNameFor({
|
|
32
20
|
line: line1Based,
|
|
@@ -81,16 +69,11 @@ async function symbolicate(stack, maps, config, extraData) {
|
|
|
81
69
|
return null;
|
|
82
70
|
}
|
|
83
71
|
const mapping = module.map[mappingIndex];
|
|
84
|
-
if (
|
|
85
|
-
mapping[0] !== generatedPosInModule.line1Based ||
|
|
86
|
-
mapping.length < 4 /* no source line/column info */
|
|
87
|
-
) {
|
|
72
|
+
if (mapping[0] !== generatedPosInModule.line1Based || mapping.length < 4) {
|
|
88
73
|
return null;
|
|
89
74
|
}
|
|
90
75
|
return {
|
|
91
|
-
// $FlowFixMe: Length checks do not refine tuple unions.
|
|
92
76
|
line1Based: mapping[2],
|
|
93
|
-
// $FlowFixMe: Length checks do not refine tuple unions.
|
|
94
77
|
column0Based: mapping[3],
|
|
95
78
|
};
|
|
96
79
|
}
|
|
@@ -133,15 +116,6 @@ async function symbolicate(stack, maps, config, extraData) {
|
|
|
133
116
|
column: originalPos.column0Based,
|
|
134
117
|
};
|
|
135
118
|
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* `customizeFrame` allows for custom modifications of the symbolicated frame in a stack.
|
|
139
|
-
* It can be used to collapse stack frames that are not relevant to users, pointing them
|
|
140
|
-
* to more relevant product code instead.
|
|
141
|
-
*
|
|
142
|
-
* An example usecase is a library throwing an error while sanitizing inputs from product code.
|
|
143
|
-
* In some cases, it's more useful to point the developer looking at the error towards the product code directly.
|
|
144
|
-
*/
|
|
145
119
|
async function customizeFrame(frame) {
|
|
146
120
|
const customizations =
|
|
147
121
|
(await config.symbolicator.customizeFrame(frame)) || {};
|
|
@@ -150,14 +124,6 @@ async function symbolicate(stack, maps, config, extraData) {
|
|
|
150
124
|
...customizations,
|
|
151
125
|
};
|
|
152
126
|
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* `customizeStack` allows for custom modifications of a symbolicated stack.
|
|
156
|
-
* Where `customizeFrame` operates on individual frames, this hook can process the entire stack in context.
|
|
157
|
-
*
|
|
158
|
-
* Note: `customizeStack` has access to an `extraData` object which can be used to attach metadata
|
|
159
|
-
* to the error coming in, to be used by the customizeStack hook.
|
|
160
|
-
*/
|
|
161
127
|
async function customizeStack(symbolicatedStack) {
|
|
162
128
|
return await config.symbolicator.customizeStack(
|
|
163
129
|
symbolicatedStack,
|