Skip to content

Commit

Permalink
fix(npx): use proper cache param
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wraithgar committed Jun 16, 2021
1 parent 16a95c6 commit 84d640f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class Exec extends BaseCommand {
// can be named correctly
async _exec (_args, { locationMsg, path, runPath }) {
const args = [..._args]
const cache = this.npm.config.get('cache')
const call = this.npm.config.get('call')
const color = this.npm.config.get('color')
const {
Expand All @@ -88,7 +87,6 @@ class Exec extends BaseCommand {
...flatOptions,
args,
call,
cache,
color,
localBin,
locationMsg,
Expand Down
2 changes: 0 additions & 2 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class Init extends BaseCommand {
}

const newArgs = [packageName, ...otherArgs]
const cache = this.npm.config.get('cache')
const { color } = this.npm.flatOptions
const {
flatOptions,
Expand All @@ -128,7 +127,6 @@ class Init extends BaseCommand {
await libexec({
...flatOptions,
args: newArgs,
cache,
color,
localBin,
locationMsg,
Expand Down
3 changes: 2 additions & 1 deletion test/lib/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ let PROGRESS_ENABLED = true
const LOG_WARN = []
let PROGRESS_IGNORED = false
const flatOptions = {
cache: 'cache-dir',
legacyPeerDeps: false,
package: [],
}
const config = {
cache: 'cache-dir',
cache: 'bad-cache-dir', //this should never show up passed into libnpmexec
yes: true,
call: '',
package: [],
Expand Down
9 changes: 7 additions & 2 deletions test/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ const npmLog = {
silly: () => null,
}
const config = {
cache: 'bad-cache-dir',
'init-module': '~/.npm-init.js',
yes: true,
}
const npm = mockNpm({
flatOptions: {
cache: 'test-config-dir'
},
config,
log: npmLog,
})
Expand Down Expand Up @@ -82,16 +86,17 @@ t.test('classic interactive npm init', t => {
})

t.test('npm init <arg>', t => {
t.plan(1)
t.plan(2)
npm.localPrefix = t.testdir({})

const Init = t.mock('../../lib/init.js', {
libnpmexec: ({ args }) => {
libnpmexec: ({ args, cache }) => {
t.same(
args,
['create-react-app'],
'should npx with listed packages'
)
t.same(cache, 'test-config-dir')
},
})
const init = new Init(npm)
Expand Down

0 comments on commit 84d640f

Please sign in to comment.