mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
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:
6
.changeset/giant-ads-provide.md
Normal file
6
.changeset/giant-ads-provide.md
Normal 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',
|
||||
|
||||
Reference in New Issue
Block a user