reading envFile: use dotenv for better support. (#1062)
* reading envFile: use dotenv for better support. Co-authored-by: Grant, John K <john.k.grant@warnerbros.com>
This commit is contained in:
parent
2356afb255
commit
b5d9556087
|
@ -862,6 +862,11 @@
|
|||
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
|
||||
"dev": true
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
|
||||
},
|
||||
"electron-to-chromium": {
|
||||
"version": "1.3.774",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.774.tgz",
|
||||
|
|
|
@ -959,6 +959,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"compare-versions": "^3.6.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"uuid": "^8.3.1",
|
||||
"vscode-extension-telemetry-wrapper": "^0.9.0",
|
||||
|
|
|
@ -6,6 +6,8 @@ import * as os from "os";
|
|||
import * as path from "path";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
import { instrumentOperation, sendError, sendInfo, setUserError } from "vscode-extension-telemetry-wrapper";
|
||||
import * as anchor from "./anchor";
|
||||
import { buildWorkspace } from "./build";
|
||||
|
@ -721,20 +723,7 @@ function readEnvFile(file: string): { [key: string]: string } {
|
|||
}
|
||||
|
||||
const buffer = stripBOM(fs.readFileSync(file, "utf8"));
|
||||
const env: { [key: string]: string } = {};
|
||||
for (const line of buffer.split("\n")) {
|
||||
const r = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/);
|
||||
if (!r) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = r[2] || "";
|
||||
// .env variables never overwrite existing variables (see #21169)
|
||||
if (value.length > 0 && value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') {
|
||||
value = value.replace(/\\n/gm, "\n");
|
||||
}
|
||||
env[r[1]] = value.replace(/(^['"]|['"]$)/g, "");
|
||||
}
|
||||
const env = dotenv.parse(Buffer.from(buffer));
|
||||
|
||||
return env;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue