import os from 'node:os'; import { isNonEmptyString } from '@sindresorhus/is'; import upath from 'upath'; import { logger } from '../../../logger/index.ts'; import { readSystemFile } from '../../../util/fs/index.ts'; import type { GlobalManagerConfig } from '../types.ts'; export async function detectGlobalConfig(): Promise { const res: GlobalManagerConfig = {}; const homedir = os.homedir(); const npmrcFileName = upath.join(homedir, '.npmrc'); try { const npmrc = await readSystemFile(npmrcFileName, 'utf8'); // v8 ignore else -- TODO: add test #40625 if (isNonEmptyString(npmrc)) { res.npmrc = npmrc; res.npmrcMerge = true; logger.debug(`Detected ${npmrcFileName} and adding it to global config`); } } catch { logger.warn({ npmrcFileName }, 'Error reading .npmrc file'); } return res; }