Skip to content

Commit

Permalink
fix: config set should write to the global config file
Browse files Browse the repository at this point in the history
close #5877
  • Loading branch information
zkochan committed Feb 25, 2023
1 parent f39d608 commit f7461de
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/serious-rice-boil.md
Original file line number Diff line number Diff line change
@@ -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).
1 change: 1 addition & 0 deletions config/plugin-commands-config/src/ConfigCommandOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Config } from '@pnpm/config'

export type ConfigCommandOptions = Pick<Config,
| 'configDir'
| 'cliOptions'
| 'dir'
| 'global'
| 'rawConfig'
Expand Down
6 changes: 6 additions & 0 deletions config/plugin-commands-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>',
},
],
},
],
Expand All @@ -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': {
Expand Down
1 change: 1 addition & 0 deletions config/plugin-commands-config/test/configDelete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cache-dir=~/cache`)

await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
global: true,
rawConfig: {},
Expand Down
1 change: 1 addition & 0 deletions config/plugin-commands-config/test/configGet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 2 additions & 0 deletions config/plugin-commands-config/test/configList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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: {
Expand Down
7 changes: 7 additions & 0 deletions config/plugin-commands-config/test/configSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('config set using the global option', async () => {

await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
global: true,
rawConfig: {},
Expand All @@ -31,6 +32,7 @@ test('config set using the location=global option', async () => {

await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
location: 'global',
rawConfig: {},
Expand All @@ -50,6 +52,7 @@ test('config set using the location=project option', async () => {

await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
location: 'project',
rawConfig: {},
Expand All @@ -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'])

Expand All @@ -87,6 +92,7 @@ test('config set key=value', async () => {

await config.handler({
dir: process.cwd(),
cliOptions: {},
configDir,
location: 'project',
rawConfig: {},
Expand All @@ -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: {},
Expand Down

0 comments on commit f7461de

Please sign in to comment.