cf-envsync 0.3.10 → 0.3.12

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 +160 -50
  2. package/package.json +3 -2
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 define = (object, key, value) => Object.defineProperty(object, key, { value });
12494
+ var define2 = (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
- define(this, KEY_IGNORE, true);
12637
+ define2(this, KEY_IGNORE, true);
12638
12638
  this._rules = [];
12639
12639
  this._ignoreCase = ignoreCase;
12640
12640
  this._allowRelativePaths = allowRelativePaths;
@@ -13440,6 +13440,152 @@ 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
+
13443
13589
  // src/utils/process.ts
13444
13590
  import { spawn } from "node:child_process";
13445
13591
  async function exec(command, options = {}) {
@@ -13486,47 +13632,6 @@ var init_process = () => {};
13486
13632
 
13487
13633
  // src/core/wrangler.ts
13488
13634
  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
13635
  async function checkWrangler() {
13531
13636
  const result = await exec(["npx", "wrangler", "--version"]);
13532
13637
  return result.success;
@@ -13581,23 +13686,28 @@ function findWranglerConfig(appPath) {
13581
13686
  }
13582
13687
  return;
13583
13688
  }
13584
- async function updateWranglerVars(appPath, vars) {
13689
+ async function updateWranglerVars(appPath, environment, vars) {
13585
13690
  const configPath = findWranglerConfig(appPath);
13586
13691
  if (!configPath) {
13587
13692
  return { success: false, updatedCount: 0 };
13588
13693
  }
13589
13694
  const content = await readFile(configPath);
13590
- const stripped = stripJsonc(content);
13591
- const config = JSON.parse(stripped);
13592
- config.vars = { ...config.vars || {}, ...vars };
13593
- await writeFile(configPath, JSON.stringify(config, null, 2) + `
13594
- `);
13695
+ const config = import_jsonc_parser.parse(content);
13696
+ const envSection = config?.env ?? {};
13697
+ const existingVars = envSection[environment]?.vars ?? {};
13698
+ 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);
13595
13703
  return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
13596
13704
  }
13705
+ var import_jsonc_parser;
13597
13706
  var init_wrangler = __esm(() => {
13598
13707
  init_dist2();
13599
13708
  init_process();
13600
13709
  init_fs();
13710
+ import_jsonc_parser = __toESM(require_main3(), 1);
13601
13711
  });
13602
13712
 
13603
13713
  // src/commands/push.ts
@@ -13775,7 +13885,7 @@ var init_push = __esm(() => {
13775
13885
  }
13776
13886
  }
13777
13887
  if (varsCount > 0) {
13778
- const varsResult = await updateWranglerVars(app.absolutePath, varsToPush);
13888
+ const varsResult = await updateWranglerVars(app.absolutePath, environment, varsToPush);
13779
13889
  if (varsResult.success) {
13780
13890
  consola.success(` Wrote ${varsCount} vars to ${varsResult.filePath}`);
13781
13891
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cf-envsync",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "description": "Sync .env files to Cloudflare Workers secrets, .dev.vars, and more",
5
5
  "type": "module",
6
6
  "exports": {
@@ -33,7 +33,8 @@
33
33
  "@dotenvx/dotenvx": "^1.52.0",
34
34
  "citty": "^0.2.1",
35
35
  "consola": "^3.4.2",
36
- "jiti": "^2.4.2"
36
+ "jiti": "^2.4.2",
37
+ "jsonc-parser": "^3.3.1"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@types/node": "^22"