Skip to content

Commit

Permalink
Fix Firefox WSL1 resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 22, 2024
1 parent 7ece34b commit d22b562
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ export abstract class Browser {
constructor(opts: BrowserOptions) {
this.purpose = opts.purpose
}

get kind() {
return (this.constructor as typeof Browser).kind
}

get protocol() {
return (this.constructor as typeof Browser).protocol
}
}
45 changes: 30 additions & 15 deletions src/browser/finders/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ const firefoxFinderDarwin = async () =>
'/Applications/Firefox.app/Contents/MacOS/firefox', // Firefox stable, ESR, and beta
])

const winDriveMatcher = /^[a-z]:\\/i
const winPossibleDrives = () => {
const possibleDriveSet = new Set<string>()
const pathEnvs = process.env.PATH?.split(';') ?? ['c:\\']

for (const pathEnv of pathEnvs) {
if (winDriveMatcher.test(pathEnv)) {
possibleDriveSet.add(pathEnv[0].toLowerCase())
}
}

return Array.from(possibleDriveSet).sort()
}

const firefoxFinderWin32 = async () => {
const prefixes: string[] = []

const winDriveMatcher = /^[a-z]:\\/i
const winPossibleDrives = () => {
const possibleDriveSet = new Set<string>()
const pathEnvs = process.env.PATH?.split(';') ?? ['c:\\']

for (const pathEnv of pathEnvs) {
if (winDriveMatcher.test(pathEnv)) {
possibleDriveSet.add(pathEnv[0].toLowerCase())
}
}

return Array.from(possibleDriveSet).sort()
}

for (const drive of winPossibleDrives()) {
for (const prefix of [
process.env.PROGRAMFILES,
Expand All @@ -80,6 +80,20 @@ const firefoxFinderWin32 = async () => {
const firefoxFinderWSL1 = async () => {
const prefixes: string[] = []

const winDriveMatcher = /^\/mnt\/[a-z]\//i
const winPossibleDrives = () => {
const possibleDriveSet = new Set<string>()
const pathEnvs = process.env.PATH?.split(':') ?? ['/mnt/c/']

for (const pathEnv of pathEnvs) {
if (winDriveMatcher.test(pathEnv)) {
possibleDriveSet.add(pathEnv[5].toLowerCase())
}
}

return Array.from(possibleDriveSet).sort()
}

for (const drive of winPossibleDrives()) {
prefixes.push(`/mnt/${drive}/Program Files`)
prefixes.push(`/mnt/${drive}/Program Files (x86)`)
Expand All @@ -98,7 +112,8 @@ const firefoxFinderWSL1 = async () => {
const firefoxFinderFallback = async () =>
await findExecutableBinary(
// In Linux, Firefox must have only an executable name `firefox` in every
// editions, but some packages may provide different executable names.
// editions, but some distributions may have provided different executable
// names.
[
'firefox-nightly',
'firefox-developer-edition',
Expand Down

0 comments on commit d22b562

Please sign in to comment.