npx
npx copied to clipboard
feat(node-path): append temp packages to $NODE_PATH
Ref: #160
This makes it so you can do npx -p lodash node -r lodash
when lodash is not
already installed. One big downside of this patch is that because of the semantics
of that node feature, NODE_PATH will always be treated as a fallback. That is, if
you already have one version of lodash installed in a local npm project you're
currently in the directory of, you won't be able to override it with the
temporary install.
I threw together a sloppy, terribad, not OS-independent workaround while we wait for this one.
$ npx -q -p lodash -p @sisk/npx repl -e "console.log(require('lodash').VERSION)"
4.17.10
$ npx -q -p lodash -p @sisk/npx exec sh -c 'echo ${NODE_PATH}'
/Users/kittens/.npm/_npx/80711/lib/node_modules
The bins are this nightmare:
#!/bin/sh
NODE_PATH="$(printf "%s" "$PATH" | sed -e 's/:.*$//' -e 's:/[^/]*$::')"
[ "${0##*/}" = 'repl' ] && set -- node "$@"
exec env NODE_PATH="$NODE_PATH/lib/node_modules" "$@"