metro 0.52.0 → 0.54.1
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 +17 -15
- package/src/Assets.js +7 -0
- package/src/Assets.js.flow +28 -16
- package/src/Bundler/util.js +0 -1
- package/src/Bundler/util.js.flow +15 -9
- package/src/Bundler.js.flow +2 -2
- package/src/DeltaBundler/DeltaCalculator.js.flow +7 -7
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +8 -2
- package/src/DeltaBundler/Serializers/deltaJSBundle.js.flow +8 -4
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +30 -25
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +3 -3
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +1 -1
- package/src/DeltaBundler/Serializers/helpers/serializeDeltaJSBundle.js.flow +5 -5
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +6 -4
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +1 -1
- package/src/DeltaBundler/Transformer.js +7 -0
- package/src/DeltaBundler/Transformer.js.flow +7 -3
- package/src/DeltaBundler/WorkerFarm.js +0 -7
- package/src/DeltaBundler/WorkerFarm.js.flow +3 -11
- package/src/DeltaBundler/__fixtures__/hasteImpl.js +1 -1
- package/src/DeltaBundler/traverseDependencies.js.flow +5 -5
- package/src/DeltaBundler.js.flow +5 -3
- package/src/HmrServer.js.flow +7 -7
- package/src/IncrementalBundler.js +2 -0
- package/src/IncrementalBundler.js.flow +9 -7
- package/src/JSTransformer/worker/constant-folding-plugin.js.flow +7 -7
- package/src/JSTransformer/worker/import-export-plugin.js +6 -0
- package/src/JSTransformer/worker/import-export-plugin.js.flow +15 -9
- package/src/JSTransformer/worker/inline-platform.js +1 -1
- package/src/JSTransformer/worker/inline-platform.js.flow +26 -15
- package/src/JSTransformer/worker/inline-plugin.js +10 -4
- package/src/JSTransformer/worker/inline-plugin.js.flow +16 -9
- package/src/JSTransformer/worker/normalizePseudoglobals.js.flow +5 -5
- package/src/JSTransformer/worker.js +2 -1
- package/src/JSTransformer/worker.js.flow +5 -5
- package/src/ModuleGraph/node-haste/HasteFS.js +0 -7
- package/src/ModuleGraph/node-haste/HasteFS.js.flow +19 -14
- package/src/ModuleGraph/node-haste/Module.js.flow +4 -3
- package/src/ModuleGraph/node-haste/Package.js.flow +3 -3
- package/src/ModuleGraph/node-haste/node-haste.js.flow +15 -10
- package/src/ModuleGraph/output/indexed-ram-bundle.js +30 -2
- package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +23 -15
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js +30 -2
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +14 -14
- package/src/ModuleGraph/output/plain-bundle.js +7 -25
- package/src/ModuleGraph/output/plain-bundle.js.flow +14 -22
- package/src/ModuleGraph/output/util.js +8 -2
- package/src/ModuleGraph/output/util.js.flow +7 -3
- package/src/ModuleGraph/silent-console.js +3 -0
- package/src/ModuleGraph/silent-console.js.flow +3 -0
- package/src/ModuleGraph/types.flow.js.flow +7 -5
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +1 -1
- package/src/ModuleGraph/worker/generate.js.flow +1 -1
- package/src/ModuleGraph/worker/mergeSourceMaps.js.flow +0 -1
- package/src/ModuleGraph/worker/optimizeDependencies.js.flow +3 -3
- package/src/Server/symbolicate/symbolicate.js +4 -6
- package/src/Server/symbolicate/symbolicate.js.flow +33 -26
- package/src/Server/symbolicate/util.js.flow +5 -4
- package/src/Server.js +16 -11
- package/src/Server.js.flow +61 -28
- package/src/commands/build.js.flow +7 -4
- package/src/commands/serve.js.flow +2 -2
- package/src/index.js +21 -4
- package/src/index.js.flow +63 -28
- package/src/integration_tests/basic_bundle/import-export/export-1.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-2.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-3.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-4.js.flow +1 -1
- package/src/integration_tests/execBundle.js +1 -1
- package/src/integration_tests/execBundle.js.flow +1 -1
- package/src/integration_tests/metro.config.js +1 -1
- package/src/legacy.js.flow +2 -2
- package/src/lib/BatchProcessor.js +0 -6
- package/src/lib/BatchProcessor.js.flow +18 -17
- package/src/lib/JsonReporter.js +1 -46
- package/src/lib/JsonReporter.js.flow +5 -19
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.js +1 -12
- package/src/lib/TerminalReporter.js.flow +20 -26
- package/src/lib/addParamsToDefineCall.js +2 -2
- package/src/lib/addParamsToDefineCall.js.flow +2 -2
- package/src/lib/attachWebsocketServer.js.flow +1 -1
- package/src/lib/bundle-modules/DeltaClient/bundleDB.js.flow +37 -33
- package/src/lib/bundle-modules/DeltaClient/bundleToString.js.flow +2 -5
- package/src/lib/bundle-modules/DeltaClient/dev.js +2 -1
- package/src/lib/bundle-modules/DeltaClient/dev.js.flow +27 -17
- package/src/lib/bundle-modules/DeltaClient/index.js.flow +8 -4
- package/src/lib/bundle-modules/DeltaClient/metadata.js.flow +2 -2
- package/src/lib/bundle-modules/DeltaClient/response.js +1 -0
- package/src/lib/bundle-modules/DeltaClient/response.js.flow +3 -1
- package/src/lib/bundle-modules/WebSocketHMRClient.js.flow +2 -2
- package/src/lib/bundle-modules/injectUpdate.js.flow +3 -3
- package/src/lib/bundle-modules/registerServiceWorker.js +59 -41
- package/src/lib/bundle-modules/registerServiceWorker.js.flow +61 -42
- package/src/lib/debounceAsyncQueue.js.flow +4 -4
- package/src/lib/getAppendScripts.js.flow +4 -4
- package/src/lib/getGraphId.js +1 -0
- package/src/lib/getGraphId.js.flow +1 -0
- package/src/lib/getKeyFromFiles.js.flow +3 -1
- package/src/lib/getPreludeCode.js +12 -6
- package/src/lib/getPreludeCode.js.flow +15 -6
- package/src/lib/getPrependedScripts.js.flow +1 -1
- package/src/lib/parseCustomTransformOptions.js +1 -1
- package/src/lib/parseCustomTransformOptions.js.flow +2 -2
- package/src/lib/parseOptionsFromUrl.js.flow +2 -5
- package/src/lib/polyfills/require.js +91 -114
- package/src/lib/polyfills/require.js.flow +46 -50
- package/src/lib/relativizeSourceMap.js.flow +1 -1
- package/src/lib/reporting.js.flow +2 -2
- package/src/lib/transformHelpers.js +3 -0
- package/src/lib/transformHelpers.js.flow +5 -1
- package/src/node-haste/AssetResolutionCache.js.flow +5 -2
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +15 -6
- package/src/node-haste/DependencyGraph/ResolutionRequest.js.flow +2 -2
- package/src/node-haste/DependencyGraph.js.flow +8 -5
- package/src/node-haste/Package.js.flow +1 -1
- package/src/node-haste/lib/AssetPaths.js.flow +1 -1
- package/src/shared/output/RamBundle/as-assets.js.flow +17 -8
- package/src/shared/output/RamBundle/as-indexed-file.js +28 -5
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +46 -20
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +2 -2
- package/src/shared/output/RamBundle/util.js.flow +14 -9
- package/src/shared/output/RamBundle.js +4 -8
- package/src/shared/output/RamBundle.js.flow +4 -7
- package/src/shared/output/bundle.js.flow +1 -1
- package/src/shared/output/meta.js +4 -4
- package/src/shared/output/meta.js.flow +16 -9
- package/src/shared/types.flow.js.flow +14 -1
- package/src/ModuleGraph/build.js +0 -193
- package/src/ModuleGraph/build.js.flow +0 -70
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.54.1",
|
|
3
3
|
"name": "metro",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
@@ -35,19 +35,21 @@
|
|
|
35
35
|
"graceful-fs": "^4.1.3",
|
|
36
36
|
"image-size": "^0.6.0",
|
|
37
37
|
"invariant": "^2.2.4",
|
|
38
|
-
"jest-haste-map": "24.
|
|
39
|
-
"jest-worker": "24.
|
|
38
|
+
"jest-haste-map": "^24.7.1",
|
|
39
|
+
"jest-worker": "^24.6.0",
|
|
40
40
|
"json-stable-stringify": "^1.0.1",
|
|
41
41
|
"lodash.throttle": "^4.1.1",
|
|
42
42
|
"merge-stream": "^1.0.1",
|
|
43
|
-
"metro-babel-
|
|
44
|
-
"metro-
|
|
45
|
-
"metro-
|
|
46
|
-
"metro-
|
|
47
|
-
"metro-
|
|
48
|
-
"metro-
|
|
49
|
-
"metro-
|
|
50
|
-
"metro-
|
|
43
|
+
"metro-babel-register": "0.54.1",
|
|
44
|
+
"metro-babel-transformer": "0.54.1",
|
|
45
|
+
"metro-cache": "0.54.1",
|
|
46
|
+
"metro-config": "0.54.1",
|
|
47
|
+
"metro-core": "0.54.1",
|
|
48
|
+
"metro-inspector-proxy": "0.54.1",
|
|
49
|
+
"metro-minify-uglify": "0.54.1",
|
|
50
|
+
"metro-react-native-babel-preset": "0.54.1",
|
|
51
|
+
"metro-resolver": "0.54.1",
|
|
52
|
+
"metro-source-map": "0.54.1",
|
|
51
53
|
"mime-types": "2.1.11",
|
|
52
54
|
"mkdirp": "^0.5.1",
|
|
53
55
|
"node-fetch": "^2.2.0",
|
|
@@ -69,10 +71,10 @@
|
|
|
69
71
|
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.0.0",
|
|
70
72
|
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
|
|
71
73
|
"acorn": "^5.1.2",
|
|
72
|
-
"metro-memory-fs": "0.
|
|
73
|
-
"metro-react-native-babel-preset": "0.
|
|
74
|
-
"metro-react-native-babel-transformer": "0.
|
|
75
|
-
"metro-visualizer": "0.
|
|
74
|
+
"metro-memory-fs": "0.54.1",
|
|
75
|
+
"metro-react-native-babel-preset": "0.54.1",
|
|
76
|
+
"metro-react-native-babel-transformer": "0.54.1",
|
|
77
|
+
"metro-visualizer": "0.54.1"
|
|
76
78
|
},
|
|
77
79
|
"license": "MIT"
|
|
78
80
|
}
|
package/src/Assets.js
CHANGED
|
@@ -345,12 +345,19 @@ function _getAsset() {
|
|
|
345
345
|
) {
|
|
346
346
|
let platform =
|
|
347
347
|
arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
348
|
+
let assetExts = arguments.length > 4 ? arguments[4] : undefined;
|
|
348
349
|
const assetData = AssetPaths.parse(
|
|
349
350
|
relativePath,
|
|
350
351
|
new Set(platform != null ? [platform] : [])
|
|
351
352
|
);
|
|
352
353
|
const absolutePath = path.resolve(projectRoot, relativePath);
|
|
353
354
|
|
|
355
|
+
if (!assetExts.includes(assetData.type)) {
|
|
356
|
+
throw new Error(
|
|
357
|
+
`'${relativePath}' cannot be loaded as its extension is not registered in assetExts`
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
354
361
|
if (
|
|
355
362
|
!pathBelongsToRoots(
|
|
356
363
|
absolutePath,
|
package/src/Assets.js.flow
CHANGED
|
@@ -23,6 +23,8 @@ const {isAssetTypeAnImage} = require('./Bundler/util');
|
|
|
23
23
|
const readDir = denodeify(fs.readdir);
|
|
24
24
|
const readFile = denodeify(fs.readFile);
|
|
25
25
|
|
|
26
|
+
import type {AssetPath} from './node-haste/lib/AssetPaths';
|
|
27
|
+
|
|
26
28
|
export type AssetInfo = {|
|
|
27
29
|
+files: Array<string>,
|
|
28
30
|
+hash: string,
|
|
@@ -42,6 +44,16 @@ export type AssetDataWithoutFiles = {
|
|
|
42
44
|
+type: string,
|
|
43
45
|
+width: ?number,
|
|
44
46
|
};
|
|
47
|
+
export type AssetDataFiltered = {
|
|
48
|
+
+__packager_asset: boolean,
|
|
49
|
+
+hash: string,
|
|
50
|
+
+height: ?number,
|
|
51
|
+
+httpServerLocation: string,
|
|
52
|
+
+name: string,
|
|
53
|
+
+scales: Array<number>,
|
|
54
|
+
+type: string,
|
|
55
|
+
+width: ?number,
|
|
56
|
+
};
|
|
45
57
|
|
|
46
58
|
export type AssetData = AssetDataWithoutFiles & {
|
|
47
59
|
+files: Array<string>,
|
|
@@ -51,7 +63,7 @@ export type AssetDataPlugin = (
|
|
|
51
63
|
assetData: AssetData,
|
|
52
64
|
) => AssetData | Promise<AssetData>;
|
|
53
65
|
|
|
54
|
-
const hashFiles = denodeify(function hashFilesCb(files, hash, callback) {
|
|
66
|
+
const hashFiles = denodeify(function hashFilesCb(files, hash, callback): void {
|
|
55
67
|
if (!files.length) {
|
|
56
68
|
callback(null);
|
|
57
69
|
return;
|
|
@@ -59,7 +71,7 @@ const hashFiles = denodeify(function hashFilesCb(files, hash, callback) {
|
|
|
59
71
|
|
|
60
72
|
const file = files.shift();
|
|
61
73
|
|
|
62
|
-
fs.readFile(file, (err, data) => {
|
|
74
|
+
fs.readFile(file, (err, data: Buffer) => {
|
|
63
75
|
if (err) {
|
|
64
76
|
callback(err);
|
|
65
77
|
return;
|
|
@@ -74,17 +86,13 @@ function buildAssetMap(
|
|
|
74
86
|
dir: string,
|
|
75
87
|
files: $ReadOnlyArray<string>,
|
|
76
88
|
platform: ?string,
|
|
77
|
-
): Map<
|
|
78
|
-
string,
|
|
79
|
-
{|
|
|
80
|
-
files: Array<string>,
|
|
81
|
-
scales: Array<number>,
|
|
82
|
-
|},
|
|
83
|
-
> {
|
|
89
|
+
): Map<string, {|files: Array<string>, scales: Array<number>|}> {
|
|
84
90
|
const platforms = new Set(platform != null ? [platform] : []);
|
|
85
|
-
const assets = files.map(
|
|
91
|
+
const assets = files.map((file: string) =>
|
|
92
|
+
AssetPaths.tryParse(file, platforms),
|
|
93
|
+
);
|
|
86
94
|
const map = new Map();
|
|
87
|
-
assets.forEach(function(asset, i) {
|
|
95
|
+
assets.forEach(function(asset: ?AssetPath, i: number) {
|
|
88
96
|
if (asset == null) {
|
|
89
97
|
return;
|
|
90
98
|
}
|
|
@@ -114,7 +122,7 @@ function buildAssetMap(
|
|
|
114
122
|
return map;
|
|
115
123
|
}
|
|
116
124
|
|
|
117
|
-
function getAssetKey(assetName, platform) {
|
|
125
|
+
function getAssetKey(assetName: string, platform: ?string): string {
|
|
118
126
|
if (platform != null) {
|
|
119
127
|
return `${assetName} : ${platform}`;
|
|
120
128
|
} else {
|
|
@@ -125,10 +133,7 @@ function getAssetKey(assetName, platform) {
|
|
|
125
133
|
async function getAbsoluteAssetRecord(
|
|
126
134
|
assetPath: string,
|
|
127
135
|
platform: ?string = null,
|
|
128
|
-
): Promise<{|
|
|
129
|
-
files: Array<string>,
|
|
130
|
-
scales: Array<number>,
|
|
131
|
-
|}> {
|
|
136
|
+
): Promise<{|files: Array<string>, scales: Array<number>|}> {
|
|
132
137
|
const filename = path.basename(assetPath);
|
|
133
138
|
const dir = path.dirname(assetPath);
|
|
134
139
|
const files = await readDir(dir);
|
|
@@ -265,6 +270,7 @@ async function getAsset(
|
|
|
265
270
|
projectRoot: string,
|
|
266
271
|
watchFolders: $ReadOnlyArray<string>,
|
|
267
272
|
platform: ?string = null,
|
|
273
|
+
assetExts: $ReadOnlyArray<string>,
|
|
268
274
|
): Promise<Buffer> {
|
|
269
275
|
const assetData = AssetPaths.parse(
|
|
270
276
|
relativePath,
|
|
@@ -273,6 +279,12 @@ async function getAsset(
|
|
|
273
279
|
|
|
274
280
|
const absolutePath = path.resolve(projectRoot, relativePath);
|
|
275
281
|
|
|
282
|
+
if (!assetExts.includes(assetData.type)) {
|
|
283
|
+
throw new Error(
|
|
284
|
+
`'${relativePath}' cannot be loaded as its extension is not registered in assetExts`,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
276
288
|
if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
|
|
277
289
|
throw new Error(
|
|
278
290
|
`'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
|
package/src/Bundler/util.js
CHANGED
|
@@ -159,7 +159,6 @@ function filterObject(object, blacklist) {
|
|
|
159
159
|
|
|
160
160
|
function createRamBundleGroups(ramGroups, groupableModules, subtree) {
|
|
161
161
|
// build two maps that allow to lookup module data
|
|
162
|
-
// by path or (numeric) module id;
|
|
163
162
|
const byPath = new Map();
|
|
164
163
|
const byId = new Map();
|
|
165
164
|
groupableModules.forEach(m => {
|
package/src/Bundler/util.js.flow
CHANGED
|
@@ -14,7 +14,7 @@ const template = require('@babel/template').default;
|
|
|
14
14
|
const babelTypes = require('@babel/types');
|
|
15
15
|
const babylon = require('@babel/parser');
|
|
16
16
|
|
|
17
|
-
import type {AssetDataWithoutFiles} from '../Assets';
|
|
17
|
+
import type {AssetDataFiltered, AssetDataWithoutFiles} from '../Assets';
|
|
18
18
|
import type {ModuleTransportLike} from '../shared/types.flow';
|
|
19
19
|
import type {Ast} from '@babel/core';
|
|
20
20
|
|
|
@@ -128,8 +128,8 @@ function generateRemoteAssetCodeFileAst(
|
|
|
128
128
|
SCALE_ARRAY: t.arrayExpression(
|
|
129
129
|
Object.keys(descriptor)
|
|
130
130
|
.map(Number)
|
|
131
|
-
.sort((a, b) => a - b)
|
|
132
|
-
.map(scale => t.numericLiteral(scale)),
|
|
131
|
+
.sort((a: number, b: number) => a - b)
|
|
132
|
+
.map((scale: number) => t.numericLiteral(scale)),
|
|
133
133
|
),
|
|
134
134
|
}),
|
|
135
135
|
]),
|
|
@@ -146,7 +146,10 @@ function isAssetTypeAnImage(type: string): boolean {
|
|
|
146
146
|
);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
function filterObject(
|
|
149
|
+
function filterObject(
|
|
150
|
+
object: AssetDataWithoutFiles,
|
|
151
|
+
blacklist: Set<string>,
|
|
152
|
+
): AssetDataFiltered {
|
|
150
153
|
const copied = Object.assign({}, object);
|
|
151
154
|
for (const key of blacklist) {
|
|
152
155
|
delete copied[key];
|
|
@@ -161,16 +164,16 @@ function createRamBundleGroups<T: ModuleTransportLike>(
|
|
|
161
164
|
): Map<number, Set<number>> {
|
|
162
165
|
// build two maps that allow to lookup module data
|
|
163
166
|
// by path or (numeric) module id;
|
|
164
|
-
const byPath = new Map();
|
|
165
|
-
const byId = new Map();
|
|
166
|
-
groupableModules.forEach(m => {
|
|
167
|
+
const byPath: Map<string, T> = new Map();
|
|
168
|
+
const byId: Map<number, string> = new Map();
|
|
169
|
+
groupableModules.forEach((m: T) => {
|
|
167
170
|
byPath.set(m.sourcePath, m);
|
|
168
171
|
byId.set(m.id, m.sourcePath);
|
|
169
172
|
});
|
|
170
173
|
|
|
171
174
|
// build a map of group root IDs to an array of module IDs in the group
|
|
172
175
|
const result: Map<number, Set<number>> = new Map(
|
|
173
|
-
ramGroups.map(modulePath => {
|
|
176
|
+
ramGroups.map((modulePath: string) => {
|
|
174
177
|
const root = byPath.get(modulePath);
|
|
175
178
|
if (root == null) {
|
|
176
179
|
throw Error(`Group root ${modulePath} is not part of the bundle`);
|
|
@@ -209,7 +212,10 @@ function createRamBundleGroups<T: ModuleTransportLike>(
|
|
|
209
212
|
return result;
|
|
210
213
|
}
|
|
211
214
|
|
|
212
|
-
function* filter
|
|
215
|
+
function* filter<A: number, B: number>(
|
|
216
|
+
iterator: ArrayMap<A, B>,
|
|
217
|
+
predicate: ([A, Array<B>]) => boolean,
|
|
218
|
+
): Generator<[A, Array<B>], void, void> {
|
|
213
219
|
for (const value of iterator) {
|
|
214
220
|
if (predicate(value)) {
|
|
215
221
|
yield value;
|
package/src/Bundler.js.flow
CHANGED
|
@@ -25,7 +25,7 @@ class Bundler {
|
|
|
25
25
|
this._depGraphPromise = DependencyGraph.load(config);
|
|
26
26
|
|
|
27
27
|
this._depGraphPromise
|
|
28
|
-
.then(dependencyGraph => {
|
|
28
|
+
.then((dependencyGraph: DependencyGraph) => {
|
|
29
29
|
this._transformer = new Transformer(
|
|
30
30
|
config,
|
|
31
31
|
dependencyGraph.getSha1.bind(dependencyGraph),
|
|
@@ -36,7 +36,7 @@ class Bundler {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async end() {
|
|
39
|
+
async end(): Promise<void> {
|
|
40
40
|
const dependencyGraph = await this._depGraphPromise;
|
|
41
41
|
|
|
42
42
|
this._transformer.end();
|
|
@@ -59,7 +59,7 @@ class DeltaCalculator<T> extends EventEmitter {
|
|
|
59
59
|
/**
|
|
60
60
|
* Stops listening for file changes and clears all the caches.
|
|
61
61
|
*/
|
|
62
|
-
end() {
|
|
62
|
+
end(): void {
|
|
63
63
|
this._dependencyGraph
|
|
64
64
|
.getWatcher()
|
|
65
65
|
.removeListener('change', this._handleMultipleFileChanges);
|
|
@@ -113,8 +113,8 @@ class DeltaCalculator<T> extends EventEmitter {
|
|
|
113
113
|
// processed (since we haven't actually created any delta). If we do not
|
|
114
114
|
// do so, asking for a delta after an error will produce an empty Delta,
|
|
115
115
|
// which is not correct.
|
|
116
|
-
modifiedFiles.forEach(file => this._modifiedFiles.add(file));
|
|
117
|
-
deletedFiles.forEach(file => this._deletedFiles.add(file));
|
|
116
|
+
modifiedFiles.forEach((file: string) => this._modifiedFiles.add(file));
|
|
117
|
+
deletedFiles.forEach((file: string) => this._deletedFiles.add(file));
|
|
118
118
|
|
|
119
119
|
// If after an error the number of modules has changed, we could be in
|
|
120
120
|
// a weird state. As a safe net we clean the dependency modules to force
|
|
@@ -201,11 +201,11 @@ class DeltaCalculator<T> extends EventEmitter {
|
|
|
201
201
|
|
|
202
202
|
// If a file has been deleted, we want to invalidate any other file that
|
|
203
203
|
// depends on it, so we can process it and correctly return an error.
|
|
204
|
-
deletedFiles.forEach(filePath => {
|
|
204
|
+
deletedFiles.forEach((filePath: string) => {
|
|
205
205
|
const module = this._graph.dependencies.get(filePath);
|
|
206
206
|
|
|
207
207
|
if (module) {
|
|
208
|
-
module.inverseDependencies.forEach(path => {
|
|
208
|
+
module.inverseDependencies.forEach((path: string) => {
|
|
209
209
|
// Only mark the inverse dependency as modified if it's not already
|
|
210
210
|
// marked as deleted (in that case we can just ignore it).
|
|
211
211
|
if (!deletedFiles.has(path)) {
|
|
@@ -216,8 +216,8 @@ class DeltaCalculator<T> extends EventEmitter {
|
|
|
216
216
|
});
|
|
217
217
|
|
|
218
218
|
// We only want to process files that are in the bundle.
|
|
219
|
-
const modifiedDependencies = Array.from(modifiedFiles).filter(
|
|
220
|
-
this._graph.dependencies.has(filePath),
|
|
219
|
+
const modifiedDependencies = Array.from(modifiedFiles).filter(
|
|
220
|
+
(filePath: string) => this._graph.dependencies.has(filePath),
|
|
221
221
|
);
|
|
222
222
|
|
|
223
223
|
// No changes happened. Return empty delta.
|
|
@@ -14,7 +14,12 @@ const getAppendScripts = require('../../lib/getAppendScripts');
|
|
|
14
14
|
const processModules = require('./helpers/processModules');
|
|
15
15
|
|
|
16
16
|
import type {Bundle} from '../../lib/bundle-modules/types.flow';
|
|
17
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
Graph,
|
|
19
|
+
MixedOutput,
|
|
20
|
+
Module,
|
|
21
|
+
SerializerOptions,
|
|
22
|
+
} from '../types.flow';
|
|
18
23
|
|
|
19
24
|
function baseJSBundle(
|
|
20
25
|
entryPoint: string,
|
|
@@ -38,7 +43,8 @@ function baseJSBundle(
|
|
|
38
43
|
.join('\n');
|
|
39
44
|
|
|
40
45
|
const modules = [...graph.dependencies.values()].sort(
|
|
41
|
-
(a
|
|
46
|
+
(a: Module<MixedOutput>, b: Module<MixedOutput>) =>
|
|
47
|
+
options.createModuleId(a.path) - options.createModuleId(b.path),
|
|
42
48
|
);
|
|
43
49
|
|
|
44
50
|
const postCode = processModules(
|
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
Module,
|
|
24
24
|
SerializerOptions,
|
|
25
25
|
} from '../types.flow';
|
|
26
|
+
import type {MixedOutput} from '../types.flow';
|
|
26
27
|
|
|
27
28
|
function deltaJSBundle(
|
|
28
29
|
entryPoint: string,
|
|
@@ -47,7 +48,8 @@ function deltaJSBundle(
|
|
|
47
48
|
|
|
48
49
|
if (delta.reset) {
|
|
49
50
|
const modules = [...graph.dependencies.values()].sort(
|
|
50
|
-
(a
|
|
51
|
+
(a: Module<MixedOutput>, b: Module<MixedOutput>) =>
|
|
52
|
+
options.createModuleId(a.path) - options.createModuleId(b.path),
|
|
51
53
|
);
|
|
52
54
|
const appendScripts = getAppendScripts(
|
|
53
55
|
entryPoint,
|
|
@@ -61,12 +63,12 @@ function deltaJSBundle(
|
|
|
61
63
|
pre: pre
|
|
62
64
|
.filter(isJsModule)
|
|
63
65
|
.filter(processModuleFilter)
|
|
64
|
-
.map(module => getJsOutput(module).data.code)
|
|
66
|
+
.map((module: Module<>) => getJsOutput(module).data.code)
|
|
65
67
|
.join('\n'),
|
|
66
68
|
post: appendScripts
|
|
67
69
|
.filter(isJsModule)
|
|
68
70
|
.filter(processModuleFilter)
|
|
69
|
-
.map(module => getJsOutput(module).data.code)
|
|
71
|
+
.map((module: Module<>) => getJsOutput(module).data.code)
|
|
70
72
|
.join('\n'),
|
|
71
73
|
modules: [...added],
|
|
72
74
|
};
|
|
@@ -77,7 +79,9 @@ function deltaJSBundle(
|
|
|
77
79
|
processOpts,
|
|
78
80
|
).map(([module, code]) => [options.createModuleId(module.path), code]);
|
|
79
81
|
|
|
80
|
-
const deleted = [...delta.deleted].map(path =>
|
|
82
|
+
const deleted = [...delta.deleted].map((path: string) =>
|
|
83
|
+
options.createModuleId(path),
|
|
84
|
+
);
|
|
81
85
|
|
|
82
86
|
return {
|
|
83
87
|
base: false,
|
|
@@ -19,7 +19,10 @@ const path = require('path');
|
|
|
19
19
|
const {createRamBundleGroups} = require('../../Bundler/util');
|
|
20
20
|
const {isJsModule, wrapModule} = require('./helpers/js');
|
|
21
21
|
|
|
22
|
-
import type {
|
|
22
|
+
import type {
|
|
23
|
+
ModuleTransportLike,
|
|
24
|
+
RamModuleTransport,
|
|
25
|
+
} from '../../shared/types.flow';
|
|
23
26
|
import type {Graph, Module, SerializerOptions} from '../types.flow';
|
|
24
27
|
import type {GetTransformOptions} from 'metro-config/src/configTypes.flow.js';
|
|
25
28
|
|
|
@@ -43,27 +46,32 @@ async function getRamBundleInfo(
|
|
|
43
46
|
graph: Graph<>,
|
|
44
47
|
options: Options,
|
|
45
48
|
): Promise<RamBundleInfo> {
|
|
46
|
-
let modules = [
|
|
49
|
+
let modules: $ReadOnlyArray<Module<>> = [
|
|
50
|
+
...pre,
|
|
51
|
+
...graph.dependencies.values(),
|
|
52
|
+
];
|
|
47
53
|
modules = modules.concat(getAppendScripts(entryPoint, modules, options));
|
|
48
54
|
|
|
49
|
-
modules.forEach(module => options.createModuleId(module.path));
|
|
55
|
+
modules.forEach((module: Module<>) => options.createModuleId(module.path));
|
|
50
56
|
|
|
51
|
-
const ramModules = modules
|
|
57
|
+
const ramModules: Array<RamModuleTransport> = modules
|
|
52
58
|
.filter(isJsModule)
|
|
53
59
|
.filter(options.processModuleFilter)
|
|
54
|
-
.map(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
.map(
|
|
61
|
+
(module: Module<>): RamModuleTransport => ({
|
|
62
|
+
id: options.createModuleId(module.path),
|
|
63
|
+
code: wrapModule(module, options),
|
|
64
|
+
map: fullSourceMapObject([module], {
|
|
65
|
+
excludeSource: options.excludeSource,
|
|
66
|
+
processModuleFilter: options.processModuleFilter,
|
|
67
|
+
}),
|
|
68
|
+
name: path.basename(module.path),
|
|
69
|
+
sourcePath: module.path,
|
|
70
|
+
source: module.getSource().toString(),
|
|
71
|
+
type: nullthrows(module.output.find(({type}) => type.startsWith('js')))
|
|
72
|
+
.type,
|
|
60
73
|
}),
|
|
61
|
-
|
|
62
|
-
sourcePath: module.path,
|
|
63
|
-
source: module.getSource().toString(),
|
|
64
|
-
type: nullthrows(module.output.find(({type}) => type.startsWith('js')))
|
|
65
|
-
.type,
|
|
66
|
-
}));
|
|
74
|
+
);
|
|
67
75
|
|
|
68
76
|
const {preloadedModules, ramGroups} = await _getRamOptions(
|
|
69
77
|
entryPoint,
|
|
@@ -71,14 +79,14 @@ async function getRamBundleInfo(
|
|
|
71
79
|
dev: options.dev,
|
|
72
80
|
platform: options.platform,
|
|
73
81
|
},
|
|
74
|
-
filePath => getTransitiveDependencies(filePath, graph),
|
|
82
|
+
(filePath: string) => getTransitiveDependencies(filePath, graph),
|
|
75
83
|
options.getTransformOptions,
|
|
76
84
|
);
|
|
77
85
|
|
|
78
86
|
const startupModules = [];
|
|
79
87
|
const lazyModules = [];
|
|
80
88
|
|
|
81
|
-
ramModules.forEach(module => {
|
|
89
|
+
ramModules.forEach((module: RamModuleTransport) => {
|
|
82
90
|
if (preloadedModules.hasOwnProperty(module.sourcePath)) {
|
|
83
91
|
startupModules.push(module);
|
|
84
92
|
return;
|
|
@@ -100,7 +108,7 @@ async function getRamBundleInfo(
|
|
|
100
108
|
(
|
|
101
109
|
module: ModuleTransportLike,
|
|
102
110
|
dependenciesByPath: Map<string, ModuleTransportLike>,
|
|
103
|
-
) => {
|
|
111
|
+
): Set<number> => {
|
|
104
112
|
const deps = getTransitiveDependencies(module.sourcePath, graph);
|
|
105
113
|
const output = new Set();
|
|
106
114
|
|
|
@@ -117,7 +125,7 @@ async function getRamBundleInfo(
|
|
|
117
125
|
);
|
|
118
126
|
|
|
119
127
|
return {
|
|
120
|
-
getDependencies: (filePath: string) =>
|
|
128
|
+
getDependencies: (filePath: string): Set<string> =>
|
|
121
129
|
getTransitiveDependencies(filePath, graph),
|
|
122
130
|
groups,
|
|
123
131
|
lazyModules,
|
|
@@ -133,10 +141,7 @@ async function _getRamOptions(
|
|
|
133
141
|
options: {dev: boolean, platform: ?string},
|
|
134
142
|
getDependencies: string => Iterable<string>,
|
|
135
143
|
getTransformOptions: ?GetTransformOptions,
|
|
136
|
-
): Promise<{
|
|
137
|
-
+preloadedModules: {[string]: true},
|
|
138
|
-
+ramGroups: Array<string>,
|
|
139
|
-
|}> {
|
|
144
|
+
): Promise<{|+preloadedModules: {[string]: true}, +ramGroups: Array<string>|}> {
|
|
140
145
|
if (getTransformOptions == null) {
|
|
141
146
|
return {
|
|
142
147
|
preloadedModules: {},
|
|
@@ -147,7 +152,7 @@ async function _getRamOptions(
|
|
|
147
152
|
const {preloadedModules, ramGroups} = await getTransformOptions(
|
|
148
153
|
[entryFile],
|
|
149
154
|
{dev: options.dev, hot: true, platform: options.platform},
|
|
150
|
-
async x => Array.from(getDependencies),
|
|
155
|
+
async (x: string) => Array.from(getDependencies),
|
|
151
156
|
);
|
|
152
157
|
|
|
153
158
|
return {
|
|
@@ -15,7 +15,7 @@ const invariant = require('invariant');
|
|
|
15
15
|
const path = require('path');
|
|
16
16
|
|
|
17
17
|
import type {JsOutput} from '../../../JSTransformer/worker';
|
|
18
|
-
import type {MixedOutput, Module} from '../../types.flow';
|
|
18
|
+
import type {MixedOutput, Module, Dependency} from '../../types.flow';
|
|
19
19
|
|
|
20
20
|
export type Options = {
|
|
21
21
|
+createModuleId: string => number | string,
|
|
@@ -23,7 +23,7 @@ export type Options = {
|
|
|
23
23
|
+projectRoot: string,
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
function wrapModule(module: Module<>, options: Options) {
|
|
26
|
+
function wrapModule(module: Module<>, options: Options): string {
|
|
27
27
|
const output = getJsOutput(module);
|
|
28
28
|
|
|
29
29
|
if (output.type.startsWith('js/script')) {
|
|
@@ -33,7 +33,7 @@ function wrapModule(module: Module<>, options: Options) {
|
|
|
33
33
|
const moduleId = options.createModuleId(module.path);
|
|
34
34
|
const params = [
|
|
35
35
|
moduleId,
|
|
36
|
-
Array.from(module.dependencies.values()).map(dependency => {
|
|
36
|
+
Array.from(module.dependencies.values()).map((dependency: Dependency) => {
|
|
37
37
|
return options.createModuleId(dependency.absolutePath);
|
|
38
38
|
}),
|
|
39
39
|
];
|
|
@@ -51,7 +51,7 @@ exports.toBinaryStream = (bundle: BundleVariant): Readable => {
|
|
|
51
51
|
const MAGIC_NUMBER = Buffer.of(0xfb, 0xde, 0x17, 0xa5);
|
|
52
52
|
const FORMAT_VERSION = [0x01, 0x00, 0x00];
|
|
53
53
|
|
|
54
|
-
function* streamBundle(bundle: BundleVariant) {
|
|
54
|
+
function* streamBundle(bundle: BundleVariant): Generator<Buffer, void, void> {
|
|
55
55
|
yield MAGIC_NUMBER;
|
|
56
56
|
yield Buffer.of(...FORMAT_VERSION, bundle.base ? 1 : 0);
|
|
57
57
|
|
|
@@ -81,7 +81,7 @@ function* streamBundle(bundle: BundleVariant) {
|
|
|
81
81
|
|
|
82
82
|
const SIZEOF_UINT32 = 4;
|
|
83
83
|
|
|
84
|
-
function str(value) {
|
|
84
|
+
function str(value: string): Buffer {
|
|
85
85
|
const size = Buffer.byteLength(value);
|
|
86
86
|
const buffer = Buffer.allocUnsafe(size + SIZEOF_UINT32);
|
|
87
87
|
buffer.writeUInt32LE(size, 0);
|
|
@@ -94,7 +94,7 @@ const ABSENT_BUFFER = [0xff, 0xff, 0xff, 0xff];
|
|
|
94
94
|
const EMPTY_CRC32 = [0x00, 0x00, 0x00, 0x00];
|
|
95
95
|
const EMPTY_PRE_OR_POST_SECTION = Buffer.of(...ABSENT_BUFFER, ...EMPTY_CRC32);
|
|
96
96
|
|
|
97
|
-
function preOrPostSection(section) {
|
|
97
|
+
function preOrPostSection(section: string): Buffer {
|
|
98
98
|
if (section.length === 0) {
|
|
99
99
|
return EMPTY_PRE_OR_POST_SECTION;
|
|
100
100
|
}
|
|
@@ -110,7 +110,7 @@ function preOrPostSection(section) {
|
|
|
110
110
|
return buffer;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
function module(idAndCode) {
|
|
113
|
+
function module(idAndCode: [number, string] | [number, null]): Buffer {
|
|
114
114
|
const code = idAndCode[1];
|
|
115
115
|
let buffer, length;
|
|
116
116
|
if (code == null) {
|
|
@@ -127,7 +127,7 @@ function module(idAndCode) {
|
|
|
127
127
|
return buffer;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
function appendCRC32(buffer) {
|
|
130
|
+
function appendCRC32(buffer: Buffer): void {
|
|
131
131
|
const CRC32_OFFSET = buffer.length - SIZEOF_UINT32;
|
|
132
132
|
buffer.writeUInt32LE(
|
|
133
133
|
crc32.unsigned(buffer.slice(0, CRC32_OFFSET)),
|
|
@@ -68,10 +68,10 @@ function hmrJSBundle(
|
|
|
68
68
|
options: Options,
|
|
69
69
|
): {|
|
|
70
70
|
+added: ModuleMap,
|
|
71
|
-
+modified: ModuleMap,
|
|
72
|
-
+deleted: $ReadOnlyArray<number>,
|
|
73
71
|
+addedSourceMappingURLs: $ReadOnlyArray<string>,
|
|
74
72
|
+addedSourceURLs: $ReadOnlyArray<string>,
|
|
73
|
+
+deleted: $ReadOnlyArray<number>,
|
|
74
|
+
+modified: ModuleMap,
|
|
75
75
|
+modifiedSourceMappingURLs: $ReadOnlyArray<string>,
|
|
76
76
|
+modifiedSourceURLs: $ReadOnlyArray<string>,
|
|
77
77
|
|} {
|
|
@@ -89,7 +89,9 @@ function hmrJSBundle(
|
|
|
89
89
|
return {
|
|
90
90
|
added,
|
|
91
91
|
modified,
|
|
92
|
-
deleted: [...delta.deleted].map(path =>
|
|
92
|
+
deleted: [...delta.deleted].map((path: string) =>
|
|
93
|
+
options.createModuleId(path),
|
|
94
|
+
),
|
|
93
95
|
addedSourceMappingURLs,
|
|
94
96
|
addedSourceURLs,
|
|
95
97
|
modifiedSourceMappingURLs,
|
|
@@ -111,7 +113,7 @@ function _prepareModule(
|
|
|
111
113
|
|
|
112
114
|
// Transform the inverse dependency paths to ids.
|
|
113
115
|
const inverseDependenciesById = Object.create(null);
|
|
114
|
-
Object.keys(inverseDependencies).forEach(path => {
|
|
116
|
+
Object.keys(inverseDependencies).forEach((path: string) => {
|
|
115
117
|
inverseDependenciesById[options.createModuleId(path)] = inverseDependencies[
|
|
116
118
|
path
|
|
117
119
|
].map(options.createModuleId);
|
|
@@ -29,7 +29,7 @@ function sourceMapGenerator(
|
|
|
29
29
|
const sourceMapInfos = modules
|
|
30
30
|
.filter(isJsModule)
|
|
31
31
|
.filter(options.processModuleFilter)
|
|
32
|
-
.map(module =>
|
|
32
|
+
.map((module: Module<>) =>
|
|
33
33
|
getSourceMapInfo(module, {excludeSource: options.excludeSource}),
|
|
34
34
|
);
|
|
35
35
|
return fromRawMappings(sourceMapInfos);
|
|
@@ -163,8 +163,11 @@ class Transformer {
|
|
|
163
163
|
experimentalImportSupport =
|
|
164
164
|
transformerOptions.experimentalImportSupport,
|
|
165
165
|
hot = transformerOptions.hot,
|
|
166
|
+
inlinePlatform = transformerOptions.inlinePlatform,
|
|
166
167
|
inlineRequires = transformerOptions.inlineRequires,
|
|
167
168
|
minify = transformerOptions.minify,
|
|
169
|
+
unstable_disableES6Transforms =
|
|
170
|
+
transformerOptions.unstable_disableES6Transforms,
|
|
168
171
|
platform = transformerOptions.platform,
|
|
169
172
|
type = transformerOptions.type,
|
|
170
173
|
extra = _objectWithoutProperties(transformerOptions, [
|
|
@@ -172,8 +175,10 @@ class Transformer {
|
|
|
172
175
|
"dev",
|
|
173
176
|
"experimentalImportSupport",
|
|
174
177
|
"hot",
|
|
178
|
+
"inlinePlatform",
|
|
175
179
|
"inlineRequires",
|
|
176
180
|
"minify",
|
|
181
|
+
"unstable_disableES6Transforms",
|
|
177
182
|
"platform",
|
|
178
183
|
"type"
|
|
179
184
|
]);
|
|
@@ -195,8 +200,10 @@ class Transformer {
|
|
|
195
200
|
dev,
|
|
196
201
|
experimentalImportSupport,
|
|
197
202
|
hot,
|
|
203
|
+
inlinePlatform,
|
|
198
204
|
inlineRequires,
|
|
199
205
|
minify,
|
|
206
|
+
unstable_disableES6Transforms,
|
|
200
207
|
platform,
|
|
201
208
|
type
|
|
202
209
|
]);
|