Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2020-07-31 04:33:55 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2020-07-31 19:37:36 +0300
commit5473bbda76fd0fbb3d8321c19bc045c71c06a44c (patch)
tree96c2a0760017ea60b006410fea232dc77d34a6cd /bin/npx-cli.js
parentbcc663807330c21dffe4b7cf7647d0dbcd48a022 (diff)
Add 'npm exec', port npx to use it directly
This removes libnpx, and adds a new command, 'npm exec', which implements the functionality. As of this change going live, we are dropping support for the standalone top-level package 'npx'. Not all of the functionality of the old version of npx is maintained. The shell fallback functionality is dropped. It's insecure, and not something we want to support or encourage. If anyone wants it, they can hack up their .bashrc file themselves. --no-install is not supported. If the package is not found locally, it is installed in a predictable location in the cache, rather than failing. This is something we might want to review, as automatically installing in the case of misspellings may be a security footgun. --ignore-existing is dropped. Existing packages are always given priority. --quiet or -q can be accomplished by using the --silent npm option, so it's also dropped. --npm option is dropped. npx will always use the npm that it ships with. --node-arg is dropped. There are other ways to set node options via environment variables in the Node.js versions we support. --always-spawn is dropped. npx will always spawn a child process to execute commands. The --shell option can be accomplished by using the --script-shell npm option. --version and --help are just passed through to npm. As an added bonus, I noticed that the files in `bin/` were not getting run. So now we have full coverage for npm-cli.js and npx-cli.js. PR-URL: https://github.com/npm/cli/pull/1588 Credit: @isaacs Close: #1588 Reviewed-by: @ruyadorno
Diffstat (limited to 'bin/npx-cli.js')
-rw-r--r--[-rwxr-xr-x]bin/npx-cli.js30
1 files changed, 26 insertions, 4 deletions
diff --git a/bin/npx-cli.js b/bin/npx-cli.js
index f40436505..dc2072ffd 100755..100644
--- a/bin/npx-cli.js
+++ b/bin/npx-cli.js
@@ -1,8 +1,30 @@
#!/usr/bin/env node
-const npx = require('libnpx')
-const path = require('path')
+const cli = require('../lib/cli.js')
-const NPM_PATH = path.join(__dirname, 'npm-cli.js')
+// run the resulting command as `npm exec ...args`
+process.argv[1] = require.resolve('./npm-cli.js')
+process.argv.splice(2, 0, 'exec')
-npx(npx.parseArgs(process.argv, NPM_PATH))
+// break out of loop when we find a positional argument or --
+// If we find a positional arg, we shove -- in front of it, and
+// let the normal npm cli handle the rest.
+let i
+for (i = 3; i < process.argv.length; i++) {
+ const arg = process.argv[i]
+ if (arg === '--') {
+ break
+ } else if (/^-/.test(arg)) {
+ // `--package foo` treated the same as `--package=foo`
+ if (!arg.includes('=')) {
+ i++
+ }
+ continue
+ } else {
+ // found a positional arg, put -- in front of it, and we're done
+ process.argv.splice(i, 0, '--')
+ break
+ }
+}
+
+cli(process)