metro 0.73.4 → 0.73.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 +28 -28
- package/src/Assets.js +7 -40
- package/src/Bundler/util.js +26 -33
- package/src/Bundler.js +4 -12
- package/src/DeltaBundler/DeltaCalculator.js +33 -49
- package/src/DeltaBundler/Graph.js +69 -137
- package/src/DeltaBundler/Graph.js.flow +8 -15
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +15 -26
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +12 -17
- package/src/DeltaBundler/Serializers/baseJSBundle.js +15 -23
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +12 -17
- 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 +3 -18
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +6 -8
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +7 -29
- package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +5 -26
- 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 +35 -16
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +44 -9
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +11 -3
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +12 -6
- package/src/DeltaBundler/Serializers/helpers/processModules.js +11 -3
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +12 -6
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +8 -19
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +7 -5
- 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/Transformer.js.flow +4 -1
- 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/types.flow.js.flow +16 -16
- package/src/DeltaBundler.js +4 -20
- package/src/HmrServer.js +8 -57
- package/src/HmrServer.js.flow +8 -5
- 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/ModuleGraph/test-helpers.js +4 -9
- package/src/ModuleGraph/worker/JsFileWrapping.js +5 -18
- package/src/ModuleGraph/worker/collectDependencies.js +43 -115
- package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -5
- package/src/ModuleGraph/worker/generateImportNames.js +2 -3
- package/src/Server/MultipartResponse.js +1 -16
- package/src/Server/symbolicate.js +9 -36
- package/src/Server.js +53 -167
- package/src/Server.js.flow +9 -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 +13 -64
- 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 +7 -2
- package/src/integration_tests/basic_bundle/TestBigInt.js.flow +3 -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 +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-2.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-3.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-4.js +2 -2
- 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 +7 -15
- 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 +2 -3
- 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 +16 -92
- package/src/lib/bundleToBytecode.js +6 -13
- 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 +2 -46
- package/src/lib/getAppendScripts.js.flow +4 -40
- 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/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 +9 -46
- package/src/node-haste/DependencyGraph/createHasteMap.js +5 -13
- package/src/node-haste/DependencyGraph.js +57 -98
- package/src/node-haste/DependencyGraph.js.flow +21 -28
- package/src/node-haste/Module.js +1 -5
- package/src/node-haste/ModuleCache.js +5 -26
- 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/src/ModuleGraph/module.js +0 -28
- package/src/ModuleGraph/module.js.flow +0 -32
- package/src/ModuleGraph/node-haste/HasteFS.js +0 -90
- package/src/ModuleGraph/node-haste/HasteFS.js.flow +0 -101
- package/src/ModuleGraph/node-haste/Module.js +0 -32
- package/src/ModuleGraph/node-haste/Module.js.flow +0 -46
- package/src/ModuleGraph/node-haste/ModuleCache.js +0 -74
- package/src/ModuleGraph/node-haste/ModuleCache.js.flow +0 -80
- package/src/ModuleGraph/node-haste/Package.js +0 -129
- package/src/ModuleGraph/node-haste/Package.js.flow +0 -131
- package/src/ModuleGraph/node-haste/node-haste.flow.js +0 -11
- package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +0 -70
- package/src/ModuleGraph/node-haste/node-haste.js +0 -197
- package/src/ModuleGraph/node-haste/node-haste.js.flow +0 -232
- package/src/ModuleGraph/output/indexed-ram-bundle.js +0 -109
- package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +0 -140
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js +0 -93
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +0 -97
- package/src/ModuleGraph/output/plain-bundle.js +0 -59
- package/src/ModuleGraph/output/plain-bundle.js.flow +0 -62
- package/src/ModuleGraph/output/reverse-dependency-map-references.js +0 -68
- package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +0 -76
- package/src/ModuleGraph/output/util.js +0 -335
- package/src/ModuleGraph/output/util.js.flow +0 -372
- package/src/ModuleGraph/silent-console.js +0 -27
- package/src/ModuleGraph/silent-console.js.flow +0 -24
- package/src/ModuleGraph/types.flow.js +0 -11
- package/src/ModuleGraph/types.flow.js.flow +0 -326
- package/src/ModuleGraph/worker/Platforms.js +0 -22
- package/src/ModuleGraph/worker/Platforms.js.flow +0 -22
- package/src/ModuleGraph/worker/generate.js +0 -38
- package/src/ModuleGraph/worker/generate.js.flow +0 -44
- package/src/ModuleGraph/worker/mergeSourceMaps.js +0 -48
- package/src/ModuleGraph/worker/mergeSourceMaps.js.flow +0 -52
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.73.
|
|
3
|
+
"version": "0.73.6",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/code-frame": "^7.0.0",
|
|
17
|
-
"@babel/core": "^7.
|
|
18
|
-
"@babel/generator": "^7.
|
|
19
|
-
"@babel/parser": "^7.
|
|
17
|
+
"@babel/core": "^7.20.0",
|
|
18
|
+
"@babel/generator": "^7.20.0",
|
|
19
|
+
"@babel/parser": "^7.20.0",
|
|
20
20
|
"@babel/template": "^7.0.0",
|
|
21
|
-
"@babel/traverse": "^7.
|
|
22
|
-
"@babel/types": "^7.
|
|
21
|
+
"@babel/traverse": "^7.20.0",
|
|
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.6",
|
|
39
|
+
"metro-cache": "0.73.6",
|
|
40
|
+
"metro-cache-key": "0.73.6",
|
|
41
|
+
"metro-config": "0.73.6",
|
|
42
|
+
"metro-core": "0.73.6",
|
|
43
|
+
"metro-file-map": "0.73.6",
|
|
44
|
+
"metro-hermes-compiler": "0.73.6",
|
|
45
|
+
"metro-inspector-proxy": "0.73.6",
|
|
46
|
+
"metro-minify-terser": "0.73.6",
|
|
47
|
+
"metro-minify-uglify": "0.73.6",
|
|
48
|
+
"metro-react-native-babel-preset": "0.73.6",
|
|
49
|
+
"metro-resolver": "0.73.6",
|
|
50
|
+
"metro-runtime": "0.73.6",
|
|
51
|
+
"metro-source-map": "0.73.6",
|
|
52
|
+
"metro-symbolicate": "0.73.6",
|
|
53
|
+
"metro-transform-plugins": "0.73.6",
|
|
54
|
+
"metro-transform-worker": "0.73.6",
|
|
56
55
|
"mime-types": "^2.1.27",
|
|
57
56
|
"node-fetch": "^2.2.0",
|
|
58
57
|
"nullthrows": "^1.1.1",
|
|
@@ -70,10 +69,11 @@
|
|
|
70
69
|
"babel-jest": "^29.2.1",
|
|
71
70
|
"dedent": "^0.7.0",
|
|
72
71
|
"jest-snapshot": "^26.5.2",
|
|
73
|
-
"
|
|
74
|
-
"metro-
|
|
75
|
-
"metro-
|
|
76
|
-
"metro-react-native-babel-
|
|
72
|
+
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
73
|
+
"metro-babel-register": "0.73.6",
|
|
74
|
+
"metro-memory-fs": "0.73.6",
|
|
75
|
+
"metro-react-native-babel-preset": "0.73.6",
|
|
76
|
+
"metro-react-native-babel-transformer": "0.73.6",
|
|
77
77
|
"mock-req": "^0.2.0",
|
|
78
78
|
"mock-res": "^0.6.0",
|
|
79
79
|
"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,18 +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) {
|
|
115
118
|
// $FlowFixMe[prop-missing]
|
|
116
119
|
delete copied[key];
|
|
117
120
|
}
|
|
118
|
-
|
|
119
121
|
return copied;
|
|
120
122
|
}
|
|
121
|
-
|
|
122
123
|
function createRamBundleGroups(ramGroups, groupableModules, subtree) {
|
|
123
124
|
// build two maps that allow to lookup module data
|
|
124
125
|
// by path or (numeric) module id;
|
|
@@ -127,35 +128,33 @@ function createRamBundleGroups(ramGroups, groupableModules, subtree) {
|
|
|
127
128
|
groupableModules.forEach((m) => {
|
|
128
129
|
byPath.set(m.sourcePath, m);
|
|
129
130
|
byId.set(m.id, m.sourcePath);
|
|
130
|
-
});
|
|
131
|
+
});
|
|
131
132
|
|
|
133
|
+
// build a map of group root IDs to an array of module IDs in the group
|
|
132
134
|
const result = new Map(
|
|
133
135
|
ramGroups.map((modulePath) => {
|
|
134
136
|
const root = byPath.get(modulePath);
|
|
135
|
-
|
|
136
137
|
if (root == null) {
|
|
137
138
|
throw Error(`Group root ${modulePath} is not part of the bundle`);
|
|
138
139
|
}
|
|
139
|
-
|
|
140
140
|
return [
|
|
141
|
-
root.id,
|
|
141
|
+
root.id,
|
|
142
|
+
// `subtree` yields the IDs of all transitive dependencies of a module
|
|
142
143
|
new Set(subtree(root, byPath)),
|
|
143
144
|
];
|
|
144
145
|
})
|
|
145
146
|
);
|
|
146
|
-
|
|
147
147
|
if (ramGroups.length > 1) {
|
|
148
148
|
// build a map of all grouped module IDs to an array of group root IDs
|
|
149
149
|
const all = new ArrayMap();
|
|
150
|
-
|
|
151
150
|
for (const [parent, children] of result) {
|
|
152
151
|
for (const module of children) {
|
|
153
152
|
all.get(module).push(parent);
|
|
154
153
|
}
|
|
155
|
-
}
|
|
154
|
+
}
|
|
156
155
|
|
|
156
|
+
// find all module IDs that are part of more than one group
|
|
157
157
|
const doubles = filter(all, ([, parents]) => parents.length > 1);
|
|
158
|
-
|
|
159
158
|
for (const [moduleId, parents] of doubles) {
|
|
160
159
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
161
160
|
const parentNames = parents.map(byId.get, byId);
|
|
@@ -169,10 +168,8 @@ function createRamBundleGroups(ramGroups, groupableModules, subtree) {
|
|
|
169
168
|
);
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
|
-
|
|
173
171
|
return result;
|
|
174
172
|
}
|
|
175
|
-
|
|
176
173
|
function* filter(iterator, predicate) {
|
|
177
174
|
for (const value of iterator) {
|
|
178
175
|
if (predicate(value)) {
|
|
@@ -180,20 +177,16 @@ function* filter(iterator, predicate) {
|
|
|
180
177
|
}
|
|
181
178
|
}
|
|
182
179
|
}
|
|
183
|
-
|
|
184
180
|
class ArrayMap extends Map {
|
|
185
181
|
get(key) {
|
|
186
182
|
let array = super.get(key);
|
|
187
|
-
|
|
188
183
|
if (!array) {
|
|
189
184
|
array = [];
|
|
190
185
|
this.set(key, array);
|
|
191
186
|
}
|
|
192
|
-
|
|
193
187
|
return array;
|
|
194
188
|
}
|
|
195
189
|
}
|
|
196
|
-
|
|
197
190
|
module.exports = {
|
|
198
191
|
createRamBundleGroups,
|
|
199
192
|
generateAssetCodeFileAst,
|
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;
|