fix: config set should write to the global config file (#6132)

close #5877
close #6131
This commit is contained in:
Zoltan Kochan
2023-02-25 18:15:38 +02:00
committed by GitHub
parent f39d608acb
commit a3e0223ce4
7 changed files with 24 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-config": patch
"pnpm": patch
---
`pnpm config set` should write to the global config file by default [#5877](https://github.com/pnpm/pnpm/issues/5877).

View File

@@ -2,6 +2,7 @@ import { Config } from '@pnpm/config'
export type ConfigCommandOptions = Pick<Config,
| 'configDir'
| 'cliOptions'
| 'dir'
| 'global'
| 'rawConfig'

View File

@@ -53,6 +53,10 @@ export function help () {
name: '--global',
shortAlias: '-g',
},
{
description: 'When set to "project", the .npmrc file at the nearest package.json will be used',
name: '--location <project|global>',
},
],
},
],
@@ -74,6 +78,8 @@ export async function handler (opts: ConfigCommandOptions, params: string[]) {
}
if (opts.location) {
opts.global = opts.location === 'global'
} else if (opts.cliOptions['global'] == null) {
opts.global = true
}
switch (params[0]) {
case 'set': {

View File

@@ -13,6 +13,7 @@ cache-dir=~/cache`)
await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
global: true,
rawConfig: {},

View File

@@ -3,6 +3,7 @@ import { config } from '@pnpm/plugin-commands-config'
test('config get', async () => {
const configKey = await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir: process.cwd(),
global: true,
rawConfig: {

View File

@@ -9,6 +9,7 @@ function normalizeNewlines (str: string) {
test('config list', async () => {
const output = await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir: process.cwd(),
rawConfig: {
'store-dir': '~/store',
@@ -24,6 +25,7 @@ store-dir=~/store
test('config list --json', async () => {
const output = await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir: process.cwd(),
json: true,
rawConfig: {

View File

@@ -12,6 +12,7 @@ test('config set using the global option', async () => {
await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
global: true,
rawConfig: {},
@@ -31,6 +32,7 @@ test('config set using the location=global option', async () => {
await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
location: 'global',
rawConfig: {},
@@ -50,6 +52,7 @@ test('config set using the location=project option', async () => {
await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
location: 'project',
rawConfig: {},
@@ -68,8 +71,10 @@ test('config set in project .npmrc file', async () => {
await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
global: false,
location: 'project',
rawConfig: {},
}, ['set', 'fetch-retries', '1'])
@@ -87,6 +92,7 @@ test('config set key=value', async () => {
await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
location: 'project',
rawConfig: {},
@@ -106,6 +112,7 @@ test('config set key=value, when value contains a "="', async () => {
await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
location: 'project',
rawConfig: {},