metro 0.83.3 → 0.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -25
- package/src/Assets.js +42 -29
- package/src/Assets.js.flow +26 -15
- package/src/Bundler/util.js +25 -21
- package/src/Bundler/util.js.flow +2 -2
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.js +4 -4
- package/src/DeltaBundler/DeltaCalculator.js.flow +8 -8
- package/src/DeltaBundler/Graph.js +16 -16
- package/src/DeltaBundler/Graph.js.flow +30 -30
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +8 -8
- package/src/DeltaBundler/Serializers/helpers/js.js +25 -21
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +6 -6
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +25 -21
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +5 -5
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +2 -2
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
- package/src/DeltaBundler/Transformer.js.flow +3 -3
- package/src/DeltaBundler/Worker.flow.js.flow +1 -1
- package/src/DeltaBundler/WorkerFarm.js +1 -1
- package/src/DeltaBundler/WorkerFarm.js.flow +26 -13
- package/src/DeltaBundler/buildSubgraph.js +4 -4
- package/src/DeltaBundler/buildSubgraph.js.flow +8 -8
- package/src/DeltaBundler/types.js.flow +36 -34
- package/src/DeltaBundler.js.flow +2 -2
- package/src/HmrServer.js +34 -29
- package/src/HmrServer.js.flow +17 -12
- package/src/IncrementalBundler.js +29 -21
- package/src/IncrementalBundler.js.flow +13 -9
- package/src/ModuleGraph/worker/JsFileWrapping.js +25 -21
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +10 -5
- package/src/ModuleGraph/worker/collectDependencies.js +25 -21
- package/src/ModuleGraph/worker/collectDependencies.js.flow +27 -21
- package/src/ModuleGraph/worker/generateImportNames.js.flow +4 -2
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +7 -3
- package/src/Server/MultipartResponse.js.flow +1 -1
- package/src/Server/symbolicate.js.flow +4 -4
- package/src/Server.js +139 -39
- package/src/Server.js.flow +158 -47
- package/src/cli/parseKeyValueParamArray.js.flow +1 -1
- package/src/cli-utils.js.flow +2 -2
- package/src/commands/build.js.flow +11 -10
- package/src/commands/dependencies.js.flow +8 -4
- package/src/commands/serve.js +2 -0
- package/src/commands/serve.js.flow +14 -9
- package/src/index.flow.js +30 -26
- package/src/index.flow.js.flow +25 -20
- package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
- package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/index.js +25 -21
- package/src/integration_tests/basic_bundle/import-export/index.js.flow +3 -3
- package/src/integration_tests/basic_bundle/import-export/utils.js.flow +2 -2
- package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js.flow +1 -1
- package/src/integration_tests/basic_bundle/optional-dependencies/index.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/empty.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/matching.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +2 -2
- package/src/integration_tests/basic_bundle/require-context/utils.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/execBundle.js.flow +1 -1
- package/src/lib/BatchProcessor.js +5 -2
- package/src/lib/BatchProcessor.js.flow +10 -7
- package/src/lib/CountingSet.js.flow +4 -4
- package/src/lib/JsonReporter.js +5 -3
- package/src/lib/JsonReporter.js.flow +19 -17
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.js +31 -27
- package/src/lib/TerminalReporter.js.flow +15 -15
- package/src/lib/contextModule.js.flow +1 -1
- package/src/lib/contextModuleTemplates.js +25 -21
- package/src/lib/countLines.js +4 -3
- package/src/lib/countLines.js.flow +3 -4
- package/src/lib/createWebsocketServer.js +9 -2
- package/src/lib/createWebsocketServer.js.flow +16 -9
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/getAppendScripts.js.flow +4 -4
- package/src/lib/getGraphId.js.flow +1 -1
- package/src/lib/getPreludeCode.js +4 -0
- package/src/lib/getPreludeCode.js.flow +10 -3
- package/src/lib/getPrependedScripts.js +36 -22
- package/src/lib/getPrependedScripts.js.flow +10 -3
- package/src/lib/logToConsole.js.flow +2 -2
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +25 -21
- package/src/lib/parseCustomResolverOptions.js.flow +2 -2
- package/src/lib/parseCustomTransformOptions.js.flow +1 -1
- package/src/lib/parseJsonBody.js.flow +11 -1
- package/src/lib/pathUtils.js +25 -21
- package/src/lib/pathUtils.js.flow +1 -1
- package/src/lib/reporting.js.flow +4 -4
- package/src/lib/transformHelpers.js +11 -9
- package/src/lib/transformHelpers.js.flow +17 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.js +48 -42
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +35 -32
- package/src/node-haste/DependencyGraph/createFileMap.js +56 -38
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +44 -18
- package/src/node-haste/DependencyGraph.js +40 -31
- package/src/node-haste/DependencyGraph.js.flow +35 -37
- package/src/node-haste/lib/AssetPaths.js +2 -2
- package/src/node-haste/lib/AssetPaths.js.flow +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.js +6 -6
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +4 -4
- package/src/shared/output/RamBundle/as-assets.js.flow +6 -6
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +5 -5
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +5 -5
- package/src/shared/output/RamBundle/util.js.flow +5 -5
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.js.flow +1 -1
- package/src/shared/output/bundle.flow.js.flow +3 -3
- package/src/shared/output/meta.js +2 -2
- package/src/shared/output/meta.js.flow +1 -1
- package/src/shared/output/writeFile.js +8 -3
- package/src/shared/output/writeFile.js.flow +8 -2
- package/src/shared/types.js.flow +20 -5
- package/src/Asset.d.ts +0 -25
- package/src/Bundler.d.ts +0 -39
- package/src/DeltaBundler/Graph.d.ts +0 -40
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +0 -26
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +0 -18
- package/src/DeltaBundler/Worker.d.ts +0 -45
- package/src/DeltaBundler/types.d.ts +0 -166
- package/src/DeltaBundler.d.ts +0 -58
- package/src/IncrementalBundler.d.ts +0 -98
- package/src/ModuleGraph/test-helpers.js +0 -75
- package/src/ModuleGraph/worker/collectDependencies.d.ts +0 -27
- package/src/Server/MultipartResponse.d.ts +0 -31
- package/src/Server/symbolicate.d.ts +0 -31
- package/src/Server.d.ts +0 -118
- package/src/index.d.ts +0 -193
- package/src/lib/CountingSet.d.ts +0 -48
- package/src/lib/TerminalReporter.d.ts +0 -27
- package/src/lib/contextModule.d.ts +0 -22
- package/src/lib/getGraphId.d.ts +0 -11
- package/src/lib/reporting.d.ts +0 -144
- package/src/node-haste/DependencyGraph.d.ts +0 -62
- package/src/shared/output/bundle.d.ts +0 -35
- package/src/shared/types.d.ts +0 -130
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.84.0",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -11,21 +11,22 @@
|
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git
|
|
14
|
+
"url": "git+https://github.com/facebook/metro.git",
|
|
15
|
+
"directory": "packages/metro"
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|
|
17
18
|
"prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
|
|
18
19
|
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@babel/code-frame": "^7.
|
|
22
|
+
"@babel/code-frame": "^7.29.0",
|
|
22
23
|
"@babel/core": "^7.25.2",
|
|
23
|
-
"@babel/generator": "^7.
|
|
24
|
-
"@babel/parser": "^7.
|
|
25
|
-
"@babel/template": "^7.
|
|
26
|
-
"@babel/traverse": "^7.
|
|
27
|
-
"@babel/types": "^7.
|
|
28
|
-
"accepts": "^
|
|
24
|
+
"@babel/generator": "^7.29.1",
|
|
25
|
+
"@babel/parser": "^7.29.0",
|
|
26
|
+
"@babel/template": "^7.28.6",
|
|
27
|
+
"@babel/traverse": "^7.29.0",
|
|
28
|
+
"@babel/types": "^7.29.0",
|
|
29
|
+
"accepts": "^2.0.0",
|
|
29
30
|
"chalk": "^4.0.0",
|
|
30
31
|
"ci-info": "^2.0.0",
|
|
31
32
|
"connect": "^3.6.5",
|
|
@@ -33,25 +34,25 @@
|
|
|
33
34
|
"error-stack-parser": "^2.0.6",
|
|
34
35
|
"flow-enums-runtime": "^0.0.6",
|
|
35
36
|
"graceful-fs": "^4.2.4",
|
|
36
|
-
"hermes-parser": "0.
|
|
37
|
+
"hermes-parser": "0.33.3",
|
|
37
38
|
"image-size": "^1.0.2",
|
|
38
39
|
"invariant": "^2.2.4",
|
|
39
40
|
"jest-worker": "^29.7.0",
|
|
40
41
|
"jsc-safe-url": "^0.2.2",
|
|
41
42
|
"lodash.throttle": "^4.1.1",
|
|
42
|
-
"metro-babel-transformer": "0.
|
|
43
|
-
"metro-cache": "0.
|
|
44
|
-
"metro-cache-key": "0.
|
|
45
|
-
"metro-config": "0.
|
|
46
|
-
"metro-core": "0.
|
|
47
|
-
"metro-file-map": "0.
|
|
48
|
-
"metro-resolver": "0.
|
|
49
|
-
"metro-runtime": "0.
|
|
50
|
-
"metro-source-map": "0.
|
|
51
|
-
"metro-symbolicate": "0.
|
|
52
|
-
"metro-transform-plugins": "0.
|
|
53
|
-
"metro-transform-worker": "0.
|
|
54
|
-
"mime-types": "^
|
|
43
|
+
"metro-babel-transformer": "0.84.0",
|
|
44
|
+
"metro-cache": "0.84.0",
|
|
45
|
+
"metro-cache-key": "0.84.0",
|
|
46
|
+
"metro-config": "0.84.0",
|
|
47
|
+
"metro-core": "0.84.0",
|
|
48
|
+
"metro-file-map": "0.84.0",
|
|
49
|
+
"metro-resolver": "0.84.0",
|
|
50
|
+
"metro-runtime": "0.84.0",
|
|
51
|
+
"metro-source-map": "0.84.0",
|
|
52
|
+
"metro-symbolicate": "0.84.0",
|
|
53
|
+
"metro-transform-plugins": "0.84.0",
|
|
54
|
+
"metro-transform-worker": "0.84.0",
|
|
55
|
+
"mime-types": "^3.0.1",
|
|
55
56
|
"nullthrows": "^1.1.1",
|
|
56
57
|
"serialize-error": "^2.1.0",
|
|
57
58
|
"source-map": "^0.5.6",
|
|
@@ -65,11 +66,13 @@
|
|
|
65
66
|
"@babel/plugin-transform-runtime": "^7.24.7",
|
|
66
67
|
"@react-native/babel-preset": "0.78.0",
|
|
67
68
|
"@react-native/metro-babel-transformer": "0.78.0",
|
|
69
|
+
"@types/ws": "^7.4.7",
|
|
70
|
+
"@types/yargs": "^17.0.35",
|
|
68
71
|
"babel-jest": "^29.7.0",
|
|
69
72
|
"dedent": "^0.7.0",
|
|
70
73
|
"jest-snapshot": "^29.7.0",
|
|
71
74
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
72
|
-
"metro-babel-register": "0.
|
|
75
|
+
"metro-babel-register": "0.84.0",
|
|
73
76
|
"metro-memory-fs": "*",
|
|
74
77
|
"mock-req": "^0.2.0",
|
|
75
78
|
"mock-res": "^0.6.0",
|
|
@@ -77,6 +80,6 @@
|
|
|
77
80
|
},
|
|
78
81
|
"license": "MIT",
|
|
79
82
|
"engines": {
|
|
80
|
-
"node": "
|
|
83
|
+
"node": "^20.19.4 || ^22.13.0 || ^24.3.0 || >= 25.0.0"
|
|
81
84
|
}
|
|
82
85
|
}
|
package/src/Assets.js
CHANGED
|
@@ -19,28 +19,32 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
19
19
|
function _interopRequireDefault(e) {
|
|
20
20
|
return e && e.__esModule ? e : { default: e };
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
if ("function"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var n = { __proto__: null },
|
|
37
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
|
-
for (var u in e)
|
|
39
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
40
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
41
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
22
|
+
function _interopRequireWildcard(e, t) {
|
|
23
|
+
if ("function" == typeof WeakMap)
|
|
24
|
+
var r = new WeakMap(),
|
|
25
|
+
n = new WeakMap();
|
|
26
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
27
|
+
if (!t && e && e.__esModule) return e;
|
|
28
|
+
var o,
|
|
29
|
+
i,
|
|
30
|
+
f = { __proto__: null, default: e };
|
|
31
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
32
|
+
return f;
|
|
33
|
+
if ((o = t ? n : r)) {
|
|
34
|
+
if (o.has(e)) return o.get(e);
|
|
35
|
+
o.set(e, f);
|
|
42
36
|
}
|
|
43
|
-
|
|
37
|
+
for (const t in e)
|
|
38
|
+
"default" !== t &&
|
|
39
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
40
|
+
((i =
|
|
41
|
+
(o = Object.defineProperty) &&
|
|
42
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
43
|
+
(i.get || i.set)
|
|
44
|
+
? o(f, t, i)
|
|
45
|
+
: (f[t] = e[t]));
|
|
46
|
+
return f;
|
|
47
|
+
})(e, t);
|
|
44
48
|
}
|
|
45
49
|
function isAssetTypeAnImage(type) {
|
|
46
50
|
return (
|
|
@@ -158,7 +162,7 @@ async function getAssetData(
|
|
|
158
162
|
assetPath,
|
|
159
163
|
localPath,
|
|
160
164
|
assetDataPlugins,
|
|
161
|
-
platform
|
|
165
|
+
platform,
|
|
162
166
|
publicPath,
|
|
163
167
|
) {
|
|
164
168
|
let assetUrlPath = localPath.startsWith("..")
|
|
@@ -166,7 +170,7 @@ async function getAssetData(
|
|
|
166
170
|
: _path.default.join(publicPath, _path.default.dirname(localPath));
|
|
167
171
|
assetUrlPath = (0, _pathUtils.normalizePathSeparatorsToPosix)(assetUrlPath);
|
|
168
172
|
const isImage = isAssetTypeAnImage(_path.default.extname(assetPath).slice(1));
|
|
169
|
-
const assetInfo = await getAbsoluteAssetInfo(assetPath, platform);
|
|
173
|
+
const assetInfo = await getAbsoluteAssetInfo(assetPath, platform ?? null);
|
|
170
174
|
const isImageInput = assetInfo.files[0].includes(".zip/")
|
|
171
175
|
? _fs.default.readFileSync(assetInfo.files[0])
|
|
172
176
|
: assetInfo.files[0];
|
|
@@ -203,8 +207,9 @@ async function getAsset(
|
|
|
203
207
|
relativePath,
|
|
204
208
|
projectRoot,
|
|
205
209
|
watchFolders,
|
|
206
|
-
platform
|
|
210
|
+
platform,
|
|
207
211
|
assetExts,
|
|
212
|
+
fileExistsInFileMap,
|
|
208
213
|
) {
|
|
209
214
|
const assetData = AssetPaths.parse(
|
|
210
215
|
relativePath,
|
|
@@ -216,12 +221,20 @@ async function getAsset(
|
|
|
216
221
|
`'${relativePath}' cannot be loaded as its extension is not registered in assetExts`,
|
|
217
222
|
);
|
|
218
223
|
}
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
224
|
+
if (fileExistsInFileMap != null) {
|
|
225
|
+
if (!fileExistsInFileMap(absolutePath)) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`'${relativePath}' could not be found, because it is not within the projectRoot or watchFolders, or it is blocked via the resolver.blockList config`,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
|
|
232
|
+
throw new Error(
|
|
233
|
+
`'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
|
|
234
|
+
);
|
|
235
|
+
}
|
|
223
236
|
}
|
|
224
|
-
const record = await getAbsoluteAssetRecord(absolutePath, platform);
|
|
237
|
+
const record = await getAbsoluteAssetRecord(absolutePath, platform ?? null);
|
|
225
238
|
for (let i = 0; i < record.scales.length; i++) {
|
|
226
239
|
if (record.scales[i] >= assetData.resolution) {
|
|
227
240
|
return _fs.default.promises.readFile(record.files[i]);
|
package/src/Assets.js.flow
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @flow
|
|
7
|
+
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
@@ -15,6 +15,7 @@ import {normalizePathSeparatorsToPosix} from './lib/pathUtils';
|
|
|
15
15
|
import * as AssetPaths from './node-haste/lib/AssetPaths';
|
|
16
16
|
import crypto from 'crypto';
|
|
17
17
|
import fs from 'fs';
|
|
18
|
+
// $FlowFixMe[untyped-import] image-size
|
|
18
19
|
import getImageSize from 'image-size';
|
|
19
20
|
import path from 'path';
|
|
20
21
|
|
|
@@ -92,7 +93,7 @@ export type AssetDataPlugin = (
|
|
|
92
93
|
|
|
93
94
|
function buildAssetMap(
|
|
94
95
|
dir: string,
|
|
95
|
-
files:
|
|
96
|
+
files: ReadonlyArray<string>,
|
|
96
97
|
platform: ?string,
|
|
97
98
|
): Map<string, {files: Array<string>, scales: Array<number>}> {
|
|
98
99
|
const platforms = new Set(platform != null ? [platform] : []);
|
|
@@ -200,8 +201,8 @@ async function getAbsoluteAssetInfo(
|
|
|
200
201
|
export async function getAssetData(
|
|
201
202
|
assetPath: string,
|
|
202
203
|
localPath: string,
|
|
203
|
-
assetDataPlugins:
|
|
204
|
-
platform: ?string
|
|
204
|
+
assetDataPlugins: ReadonlyArray<string>,
|
|
205
|
+
platform: ?string,
|
|
205
206
|
publicPath: string,
|
|
206
207
|
): Promise<AssetData> {
|
|
207
208
|
// If the path of the asset is outside of the projectRoot, we don't want to
|
|
@@ -215,7 +216,7 @@ export async function getAssetData(
|
|
|
215
216
|
assetUrlPath = normalizePathSeparatorsToPosix(assetUrlPath);
|
|
216
217
|
|
|
217
218
|
const isImage = isAssetTypeAnImage(path.extname(assetPath).slice(1));
|
|
218
|
-
const assetInfo = await getAbsoluteAssetInfo(assetPath, platform);
|
|
219
|
+
const assetInfo = await getAbsoluteAssetInfo(assetPath, platform ?? null);
|
|
219
220
|
|
|
220
221
|
const isImageInput = assetInfo.files[0].includes('.zip/')
|
|
221
222
|
? fs.readFileSync(assetInfo.files[0])
|
|
@@ -239,7 +240,7 @@ export async function getAssetData(
|
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
async function applyAssetDataPlugins(
|
|
242
|
-
assetDataPlugins:
|
|
243
|
+
assetDataPlugins: ReadonlyArray<string>,
|
|
243
244
|
assetData: AssetData,
|
|
244
245
|
): Promise<AssetData> {
|
|
245
246
|
if (!assetDataPlugins.length) {
|
|
@@ -279,9 +280,10 @@ export async function getAssetFiles(
|
|
|
279
280
|
export async function getAsset(
|
|
280
281
|
relativePath: string,
|
|
281
282
|
projectRoot: string,
|
|
282
|
-
watchFolders:
|
|
283
|
-
platform: ?string
|
|
284
|
-
assetExts:
|
|
283
|
+
watchFolders: ReadonlyArray<string>,
|
|
284
|
+
platform: ?string,
|
|
285
|
+
assetExts: ReadonlyArray<string>,
|
|
286
|
+
fileExistsInFileMap?: (absolutePath: string) => boolean,
|
|
285
287
|
): Promise<Buffer> {
|
|
286
288
|
const assetData = AssetPaths.parse(
|
|
287
289
|
relativePath,
|
|
@@ -296,13 +298,22 @@ export async function getAsset(
|
|
|
296
298
|
);
|
|
297
299
|
}
|
|
298
300
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
// NOTE: If fileExistsInFileMap is not provided, we fall back to pathBelongsToRoots for backward compatibility, as getAsset is part of the public API.
|
|
302
|
+
if (fileExistsInFileMap != null) {
|
|
303
|
+
if (!fileExistsInFileMap(absolutePath)) {
|
|
304
|
+
throw new Error(
|
|
305
|
+
`'${relativePath}' could not be found, because it is not within the projectRoot or watchFolders, or it is blocked via the resolver.blockList config`,
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
`'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
303
314
|
}
|
|
304
315
|
|
|
305
|
-
const record = await getAbsoluteAssetRecord(absolutePath, platform);
|
|
316
|
+
const record = await getAbsoluteAssetRecord(absolutePath, platform ?? null);
|
|
306
317
|
|
|
307
318
|
for (let i = 0; i < record.scales.length; i++) {
|
|
308
319
|
if (record.scales[i] >= assetData.resolution) {
|
|
@@ -315,7 +326,7 @@ export async function getAsset(
|
|
|
315
326
|
|
|
316
327
|
function pathBelongsToRoots(
|
|
317
328
|
pathToCheck: string,
|
|
318
|
-
roots:
|
|
329
|
+
roots: ReadonlyArray<string>,
|
|
319
330
|
): boolean {
|
|
320
331
|
for (const rootFolder of roots) {
|
|
321
332
|
if (pathToCheck.startsWith(path.resolve(rootFolder))) {
|
package/src/Bundler/util.js
CHANGED
|
@@ -11,28 +11,32 @@ var babelTypes = _interopRequireWildcard(require("@babel/types"));
|
|
|
11
11
|
function _interopRequireDefault(e) {
|
|
12
12
|
return e && e.__esModule ? e : { default: e };
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
if ("function"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var n = { __proto__: null },
|
|
29
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
30
|
-
for (var u in e)
|
|
31
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
32
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
33
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
14
|
+
function _interopRequireWildcard(e, t) {
|
|
15
|
+
if ("function" == typeof WeakMap)
|
|
16
|
+
var r = new WeakMap(),
|
|
17
|
+
n = new WeakMap();
|
|
18
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
19
|
+
if (!t && e && e.__esModule) return e;
|
|
20
|
+
var o,
|
|
21
|
+
i,
|
|
22
|
+
f = { __proto__: null, default: e };
|
|
23
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
24
|
+
return f;
|
|
25
|
+
if ((o = t ? n : r)) {
|
|
26
|
+
if (o.has(e)) return o.get(e);
|
|
27
|
+
o.set(e, f);
|
|
34
28
|
}
|
|
35
|
-
|
|
29
|
+
for (const t in e)
|
|
30
|
+
"default" !== t &&
|
|
31
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
32
|
+
((i =
|
|
33
|
+
(o = Object.defineProperty) &&
|
|
34
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
35
|
+
(i.get || i.set)
|
|
36
|
+
? o(f, t, i)
|
|
37
|
+
: (f[t] = e[t]));
|
|
38
|
+
return f;
|
|
39
|
+
})(e, t);
|
|
36
40
|
}
|
|
37
41
|
const assetPropertyBlockList = new Set(["files", "fileSystemLocation", "path"]);
|
|
38
42
|
function generateAssetCodeFileAst(assetRegistryPath, assetDescriptor) {
|
package/src/Bundler/util.js.flow
CHANGED
|
@@ -67,8 +67,8 @@ function filterObject(
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export function createRamBundleGroups<T: ModuleTransportLike>(
|
|
70
|
-
ramGroups:
|
|
71
|
-
groupableModules:
|
|
70
|
+
ramGroups: ReadonlyArray<string>,
|
|
71
|
+
groupableModules: ReadonlyArray<T>,
|
|
72
72
|
subtree: SubTree<T>,
|
|
73
73
|
): Map<number, Set<number>> {
|
|
74
74
|
// build two maps that allow to lookup module data
|
package/src/Bundler.js.flow
CHANGED
|
@@ -17,7 +17,7 @@ import type {ConfigT} from 'metro-config';
|
|
|
17
17
|
import Transformer from './DeltaBundler/Transformer';
|
|
18
18
|
import DependencyGraph from './node-haste/DependencyGraph';
|
|
19
19
|
|
|
20
|
-
export type BundlerOptions =
|
|
20
|
+
export type BundlerOptions = Readonly<{
|
|
21
21
|
hasReducedPerformance?: boolean,
|
|
22
22
|
watch?: boolean,
|
|
23
23
|
}>;
|
|
@@ -84,8 +84,8 @@ class DeltaCalculator extends _events.default {
|
|
|
84
84
|
});
|
|
85
85
|
return {
|
|
86
86
|
added: this._graph.dependencies,
|
|
87
|
-
modified: new Map(),
|
|
88
87
|
deleted: new Set(),
|
|
88
|
+
modified: new Map(),
|
|
89
89
|
reset: true,
|
|
90
90
|
};
|
|
91
91
|
}
|
|
@@ -157,8 +157,8 @@ class DeltaCalculator extends _events.default {
|
|
|
157
157
|
);
|
|
158
158
|
return {
|
|
159
159
|
added,
|
|
160
|
-
modified: new Map(),
|
|
161
160
|
deleted: new Set(),
|
|
161
|
+
modified: new Map(),
|
|
162
162
|
reset: true,
|
|
163
163
|
};
|
|
164
164
|
}
|
|
@@ -182,8 +182,8 @@ class DeltaCalculator extends _events.default {
|
|
|
182
182
|
if (modifiedDependencies.length === 0) {
|
|
183
183
|
return {
|
|
184
184
|
added: new Map(),
|
|
185
|
-
modified: new Map(),
|
|
186
185
|
deleted: new Set(),
|
|
186
|
+
modified: new Map(),
|
|
187
187
|
reset: false,
|
|
188
188
|
};
|
|
189
189
|
}
|
|
@@ -200,8 +200,8 @@ class DeltaCalculator extends _events.default {
|
|
|
200
200
|
);
|
|
201
201
|
return {
|
|
202
202
|
added,
|
|
203
|
-
modified,
|
|
204
203
|
deleted,
|
|
204
|
+
modified,
|
|
205
205
|
reset: false,
|
|
206
206
|
};
|
|
207
207
|
}
|
|
@@ -34,12 +34,12 @@ export default class DeltaCalculator<T> extends EventEmitter {
|
|
|
34
34
|
_deletedFiles: Set<string> = new Set();
|
|
35
35
|
_modifiedFiles: Set<string> = new Set();
|
|
36
36
|
_addedFiles: Set<string> = new Set();
|
|
37
|
-
_requiresReset = false;
|
|
37
|
+
_requiresReset: boolean = false;
|
|
38
38
|
|
|
39
39
|
_graph: Graph<T>;
|
|
40
40
|
|
|
41
41
|
constructor(
|
|
42
|
-
entryPoints:
|
|
42
|
+
entryPoints: ReadonlySet<string>,
|
|
43
43
|
changeEventSource: EventEmitter,
|
|
44
44
|
options: Options<T>,
|
|
45
45
|
) {
|
|
@@ -154,8 +154,8 @@ export default class DeltaCalculator<T> extends EventEmitter {
|
|
|
154
154
|
|
|
155
155
|
return {
|
|
156
156
|
added: this._graph.dependencies,
|
|
157
|
-
modified: new Map(),
|
|
158
157
|
deleted: new Set(),
|
|
158
|
+
modified: new Map(),
|
|
159
159
|
reset: true,
|
|
160
160
|
};
|
|
161
161
|
}
|
|
@@ -186,7 +186,7 @@ export default class DeltaCalculator<T> extends EventEmitter {
|
|
|
186
186
|
_handleFileChange = (
|
|
187
187
|
{type, filePath, metadata}: ChangeEvent['eventsQueue'][number],
|
|
188
188
|
logger: ?RootPerfLogger,
|
|
189
|
-
):
|
|
189
|
+
): unknown => {
|
|
190
190
|
debug('Handling %s: %s (type: %s)', type, filePath, metadata.type);
|
|
191
191
|
if (
|
|
192
192
|
metadata.type === 'l' ||
|
|
@@ -234,7 +234,7 @@ export default class DeltaCalculator<T> extends EventEmitter {
|
|
|
234
234
|
this._addedFiles.delete(filePath);
|
|
235
235
|
break;
|
|
236
236
|
default:
|
|
237
|
-
|
|
237
|
+
nextState as empty;
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
// Notify users that there is a change in some of the bundle files. This
|
|
@@ -256,8 +256,8 @@ export default class DeltaCalculator<T> extends EventEmitter {
|
|
|
256
256
|
|
|
257
257
|
return {
|
|
258
258
|
added,
|
|
259
|
-
modified: new Map(),
|
|
260
259
|
deleted: new Set(),
|
|
260
|
+
modified: new Map(),
|
|
261
261
|
reset: true,
|
|
262
262
|
};
|
|
263
263
|
}
|
|
@@ -297,8 +297,8 @@ export default class DeltaCalculator<T> extends EventEmitter {
|
|
|
297
297
|
if (modifiedDependencies.length === 0) {
|
|
298
298
|
return {
|
|
299
299
|
added: new Map(),
|
|
300
|
-
modified: new Map(),
|
|
301
300
|
deleted: new Set(),
|
|
301
|
+
modified: new Map(),
|
|
302
302
|
reset: false,
|
|
303
303
|
};
|
|
304
304
|
}
|
|
@@ -317,8 +317,8 @@ export default class DeltaCalculator<T> extends EventEmitter {
|
|
|
317
317
|
|
|
318
318
|
return {
|
|
319
319
|
added,
|
|
320
|
-
modified,
|
|
321
320
|
deleted,
|
|
321
|
+
modified,
|
|
322
322
|
reset: false,
|
|
323
323
|
};
|
|
324
324
|
}
|
|
@@ -18,11 +18,11 @@ function getInternalOptions({ transform, resolve, onProgress, lazy, shallow }) {
|
|
|
18
18
|
let total = 0;
|
|
19
19
|
return {
|
|
20
20
|
lazy,
|
|
21
|
-
transform,
|
|
22
|
-
resolve,
|
|
23
21
|
onDependencyAdd: () => onProgress && onProgress(numProcessed, ++total),
|
|
24
22
|
onDependencyAdded: () => onProgress && onProgress(++numProcessed, total),
|
|
23
|
+
resolve,
|
|
25
24
|
shallow,
|
|
25
|
+
transform,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
function isWeakOrLazy(dependency, options) {
|
|
@@ -88,11 +88,11 @@ class Graph {
|
|
|
88
88
|
} catch (error) {
|
|
89
89
|
const rollbackDelta = {
|
|
90
90
|
added: delta.added,
|
|
91
|
+
baseModuleData: new Map(),
|
|
91
92
|
deleted: delta.deleted,
|
|
93
|
+
errors: new Map(),
|
|
92
94
|
touched: new Set(),
|
|
93
95
|
updatedModuleData: delta.baseModuleData,
|
|
94
|
-
baseModuleData: new Map(),
|
|
95
|
-
errors: new Map(),
|
|
96
96
|
};
|
|
97
97
|
for (const modified of modifiedPathsInBaseGraph) {
|
|
98
98
|
const module = this.dependencies.get(modified);
|
|
@@ -127,8 +127,8 @@ class Graph {
|
|
|
127
127
|
}
|
|
128
128
|
return {
|
|
129
129
|
added,
|
|
130
|
-
modified,
|
|
131
130
|
deleted: delta.deleted,
|
|
131
|
+
modified,
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
async initialTraverseDependencies(options) {
|
|
@@ -155,8 +155,8 @@ class Graph {
|
|
|
155
155
|
});
|
|
156
156
|
return {
|
|
157
157
|
added: this.dependencies,
|
|
158
|
-
modified: new Map(),
|
|
159
158
|
deleted: new Set(),
|
|
159
|
+
modified: new Map(),
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
162
|
async _buildDelta(pathsToVisit, options, moduleFilter) {
|
|
@@ -165,27 +165,27 @@ class Graph {
|
|
|
165
165
|
this.#resolvedContexts,
|
|
166
166
|
{
|
|
167
167
|
resolve: options.resolve,
|
|
168
|
-
transform: async (absolutePath, requireContext) => {
|
|
169
|
-
options.onDependencyAdd();
|
|
170
|
-
const result = await options.transform(absolutePath, requireContext);
|
|
171
|
-
options.onDependencyAdded();
|
|
172
|
-
return result;
|
|
173
|
-
},
|
|
174
168
|
shouldTraverse: (dependency) => {
|
|
175
169
|
if (options.shallow || isWeakOrLazy(dependency, options)) {
|
|
176
170
|
return false;
|
|
177
171
|
}
|
|
178
172
|
return moduleFilter == null || moduleFilter(dependency.absolutePath);
|
|
179
173
|
},
|
|
174
|
+
transform: async (absolutePath, requireContext) => {
|
|
175
|
+
options.onDependencyAdd();
|
|
176
|
+
const result = await options.transform(absolutePath, requireContext);
|
|
177
|
+
options.onDependencyAdded();
|
|
178
|
+
return result;
|
|
179
|
+
},
|
|
180
180
|
},
|
|
181
181
|
);
|
|
182
182
|
return {
|
|
183
183
|
added: new Set(),
|
|
184
|
-
touched: new Set(),
|
|
185
|
-
deleted: new Set(),
|
|
186
|
-
updatedModuleData: subGraph.moduleData,
|
|
187
184
|
baseModuleData: new Map(),
|
|
185
|
+
deleted: new Set(),
|
|
188
186
|
errors: subGraph.errors,
|
|
187
|
+
touched: new Set(),
|
|
188
|
+
updatedModuleData: subGraph.moduleData,
|
|
189
189
|
};
|
|
190
190
|
}
|
|
191
191
|
_recursivelyCommitModule(
|
|
@@ -462,9 +462,9 @@ class Graph {
|
|
|
462
462
|
}
|
|
463
463
|
return {
|
|
464
464
|
dependencies: new Map(dependencies),
|
|
465
|
-
resolvedContexts,
|
|
466
465
|
getSource,
|
|
467
466
|
output,
|
|
467
|
+
resolvedContexts,
|
|
468
468
|
unstable_transformResultKey,
|
|
469
469
|
};
|
|
470
470
|
}
|