Skip to content

Commit

Permalink
remove puka
Browse files Browse the repository at this point in the history
PR-URL: #22
Credit: @nlf
Close: #22
Reviewed-by: @ruyadorno
  • Loading branch information
nlf authored and ruyadorno committed Mar 9, 2021
1 parent f976fd3 commit eeeb3f4
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 37 deletions.
20 changes: 1 addition & 19 deletions lib/make-spawn-args.js
Expand Up @@ -3,24 +3,6 @@ const isWindows = require('./is-windows.js')
const setPATH = require('./set-path.js')
const {resolve} = require('path')
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
const { quoteForShell, ShellString, ShellStringText, ShellStringUnquoted } = require('puka')

const escapeCmd = cmd => {
const result = []
const parsed = ShellString.sh([cmd])
for (const child of parsed.children) {
if (child instanceof ShellStringText) {
const children = child.contents.filter(segment => segment !== null).map(segment => quoteForShell(segment, false, isWindows && 'win32'))
result.push(...children)
} else if (child instanceof ShellStringUnquoted) {
result.push(child.value)
} else {
result.push(isWindows ? '&' : ';')
}
}

return result.join('')
}

const makeSpawnArgs = options => {
const {
Expand All @@ -34,7 +16,7 @@ const makeSpawnArgs = options => {
} = options

const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
const args = isCmd ? ['/d', '/s', '/c', escapeCmd(cmd)] : ['-c', cmd]
const args = isCmd ? ['/d', '/s', '/c', cmd] : ['-c', cmd]

const spawnOpts = {
env: setPATH(path, {
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -32,7 +32,6 @@
"@npmcli/promise-spawn": "^1.3.2",
"infer-owner": "^1.0.4",
"node-gyp": "^7.1.0",
"puka": "^1.0.1",
"read-package-json-fast": "^2.0.1"
},
"files": [
Expand Down
6 changes: 3 additions & 3 deletions test/make-spawn-args.js
Expand Up @@ -24,7 +24,7 @@ if (isWindows) {
cmd: 'script "quoted parameter"; second command',
}), [
'cmd',
[ '/d', '/s', '/c', `script "quoted parameter"& second command` ],
[ '/d', '/s', '/c', `script \"quoted parameter\"; second command` ],
{
env: {
npm_package_json: /package\.json$/,
Expand Down Expand Up @@ -66,7 +66,7 @@ if (isWindows) {
scriptShell: 'cmd.exe',
}), [
'cmd.exe',
[ '/d', '/s', '/c', `script "quoted parameter"& second command` ],
[ '/d', '/s', '/c', `script \"quoted parameter\"; second command` ],
{
env: {
npm_package_json: /package\.json$/,
Expand Down Expand Up @@ -113,7 +113,7 @@ if (isWindows) {
scriptShell: 'cmd.exe',
}), [
'cmd.exe',
[ '/d', '/s', '/c', `script 'quoted parameter'; second command` ],
[ '/d', '/s', '/c', `script \"quoted parameter\"; second command` ],
{
env: {
npm_package_json: /package\.json$/,
Expand Down

0 comments on commit eeeb3f4

Please sign in to comment.