Skip to content

Commit 54f5db5

Browse files
committed
fix(npx): use proper cache param
The `flatOptions` cache is the one that is intended to be passed down into other modules, as it has the `_cacache` suffix attached. What was happening before was that `npx` was creating a new alternate cache one directory up from where everything else was, and also putting the `_npx` content there. It is possible this is the source of at least some of our "npx doesn't find the right versions" bugs.
1 parent 16a95c6 commit 54f5db5

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

lib/exec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class Exec extends BaseCommand {
6767
// can be named correctly
6868
async _exec (_args, { locationMsg, path, runPath }) {
6969
const args = [..._args]
70-
const cache = this.npm.config.get('cache')
7170
const call = this.npm.config.get('call')
7271
const color = this.npm.config.get('color')
7372
const {
@@ -88,7 +87,6 @@ class Exec extends BaseCommand {
8887
...flatOptions,
8988
args,
9089
call,
91-
cache,
9290
color,
9391
localBin,
9492
locationMsg,

lib/init.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class Init extends BaseCommand {
106106
}
107107

108108
const newArgs = [packageName, ...otherArgs]
109-
const cache = this.npm.config.get('cache')
110109
const { color } = this.npm.flatOptions
111110
const {
112111
flatOptions,
@@ -128,7 +127,6 @@ class Init extends BaseCommand {
128127
await libexec({
129128
...flatOptions,
130129
args: newArgs,
131-
cache,
132130
color,
133131
localBin,
134132
locationMsg,

test/lib/exec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ let PROGRESS_ENABLED = true
2424
const LOG_WARN = []
2525
let PROGRESS_IGNORED = false
2626
const flatOptions = {
27+
cache: 'cache-dir',
2728
legacyPeerDeps: false,
2829
package: [],
2930
}
3031
const config = {
31-
cache: 'cache-dir',
32+
cache: 'bad-cache-dir', // this should never show up passed into libnpmexec
3233
yes: true,
3334
call: '',
3435
package: [],

test/lib/init.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ const npmLog = {
1212
silly: () => null,
1313
}
1414
const config = {
15+
cache: 'bad-cache-dir',
1516
'init-module': '~/.npm-init.js',
1617
yes: true,
1718
}
1819
const npm = mockNpm({
20+
flatOptions: {
21+
cache: 'test-config-dir',
22+
},
1923
config,
2024
log: npmLog,
2125
})
@@ -82,16 +86,17 @@ t.test('classic interactive npm init', t => {
8286
})
8387

8488
t.test('npm init <arg>', t => {
85-
t.plan(1)
89+
t.plan(2)
8690
npm.localPrefix = t.testdir({})
8791

8892
const Init = t.mock('../../lib/init.js', {
89-
libnpmexec: ({ args }) => {
93+
libnpmexec: ({ args, cache }) => {
9094
t.same(
9195
args,
9296
['create-react-app'],
9397
'should npx with listed packages'
9498
)
99+
t.same(cache, 'test-config-dir')
95100
},
96101
})
97102
const init = new Init(npm)

0 commit comments

Comments
 (0)