Skip to content

Commit d6830f4

Browse files
committed
deps: @npmcli/run-script@10.0.2
1 parent bcc7ec8 commit d6830f4

File tree

14 files changed

+695
-14
lines changed

14 files changed

+695
-14
lines changed

node_modules/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
!/@npmcli/query
4141
!/@npmcli/redact
4242
!/@npmcli/run-script
43+
!/@npmcli/run-script/node_modules/
44+
/@npmcli/run-script/node_modules/*
45+
!/@npmcli/run-script/node_modules/@npmcli/
46+
/@npmcli/run-script/node_modules/@npmcli/*
47+
!/@npmcli/run-script/node_modules/@npmcli/node-gyp
48+
!/@npmcli/run-script/node_modules/@npmcli/promise-spawn
49+
!/@npmcli/run-script/node_modules/proc-log
4350
!/@pkgjs/
4451
/@pkgjs/*
4552
!/@pkgjs/parseargs
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ISC License:
2+
3+
Copyright (c) 2023 by GitHub Inc.
4+
5+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const util = require('util')
2+
const fs = require('fs')
3+
const { stat } = fs.promises || { stat: util.promisify(fs.stat) }
4+
5+
async function isNodeGypPackage (path) {
6+
return await stat(`${path}/binding.gyp`)
7+
.then(st => st.isFile())
8+
.catch(() => false)
9+
}
10+
11+
module.exports = {
12+
isNodeGypPackage,
13+
defaultGypInstallScript: 'node-gyp rebuild',
14+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@npmcli/node-gyp",
3+
"version": "5.0.0",
4+
"description": "Tools for dealing with node-gyp packages",
5+
"scripts": {
6+
"test": "tap",
7+
"lint": "npm run eslint",
8+
"postlint": "template-oss-check",
9+
"template-oss-apply": "template-oss-apply --force",
10+
"lintfix": "npm run eslint -- --fix",
11+
"snap": "tap",
12+
"posttest": "npm run lint",
13+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/npm/node-gyp.git"
18+
},
19+
"keywords": [
20+
"npm",
21+
"cli",
22+
"node-gyp"
23+
],
24+
"files": [
25+
"bin/",
26+
"lib/"
27+
],
28+
"main": "lib/index.js",
29+
"author": "GitHub Inc.",
30+
"license": "ISC",
31+
"devDependencies": {
32+
"@npmcli/eslint-config": "^5.0.0",
33+
"@npmcli/template-oss": "4.27.1",
34+
"tap": "^16.0.1"
35+
},
36+
"engines": {
37+
"node": "^20.17.0 || >=22.9.0"
38+
},
39+
"templateOSS": {
40+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
41+
"version": "4.27.1",
42+
"publish": true
43+
},
44+
"tap": {
45+
"nyc-arg": [
46+
"--exclude",
47+
"tap-snapshots/**"
48+
]
49+
}
50+
}
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

0 commit comments

Comments
 (0)