JavaScript: node:parseEnv sucks really badly.
This is my version.
Loads all ENV vars to the process.env
- ignore comments (any amount of spaces then
#
) - any
=
after the first is part of the value - keys will always be uppercase and spaces replaced with
_
const rcEnvFilePath = path.join(os.homedir(), '.progrc');
(await readFile(rcEnvFilePath, 'utf-8').catch(_ => '')).split('\n').map(line => line.trim()).filter(line => line.length > 0 && !line.startsWith('#')).map(line => line.split(/=(.*)/).map(part => part.trim())).filter(line => line[1].length > 0).forEach(line => process.env[line[0].toUpperCase().replaceAll(' ', '_')] = line[1]);