mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 18:46:18 -04:00
fix: config set should write to the global config file (#6132)
close #5877 close #6131
This commit is contained in:
6
.changeset/serious-rice-boil.md
Normal file
6
.changeset/serious-rice-boil.md
Normal 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).
|
||||||
@@ -2,6 +2,7 @@ import { Config } from '@pnpm/config'
|
|||||||
|
|
||||||
export type ConfigCommandOptions = Pick<Config,
|
export type ConfigCommandOptions = Pick<Config,
|
||||||
| 'configDir'
|
| 'configDir'
|
||||||
|
| 'cliOptions'
|
||||||
| 'dir'
|
| 'dir'
|
||||||
| 'global'
|
| 'global'
|
||||||
| 'rawConfig'
|
| 'rawConfig'
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ export function help () {
|
|||||||
name: '--global',
|
name: '--global',
|
||||||
shortAlias: '-g',
|
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) {
|
if (opts.location) {
|
||||||
opts.global = opts.location === 'global'
|
opts.global = opts.location === 'global'
|
||||||
|
} else if (opts.cliOptions['global'] == null) {
|
||||||
|
opts.global = true
|
||||||
}
|
}
|
||||||
switch (params[0]) {
|
switch (params[0]) {
|
||||||
case 'set': {
|
case 'set': {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ cache-dir=~/cache`)
|
|||||||
|
|
||||||
await config.handler({
|
await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir,
|
configDir,
|
||||||
global: true,
|
global: true,
|
||||||
rawConfig: {},
|
rawConfig: {},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { config } from '@pnpm/plugin-commands-config'
|
|||||||
test('config get', async () => {
|
test('config get', async () => {
|
||||||
const configKey = await config.handler({
|
const configKey = await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir: process.cwd(),
|
configDir: process.cwd(),
|
||||||
global: true,
|
global: true,
|
||||||
rawConfig: {
|
rawConfig: {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ function normalizeNewlines (str: string) {
|
|||||||
test('config list', async () => {
|
test('config list', async () => {
|
||||||
const output = await config.handler({
|
const output = await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir: process.cwd(),
|
configDir: process.cwd(),
|
||||||
rawConfig: {
|
rawConfig: {
|
||||||
'store-dir': '~/store',
|
'store-dir': '~/store',
|
||||||
@@ -24,6 +25,7 @@ store-dir=~/store
|
|||||||
test('config list --json', async () => {
|
test('config list --json', async () => {
|
||||||
const output = await config.handler({
|
const output = await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir: process.cwd(),
|
configDir: process.cwd(),
|
||||||
json: true,
|
json: true,
|
||||||
rawConfig: {
|
rawConfig: {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ test('config set using the global option', async () => {
|
|||||||
|
|
||||||
await config.handler({
|
await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir,
|
configDir,
|
||||||
global: true,
|
global: true,
|
||||||
rawConfig: {},
|
rawConfig: {},
|
||||||
@@ -31,6 +32,7 @@ test('config set using the location=global option', async () => {
|
|||||||
|
|
||||||
await config.handler({
|
await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir,
|
configDir,
|
||||||
location: 'global',
|
location: 'global',
|
||||||
rawConfig: {},
|
rawConfig: {},
|
||||||
@@ -50,6 +52,7 @@ test('config set using the location=project option', async () => {
|
|||||||
|
|
||||||
await config.handler({
|
await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir,
|
configDir,
|
||||||
location: 'project',
|
location: 'project',
|
||||||
rawConfig: {},
|
rawConfig: {},
|
||||||
@@ -68,8 +71,10 @@ test('config set in project .npmrc file', async () => {
|
|||||||
|
|
||||||
await config.handler({
|
await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir,
|
configDir,
|
||||||
global: false,
|
global: false,
|
||||||
|
location: 'project',
|
||||||
rawConfig: {},
|
rawConfig: {},
|
||||||
}, ['set', 'fetch-retries', '1'])
|
}, ['set', 'fetch-retries', '1'])
|
||||||
|
|
||||||
@@ -87,6 +92,7 @@ test('config set key=value', async () => {
|
|||||||
|
|
||||||
await config.handler({
|
await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir,
|
configDir,
|
||||||
location: 'project',
|
location: 'project',
|
||||||
rawConfig: {},
|
rawConfig: {},
|
||||||
@@ -106,6 +112,7 @@ test('config set key=value, when value contains a "="', async () => {
|
|||||||
|
|
||||||
await config.handler({
|
await config.handler({
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
|
cliOptions: {},
|
||||||
configDir,
|
configDir,
|
||||||
location: 'project',
|
location: 'project',
|
||||||
rawConfig: {},
|
rawConfig: {},
|
||||||
|
|||||||
Reference in New Issue
Block a user