opencode-dotenv 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +11 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -814,6 +814,8 @@ function getHomeDir() {
|
|
|
814
814
|
}
|
|
815
815
|
function parseDotenv(content) {
|
|
816
816
|
const result = {};
|
|
817
|
+
if (typeof content !== "string")
|
|
818
|
+
return result;
|
|
817
819
|
const lines = content.split(`
|
|
818
820
|
`);
|
|
819
821
|
let i = 0;
|
|
@@ -842,6 +844,8 @@ function parseDotenv(content) {
|
|
|
842
844
|
return result;
|
|
843
845
|
}
|
|
844
846
|
function parseValue(raw) {
|
|
847
|
+
if (typeof raw !== "string")
|
|
848
|
+
return "";
|
|
845
849
|
let value = raw.trim();
|
|
846
850
|
if (value.startsWith('"')) {
|
|
847
851
|
const endQuote = findClosingQuote(value, '"');
|
|
@@ -934,6 +938,10 @@ async function loadConfig() {
|
|
|
934
938
|
const config = parse2(content, [], {
|
|
935
939
|
allowTrailingComma: true
|
|
936
940
|
});
|
|
941
|
+
if (!config || !Array.isArray(config.files)) {
|
|
942
|
+
logToFile("Invalid config format, using defaults");
|
|
943
|
+
return { files: [], load_cwd_env: true };
|
|
944
|
+
}
|
|
937
945
|
loggingEnabled = config.logging?.enabled !== false;
|
|
938
946
|
return config;
|
|
939
947
|
}
|
|
@@ -943,29 +951,22 @@ async function loadConfig() {
|
|
|
943
951
|
return { files: [], load_cwd_env: true };
|
|
944
952
|
}
|
|
945
953
|
async function loadDotenvFile(filePath, prefix) {
|
|
946
|
-
const skipped = [];
|
|
947
954
|
try {
|
|
948
955
|
const file = Bun.file(filePath);
|
|
949
956
|
if (!await file.exists()) {
|
|
950
957
|
logToFile(`File not found: ${filePath}`);
|
|
951
|
-
return { count: 0, success: false
|
|
958
|
+
return { count: 0, success: false };
|
|
952
959
|
}
|
|
953
960
|
const content = await file.text();
|
|
954
961
|
const envVars = parseDotenv(content);
|
|
955
|
-
let count = 0;
|
|
956
962
|
for (const [key, value] of Object.entries(envVars)) {
|
|
957
|
-
if (!isValidEnvKey(key)) {
|
|
958
|
-
skipped.push(key);
|
|
959
|
-
continue;
|
|
960
|
-
}
|
|
961
963
|
const envKey = prefix ? `${prefix}${key}` : key;
|
|
962
964
|
process.env[envKey] = value;
|
|
963
|
-
count++;
|
|
964
965
|
}
|
|
965
|
-
return { count, success: true
|
|
966
|
+
return { count: Object.keys(envVars).length, success: true };
|
|
966
967
|
} catch (error) {
|
|
967
968
|
logToFile(`Failed to load ${filePath}: ${error}`);
|
|
968
|
-
return { count: 0, success: false
|
|
969
|
+
return { count: 0, success: false };
|
|
969
970
|
}
|
|
970
971
|
}
|
|
971
972
|
var DotEnvPlugin = async () => {
|
|
@@ -990,9 +991,6 @@ var DotEnvPlugin = async () => {
|
|
|
990
991
|
totalFiles++;
|
|
991
992
|
totalVars += result.count;
|
|
992
993
|
logToFile(`Loaded ${result.count} vars`);
|
|
993
|
-
if (result.skipped.length > 0) {
|
|
994
|
-
logToFile(`Skipped invalid keys: ${result.skipped.join(", ")}`);
|
|
995
|
-
}
|
|
996
994
|
}
|
|
997
995
|
}
|
|
998
996
|
if (config.load_cwd_env !== false) {
|
|
@@ -1003,9 +1001,6 @@ var DotEnvPlugin = async () => {
|
|
|
1003
1001
|
totalFiles++;
|
|
1004
1002
|
totalVars += result.count;
|
|
1005
1003
|
logToFile(`Loaded ${result.count} vars from cwd`);
|
|
1006
|
-
if (result.skipped.length > 0) {
|
|
1007
|
-
logToFile(`Skipped invalid keys: ${result.skipped.join(", ")}`);
|
|
1008
|
-
}
|
|
1009
1004
|
}
|
|
1010
1005
|
}
|
|
1011
1006
|
logToFile(`Plugin finished: ${totalFiles} files, ${totalVars} vars`);
|