feat(config): get on array (#7917)

* refactor(config): return type annotations

* refactor: simplify configGet

* test: fix typescript errors

* feat(config): get on array

* feat(config): use comma instead

* lint: fix
This commit is contained in:
Khải
2024-04-13 19:14:52 +07:00
committed by GitHub
parent ea58e1d438
commit e0f47f45e4
3 changed files with 24 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/config": minor
"pnpm": minor
---
`pnpm config get` now prints a comma-separated list for an array value instead of nothing.

View File

@@ -2,5 +2,5 @@ import { type ConfigCommandOptions } from './ConfigCommandOptions'
export function configGet (opts: ConfigCommandOptions, key: string): string {
const config = opts.rawConfig[key]
return String(config)
return Array.isArray(config) ? config.join(',') : String(config)
}

View File

@@ -28,6 +28,23 @@ test('config get a boolean should return string format', async () => {
expect(configKey).toEqual('true')
})
test('config get on array should return a comma-separated list', async () => {
const configKey = await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir: process.cwd(),
global: true,
rawConfig: {
'public-hoist-pattern': [
'*eslint*',
'*prettier*',
],
},
}, ['get', 'public-hoist-pattern'])
expect(configKey).toBe('*eslint*,*prettier*')
})
test('config get without key show list all settings ', async () => {
const rawConfig = {
'store-dir': '~/store',