cf-envsync 0.3.11 → 0.3.13
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 +167 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13527,6 +13527,119 @@ function stripJsonc(text) {
|
|
|
13527
13527
|
}
|
|
13528
13528
|
return result.replace(/,(\s*[}\]])/g, "$1");
|
|
13529
13529
|
}
|
|
13530
|
+
function findValueEnd(text, start) {
|
|
13531
|
+
const open = text[start];
|
|
13532
|
+
const close = open === "{" ? "}" : open === "[" ? "]" : undefined;
|
|
13533
|
+
if (!close) {
|
|
13534
|
+
let i3 = start;
|
|
13535
|
+
if (text[i3] === '"') {
|
|
13536
|
+
i3++;
|
|
13537
|
+
while (i3 < text.length) {
|
|
13538
|
+
if (text[i3] === "\\" && i3 + 1 < text.length) {
|
|
13539
|
+
i3 += 2;
|
|
13540
|
+
continue;
|
|
13541
|
+
}
|
|
13542
|
+
if (text[i3] === '"')
|
|
13543
|
+
return i3 + 1;
|
|
13544
|
+
i3++;
|
|
13545
|
+
}
|
|
13546
|
+
return i3;
|
|
13547
|
+
}
|
|
13548
|
+
while (i3 < text.length && text[i3] !== "," && text[i3] !== "}" && text[i3] !== "]")
|
|
13549
|
+
i3++;
|
|
13550
|
+
return i3;
|
|
13551
|
+
}
|
|
13552
|
+
let depth = 1;
|
|
13553
|
+
let i2 = start + 1;
|
|
13554
|
+
let inStr = false;
|
|
13555
|
+
while (i2 < text.length && depth > 0) {
|
|
13556
|
+
if (inStr) {
|
|
13557
|
+
if (text[i2] === "\\" && i2 + 1 < text.length) {
|
|
13558
|
+
i2 += 2;
|
|
13559
|
+
continue;
|
|
13560
|
+
}
|
|
13561
|
+
if (text[i2] === '"')
|
|
13562
|
+
inStr = false;
|
|
13563
|
+
i2++;
|
|
13564
|
+
continue;
|
|
13565
|
+
}
|
|
13566
|
+
if (text[i2] === '"') {
|
|
13567
|
+
inStr = true;
|
|
13568
|
+
i2++;
|
|
13569
|
+
continue;
|
|
13570
|
+
}
|
|
13571
|
+
if (text[i2] === "/" && text[i2 + 1] === "/") {
|
|
13572
|
+
while (i2 < text.length && text[i2] !== `
|
|
13573
|
+
`)
|
|
13574
|
+
i2++;
|
|
13575
|
+
continue;
|
|
13576
|
+
}
|
|
13577
|
+
if (text[i2] === "/" && text[i2 + 1] === "*") {
|
|
13578
|
+
i2 += 2;
|
|
13579
|
+
while (i2 < text.length && !(text[i2] === "*" && text[i2 + 1] === "/"))
|
|
13580
|
+
i2++;
|
|
13581
|
+
i2 += 2;
|
|
13582
|
+
continue;
|
|
13583
|
+
}
|
|
13584
|
+
if (text[i2] === open)
|
|
13585
|
+
depth++;
|
|
13586
|
+
if (text[i2] === close)
|
|
13587
|
+
depth--;
|
|
13588
|
+
i2++;
|
|
13589
|
+
}
|
|
13590
|
+
return i2;
|
|
13591
|
+
}
|
|
13592
|
+
function findKeyRange(text, key, searchStart = 0) {
|
|
13593
|
+
const needle = `"${key}"`;
|
|
13594
|
+
let i2 = searchStart;
|
|
13595
|
+
let inString = false;
|
|
13596
|
+
while (i2 < text.length) {
|
|
13597
|
+
if (inString) {
|
|
13598
|
+
if (text[i2] === "\\" && i2 + 1 < text.length) {
|
|
13599
|
+
i2 += 2;
|
|
13600
|
+
continue;
|
|
13601
|
+
}
|
|
13602
|
+
if (text[i2] === '"')
|
|
13603
|
+
inString = false;
|
|
13604
|
+
i2++;
|
|
13605
|
+
continue;
|
|
13606
|
+
}
|
|
13607
|
+
if (text[i2] === "/" && text[i2 + 1] === "/") {
|
|
13608
|
+
while (i2 < text.length && text[i2] !== `
|
|
13609
|
+
`)
|
|
13610
|
+
i2++;
|
|
13611
|
+
continue;
|
|
13612
|
+
}
|
|
13613
|
+
if (text[i2] === "/" && text[i2 + 1] === "*") {
|
|
13614
|
+
i2 += 2;
|
|
13615
|
+
while (i2 < text.length && !(text[i2] === "*" && text[i2 + 1] === "/"))
|
|
13616
|
+
i2++;
|
|
13617
|
+
i2 += 2;
|
|
13618
|
+
continue;
|
|
13619
|
+
}
|
|
13620
|
+
if (text.startsWith(needle, i2)) {
|
|
13621
|
+
let j = i2 + needle.length;
|
|
13622
|
+
while (j < text.length && (text[j] === " " || text[j] === "\t" || text[j] === `
|
|
13623
|
+
` || text[j] === "\r"))
|
|
13624
|
+
j++;
|
|
13625
|
+
if (text[j] === ":") {
|
|
13626
|
+
j++;
|
|
13627
|
+
while (j < text.length && (text[j] === " " || text[j] === "\t" || text[j] === `
|
|
13628
|
+
` || text[j] === "\r"))
|
|
13629
|
+
j++;
|
|
13630
|
+
const end = findValueEnd(text, j);
|
|
13631
|
+
return [j, end];
|
|
13632
|
+
}
|
|
13633
|
+
}
|
|
13634
|
+
if (text[i2] === '"') {
|
|
13635
|
+
inString = true;
|
|
13636
|
+
i2++;
|
|
13637
|
+
continue;
|
|
13638
|
+
}
|
|
13639
|
+
i2++;
|
|
13640
|
+
}
|
|
13641
|
+
return;
|
|
13642
|
+
}
|
|
13530
13643
|
async function checkWrangler() {
|
|
13531
13644
|
const result = await exec(["npx", "wrangler", "--version"]);
|
|
13532
13645
|
return result.success;
|
|
@@ -13581,25 +13694,65 @@ function findWranglerConfig(appPath) {
|
|
|
13581
13694
|
}
|
|
13582
13695
|
return;
|
|
13583
13696
|
}
|
|
13697
|
+
function detectIndent(content) {
|
|
13698
|
+
const match = content.match(/\n(\s+)"/);
|
|
13699
|
+
return match ? match[1] : " ";
|
|
13700
|
+
}
|
|
13584
13701
|
async function updateWranglerVars(appPath, environment, vars) {
|
|
13585
13702
|
const configPath = findWranglerConfig(appPath);
|
|
13586
13703
|
if (!configPath) {
|
|
13587
13704
|
return { success: false, updatedCount: 0 };
|
|
13588
13705
|
}
|
|
13589
|
-
|
|
13590
|
-
const
|
|
13591
|
-
const
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
}
|
|
13595
|
-
const
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13706
|
+
let content = await readFile(configPath);
|
|
13707
|
+
const indent = detectIndent(content);
|
|
13708
|
+
const parsed = JSON.parse(stripJsonc(content));
|
|
13709
|
+
const envSection = parsed?.env ?? {};
|
|
13710
|
+
const existingVars = envSection[environment]?.vars ?? {};
|
|
13711
|
+
const mergedVars = { ...existingVars, ...vars };
|
|
13712
|
+
const varsJson = JSON.stringify(mergedVars, null, indent);
|
|
13713
|
+
const envRange = findKeyRange(content, "env");
|
|
13714
|
+
if (envRange) {
|
|
13715
|
+
const envObjRange = findKeyRange(content, environment, envRange[0]);
|
|
13716
|
+
if (envObjRange) {
|
|
13717
|
+
const varsRange = findKeyRange(content, "vars", envObjRange[0]);
|
|
13718
|
+
if (varsRange) {
|
|
13719
|
+
content = content.slice(0, varsRange[0]) + varsJson + content.slice(varsRange[1]);
|
|
13720
|
+
await writeFile(configPath, content);
|
|
13721
|
+
return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
|
|
13722
|
+
}
|
|
13723
|
+
const insertAt2 = envObjRange[1] - 1;
|
|
13724
|
+
const envIndent3 = indent.repeat(3);
|
|
13725
|
+
const insertion3 = `,
|
|
13726
|
+
${envIndent3}"vars": ${varsJson}
|
|
13727
|
+
${indent.repeat(2)}`;
|
|
13728
|
+
content = content.slice(0, insertAt2) + insertion3 + content.slice(insertAt2);
|
|
13729
|
+
await writeFile(configPath, content);
|
|
13730
|
+
return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
|
|
13731
|
+
}
|
|
13732
|
+
const insertAt = envRange[1] - 1;
|
|
13733
|
+
const envIndent2 = indent.repeat(2);
|
|
13734
|
+
const inner2 = `{
|
|
13735
|
+
${indent.repeat(3)}"vars": ${varsJson}
|
|
13736
|
+
${envIndent2}}`;
|
|
13737
|
+
const insertion2 = `,
|
|
13738
|
+
${envIndent2}"${environment}": ${inner2}
|
|
13739
|
+
${indent}`;
|
|
13740
|
+
content = content.slice(0, insertAt) + insertion2 + content.slice(insertAt);
|
|
13741
|
+
await writeFile(configPath, content);
|
|
13742
|
+
return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
|
|
13743
|
+
}
|
|
13744
|
+
const lastBrace = content.lastIndexOf("}");
|
|
13745
|
+
const envIndent = indent;
|
|
13746
|
+
const inner = `{
|
|
13747
|
+
${indent.repeat(2)}"${environment}": ` + `{
|
|
13748
|
+
${indent.repeat(3)}"vars": ${varsJson}
|
|
13749
|
+
${indent.repeat(2)}}
|
|
13750
|
+
${indent}}`;
|
|
13751
|
+
const insertion = `,
|
|
13752
|
+
${envIndent}"env": ${inner}
|
|
13753
|
+
`;
|
|
13754
|
+
content = content.slice(0, lastBrace) + insertion + content.slice(lastBrace);
|
|
13755
|
+
await writeFile(configPath, content);
|
|
13603
13756
|
return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
|
|
13604
13757
|
}
|
|
13605
13758
|
var init_wrangler = __esm(() => {
|