opencode-supertask 0.1.6 → 0.1.8

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
  }
@@ -22822,6 +22832,23 @@ function findBunPath() {
22822
22832
  return process.execPath;
22823
22833
  }
22824
22834
  }
22835
+ function pm2StartGateway(version2) {
22836
+ const bunPath = findBunPath();
22837
+ return pm2Exec([
22838
+ "start",
22839
+ bunPath,
22840
+ "--name",
22841
+ PROCESS_NAME,
22842
+ "--interpreter",
22843
+ "none",
22844
+ "--restart-delay",
22845
+ "5000",
22846
+ "--max-restarts",
22847
+ "30",
22848
+ "--",
22849
+ GATEWAY_ENTRY
22850
+ ]);
22851
+ }
22825
22852
  function install() {
22826
22853
  if (!isPm2Installed()) {
22827
22854
  if (!installPm2()) {
@@ -22840,19 +22867,8 @@ function install() {
22840
22867
  }
22841
22868
  } else {
22842
22869
  console.log("[supertask] Starting Gateway with pm2...");
22843
- const bunPath = findBunPath();
22844
- const { ok, output } = pm2Exec([
22845
- "start",
22846
- GATEWAY_ENTRY,
22847
- "--name",
22848
- PROCESS_NAME,
22849
- "--interpreter",
22850
- bunPath,
22851
- "--restart-delay",
22852
- "5000",
22853
- "--max-restarts",
22854
- "30"
22855
- ]);
22870
+ const version2 = getPackageVersion();
22871
+ const { ok, output } = pm2StartGateway(version2);
22856
22872
  if (!ok) {
22857
22873
  throw new Error(`[supertask] pm2 start failed: ${output}`);
22858
22874
  }
@@ -22886,10 +22902,20 @@ function uninstall() {
22886
22902
  console.log("[supertask] To fully remove pm2 startup: pm2 unstartup");
22887
22903
  }
22888
22904
  function ensureGateway() {
22905
+ const currentVersion = getPackageVersion();
22889
22906
  try {
22890
22907
  const list = pm2JsonList();
22891
22908
  const proc = list.find((p) => p.name === PROCESS_NAME);
22892
22909
  if (proc && proc.pm2_env?.status === "online") {
22910
+ const runningVersion = proc.pm2_env.pm_exec_path ? void 0 : void 0;
22911
+ const envVersion = proc.pm2_env.env?.SUPERTASK_VERSION;
22912
+ if (envVersion === currentVersion) {
22913
+ return;
22914
+ }
22915
+ console.log(`[supertask] Version changed: ${envVersion ?? "unknown"} \u2192 ${currentVersion}, reloading Gateway...`);
22916
+ pm2Exec(["delete", PROCESS_NAME]);
22917
+ pm2StartGateway(currentVersion);
22918
+ pm2Exec(["save"]);
22893
22919
  return;
22894
22920
  }
22895
22921
  } catch {
@@ -22912,19 +22938,8 @@ function ensureGateway() {
22912
22938
  if (existing) {
22913
22939
  pm2Exec(["restart", PROCESS_NAME]);
22914
22940
  } else {
22915
- const bunPath = findBunPath();
22916
- pm2Exec([
22917
- "start",
22918
- GATEWAY_ENTRY,
22919
- "--name",
22920
- PROCESS_NAME,
22921
- "--interpreter",
22922
- bunPath,
22923
- "--restart-delay",
22924
- "5000",
22925
- "--max-restarts",
22926
- "30"
22927
- ]);
22941
+ const version2 = getPackageVersion();
22942
+ pm2StartGateway(version2);
22928
22943
  }
22929
22944
  pm2Exec(["save"]);
22930
22945
  }