mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-24 05:26:25 +00:00
24 lines
755 B
TypeScript
24 lines
755 B
TypeScript
|
import os from 'os';
|
||
|
import is from '@sindresorhus/is';
|
||
|
import { join } from 'upath';
|
||
|
import { logger } from '../../logger';
|
||
|
import { readFile } from '../../util/fs';
|
||
|
import { GlobalManagerConfig } from '../types';
|
||
|
|
||
|
export async function detectGlobalConfig(): Promise<GlobalManagerConfig> {
|
||
|
const res: GlobalManagerConfig = {};
|
||
|
const homedir = os.homedir();
|
||
|
const npmrcFileName = join(homedir, '.npmrc');
|
||
|
try {
|
||
|
const npmrc = await readFile(npmrcFileName, 'utf8');
|
||
|
if (is.nonEmptyString(npmrc)) {
|
||
|
res.npmrc = npmrc;
|
||
|
res.npmrcMerge = true;
|
||
|
logger.debug(`Detected ${npmrcFileName} and adding it to global config`);
|
||
|
}
|
||
|
} catch (err) {
|
||
|
logger.warn({ npmrcFileName }, 'Error reading .npmrc file');
|
||
|
}
|
||
|
return res;
|
||
|
}
|