1import betterOpenBrowserAsync from 'better-opn'; 2 3/** 4 * Due to a bug in `open`, which is used as fallback on Windows, we need to ensure `process.env.SYSTEMROOT` is set. 5 * This environment variable is set by Windows on `SystemRoot`, causing `open` to execute a command with an "unknown" drive letter. 6 * 7 * @see https://github.com/sindresorhus/open/issues/205 8 */ 9export async function openBrowserAsync( 10 target: string, 11 options?: any 12): Promise<import('child_process').ChildProcess | false> { 13 if (process.platform !== 'win32') { 14 return await betterOpenBrowserAsync(target, options); 15 } 16 17 const oldSystemRoot = process.env.SYSTEMROOT; 18 try { 19 process.env.SYSTEMROOT = process.env.SYSTEMROOT ?? process.env.SystemRoot; 20 return await betterOpenBrowserAsync(target, options); 21 } finally { 22 process.env.SYSTEMROOT = oldSystemRoot; 23 } 24} 25