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
|
@@ -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
|
function getPreludeCode({
|
|
@@ -18,8 +7,6 @@ function getPreludeCode({
|
|
|
18
7
|
requireCycleIgnorePatterns,
|
|
19
8
|
}) {
|
|
20
9
|
const vars = [
|
|
21
|
-
// Ensure these variable names match the ones referenced in metro-runtime
|
|
22
|
-
// require.js
|
|
23
10
|
"__BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now()",
|
|
24
11
|
`__DEV__=${String(isDev)}`,
|
|
25
12
|
...formatExtraVars(extraVars),
|
|
@@ -27,8 +14,6 @@ function getPreludeCode({
|
|
|
27
14
|
`__METRO_GLOBAL_PREFIX__='${globalPrefix}'`,
|
|
28
15
|
];
|
|
29
16
|
if (isDev) {
|
|
30
|
-
// Ensure these variable names match the ones referenced in metro-runtime
|
|
31
|
-
// require.js
|
|
32
17
|
vars.push(
|
|
33
18
|
`${globalPrefix}__requireCycleIgnorePatterns=[${requireCycleIgnorePatterns
|
|
34
19
|
.map((regex) => regex.toString())
|
|
@@ -44,9 +29,6 @@ function formatExtraVars(extraVars) {
|
|
|
44
29
|
const assignments = [];
|
|
45
30
|
for (const key in extraVars) {
|
|
46
31
|
if (extraVars.hasOwnProperty(key) && !excluded.has(key)) {
|
|
47
|
-
/* $FlowFixMe(>=0.95.0 site=react_native_fb) This comment suppresses an
|
|
48
|
-
* error found when Flow v0.95 was deployed. To see the error, delete
|
|
49
|
-
* this comment and run Flow. */
|
|
50
32
|
assignments.push(`${key}=${JSON.stringify(extraVars[key])}`);
|
|
51
33
|
}
|
|
52
34
|
}
|
|
@@ -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
|
var _CountingSet = _interopRequireDefault(require("./CountingSet"));
|
|
@@ -26,8 +15,6 @@ async function getPrependedScripts(
|
|
|
26
15
|
bundler,
|
|
27
16
|
deltaBundler
|
|
28
17
|
) {
|
|
29
|
-
// Get all the polyfills from the relevant option params (the
|
|
30
|
-
// `getPolyfills()` method and the `polyfillModuleNames` variable).
|
|
31
18
|
const polyfillModuleNames = config.serializer
|
|
32
19
|
.getPolyfills({
|
|
33
20
|
platform: options.platform,
|
package/src/lib/logToConsole.js
CHANGED
|
@@ -1,15 +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
|
-
/* eslint-disable no-console */
|
|
12
|
-
|
|
13
1
|
"use strict";
|
|
14
2
|
|
|
15
3
|
const chalk = require("chalk");
|
|
@@ -29,7 +17,6 @@ module.exports = (terminal, level, mode, ...data) => {
|
|
|
29
17
|
} else if (level === "groupCollapsed") {
|
|
30
18
|
groupStack.push(level);
|
|
31
19
|
clearTimeout(collapsedGuardTimer);
|
|
32
|
-
// Inform users that logs get swallowed if they forget to call `groupEnd`.
|
|
33
20
|
collapsedGuardTimer = setTimeout(() => {
|
|
34
21
|
if (groupStack.includes("groupCollapsed")) {
|
|
35
22
|
terminal.log(
|
|
@@ -48,7 +35,6 @@ module.exports = (terminal, level, mode, ...data) => {
|
|
|
48
35
|
return;
|
|
49
36
|
}
|
|
50
37
|
if (!groupStack.includes("groupCollapsed")) {
|
|
51
|
-
// Remove excess whitespace at the end of a log message, if possible.
|
|
52
38
|
const lastItem = data[data.length - 1];
|
|
53
39
|
if (typeof lastItem === "string") {
|
|
54
40
|
data[data.length - 1] = lastItem.trimEnd();
|
|
@@ -58,10 +44,6 @@ module.exports = (terminal, level, mode, ...data) => {
|
|
|
58
44
|
terminal.log(
|
|
59
45
|
color.bold(` ${modePrefix}${logFunction.toUpperCase()} `) +
|
|
60
46
|
"".padEnd(groupStack.length * 2, " "),
|
|
61
|
-
// `util.format` actually accepts any arguments.
|
|
62
|
-
// If the first argument is a string, it tries to format it.
|
|
63
|
-
// Otherwise, it just concatenates all arguments.
|
|
64
|
-
// $FlowIssue[incompatible-call] util.format expected the first argument to be a string
|
|
65
47
|
util.format(...data)
|
|
66
48
|
);
|
|
67
49
|
}
|
|
@@ -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 nullthrows = require("nullthrows");
|
|
@@ -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 nullthrows = require("nullthrows");
|
|
@@ -18,7 +7,6 @@ module.exports = function parseCustomTransformOptions(urlObj) {
|
|
|
18
7
|
const query = nullthrows(urlObj.query);
|
|
19
8
|
Object.keys(query).forEach((key) => {
|
|
20
9
|
if (key.startsWith(PREFIX)) {
|
|
21
|
-
// $FlowFixMe[prop-missing]
|
|
22
10
|
customTransformOptions[key.substr(PREFIX.length)] = query[key];
|
|
23
11
|
}
|
|
24
12
|
});
|
|
@@ -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 parsePlatformFilePath = require("../node-haste/lib/parsePlatformFilePath");
|
|
@@ -29,7 +18,7 @@ const getTransformProfile = (transformProfile) =>
|
|
|
29
18
|
? transformProfile
|
|
30
19
|
: "default";
|
|
31
20
|
module.exports = function parseOptionsFromUrl(normalizedRequestUrl, platforms) {
|
|
32
|
-
const parsedURL = nullthrows(url.parse(normalizedRequestUrl, true));
|
|
21
|
+
const parsedURL = nullthrows(url.parse(normalizedRequestUrl, true));
|
|
33
22
|
const query = nullthrows(parsedURL.query);
|
|
34
23
|
const pathname =
|
|
35
24
|
query.bundleEntry ||
|
|
@@ -55,11 +44,6 @@ module.exports = function parseOptionsFromUrl(normalizedRequestUrl, platforms) {
|
|
|
55
44
|
shallow: getBoolean(query, "shallow", false),
|
|
56
45
|
sourceMapUrl: url.format({
|
|
57
46
|
...parsedURL,
|
|
58
|
-
// The Chrome Debugger loads bundles via Blob urls, whose
|
|
59
|
-
// protocol is blob:http. This breaks loading source maps through
|
|
60
|
-
// protocol-relative URLs, which is why we must force the HTTP protocol
|
|
61
|
-
// when loading the bundle for either Android or iOS.
|
|
62
|
-
// TODO(T167298674): Remove when remote debugging is not needed in React Native
|
|
63
47
|
protocol:
|
|
64
48
|
platform != null && platform.match(/^(android|ios|vr|windows|macos)$/)
|
|
65
49
|
? "http"
|
|
@@ -1,19 +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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const path = require("path");
|
|
15
4
|
function relativizeSourceMapInline(sourceMap, sourcesRoot) {
|
|
16
|
-
// eslint-disable-next-line lint/strictly-null
|
|
17
5
|
if (sourceMap.mappings === undefined) {
|
|
18
6
|
for (let i = 0; i < sourceMap.sections.length; i++) {
|
|
19
7
|
relativizeSourceMapInline(sourceMap.sections[i].map, sourcesRoot);
|
package/src/lib/reporting.js
CHANGED
|
@@ -1,49 +1,19 @@
|
|
|
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 chalk = require("chalk");
|
|
15
4
|
const stripAnsi = require("strip-ansi");
|
|
16
5
|
const util = require("util");
|
|
17
|
-
/**
|
|
18
|
-
* A standard way to log a warning to the terminal. This should not be called
|
|
19
|
-
* from some arbitrary Metro logic, only from the reporters. Instead of
|
|
20
|
-
* calling this, add a new type of ReportableEvent instead, and implement a
|
|
21
|
-
* proper handler in the reporter(s).
|
|
22
|
-
*/
|
|
23
6
|
function logWarning(terminal, format, ...args) {
|
|
24
7
|
const str = util.format(format, ...args);
|
|
25
8
|
terminal.log("%s: %s", chalk.yellow("warning"), str);
|
|
26
9
|
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Similar to `logWarning`, but for messages that require the user to act.
|
|
30
|
-
*/
|
|
31
10
|
function logError(terminal, format, ...args) {
|
|
32
11
|
terminal.log(
|
|
33
12
|
"%s: %s",
|
|
34
13
|
chalk.red("error"),
|
|
35
|
-
// Syntax errors may have colors applied for displaying code frames
|
|
36
|
-
// in various places outside of where Metro is currently running.
|
|
37
|
-
// If the current terminal does not support color, we'll strip the colors
|
|
38
|
-
// here.
|
|
39
14
|
util.format(chalk.supportsColor ? format : stripAnsi(format), ...args)
|
|
40
15
|
);
|
|
41
16
|
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* A reporter that does nothing. Errors and warnings will be swallowed, that
|
|
45
|
-
* is generally not what you want.
|
|
46
|
-
*/
|
|
47
17
|
const nullReporter = {
|
|
48
18
|
update() {},
|
|
49
19
|
};
|
|
@@ -1,19 +1,5 @@
|
|
|
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
|
-
/**
|
|
15
|
-
* Splits a BundleOptions object into smaller, more manageable parts.
|
|
16
|
-
*/
|
|
17
3
|
function splitBundleOptions(options) {
|
|
18
4
|
return {
|
|
19
5
|
entryFile: options.entryFile,
|
|
@@ -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
|
var _contextModuleTemplates = require("./contextModuleTemplates");
|
|
@@ -43,10 +32,6 @@ async function calcTransformerOptions(
|
|
|
43
32
|
platform: options.platform,
|
|
44
33
|
unstable_transformProfile: options.unstable_transformProfile,
|
|
45
34
|
};
|
|
46
|
-
|
|
47
|
-
// When we're processing scripts, we don't need to calculate any
|
|
48
|
-
// inlineRequires information, since scripts by definition don't have
|
|
49
|
-
// requires().
|
|
50
35
|
if (options.type === "script") {
|
|
51
36
|
return {
|
|
52
37
|
...baseOptions,
|
|
@@ -129,11 +114,6 @@ async function getTransformFn(
|
|
|
129
114
|
let templateBuffer;
|
|
130
115
|
if (requireContext) {
|
|
131
116
|
const graph = await bundler.getDependencyGraph();
|
|
132
|
-
|
|
133
|
-
// TODO: Check delta changes to avoid having to look over all files each time
|
|
134
|
-
// this is a massive performance boost.
|
|
135
|
-
|
|
136
|
-
// Search against all files in a subtree.
|
|
137
117
|
const files = Array.from(
|
|
138
118
|
graph.matchFilesWithContext(requireContext.from, {
|
|
139
119
|
filter: requireContext.filter,
|
|
@@ -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 { codeFrameColumns } = require("@babel/code-frame");
|
|
@@ -19,10 +8,6 @@ const createDefaultContext = require("metro-resolver/src/createDefaultContext");
|
|
|
19
8
|
const path = require("path");
|
|
20
9
|
const util = require("util");
|
|
21
10
|
class ModuleResolver {
|
|
22
|
-
// A module representing the project root, used as the origin when resolving `emptyModulePath`.
|
|
23
|
-
|
|
24
|
-
// An empty module, the result of resolving `emptyModulePath` from the project root.
|
|
25
|
-
|
|
26
11
|
constructor(options) {
|
|
27
12
|
this._options = options;
|
|
28
13
|
const { projectRoot, moduleCache } = this._options;
|
|
@@ -53,7 +38,7 @@ class ModuleResolver {
|
|
|
53
38
|
},
|
|
54
39
|
false,
|
|
55
40
|
null,
|
|
56
|
-
|
|
41
|
+
{
|
|
57
42
|
dev: false,
|
|
58
43
|
}
|
|
59
44
|
);
|
|
@@ -171,20 +156,14 @@ class ModuleResolver {
|
|
|
171
156
|
_getPackage = (packageJsonPath) => {
|
|
172
157
|
try {
|
|
173
158
|
return this._options.moduleCache.getPackage(packageJsonPath).read();
|
|
174
|
-
} catch (e) {
|
|
175
|
-
// Do nothing. The standard module cache does not trigger any error, but
|
|
176
|
-
// the ModuleGraph one does, if the module does not exist.
|
|
177
|
-
}
|
|
159
|
+
} catch (e) {}
|
|
178
160
|
return null;
|
|
179
161
|
};
|
|
180
162
|
_getPackageForModule = (fromModule, modulePath) => {
|
|
181
163
|
let pkg;
|
|
182
164
|
try {
|
|
183
165
|
pkg = this._options.moduleCache.getPackageOf(modulePath);
|
|
184
|
-
} catch (e) {
|
|
185
|
-
// Do nothing. The standard module cache does not trigger any error, but
|
|
186
|
-
// the ModuleGraph one does, if the module does not exist.
|
|
187
|
-
}
|
|
166
|
+
} catch (e) {}
|
|
188
167
|
return pkg != null
|
|
189
168
|
? {
|
|
190
169
|
rootPath: path.dirname(pkg.path),
|
|
@@ -192,17 +171,11 @@ class ModuleResolver {
|
|
|
192
171
|
}
|
|
193
172
|
: null;
|
|
194
173
|
};
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* TODO: Return Resolution instead of coercing to BundlerResolution here
|
|
198
|
-
*/
|
|
199
174
|
_getFileResolvedModule(resolution) {
|
|
200
175
|
switch (resolution.type) {
|
|
201
176
|
case "sourceFile":
|
|
202
177
|
return resolution;
|
|
203
178
|
case "assetFiles":
|
|
204
|
-
// FIXME: we should forward ALL the paths/metadata,
|
|
205
|
-
// not just an arbitrary item!
|
|
206
179
|
const arbitrary = getArrayLowestItem(resolution.filePaths);
|
|
207
180
|
invariant(arbitrary != null, "invalid asset resolution");
|
|
208
181
|
return {
|
|
@@ -245,19 +218,6 @@ function getArrayLowestItem(a) {
|
|
|
245
218
|
return lowest;
|
|
246
219
|
}
|
|
247
220
|
class UnableToResolveError extends Error {
|
|
248
|
-
/**
|
|
249
|
-
* File path of the module that tried to require a module, ex. `/js/foo.js`.
|
|
250
|
-
*/
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* The name of the module that was required, no necessarily a path,
|
|
254
|
-
* ex. `./bar`, or `invariant`.
|
|
255
|
-
*/
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Original error that causes this error
|
|
259
|
-
*/
|
|
260
|
-
|
|
261
221
|
constructor(originModulePath, targetModuleName, message, options) {
|
|
262
222
|
super();
|
|
263
223
|
this.originModulePath = originModulePath;
|
|
@@ -278,10 +238,6 @@ class UnableToResolveError extends Error {
|
|
|
278
238
|
file = fs.readFileSync(this.originModulePath, "utf8");
|
|
279
239
|
} catch (error) {
|
|
280
240
|
if (error.code === "ENOENT" || error.code === "EISDIR") {
|
|
281
|
-
// We're probably dealing with a virtualised file system where
|
|
282
|
-
// `this.originModulePath` doesn't actually exist on disk.
|
|
283
|
-
// We can't show a code frame, but there's no need to let this I/O
|
|
284
|
-
// error shadow the original module resolution error.
|
|
285
241
|
return null;
|
|
286
242
|
}
|
|
287
243
|
throw error;
|
|
@@ -292,8 +248,7 @@ class UnableToResolveError extends Error {
|
|
|
292
248
|
file,
|
|
293
249
|
this.targetModuleName
|
|
294
250
|
)
|
|
295
|
-
:
|
|
296
|
-
guessDependencyLocation(file, this.targetModuleName);
|
|
251
|
+
: guessDependencyLocation(file, this.targetModuleName);
|
|
297
252
|
return codeFrameColumns(
|
|
298
253
|
fs.readFileSync(this.originModulePath, "utf8"),
|
|
299
254
|
location,
|
|
@@ -303,16 +258,8 @@ class UnableToResolveError extends Error {
|
|
|
303
258
|
);
|
|
304
259
|
}
|
|
305
260
|
}
|
|
306
|
-
|
|
307
|
-
// Given a source location for an import declaration or `require()` call (etc),
|
|
308
|
-
// return a location for use with @babel/code-frame in the resolution error.
|
|
309
261
|
function refineDependencyLocation(loc, fileContents, targetSpecifier) {
|
|
310
262
|
const lines = fileContents.split("\n");
|
|
311
|
-
// If we can find the module name in range of the given loc, surrounded by
|
|
312
|
-
// matching quotes, that's likely our specifier. Point to the first column of
|
|
313
|
-
// the *last* valid occurrence.
|
|
314
|
-
// Note that module names may not always be found in the source code verbatim,
|
|
315
|
-
// whether because of escaping or because of exotic dependency APIs.
|
|
316
263
|
for (let line = loc.end.line - 1; line >= loc.start.line - 1; line--) {
|
|
317
264
|
const maxColumn =
|
|
318
265
|
line === loc.end.line ? loc.end.column + 2 : lines[line].length;
|
|
@@ -321,10 +268,7 @@ function refineDependencyLocation(loc, fileContents, targetSpecifier) {
|
|
|
321
268
|
const lineSlice = lineStr.slice(minColumn, maxColumn);
|
|
322
269
|
for (
|
|
323
270
|
let offset = lineSlice.lastIndexOf(targetSpecifier);
|
|
324
|
-
offset !== -1 &&
|
|
325
|
-
// leave room for quotes
|
|
326
|
-
offset > 0 &&
|
|
327
|
-
offset < lineSlice.length - 1;
|
|
271
|
+
offset !== -1 && offset > 0 && offset < lineSlice.length - 1;
|
|
328
272
|
offset = lineSlice.lastIndexOf(targetSpecifier, offset - 1)
|
|
329
273
|
) {
|
|
330
274
|
const maybeQuoteBefore = lineSlice[minColumn + offset - 1];
|
|
@@ -340,7 +284,6 @@ function refineDependencyLocation(loc, fileContents, targetSpecifier) {
|
|
|
340
284
|
}
|
|
341
285
|
}
|
|
342
286
|
}
|
|
343
|
-
// Otherwise, if this is a single-line loc, return it exactly, as a range.
|
|
344
287
|
if (loc.start.line === loc.end.line) {
|
|
345
288
|
return {
|
|
346
289
|
start: {
|
|
@@ -353,8 +296,6 @@ function refineDependencyLocation(loc, fileContents, targetSpecifier) {
|
|
|
353
296
|
},
|
|
354
297
|
};
|
|
355
298
|
}
|
|
356
|
-
// Otherwise, point to the first column of the loc, to avoid including too
|
|
357
|
-
// much unnecessary context.
|
|
358
299
|
return {
|
|
359
300
|
start: {
|
|
360
301
|
line: loc.start.line,
|
|
@@ -41,24 +41,10 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
41
41
|
}
|
|
42
42
|
return newObj;
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
46
|
-
*
|
|
47
|
-
* This source code is licensed under the MIT license found in the
|
|
48
|
-
* LICENSE file in the root directory of this source tree.
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @format
|
|
52
|
-
* @oncall react_native
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
44
|
const ci = require("ci-info");
|
|
56
45
|
function getIgnorePattern(config) {
|
|
57
|
-
// For now we support both options
|
|
58
46
|
const { blockList, blacklistRE } = config.resolver;
|
|
59
47
|
const ignorePattern = blacklistRE || blockList;
|
|
60
|
-
|
|
61
|
-
// If neither option has been set, use default pattern
|
|
62
48
|
if (!ignorePattern) {
|
|
63
49
|
return / ^/;
|
|
64
50
|
}
|
|
@@ -81,8 +67,6 @@ function getIgnorePattern(config) {
|
|
|
81
67
|
.join("|"),
|
|
82
68
|
regexes[0]?.flags ?? ""
|
|
83
69
|
);
|
|
84
|
-
|
|
85
|
-
// If ignorePattern is an array, merge it into one
|
|
86
70
|
if (Array.isArray(ignorePattern)) {
|
|
87
71
|
return combine(ignorePattern);
|
|
88
72
|
}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _metroFileMap = require("metro-file-map");
|
|
4
|
-
/**
|
|
5
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @format
|
|
12
|
-
* @oncall react_native
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
4
|
const createFileMap = require("./DependencyGraph/createFileMap");
|
|
16
5
|
const { ModuleResolver } = require("./DependencyGraph/ModuleResolution");
|
|
17
6
|
const ModuleCache = require("./ModuleCache");
|
|
@@ -50,9 +39,6 @@ class DependencyGraph extends EventEmitter {
|
|
|
50
39
|
const fileMap = createFileMap(config, {
|
|
51
40
|
watch,
|
|
52
41
|
});
|
|
53
|
-
|
|
54
|
-
// We can have a lot of graphs listening to Haste for changes.
|
|
55
|
-
// Bump this up to silence the max listeners EventEmitter warning.
|
|
56
42
|
fileMap.setMaxListeners(1000);
|
|
57
43
|
this._haste = fileMap;
|
|
58
44
|
this._haste.on("status", (status) => this._onWatcherStatus(status));
|
|
@@ -86,15 +72,9 @@ class DependencyGraph extends EventEmitter {
|
|
|
86
72
|
status,
|
|
87
73
|
});
|
|
88
74
|
}
|
|
89
|
-
|
|
90
|
-
// Waits for the dependency graph to become ready after initialisation.
|
|
91
|
-
// Don't read anything from the graph until this resolves.
|
|
92
75
|
async ready() {
|
|
93
76
|
await this._readyPromise;
|
|
94
77
|
}
|
|
95
|
-
|
|
96
|
-
// Creates the dependency graph and waits for it to become ready.
|
|
97
|
-
// @deprecated Use the constructor + ready() directly.
|
|
98
78
|
static async load(config, options) {
|
|
99
79
|
const self = new DependencyGraph(config, options);
|
|
100
80
|
await self.ready();
|
|
@@ -105,8 +85,6 @@ class DependencyGraph extends EventEmitter {
|
|
|
105
85
|
const root = parsedPath.root;
|
|
106
86
|
let dir = path.join(parsedPath.dir, parsedPath.base);
|
|
107
87
|
do {
|
|
108
|
-
// If we've hit a node_modules directory, the closest package was not
|
|
109
|
-
// found (`filePath` was likely nonexistent).
|
|
110
88
|
if (path.basename(dir) === "node_modules") {
|
|
111
89
|
return null;
|
|
112
90
|
}
|
|
@@ -127,6 +105,10 @@ class DependencyGraph extends EventEmitter {
|
|
|
127
105
|
this.emit("change");
|
|
128
106
|
}
|
|
129
107
|
_createModuleResolver() {
|
|
108
|
+
const getRealPathIfFile = (path) => {
|
|
109
|
+
const result = this._fileSystem.lookup(path);
|
|
110
|
+
return result.exists && result.type === "f" ? result.realPath : null;
|
|
111
|
+
};
|
|
130
112
|
this._moduleResolver = new ModuleResolver({
|
|
131
113
|
assetExts: new Set(this._config.resolver.assetExts),
|
|
132
114
|
dirExists: (filePath) => {
|
|
@@ -159,9 +141,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
159
141
|
),
|
|
160
142
|
];
|
|
161
143
|
if (this._config.resolver.unstable_enableSymlinks) {
|
|
162
|
-
assets = assets
|
|
163
|
-
.map((candidate) => this._fileSystem.getRealPath(candidate))
|
|
164
|
-
.filter(Boolean);
|
|
144
|
+
assets = assets.map(getRealPathIfFile).filter(Boolean);
|
|
165
145
|
} else {
|
|
166
146
|
assets = assets.filter((candidate) =>
|
|
167
147
|
this._fileSystem.exists(candidate)
|
|
@@ -177,7 +157,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
177
157
|
unstable_enablePackageExports:
|
|
178
158
|
this._config.resolver.unstable_enablePackageExports,
|
|
179
159
|
unstable_getRealPath: this._config.resolver.unstable_enableSymlinks
|
|
180
|
-
?
|
|
160
|
+
? getRealPathIfFile
|
|
181
161
|
: null,
|
|
182
162
|
});
|
|
183
163
|
}
|
|
@@ -190,15 +170,6 @@ class DependencyGraph extends EventEmitter {
|
|
|
190
170
|
return nullthrows(this._fileSystem).getAllFiles();
|
|
191
171
|
}
|
|
192
172
|
getSha1(filename) {
|
|
193
|
-
// Prior to unstable_enableSymlinks:
|
|
194
|
-
// Calling realpath allows us to get a hash for a given path even when
|
|
195
|
-
// it's a symlink to a file, which prevents Metro from crashing in such a
|
|
196
|
-
// case. However, it doesn't allow Metro to track changes to the target file
|
|
197
|
-
// of the symlink. We should fix this by implementing a symlink map into
|
|
198
|
-
// Metro (or maybe by implementing those "extra transformation sources" we've
|
|
199
|
-
// been talking about for stuff like CSS or WASM).
|
|
200
|
-
//
|
|
201
|
-
// This is unnecessary with a symlink-aware fileSystem implementation.
|
|
202
173
|
const resolvedPath = this._config.resolver.unstable_enableSymlinks
|
|
203
174
|
? filename
|
|
204
175
|
: fs.realpathSync(filename);
|
|
@@ -215,11 +186,8 @@ class DependencyGraph extends EventEmitter {
|
|
|
215
186
|
return this._haste;
|
|
216
187
|
}
|
|
217
188
|
end() {
|
|
218
|
-
// $FlowFixMe[unused-promise]
|
|
219
189
|
this._haste.end();
|
|
220
190
|
}
|
|
221
|
-
|
|
222
|
-
/** Given a search context, return a list of file paths matching the query. */
|
|
223
191
|
matchFilesWithContext(from, context) {
|
|
224
192
|
return this._fileSystem.matchFiles({
|
|
225
193
|
rootDir: from,
|
|
@@ -234,30 +202,22 @@ class DependencyGraph extends EventEmitter {
|
|
|
234
202
|
dependency,
|
|
235
203
|
platform,
|
|
236
204
|
resolverOptions,
|
|
237
|
-
// TODO: Fold assumeFlatNodeModules into resolverOptions and add to graphId
|
|
238
205
|
{ assumeFlatNodeModules } = {
|
|
239
206
|
assumeFlatNodeModules: false,
|
|
240
207
|
}
|
|
241
208
|
) {
|
|
242
209
|
const to = dependency.name;
|
|
243
210
|
const isSensitiveToOriginFolder =
|
|
244
|
-
// Resolution is always relative to the origin folder unless we assume a flat node_modules
|
|
245
211
|
!assumeFlatNodeModules ||
|
|
246
|
-
// Path requests are resolved relative to the origin folder
|
|
247
212
|
to.includes("/") ||
|
|
248
213
|
to === "." ||
|
|
249
214
|
to === ".." ||
|
|
250
|
-
// Preserve standard assumptions under node_modules
|
|
251
215
|
from.includes(path.sep + "node_modules" + path.sep);
|
|
252
|
-
|
|
253
|
-
// Compound key for the resolver cache
|
|
254
216
|
const resolverOptionsKey =
|
|
255
217
|
JSON.stringify(resolverOptions ?? {}, canonicalize) ?? "";
|
|
256
218
|
const originKey = isSensitiveToOriginFolder ? path.dirname(from) : "";
|
|
257
219
|
const targetKey = to;
|
|
258
220
|
const platformKey = platform ?? NULL_PLATFORM;
|
|
259
|
-
|
|
260
|
-
// Traverse the resolver cache, which is a tree of maps
|
|
261
221
|
const mapByResolverOptions = this._resolutionCache;
|
|
262
222
|
const mapByOrigin = getOrCreateMap(
|
|
263
223
|
mapByResolverOptions,
|
|
@@ -180,6 +180,11 @@ class DependencyGraph extends EventEmitter {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
_createModuleResolver() {
|
|
183
|
+
const getRealPathIfFile = (path: string) => {
|
|
184
|
+
const result = this._fileSystem.lookup(path);
|
|
185
|
+
return result.exists && result.type === 'f' ? result.realPath : null;
|
|
186
|
+
};
|
|
187
|
+
|
|
183
188
|
this._moduleResolver = new ModuleResolver({
|
|
184
189
|
assetExts: new Set(this._config.resolver.assetExts),
|
|
185
190
|
dirExists: (filePath: string) => {
|
|
@@ -213,9 +218,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
213
218
|
];
|
|
214
219
|
|
|
215
220
|
if (this._config.resolver.unstable_enableSymlinks) {
|
|
216
|
-
assets = assets
|
|
217
|
-
.map(candidate => this._fileSystem.getRealPath(candidate))
|
|
218
|
-
.filter(Boolean);
|
|
221
|
+
assets = assets.map(getRealPathIfFile).filter(Boolean);
|
|
219
222
|
} else {
|
|
220
223
|
assets = assets.filter(candidate =>
|
|
221
224
|
this._fileSystem.exists(candidate),
|
|
@@ -232,7 +235,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
232
235
|
unstable_enablePackageExports:
|
|
233
236
|
this._config.resolver.unstable_enablePackageExports,
|
|
234
237
|
unstable_getRealPath: this._config.resolver.unstable_enableSymlinks
|
|
235
|
-
?
|
|
238
|
+
? getRealPathIfFile
|
|
236
239
|
: null,
|
|
237
240
|
});
|
|
238
241
|
}
|