metro 0.84.2 → 0.84.4
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 +15 -16
- package/src/Assets.js +20 -13
- package/src/Assets.js.flow +20 -13
- package/src/Bundler/util.js.flow +3 -3
- package/src/DeltaBundler/DeltaCalculator.d.ts +1 -11
- package/src/DeltaBundler/DeltaCalculator.js +55 -46
- package/src/DeltaBundler/DeltaCalculator.js.flow +72 -61
- package/src/DeltaBundler/getTransformCacheKey.js +3 -1
- package/src/DeltaBundler/getTransformCacheKey.js.flow +7 -2
- package/src/HmrServer.d.ts +15 -3
- package/src/HmrServer.js +7 -0
- package/src/HmrServer.js.flow +15 -5
- package/src/ModuleGraph/worker/collectDependencies.js +52 -0
- package/src/ModuleGraph/worker/collectDependencies.js.flow +67 -0
- package/src/Server.d.ts +4 -1
- package/src/Server.js +42 -5
- package/src/Server.js.flow +45 -5
- package/src/index.d.ts +22 -3
- package/src/index.flow.js +2 -2
- package/src/index.flow.js.flow +23 -4
- package/src/lib/JsonReporter.js.flow +2 -2
- package/src/lib/TerminalReporter.js +39 -41
- package/src/lib/TerminalReporter.js.flow +51 -32
- package/src/lib/getAppendScripts.js.flow +2 -2
- package/src/lib/logToConsole.js +8 -7
- package/src/lib/logToConsole.js.flow +7 -7
- package/src/lib/reporting.js +16 -7
- package/src/lib/reporting.js.flow +16 -5
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +9 -22
- package/src/node-haste/DependencyGraph/ModuleResolution.js +4 -22
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +10 -59
- package/src/node-haste/DependencyGraph/createFileMap.js +1 -2
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +4 -3
- package/src/node-haste/DependencyGraph.d.ts +2 -5
- package/src/node-haste/DependencyGraph.js +22 -11
- package/src/node-haste/DependencyGraph.js.flow +24 -13
- package/src/node-haste/PackageCache.d.ts +12 -16
- package/src/node-haste/PackageCache.js +65 -54
- package/src/node-haste/PackageCache.js.flow +103 -79
- package/src/node-haste/Package.d.ts +0 -28
- package/src/node-haste/Package.js +0 -28
- package/src/node-haste/Package.js.flow +0 -39
|
@@ -12,15 +12,22 @@
|
|
|
12
12
|
import type {BundleDetails, ReportableEvent} from './reporting';
|
|
13
13
|
import type {Terminal} from 'metro-core';
|
|
14
14
|
import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
|
|
15
|
+
import type {BackgroundColors, ForegroundColors, Modifiers} from 'util';
|
|
15
16
|
|
|
16
17
|
import {calculateBundleProgressRatio} from './bundleProgressUtils';
|
|
17
18
|
import logToConsole from './logToConsole';
|
|
18
19
|
import * as reporting from './reporting';
|
|
19
|
-
import chalk from 'chalk';
|
|
20
20
|
// $FlowFixMe[untyped-import] lodash.throttle
|
|
21
21
|
import throttle from 'lodash.throttle';
|
|
22
22
|
import {AmbiguousModuleResolutionError} from 'metro-core';
|
|
23
23
|
import path from 'path';
|
|
24
|
+
import util from 'util';
|
|
25
|
+
|
|
26
|
+
type StyleFormat = ReadonlyArray<
|
|
27
|
+
ForegroundColors | BackgroundColors | Modifiers,
|
|
28
|
+
>;
|
|
29
|
+
const style = (format: StyleFormat, text: string): string =>
|
|
30
|
+
util.styleText(format, text);
|
|
24
31
|
|
|
25
32
|
type BundleProgress = {
|
|
26
33
|
bundleDetails: BundleDetails,
|
|
@@ -121,28 +128,26 @@ export default class TerminalReporter {
|
|
|
121
128
|
): string {
|
|
122
129
|
const localPath = path.relative('.', entryFile);
|
|
123
130
|
const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
|
|
124
|
-
const bundleTypeColor =
|
|
125
|
-
phase === 'done'
|
|
126
|
-
? chalk.green
|
|
127
|
-
: phase === 'failed'
|
|
128
|
-
? chalk.red
|
|
129
|
-
: chalk.yellow;
|
|
131
|
+
const bundleTypeColor: StyleFormat =
|
|
132
|
+
phase === 'done' ? ['green'] : phase === 'failed' ? ['red'] : ['yellow'];
|
|
130
133
|
const progress =
|
|
131
134
|
phase === 'in_progress'
|
|
132
|
-
?
|
|
133
|
-
|
|
135
|
+
? style(['green', 'bgGreen'], DARK_BLOCK_CHAR.repeat(filledBar)) +
|
|
136
|
+
style(
|
|
137
|
+
['bgWhite', 'white'],
|
|
134
138
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
135
139
|
) +
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
style(['bold'], ` ${Math.floor(100 * ratio)}% `) +
|
|
141
|
+
style(['dim'], `(${transformedFileCount}/${totalFileCount})`)
|
|
138
142
|
: '';
|
|
139
143
|
|
|
140
144
|
return (
|
|
141
|
-
|
|
145
|
+
style(
|
|
146
|
+
[...bundleTypeColor, 'inverse', 'bold'],
|
|
142
147
|
` ${isPrefetch === true ? 'PREBUNDLE' : bundleType.toUpperCase()} `,
|
|
143
148
|
) +
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
style(['reset', 'dim'], ` ${path.dirname(localPath)}/`) +
|
|
150
|
+
style(['bold'], path.basename(localPath)) +
|
|
146
151
|
' ' +
|
|
147
152
|
progress
|
|
148
153
|
);
|
|
@@ -191,31 +196,37 @@ export default class TerminalReporter {
|
|
|
191
196
|
'',
|
|
192
197
|
];
|
|
193
198
|
|
|
194
|
-
const color = hasReducedPerformance ?
|
|
195
|
-
this.terminal.log(color
|
|
199
|
+
const color: StyleFormat = hasReducedPerformance ? ['red'] : ['blue'];
|
|
200
|
+
this.terminal.log(style(color, logo.join('\n')));
|
|
196
201
|
}
|
|
197
202
|
|
|
198
203
|
_logInitializingFailed(port: number, error: SnippetError): void {
|
|
199
204
|
if (error.code === 'EADDRINUSE') {
|
|
200
205
|
this.terminal.log(
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
style(['bgRed', 'bold'], ' ERROR '),
|
|
207
|
+
style(
|
|
208
|
+
['red'],
|
|
209
|
+
`Metro can't listen on port ${style(['bold'], String(port))}`,
|
|
210
|
+
),
|
|
203
211
|
);
|
|
204
212
|
this.terminal.log(
|
|
205
213
|
'Most likely another process is already using this port',
|
|
206
214
|
);
|
|
207
215
|
this.terminal.log('Run the following command to find out which process:');
|
|
208
|
-
this.terminal.log('\n ',
|
|
216
|
+
this.terminal.log('\n ', style(['bold'], 'lsof -i :' + port), '\n');
|
|
209
217
|
this.terminal.log('Then, you can either shut down the other process:');
|
|
210
|
-
this.terminal.log('\n ',
|
|
218
|
+
this.terminal.log('\n ', style(['bold'], 'kill -9 <PID>'), '\n');
|
|
211
219
|
this.terminal.log('or run Metro on different port.');
|
|
212
220
|
} else {
|
|
213
|
-
this.terminal.log(
|
|
221
|
+
this.terminal.log(
|
|
222
|
+
style(['bgRed', 'bold'], ' ERROR '),
|
|
223
|
+
style(['red'], error.message),
|
|
224
|
+
);
|
|
214
225
|
const errorAttributes = JSON.stringify(error);
|
|
215
226
|
if (errorAttributes !== '{}') {
|
|
216
|
-
this.terminal.log(
|
|
227
|
+
this.terminal.log(style(['red'], errorAttributes));
|
|
217
228
|
}
|
|
218
|
-
this.terminal.log(
|
|
229
|
+
this.terminal.log(style(['red'], String(error.stack)));
|
|
219
230
|
}
|
|
220
231
|
}
|
|
221
232
|
|
|
@@ -271,20 +282,26 @@ export default class TerminalReporter {
|
|
|
271
282
|
logFn(this.terminal, String(format), ...args);
|
|
272
283
|
break;
|
|
273
284
|
case 'dep_graph_loading':
|
|
274
|
-
const color = event.hasReducedPerformance
|
|
285
|
+
const color: StyleFormat = event.hasReducedPerformance
|
|
286
|
+
? ['red']
|
|
287
|
+
: ['blue'];
|
|
275
288
|
// eslint-disable-next-line import/no-commonjs
|
|
276
289
|
// $FlowFixMe[untyped-import] package.json
|
|
277
290
|
const version = 'v' + require('../../package.json').version;
|
|
278
291
|
this.terminal.log(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
'
|
|
282
|
-
|
|
292
|
+
style(
|
|
293
|
+
[...color, 'bold'],
|
|
294
|
+
' '.repeat(19 - version.length / 2) +
|
|
295
|
+
' Welcome to Metro ' +
|
|
296
|
+
style(['white'], version) +
|
|
297
|
+
'\n',
|
|
298
|
+
) + style(['dim'], ' Fast - Scalable - Integrated\n\n'),
|
|
283
299
|
);
|
|
284
300
|
|
|
285
301
|
if (event.hasReducedPerformance) {
|
|
286
302
|
this.terminal.log(
|
|
287
|
-
|
|
303
|
+
style(
|
|
304
|
+
['red'],
|
|
288
305
|
'Metro is operating with reduced performance.\n' +
|
|
289
306
|
'Please fix the problem above and restart Metro.\n\n',
|
|
290
307
|
),
|
|
@@ -459,7 +476,7 @@ export default class TerminalReporter {
|
|
|
459
476
|
// Only report success after a prior failure.
|
|
460
477
|
if (this._prevHealthCheckResult) {
|
|
461
478
|
this.terminal.log(
|
|
462
|
-
|
|
479
|
+
style(['green'], `Watcher ${watcherName} is now healthy.`),
|
|
463
480
|
);
|
|
464
481
|
}
|
|
465
482
|
break;
|
|
@@ -499,7 +516,8 @@ export default class TerminalReporter {
|
|
|
499
516
|
break;
|
|
500
517
|
case 'watchman_slow_command':
|
|
501
518
|
this.terminal.log(
|
|
502
|
-
|
|
519
|
+
style(
|
|
520
|
+
['dim'],
|
|
503
521
|
`Waiting for Watchman \`${status.command}\` (${Math.round(
|
|
504
522
|
status.timeElapsed / 1000,
|
|
505
523
|
)}s)...`,
|
|
@@ -508,7 +526,8 @@ export default class TerminalReporter {
|
|
|
508
526
|
break;
|
|
509
527
|
case 'watchman_slow_command_complete':
|
|
510
528
|
this.terminal.log(
|
|
511
|
-
|
|
529
|
+
style(
|
|
530
|
+
['green'],
|
|
512
531
|
`Watchman \`${status.command}\` finished after ${(
|
|
513
532
|
status.timeElapsed / 1000
|
|
514
533
|
).toFixed(1)}s.`,
|
|
@@ -18,7 +18,7 @@ import CountingSet from './CountingSet';
|
|
|
18
18
|
import countLines from './countLines';
|
|
19
19
|
import nullthrows from 'nullthrows';
|
|
20
20
|
|
|
21
|
-
type Options<T
|
|
21
|
+
type Options<T extends number | string> = Readonly<{
|
|
22
22
|
asyncRequireModulePath: string,
|
|
23
23
|
createModuleId: string => T,
|
|
24
24
|
getRunModuleStatement: (moduleId: T, globalPrefix: string) => string,
|
|
@@ -33,7 +33,7 @@ type Options<T: number | string> = Readonly<{
|
|
|
33
33
|
...
|
|
34
34
|
}>;
|
|
35
35
|
|
|
36
|
-
export default function getAppendScripts<T
|
|
36
|
+
export default function getAppendScripts<T extends number | string>(
|
|
37
37
|
entryPoint: string,
|
|
38
38
|
modules: ReadonlyArray<Module<>>,
|
|
39
39
|
options: Options<T>,
|
package/src/lib/logToConsole.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
8
7
|
var _util = _interopRequireDefault(require("util"));
|
|
9
8
|
function _interopRequireDefault(e) {
|
|
10
9
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -15,10 +14,10 @@ var _default = (terminal, level, ...data) => {
|
|
|
15
14
|
const logFunction = console[level] && level !== "trace" ? level : "log";
|
|
16
15
|
const color =
|
|
17
16
|
level === "error"
|
|
18
|
-
?
|
|
17
|
+
? ["inverse", "red"]
|
|
19
18
|
: level === "warn"
|
|
20
|
-
?
|
|
21
|
-
:
|
|
19
|
+
? ["inverse", "yellow"]
|
|
20
|
+
: ["inverse", "white"];
|
|
22
21
|
if (level === "group") {
|
|
23
22
|
groupStack.push(level);
|
|
24
23
|
} else if (level === "groupCollapsed") {
|
|
@@ -27,7 +26,7 @@ var _default = (terminal, level, ...data) => {
|
|
|
27
26
|
collapsedGuardTimer = setTimeout(() => {
|
|
28
27
|
if (groupStack.includes("groupCollapsed")) {
|
|
29
28
|
terminal.log(
|
|
30
|
-
|
|
29
|
+
_util.default.styleText(["inverse", "yellow", "bold"], " WARN "),
|
|
31
30
|
"Expected `console.groupEnd` to be called after `console.groupCollapsed`.",
|
|
32
31
|
);
|
|
33
32
|
groupStack.length = 0;
|
|
@@ -47,8 +46,10 @@ var _default = (terminal, level, ...data) => {
|
|
|
47
46
|
data[data.length - 1] = lastItem.trimEnd();
|
|
48
47
|
}
|
|
49
48
|
terminal.log(
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
_util.default.styleText(
|
|
50
|
+
[...color, "bold"],
|
|
51
|
+
` ${logFunction.toUpperCase()} `,
|
|
52
|
+
) + "".padEnd(groupStack.length * 2, " "),
|
|
52
53
|
_util.default.format(...data),
|
|
53
54
|
);
|
|
54
55
|
}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
/* eslint-disable no-console */
|
|
12
12
|
|
|
13
13
|
import type {Terminal} from 'metro-core';
|
|
14
|
+
import type {BackgroundColors, ForegroundColors, Modifiers} from 'util';
|
|
14
15
|
|
|
15
|
-
import chalk from 'chalk';
|
|
16
16
|
import util from 'util';
|
|
17
17
|
|
|
18
18
|
const groupStack = [];
|
|
@@ -21,12 +21,12 @@ let collapsedGuardTimer;
|
|
|
21
21
|
export default (terminal: Terminal, level: string, ...data: Array<unknown>) => {
|
|
22
22
|
// $FlowFixMe[invalid-computed-prop]
|
|
23
23
|
const logFunction = console[level] && level !== 'trace' ? level : 'log';
|
|
24
|
-
const color =
|
|
24
|
+
const color: ReadonlyArray<ForegroundColors | BackgroundColors | Modifiers> =
|
|
25
25
|
level === 'error'
|
|
26
|
-
?
|
|
26
|
+
? ['inverse', 'red']
|
|
27
27
|
: level === 'warn'
|
|
28
|
-
?
|
|
29
|
-
:
|
|
28
|
+
? ['inverse', 'yellow']
|
|
29
|
+
: ['inverse', 'white'];
|
|
30
30
|
|
|
31
31
|
if (level === 'group') {
|
|
32
32
|
groupStack.push(level);
|
|
@@ -37,7 +37,7 @@ export default (terminal: Terminal, level: string, ...data: Array<unknown>) => {
|
|
|
37
37
|
collapsedGuardTimer = setTimeout(() => {
|
|
38
38
|
if (groupStack.includes('groupCollapsed')) {
|
|
39
39
|
terminal.log(
|
|
40
|
-
|
|
40
|
+
util.styleText(['inverse', 'yellow', 'bold'], ' WARN '),
|
|
41
41
|
'Expected `console.groupEnd` to be called after `console.groupCollapsed`.',
|
|
42
42
|
);
|
|
43
43
|
groupStack.length = 0;
|
|
@@ -60,7 +60,7 @@ export default (terminal: Terminal, level: string, ...data: Array<unknown>) => {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
terminal.log(
|
|
63
|
-
color
|
|
63
|
+
util.styleText([...color, 'bold'], ` ${logFunction.toUpperCase()} `) +
|
|
64
64
|
''.padEnd(groupStack.length * 2, ' '),
|
|
65
65
|
// `util.format` actually accepts any arguments.
|
|
66
66
|
// If the first argument is a string, it tries to format it.
|
package/src/lib/reporting.js
CHANGED
|
@@ -7,30 +7,39 @@ exports.logError = logError;
|
|
|
7
7
|
exports.logInfo = logInfo;
|
|
8
8
|
exports.logWarning = logWarning;
|
|
9
9
|
exports.nullReporter = void 0;
|
|
10
|
-
var
|
|
10
|
+
var _tty = _interopRequireDefault(require("tty"));
|
|
11
11
|
var _util = _interopRequireDefault(require("util"));
|
|
12
12
|
function _interopRequireDefault(e) {
|
|
13
13
|
return e && e.__esModule ? e : { default: e };
|
|
14
14
|
}
|
|
15
|
+
const supportsColor = () =>
|
|
16
|
+
process.stdout instanceof _tty.default.WriteStream &&
|
|
17
|
+
process.stdout.hasColors();
|
|
15
18
|
function logWarning(terminal, format, ...args) {
|
|
16
19
|
const str = _util.default.format(format, ...args);
|
|
17
|
-
terminal.log(
|
|
20
|
+
terminal.log(
|
|
21
|
+
"%s %s",
|
|
22
|
+
_util.default.styleText(["yellow", "inverse", "bold"], " WARN "),
|
|
23
|
+
str,
|
|
24
|
+
);
|
|
18
25
|
}
|
|
19
26
|
function logError(terminal, format, ...args) {
|
|
20
27
|
terminal.log(
|
|
21
28
|
"%s %s",
|
|
22
|
-
|
|
29
|
+
_util.default.styleText(["red", "inverse", "bold"], " ERROR "),
|
|
23
30
|
_util.default.format(
|
|
24
|
-
|
|
25
|
-
? format
|
|
26
|
-
: _util.default.stripVTControlCharacters(format),
|
|
31
|
+
supportsColor() ? format : _util.default.stripVTControlCharacters(format),
|
|
27
32
|
...args,
|
|
28
33
|
),
|
|
29
34
|
);
|
|
30
35
|
}
|
|
31
36
|
function logInfo(terminal, format, ...args) {
|
|
32
37
|
const str = _util.default.format(format, ...args);
|
|
33
|
-
terminal.log(
|
|
38
|
+
terminal.log(
|
|
39
|
+
"%s %s",
|
|
40
|
+
_util.default.styleText(["cyan", "inverse", "bold"], " INFO "),
|
|
41
|
+
str,
|
|
42
|
+
);
|
|
34
43
|
}
|
|
35
44
|
const nullReporter = (exports.nullReporter = {
|
|
36
45
|
update() {},
|
|
@@ -14,9 +14,12 @@ import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
|
|
|
14
14
|
import type {CustomResolverOptions} from 'metro-resolver';
|
|
15
15
|
import type {CustomTransformOptions} from 'metro-transform-worker';
|
|
16
16
|
|
|
17
|
-
import
|
|
17
|
+
import tty from 'tty';
|
|
18
18
|
import util from 'util';
|
|
19
19
|
|
|
20
|
+
const supportsColor = (): boolean =>
|
|
21
|
+
process.stdout instanceof tty.WriteStream && process.stdout.hasColors();
|
|
22
|
+
|
|
20
23
|
export type BundleDetails = {
|
|
21
24
|
bundleType: string,
|
|
22
25
|
customResolverOptions: CustomResolverOptions,
|
|
@@ -190,7 +193,11 @@ export function logWarning(
|
|
|
190
193
|
...args: Array<unknown>
|
|
191
194
|
): void {
|
|
192
195
|
const str = util.format(format, ...args);
|
|
193
|
-
terminal.log(
|
|
196
|
+
terminal.log(
|
|
197
|
+
'%s %s',
|
|
198
|
+
util.styleText(['yellow', 'inverse', 'bold'], ' WARN '),
|
|
199
|
+
str,
|
|
200
|
+
);
|
|
194
201
|
}
|
|
195
202
|
|
|
196
203
|
/**
|
|
@@ -203,13 +210,13 @@ export function logError(
|
|
|
203
210
|
): void {
|
|
204
211
|
terminal.log(
|
|
205
212
|
'%s %s',
|
|
206
|
-
|
|
213
|
+
util.styleText(['red', 'inverse', 'bold'], ' ERROR '),
|
|
207
214
|
// Syntax errors may have colors applied for displaying code frames
|
|
208
215
|
// in various places outside of where Metro is currently running.
|
|
209
216
|
// If the current terminal does not support color, we'll strip the colors
|
|
210
217
|
// here.
|
|
211
218
|
util.format(
|
|
212
|
-
|
|
219
|
+
supportsColor() ? format : util.stripVTControlCharacters(format),
|
|
213
220
|
...args,
|
|
214
221
|
),
|
|
215
222
|
);
|
|
@@ -224,7 +231,11 @@ export function logInfo(
|
|
|
224
231
|
...args: Array<unknown>
|
|
225
232
|
): void {
|
|
226
233
|
const str = util.format(format, ...args);
|
|
227
|
-
terminal.log(
|
|
234
|
+
terminal.log(
|
|
235
|
+
'%s %s',
|
|
236
|
+
util.styleText(['cyan', 'inverse', 'bold'], ' INFO '),
|
|
237
|
+
str,
|
|
238
|
+
);
|
|
228
239
|
}
|
|
229
240
|
|
|
230
241
|
/**
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
-
* @generated SignedSource<<
|
|
9
|
+
* @generated SignedSource<<0024fd05b95efe19a24f9acc84ff474b>>
|
|
10
10
|
*
|
|
11
11
|
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
12
|
* Original file: packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js
|
|
@@ -32,19 +32,7 @@ import type {
|
|
|
32
32
|
import type {PackageForModule, PackageJson} from 'metro-resolver/private/types';
|
|
33
33
|
|
|
34
34
|
export type DirExistsFn = (filePath: string) => boolean;
|
|
35
|
-
|
|
36
|
-
export type Moduleish = {readonly path: string};
|
|
37
|
-
export type PackageishCache<TPackage> = {
|
|
38
|
-
getPackage(
|
|
39
|
-
name: string,
|
|
40
|
-
platform?: string,
|
|
41
|
-
supportsNativePlatform?: boolean,
|
|
42
|
-
): TPackage;
|
|
43
|
-
getPackageOf(
|
|
44
|
-
absolutePath: string,
|
|
45
|
-
): null | undefined | {pkg: TPackage; packageRelativePath: string};
|
|
46
|
-
};
|
|
47
|
-
type Options<TPackage> = Readonly<{
|
|
35
|
+
type Options = Readonly<{
|
|
48
36
|
assetExts: ReadonlySet<string>;
|
|
49
37
|
dirExists: DirExistsFn;
|
|
50
38
|
disableHierarchicalLookup: boolean;
|
|
@@ -61,7 +49,10 @@ type Options<TPackage> = Readonly<{
|
|
|
61
49
|
platform: null | undefined | string,
|
|
62
50
|
) => null | undefined | string;
|
|
63
51
|
mainFields: ReadonlyArray<string>;
|
|
64
|
-
|
|
52
|
+
getPackage: (packageJsonPath: string) => null | undefined | PackageJson;
|
|
53
|
+
getPackageForModule: (
|
|
54
|
+
absolutePath: string,
|
|
55
|
+
) => null | undefined | PackageForModule;
|
|
65
56
|
nodeModulesPaths: ReadonlyArray<string>;
|
|
66
57
|
preferNativePlatform: boolean;
|
|
67
58
|
projectRoot: string;
|
|
@@ -76,11 +67,11 @@ type Options<TPackage> = Readonly<{
|
|
|
76
67
|
unstable_enablePackageExports: boolean;
|
|
77
68
|
unstable_incrementalResolution: boolean;
|
|
78
69
|
}>;
|
|
79
|
-
export declare class ModuleResolver
|
|
80
|
-
_options: Options
|
|
70
|
+
export declare class ModuleResolver {
|
|
71
|
+
_options: Options;
|
|
81
72
|
_projectRootFakeModulePath: string;
|
|
82
73
|
_cachedEmptyModule: null | undefined | BundlerResolution;
|
|
83
|
-
constructor(options: Options
|
|
74
|
+
constructor(options: Options);
|
|
84
75
|
_getEmptyModule(): BundlerResolution;
|
|
85
76
|
resolveDependency(
|
|
86
77
|
originModulePath: string,
|
|
@@ -89,10 +80,6 @@ export declare class ModuleResolver<TPackage extends Packageish> {
|
|
|
89
80
|
platform: string | null,
|
|
90
81
|
resolverOptions: ResolverInputOptions,
|
|
91
82
|
): BundlerResolution;
|
|
92
|
-
_getPackage: (packageJsonPath: string) => null | undefined | PackageJson;
|
|
93
|
-
_getPackageForModule: (
|
|
94
|
-
absolutePath: string,
|
|
95
|
-
) => null | undefined | PackageForModule;
|
|
96
83
|
/**
|
|
97
84
|
* TODO: Return Resolution instead of coercing to BundlerResolution here
|
|
98
85
|
*/
|
|
@@ -86,6 +86,8 @@ class ModuleResolver {
|
|
|
86
86
|
doesFileExist,
|
|
87
87
|
extraNodeModules,
|
|
88
88
|
fileSystemLookup,
|
|
89
|
+
getPackage,
|
|
90
|
+
getPackageForModule,
|
|
89
91
|
mainFields,
|
|
90
92
|
nodeModulesPaths,
|
|
91
93
|
preferNativePlatform,
|
|
@@ -109,9 +111,8 @@ class ModuleResolver {
|
|
|
109
111
|
doesFileExist,
|
|
110
112
|
extraNodeModules,
|
|
111
113
|
fileSystemLookup,
|
|
112
|
-
getPackage
|
|
113
|
-
getPackageForModule
|
|
114
|
-
this._getPackageForModule(absoluteModulePath),
|
|
114
|
+
getPackage,
|
|
115
|
+
getPackageForModule,
|
|
115
116
|
isESMImport: dependency.data.isESMImport,
|
|
116
117
|
mainFields,
|
|
117
118
|
nodeModulesPaths,
|
|
@@ -191,25 +192,6 @@ class ModuleResolver {
|
|
|
191
192
|
throw error;
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
|
-
_getPackage = (packageJsonPath) => {
|
|
195
|
-
try {
|
|
196
|
-
return this._options.packageCache.getPackage(packageJsonPath).read();
|
|
197
|
-
} catch (e) {}
|
|
198
|
-
return null;
|
|
199
|
-
};
|
|
200
|
-
_getPackageForModule = (absolutePath) => {
|
|
201
|
-
let result;
|
|
202
|
-
try {
|
|
203
|
-
result = this._options.packageCache.getPackageOf(absolutePath);
|
|
204
|
-
} catch (e) {}
|
|
205
|
-
return result != null
|
|
206
|
-
? {
|
|
207
|
-
packageJson: result.pkg.read(),
|
|
208
|
-
packageRelativePath: result.packageRelativePath,
|
|
209
|
-
rootPath: _path.default.dirname(result.pkg.path),
|
|
210
|
-
}
|
|
211
|
-
: null;
|
|
212
|
-
};
|
|
213
195
|
_getFileResolvedModule(resolution) {
|
|
214
196
|
switch (resolution.type) {
|
|
215
197
|
case "sourceFile":
|
|
@@ -35,28 +35,7 @@ import util from 'util';
|
|
|
35
35
|
|
|
36
36
|
export type DirExistsFn = (filePath: string) => boolean;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
path: string,
|
|
40
|
-
read(): PackageJson,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type Moduleish = interface {
|
|
44
|
-
+path: string,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type PackageishCache<TPackage> = interface {
|
|
48
|
-
getPackage(
|
|
49
|
-
name: string,
|
|
50
|
-
platform?: string,
|
|
51
|
-
supportsNativePlatform?: boolean,
|
|
52
|
-
): TPackage,
|
|
53
|
-
getPackageOf(absolutePath: string): ?{
|
|
54
|
-
pkg: TPackage,
|
|
55
|
-
packageRelativePath: string,
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
type Options<TPackage> = Readonly<{
|
|
38
|
+
type Options = Readonly<{
|
|
60
39
|
assetExts: ReadonlySet<string>,
|
|
61
40
|
dirExists: DirExistsFn,
|
|
62
41
|
disableHierarchicalLookup: boolean,
|
|
@@ -67,7 +46,8 @@ type Options<TPackage> = Readonly<{
|
|
|
67
46
|
getHasteModulePath: (name: string, platform: ?string) => ?string,
|
|
68
47
|
getHastePackagePath: (name: string, platform: ?string) => ?string,
|
|
69
48
|
mainFields: ReadonlyArray<string>,
|
|
70
|
-
|
|
49
|
+
getPackage: (packageJsonPath: string) => ?PackageJson,
|
|
50
|
+
getPackageForModule: (absolutePath: string) => ?PackageForModule,
|
|
71
51
|
nodeModulesPaths: ReadonlyArray<string>,
|
|
72
52
|
preferNativePlatform: boolean,
|
|
73
53
|
projectRoot: string,
|
|
@@ -83,14 +63,14 @@ type Options<TPackage> = Readonly<{
|
|
|
83
63
|
unstable_incrementalResolution: boolean,
|
|
84
64
|
}>;
|
|
85
65
|
|
|
86
|
-
export class ModuleResolver
|
|
87
|
-
_options: Options
|
|
66
|
+
export class ModuleResolver {
|
|
67
|
+
_options: Options;
|
|
88
68
|
// A module representing the project root, used as the origin when resolving `emptyModulePath`.
|
|
89
69
|
_projectRootFakeModulePath: string;
|
|
90
70
|
// An empty module, the result of resolving `emptyModulePath` from the project root.
|
|
91
71
|
_cachedEmptyModule: ?BundlerResolution;
|
|
92
72
|
|
|
93
|
-
constructor(options: Options
|
|
73
|
+
constructor(options: Options) {
|
|
94
74
|
this._options = options;
|
|
95
75
|
const {projectRoot} = this._options;
|
|
96
76
|
this._projectRootFakeModulePath = path.join(projectRoot, '_');
|
|
@@ -132,6 +112,8 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
132
112
|
doesFileExist,
|
|
133
113
|
extraNodeModules,
|
|
134
114
|
fileSystemLookup,
|
|
115
|
+
getPackage,
|
|
116
|
+
getPackageForModule,
|
|
135
117
|
mainFields,
|
|
136
118
|
nodeModulesPaths,
|
|
137
119
|
preferNativePlatform,
|
|
@@ -156,9 +138,8 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
156
138
|
doesFileExist,
|
|
157
139
|
extraNodeModules,
|
|
158
140
|
fileSystemLookup,
|
|
159
|
-
getPackage
|
|
160
|
-
getPackageForModule
|
|
161
|
-
this._getPackageForModule(absoluteModulePath),
|
|
141
|
+
getPackage,
|
|
142
|
+
getPackageForModule,
|
|
162
143
|
isESMImport: dependency.data.isESMImport,
|
|
163
144
|
mainFields,
|
|
164
145
|
nodeModulesPaths,
|
|
@@ -240,36 +221,6 @@ export class ModuleResolver<TPackage: Packageish> {
|
|
|
240
221
|
}
|
|
241
222
|
}
|
|
242
223
|
|
|
243
|
-
_getPackage = (packageJsonPath: string): ?PackageJson => {
|
|
244
|
-
try {
|
|
245
|
-
return this._options.packageCache.getPackage(packageJsonPath).read();
|
|
246
|
-
} catch (e) {
|
|
247
|
-
// Do nothing. The standard module cache does not trigger any error, but
|
|
248
|
-
// the ModuleGraph one does, if the module does not exist.
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return null;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
_getPackageForModule = (absolutePath: string): ?PackageForModule => {
|
|
255
|
-
let result;
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
result = this._options.packageCache.getPackageOf(absolutePath);
|
|
259
|
-
} catch (e) {
|
|
260
|
-
// Do nothing. The standard module cache does not trigger any error, but
|
|
261
|
-
// the ModuleGraph one does, if the module does not exist.
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return result != null
|
|
265
|
-
? {
|
|
266
|
-
packageJson: result.pkg.read(),
|
|
267
|
-
packageRelativePath: result.packageRelativePath,
|
|
268
|
-
rootPath: path.dirname(result.pkg.path),
|
|
269
|
-
}
|
|
270
|
-
: null;
|
|
271
|
-
};
|
|
272
|
-
|
|
273
224
|
/**
|
|
274
225
|
* TODO: Return Resolution instead of coercing to BundlerResolution here
|
|
275
226
|
*/
|
|
@@ -71,7 +71,7 @@ function createFileMap(config, options) {
|
|
|
71
71
|
const { enabled: autoSaveEnabled, ...autoSaveOpts } =
|
|
72
72
|
config.watcher.unstable_autoSaveCache ?? {};
|
|
73
73
|
const autoSave = watch && autoSaveEnabled ? autoSaveOpts : false;
|
|
74
|
-
const plugins = [];
|
|
74
|
+
const plugins = [...(config.unstable_fileMapPlugins ?? [])];
|
|
75
75
|
let dependencyPlugin = null;
|
|
76
76
|
if (
|
|
77
77
|
config.resolver.dependencyExtractor != null &&
|
|
@@ -80,7 +80,6 @@ function createFileMap(config, options) {
|
|
|
80
80
|
dependencyPlugin = new _metroFileMap.DependencyPlugin({
|
|
81
81
|
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
82
82
|
computeDependencies: true,
|
|
83
|
-
rootDir: config.projectRoot,
|
|
84
83
|
});
|
|
85
84
|
plugins.push(dependencyPlugin);
|
|
86
85
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type {ConfigT} from 'metro-config';
|
|
13
|
-
import type {HasteMap} from 'metro-file-map';
|
|
13
|
+
import type {HasteMap, InputFileMapPlugin} from 'metro-file-map';
|
|
14
14
|
|
|
15
15
|
import ci from 'ci-info';
|
|
16
16
|
import MetroFileMap, {
|
|
@@ -75,7 +75,9 @@ export default function createFileMap(
|
|
|
75
75
|
config.watcher.unstable_autoSaveCache ?? {};
|
|
76
76
|
const autoSave = watch && autoSaveEnabled ? autoSaveOpts : false;
|
|
77
77
|
|
|
78
|
-
const plugins: Array<
|
|
78
|
+
const plugins: Array<InputFileMapPlugin> = [
|
|
79
|
+
...(config.unstable_fileMapPlugins ?? []),
|
|
80
|
+
];
|
|
79
81
|
|
|
80
82
|
let dependencyPlugin = null;
|
|
81
83
|
// Add DependencyPlugin if dependencies should be extracted
|
|
@@ -86,7 +88,6 @@ export default function createFileMap(
|
|
|
86
88
|
dependencyPlugin = new DependencyPlugin({
|
|
87
89
|
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
88
90
|
computeDependencies: true,
|
|
89
|
-
rootDir: config.projectRoot,
|
|
90
91
|
});
|
|
91
92
|
plugins.push(dependencyPlugin);
|
|
92
93
|
}
|