-
-
Notifications
You must be signed in to change notification settings - Fork 933
/
readLocalConfig.ts
31 lines (30 loc) · 932 Bytes
/
readLocalConfig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import path from 'path'
import camelcaseKeys from 'camelcase-keys'
import { envReplace } from '@pnpm/config.env-replace'
import readIniFile from 'read-ini-file'
export async function readLocalConfig (prefix: string) {
try {
const ini = await readIniFile(path.join(prefix, '.npmrc')) as Record<string, string>
const config = camelcaseKeys(ini) as (Record<string, string> & { hoist?: boolean })
if (config.shamefullyFlatten) {
config.hoistPattern = '*'
// TODO: print a warning
}
if (config.hoist === false) {
config.hoistPattern = ''
}
for (const [key, val] of Object.entries(config)) {
if (typeof val === 'string') {
try {
config[key] = envReplace(val, process.env)
} catch (err) {
// ignore
}
}
}
return config
} catch (err: any) { // eslint-disable-line
if (err.code !== 'ENOENT') throw err
return {}
}
}