diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2017-07-09 01:20:33 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2017-07-11 03:09:54 +0300 |
commit | fb040bee0710759c60e45bf8fa2a3b8ddcf4212a (patch) | |
tree | fbd20b9c0b119495436404b8effa5a417269e80c /bin | |
parent | 88aafee8b5b232b7eeb5690279a098d056575791 (diff) |
npx: bundle npx with npm itself
npx is an npm package runner with a bunch of nice features. While
it is also available on the npm registry as `npx`, it's the sort
of thing that's better off being bundles with npm itself.
Fixes: #6053
PR-URL: https://github.com/npm/npm/pull/17685
Credit: @zkat
Reviewed-By: @iarna
Diffstat (limited to 'bin')
-rw-r--r-- | bin/npx | 34 | ||||
-rwxr-xr-x | bin/npx-cli.js | 8 | ||||
-rw-r--r-- | bin/npx.cmd | 19 |
3 files changed, 61 insertions, 0 deletions
diff --git a/bin/npx b/bin/npx new file mode 100644 index 000000000..a49c608ba --- /dev/null +++ b/bin/npx @@ -0,0 +1,34 @@ +#!/bin/sh +(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix + +basedir=`dirname "$0"` + +case `uname` in + *CYGWIN*) basedir=`cygpath -w "$basedir"`;; +esac + +NODE_EXE="$basedir/node.exe" +if ! [ -x "$NODE_EXE" ]; then + NODE_EXE=node +fi + +NPX_CLI_JS="$basedir/node_modules/npm/bin/npx-cli.js" + +case `uname` in + *MINGW*) + NPM_PREFIX=`"$NODE_EXE" "$NPX_CLI_JS" prefix -g` + NPM_PREFIX_NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js" + if [ -f "$NPM_PREFIX_NPX_CLI_JS" ]; then + NPX_CLI_JS="$NPM_PREFIX_NPX_CLI_JS" + fi + ;; + *CYGWIN*) + NPM_PREFIX=`"$NODE_EXE" "$NPX_CLI_JS" prefix -g` + NPM_PREFIX_NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js" + if [ -f "$NPM_PREFIX_NPX_CLI_JS" ]; then + NPX_CLI_JS="$NPM_PREFIX_NPX_CLI_JS" + fi + ;; +esac + +"$NODE_EXE" "$NPX_CLI_JS" "$@" diff --git a/bin/npx-cli.js b/bin/npx-cli.js new file mode 100755 index 000000000..f40436505 --- /dev/null +++ b/bin/npx-cli.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +const npx = require('libnpx') +const path = require('path') + +const NPM_PATH = path.join(__dirname, 'npm-cli.js') + +npx(npx.parseArgs(process.argv, NPM_PATH)) diff --git a/bin/npx.cmd b/bin/npx.cmd new file mode 100644 index 000000000..72526178e --- /dev/null +++ b/bin/npx.cmd @@ -0,0 +1,19 @@ +:: Created by npm, please don't edit manually.
+@ECHO OFF
+
+SETLOCAL
+
+SET "NODE_EXE=%~dp0\node.exe"
+IF NOT EXIST "%NODE_EXE%" (
+ SET "NODE_EXE=node"
+)
+
+SET "NPX_CLI_JS=%~dp0\node_modules\npm\bin\npx-cli.js"
+FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPX_CLI_JS%" prefix -g') DO (
+ SET "NPM_PREFIX_NPX_CLI_JS=%%F\node_modules\npm\bin\npx-cli.js"
+)
+IF EXIST "%NPM_PREFIX_NPX_CLI_JS%" (
+ SET "NPX_CLI_JS=%NPM_PREFIX_NPX_CLI_JS%"
+)
+
+"%NODE_EXE%" "%NPX_CLI_JS%" %*
|