opencode-supertask 0.1.6 → 0.1.7

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/cli/index.js CHANGED
@@ -18846,8 +18846,8 @@ var require_CronFileParser = __commonJS({
18846
18846
  * @throws If file cannot be read
18847
18847
  */
18848
18848
  static parseFileSync(filePath) {
18849
- const { readFileSync: readFileSync3 } = __require("fs");
18850
- const data = readFileSync3(filePath, "utf8");
18849
+ const { readFileSync: readFileSync4 } = __require("fs");
18850
+ const data = readFileSync4(filePath, "utf8");
18851
18851
  return _CronFileParser.#parseContent(data);
18852
18852
  }
18853
18853
  /**
@@ -22759,6 +22759,16 @@ __export(pm2_exports, {
22759
22759
  import { execSync, spawnSync } from "child_process";
22760
22760
  import { join as join3, dirname as dirname3 } from "path";
22761
22761
  import { fileURLToPath as fileURLToPath2 } from "url";
22762
+ import { readFileSync as readFileSync3 } from "fs";
22763
+ function getPackageVersion() {
22764
+ try {
22765
+ const pkgPath = join3(__dirname, "../package.json");
22766
+ const pkg = JSON.parse(readFileSync3(pkgPath, "utf-8"));
22767
+ return pkg.version || "0.0.0";
22768
+ } catch {
22769
+ return "0.0.0";
22770
+ }
22771
+ }
22762
22772
  function pm2Bin() {
22763
22773
  return process.platform === "win32" ? "pm2.cmd" : "pm2";
22764
22774
  }
@@ -22841,6 +22851,7 @@ function install() {
22841
22851
  } else {
22842
22852
  console.log("[supertask] Starting Gateway with pm2...");
22843
22853
  const bunPath = findBunPath();
22854
+ const version2 = getPackageVersion();
22844
22855
  const { ok, output } = pm2Exec([
22845
22856
  "start",
22846
22857
  GATEWAY_ENTRY,
@@ -22851,7 +22862,9 @@ function install() {
22851
22862
  "--restart-delay",
22852
22863
  "5000",
22853
22864
  "--max-restarts",
22854
- "30"
22865
+ "30",
22866
+ "--env",
22867
+ `SUPERTASK_VERSION=${version2}`
22855
22868
  ]);
22856
22869
  if (!ok) {
22857
22870
  throw new Error(`[supertask] pm2 start failed: ${output}`);
@@ -22886,10 +22899,37 @@ function uninstall() {
22886
22899
  console.log("[supertask] To fully remove pm2 startup: pm2 unstartup");
22887
22900
  }
22888
22901
  function ensureGateway() {
22902
+ const currentVersion = getPackageVersion();
22889
22903
  try {
22890
22904
  const list = pm2JsonList();
22891
22905
  const proc = list.find((p) => p.name === PROCESS_NAME);
22892
22906
  if (proc && proc.pm2_env?.status === "online") {
22907
+ const runningVersion = proc.pm2_env.pm_exec_path ? void 0 : void 0;
22908
+ const envVersion = proc.pm2_env.env?.SUPERTASK_VERSION;
22909
+ if (envVersion === currentVersion) {
22910
+ return;
22911
+ }
22912
+ console.log(`[supertask] Version changed: ${envVersion ?? "unknown"} \u2192 ${currentVersion}, reloading Gateway...`);
22913
+ const bunPath = findBunPath();
22914
+ pm2Exec([
22915
+ "delete",
22916
+ PROCESS_NAME
22917
+ ]);
22918
+ pm2Exec([
22919
+ "start",
22920
+ GATEWAY_ENTRY,
22921
+ "--name",
22922
+ PROCESS_NAME,
22923
+ "--interpreter",
22924
+ bunPath,
22925
+ "--restart-delay",
22926
+ "5000",
22927
+ "--max-restarts",
22928
+ "30",
22929
+ "--env",
22930
+ `SUPERTASK_VERSION=${currentVersion}`
22931
+ ]);
22932
+ pm2Exec(["save"]);
22893
22933
  return;
22894
22934
  }
22895
22935
  } catch {
@@ -22913,6 +22953,7 @@ function ensureGateway() {
22913
22953
  pm2Exec(["restart", PROCESS_NAME]);
22914
22954
  } else {
22915
22955
  const bunPath = findBunPath();
22956
+ const version2 = getPackageVersion();
22916
22957
  pm2Exec([
22917
22958
  "start",
22918
22959
  GATEWAY_ENTRY,
@@ -22923,7 +22964,9 @@ function ensureGateway() {
22923
22964
  "--restart-delay",
22924
22965
  "5000",
22925
22966
  "--max-restarts",
22926
- "30"
22967
+ "30",
22968
+ "--env",
22969
+ `SUPERTASK_VERSION=${version2}`
22927
22970
  ]);
22928
22971
  }
22929
22972
  pm2Exec(["save"]);