From 52624e2b6b45abae40f26d24fc1c19136e3d14e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=E1=BA=A3i?= Date: Wed, 13 Aug 2025 05:10:20 +0700 Subject: [PATCH] refactor: extract a function into its own file (#9848) * refactor: extract a function into its own file * style: remove leading empty line * fix: eslint --- config/plugin-commands-config/src/configGet.ts | 2 +- config/plugin-commands-config/src/configSet.ts | 9 +-------- .../src/settingShouldFallBackToNpm.ts | 7 +++++++ 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 config/plugin-commands-config/src/settingShouldFallBackToNpm.ts diff --git a/config/plugin-commands-config/src/configGet.ts b/config/plugin-commands-config/src/configGet.ts index e373a8a08b..7815e16379 100644 --- a/config/plugin-commands-config/src/configGet.ts +++ b/config/plugin-commands-config/src/configGet.ts @@ -1,7 +1,7 @@ import kebabCase from 'lodash.kebabcase' import { runNpm } from '@pnpm/run-npm' import { type ConfigCommandOptions } from './ConfigCommandOptions' -import { settingShouldFallBackToNpm } from './configSet' +import { settingShouldFallBackToNpm } from './settingShouldFallBackToNpm' export function configGet (opts: ConfigCommandOptions, key: string): { output: string, exitCode: number } { if (opts.global && settingShouldFallBackToNpm(key)) { diff --git a/config/plugin-commands-config/src/configSet.ts b/config/plugin-commands-config/src/configSet.ts index 102f07c3a0..4413e80ea8 100644 --- a/config/plugin-commands-config/src/configSet.ts +++ b/config/plugin-commands-config/src/configSet.ts @@ -9,6 +9,7 @@ import kebabCase from 'lodash.kebabcase' import { readIniFile } from 'read-ini-file' import { writeIniFile } from 'write-ini-file' import { type ConfigCommandOptions } from './ConfigCommandOptions' +import { settingShouldFallBackToNpm } from './settingShouldFallBackToNpm' export async function configSet (opts: ConfigCommandOptions, key: string, value: string | null): Promise { if (opts.global && settingShouldFallBackToNpm(key)) { @@ -72,14 +73,6 @@ function castField (value: unknown, key: string) { return value } -export function settingShouldFallBackToNpm (key: string): boolean { - return ( - ['registry', '_auth', '_authToken', 'username', '_password'].includes(key) || - key[0] === '@' || - key.startsWith('//') - ) -} - async function safeReadIniFile (configPath: string): Promise> { try { return await readIniFile(configPath) as Record diff --git a/config/plugin-commands-config/src/settingShouldFallBackToNpm.ts b/config/plugin-commands-config/src/settingShouldFallBackToNpm.ts new file mode 100644 index 0000000000..aa44437f9f --- /dev/null +++ b/config/plugin-commands-config/src/settingShouldFallBackToNpm.ts @@ -0,0 +1,7 @@ +export function settingShouldFallBackToNpm (key: string): boolean { + return ( + ['registry', '_auth', '_authToken', 'username', '_password'].includes(key) || + key[0] === '@' || + key.startsWith('//') + ) +}