Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): add flatOptions.npxCache #3430

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ define('cache', {
`,
flatten (key, obj, flatOptions) {
flatOptions.cache = join(obj.cache, '_cacache')
flatOptions.npxCache = join(obj.cache, '_npx')
},
})

Expand Down
6 changes: 5 additions & 1 deletion test/lib/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ let PROGRESS_ENABLED = true
const LOG_WARN = []
let PROGRESS_IGNORED = false
const flatOptions = {
npxCache: 'npx-cache-dir',
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 Expand Up @@ -134,6 +136,8 @@ t.test('npx foo, bin already exists locally', t => {
t.match(RUN_SCRIPTS, [{
pkg: { scripts: { npx: 'foo' }},
args: ['one arg', 'two arg'],
cache: flatOptions.cache,
npxCache: flatOptions.npxCache,
banner: false,
path: process.cwd(),
stdioString: true,
Expand Down
12 changes: 10 additions & 2 deletions test/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ const npmLog = {
silly: () => null,
}
const config = {
cache: 'bad-cache-dir',
'init-module': '~/.npm-init.js',
yes: true,
}
const flatOptions = {
cache: 'test-config-dir/_cacache',
npxCache: 'test-config-dir/_npx',
}
const npm = mockNpm({
flatOptions,
config,
log: npmLog,
})
Expand Down Expand Up @@ -82,16 +88,18 @@ t.test('classic interactive npm init', t => {
})

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

const Init = t.mock('../../lib/init.js', {
libnpmexec: ({ args }) => {
libnpmexec: ({ args, cache, npxCache }) => {
t.same(
args,
['create-react-app'],
'should npx with listed packages'
)
t.same(cache, flatOptions.cache)
t.same(npxCache, flatOptions.npxCache)
},
})
const init = new Init(npm)
Expand Down
1 change: 1 addition & 0 deletions test/lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ t.test('cache', t => {
defsNix.cache.flatten('cache', { cache: '/some/cache/value' }, flat)
const {join} = require('path')
t.equal(flat.cache, join('/some/cache/value', '_cacache'))
t.equal(flat.npxCache, join('/some/cache/value', '_npx'))

t.end()
})
Expand Down