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 authored and GitHub committed 2024-04-13 14:14:52 +02:00
1 parent ea58e1d438
commit e0f47f45e4
3 files changed
+24 -1

No files matched your search

+6
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.
@@ -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)
}
@@ -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',