@boxes-dev/dvb 1.0.482 → 1.0.484

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/bin/dvbd.cjs CHANGED
@@ -3053,6 +3053,7 @@ var UPDATER_INTERVAL_MS = 15 * 60 * 1e3;
3053
3053
  var MAX_UPDATER_ERROR_LENGTH = 2e3;
3054
3054
  var runtimeManagerTestHooks = {
3055
3055
  ensureBundledRuntimeStaged: void 0,
3056
+ listLiveRuntimeVersions: void 0,
3056
3057
  startBackgroundUpdater: void 0,
3057
3058
  runRuntimeChild: void 0
3058
3059
  };
@@ -3105,6 +3106,15 @@ var readStageVersion = async (runtimeDir) => {
3105
3106
  }
3106
3107
  };
3107
3108
  var resolveRuntimeBinPath = (runtimeDir, kind) => import_node_path11.default.join(runtimeDir, "dist", "bin", `${kind}.cjs`);
3109
+ var readLinkedRuntimeVersion = async (linkPath) => {
3110
+ try {
3111
+ const runtimeDir = await import_promises2.default.realpath(linkPath);
3112
+ const version = import_node_path11.default.basename(runtimeDir).trim();
3113
+ return version.length > 0 ? version : null;
3114
+ } catch {
3115
+ return null;
3116
+ }
3117
+ };
3108
3118
  var readCurrentRuntime = async (homeDir = import_node_os2.default.homedir()) => {
3109
3119
  const currentLink = resolveCurrentRuntimeLink(homeDir);
3110
3120
  try {
@@ -3121,6 +3131,74 @@ var readCurrentRuntime = async (homeDir = import_node_os2.default.homedir()) =>
3121
3131
  return null;
3122
3132
  }
3123
3133
  };
3134
+ var listLiveRuntimeVersions = async (homeDir = import_node_os2.default.homedir()) => {
3135
+ const releasesDir = resolveRuntimeReleasesDir(homeDir);
3136
+ const ps2 = (0, import_node_child_process.spawnSync)("ps", ["eww", "-Ao", "command="], {
3137
+ encoding: "utf8"
3138
+ });
3139
+ if (ps2.error || ps2.status !== 0 || typeof ps2.stdout !== "string") {
3140
+ return [];
3141
+ }
3142
+ const versions = /* @__PURE__ */ new Set();
3143
+ const runtimePattern = new RegExp(
3144
+ `${escapeRegExp(releasesDir)}/([^/\\s]+)/dist/bin/dvb(?:d)?\\.cjs(?=\\s|$)`,
3145
+ "g"
3146
+ );
3147
+ for (const line of ps2.stdout.split(/\r?\n/)) {
3148
+ runtimePattern.lastIndex = 0;
3149
+ for (let match = runtimePattern.exec(line); match; match = runtimePattern.exec(line)) {
3150
+ const version = match[1]?.trim();
3151
+ if (version) {
3152
+ versions.add(version);
3153
+ }
3154
+ }
3155
+ }
3156
+ return [...versions];
3157
+ };
3158
+ var pruneRuntimeReleases = async (homeDir = import_node_os2.default.homedir()) => {
3159
+ const releasesDir = resolveRuntimeReleasesDir(homeDir);
3160
+ const keep = /* @__PURE__ */ new Set();
3161
+ const current = await readCurrentRuntime(homeDir);
3162
+ if (current) {
3163
+ keep.add(current.version);
3164
+ }
3165
+ const previous = await readLinkedRuntimeVersion(
3166
+ resolvePreviousRuntimeLink(homeDir)
3167
+ );
3168
+ if (previous) {
3169
+ keep.add(previous);
3170
+ }
3171
+ const listLiveRuntimeVersionsFn = runtimeManagerTestHooks.listLiveRuntimeVersions ?? listLiveRuntimeVersions;
3172
+ for (const version of await listLiveRuntimeVersionsFn(homeDir)) {
3173
+ const normalized = version.trim();
3174
+ if (normalized.length > 0) {
3175
+ keep.add(normalized);
3176
+ }
3177
+ }
3178
+ try {
3179
+ const entries = await import_promises2.default.readdir(releasesDir, { withFileTypes: true });
3180
+ for (const entry of entries) {
3181
+ if (!entry.isDirectory()) {
3182
+ continue;
3183
+ }
3184
+ if (entry.name.startsWith(".tmp-")) {
3185
+ continue;
3186
+ }
3187
+ if (keep.has(entry.name)) {
3188
+ continue;
3189
+ }
3190
+ await import_promises2.default.rm(import_node_path11.default.join(releasesDir, entry.name), {
3191
+ recursive: true,
3192
+ force: true
3193
+ });
3194
+ }
3195
+ } catch (error) {
3196
+ const code = error?.code;
3197
+ if (code !== "ENOENT") {
3198
+ throw error;
3199
+ }
3200
+ }
3201
+ };
3124
3202
  var resolveBundledRuntimeRoot = () => {
3125
3203
  const require2 = (0, import_node_module.createRequire)(resolveBasePath());
3126
3204
  const manifestPath = require2.resolve(`${RUNTIME_PACKAGE_NAME}/package.json`);
@@ -3156,6 +3234,7 @@ var trimUpdaterError = (error) => {
3156
3234
  const message = error instanceof Error ? error.message : String(error);
3157
3235
  return message.length > MAX_UPDATER_ERROR_LENGTH ? `${message.slice(0, MAX_UPDATER_ERROR_LENGTH)}...` : message;
3158
3236
  };
3237
+ var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3159
3238
  var isProcessAlive = (pid) => {
3160
3239
  if (!Number.isInteger(pid) || pid <= 0) {
3161
3240
  return false;
@@ -3471,6 +3550,10 @@ var promoteRuntimeStage = async (stageDir, version, homeDir = import_node_os2.de
3471
3550
  );
3472
3551
  }
3473
3552
  await writeSymlinkAtomic(resolveCurrentRuntimeLink(homeDir), version);
3553
+ try {
3554
+ await pruneRuntimeReleases(homeDir);
3555
+ } catch {
3556
+ }
3474
3557
  };
3475
3558
  var installBundledRuntime = async (bundled, homeDir = import_node_os2.default.homedir()) => {
3476
3559
  const stageDir = await createStageDir(bundled.version, homeDir);