Skip to content

Commit 4206c12

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Rename BrowserLauncher interface and implementations
Summary: Renames the **"BrowserLauncher"** concept (`unstable_browserLauncher`) to **"DevToolLauncher"** (`unstable_toolLauncher`), since the scope is now widened to open the desktop debugger shell by default. Also rename and remove `unstable_` prefixes for `launchDebuggerShell` and `prepareDebuggerShell` methods (APIs remain unstable on the root option key). **Why not `DebuggerLauncher`?** This naming remains wide enough to cover other host process delegation in future (e.g. opening other secondary tools, or opening a generic URL in the browser). Debugger launching methods remain specifically named to match their intent. Changelog: [Internal] Reviewed By: vzaidman Differential Revision: D94218654 fbshipit-source-id: e59d5465f200666cd0f1a189414f2223f5e46f69
1 parent 58d9486 commit 4206c12

9 files changed

Lines changed: 65 additions & 70 deletions

File tree

packages/dev-middleware/src/__tests__/InspectorProxyHttpApi-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
JsonVersionResponse,
1414
} from '../inspector-proxy/types';
1515

16-
import DefaultBrowserLauncher from '../utils/DefaultBrowserLauncher';
16+
import DefaultToolLauncher from '../utils/DefaultToolLauncher';
1717
import {fetchJson, requestLocal} from './FetchUtils';
1818
import {createDeviceMock} from './InspectorDeviceUtils';
1919
import {withAbortSignalForEachTest} from './ResourceUtils';
@@ -397,9 +397,9 @@ describe('inspector proxy HTTP API', () => {
397397
]);
398398
jest.advanceTimersByTime(PAGES_POLLING_DELAY);
399399

400-
// Hook into `DefaultBrowserLauncher.launchDebuggerAppWindow` to ensure debugger was launched
400+
// Hook into `DefaultToolLauncher.launchDebuggerAppWindow` to ensure debugger was launched
401401
const launchDebuggerSpy = jest
402-
.spyOn(DefaultBrowserLauncher, 'launchDebuggerAppWindow')
402+
.spyOn(DefaultToolLauncher, 'launchDebuggerAppWindow')
403403
.mockResolvedValueOnce();
404404

