metro 0.75.0 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +23 -24
- package/src/Assets.js +2 -2
- package/src/Assets.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.js +18 -11
- package/src/DeltaBundler/DeltaCalculator.js.flow +15 -11
- package/src/DeltaBundler/Graph.js +11 -28
- package/src/DeltaBundler/Graph.js.flow +7 -0
- package/src/DeltaBundler/Serializers/helpers/js.js +2 -7
- package/src/DeltaBundler/types.flow.js.flow +2 -7
- package/src/HmrServer.js +9 -32
- package/src/IncrementalBundler.js +9 -9
- package/src/IncrementalBundler.js.flow +4 -0
- package/src/ModuleGraph/worker/collectDependencies.js +53 -89
- package/src/ModuleGraph/worker/collectDependencies.js.flow +113 -141
- package/src/Server/symbolicate.js +1 -5
- package/src/Server.js +15 -53
- package/src/Server.js.flow +5 -0
- package/src/commands/dependencies.js +1 -5
- package/src/index.flow.js +1 -2
- package/src/integration_tests/basic_bundle/TestBigInt.js +0 -3
- package/src/integration_tests/basic_bundle/TestBigInt.js.flow +0 -3
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js +1 -0
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +1 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js +28 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +33 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js +20 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +23 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js +18 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +21 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js +28 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +33 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js +19 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js.flow +18 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js +13 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/utils.js +1 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/utils.js.flow +14 -0
- package/src/lib/CountingSet.js +1 -5
- package/src/lib/RamBundleParser.js +0 -1
- package/src/lib/RamBundleParser.js.flow +0 -1
- package/src/lib/TerminalReporter.js +9 -17
- package/src/lib/TerminalReporter.js.flow +7 -0
- package/src/lib/contextModuleTemplates.js +1 -1
- package/src/lib/contextModuleTemplates.js.flow +1 -1
- package/src/lib/formatBundlingError.js +0 -3
- package/src/lib/formatBundlingError.js.flow +0 -3
- package/src/lib/getAppendScripts.js +0 -3
- package/src/lib/getAppendScripts.js.flow +0 -3
- package/src/lib/getGraphId.js +2 -11
- package/src/lib/getPrependedScripts.js +2 -1
- package/src/lib/getPrependedScripts.js.flow +2 -1
- package/src/lib/reporting.js.flow +4 -0
- package/src/lib/transformHelpers.js +16 -22
- package/src/lib/transformHelpers.js.flow +7 -8
- package/src/node-haste/DependencyGraph/ModuleResolution.js +13 -11
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +17 -5
- package/src/node-haste/DependencyGraph/createHasteMap.js +13 -38
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +2 -1
- package/src/node-haste/DependencyGraph.js +28 -22
- package/src/node-haste/DependencyGraph.js.flow +25 -9
- package/src/node-haste/Module.js +5 -3
- package/src/node-haste/Module.js.flow +2 -3
- package/src/node-haste/ModuleCache.js +1 -5
|
@@ -39,11 +39,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
39
39
|
constructor(config, options) {
|
|
40
40
|
super();
|
|
41
41
|
this._config = config;
|
|
42
|
-
|
|
43
|
-
config.resolver.assetExts.map((asset) => "." + asset)
|
|
44
|
-
);
|
|
45
|
-
const { hasReducedPerformance, watch } =
|
|
46
|
-
options !== null && options !== void 0 ? options : {};
|
|
42
|
+
const { hasReducedPerformance, watch } = options ?? {};
|
|
47
43
|
const initializingMetroLogEntry = log(
|
|
48
44
|
createActionStartEntry("Initializing Metro")
|
|
49
45
|
);
|
|
@@ -129,6 +125,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
129
125
|
}
|
|
130
126
|
_createModuleResolver() {
|
|
131
127
|
this._moduleResolver = new ModuleResolver({
|
|
128
|
+
assetExts: new Set(this._config.resolver.assetExts),
|
|
132
129
|
dirExists: (filePath) => {
|
|
133
130
|
try {
|
|
134
131
|
return fs.lstatSync(filePath).isDirectory();
|
|
@@ -144,20 +141,29 @@ class DependencyGraph extends EventEmitter {
|
|
|
144
141
|
this._hasteModuleMap.getModule(name, platform, true),
|
|
145
142
|
getHastePackagePath: (name, platform) =>
|
|
146
143
|
this._hasteModuleMap.getPackage(name, platform, true),
|
|
147
|
-
isAssetFile: (file) => this._assetExtensions.has(path.extname(file)),
|
|
148
144
|
mainFields: this._config.resolver.resolverMainFields,
|
|
149
145
|
moduleCache: this._moduleCache,
|
|
150
146
|
nodeModulesPaths: this._config.resolver.nodeModulesPaths,
|
|
151
147
|
preferNativePlatform: true,
|
|
152
148
|
projectRoot: this._config.projectRoot,
|
|
149
|
+
reporter: this._config.reporter,
|
|
153
150
|
resolveAsset: (dirPath, assetName, extension) => {
|
|
154
151
|
const basePath = dirPath + path.sep + assetName;
|
|
155
|
-
|
|
152
|
+
let assets = [
|
|
156
153
|
basePath + extension,
|
|
157
154
|
...this._config.resolver.assetResolutions.map(
|
|
158
155
|
(resolution) => basePath + "@" + resolution + "x" + extension
|
|
159
156
|
),
|
|
160
|
-
]
|
|
157
|
+
];
|
|
158
|
+
if (this._config.resolver.unstable_enableSymlinks) {
|
|
159
|
+
assets = assets
|
|
160
|
+
.map((candidate) => this._fileSystem.getRealPath(candidate))
|
|
161
|
+
.filter(Boolean);
|
|
162
|
+
} else {
|
|
163
|
+
assets = assets.filter((candidate) =>
|
|
164
|
+
this._fileSystem.exists(candidate)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
161
167
|
return assets.length ? assets : null;
|
|
162
168
|
},
|
|
163
169
|
resolveRequest: this._config.resolver.resolveRequest,
|
|
@@ -167,6 +173,9 @@ class DependencyGraph extends EventEmitter {
|
|
|
167
173
|
this._config.resolver.unstable_conditionsByPlatform,
|
|
168
174
|
unstable_enablePackageExports:
|
|
169
175
|
this._config.resolver.unstable_enablePackageExports,
|
|
176
|
+
unstable_getRealPath: this._config.resolver.unstable_enableSymlinks
|
|
177
|
+
? (path) => this._fileSystem.getRealPath(path)
|
|
178
|
+
: null,
|
|
170
179
|
});
|
|
171
180
|
}
|
|
172
181
|
_createModuleCache() {
|
|
@@ -186,14 +195,18 @@ class DependencyGraph extends EventEmitter {
|
|
|
186
195
|
const containerName =
|
|
187
196
|
splitIndex !== -1 ? filename.slice(0, splitIndex + 4) : filename;
|
|
188
197
|
|
|
189
|
-
//
|
|
198
|
+
// Prior to unstable_enableSymlinks:
|
|
199
|
+
// Calling realpath allows us to get a hash for a given path even when
|
|
190
200
|
// it's a symlink to a file, which prevents Metro from crashing in such a
|
|
191
201
|
// case. However, it doesn't allow Metro to track changes to the target file
|
|
192
202
|
// of the symlink. We should fix this by implementing a symlink map into
|
|
193
203
|
// Metro (or maybe by implementing those "extra transformation sources" we've
|
|
194
204
|
// been talking about for stuff like CSS or WASM).
|
|
195
|
-
|
|
196
|
-
|
|
205
|
+
//
|
|
206
|
+
// This is unnecessary with a symlink-aware fileSystem implementation.
|
|
207
|
+
const resolvedPath = this._config.resolver.unstable_enableSymlinks
|
|
208
|
+
? containerName
|
|
209
|
+
: fs.realpathSync(containerName);
|
|
197
210
|
const sha1 = this._fileSystem.getSha1(resolvedPath);
|
|
198
211
|
if (!sha1) {
|
|
199
212
|
throw new ReferenceError(`SHA-1 for file ${filename} (${resolvedPath}) is not computed.
|
|
@@ -224,7 +237,6 @@ class DependencyGraph extends EventEmitter {
|
|
|
224
237
|
assumeFlatNodeModules: false,
|
|
225
238
|
}
|
|
226
239
|
) {
|
|
227
|
-
var _JSON$stringify, _resolverOptions$cust;
|
|
228
240
|
const isSensitiveToOriginFolder =
|
|
229
241
|
// Resolution is always relative to the origin folder unless we assume a flat node_modules
|
|
230
242
|
!assumeFlatNodeModules ||
|
|
@@ -237,19 +249,13 @@ class DependencyGraph extends EventEmitter {
|
|
|
237
249
|
|
|
238
250
|
// Compound key for the resolver cache
|
|
239
251
|
const resolverOptionsKey =
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
null && _resolverOptions$cust !== void 0
|
|
243
|
-
? _resolverOptions$cust
|
|
244
|
-
: {},
|
|
252
|
+
JSON.stringify(
|
|
253
|
+
resolverOptions.customResolverOptions ?? {},
|
|
245
254
|
canonicalize
|
|
246
|
-
)
|
|
247
|
-
? _JSON$stringify
|
|
248
|
-
: "";
|
|
255
|
+
) ?? "";
|
|
249
256
|
const originKey = isSensitiveToOriginFolder ? path.dirname(from) : "";
|
|
250
257
|
const targetKey = to;
|
|
251
|
-
const platformKey =
|
|
252
|
-
platform !== null && platform !== void 0 ? platform : NULL_PLATFORM;
|
|
258
|
+
const platformKey = platform ?? NULL_PLATFORM;
|
|
253
259
|
|
|
254
260
|
// Traverse the resolver cache, which is a tree of maps
|
|
255
261
|
const mapByResolverOptions = this._resolutionCache;
|
|
@@ -53,7 +53,6 @@ function getOrCreateMap<T>(
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
class DependencyGraph extends EventEmitter {
|
|
56
|
-
_assetExtensions: Set<string>;
|
|
57
56
|
_config: ConfigT;
|
|
58
57
|
_haste: MetroFileMap;
|
|
59
58
|
_fileSystem: FileSystem;
|
|
@@ -89,9 +88,6 @@ class DependencyGraph extends EventEmitter {
|
|
|
89
88
|
super();
|
|
90
89
|
|
|
91
90
|
this._config = config;
|
|
92
|
-
this._assetExtensions = new Set(
|
|
93
|
-
config.resolver.assetExts.map(asset => '.' + asset),
|
|
94
|
-
);
|
|
95
91
|
|
|
96
92
|
const {hasReducedPerformance, watch} = options ?? {};
|
|
97
93
|
const initializingMetroLogEntry = log(
|
|
@@ -176,6 +172,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
176
172
|
|
|
177
173
|
_createModuleResolver() {
|
|
178
174
|
this._moduleResolver = new ModuleResolver({
|
|
175
|
+
assetExts: new Set(this._config.resolver.assetExts),
|
|
179
176
|
dirExists: (filePath: string) => {
|
|
180
177
|
try {
|
|
181
178
|
return fs.lstatSync(filePath).isDirectory();
|
|
@@ -191,20 +188,31 @@ class DependencyGraph extends EventEmitter {
|
|
|
191
188
|
this._hasteModuleMap.getModule(name, platform, true),
|
|
192
189
|
getHastePackagePath: (name, platform) =>
|
|
193
190
|
this._hasteModuleMap.getPackage(name, platform, true),
|
|
194
|
-
isAssetFile: file => this._assetExtensions.has(path.extname(file)),
|
|
195
191
|
mainFields: this._config.resolver.resolverMainFields,
|
|
196
192
|
moduleCache: this._moduleCache,
|
|
197
193
|
nodeModulesPaths: this._config.resolver.nodeModulesPaths,
|
|
198
194
|
preferNativePlatform: true,
|
|
199
195
|
projectRoot: this._config.projectRoot,
|
|
196
|
+
reporter: this._config.reporter,
|
|
200
197
|
resolveAsset: (dirPath: string, assetName: string, extension: string) => {
|
|
201
198
|
const basePath = dirPath + path.sep + assetName;
|
|
202
|
-
|
|
199
|
+
let assets = [
|
|
203
200
|
basePath + extension,
|
|
204
201
|
...this._config.resolver.assetResolutions.map(
|
|
205
202
|
resolution => basePath + '@' + resolution + 'x' + extension,
|
|
206
203
|
),
|
|
207
|
-
]
|
|
204
|
+
];
|
|
205
|
+
|
|
206
|
+
if (this._config.resolver.unstable_enableSymlinks) {
|
|
207
|
+
assets = assets
|
|
208
|
+
.map(candidate => this._fileSystem.getRealPath(candidate))
|
|
209
|
+
.filter(Boolean);
|
|
210
|
+
} else {
|
|
211
|
+
assets = assets.filter(candidate =>
|
|
212
|
+
this._fileSystem.exists(candidate),
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
208
216
|
return assets.length ? assets : null;
|
|
209
217
|
},
|
|
210
218
|
resolveRequest: this._config.resolver.resolveRequest,
|
|
@@ -214,6 +222,9 @@ class DependencyGraph extends EventEmitter {
|
|
|
214
222
|
this._config.resolver.unstable_conditionsByPlatform,
|
|
215
223
|
unstable_enablePackageExports:
|
|
216
224
|
this._config.resolver.unstable_enablePackageExports,
|
|
225
|
+
unstable_getRealPath: this._config.resolver.unstable_enableSymlinks
|
|
226
|
+
? path => this._fileSystem.getRealPath(path)
|
|
227
|
+
: null,
|
|
217
228
|
});
|
|
218
229
|
}
|
|
219
230
|
|
|
@@ -236,14 +247,19 @@ class DependencyGraph extends EventEmitter {
|
|
|
236
247
|
const containerName =
|
|
237
248
|
splitIndex !== -1 ? filename.slice(0, splitIndex + 4) : filename;
|
|
238
249
|
|
|
239
|
-
//
|
|
250
|
+
// Prior to unstable_enableSymlinks:
|
|
251
|
+
// Calling realpath allows us to get a hash for a given path even when
|
|
240
252
|
// it's a symlink to a file, which prevents Metro from crashing in such a
|
|
241
253
|
// case. However, it doesn't allow Metro to track changes to the target file
|
|
242
254
|
// of the symlink. We should fix this by implementing a symlink map into
|
|
243
255
|
// Metro (or maybe by implementing those "extra transformation sources" we've
|
|
244
256
|
// been talking about for stuff like CSS or WASM).
|
|
257
|
+
//
|
|
258
|
+
// This is unnecessary with a symlink-aware fileSystem implementation.
|
|
259
|
+
const resolvedPath = this._config.resolver.unstable_enableSymlinks
|
|
260
|
+
? containerName
|
|
261
|
+
: fs.realpathSync(containerName);
|
|
245
262
|
|
|
246
|
-
const resolvedPath = fs.realpathSync(containerName);
|
|
247
263
|
const sha1 = this._fileSystem.getSha1(resolvedPath);
|
|
248
264
|
|
|
249
265
|
if (!sha1) {
|
package/src/node-haste/Module.js
CHANGED
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
|
15
|
+
function _interopRequireDefault(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
17
|
+
}
|
|
15
18
|
class Module {
|
|
16
|
-
// $FlowFixMe[missing-local-annot]
|
|
17
19
|
constructor(file, moduleCache) {
|
|
18
|
-
if (!
|
|
20
|
+
if (!_path.default.isAbsolute(file)) {
|
|
19
21
|
throw new Error("Expected file to be absolute path but got " + file);
|
|
20
22
|
}
|
|
21
23
|
this.path = file;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import type ModuleCache from './ModuleCache';
|
|
15
15
|
import type Package from './Package';
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
import path from 'path';
|
|
18
18
|
|
|
19
19
|
class Module {
|
|
20
20
|
path: string;
|
|
@@ -22,9 +22,8 @@ class Module {
|
|
|
22
22
|
_moduleCache: ModuleCache;
|
|
23
23
|
_sourceCode: ?string;
|
|
24
24
|
|
|
25
|
-
// $FlowFixMe[missing-local-annot]
|
|
26
25
|
constructor(file: string, moduleCache: ModuleCache) {
|
|
27
|
-
if (!
|
|
26
|
+
if (!path.isAbsolute(file)) {
|
|
28
27
|
throw new Error('Expected file to be absolute path but got ' + file);
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -43,7 +43,6 @@ class ModuleCache {
|
|
|
43
43
|
return this.getPackageOf(module.path);
|
|
44
44
|
}
|
|
45
45
|
getPackageOf(modulePath) {
|
|
46
|
-
var _this$_modulePathsByP;
|
|
47
46
|
let packagePath = this._packagePathByModulePath[modulePath];
|
|
48
47
|
if (packagePath && this._packageCache[packagePath]) {
|
|
49
48
|
return this._packageCache[packagePath];
|
|
@@ -54,10 +53,7 @@ class ModuleCache {
|
|
|
54
53
|
}
|
|
55
54
|
this._packagePathByModulePath[modulePath] = packagePath;
|
|
56
55
|
const modulePaths =
|
|
57
|
-
|
|
58
|
-
null && _this$_modulePathsByP !== void 0
|
|
59
|
-
? _this$_modulePathsByP
|
|
60
|
-
: new Set();
|
|
56
|
+
this._modulePathsByPackagePath[packagePath] ?? new Set();
|
|
61
57
|
modulePaths.add(modulePath);
|
|
62
58
|
this._modulePathsByPackagePath[packagePath] = modulePaths;
|
|
63
59
|
return this.getPackage(packagePath);
|