Skip to content

Commit 89c4151

Browse files
committed
deps: @npmcli/[email protected]
1 parent c6d109d commit 89c4151

File tree

20 files changed

+1184
-193
lines changed

20 files changed

+1184
-193
lines changed

node_modules/.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@
2323
!/@npmcli/git
2424
!/@npmcli/git/node_modules/
2525
/@npmcli/git/node_modules/*
26-
!/@npmcli/git/node_modules/proc-log
26+
!/@npmcli/git/node_modules/@npmcli/
27+
/@npmcli/git/node_modules/@npmcli/*
28+
!/@npmcli/git/node_modules/@npmcli/promise-spawn
29+
!/@npmcli/git/node_modules/@npmcli/promise-spawn/node_modules/
30+
/@npmcli/git/node_modules/@npmcli/promise-spawn/node_modules/*
31+
!/@npmcli/git/node_modules/@npmcli/promise-spawn/node_modules/which
32+
!/@npmcli/git/node_modules/ini
33+
!/@npmcli/git/node_modules/which
2734
!/@npmcli/installed-package-contents
2835
!/@npmcli/map-workspaces
2936
!/@npmcli/metavuln-calculator
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) npm, Inc.
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE NPM DISCLAIMS ALL WARRANTIES WITH
10+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11+
FITNESS. IN NO EVENT SHALL THE NPM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
12+
OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
13+
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14+
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15+
SOFTWARE.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict'
2+
3+
// this code adapted from: https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
4+
const cmd = (input, doubleEscape) => {
5+
if (!input.length) {
6+
return '""'
7+
}
8+
9+
let result
10+
if (!/[ \t\n\v"]/.test(input)) {
11+
result = input
12+
} else {
13+
result = '"'
14+
for (let i = 0; i <= input.length; ++i) {
15+
let slashCount = 0
16+
while (input[i] === '\\') {
17+
++i
18+
++slashCount
19+
}
20+
21+
if (i === input.length) {
22+
result += '\\'.repeat(slashCount * 2)
23+
break
24+
}
25+
26+
if (input[i] === '"') {
27+
result += '\\'.repeat(slashCount * 2 + 1)
28+
result += input[i]
29+
} else {
30+
result += '\\'.repeat(slashCount)
31+
result += input[i]
32+
}
33+
}
34+
result += '"'
35+
}
36+
37+
// and finally, prefix shell meta chars with a ^
38+
result = result.replace(/[ !%^&()<>|"]/g, '^$&')
39+
if (doubleEscape) {
40+
result = result.replace(/[ !%^&()<>|"]/g, '^$&')
41+
}
42+
43+
return result
44+
}
45+
46+
const sh = (input) => {
47+
if (!input.length) {
48+
return `''`
49+
}
50+
51+
if (!/[\t\n\r "#$&'()*;<>?\\`|~]/.test(input)) {
52+
return input
53+
}
54+
55+
// replace single quotes with '\'' and wrap the whole result in a fresh set of quotes
56+
const result = `'${input.replace(/'/g, `'\\''`)}'`
57+
// if the input string already had single quotes around it, clean those up
58+
.replace(/^(?:'')+(?!$)/, '')
59+
.replace(/\\'''/g, `\\'`)
60+
61+
return result
62+
}
63+
64+
module.exports = {
65+
cmd,
66+
sh,
67+
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
'use strict'
2+
3+
const { spawn } = require('child_process')
4+
const os = require('os')
5+
const which = require('which')
6+
7+
const escape = require('./escape.js')
8+
9+
// 'extra' object is for decorating the error a bit more
10+
const promiseSpawn = (cmd, args, opts = {}, extra = {}) => {
11+
if (opts.shell) {
12+
return spawnWithShell(cmd, args, opts, extra)
13+
}
14+
15+
let resolve, reject
16+
const promise = new Promise((_resolve, _reject) => {
17+
resolve = _resolve
18+
reject = _reject
19+
})
20+
21+
// Create error here so we have a more useful stack trace when rejecting
22+
const closeError = new Error('command failed')
23+
24+
const stdout = []
25+
const stderr = []
26+
27+
const getResult = (result) => ({
28+
cmd,
29+
args,
30+
...result,
31+
...stdioResult(stdout, stderr, opts),
32+
...extra,
33+
})
34+
const rejectWithOpts = (er, erOpts) => {
35+
const resultError = getResult(erOpts)
36+
reject(Object.assign(er, resultError))
37+
}
38+
39+
const proc = spawn(cmd, args, opts)
40+
promise.stdin = proc.stdin
41+
promise.process = proc
42+
43+
proc.on('error', rejectWithOpts)
44+
45+
if (proc.stdout) {
46+
proc.stdout.on('data', c => stdout.push(c))
47+
proc.stdout.on('error', rejectWithOpts)
48+
}
49+
50+
if (proc.stderr) {
51+
proc.stderr.on('data', c => stderr.push(c))
52+
proc.stderr.on('error', rejectWithOpts)
53+
}
54+
55+
proc.on('close', (code, signal) => {
56+
if (code || signal) {
57+
rejectWithOpts(closeError, { code, signal })
58+
} else {
59+
resolve(getResult({ code, signal }))
60+
}
61+
})
62+
63+
return promise
64+
}
65+
66+
const spawnWithShell = (cmd, args, opts, extra) => {
67+
let command = opts.shell
68+
// if shell is set to true, we use a platform default. we can't let the core
69+
// spawn method decide this for us because we need to know what shell is in use
70+
// ahead of time so that we can escape arguments properly. we don't need coverage here.
71+
if (command === true) {
72+
// istanbul ignore next
73+
command = process.platform === 'win32' ? (process.env.ComSpec || 'cmd.exe') : 'sh'
74+
}
75+
76+
const options = { ...opts, shell: false }
77+
const realArgs = []
78+
let script = cmd
79+
80+
// first, determine if we're in windows because if we are we need to know if we're
81+
// running an .exe or a .cmd/.bat since the latter requires extra escaping
82+
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(command)
83+
if (isCmd) {
84+
let doubleEscape = false
85+
86+
// find the actual command we're running
87+
let initialCmd = ''
88+
let insideQuotes = false
89+
for (let i = 0; i < cmd.length; ++i) {
90+
const char = cmd.charAt(i)
91+
if (char === ' ' && !insideQuotes) {
92+
break
93+
}
94+
95+
initialCmd += char
96+
if (char === '"' || char === "'") {
97+
insideQuotes = !insideQuotes
98+
}
99+
}
100+
101+
let pathToInitial
102+
try {
103+
pathToInitial = which.sync(initialCmd, {
104+
path: (options.env && findInObject(options.env, 'PATH')) || process.env.PATH,
105+
pathext: (options.env && findInObject(options.env, 'PATHEXT')) || process.env.PATHEXT,
106+
}).toLowerCase()
107+
} catch (err) {
108+
pathToInitial = initialCmd.toLowerCase()
109+
}
110+
111+
doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')
112+
for (const arg of args) {
113+
script += ` ${escape.cmd(arg, doubleEscape)}`
114+
}
115+
realArgs.push('/d', '/s', '/c', script)
116+
options.windowsVerbatimArguments = true
117+
} else {
118+
for (const arg of args) {
119+
script += ` ${escape.sh(arg)}`
120+
}
121+
realArgs.push('-c', script)
122+
}
123+
124+
return promiseSpawn(command, realArgs, options, extra)
125+
}
126+
127+
// open a file with the default application as defined by the user's OS
128+
const open = (_args, opts = {}, extra = {}) => {
129+
const options = { ...opts, shell: true }
130+
const args = [].concat(_args)
131+
132+
let platform = process.platform
133+
// process.platform === 'linux' may actually indicate WSL, if that's the case
134+
// open the argument with sensible-browser which is pre-installed
135+
// In WSL, set the default browser using, for example,
136+
// export BROWSER="/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"
137+
// or
138+
// export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
139+
// To permanently set the default browser, add the appropriate entry to your shell's
140+
// RC file, e.g. .bashrc or .zshrc.
141+
if (platform === 'linux' && os.release().toLowerCase().includes('microsoft')) {
142+
platform = 'wsl'
143+
if (!process.env.BROWSER) {
144+
return Promise.reject(
145+
new Error('Set the BROWSER environment variable to your desired browser.'))
146+
}
147+
}
148+
149+
let command = options.command
150+
if (!command) {
151+
if (platform === 'win32') {
152+
// spawnWithShell does not do the additional os.release() check, so we
153+
// have to force the shell here to make sure we treat WSL as windows.
154+
options.shell = process.env.ComSpec
155+
// also, the start command accepts a title so to make sure that we don't
156+
// accidentally interpret the first arg as the title, we stick an empty
157+
// string immediately after the start command
158+
command = 'start ""'
159+
} else if (platform === 'wsl') {
160+
command = 'sensible-browser'
161+
} else if (platform === 'darwin') {
162+
command = 'open'
163+
} else {
164+
command = 'xdg-open'
165+
}
166+
}
167+
168+
return spawnWithShell(command, args, options, extra)
169+
}
170+
promiseSpawn.open = open
171+
172+
const isPipe = (stdio = 'pipe', fd) => {
173+
if (stdio === 'pipe' || stdio === null) {
174+
return true
175+
}
176+
177+
if (Array.isArray(stdio)) {
178+
return isPipe(stdio[fd], fd)
179+
}
180+
181+
return false
182+
}
183+
184+
const stdioResult = (stdout, stderr, { stdioString = true, stdio }) => {
185+
const result = {
186+
stdout: null,
187+
stderr: null,
188+
}
189+
190+
// stdio is [stdin, stdout, stderr]
191+
if (isPipe(stdio, 1)) {
192+
result.stdout = Buffer.concat(stdout)
193+
if (stdioString) {
194+
result.stdout = result.stdout.toString().trim()
195+
}
196+
}
197+
198+
if (isPipe(stdio, 2)) {
199+
result.stderr = Buffer.concat(stderr)
200+
if (stdioString) {
201+
result.stderr = result.stderr.toString().trim()
202+
}
203+
}
204+
205+
return result
206+
}
207+
208+
// case insensitive lookup in an object
209+
const findInObject = (obj, key) => {
210+
key = key.toLowerCase()
211+
for (const objKey of Object.keys(obj).sort()) {
212+
if (objKey.toLowerCase() === key) {
213+
return obj[objKey]
214+
}
215+
}
216+
}
217+
218+
module.exports = promiseSpawn

node_modules/@npmcli/git/node_modules/proc-log/LICENSE renamed to node_modules/@npmcli/git/node_modules/@npmcli/promise-spawn/node_modules/which/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The ISC License
22

3-
Copyright (c) GitHub, Inc.
3+
Copyright (c) Isaac Z. Schlueter and Contributors
44

55
Permission to use, copy, modify, and/or distribute this software for any
66
purpose with or without fee is hereby granted, provided that the above
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env node
2+
3+
const which = require('../lib')
4+
const argv = process.argv.slice(2)
5+
6+
const usage = (err) => {
7+
if (err) {
8+
console.error(`which: ${err}`)
9+
}
10+
console.error('usage: which [-as] program ...')
11+
process.exit(1)
12+
}
13+
14+
if (!argv.length) {
15+
return usage()
16+
}
17+
18+
let dashdash = false
19+
const [commands, flags] = argv.reduce((acc, arg) => {
20+
if (dashdash || arg === '--') {
21+
dashdash = true
22+
return acc
23+
}
24+
25+
if (!/^-/.test(arg)) {
26+
acc[0].push(arg)
27+
return acc
28+
}
29+
30+
for (const flag of arg.slice(1).split('')) {
31+
if (flag === 's') {
32+
acc[1].silent = true
33+
} else if (flag === 'a') {
34+
acc[1].all = true
35+
} else {
36+
usage(`illegal option -- ${flag}`)
37+
}
38+
}
39+
40+
return acc
41+
}, [[], {}])
42+
43+
for (const command of commands) {
44+
try {
45+
const res = which.sync(command, { all: flags.all })
46+
if (!flags.silent) {
47+
console.log([].concat(res).join('\n'))
48+
}
49+
} catch (err) {
50+
process.exitCode = 1
51+
}
52+
}

0 commit comments

Comments
 (0)