From 6cf8e887ed5fd501a6d180aeae7439379b5f5e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Wed, 7 Mar 2018 23:25:16 -0800 Subject: [PATCH] fix(standard): get things in line with standard 11 --- child.js | 18 +++---- get-prefix.js | 4 +- index.js | 8 +-- package.json | 2 +- parse-args.js | 134 +++++++++++++++++++++++++------------------------- 5 files changed, 83 insertions(+), 83 deletions(-) diff --git a/child.js b/child.js index 1b7c4c6..cabc715 100644 --- a/child.js +++ b/child.js @@ -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 } diff --git a/get-prefix.js b/get-prefix.js index 3bb6780..3fef7f7 100644 --- a/get-prefix.js +++ b/get-prefix.js @@ -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 === '/' } diff --git a/index.js b/index.js index e607de6..070f75e 100644 --- a/index.js +++ b/index.js @@ -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(() => { @@ -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 { diff --git a/package.json b/package.json index e7ad2ec..6f62955 100644 --- a/package.json +++ b/package.json @@ -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'", diff --git a/parse-args.js b/parse-args.js index 41215de..3f50660 100644 --- a/parse-args.js +++ b/parse-args.js @@ -47,8 +47,8 @@ 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') { @@ -56,8 +56,8 @@ function parseArgs (argv, defaultNpm) { } 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 @@ -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()) } @@ -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