metro 0.73.3 → 0.73.5
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 +24 -25
- package/src/Assets.js +7 -40
- package/src/Bundler/util.js +27 -33
- package/src/Bundler/util.js.flow +1 -0
- package/src/Bundler.js +4 -12
- package/src/DeltaBundler/DeltaCalculator.js +49 -63
- package/src/DeltaBundler/DeltaCalculator.js.flow +27 -21
- package/src/DeltaBundler/Graph.js +124 -159
- package/src/DeltaBundler/Graph.js.flow +57 -43
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +3 -9
- package/src/DeltaBundler/Serializers/baseJSBundle.js +3 -6
- package/src/DeltaBundler/Serializers/getAllFiles.js +1 -9
- package/src/DeltaBundler/Serializers/getAssets.js +1 -6
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +1 -4
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +2 -15
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +4 -12
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +1 -1
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +1 -4
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +4 -9
- package/src/DeltaBundler/Serializers/helpers/js.js +1 -12
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +1 -2
- package/src/DeltaBundler/Serializers/helpers/processModules.js +1 -2
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +8 -19
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +1 -16
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +3 -1
- package/src/DeltaBundler/Serializers/sourceMapObject.js +1 -3
- package/src/DeltaBundler/Serializers/sourceMapString.js +1 -2
- package/src/DeltaBundler/Transformer.js +12 -28
- package/src/DeltaBundler/Worker.flow.js +4 -15
- package/src/DeltaBundler/Worker.js +2 -2
- package/src/DeltaBundler/WorkerFarm.js +6 -17
- package/src/DeltaBundler/__fixtures__/hasteImpl.js +2 -4
- package/src/DeltaBundler/getTransformCacheKey.js +3 -6
- package/src/DeltaBundler/mergeDeltas.js +1 -8
- package/src/DeltaBundler/types.flow.js +1 -1
- package/src/DeltaBundler.js +4 -20
- package/src/HmrServer.js +51 -62
- package/src/HmrServer.js.flow +45 -12
- package/src/IncrementalBundler/GraphNotFoundError.js +1 -1
- package/src/IncrementalBundler/ResourceNotFoundError.js +1 -1
- package/src/IncrementalBundler/RevisionNotFoundError.js +1 -1
- package/src/IncrementalBundler.js +6 -48
- package/src/IncrementalBundler.js.flow +3 -3
- package/src/ModuleGraph/module.js +4 -3
- package/src/ModuleGraph/node-haste/HasteFS.js +3 -16
- package/src/ModuleGraph/node-haste/Module.js +1 -3
- package/src/ModuleGraph/node-haste/ModuleCache.js +1 -13
- package/src/ModuleGraph/node-haste/Package.js +16 -32
- package/src/ModuleGraph/node-haste/node-haste.flow.js +1 -0
- package/src/ModuleGraph/node-haste/node-haste.js +21 -40
- package/src/ModuleGraph/node-haste/node-haste.js.flow +17 -12
- package/src/ModuleGraph/output/indexed-ram-bundle.js +7 -14
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js +14 -13
- package/src/ModuleGraph/output/plain-bundle.js +1 -8
- package/src/ModuleGraph/output/reverse-dependency-map-references.js +1 -8
- package/src/ModuleGraph/output/util.js +32 -52
- package/src/ModuleGraph/output/util.js.flow +1 -1
- package/src/ModuleGraph/silent-console.js +1 -3
- package/src/ModuleGraph/test-helpers.js +4 -9
- package/src/ModuleGraph/types.flow.js +1 -0
- package/src/ModuleGraph/worker/JsFileWrapping.js +5 -18
- package/src/ModuleGraph/worker/Platforms.js +2 -1
- package/src/ModuleGraph/worker/collectDependencies.js +37 -112
- package/src/ModuleGraph/worker/collectDependencies.js.flow +9 -2
- package/src/ModuleGraph/worker/generate.js +1 -4
- package/src/ModuleGraph/worker/generateImportNames.js +2 -3
- package/src/ModuleGraph/worker/mergeSourceMaps.js +5 -6
- package/src/Server/MultipartResponse.js +1 -16
- package/src/Server/symbolicate.js +9 -36
- package/src/Server.js +53 -166
- package/src/Server.js.flow +4 -1
- package/src/cli-utils.js +2 -3
- package/src/cli-utils.js.flow +1 -1
- package/src/cli.js +0 -4
- package/src/commands/build.js +7 -10
- package/src/commands/dependencies.js +1 -11
- package/src/commands/serve.js +11 -14
- package/src/index.flow.js +15 -64
- package/src/index.flow.js.flow +3 -0
- package/src/index.js +2 -2
- package/src/integration_tests/basic_bundle/AssetRegistry.js +1 -0
- package/src/integration_tests/basic_bundle/Bar.js +1 -1
- package/src/integration_tests/basic_bundle/ErrorBundle.js +3 -3
- package/src/integration_tests/basic_bundle/Foo.js +1 -1
- package/src/integration_tests/basic_bundle/TestBigInt.js +5 -2
- package/src/integration_tests/basic_bundle/TestBigInt.js.flow +1 -0
- package/src/integration_tests/basic_bundle/TestBundle.js +6 -5
- package/src/integration_tests/basic_bundle/TestPolyfill.js +1 -0
- package/src/integration_tests/basic_bundle/import-export/export-1.js +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-2.js +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-3.js +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-4.js +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-5.js +1 -0
- package/src/integration_tests/basic_bundle/import-export/export-6.js +1 -0
- package/src/integration_tests/basic_bundle/import-export/export-null.js +1 -0
- package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js +1 -0
- package/src/integration_tests/basic_bundle/import-export/index.js +1 -10
- package/src/integration_tests/basic_bundle/polyfill.js +4 -2
- package/src/integration_tests/basic_bundle/require-context/conflict.js +1 -4
- package/src/integration_tests/basic_bundle/require-context/empty.js +1 -3
- package/src/integration_tests/basic_bundle/require-context/matching.js +1 -4
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js +1 -2
- 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 +1 -2
- 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 +1 -2
- 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 +1 -2
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/subdir/a.js +1 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/b.js +0 -1
- package/src/integration_tests/basic_bundle/require-context/subdir/c.js +1 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js +1 -0
- package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js +1 -0
- package/src/integration_tests/basic_bundle/require-context/utils.js +1 -2
- package/src/integration_tests/execBundle.js +1 -1
- package/src/integration_tests/metro.config.js +1 -1
- package/src/lib/BatchProcessor.js +7 -22
- package/src/lib/CountingSet.js +8 -19
- package/src/lib/JsonReporter.js +2 -3
- package/src/lib/RamBundleParser.js +5 -12
- package/src/lib/TerminalReporter.js +51 -87
- package/src/lib/TerminalReporter.js.flow +37 -2
- package/src/lib/bundleToBytecode.js +8 -16
- package/src/lib/bundleToBytecode.js.flow +1 -2
- package/src/lib/bundleToString.js +3 -6
- package/src/lib/contextModule.js +8 -12
- package/src/lib/contextModuleTemplates.js +13 -20
- package/src/lib/countLines.js +1 -2
- package/src/lib/createModuleIdFactory.js +1 -3
- package/src/lib/createWebsocketServer.js +1 -6
- package/src/lib/debounceAsyncQueue.js +4 -8
- package/src/lib/formatBundlingError.js +1 -13
- package/src/lib/getAppendScripts.js +3 -16
- package/src/lib/getAppendScripts.js.flow +2 -2
- package/src/lib/getGraphId.js +1 -3
- package/src/lib/getMaxWorkers.js +1 -1
- package/src/lib/getPreludeCode.js +1 -8
- package/src/lib/getPrependedScripts.js +5 -10
- package/src/lib/logToConsole.js +5 -12
- package/src/lib/parseCustomResolverOptions.js +1 -2
- package/src/lib/parseCustomTransformOptions.js +1 -2
- package/src/lib/parseOptionsFromUrl.js +1 -11
- package/src/lib/relativizeSourceMap.js +1 -2
- package/src/lib/reporting.js +5 -6
- package/src/lib/reporting.js.flow +5 -1
- package/src/lib/splitBundleOptions.js +1 -1
- package/src/lib/transformHelpers.js +30 -25
- package/src/lib/transformHelpers.js.flow +4 -4
- package/src/node-haste/DependencyGraph/ModuleResolution.js +11 -48
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +20 -20
- package/src/node-haste/DependencyGraph/createHasteMap.js +7 -26
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +1 -1
- package/src/node-haste/DependencyGraph.js +71 -96
- package/src/node-haste/DependencyGraph.js.flow +37 -29
- package/src/node-haste/Module.js +1 -5
- package/src/node-haste/ModuleCache.js +6 -27
- package/src/node-haste/ModuleCache.js.flow +1 -1
- package/src/node-haste/Package.js +10 -32
- package/src/node-haste/lib/AssetPaths.js +2 -15
- package/src/node-haste/lib/parsePlatformFilePath.js +2 -7
- package/src/shared/output/RamBundle/as-assets.js +4 -18
- package/src/shared/output/RamBundle/as-assets.js.flow +8 -2
- package/src/shared/output/RamBundle/as-indexed-file.js +14 -32
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +8 -2
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +3 -4
- package/src/shared/output/RamBundle/magic-number.js +1 -0
- package/src/shared/output/RamBundle/util.js +4 -21
- package/src/shared/output/RamBundle/write-sourcemap.js +1 -3
- package/src/shared/output/RamBundle.js +1 -5
- package/src/shared/output/bundle.flow.js +3 -10
- package/src/shared/output/bundle.js +2 -2
- package/src/shared/output/meta.js +1 -8
- package/src/shared/output/unbundle.js +2 -1
- package/src/shared/output/writeFile.js +1 -3
- package/src/shared/types.flow.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.73.
|
|
3
|
+
"version": "0.73.5",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/code-frame": "^7.0.0",
|
|
17
17
|
"@babel/core": "^7.14.0",
|
|
18
|
-
"@babel/generator": "^7.
|
|
18
|
+
"@babel/generator": "^7.20.0",
|
|
19
19
|
"@babel/parser": "^7.14.0",
|
|
20
20
|
"@babel/template": "^7.0.0",
|
|
21
21
|
"@babel/traverse": "^7.14.0",
|
|
22
|
-
"@babel/types": "^7.
|
|
22
|
+
"@babel/types": "^7.20.0",
|
|
23
23
|
"absolute-path": "^0.0.0",
|
|
24
24
|
"accepts": "^1.3.7",
|
|
25
25
|
"async": "^3.2.2",
|
|
@@ -29,30 +29,29 @@
|
|
|
29
29
|
"debug": "^2.2.0",
|
|
30
30
|
"denodeify": "^1.2.1",
|
|
31
31
|
"error-stack-parser": "^2.0.6",
|
|
32
|
-
"fs-extra": "^1.0.0",
|
|
33
32
|
"graceful-fs": "^4.2.4",
|
|
34
33
|
"hermes-parser": "0.8.0",
|
|
35
34
|
"image-size": "^0.6.0",
|
|
36
35
|
"invariant": "^2.2.4",
|
|
37
36
|
"jest-worker": "^27.2.0",
|
|
38
37
|
"lodash.throttle": "^4.1.1",
|
|
39
|
-
"metro-babel-transformer": "0.73.
|
|
40
|
-
"metro-cache": "0.73.
|
|
41
|
-
"metro-cache-key": "0.73.
|
|
42
|
-
"metro-config": "0.73.
|
|
43
|
-
"metro-core": "0.73.
|
|
44
|
-
"metro-file-map": "0.73.
|
|
45
|
-
"metro-hermes-compiler": "0.73.
|
|
46
|
-
"metro-inspector-proxy": "0.73.
|
|
47
|
-
"metro-minify-terser": "0.73.
|
|
48
|
-
"metro-minify-uglify": "0.73.
|
|
49
|
-
"metro-react-native-babel-preset": "0.73.
|
|
50
|
-
"metro-resolver": "0.73.
|
|
51
|
-
"metro-runtime": "0.73.
|
|
52
|
-
"metro-source-map": "0.73.
|
|
53
|
-
"metro-symbolicate": "0.73.
|
|
54
|
-
"metro-transform-plugins": "0.73.
|
|
55
|
-
"metro-transform-worker": "0.73.
|
|
38
|
+
"metro-babel-transformer": "0.73.5",
|
|
39
|
+
"metro-cache": "0.73.5",
|
|
40
|
+
"metro-cache-key": "0.73.5",
|
|
41
|
+
"metro-config": "0.73.5",
|
|
42
|
+
"metro-core": "0.73.5",
|
|
43
|
+
"metro-file-map": "0.73.5",
|
|
44
|
+
"metro-hermes-compiler": "0.73.5",
|
|
45
|
+
"metro-inspector-proxy": "0.73.5",
|
|
46
|
+
"metro-minify-terser": "0.73.5",
|
|
47
|
+
"metro-minify-uglify": "0.73.5",
|
|
48
|
+
"metro-react-native-babel-preset": "0.73.5",
|
|
49
|
+
"metro-resolver": "0.73.5",
|
|
50
|
+
"metro-runtime": "0.73.5",
|
|
51
|
+
"metro-source-map": "0.73.5",
|
|
52
|
+
"metro-symbolicate": "0.73.5",
|
|
53
|
+
"metro-transform-plugins": "0.73.5",
|
|
54
|
+
"metro-transform-worker": "0.73.5",
|
|
56
55
|
"mime-types": "^2.1.27",
|
|
57
56
|
"node-fetch": "^2.2.0",
|
|
58
57
|
"nullthrows": "^1.1.1",
|
|
@@ -70,10 +69,10 @@
|
|
|
70
69
|
"babel-jest": "^29.2.1",
|
|
71
70
|
"dedent": "^0.7.0",
|
|
72
71
|
"jest-snapshot": "^26.5.2",
|
|
73
|
-
"metro-babel-register": "0.73.
|
|
74
|
-
"metro-memory-fs": "0.73.
|
|
75
|
-
"metro-react-native-babel-preset": "0.73.
|
|
76
|
-
"metro-react-native-babel-transformer": "0.73.
|
|
72
|
+
"metro-babel-register": "0.73.5",
|
|
73
|
+
"metro-memory-fs": "0.73.5",
|
|
74
|
+
"metro-react-native-babel-preset": "0.73.5",
|
|
75
|
+
"metro-react-native-babel-transformer": "0.73.5",
|
|
77
76
|
"mock-req": "^0.2.0",
|
|
78
77
|
"mock-res": "^0.6.0",
|
|
79
78
|
"stack-trace": "^0.0.10"
|
package/src/Assets.js
CHANGED
|
@@ -8,22 +8,16 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
|
+
|
|
11
12
|
"use strict";
|
|
12
13
|
|
|
13
14
|
const { isAssetTypeAnImage } = require("./Bundler/util");
|
|
14
|
-
|
|
15
15
|
const AssetPaths = require("./node-haste/lib/AssetPaths");
|
|
16
|
-
|
|
17
16
|
const crypto = require("crypto");
|
|
18
|
-
|
|
19
17
|
const denodeify = require("denodeify");
|
|
20
|
-
|
|
21
18
|
const fs = require("fs");
|
|
22
|
-
|
|
23
19
|
const imageSize = require("image-size");
|
|
24
|
-
|
|
25
20
|
const path = require("path");
|
|
26
|
-
|
|
27
21
|
const readDir = denodeify(fs.readdir);
|
|
28
22
|
const readFile = denodeify(fs.readFile);
|
|
29
23
|
const hashFiles = denodeify(function hashFilesCb(files, hash, callback) {
|
|
@@ -31,7 +25,6 @@ const hashFiles = denodeify(function hashFilesCb(files, hash, callback) {
|
|
|
31
25
|
callback(null);
|
|
32
26
|
return;
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
const file = files.shift();
|
|
36
29
|
fs.readFile(file, (err, data) => {
|
|
37
30
|
if (err) {
|
|
@@ -43,7 +36,6 @@ const hashFiles = denodeify(function hashFilesCb(files, hash, callback) {
|
|
|
43
36
|
}
|
|
44
37
|
});
|
|
45
38
|
});
|
|
46
|
-
|
|
47
39
|
function buildAssetMap(dir, files, platform) {
|
|
48
40
|
const platforms = new Set(platform != null ? [platform] : []);
|
|
49
41
|
const assets = files.map((file) => AssetPaths.tryParse(file, platforms));
|
|
@@ -52,11 +44,9 @@ function buildAssetMap(dir, files, platform) {
|
|
|
52
44
|
if (asset == null) {
|
|
53
45
|
return;
|
|
54
46
|
}
|
|
55
|
-
|
|
56
47
|
const file = files[i];
|
|
57
48
|
const assetKey = getAssetKey(asset.assetName, asset.platform);
|
|
58
49
|
let record = map.get(assetKey);
|
|
59
|
-
|
|
60
50
|
if (!record) {
|
|
61
51
|
record = {
|
|
62
52
|
scales: [],
|
|
@@ -64,22 +54,18 @@ function buildAssetMap(dir, files, platform) {
|
|
|
64
54
|
};
|
|
65
55
|
map.set(assetKey, record);
|
|
66
56
|
}
|
|
67
|
-
|
|
68
57
|
let insertIndex;
|
|
69
58
|
const length = record.scales.length;
|
|
70
|
-
|
|
71
59
|
for (insertIndex = 0; insertIndex < length; insertIndex++) {
|
|
72
60
|
if (asset.resolution < record.scales[insertIndex]) {
|
|
73
61
|
break;
|
|
74
62
|
}
|
|
75
63
|
}
|
|
76
|
-
|
|
77
64
|
record.scales.splice(insertIndex, 0, asset.resolution);
|
|
78
65
|
record.files.splice(insertIndex, 0, path.join(dir, file));
|
|
79
66
|
});
|
|
80
67
|
return map;
|
|
81
68
|
}
|
|
82
|
-
|
|
83
69
|
function getAssetKey(assetName, platform) {
|
|
84
70
|
if (platform != null) {
|
|
85
71
|
return `${assetName} : ${platform}`;
|
|
@@ -87,7 +73,6 @@ function getAssetKey(assetName, platform) {
|
|
|
87
73
|
return assetName;
|
|
88
74
|
}
|
|
89
75
|
}
|
|
90
|
-
|
|
91
76
|
async function getAbsoluteAssetRecord(assetPath, platform = null) {
|
|
92
77
|
const filename = path.basename(assetPath);
|
|
93
78
|
const dir = path.dirname(assetPath);
|
|
@@ -98,7 +83,6 @@ async function getAbsoluteAssetRecord(assetPath, platform = null) {
|
|
|
98
83
|
);
|
|
99
84
|
const map = buildAssetMap(dir, files, platform);
|
|
100
85
|
let record;
|
|
101
|
-
|
|
102
86
|
if (platform != null) {
|
|
103
87
|
record =
|
|
104
88
|
map.get(getAssetKey(assetData.assetName, platform)) ||
|
|
@@ -106,7 +90,6 @@ async function getAbsoluteAssetRecord(assetPath, platform = null) {
|
|
|
106
90
|
} else {
|
|
107
91
|
record = map.get(assetData.assetName);
|
|
108
92
|
}
|
|
109
|
-
|
|
110
93
|
if (!record) {
|
|
111
94
|
throw new Error(
|
|
112
95
|
`Asset not found: ${assetPath} for platform: ${
|
|
@@ -114,10 +97,8 @@ async function getAbsoluteAssetRecord(assetPath, platform = null) {
|
|
|
114
97
|
}`
|
|
115
98
|
);
|
|
116
99
|
}
|
|
117
|
-
|
|
118
100
|
return record;
|
|
119
101
|
}
|
|
120
|
-
|
|
121
102
|
async function getAbsoluteAssetInfo(assetPath, platform = null) {
|
|
122
103
|
const nameData = AssetPaths.parse(
|
|
123
104
|
assetPath,
|
|
@@ -126,11 +107,9 @@ async function getAbsoluteAssetInfo(assetPath, platform = null) {
|
|
|
126
107
|
const { name, type } = nameData;
|
|
127
108
|
const { scales, files } = await getAbsoluteAssetRecord(assetPath, platform);
|
|
128
109
|
const hasher = crypto.createHash("md5");
|
|
129
|
-
|
|
130
110
|
if (files.length > 0) {
|
|
131
111
|
await hashFiles(Array.from(files), hasher);
|
|
132
112
|
}
|
|
133
|
-
|
|
134
113
|
return {
|
|
135
114
|
files,
|
|
136
115
|
hash: hasher.digest("hex"),
|
|
@@ -139,7 +118,6 @@ async function getAbsoluteAssetInfo(assetPath, platform = null) {
|
|
|
139
118
|
type,
|
|
140
119
|
};
|
|
141
120
|
}
|
|
142
|
-
|
|
143
121
|
async function getAssetData(
|
|
144
122
|
assetPath,
|
|
145
123
|
localPath,
|
|
@@ -152,12 +130,12 @@ async function getAssetData(
|
|
|
152
130
|
// case we just concatenate the publicPath with the relative path.
|
|
153
131
|
let assetUrlPath = localPath.startsWith("..")
|
|
154
132
|
? publicPath.replace(/\/$/, "") + "/" + path.dirname(localPath)
|
|
155
|
-
: path.join(publicPath, path.dirname(localPath));
|
|
133
|
+
: path.join(publicPath, path.dirname(localPath));
|
|
156
134
|
|
|
135
|
+
// On Windows, change backslashes to slashes to get proper URL path from file path.
|
|
157
136
|
if (path.sep === "\\") {
|
|
158
137
|
assetUrlPath = assetUrlPath.replace(/\\/g, "/");
|
|
159
138
|
}
|
|
160
|
-
|
|
161
139
|
const isImage = isAssetTypeAnImage(path.extname(assetPath).slice(1));
|
|
162
140
|
const assetInfo = await getAbsoluteAssetInfo(assetPath, platform);
|
|
163
141
|
const isImageInput = assetInfo.files[0].includes(".zip/")
|
|
@@ -179,27 +157,25 @@ async function getAssetData(
|
|
|
179
157
|
};
|
|
180
158
|
return await applyAssetDataPlugins(assetDataPlugins, assetData);
|
|
181
159
|
}
|
|
182
|
-
|
|
183
160
|
async function applyAssetDataPlugins(assetDataPlugins, assetData) {
|
|
184
161
|
if (!assetDataPlugins.length) {
|
|
185
162
|
return assetData;
|
|
186
163
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
164
|
+
const [currentAssetPlugin, ...remainingAssetPlugins] = assetDataPlugins;
|
|
165
|
+
// $FlowFixMe: impossible to type a dynamic require.
|
|
190
166
|
const assetPluginFunction = require(currentAssetPlugin);
|
|
191
|
-
|
|
192
167
|
const resultAssetData = await assetPluginFunction(assetData);
|
|
193
168
|
return await applyAssetDataPlugins(remainingAssetPlugins, resultAssetData);
|
|
194
169
|
}
|
|
170
|
+
|
|
195
171
|
/**
|
|
196
172
|
* Returns all the associated files (for different resolutions) of an asset.
|
|
197
173
|
**/
|
|
198
|
-
|
|
199
174
|
async function getAssetFiles(assetPath, platform = null) {
|
|
200
175
|
const assetData = await getAbsoluteAssetRecord(assetPath, platform);
|
|
201
176
|
return assetData.files;
|
|
202
177
|
}
|
|
178
|
+
|
|
203
179
|
/**
|
|
204
180
|
* Return a buffer with the actual image given a request for an image by path.
|
|
205
181
|
* The relativePath can contain a resolution postfix, in this case we need to
|
|
@@ -211,7 +187,6 @@ async function getAssetFiles(assetPath, platform = null) {
|
|
|
211
187
|
* 3. Then try to pick platform-specific asset records
|
|
212
188
|
* 4. Then pick the closest resolution (rounding up) to the requested one
|
|
213
189
|
*/
|
|
214
|
-
|
|
215
190
|
async function getAsset(
|
|
216
191
|
relativePath,
|
|
217
192
|
projectRoot,
|
|
@@ -224,40 +199,32 @@ async function getAsset(
|
|
|
224
199
|
new Set(platform != null ? [platform] : [])
|
|
225
200
|
);
|
|
226
201
|
const absolutePath = path.resolve(projectRoot, relativePath);
|
|
227
|
-
|
|
228
202
|
if (!assetExts.includes(assetData.type)) {
|
|
229
203
|
throw new Error(
|
|
230
204
|
`'${relativePath}' cannot be loaded as its extension is not registered in assetExts`
|
|
231
205
|
);
|
|
232
206
|
}
|
|
233
|
-
|
|
234
207
|
if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
|
|
235
208
|
throw new Error(
|
|
236
209
|
`'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`
|
|
237
210
|
);
|
|
238
211
|
}
|
|
239
|
-
|
|
240
212
|
const record = await getAbsoluteAssetRecord(absolutePath, platform);
|
|
241
|
-
|
|
242
213
|
for (let i = 0; i < record.scales.length; i++) {
|
|
243
214
|
if (record.scales[i] >= assetData.resolution) {
|
|
244
215
|
return readFile(record.files[i]);
|
|
245
216
|
}
|
|
246
217
|
}
|
|
247
|
-
|
|
248
218
|
return readFile(record.files[record.files.length - 1]);
|
|
249
219
|
}
|
|
250
|
-
|
|
251
220
|
function pathBelongsToRoots(pathToCheck, roots) {
|
|
252
221
|
for (const rootFolder of roots) {
|
|
253
222
|
if (pathToCheck.startsWith(path.resolve(rootFolder))) {
|
|
254
223
|
return true;
|
|
255
224
|
}
|
|
256
225
|
}
|
|
257
|
-
|
|
258
226
|
return false;
|
|
259
227
|
}
|
|
260
|
-
|
|
261
228
|
module.exports = {
|
|
262
229
|
getAsset,
|
|
263
230
|
getAssetData,
|
package/src/Bundler/util.js
CHANGED
|
@@ -8,29 +8,30 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
|
+
|
|
11
12
|
"use strict";
|
|
12
13
|
|
|
13
14
|
const babylon = require("@babel/parser");
|
|
14
|
-
|
|
15
15
|
const template = require("@babel/template").default;
|
|
16
|
-
|
|
17
16
|
const babelTypes = require("@babel/types");
|
|
17
|
+
const nullthrows = require("nullthrows");
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// Structure of the object: dir.name.scale = asset
|
|
20
20
|
|
|
21
21
|
const assetPropertyBlockList = new Set(["files", "fileSystemLocation", "path"]);
|
|
22
|
-
|
|
23
22
|
function generateAssetCodeFileAst(assetRegistryPath, assetDescriptor) {
|
|
24
23
|
const properDescriptor = filterObject(
|
|
25
24
|
assetDescriptor,
|
|
26
25
|
assetPropertyBlockList
|
|
27
|
-
);
|
|
26
|
+
);
|
|
28
27
|
|
|
28
|
+
// {...}
|
|
29
29
|
const descriptorAst = babylon.parseExpression(
|
|
30
30
|
JSON.stringify(properDescriptor)
|
|
31
31
|
);
|
|
32
|
-
const t = babelTypes;
|
|
32
|
+
const t = babelTypes;
|
|
33
33
|
|
|
34
|
+
// require('AssetRegistry').registerAsset({...})
|
|
34
35
|
const buildRequire = template.statement(`
|
|
35
36
|
module.exports = require(ASSET_REGISTRY_PATH).registerAsset(DESCRIPTOR_AST)
|
|
36
37
|
`);
|
|
@@ -43,12 +44,12 @@ function generateAssetCodeFileAst(assetRegistryPath, assetDescriptor) {
|
|
|
43
44
|
])
|
|
44
45
|
);
|
|
45
46
|
}
|
|
47
|
+
|
|
46
48
|
/**
|
|
47
49
|
* Generates the code involved in requiring an asset, but to be loaded remotely.
|
|
48
50
|
* If the asset cannot be found within the map, then it falls back to the
|
|
49
51
|
* standard asset.
|
|
50
52
|
*/
|
|
51
|
-
|
|
52
53
|
function generateRemoteAssetCodeFileAst(
|
|
53
54
|
assetUtilsPath,
|
|
54
55
|
assetDescriptor,
|
|
@@ -59,19 +60,20 @@ function generateRemoteAssetCodeFileAst(
|
|
|
59
60
|
const file = remoteFileMap[assetDescriptor.fileSystemLocation];
|
|
60
61
|
const descriptor = file && file[assetDescriptor.name];
|
|
61
62
|
const data = {};
|
|
62
|
-
|
|
63
63
|
if (!descriptor) {
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
66
|
for (const scale in descriptor) {
|
|
68
67
|
data[+scale] = descriptor[+scale].handle;
|
|
69
|
-
}
|
|
68
|
+
}
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
// {2: 'path/to/image@2x', 3: 'path/to/image@3x', ...}
|
|
71
|
+
const astData = babylon.parseExpression(JSON.stringify(data));
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
// URI to remote server
|
|
74
|
+
const URI = t.stringLiteral(remoteServer);
|
|
74
75
|
|
|
76
|
+
// Size numbers.
|
|
75
77
|
const WIDTH = t.numericLiteral(nullthrows(assetDescriptor.width));
|
|
76
78
|
const HEIGHT = t.numericLiteral(nullthrows(assetDescriptor.height));
|
|
77
79
|
const buildRequire = template.program(`
|
|
@@ -97,9 +99,10 @@ function generateRemoteAssetCodeFileAst(
|
|
|
97
99
|
),
|
|
98
100
|
})
|
|
99
101
|
);
|
|
100
|
-
}
|
|
101
|
-
// If it's not one of these, we won't treat it as an image.
|
|
102
|
+
}
|
|
102
103
|
|
|
104
|
+
// Test extension against all types supported by image-size module.
|
|
105
|
+
// If it's not one of these, we won't treat it as an image.
|
|
103
106
|
function isAssetTypeAnImage(type) {
|
|
104
107
|
return (
|
|
105
108
|
["png", "jpg", "jpeg", "bmp", "gif", "webp", "psd", "svg", "tiff"].indexOf(
|
|
@@ -107,17 +110,16 @@ function isAssetTypeAnImage(type) {
|
|
|
107
110
|
) !== -1
|
|
108
111
|
);
|
|
109
112
|
}
|
|
110
|
-
|
|
111
113
|
function filterObject(object, blockList) {
|
|
112
|
-
const copied = {
|
|
113
|
-
|
|
114
|
+
const copied = {
|
|
115
|
+
...object,
|
|
116
|
+
};
|
|
114
117
|
for (const key of blockList) {
|
|
118
|
+
// $FlowFixMe[prop-missing]
|
|
115
119
|
delete copied[key];
|
|
116
120
|
}
|
|
117
|
-
|
|
118
121
|
return copied;
|
|
119
122
|
}
|
|
120
|
-
|
|
121
123
|
function createRamBundleGroups(ramGroups, groupableModules, subtree) {
|
|
122
124
|
// build two maps that allow to lookup module data
|
|
123
125
|
// by path or (numeric) module id;
|
|
@@ -126,35 +128,33 @@ function createRamBundleGroups(ramGroups, groupableModules, subtree) {
|
|
|
126
128
|
groupableModules.forEach((m) => {
|
|
127
129
|
byPath.set(m.sourcePath, m);
|
|
128
130
|
byId.set(m.id, m.sourcePath);
|
|
129
|
-
});
|
|
131
|
+
});
|
|
130
132
|
|
|
133
|
+
// build a map of group root IDs to an array of module IDs in the group
|
|
131
134
|
const result = new Map(
|
|
132
135
|
ramGroups.map((modulePath) => {
|
|
133
136
|
const root = byPath.get(modulePath);
|
|
134
|
-
|
|
135
137
|
if (root == null) {
|
|
136
138
|
throw Error(`Group root ${modulePath} is not part of the bundle`);
|
|
137
139
|
}
|
|
138
|
-
|
|
139
140
|
return [
|
|
140
|
-
root.id,
|
|
141
|
+
root.id,
|
|
142
|
+
// `subtree` yields the IDs of all transitive dependencies of a module
|
|
141
143
|
new Set(subtree(root, byPath)),
|
|
142
144
|
];
|
|
143
145
|
})
|
|
144
146
|
);
|
|
145
|
-
|
|
146
147
|
if (ramGroups.length > 1) {
|
|
147
148
|
// build a map of all grouped module IDs to an array of group root IDs
|
|
148
149
|
const all = new ArrayMap();
|
|
149
|
-
|
|
150
150
|
for (const [parent, children] of result) {
|
|
151
151
|
for (const module of children) {
|
|
152
152
|
all.get(module).push(parent);
|
|
153
153
|
}
|
|
154
|
-
}
|
|
154
|
+
}
|
|
155
155
|
|
|
156
|
+
// find all module IDs that are part of more than one group
|
|
156
157
|
const doubles = filter(all, ([, parents]) => parents.length > 1);
|
|
157
|
-
|
|
158
158
|
for (const [moduleId, parents] of doubles) {
|
|
159
159
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
160
160
|
const parentNames = parents.map(byId.get, byId);
|
|
@@ -168,10 +168,8 @@ function createRamBundleGroups(ramGroups, groupableModules, subtree) {
|
|
|
168
168
|
);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
|
|
172
171
|
return result;
|
|
173
172
|
}
|
|
174
|
-
|
|
175
173
|
function* filter(iterator, predicate) {
|
|
176
174
|
for (const value of iterator) {
|
|
177
175
|
if (predicate(value)) {
|
|
@@ -179,20 +177,16 @@ function* filter(iterator, predicate) {
|
|
|
179
177
|
}
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
|
-
|
|
183
180
|
class ArrayMap extends Map {
|
|
184
181
|
get(key) {
|
|
185
182
|
let array = super.get(key);
|
|
186
|
-
|
|
187
183
|
if (!array) {
|
|
188
184
|
array = [];
|
|
189
185
|
this.set(key, array);
|
|
190
186
|
}
|
|
191
|
-
|
|
192
187
|
return array;
|
|
193
188
|
}
|
|
194
189
|
}
|
|
195
|
-
|
|
196
190
|
module.exports = {
|
|
197
191
|
createRamBundleGroups,
|
|
198
192
|
generateAssetCodeFileAst,
|
package/src/Bundler/util.js.flow
CHANGED
package/src/Bundler.js
CHANGED
|
@@ -8,12 +8,11 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
|
+
|
|
11
12
|
"use strict";
|
|
12
13
|
|
|
13
14
|
const Transformer = require("./DeltaBundler/Transformer");
|
|
14
|
-
|
|
15
15
|
const DependencyGraph = require("./node-haste/DependencyGraph");
|
|
16
|
-
|
|
17
16
|
class Bundler {
|
|
18
17
|
constructor(config, options) {
|
|
19
18
|
this._depGraph = new DependencyGraph(config, options);
|
|
@@ -38,28 +37,21 @@ class Bundler {
|
|
|
38
37
|
});
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
|
-
|
|
42
40
|
getWatcher() {
|
|
43
41
|
return this._depGraph.getWatcher();
|
|
44
42
|
}
|
|
45
|
-
|
|
46
43
|
async end() {
|
|
47
44
|
await this._depGraph.ready();
|
|
48
|
-
|
|
49
45
|
this._transformer.end();
|
|
50
|
-
|
|
51
46
|
this._depGraph.end();
|
|
52
47
|
}
|
|
53
|
-
|
|
54
48
|
async getDependencyGraph() {
|
|
55
49
|
await this._depGraph.ready();
|
|
56
50
|
return this._depGraph;
|
|
57
51
|
}
|
|
58
|
-
|
|
59
52
|
async transformFile(
|
|
60
53
|
filePath,
|
|
61
|
-
transformOptions,
|
|
62
|
-
/** Optionally provide the file contents, this can be used to provide virtual contents for a file. */
|
|
54
|
+
transformOptions /** Optionally provide the file contents, this can be used to provide virtual contents for a file. */,
|
|
63
55
|
fileBuffer
|
|
64
56
|
) {
|
|
65
57
|
// We need to be sure that the DependencyGraph has been initialized.
|
|
@@ -70,11 +62,11 @@ class Bundler {
|
|
|
70
62
|
transformOptions,
|
|
71
63
|
fileBuffer
|
|
72
64
|
);
|
|
73
|
-
}
|
|
65
|
+
}
|
|
74
66
|
|
|
67
|
+
// Waits for the bundler to become ready.
|
|
75
68
|
async ready() {
|
|
76
69
|
await this._readyPromise;
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
module.exports = Bundler;
|