@kenkaiiii/gg-core 5.100.2 → 5.100.3

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.cjs CHANGED
@@ -546,6 +546,15 @@ async function download(asset, dest, opts) {
546
546
  );
547
547
  }
548
548
  }
549
+ function compareVersions(a, b) {
550
+ const pa = a.split(/[.-]/).map((n) => Number.parseInt(n, 10) || 0);
551
+ const pb = b.split(/[.-]/).map((n) => Number.parseInt(n, 10) || 0);
552
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
553
+ const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
554
+ if (diff !== 0) return diff;
555
+ }
556
+ return 0;
557
+ }
549
558
  async function removeOldVersions(home, keep) {
550
559
  let entries;
551
560
  try {
@@ -556,6 +565,7 @@ async function removeOldVersions(home, keep) {
556
565
  for (const entry of entries) {
557
566
  if (!entry.isDirectory() || entry.name === keep || entry.name === "config") continue;
558
567
  if (!/^\d+\.\d+\.\d+/.test(entry.name)) continue;
568
+ if (compareVersions(entry.name, keep) > 0) continue;
559
569
  await import_promises2.default.rm(import_node_path2.default.join(home, entry.name), { recursive: true, force: true }).catch(() => {
560
570
  });
561
571
  }
@@ -4782,7 +4792,7 @@ var import_node_fs5 = __toESM(require("fs"), 1);
4782
4792
  var import_node_path6 = __toESM(require("path"), 1);
4783
4793
  var CHECK_INTERVAL_MS = 60 * 60 * 1e3;
4784
4794
  var FETCH_TIMEOUT_MS = 1e4;
4785
- function compareVersions(a, b) {
4795
+ function compareVersions2(a, b) {
4786
4796
  const pa = a.split(".").map(Number);
4787
4797
  const pb = b.split(".").map(Number);
4788
4798
  for (let i = 0; i < 3; i++) {
@@ -4868,7 +4878,7 @@ function createAutoUpdater(config) {
4868
4878
  latestVersion: latestVersion ?? void 0,
4869
4879
  updatePending: false
4870
4880
  };
4871
- if (latestVersion && compareVersions(latestVersion, currentVersion) > 0) {
4881
+ if (latestVersion && compareVersions2(latestVersion, currentVersion) > 0) {
4872
4882
  newState.updatePending = true;
4873
4883
  }
4874
4884
  writeState(newState);
@@ -4880,7 +4890,7 @@ function createAutoUpdater(config) {
4880
4890
  const state = readState();
4881
4891
  let message = null;
4882
4892
  if (state?.updatePending && state.latestVersion) {
4883
- if (compareVersions(state.latestVersion, currentVersion) > 0) {
4893
+ if (compareVersions2(state.latestVersion, currentVersion) > 0) {
4884
4894
  const info = detectInstallInfo();
4885
4895
  if (info.updateCommand) {
4886
4896
  performUpdateInBackground(info.updateCommand);
@@ -4907,7 +4917,7 @@ function createAutoUpdater(config) {
4907
4917
  try {
4908
4918
  const state = readState();
4909
4919
  if (!state?.latestVersion) return null;
4910
- if (compareVersions(state.latestVersion, currentVersion) <= 0) return null;
4920
+ if (compareVersions2(state.latestVersion, currentVersion) <= 0) return null;
4911
4921
  return { latestVersion: state.latestVersion };
4912
4922
  } catch {
4913
4923
  return null;
@@ -4918,7 +4928,7 @@ function createAutoUpdater(config) {
4918
4928
  periodicTimer = setInterval(() => {
4919
4929
  fetchLatestVersion().then((latestVersion) => {
4920
4930
  if (!latestVersion) return;
4921
- if (compareVersions(latestVersion, currentVersion) <= 0) return;
4931
+ if (compareVersions2(latestVersion, currentVersion) <= 0) return;
4922
4932
  const info = detectInstallInfo();
4923
4933
  if (!info.updateCommand) return;
4924
4934
  writeState({ lastCheckedAt: Date.now(), latestVersion, updatePending: true });