(npm, url, title, prompt, { signal })
| 53 | |
| 54 | // Prompt to open URL in browser if possible |
| 55 | const openUrlPrompt = async (npm, url, title, prompt, { signal }) => { |
| 56 | const browser = npm.config.get('browser') |
| 57 | const json = npm.config.get('json') |
| 58 | |
| 59 | assertValidUrl(url) |
| 60 | outputMsg(json, title, url) |
| 61 | |
| 62 | if (browser === false || !process.stdin.isTTY || !process.stdout.isTTY) { |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | const rl = readline.createInterface({ |
| 67 | input: process.stdin, |
| 68 | output: process.stdout, |
| 69 | }) |
| 70 | |
| 71 | try { |
| 72 | await input.read(() => Promise.race([ |
| 73 | rl.question(prompt, { signal }), |
| 74 | once(rl, 'error'), |
| 75 | once(rl, 'SIGINT').then(() => { |
| 76 | throw new Error('canceled') |
| 77 | }), |
| 78 | ])) |
| 79 | rl.close() |
| 80 | await openUrl(npm, url, 'Browser unavailable. Please open the URL manually') |
| 81 | } catch (err) { |
| 82 | rl.close() |
| 83 | if (err.name !== 'AbortError') { |
| 84 | throw err |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // Rearrange arguments and return a function that takes the two arguments returned from the npm-profile methods that take an opener |
| 90 | const createOpener = (npm, title, prompt = 'Press ENTER to open in the browser...') => |
no test coverage detected
searching dependent graphs…