{"version":3,"file":"firefox-paths.mjs","sources":["webpack://@agent-infra/browser-finder/./src/firefox-paths.ts"],"sourcesContent":["/**\n * The following code is modified based on\n * https://github.com/shirshak55/edge-paths/blob/master/index.ts\n *\n * MIT Licensed\n * Copyright (c) 2020 Shirshak\n * https://github.com/shirshak55/edge-paths/blob/master/LICENSE\n */\nimport { existsSync } from 'fs';\nimport { sep, join } from 'path';\nimport which from 'which';\n\nconst platform = process.platform;\n\nfunction getFirefoxOnLinux(name: 'firefox'): string | null {\n  try {\n    const path = which.sync(name);\n    return path;\n  } catch (e) {}\n\n  return null;\n}\n\nfunction getFirefoxOnWindows(\n  name: 'Mozilla Firefox' | 'Firefox Developer Edition' | 'Firefox Nightly',\n): string | null {\n  const suffix = `${sep}${name}${sep}firefox.exe`;\n\n  const prefixes = [\n    process.env.LOCALAPPDATA,\n    process.env.PROGRAMFILES,\n    process.env['PROGRAMFILES(X86)'],\n  ].filter(Boolean);\n\n  for (const prefix of prefixes) {\n    const firefoxPath = join(prefix!, suffix);\n    if (existsSync(firefoxPath)) {\n      return firefoxPath;\n    }\n  }\n\n  return null;\n}\n\nfunction getFireFoxOnDarwin(\n  name: 'Firefox' | 'Firefox Developer Edition' | 'Firefox Nightly',\n): string | null {\n  const suffix = `/Applications/${name}.app/Contents/MacOS/firefox`;\n  const prefixes = ['', process.env.HOME].filter((item) => item !== undefined);\n\n  for (const prefix of prefixes) {\n    const firefoxPath = join(prefix, suffix);\n    if (existsSync(firefoxPath)) {\n      return firefoxPath;\n    }\n  }\n\n  return null;\n}\n\nconst firefoxPaths = {\n  firefox: {\n    linux: () => getFirefoxOnLinux('firefox'), // stable/beta/dev/nightly use same 'firefox' app name\n    darwin: () => getFireFoxOnDarwin('Firefox'),\n    win32: () => getFirefoxOnWindows('Mozilla Firefox'),\n  },\n  // beta and stable use same file path\n  dev: {\n    darwin: () => getFireFoxOnDarwin('Firefox Developer Edition'),\n    win32: () => getFirefoxOnWindows('Firefox Developer Edition'),\n  },\n  nightly: {\n    darwin: () => getFireFoxOnDarwin('Firefox Nightly'),\n    win32: () => getFirefoxOnWindows('Firefox Nightly'),\n  },\n};\n\nfunction getFirefoxPath() {\n  const firefox = firefoxPaths.firefox;\n\n  if (platform && Object.keys(firefox).includes(platform)) {\n    const pth = firefox[platform as keyof typeof firefox]();\n    if (pth) {\n      return pth;\n    }\n  }\n}\n\nfunction getFirefoxDevPath() {\n  const dev = firefoxPaths.dev;\n\n  if (platform && Object.keys(dev).includes(platform)) {\n    const pth = dev[platform as keyof typeof dev]();\n    if (pth) {\n      return pth;\n    }\n  }\n}\n\nfunction getFirefoxNightlyPath() {\n  const nightly = firefoxPaths.nightly;\n\n  if (platform && Object.keys(nightly).includes(platform)) {\n    const pth = nightly[platform as keyof typeof nightly]();\n    if (pth) {\n      return pth;\n    }\n  }\n}\n\nexport function getAnyFirefoxStable(): string {\n  const firefox = getFirefoxPath();\n  if (firefox) {\n    return firefox;\n  }\n\n  const dev = getFirefoxDevPath();\n  if (dev) {\n    return dev;\n  }\n\n  const canary = getFirefoxNightlyPath();\n  if (canary) {\n    return canary;\n  }\n\n  const error = new Error('Unable to find any firefox browser.');\n  error.name = 'FirefoxPathsError';\n  throw error;\n}\n"],"names":["platform","process","getFirefoxOnLinux","name","path","which","e","getFirefoxOnWindows","suffix","sep","prefixes","Boolean","prefix","firefoxPath","join","existsSync","getFireFoxOnDarwin","item","undefined","firefoxPaths","getFirefoxPath","firefox","Object","pth","getFirefoxDevPath","dev","getFirefoxNightlyPath","nightly","getAnyFirefoxStable","canary","error","Error"],"mappings":";;;;;;;AAYA,MAAMA,WAAWC,QAAQ,QAAQ;AAEjC,SAASC,kBAAkBC,IAAe;IACxC,IAAI;QACF,MAAMC,OAAOC,MAAM,IAAI,CAACF;QACxB,OAAOC;IACT,EAAE,OAAOE,GAAG,CAAC;IAEb,OAAO;AACT;AAEA,SAASC,oBACPJ,IAAyE;IAEzE,MAAMK,SAAS,GAAGC,MAAMN,OAAOM,IAAI,WAAW,C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