summaryrefslogtreecommitdiff
path: root/deps/npm/lib/utils
diff options
context:
space:
mode:
authornpm CLI robot <npm-cli+bot@github.com>2022-06-24 18:21:50 -0700
committerGitHub <noreply@github.com>2022-06-25 02:21:50 +0100
commit687e50aded0d264873911847717e7567382b1401 (patch)
treeb7f38b32e988bf3f7a9567dc3cd1c62e0be1c43f /deps/npm/lib/utils
parent3507b3f9a9da6c451c18f303d3b96e4deedf2f5b (diff)
downloadnode-new-687e50aded0d264873911847717e7567382b1401.tar.gz
deps: upgrade npm to 8.13.1
PR-URL: https://github.com/nodejs/node/pull/43552 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Diffstat (limited to 'deps/npm/lib/utils')
-rw-r--r--deps/npm/lib/utils/config/definitions.js6
-rw-r--r--deps/npm/lib/utils/open-url-prompt.js69
2 files changed, 72 insertions, 3 deletions
diff --git a/deps/npm/lib/utils/config/definitions.js b/deps/npm/lib/utils/config/definitions.js
index 4c77e375c5..6b35e7d4d0 100644
--- a/deps/npm/lib/utils/config/definitions.js
+++ b/deps/npm/lib/utils/config/definitions.js
@@ -535,7 +535,7 @@ define('dev', {
define('diff', {
default: [],
- hint: '<pkg-name|spec|version>',
+ hint: '<package-spec>',
type: [String, Array],
description: `
Define arguments to compare in \`npm diff\`.
@@ -1458,7 +1458,7 @@ define('otp', {
define('package', {
default: [],
- hint: '<pkg>[@<version>]',
+ hint: '<package-spec>',
type: [String, Array],
description: `
The package to install for [\`npm exec\`](/commands/npm-exec)
@@ -1867,7 +1867,7 @@ define('script-shell', {
type: [null, String],
description: `
The shell to use for scripts run with the \`npm exec\`,
- \`npm run\` and \`npm init <pkg>\` commands.
+ \`npm run\` and \`npm init <package-spec>\` commands.
`,
flatten (key, obj, flatOptions) {
flatOptions.scriptShell = obj[key] || undefined
diff --git a/deps/npm/lib/utils/open-url-prompt.js b/deps/npm/lib/utils/open-url-prompt.js
new file mode 100644
index 0000000000..3eb3ac288c
--- /dev/null
+++ b/deps/npm/lib/utils/open-url-prompt.js
@@ -0,0 +1,69 @@
+const readline = require('readline')
+const opener = require('opener')
+
+function print (npm, title, url) {
+ const json = npm.config.get('json')
+
+ const message = json ? JSON.stringify({ title, url }) : `${title}:\n${url}`
+
+ npm.output(message)
+}
+
+// Prompt to open URL in browser if possible
+const promptOpen = async (npm, url, title, prompt, emitter) => {
+ const browser = npm.config.get('browser')
+ const isInteractive = process.stdin.isTTY === true && process.stdout.isTTY === true
+
+ try {
+ if (!/^https?:$/.test(new URL(url).protocol)) {
+ throw new Error()
+ }
+ } catch (_) {
+ throw new Error('Invalid URL: ' + url)
+ }
+
+ print(npm, title, url)
+
+ if (browser === false || !isInteractive) {
+ return
+ }
+
+ const rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout,
+ })
+
+ const tryOpen = await new Promise(resolve => {
+ rl.question(prompt, () => {
+ resolve(true)
+ })
+
+ if (emitter && emitter.addListener) {
+ emitter.addListener('abort', () => {
+ rl.close()
+
+ // clear the prompt line
+ npm.output('')
+
+ resolve(false)
+ })
+ }
+ })
+
+ if (!tryOpen) {
+ return
+ }
+
+ const command = browser === true ? null : browser
+ await new Promise((resolve, reject) => {
+ opener(url, { command }, err => {
+ if (err) {
+ return reject(err)
+ }
+
+ return resolve()
+ })
+ })
+}
+
+module.exports = promptOpen