Skip to content

Commit 30a2193

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Drop chrome-launcher dependency (#57630)
Summary: Pull Request resolved: #57630 **Motivation** - Flagged as a papercut by Expo: `chrome-launcher` (and `chromium-edge-launcher`) constitute duplicate code (vs Expo's vendored version), and we can lighten our core package by dropping these dependencies. - `launchDebuggerAppWindow` is now a fallback (since the rollout of the RNDT desktop shell), and we can reasonably delegate more rigorous browser detection to frameworks. **This diff** Remove both `chrome-launcher` dependencies and their usages in the `launchDebuggerAppWindow` code path. In their place, use `open` (bumped to 8.x)'s `openApp` API for Chrome only. Changelog: [General][Changed] - **React Native DevTools**: When using the fallback flow for launching DevTools (desktop app fails to launch), Microsoft Edge will not be attempted. DevTools will open as a standard window in the default browser. Reviewed By: robhogan Differential Revision: D113055240
1 parent 0fc76bb commit 30a2193

7 files changed

Lines changed: 84 additions & 214 deletions

File tree

flow-typed/npm/chrome-launcher_v0.15.x.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

flow-typed/npm/chromium-edge-launcher_v0.2.x.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

flow-typed/npm/open_v7.x.x.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

flow-typed/npm/open_v8.x.x.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
* @format
9+
*/
10+
11+
declare module 'open' {
12+
import type {ChildProcess} from 'child_process';
13+
14+
declare export type AppName = 'chrome' | 'firefox' | 'edge';
15+
16+
declare export type App = Readonly<{
17+
name: string | ReadonlyArray<string>,
18+
arguments?: ReadonlyArray<string>,
19+
}>;
20+
21+
declare export type Options = Readonly<{
22+
wait?: boolean,
23+
background?: boolean,
24+
newInstance?: boolean,
25+
allowNonzeroExitCode?: boolean,
26+
app?: App | ReadonlyArray<App>,
27+
...
28+
}>;
29+
30+
declare export type OpenAppOptions = Readonly<{
31+
wait?: boolean,
32+
background?: boolean,
33+
newInstance?: boolean,
34+
allowNonzeroExitCode?: boolean,
35+
arguments?: ReadonlyArray<string>,
36+
...
37+
}>;
38+
39+
declare module.exports: ((
40+
target: string,
41+
options?: Options,
42+
) => Promise<ChildProcess>) & {
43+
apps: Record<AppName, string | ReadonlyArray<string>>,
44+
openApp: (
45+
name: string | ReadonlyArray<string>,
46+
options?: OpenAppOptions,
47+
) => Promise<ChildProcess>,
48+
...
49+
};
50+
}

packages/dev-middleware/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@
3434
"@isaacs/ttlcache": "^1.4.1",
3535
"@react-native/debugger-frontend": "0.87.0-main",
3636
"@react-native/debugger-shell": "0.87.0-main",
37-
"chrome-launcher": "^0.15.2",
38-
"chromium-edge-launcher": "^0.3.0",
3937
"connect": "^3.6.5",
4038
"debug": "^4.4.0",
4139
"invariant": "^2.2.4",
4240
"nullthrows": "^1.1.1",
43-
"open": "^7.0.3",
41+
"open": "^8.4.2",
4442
"serve-static": "^1.16.2",
4543
"ws": "^7.5.10"
4644
},

packages/dev-middleware/src/utils/DefaultToolLauncher.js

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ const {
1414
unstable_prepareDebuggerShell,
1515
unstable_spawnDebuggerShellWithArgs,
1616
} = require('@react-native/debugger-shell');
17-
const ChromeLauncher = require('chrome-launcher');
18-
const {Launcher: EdgeLauncher} = require('chromium-edge-launcher');
19-
const {spawn} = require('node:child_process');
2017
const open = require('open');
2118

