mirror of
https://github.com/renovatebot/renovate.git
synced 2024-12-22 13:38:32 +00:00
eb8c08079e
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
24 lines
780 B
TypeScript
24 lines
780 B
TypeScript
import os from 'node:os';
|
|
import is from '@sindresorhus/is';
|
|
import upath from 'upath';
|
|
import { logger } from '../../../logger';
|
|
import { readSystemFile } from '../../../util/fs';
|
|
import type { GlobalManagerConfig } from '../types';
|
|
|
|
export async function detectGlobalConfig(): Promise<GlobalManagerConfig> {
|
|
const res: GlobalManagerConfig = {};
|
|
const homedir = os.homedir();
|
|
const npmrcFileName = upath.join(homedir, '.npmrc');
|
|
try {
|
|
const npmrc = await readSystemFile(npmrcFileName, 'utf8');
|
|
if (is.nonEmptyString(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;
|
|
}
|