From 0366a0db497686240ad398cfbc5029c974e27968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Thu, 3 May 2018 14:48:01 -0700 Subject: [PATCH] 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. --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 21f44b3..54ef4ea 100644 --- a/index.js +++ b/index.js @@ -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(() => { @@ -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