19+
const {apps, openApp} = open;
20+
2221
/**
2322
* Default `DevToolLauncher` implementation which handles opening apps on the
2423
* local machine.
@@ -29,44 +28,27 @@ const DefaultToolLauncher = {
2928
assertMockedInTests();
3029
}
3130

32-
let chromePath;
33-
31+
// NOTE: Since 0.88 this is a simplified approach, since app launching is
32+
// now handled by `launchDebuggerShell`. Frameworks may still override
33+
// `DevToolLauncher` with an improved fallback stack.
3434
try {
35-
// Locate Chrome installation path, will throw if not found
36-
chromePath = ChromeLauncher.getChromePath();
37-
} catch (e) {
38-
// Fall back to Microsoft Edge
39-
chromePath = EdgeLauncher.getFirstInstallation();
40-
}
41-
42-
if (chromePath == null) {
35+
const subprocess = await openApp(apps.chrome, {
36+
arguments: [`--app=${url}`],
37+
newInstance: true,
38+
});
39+
await new Promise<void>((resolve, reject) => {
40+
subprocess.once('error', reject);
41+
subprocess.once('exit', code => {
42+
code === 0
43+
? resolve()
44+
: reject(new Error(`openApp exited with code ${code}`));
45+
});
46+
});
47+
} catch (e: unknown) {
4348
// Fall back to default browser - the frontend will warn if the browser
4449
// is not supported.
4550
await open(url);
46-
return;
4751
}
48-
49-
const chromeFlags = [`--app=${url}`, '--window-size=1200,600'];
50-
51-
return new Promise((resolve, reject) => {
52-
const childProcess = spawn(chromePath, chromeFlags, {
53-
detached: true,
54-
stdio: 'ignore',
55-
});
56-
57-
childProcess.on('data', () => {
58-
resolve();
59-
});
60-
childProcess.on('close', (code: number) => {
61-
if (code !== 0) {
62-
reject(
63-
new Error(
64-
`Failed to launch debugger app window: ${chromePath} exited with code ${code}`,
65-
),
66-
);
67-
}
68-
});
69-
});
7052
},
7153

7254
async launchDebuggerShell(url: string, windowKey: string): Promise<void> {

yarn.lock

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,27 +3314,6 @@ chardet@^0.7.0:
33143314
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
33153315
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==
33163316

3317-
chrome-launcher@^0.15.2:
3318-
version "0.15.2"
3319-
resolved "https://registry.yarnpkg.com/chrome-launcher/-/chrome-launcher-0.15.2.tgz#4e6404e32200095fdce7f6a1e1004f9bd36fa5da"
3320-
integrity sha512-zdLEwNo3aUVzIhKhTtXfxhdvZhUghrnmkvcAq2NoDd+LeOHKf03H5jwZ8T/STsAlzyALkBVK552iaG1fGf1xVQ==
3321-
dependencies:
3322-
"@types/node" "*"
3323-
escape-string-regexp "^4.0.0"
3324-
is-wsl "^2.2.0"
3325-
lighthouse-logger "^1.0.0"
3326-
3327-
chromium-edge-launcher@^0.3.0:
3328-
version "0.3.0"
3329-
resolved "https://registry.yarnpkg.com/chromium-edge-launcher/-/chromium-edge-launcher-0.3.0.tgz#34d5ca8142fc059ea2b4482bdcb184393a399ffe"
3330-
integrity sha512-p03azHlGjtyRvFEee3cyvtsRYdniSkwjkzmM/KmVnqT5d7QkkwpJBhis/zCLMYdQMVJ5tt140TBNqqrZPaWeFA==
3331-
dependencies:
3332-
"@types/node" "*"
3333-
escape-string-regexp "^4.0.0"
3334-
is-wsl "^2.2.0"
3335-
lighthouse-logger "^1.0.0"
3336-
mkdirp "^1.0.4"
3337-
33383317
ci-info@^2.0.0:
33393318
version "2.0.0"
33403319
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
@@ -3670,7 +3649,7 @@ dayjs@^1.8.15:
36703649
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.13.tgz#92430b0139055c3ebb60150aa13e860a4b5a366c"
36713650
integrity sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==
36723651

3673-
debug@2.6.9, debug@^2.6.9:
3652+
debug@2.6.9:
36743653
version "2.6.9"
36753654
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
36763655
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
@@ -3777,6 +3756,11 @@ define-data-property@^1.0.1, define-data-property@^1.1.4:
37773756
es-errors "^1.3.0"
37783757
gopd "^1.0.1"
37793758

3759+
define-lazy-prop@^2.0.0:
3760+
version "2.0.0"
3761+
resolved "https://registry.yarnpkg.com/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz#3f7ae421129bcaaac9bc74905c98a0009ec9ee7f"
3762+
integrity sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==
3763+
37803764
define-properties@^1.1.3, define-properties@^1.2.0, define-properties@^1.2.1:
37813765
version "1.2.1"
37823766
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.2.1.tgz#10781cc616eb951a80a034bafcaa7377f6af2b6c"
@@ -5534,7 +5518,7 @@ is-decimal@^2.0.0:
55345518
resolved "https://registry.yarnpkg.com/is-decimal/-/is-decimal-2.0.1.tgz#9469d2dc190d0214fd87d78b78caecc0cc14eef7"
55355519
integrity sha512-AAB9hiomQs5DXWcRB1rqsxGUstbRroFOPPVAomNk/3XHR5JyEZChOyTWe2oayKnsSsr/kcGqF+z6yuH6HHpN0A==
55365520

5537-
is-docker@^2.0.0:
5521+
is-docker@^2.0.0, is-docker@^2.1.1:
55385522
version "2.2.1"
55395523
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa"
55405524
integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==
@@ -5775,7 +5759,7 @@ is-wsl@^1.1.0:
57755759
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"
57765760
integrity sha512-gfygJYZ2gLTDlmbWMI0CE2MwnFzSN/2SZfkMlItC4K/JBlsWVDB0bO6XhqcY13YXE7iMcAJnzTCJjPiTeJJ0Mw==
57775761

5778-
is-wsl@^2.1.1, is-wsl@^2.2.0:
5762+
is-wsl@^2.2.0:
57795763
version "2.2.0"
57805764
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271"
57815765
integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==
@@ -6442,14 +6426,6 @@ levn@^0.4.1:
64426426
prelude-ls "^1.2.1"
64436427
type-check "~0.4.0"
64446428

6445-
lighthouse-logger@^1.0.0:
6446-
version "1.4.2"
6447-
resolved "https://registry.yarnpkg.com/lighthouse-logger/-/lighthouse-logger-1.4.2.tgz#aef90f9e97cd81db367c7634292ee22079280aaa"
6448-
integrity sha512-gPWxznF6TKmUHrOQjlVo2UbaL2EJ71mb2CCeRs/2qBpi4L/g4LUVc9+3lKQ6DTUZwJswfM7ainGrLO1+fOqa2g==
6449-
dependencies:
6450-
debug "^2.6.9"
6451-
marky "^1.2.2"
6452-
64536429
lines-and-columns@^1.1.6:
64546430
version "1.2.4"
64556431
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
@@ -6666,11 +6642,6 @@ markdownlint@0.37.4:
66666642
micromark-extension-math "3.1.0"
66676643
micromark-util-types "2.0.1"
66686644

6669-
marky@^1.2.2:
6670-
version "1.2.5"
6671-
resolved "https://registry.yarnpkg.com/marky/-/marky-1.2.5.tgz#55796b688cbd72390d2d399eaaf1832c9413e3c0"
6672-
integrity sha512-q9JtQJKjpsVxCRVgQ+WapguSbKC3SQ5HEzFGPAJMStgh3QjCawp00UKv3MTTAArTmGmmPUvllHZoNbZ3gs0I+Q==
6673-
66746645
math-intrinsics@^1.1.0:
66756646
version "1.1.0"
66766647
resolved "https://registry.yarnpkg.com/math-intrinsics/-/math-intrinsics-1.1.0.tgz#a0dd74be81e2aa5c2f27e65ce283605ee4e2b7f9"
@@ -7527,13 +7498,14 @@ open@^6.2.0:
75277498
dependencies:
75287499
is-wsl "^1.1.0"
75297500

7530-
open@^7.0.3:
7531-
version "7.4.2"
7532-
resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321"
7533-
integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==
7501+
open@^8.4.2:
7502+
version "8.4.2"
7503+
resolved "https://registry.yarnpkg.com/open/-/open-8.4.2.tgz#5b5ffe2a8f793dcd2aad73e550cb87b59cb084f9"
7504+
integrity sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==
75347505
dependencies:
7535-
is-docker "^2.0.0"
7536-
is-wsl "^2.1.1"
7506+
define-lazy-prop "^2.0.0"
7507+
is-docker "^2.1.1"
7508+
is-wsl "^2.2.0"
75377509

75387510
optionator@^0.9.3:
75397511
version "0.9.4"

0 commit comments

Comments
 (0)