renovate/lib/modules/manager/npm/detect.ts
Rhys Arkins dca3418bbd refactor: lib/modules (#14488)
Moves datasource, manager, platform and versioning code from lib/ into new lib/modules/

BREAKING CHANGE: External tools must update paths to datasource, manager, platform and versioning
2022-03-04 09:04:02 +01:00

23 lines
769 B
TypeScript

import os from 'os';
import is from '@sindresorhus/is';
import upath from 'upath';
import { logger } from '../../../logger';
import { readFile } 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 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;
}