-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli, dev-server): add
SYSTEMROOT
for open
when opening browse…
…rs on Windows (#23287) # Why Fixes #23252 # How - `open` has a bug on Windows, where it [uses `process.env.SYSTEMROOT`](https://github.com/sindresorhus/open/blob/main/index.js#L173) instead of [`process.env.SystemRoot`](https://en.wikipedia.org/wiki/Environment_variable#:~:text=The%20%25SystemRoot%25%20variable%20is%20a,including%20the%20drive%20and%20path.) - This causes the executed command to run with `undefined\\...` - There has been no fix yet, and due to `open` being fully ESM now, we probably can't upgrade too > See various issues [#300](sindresorhus/open#300), [#292](sindresorhus/open#292), [#270](sindresorhus/open#270), or [#205](sindresorhus/open#205) This basically sets the missing `SYSTEMROOT` when trying to open a browser on Windows. It's fixed in both `@expo/cli` as well as `@expo/dev-server` (to open the Chrome DevTools). # Test Plan This has to be tested on Windows. - `$ yarn create expo ./test-browser -t tabs@beta` - `$ cd ./test-browser` - `$ yarn start` - Try pressing the following keys: - `j` -> to open the Chrome DevTools, after connecting a device. Should work as expected. - `w` -> to open the browser with Metro web. Should work as expected. # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
72 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
packages/@expo/cli/src/register/__tests__/registerAsync.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/@expo/cli/src/start/server/__tests__/BundlerDevServer-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import betterOpenBrowserAsync from 'better-opn'; | ||
|
||
/** | ||
* Due to a bug in `open`, which is used as fallback on Windows, we need to ensure `process.env.SYSTEMROOT` is set. | ||
* This environment variable is set by Windows on `SystemRoot`, causing `open` to execute a command with an "unknown" drive letter. | ||
* | ||
* @see https://github.com/sindresorhus/open/issues/205 | ||
*/ | ||
export async function openBrowserAsync( | ||
target: string, | ||
options?: any | ||
): Promise<import('child_process').ChildProcess | false> { | ||
if (process.platform !== 'win32') { | ||
return await betterOpenBrowserAsync(target, options); | ||
} | ||
|
||
const oldSystemRoot = process.env.SYSTEMROOT; | ||
try { | ||
process.env.SYSTEMROOT = process.env.SYSTEMROOT ?? process.env.SystemRoot; | ||
return await betterOpenBrowserAsync(target, options); | ||
} finally { | ||
process.env.SYSTEMROOT = oldSystemRoot; | ||
} | ||
} |
19 changes: 18 additions & 1 deletion
19
packages/@expo/dev-server/build/LaunchBrowserImplWindows.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/@expo/dev-server/build/LaunchBrowserImplWindows.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters