cf-envsync 0.3.12 → 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.
Files changed (2) hide show
  1. package/dist/index.js +208 -157
  2. package/package.json +2 -3
package/dist/index.js CHANGED
@@ -12491,7 +12491,7 @@ var require_ignore = __commonJS((exports, module) => {
12491
12491
  TMP_KEY_IGNORE = Symbol.for("node-ignore");
12492
12492
  }
12493
12493
  var KEY_IGNORE = TMP_KEY_IGNORE;
12494
- var define2 = (object, key, value) => Object.defineProperty(object, key, { value });
12494
+ var define = (object, key, value) => Object.defineProperty(object, key, { value });
12495
12495
  var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
12496
12496
  var RETURN_FALSE = () => false;
12497
12497
  var sanitizeRange = (range) => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match : EMPTY);
@@ -12634,7 +12634,7 @@ var require_ignore = __commonJS((exports, module) => {
12634
12634
  ignoreCase = ignorecase,
12635
12635
  allowRelativePaths = false
12636
12636
  } = {}) {
12637
- define2(this, KEY_IGNORE, true);
12637
+ define(this, KEY_IGNORE, true);
12638
12638
  this._rules = [];
12639
12639
  this._ignoreCase = ignoreCase;
12640
12640
  this._allowRelativePaths = allowRelativePaths;
@@ -13440,152 +13440,6 @@ Done!`);
13440
13440
  });
13441
13441
  });
13442
13442
 
13443
- // node_modules/jsonc-parser/lib/umd/main.js
13444
- var require_main3 = __commonJS((exports, module) => {
13445
- (function(factory) {
13446
- if (typeof module === "object" && typeof module.exports === "object") {
13447
- var v2 = factory(__require, exports);
13448
- if (v2 !== undefined)
13449
- module.exports = v2;
13450
- } else if (typeof define === "function" && define.amd) {
13451
- define(["require", "exports", "./impl/format", "./impl/edit", "./impl/scanner", "./impl/parser"], factory);
13452
- }
13453
- })(function(require2, exports2) {
13454
- Object.defineProperty(exports2, "__esModule", { value: true });
13455
- exports2.applyEdits = exports2.modify = exports2.format = exports2.printParseErrorCode = exports2.ParseErrorCode = exports2.stripComments = exports2.visit = exports2.getNodeValue = exports2.getNodePath = exports2.findNodeAtOffset = exports2.findNodeAtLocation = exports2.parseTree = exports2.parse = exports2.getLocation = exports2.SyntaxKind = exports2.ScanError = exports2.createScanner = undefined;
13456
- const formatter = require2("./impl/format");
13457
- const edit = require2("./impl/edit");
13458
- const scanner = require2("./impl/scanner");
13459
- const parser = require2("./impl/parser");
13460
- exports2.createScanner = scanner.createScanner;
13461
- var ScanError;
13462
- (function(ScanError2) {
13463
- ScanError2[ScanError2["None"] = 0] = "None";
13464
- ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
13465
- ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
13466
- ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
13467
- ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
13468
- ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
13469
- ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
13470
- })(ScanError || (exports2.ScanError = ScanError = {}));
13471
- var SyntaxKind;
13472
- (function(SyntaxKind2) {
13473
- SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
13474
- SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
13475
- SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
13476
- SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
13477
- SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
13478
- SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
13479
- SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
13480
- SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
13481
- SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
13482
- SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
13483
- SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
13484
- SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
13485
- SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
13486
- SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
13487
- SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
13488
- SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
13489
- SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
13490
- })(SyntaxKind || (exports2.SyntaxKind = SyntaxKind = {}));
13491
- exports2.getLocation = parser.getLocation;
13492
- exports2.parse = parser.parse;
13493
- exports2.parseTree = parser.parseTree;
13494
- exports2.findNodeAtLocation = parser.findNodeAtLocation;
13495
- exports2.findNodeAtOffset = parser.findNodeAtOffset;
13496
- exports2.getNodePath = parser.getNodePath;
13497
- exports2.getNodeValue = parser.getNodeValue;
13498
- exports2.visit = parser.visit;
13499
- exports2.stripComments = parser.stripComments;
13500
- var ParseErrorCode;
13501
- (function(ParseErrorCode2) {
13502
- ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
13503
- ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
13504
- ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
13505
- ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
13506
- ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
13507
- ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
13508
- ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
13509
- ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
13510
- ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
13511
- ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
13512
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
13513
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
13514
- ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
13515
- ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
13516
- ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
13517
- ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
13518
- })(ParseErrorCode || (exports2.ParseErrorCode = ParseErrorCode = {}));
13519
- function printParseErrorCode(code) {
13520
- switch (code) {
13521
- case 1:
13522
- return "InvalidSymbol";
13523
- case 2:
13524
- return "InvalidNumberFormat";
13525
- case 3:
13526
- return "PropertyNameExpected";
13527
- case 4:
13528
- return "ValueExpected";
13529
- case 5:
13530
- return "ColonExpected";
13531
- case 6:
13532
- return "CommaExpected";
13533
- case 7:
13534
- return "CloseBraceExpected";
13535
- case 8:
13536
- return "CloseBracketExpected";
13537
- case 9:
13538
- return "EndOfFileExpected";
13539
- case 10:
13540
- return "InvalidCommentToken";
13541
- case 11:
13542
- return "UnexpectedEndOfComment";
13543
- case 12:
13544
- return "UnexpectedEndOfString";
13545
- case 13:
13546
- return "UnexpectedEndOfNumber";
13547
- case 14:
13548
- return "InvalidUnicode";
13549
- case 15:
13550
- return "InvalidEscapeCharacter";
13551
- case 16:
13552
- return "InvalidCharacter";
13553
- }
13554
- return "<unknown ParseErrorCode>";
13555
- }
13556
- exports2.printParseErrorCode = printParseErrorCode;
13557
- function format(documentText, range, options) {
13558
- return formatter.format(documentText, range, options);
13559
- }
13560
- exports2.format = format;
13561
- function modify(text, path, value, options) {
13562
- return edit.setProperty(text, path, value, options);
13563
- }
13564
- exports2.modify = modify;
13565
- function applyEdits(text, edits) {
13566
- let sortedEdits = edits.slice(0).sort((a2, b2) => {
13567
- const diff = a2.offset - b2.offset;
13568
- if (diff === 0) {
13569
- return a2.length - b2.length;
13570
- }
13571
- return diff;
13572
- });
13573
- let lastModifiedOffset = text.length;
13574
- for (let i2 = sortedEdits.length - 1;i2 >= 0; i2--) {
13575
- let e2 = sortedEdits[i2];
13576
- if (e2.offset + e2.length <= lastModifiedOffset) {
13577
- text = edit.applyEdit(text, e2);
13578
- } else {
13579
- throw new Error("Overlapping edit");
13580
- }
13581
- lastModifiedOffset = e2.offset;
13582
- }
13583
- return text;
13584
- }
13585
- exports2.applyEdits = applyEdits;
13586
- });
13587
- });
13588
-
13589
13443
  // src/utils/process.ts
13590
13444
  import { spawn } from "node:child_process";
13591
13445
  async function exec(command, options = {}) {
@@ -13632,6 +13486,160 @@ var init_process = () => {};
13632
13486
 
13633
13487
  // src/core/wrangler.ts
13634
13488
  import { join as join6 } from "node:path";
13489
+ function stripJsonc(text) {
13490
+ let result = "";
13491
+ let i2 = 0;
13492
+ let inString = false;
13493
+ while (i2 < text.length) {
13494
+ if (inString) {
13495
+ result += text[i2];
13496
+ if (text[i2] === "\\" && i2 + 1 < text.length) {
13497
+ result += text[i2 + 1];
13498
+ i2 += 2;
13499
+ continue;
13500
+ }
13501
+ if (text[i2] === '"')
13502
+ inString = false;
13503
+ i2++;
13504
+ continue;
13505
+ }
13506
+ if (text[i2] === '"') {
13507
+ inString = true;
13508
+ result += text[i2];
13509
+ i2++;
13510
+ continue;
13511
+ }
13512
+ if (text[i2] === "/" && text[i2 + 1] === "/") {
13513
+ while (i2 < text.length && text[i2] !== `
13514
+ `)
13515
+ i2++;
13516
+ continue;
13517
+ }
13518
+ if (text[i2] === "/" && text[i2 + 1] === "*") {
13519
+ i2 += 2;
13520
+ while (i2 < text.length && !(text[i2] === "*" && text[i2 + 1] === "/"))
13521
+ i2++;
13522
+ i2 += 2;
13523
+ continue;
13524
+ }
13525
+ result += text[i2];
13526
+ i2++;
13527
+ }
13528
+ return result.replace(/,(\s*[}\]])/g, "$1");
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
+ }
13635
13643
  async function checkWrangler() {
13636
13644
  const result = await exec(["npx", "wrangler", "--version"]);
13637
13645
  return result.success;
@@ -13686,28 +13694,71 @@ function findWranglerConfig(appPath) {
13686
13694
  }
13687
13695
  return;
13688
13696
  }
13697
+ function detectIndent(content) {
13698
+ const match = content.match(/\n(\s+)"/);
13699
+ return match ? match[1] : " ";
13700
+ }
13689
13701
  async function updateWranglerVars(appPath, environment, vars) {
13690
13702
  const configPath = findWranglerConfig(appPath);
13691
13703
  if (!configPath) {
13692
13704
  return { success: false, updatedCount: 0 };
13693
13705
  }
13694
- const content = await readFile(configPath);
13695
- const config = import_jsonc_parser.parse(content);
13696
- const envSection = config?.env ?? {};
13706
+ let content = await readFile(configPath);
13707
+ const indent = detectIndent(content);
13708
+ const parsed = JSON.parse(stripJsonc(content));
13709
+ const envSection = parsed?.env ?? {};
13697
13710
  const existingVars = envSection[environment]?.vars ?? {};
13698
13711
  const mergedVars = { ...existingVars, ...vars };
13699
- const fmt = { tabSize: 2, insertSpaces: true };
13700
- const edits = import_jsonc_parser.modify(content, ["env", environment, "vars"], mergedVars, { formattingOptions: fmt });
13701
- const updated = import_jsonc_parser.applyEdits(content, edits);
13702
- await writeFile(configPath, updated);
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);
13703
13756
  return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
13704
13757
  }
13705
- var import_jsonc_parser;
13706
13758
  var init_wrangler = __esm(() => {
13707
13759
  init_dist2();
13708
13760
  init_process();
13709
13761
  init_fs();
13710
- import_jsonc_parser = __toESM(require_main3(), 1);
13711
13762
  });
13712
13763
 
13713
13764
  // src/commands/push.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cf-envsync",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "Sync .env files to Cloudflare Workers secrets, .dev.vars, and more",
5
5
  "type": "module",
6
6
  "exports": {
@@ -33,8 +33,7 @@
33
33
  "@dotenvx/dotenvx": "^1.52.0",
34
34
  "citty": "^0.2.1",
35
35
  "consola": "^3.4.2",
36
- "jiti": "^2.4.2",
37
- "jsonc-parser": "^3.3.1"
36
+ "jiti": "^2.4.2"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@types/node": "^22"