MCPcopy Index your code
hub / github.com/nodejs/node / openUrlPrompt

Function openUrlPrompt

deps/npm/lib/utils/open-url.js:55–87  ·  view source on GitHub ↗
(npm, url, title, prompt, { signal })

Source from the content-addressed store, hash-verified

53
54// Prompt to open URL in browser if possible
55const 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
90const createOpener = (npm, title, prompt = 'Press ENTER to open in the browser...') =>

Callers 2

createOpenerFunction · 0.85
mockOpenUrlPromptFunction · 0.85

Calls 9

assertValidUrlFunction · 0.85
outputMsgFunction · 0.85
questionMethod · 0.80
openUrlFunction · 0.70
getMethod · 0.65
closeMethod · 0.65
onceFunction · 0.50
readMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…