Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
fix(standard): get things in line with standard 11
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 8, 2018
1 parent 8b10749 commit 6cf8e88
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 83 deletions.
18 changes: 9 additions & 9 deletions child.js
Expand Up @@ -74,13 +74,13 @@ function exec (cmd, args, opts) {
module.exports.escapeArg = escapeArg
function escapeArg (str, asPath) {
return process.platform === 'win32' && asPath
? path.normalize(str)
.split(/\\/)
.map(s => s.match(/\s+/) ? `"${s}"` : s)
.join('\\')
: process.platform === 'win32'
? `"${str}"`
: str.match(/[^-_.~/\w]/)
? `'${str.replace(/'/g, "'\"'\"'")}'`
: str
? path.normalize(str)
.split(/\\/)
.map(s => s.match(/\s+/) ? `"${s}"` : s)
.join('\\')
: process.platform === 'win32'
? `"${str}"`
: str.match(/[^-_.~/\w]/)
? `'${str.replace(/'/g, "'\"'\"'")}'`
: str
}
4 changes: 2 additions & 2 deletions get-prefix.js
Expand Up @@ -49,6 +49,6 @@ function fileExists (f) {
module.exports._isRootPath = isRootPath
function isRootPath (p, platform) {
return platform === 'win32'
? p.match(/^[a-z]+:[/\\]?$/i)
: p === '/'
? p.match(/^[a-z]+:[/\\]?$/i)
: p === '/'
}
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -142,8 +142,8 @@ function ensurePackages (specs, opts) {
).then(cache => {
const prefix = path.join(cache, '_npx', process.pid.toString())
const bins = process.platform === 'win32'
? prefix
: path.join(prefix, 'bin')
? prefix
: path.join(prefix, 'bin')
const rimraf = require('rimraf')
process.on('exit', () => rimraf.sync(prefix))
return promisify(rimraf)(bins).then(() => {
Expand Down Expand Up @@ -220,8 +220,8 @@ function installPackages (specs, prefix, opts) {
if (npmPath) {
args.unshift(
process.platform === 'win32'
? child.escapeArg(opts.npm)
: opts.npm
? child.escapeArg(opts.npm)
: opts.npm
)
return process.argv[0]
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -15,7 +15,7 @@
"docs": "tail -n +2 README.md | marked-man --manual 'User Commands' --version \"$npm_package_name@$npm_package_version\" > $npm_package_name.1",
"prerelease": "npm t && npm run docs",
"postrelease": "npm publish && git push --follow-tags",
"pretest": "standard ./*.js test bin/*.js locales",
"pretest": "standard *.js test bin/*.js locales",
"release": "standard-version -s",
"test": "cross-env NPX_UPDATE_LOCALE_FILES=true LC_ALL=en nyc --all -- tap -J test/*.js",
"update-coc": "weallbehave -o . && git add CODE_OF_CONDUCT.md && git commit -m 'docs(coc): updated CODE_OF_CONDUCT.md'",
Expand Down
134 changes: 67 additions & 67 deletions parse-args.js
Expand Up @@ -47,17 +47,17 @@ function parseArgs (argv, defaultNpm) {
const parsed = parser.parse(argv.slice(0, cmdIndex))
const parsedCmd = npa(argv[cmdIndex])
parsed.command = parsed.package && parsedCmd.type !== 'directory'
? argv[cmdIndex]
: guessCmdName(parsedCmd)
? argv[cmdIndex]
: guessCmdName(parsedCmd)
parsed.isLocal = parsedCmd.type === 'directory'
parsed.cmdOpts = argv.slice(cmdIndex + 1)
if (typeof parsed.package === 'string') {
parsed.package = [parsed.package]
}
parsed.packageRequested = !!parsed.package
parsed.cmdHadVersion = parsed.package || parsedCmd.type === 'directory'
? false
: parsedCmd.name !== parsedCmd.raw
? false
: parsedCmd.name !== parsedCmd.raw
const pkg = parsed.package || [argv[cmdIndex]]
parsed.p = parsed.package = pkg.map(p => npa(p).toString())
return parsed
Expand All @@ -80,13 +80,13 @@ function parseArgs (argv, defaultNpm) {
const splitCmd = parsed._.slice(2)
const parsedCmd = npa(splitCmd[0])
parsed.command = parsed.package
? splitCmd[0]
: guessCmdName(parsedCmd)
? splitCmd[0]
: guessCmdName(parsedCmd)
parsed.cmdOpts = splitCmd.slice(1)
parsed.packageRequested = !!parsed.package
parsed.cmdHadVersion = parsed.package
? false
: parsedCmd.name !== parsedCmd.raw
? false
: parsedCmd.name !== parsedCmd.raw
const pkg = parsed.package || [splitCmd[0]]
parsed.p = parsed.package = pkg.map(p => npa(p).toString())
}
Expand Down Expand Up @@ -169,65 +169,65 @@ function yargsParser (argv, defaultNpm) {
`

return require('yargs')
.usage(Y()`Execute binaries from npm packages.\n${usage}`)
.option('package', {
alias: 'p',
type: 'string',
describe: Y()`Package to be installed.`
})
.option('cache', {
type: 'string',
describe: Y()`Location of the npm cache.`
})
.option('no-install', {
type: 'boolean',
describe: Y()`Skip installation if a package is missing.`
})
.option('userconfig', {
type: 'string',
describe: Y()`Path to user npmrc.`
})
.option('call', {
alias: 'c',
type: 'string',
describe: Y()`Execute string as if inside \`npm run-script\`.`
})
.option('shell', {
alias: 's',
type: 'string',
describe: Y()`Shell to execute the command with, if any.`,
default: false
})
.option('shell-auto-fallback', {
choices: ['', 'bash', 'fish', 'zsh'],
describe: Y()`Generate shell code to use npx as the "command not found" fallback.`,
requireArg: false,
type: 'string'
})
.option('ignore-existing', {
describe: Y()`Ignores existing binaries in $PATH, or in the local project. This forces npx to do a temporary install and use the latest version.`,
type: 'boolean'
})
.option('quiet', {
alias: 'q',
describe: Y()`Suppress output from npx itself. Subcommands will not be affected.`,
type: 'boolean'
})
.option('npm', {
describe: Y()`npm binary to use for internal operations.`,
type: 'string',
default: defaultNpm || 'npm'
})
.option('node-arg', {
alias: 'n',
type: 'string',
describe: Y()`Extra node argument when calling a node binary.`
})
.version()
.alias('version', 'v')
.help()
.alias('help', 'h')
.epilogue(Y()`For the full documentation, see the manual page for npx(1).`)
.usage(Y()`Execute binaries from npm packages.\n${usage}`)
.option('package', {
alias: 'p',
type: 'string',
describe: Y()`Package to be installed.`
})
.option('cache', {
type: 'string',
describe: Y()`Location of the npm cache.`
})
.option('no-install', {
type: 'boolean',
describe: Y()`Skip installation if a package is missing.`
})
.option('userconfig', {
type: 'string',
describe: Y()`Path to user npmrc.`
})
.option('call', {
alias: 'c',
type: 'string',
describe: Y()`Execute string as if inside \`npm run-script\`.`
})
.option('shell', {
alias: 's',
type: 'string',
describe: Y()`Shell to execute the command with, if any.`,
default: false
})
.option('shell-auto-fallback', {
choices: ['', 'bash', 'fish', 'zsh'],
describe: Y()`Generate shell code to use npx as the "command not found" fallback.`,
requireArg: false,
type: 'string'
})
.option('ignore-existing', {
describe: Y()`Ignores existing binaries in $PATH, or in the local project. This forces npx to do a temporary install and use the latest version.`,
type: 'boolean'
})
.option('quiet', {
alias: 'q',
describe: Y()`Suppress output from npx itself. Subcommands will not be affected.`,
type: 'boolean'
})
.option('npm', {
describe: Y()`npm binary to use for internal operations.`,
type: 'string',
default: defaultNpm || 'npm'
})
.option('node-arg', {
alias: 'n',
type: 'string',
describe: Y()`Extra node argument when calling a node binary.`
})
.version()
.alias('version', 'v')
.help()
.alias('help', 'h')
.epilogue(Y()`For the full documentation, see the manual page for npx(1).`)
}

var _y
Expand Down

0 comments on commit 6cf8e88

Please sign in to comment.