@dotenvx/primitives 1.0.0 → 1.1.0
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.cjs +66 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6410,7 +6410,7 @@ var require_parse = __commonJS({
|
|
|
6410
6410
|
}
|
|
6411
6411
|
}
|
|
6412
6412
|
if (!encryptedPrefixed && !evaled && quote !== "'" && (!processEnv[name] || overload)) {
|
|
6413
|
-
parsedValue = resolveEscapeSequences(expand2(parsedValue, { processEnv, runningParsed, literals }));
|
|
6413
|
+
parsedValue = resolveEscapeSequences(expand2(parsedValue, { overload, processEnv, runningParsed, literals }));
|
|
6414
6414
|
}
|
|
6415
6415
|
if (quote === "'") {
|
|
6416
6416
|
literals[name] = parsedValue;
|
|
@@ -6458,6 +6458,68 @@ var require_sealed = __commonJS({
|
|
|
6458
6458
|
}
|
|
6459
6459
|
});
|
|
6460
6460
|
|
|
6461
|
+
// src/upsert.js
|
|
6462
|
+
var require_upsert = __commonJS({
|
|
6463
|
+
"src/upsert.js"(exports2, module2) {
|
|
6464
|
+
var scan2 = require_scan();
|
|
6465
|
+
function escapeForRegex(str) {
|
|
6466
|
+
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
6467
|
+
}
|
|
6468
|
+
function replaceExistingValue(src, key, originalValue, replaceValue) {
|
|
6469
|
+
const escapedKey = escapeForRegex(key);
|
|
6470
|
+
const escapedOriginalValue = escapeForRegex(originalValue);
|
|
6471
|
+
let enforceEndOfLine = "";
|
|
6472
|
+
if (escapedOriginalValue === "") {
|
|
6473
|
+
enforceEndOfLine = "$";
|
|
6474
|
+
}
|
|
6475
|
+
const currentPart = new RegExp(
|
|
6476
|
+
"^(\\s*)?(export\\s+)?" + escapedKey + "\\s*=\\s*([\"'`]?)" + escapedOriginalValue + "\\3" + enforceEndOfLine,
|
|
6477
|
+
"m"
|
|
6478
|
+
);
|
|
6479
|
+
return src.replace(currentPart, function(match, spaces = "", exportPart = "", quote = "") {
|
|
6480
|
+
let newPart = `${key}=${quote}${replaceValue}${quote}`;
|
|
6481
|
+
const newlineMatch = src.match(new RegExp(`${escapedKey}\\s*=\\s*
|
|
6482
|
+
|
|
6483
|
+
`, "m"));
|
|
6484
|
+
if (escapedOriginalValue === "" && quote === "" && newlineMatch) {
|
|
6485
|
+
const newlineCount = newlineMatch[0].match(/\n/g).length - 1;
|
|
6486
|
+
for (let i = 0; i < newlineCount; i++) {
|
|
6487
|
+
newPart += "\n";
|
|
6488
|
+
}
|
|
6489
|
+
}
|
|
6490
|
+
return `${spaces}${exportPart}${newPart}`;
|
|
6491
|
+
});
|
|
6492
|
+
}
|
|
6493
|
+
function upsert2(src, key, replaceValue) {
|
|
6494
|
+
let output;
|
|
6495
|
+
let newPart = "";
|
|
6496
|
+
const { parsed } = scan2(src, { expandDoubleQuotedNewlines: false, convertWindowsNewlines: false });
|
|
6497
|
+
if (Object.prototype.hasOwnProperty.call(parsed, key)) {
|
|
6498
|
+
const allValues = parsed[key];
|
|
6499
|
+
let duplicateOutput = src;
|
|
6500
|
+
const replacements = Array.isArray(replaceValue) ? replaceValue : allValues.map(() => replaceValue);
|
|
6501
|
+
allValues.forEach((value, index) => {
|
|
6502
|
+
duplicateOutput = replaceExistingValue(duplicateOutput, key, value, `\0DOTENVX_UPSERT_${index}\0`);
|
|
6503
|
+
});
|
|
6504
|
+
replacements.forEach((replacement, index) => {
|
|
6505
|
+
duplicateOutput = duplicateOutput.split(`\0DOTENVX_UPSERT_${index}\0`).join(replacement);
|
|
6506
|
+
});
|
|
6507
|
+
return duplicateOutput;
|
|
6508
|
+
} else {
|
|
6509
|
+
newPart += `${key}="${replaceValue}"`;
|
|
6510
|
+
if (src.endsWith("\n")) {
|
|
6511
|
+
newPart = newPart + "\n";
|
|
6512
|
+
} else {
|
|
6513
|
+
newPart = "\n" + newPart;
|
|
6514
|
+
}
|
|
6515
|
+
output = src + newPart;
|
|
6516
|
+
}
|
|
6517
|
+
return output;
|
|
6518
|
+
}
|
|
6519
|
+
module2.exports = upsert2;
|
|
6520
|
+
}
|
|
6521
|
+
});
|
|
6522
|
+
|
|
6461
6523
|
// src/index.js
|
|
6462
6524
|
var decrypt = require_decrypt();
|
|
6463
6525
|
var derive = require_derive();
|
|
@@ -6473,6 +6535,7 @@ var parseSync = require_parse().sync;
|
|
|
6473
6535
|
var publickeys = require_publickeys();
|
|
6474
6536
|
var scan = require_scan();
|
|
6475
6537
|
var sealed = require_sealed();
|
|
6538
|
+
var upsert = require_upsert();
|
|
6476
6539
|
module.exports = {
|
|
6477
6540
|
decrypt,
|
|
6478
6541
|
derive,
|
|
@@ -6487,5 +6550,6 @@ module.exports = {
|
|
|
6487
6550
|
parseSync,
|
|
6488
6551
|
publickeys,
|
|
6489
6552
|
scan,
|
|
6490
|
-
sealed
|
|
6553
|
+
sealed,
|
|
6554
|
+
upsert
|
|
6491
6555
|
};
|
package/package.json
CHANGED