opencode-dotenv 0.3.3 → 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 +9 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -844,6 +844,8 @@ function parseDotenv(content) {
|
|
|
844
844
|
return result;
|
|
845
845
|
}
|
|
846
846
|
function parseValue(raw) {
|
|
847
|
+
if (typeof raw !== "string")
|
|
848
|
+
return "";
|
|
847
849
|
let value = raw.trim();
|
|
848
850
|
if (value.startsWith('"')) {
|
|
849
851
|
const endQuote = findClosingQuote(value, '"');
|
|
@@ -936,6 +938,10 @@ async function loadConfig() {
|
|
|
936
938
|
const config = parse2(content, [], {
|
|
937
939
|
allowTrailingComma: true
|
|
938
940
|
});
|
|
941
|
+
if (!config || !Array.isArray(config.files)) {
|
|
942
|
+
logToFile("Invalid config format, using defaults");
|
|
943
|
+
return { files: [], load_cwd_env: true };
|
|
944
|
+
}
|
|
939
945
|
loggingEnabled = config.logging?.enabled !== false;
|
|
940
946
|
return config;
|
|
941
947
|
}
|
|
@@ -945,29 +951,22 @@ async function loadConfig() {
|
|
|
945
951
|
return { files: [], load_cwd_env: true };
|
|
946
952
|
}
|
|
947
953
|
async function loadDotenvFile(filePath, prefix) {
|
|
948
|
-
const skipped = [];
|
|
949
954
|
try {
|
|
950
955
|
const file = Bun.file(filePath);
|
|
951
956
|
if (!await file.exists()) {
|
|
952
957
|
logToFile(`File not found: ${filePath}`);
|
|
953
|
-
return { count: 0, success: false
|
|
958
|
+
return { count: 0, success: false };
|
|
954
959
|
}
|
|
955
960
|
const content = await file.text();
|
|
956
961
|
const envVars = parseDotenv(content);
|
|
957
|
-
let count = 0;
|
|
958
962
|
for (const [key, value] of Object.entries(envVars)) {
|
|
959
|
-
if (!isValidEnvKey(key)) {
|
|
960
|
-
skipped.push(key);
|
|
961
|
-
continue;
|
|
962
|
-
}
|
|
963
963
|
const envKey = prefix ? `${prefix}${key}` : key;
|
|
964
964
|
process.env[envKey] = value;
|
|
965
|
-
count++;
|
|
966
965
|
}
|
|
967
|
-
return { count, success: true
|
|
966
|
+
return { count: Object.keys(envVars).length, success: true };
|
|
968
967
|
} catch (error) {
|
|
969
968
|
logToFile(`Failed to load ${filePath}: ${error}`);
|
|
970
|
-
return { count: 0, success: false
|
|
969
|
+
return { count: 0, success: false };
|
|
971
970
|
}
|
|
972
971
|
}
|
|
973
972
|
var DotEnvPlugin = async () => {
|
|
@@ -992,9 +991,6 @@ var DotEnvPlugin = async () => {
|
|
|
992
991
|
totalFiles++;
|
|
993
992
|
totalVars += result.count;
|
|
994
993
|
logToFile(`Loaded ${result.count} vars`);
|
|
995
|
-
if (result.skipped.length > 0) {
|
|
996
|
-
logToFile(`Skipped invalid keys: ${result.skipped.join(", ")}`);
|
|
997
|
-
}
|
|
998
994
|
}
|
|
999
995
|
}
|
|
1000
996
|
if (config.load_cwd_env !== false) {
|
|
@@ -1005,9 +1001,6 @@ var DotEnvPlugin = async () => {
|
|
|
1005
1001
|
totalFiles++;
|
|
1006
1002
|
totalVars += result.count;
|
|
1007
1003
|
logToFile(`Loaded ${result.count} vars from cwd`);
|
|
1008
|
-
if (result.skipped.length > 0) {
|
|
1009
|
-
logToFile(`Skipped invalid keys: ${result.skipped.join(", ")}`);
|
|
1010
|
-
}
|
|
1011
1004
|
}
|
|
1012
1005
|
}
|
|
1013
1006
|
logToFile(`Plugin finished: ${totalFiles} files, ${totalVars} vars`);
|