Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Commit

Permalink
feat(node-path): append temp packages to $NODE_PATH
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zkat committed May 3, 2018
1 parent cf6437c commit 0366a0d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ function ensurePackages (specs, opts) {
const bins = process.platform === 'win32'
? prefix
: path.join(prefix, 'bin')
const libs = process.platform === 'win32'
? path.join(prefix, 'node_modules')
: path.join(prefix, 'lib', 'node_modules')
const rimraf = require('rimraf')
process.on('exit', () => rimraf.sync(prefix))
return promisify(rimraf)(bins).then(() => {
Expand All @@ -156,6 +159,7 @@ function ensurePackages (specs, opts) {
// This is intentional, since npx assumes that if you went through
// the trouble of doing `-p`, you're rather have that one. Right? ;)
process.env.PATH = `${bins}${path.delimiter}${process.env.PATH}`
process.env.NODE_PATH = `${libs}${path.delimiter}${process.env.NODE_PATH || ''}`
if (!info) { info = {} }
info.prefix = prefix
info.bin = bins
Expand Down

0 comments on commit 0366a0d

Please sign in to comment.