Open ekulabuhov opened 5 days ago
The current code is not only parsing, but also does variable substitution.
const buffer = stripBOM(fs.readFileSync(envFilePath, 'utf8'));
buffer.split('\n').forEach((line) => {
const r = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/);
if (r !== null) {
let value = r[2] || '';
if (value.length > 0 && value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') {
value = value.replace(/\\n/gm, '\n');
}
const v = value.replace(/(^['"]|['"]$)/g, '');
env[r[1]] = substituteEnvVars(v, env, globalVars!);
}
});
return env;
microsoft/vscode-python extension does env var substitution similarly, and they do not use dotenv
because it loses ordering (1).
dotenv's parse
itself is pretty straightforward (except the complex regexp) and not too many lines of code. How about borrowing the code but modifying it to preserve ordering?
Is your feature request related to a problem? Please describe. Current implementation does not support multiline env variables, example below won't read past the first line:
Describe the solution you'd like It looks like several other adapters switched to using dotenv:
Describe alternatives you've considered
Additional context Here's the current implementation: https://github.com/golang/vscode-go/blob/master/extension/src/utils/envUtils.ts#L32-L44
The change is fairly simple as env parsing code is identical in all extensions: