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): the --location=global CLI option should work #5843

Merged
merged 2 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/brave-coats-beam.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're missing a location: 'project', test case

rawConfig: {},
}, ['set', 'fetch-retries', '1'])

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