Skip to content

Commit

Permalink
fix(config): the --location=global CLI option should work
Browse files Browse the repository at this point in the history
ref #5841
  • Loading branch information
zkochan committed Dec 27, 2022
1 parent b3dfa3b commit 2ff5f52
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/brave-coats-beam.md
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-config": patch
"pnpm": patch
---

The config command should work with the `--location=global` CLI option [#5841](https://github.com/pnpm/pnpm/issues/5841).
5 changes: 4 additions & 1 deletion config/plugin-commands-config/src/ConfigCommandOptions.ts
Expand Up @@ -5,4 +5,7 @@ export type ConfigCommandOptions = Pick<Config,
| 'dir'
| 'global'
| 'rawConfig'
> & { json?: boolean }
> & {
json?: boolean
location?: 'global' | 'project'
}
4 changes: 4 additions & 0 deletions config/plugin-commands-config/src/config.ts
Expand Up @@ -13,6 +13,7 @@ export function rcOptionsTypes () {
export function cliOptionsTypes () {
return {
global: Boolean,
location: ['global', 'project'],
json: Boolean,
}
}
Expand Down Expand Up @@ -71,6 +72,9 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) {
hint: help(),
})
}
if (opts.location) {
opts.global = opts.location === 'global'
}
switch (params[0]) {
case 'set': {
return configSet(opts, params[1], params[2] ?? '')
Expand Down
39 changes: 38 additions & 1 deletion config/plugin-commands-config/test/configSet.test.ts
Expand Up @@ -4,7 +4,7 @@ import { tempDir } from '@pnpm/prepare'
import { config } from '@pnpm/plugin-commands-config'
import { readIniFileSync } from 'read-ini-file'

test('config set', async () => {
test('config set using the global option', async () => {
const tmp = tempDir()
const configDir = path.join(tmp, 'global-config')
fs.mkdirSync(configDir, { recursive: true })
Expand All @@ -22,3 +22,40 @@ test('config set', async () => {
'fetch-retries': '1',
})
})

test('config set using the location=global option', async () => {
const tmp = tempDir()
const configDir = path.join(tmp, 'global-config')
fs.mkdirSync(configDir, { recursive: true })
fs.writeFileSync(path.join(configDir, 'rc'), 'store-dir=~/store')

await config.handler({
dir: process.cwd(),
configDir,
location: 'global',
rawConfig: {},
}, ['set', 'fetch-retries', '1'])

expect(readIniFileSync(path.join(configDir, 'rc'))).toEqual({
'store-dir': '~/store',
'fetch-retries': '1',
})
})

test('config set in project .npmrc file', async () => {
const tmp = tempDir()
const configDir = path.join(tmp, 'global-config')
fs.writeFileSync(path.join(tmp, '.npmrc'), 'store-dir=~/store')

await config.handler({
dir: process.cwd(),
configDir,
global: false,
rawConfig: {},
}, ['set', 'fetch-retries', '1'])

expect(readIniFileSync(path.join(tmp, '.npmrc'))).toEqual({
'store-dir': '~/store',
'fetch-retries': '1',
})
})

0 comments on commit 2ff5f52

Please sign in to comment.