405405
try {

packages/dev-middleware/src/__tests__/StandaloneFuseboxShell-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
*/
1010

1111
import type {JsonPagesListResponse} from '../inspector-proxy/types';
12-
import type {BrowserLauncher} from '../types/BrowserLauncher';
12+
import type {DevToolLauncher} from '../types/DevToolLauncher';
1313

14-
import DefaultBrowserLauncher from '../utils/DefaultBrowserLauncher';
14+
import DefaultToolLauncher from '../utils/DefaultToolLauncher';
1515
import {fetchJson, requestLocal} from './FetchUtils';
1616
import {createDeviceMock} from './InspectorDeviceUtils';
1717
import {withAbortSignalForEachTest} from './ResourceUtils';
@@ -23,18 +23,18 @@ const PAGES_POLLING_DELAY = 2100;
2323
jest.useFakeTimers();
2424

2525
describe('enableStandaloneFuseboxShell experiment', () => {
26-
const BrowserLauncherWithFuseboxShell: BrowserLauncher = {
27-
...DefaultBrowserLauncher,
28-
unstable_showFuseboxShell: () => {
26+
const ToolLauncherWithFuseboxShell: DevToolLauncher = {
27+
...DefaultToolLauncher,
28+
launchDebuggerShell: () => {
2929
throw new Error('Not implemented');
3030
},
31-
unstable_prepareFuseboxShell: async () => {
31+
prepareDebuggerShell: async () => {
3232
return {code: 'not_implemented'};
3333
},
3434
};
3535
const serverRef = withServerForEachTest({
3636
logger: undefined,
37-
unstable_browserLauncher: BrowserLauncherWithFuseboxShell,
37+
unstable_toolLauncher: ToolLauncherWithFuseboxShell,
3838
unstable_experiments: {
3939
enableStandaloneFuseboxShell: true,
4040
},
@@ -66,10 +66,10 @@ describe('enableStandaloneFuseboxShell experiment', () => {
6666
jest.advanceTimersByTime(PAGES_POLLING_DELAY);
6767

6868
const launchDebuggerAppWindowSpy = jest
69-
.spyOn(BrowserLauncherWithFuseboxShell, 'launchDebuggerAppWindow')
69+
.spyOn(ToolLauncherWithFuseboxShell, 'launchDebuggerAppWindow')
7070
.mockResolvedValue();
7171
const showFuseboxShellSpy = jest
72-
.spyOn(BrowserLauncherWithFuseboxShell, 'unstable_showFuseboxShell')
72+
.spyOn(ToolLauncherWithFuseboxShell, 'launchDebuggerShell')
7373
.mockResolvedValue();
7474

7575
try {
@@ -128,6 +128,6 @@ describe('enableStandaloneFuseboxShell experiment', () => {
128128
}
129129
});
130130

131-
// TODO(moti): Add tests around unstable_prepareFuseboxShell
131+
// TODO(moti): Add tests around prepareDebuggerShell
132132
});
133133
});

packages/dev-middleware/src/createDevMiddleware.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
import type {CreateCustomMessageHandlerFn} from './inspector-proxy/CustomMessageHandler';
12-
import type {BrowserLauncher} from './types/BrowserLauncher';
12+
import type {DevToolLauncher} from './types/DevToolLauncher';
1313
import type {EventReporter, ReportableEvent} from './types/EventReporter';
1414
import type {Experiments, ExperimentsConfig} from './types/Experiments';
1515
import type {Logger} from './types/Logger';
@@ -18,7 +18,7 @@ import type {NextHandleFunction} from 'connect';
1818

1919
import InspectorProxy from './inspector-proxy/InspectorProxy';
2020
import openDebuggerMiddleware from './middleware/openDebuggerMiddleware';
21-
import DefaultBrowserLauncher from './utils/DefaultBrowserLauncher';
21+
import DefaultToolLauncher from './utils/DefaultToolLauncher';
2222
import reactNativeDebuggerFrontendPath from '@react-native/debugger-frontend';
2323
import connect from 'connect';
2424
import path from 'path';
@@ -31,18 +31,17 @@ type Options = Readonly<{
3131
*/
3232
serverBaseUrl: string | ReadonlyURL,
3333

34-
logger?: Logger,
35-
3634
/**
37-
* An interface for integrators to provide a custom implementation for
38-
* opening URLs in a web browser.
35+
* An implementation for logging messages to the terminal (recommended).
3936
*
40-
* This is an unstable API with no semver guarantees.
37+
* In `@react-native/community-cli-plugin`, this reuses Metro's
38+
* 'unstable_server_log' event in `TerminalReporter`.
4139
*/
42-
unstable_browserLauncher?: BrowserLauncher,
40+
logger?: Logger,
4341

4442
/**
45-
* An interface for logging events.
43+
* An `EventReporter` implementation for logging structured events
44+
* (recommended).
4645
*
4746
* This is an unstable API with no semver guarantees.
4847
*/
@@ -55,6 +54,14 @@ type Options = Readonly<{
5554
*/
5655
unstable_experiments?: ExperimentsConfig,
5756

57+
/**
58+
* Override the default handlers for launching external applications (the
59+
* debugger frontend) on the host machine (or target dev machine).
60+
*
61+
* This is an unstable API with no semver guarantees.
62+
*/
63+
unstable_toolLauncher?: DevToolLauncher,
64+
5865
/**
5966
* Create custom handler to add support for unsupported CDP events, or debuggers.
6067
* This handler is instantiated per logical device and debugger pair.
@@ -64,7 +71,8 @@ type Options = Readonly<{
6471
unstable_customInspectorMessageHandler?: CreateCustomMessageHandlerFn,
6572

6673
/**
67-
* Whether to measure the event loop performance of inspector proxy and log report it via the event reporter.
74+
* Whether to measure the event loop performance of inspector proxy and
75+
* report it via the event reporter.
6876
*
6977
* This is an unstable API with no semver guarantees.
7078
*/
@@ -79,10 +87,9 @@ type DevMiddlewareAPI = Readonly<{
7987
export default function createDevMiddleware({
8088
serverBaseUrl,
8189
logger,
82-
// $FlowFixMe[incompatible-type]
83-
unstable_browserLauncher = DefaultBrowserLauncher,
8490
unstable_eventReporter,
8591
unstable_experiments: experimentConfig = {},
92+
unstable_toolLauncher = DefaultToolLauncher,
8693
unstable_customInspectorMessageHandler,
8794
unstable_trackInspectorProxyEventLoopPerf = false,
8895
}: Options): DevMiddlewareAPI {
@@ -110,7 +117,7 @@ export default function createDevMiddleware({
110117
openDebuggerMiddleware({
111118
serverBaseUrl: normalizedServerBaseUrl,
112119
inspectorProxy,
113-
browserLauncher: unstable_browserLauncher,
120+
toolLauncher: unstable_toolLauncher,
114121
eventReporter,
115122
experiments,
116123
logger,

packages/dev-middleware/src/index.flow.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
*/
1010

1111
export type {
12-
BrowserLauncher,
12+
DevToolLauncher,
1313
DebuggerShellPreparationResult,
14-
} from './types/BrowserLauncher';
14+
} from './types/DevToolLauncher';
1515
export type {EventReporter, ReportableEvent} from './types/EventReporter';
1616
export type {
1717
CustomMessageHandler,
@@ -21,5 +21,5 @@ export type {
2121
export type {Logger} from './types/Logger';
2222
export type {ReadonlyURL} from './types/ReadonlyURL';
2323

24-
export {default as unstable_DefaultBrowserLauncher} from './utils/DefaultBrowserLauncher';
24+
export {default as unstable_DefaultToolLauncher} from './utils/DefaultToolLauncher';
2525
export {default as createDevMiddleware} from './createDevMiddleware';

packages/dev-middleware/src/middleware/openDebuggerMiddleware.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import type {InspectorProxyQueries} from '../inspector-proxy/InspectorProxy';
1212
import type {PageDescription} from '../inspector-proxy/types';
1313
import type {
14-
BrowserLauncher,
1514
DebuggerShellPreparationResult,
16-
} from '../types/BrowserLauncher';
15+
DevToolLauncher,
16+
} from '../types/DevToolLauncher';
1717
import type {EventReporter} from '../types/EventReporter';
1818
import type {Experiments} from '../types/Experiments';
1919
import type {Logger} from '../types/Logger';
@@ -30,7 +30,7 @@ const LEGACY_SYNTHETIC_PAGE_TITLE =
3030
type Options = Readonly<{
3131
serverBaseUrl: ReadonlyURL,
3232
logger?: Logger,
33-
browserLauncher: BrowserLauncher,
33+
toolLauncher: DevToolLauncher,
3434
eventReporter?: EventReporter,
3535
experiments: Experiments,
3636
inspectorProxy: InspectorProxyQueries,
@@ -44,15 +44,15 @@ type Options = Readonly<{
4444
export default function openDebuggerMiddleware({
4545
serverBaseUrl,
4646
logger,
47-
browserLauncher,
47+
toolLauncher,
4848
eventReporter,
4949
experiments,
5050
inspectorProxy,
5151
}: Options): NextHandleFunction {
5252
let shellPreparationPromise: Promise<DebuggerShellPreparationResult>;
5353
if (experiments.enableStandaloneFuseboxShell) {
5454
shellPreparationPromise =
55-
browserLauncher?.unstable_prepareFuseboxShell?.() ??
55+
toolLauncher?.prepareDebuggerShell?.() ??
5656
Promise.resolve({code: 'not_implemented'});
5757
shellPreparationPromise = shellPreparationPromise.then(result => {
5858
eventReporter?.logEvent({
@@ -196,17 +196,14 @@ export default function openDebuggerMiddleware({
196196
].join('-'),
197197
)
198198
.digest('hex');
199-
if (!browserLauncher.unstable_showFuseboxShell) {
199+
if (!toolLauncher.launchDebuggerShell) {
200200
throw new Error(
201-
'Fusebox shell is not supported by the current browser launcher',
201+
'Fusebox shell is not supported by the current app launcher',
202202
);
203203
}
204-
await browserLauncher.unstable_showFuseboxShell(
205-
frontendUrl,
206-
windowKey,
207-
);
204+
await toolLauncher.launchDebuggerShell(frontendUrl, windowKey);
208205
} else {
209-
await browserLauncher.launchDebuggerAppWindow(frontendUrl);
206+
await toolLauncher.launchDebuggerAppWindow(frontendUrl);
210207
}
211208
res.writeHead(200);
212209
res.end();

packages/dev-middleware/src/types/BrowserLauncher.js renamed to packages/dev-middleware/src/types/DevToolLauncher.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ export type {DebuggerShellPreparationResult};
1414

1515
/**
1616
* An interface for integrators to provide a custom implementation for
17-
* opening URLs in a web browser.
17+
* launching external applications on the host machine (or target dev machine).
18+
*
19+
* This is an unstable API with no semver guarantees.
1820
*/
19-
export interface BrowserLauncher {
21+
export interface DevToolLauncher {
2022
/**
21-
* Attempt to open a debugger frontend URL in a browser app window,
22-
* optionally returning an object to control the launched browser instance.
23-
* The browser used should be capable of running Chrome DevTools.
23+
* Attempt to open a debugger frontend URL in a browser app window. The
24+
* browser used should be capable of running Chrome DevTools.
2425
*
2526
* The provided URL is based on serverBaseUrl, and therefore reachable from
2627
* the host of dev-middleware. Implementations are responsible for rewriting
2728
* this as necessary where the server is remote.
2829
*/
29-
launchDebuggerAppWindow: (url: string) => Promise<void>;
30+
+launchDebuggerAppWindow: (url: string) => Promise<void>;
3031

3132
/**
3233
* Attempt to open a debugger frontend URL in a standalone shell window
@@ -46,10 +47,7 @@ export interface BrowserLauncher {
4647
* the host of dev-middleware. Implementations are responsible for rewriting
4748
* this as necessary where the server is remote.
4849
*/
49-
+unstable_showFuseboxShell?: (
50-
url: string,
51-
windowKey: string,
52-
) => Promise<void>;
50+
+launchDebuggerShell?: (url: string, windowKey: string) => Promise<void>;
5351

5452
/**
5553
* Attempt to prepare the debugger shell for use and returns a coded result
@@ -62,5 +60,5 @@ export interface BrowserLauncher {
6260
* SHOULD NOT return a rejecting promise in any case, and instead SHOULD report
6361
* errors via the returned result object.
6462
*/
65-
+unstable_prepareFuseboxShell?: () => Promise<DebuggerShellPreparationResult>;
63+
+prepareDebuggerShell?: () => Promise<DebuggerShellPreparationResult>;
6664
}

packages/dev-middleware/src/types/EventReporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
import type {DebuggerShellPreparationResult} from './BrowserLauncher';
11+
import type {DebuggerShellPreparationResult} from './DevToolLauncher';
1212

1313
type SuccessResult<Props: {...} | void = {}> = {
1414
status: 'success',

packages/dev-middleware/src/types/Experiments.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type Experiments = Readonly<{
1212
/**
1313
* Enables the handling of GET requests in the /open-debugger endpoint,
1414
* in addition to POST requests. GET requests respond by redirecting to
15-
* the debugger frontend, instead of opening it using the BrowserLauncher
15+
* the debugger frontend, instead of opening it using the DevToolLauncher
1616
* interface.
1717
*/
1818
enableOpenDebuggerRedirect: boolean,
@@ -25,8 +25,8 @@ export type Experiments = Readonly<{
2525

2626
/**
2727
* Launch the debugger frontend in a standalone shell instead of a browser.
28-
* When this is enabled, we will use the optional unstable_showFuseboxShell
29-
* method on the BrowserLauncher, or throw an error if the method is missing.
28+
* When this is enabled, we will use the optional launchDebuggerShell
29+
* method on the DevToolLauncher, or throw an error if the method is missing.
3030
*
3131
* NOTE: Disabling this also disables support for concurrent sessions in the
3232
* inspector proxy. Without the standalone shell, the proxy remains responsible

packages/dev-middleware/src/utils/DefaultBrowserLauncher.js renamed to packages/dev-middleware/src/utils/DefaultToolLauncher.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
import type {DebuggerShellPreparationResult} from '../';
11+
import type {DebuggerShellPreparationResult} from '../types/DevToolLauncher';
1212

1313
const {
1414
unstable_prepareDebuggerShell,
@@ -20,14 +20,10 @@ const {Launcher: EdgeLauncher} = require('chromium-edge-launcher');
2020
const open = require('open');
2121

2222
/**
23-
* Default `BrowserLauncher` implementation which opens URLs on the host
24-
* machine.
23+
* Default `DevToolLauncher` implementation which handles opening apps on the
24+
* local machine.
2525
*/
26-
const DefaultBrowserLauncher = {
27-
/**
28-
* Attempt to open the debugger frontend in a Google Chrome or Microsoft Edge
29-
* app window.
30-
*/
26+
const DefaultToolLauncher = {
3127
launchDebuggerAppWindow: async (url: string): Promise<void> => {
3228
let chromePath;
3329

@@ -69,21 +65,18 @@ const DefaultBrowserLauncher = {
6965
});
7066
},
7167

72-
async unstable_showFuseboxShell(
73-
url: string,
74-
windowKey: string,
75-
): Promise<void> {
68+
async launchDebuggerShell(url: string, windowKey: string): Promise<void> {
7669
return await unstable_spawnDebuggerShellWithArgs([
7770
'--frontendUrl=' + url,
7871
'--windowKey=' + windowKey,
7972
]);
8073
},
8174

82-
async unstable_prepareFuseboxShell(
75+
async prepareDebuggerShell(
8376
prebuiltBinaryPath?: ?string,
8477
): Promise<DebuggerShellPreparationResult> {
8578
return await unstable_prepareDebuggerShell();
8679
},
8780
};
8881

89-
export default DefaultBrowserLauncher;
82+
export default DefaultToolLauncher;

0 commit comments

Comments
 (0)